xref: /reactos/drivers/bus/pci/pci.h (revision 09dde2cf)
1 #ifndef _PCI_PCH_
2 #define _PCI_PCH_
3 
4 #include <ntifs.h>
5 #include <cmreslist.h>
6 #include <ntstrsafe.h>
7 
8 #define TAG_PCI '0ICP'
9 
10 typedef struct _PCI_DEVICE
11 {
12     // Entry on device list
13     LIST_ENTRY ListEntry;
14     // Physical Device Object of device
15     PDEVICE_OBJECT Pdo;
16     // PCI bus number
17     ULONG BusNumber;
18     // PCI slot number
19     PCI_SLOT_NUMBER SlotNumber;
20     // PCI configuration data
21     PCI_COMMON_CONFIG PciConfig;
22     // Enable memory space
23     BOOLEAN EnableMemorySpace;
24     // Enable I/O space
25     BOOLEAN EnableIoSpace;
26     // Enable bus master
27     BOOLEAN EnableBusMaster;
28     // Whether the device is owned by the KD
29     BOOLEAN IsDebuggingDevice;
30 } PCI_DEVICE, *PPCI_DEVICE;
31 
32 
33 typedef enum
34 {
35     dsStopped,
36     dsStarted,
37     dsPaused,
38     dsRemoved,
39     dsSurpriseRemoved
40 } PCI_DEVICE_STATE;
41 
42 
43 typedef struct _COMMON_DEVICE_EXTENSION
44 {
45     // Pointer to device object, this device extension is associated with
46     PDEVICE_OBJECT DeviceObject;
47     // Wether this device extension is for an FDO or PDO
48     BOOLEAN IsFDO;
49     // Wether the device is removed
50     BOOLEAN Removed;
51     // Current device power state for the device
52     DEVICE_POWER_STATE DevicePowerState;
53 } COMMON_DEVICE_EXTENSION, *PCOMMON_DEVICE_EXTENSION;
54 
55 /* Physical Device Object device extension for a child device */
56 typedef struct _PDO_DEVICE_EXTENSION
57 {
58     // Common device data
59     COMMON_DEVICE_EXTENSION Common;
60     // Functional device object
61     PDEVICE_OBJECT Fdo;
62     // Pointer to PCI Device informations
63     PPCI_DEVICE PciDevice;
64     // Device ID
65     UNICODE_STRING DeviceID;
66     // Instance ID
67     UNICODE_STRING InstanceID;
68     // Hardware IDs
69     UNICODE_STRING HardwareIDs;
70     // Compatible IDs
71     UNICODE_STRING CompatibleIDs;
72     // Textual description of device
73     UNICODE_STRING DeviceDescription;
74     // Textual description of device location
75     UNICODE_STRING DeviceLocation;
76     // Number of interfaces references
77     LONG References;
78 } PDO_DEVICE_EXTENSION, *PPDO_DEVICE_EXTENSION;
79 
80 /* Functional Device Object device extension for the PCI driver device object */
81 typedef struct _FDO_DEVICE_EXTENSION
82 {
83     // Common device data
84     COMMON_DEVICE_EXTENSION Common;
85     // Entry on device list
86     LIST_ENTRY ListEntry;
87     // PCI bus number serviced by this FDO
88     ULONG BusNumber;
89     // Current state of the driver
90     PCI_DEVICE_STATE State;
91     // Namespace device list
92     LIST_ENTRY DeviceListHead;
93     // Number of (not removed) devices in device list
94     ULONG DeviceListCount;
95     // Lock for namespace device list
96     KSPIN_LOCK DeviceListLock;
97     // Lower device object
98     PDEVICE_OBJECT Ldo;
99 } FDO_DEVICE_EXTENSION, *PFDO_DEVICE_EXTENSION;
100 
101 
102 /* Driver extension associated with PCI driver */
103 typedef struct _PCI_DRIVER_EXTENSION
104 {
105     //
106     LIST_ENTRY BusListHead;
107     // Lock for namespace bus list
108     KSPIN_LOCK BusListLock;
109 } PCI_DRIVER_EXTENSION, *PPCI_DRIVER_EXTENSION;
110 
111 typedef union _PCI_TYPE1_CFG_CYCLE_BITS
112 {
113     struct
114     {
115         ULONG InUse:2;
116         ULONG RegisterNumber:6;
117         ULONG FunctionNumber:3;
118         ULONG DeviceNumber:5;
119         ULONG BusNumber:8;
120         ULONG Reserved2:8;
121     };
122     ULONG AsULONG;
123 } PCI_TYPE1_CFG_CYCLE_BITS, *PPCI_TYPE1_CFG_CYCLE_BITS;
124 
125 /* We need a global variable to get the driver extension,
126  * because at least InterfacePciDevicePresent has no
127  * other way to get it... */
128 extern PPCI_DRIVER_EXTENSION DriverExtension;
129 
130 extern BOOLEAN HasDebuggingDevice;
131 extern PCI_TYPE1_CFG_CYCLE_BITS PciDebuggingDevice[2];
132 
133 /* fdo.c */
134 
135 NTSTATUS
136 FdoPnpControl(
137     PDEVICE_OBJECT DeviceObject,
138     PIRP Irp);
139 
140 NTSTATUS
141 FdoPowerControl(
142     PDEVICE_OBJECT DeviceObject,
143     PIRP Irp);
144 
145 /* pci.c */
146 
147 NTSTATUS
148 PciCreateDeviceIDString(
149     PUNICODE_STRING DeviceID,
150     PPCI_DEVICE Device);
151 
152 NTSTATUS
153 PciCreateInstanceIDString(
154     PUNICODE_STRING InstanceID,
155     PPCI_DEVICE Device);
156 
157 NTSTATUS
158 PciCreateHardwareIDsString(
159     PUNICODE_STRING HardwareIDs,
160     PPCI_DEVICE Device);
161 
162 NTSTATUS
163 PciCreateCompatibleIDsString(
164     PUNICODE_STRING HardwareIDs,
165     PPCI_DEVICE Device);
166 
167 NTSTATUS
168 PciCreateDeviceDescriptionString(
169     PUNICODE_STRING DeviceDescription,
170     PPCI_DEVICE Device);
171 
172 NTSTATUS
173 PciCreateDeviceLocationString(
174     PUNICODE_STRING DeviceLocation,
175     PPCI_DEVICE Device);
176 
177 NTSTATUS
178 PciDuplicateUnicodeString(
179     IN ULONG Flags,
180     IN PCUNICODE_STRING SourceString,
181     OUT PUNICODE_STRING DestinationString);
182 
183 /* pdo.c */
184 
185 NTSTATUS
186 PdoPnpControl(
187     PDEVICE_OBJECT DeviceObject,
188     PIRP Irp);
189 
190 NTSTATUS
191 PdoPowerControl(
192     PDEVICE_OBJECT DeviceObject,
193     PIRP Irp);
194 
195 
196 CODE_SEG("INIT")
197 NTSTATUS
198 NTAPI
199 DriverEntry(
200     IN PDRIVER_OBJECT DriverObject,
201     IN PUNICODE_STRING RegistryPath);
202 
203 #endif /* _PCI_PCH_ */
204