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