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