Visual C++ backend for rbuild (for now just a hacked mingw backend) and related compi...
[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 #ifdef _MSC_VER
10 #define STDCALL
11 #define DDKAPI
12 #endif
13
14 #define TAG(A, B, C, D) (ULONG)(((A)<<0) + ((B)<<8) + ((C)<<16) + ((D)<<24))
15 #define TAG_PCI TAG('P', 'C', 'I', '0')
16
17 typedef struct _PCI_DEVICE
18 {
19 // Entry on device list
20 LIST_ENTRY ListEntry;
21 // Physical Device Object of device
22 PDEVICE_OBJECT Pdo;
23 // PCI bus number
24 ULONG BusNumber;
25 // PCI slot number
26 PCI_SLOT_NUMBER SlotNumber;
27 // PCI configuration data
28 PCI_COMMON_CONFIG PciConfig;
29 // Flag used during enumeration to locate removed devices
30 BOOLEAN RemovePending;
31 } PCI_DEVICE, *PPCI_DEVICE;
32
33
34 typedef enum {
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
112 /* We need a global variable to get the driver extension,
113 * because at least InterfacePciDevicePresent has no
114 * other way to get it... */
115 extern PPCI_DRIVER_EXTENSION DriverExtension;
116
117 /* fdo.c */
118
119 NTSTATUS
120 FdoPnpControl(
121 PDEVICE_OBJECT DeviceObject,
122 PIRP Irp);
123
124 NTSTATUS
125 FdoPowerControl(
126 PDEVICE_OBJECT DeviceObject,
127 PIRP Irp);
128
129 /* pci.c */
130
131 NTSTATUS
132 PciCreateDeviceIDString(
133 PUNICODE_STRING DeviceID,
134 PPCI_DEVICE Device);
135
136 NTSTATUS
137 PciCreateInstanceIDString(
138 PUNICODE_STRING InstanceID,
139 PPCI_DEVICE Device);
140
141 NTSTATUS
142 PciCreateHardwareIDsString(
143 PUNICODE_STRING HardwareIDs,
144 PPCI_DEVICE Device);
145
146 NTSTATUS
147 PciCreateCompatibleIDsString(
148 PUNICODE_STRING HardwareIDs,
149 PPCI_DEVICE Device);
150
151 NTSTATUS
152 PciCreateDeviceDescriptionString(
153 PUNICODE_STRING DeviceDescription,
154 PPCI_DEVICE Device);
155
156 NTSTATUS
157 PciCreateDeviceLocationString(
158 PUNICODE_STRING DeviceLocation,
159 PPCI_DEVICE Device);
160
161 NTSTATUS
162 PciDuplicateUnicodeString(
163 IN ULONG Flags,
164 IN PCUNICODE_STRING SourceString,
165 OUT PUNICODE_STRING DestinationString);
166
167 /* pdo.c */
168
169 NTSTATUS
170 PdoPnpControl(
171 PDEVICE_OBJECT DeviceObject,
172 PIRP Irp);
173
174 NTSTATUS
175 PdoPowerControl(
176 PDEVICE_OBJECT DeviceObject,
177 PIRP Irp);
178
179 NTSTATUS
180 STDCALL
181 DriverEntry(
182 IN PDRIVER_OBJECT DriverObject,
183 IN PUNICODE_STRING RegistryPath);
184
185 #endif /* __PCI_H */