[PCIX]: Fix 17 different bugs in the new PCI driver. ACPI and PCI IRQ Routing table...
[reactos.git] / reactos / drivers / bus / pcix / pci.h
1 /*
2 * PROJECT: ReactOS PCI Bus Driver
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: drivers/bus/pci/pci.h
5 * PURPOSE: Main Header File
6 * PROGRAMMERS: ReactOS Portable Systems Group
7 */
8
9 #include <initguid.h>
10 #include <ntifs.h>
11 #include <ntagp.h>
12 #include <wdmguid.h>
13 #include <wchar.h>
14 #include <acpiioct.h>
15 #include <drivers/pci/pci.h>
16 #include <drivers/acpi/acpi.h>
17 #include "halfuncs.h"
18 #include "rtlfuncs.h"
19 #include "vffuncs.h"
20 #include "bugcodes.h"
21
22 //
23 // Tag used in all pool allocations (Pci Bus)
24 //
25 #define PCI_POOL_TAG 'BicP'
26
27 //
28 // Checks if the specified FDO is the FDO for the Root PCI Bus
29 //
30 #define PCI_IS_ROOT_FDO(x) ((x)->BusRootFdoExtension == x)
31
32 //
33 // Assertions to make sure we are dealing with the right kind of extension
34 //
35 #define ASSERT_FDO(x) ASSERT((x)->ExtensionType == PciFdoExtensionType);
36 #define ASSERT_PDO(x) ASSERT((x)->ExtensionType == PciPdoExtensionType);
37
38 //
39 // PCI Hack Entry Name Lengths
40 //
41 #define PCI_HACK_ENTRY_SIZE sizeof(L"VVVVdddd") - sizeof(UNICODE_NULL)
42 #define PCI_HACK_ENTRY_REV_SIZE sizeof(L"VVVVddddRR") - sizeof(UNICODE_NULL)
43 #define PCI_HACK_ENTRY_SUBSYS_SIZE sizeof(L"VVVVddddssssIIII") - sizeof(UNICODE_NULL)
44 #define PCI_HACK_ENTRY_FULL_SIZE sizeof(L"VVVVddddssssIIIIRR") - sizeof(UNICODE_NULL)
45
46 //
47 // PCI Hack Entry Flags
48 //
49 #define PCI_HACK_HAS_REVISION_INFO 0x01
50 #define PCI_HACK_HAS_SUBSYSTEM_INFO 0x02
51
52 //
53 // Device Extension, Interface, Translator and Arbiter Signatures
54 //
55 typedef enum _PCI_SIGNATURE
56 {
57 PciPdoExtensionType = '0Pci',
58 PciFdoExtensionType = '1Pci',
59 PciArb_Io = '2Pci',
60 PciArb_Memory = '3Pci',
61 PciArb_Interrupt = '4Pci',
62 PciArb_BusNumber = '5Pci',
63 PciTrans_Interrupt = '6Pci',
64 PciInterface_BusHandler = '7Pci',
65 PciInterface_IntRouteHandler = '8Pci',
66 PciInterface_PciCb = '9Pci',
67 PciInterface_LegacyDeviceDetection = ':Pci',
68 PciInterface_PmeHandler = ';Pci',
69 PciInterface_DevicePresent = '<Pci',
70 PciInterface_NativeIde = '=Pci',
71 PciInterface_AgpTarget = '>Pci',
72 PciInterface_Location = '?Pci'
73 } PCI_SIGNATURE, *PPCI_SIGNATURE;
74
75 //
76 // Device Extension Logic States
77 //
78 typedef enum _PCI_STATE
79 {
80 PciNotStarted,
81 PciStarted,
82 PciDeleted,
83 PciStopped,
84 PciSurpriseRemoved,
85 PciSynchronizedOperation,
86 PciMaxObjectState
87 } PCI_STATE;
88
89 //
90 // IRP Dispatch Logic Style
91 //
92 typedef enum _PCI_DISPATCH_STYLE
93 {
94 IRP_COMPLETE,
95 IRP_DOWNWARD,
96 IRP_UPWARD,
97 IRP_DISPATCH,
98 } PCI_DISPATCH_STYLE;
99
100 //
101 // PCI Hack Entry Information
102 //
103 typedef struct _PCI_HACK_ENTRY
104 {
105 USHORT VendorID;
106 USHORT DeviceID;
107 USHORT SubVendorID;
108 USHORT SubSystemID;
109 ULONGLONG HackFlags;
110 USHORT RevisionID;
111 UCHAR Flags;
112 } PCI_HACK_ENTRY, *PPCI_HACK_ENTRY;
113
114 //
115 // Power State Information for Device Extension
116 //
117 typedef struct _PCI_POWER_STATE
118 {
119 SYSTEM_POWER_STATE CurrentSystemState;
120 DEVICE_POWER_STATE CurrentDeviceState;
121 SYSTEM_POWER_STATE SystemWakeLevel;
122 DEVICE_POWER_STATE DeviceWakeLevel;
123 DEVICE_POWER_STATE SystemStateMapping[7];
124 PIRP WaitWakeIrp;
125 PVOID SavedCancelRoutine;
126 LONG Paging;
127 LONG Hibernate;
128 LONG CrashDump;
129 } PCI_POWER_STATE, *PPCI_POWER_STATE;
130
131 //
132 // Internal PCI Lock Structure
133 //
134 typedef struct _PCI_LOCK
135 {
136 LONG Atom;
137 BOOLEAN OldIrql;
138 } PCI_LOCK, *PPCI_LOCK;
139
140 //
141 // Device Extension for a Bus FDO
142 //
143 typedef struct _PCI_FDO_EXTENSION
144 {
145 SINGLE_LIST_ENTRY List;
146 ULONG ExtensionType;
147 struct _PCI_MJ_DISPATCH_TABLE *IrpDispatchTable;
148 BOOLEAN DeviceState;
149 BOOLEAN TentativeNextState;
150 KEVENT SecondaryExtLock;
151 PDEVICE_OBJECT PhysicalDeviceObject;
152 PDEVICE_OBJECT FunctionalDeviceObject;
153 PDEVICE_OBJECT AttachedDeviceObject;
154 KEVENT ChildListLock;
155 struct _PCI_PDO_EXTENSION *ChildPdoList;
156 struct _PCI_FDO_EXTENSION *BusRootFdoExtension;
157 struct _PCI_FDO_EXTENSION *ParentFdoExtension;
158 struct _PCI_PDO_EXTENSION *ChildBridgePdoList;
159 PPCI_BUS_INTERFACE_STANDARD PciBusInterface;
160 BOOLEAN MaxSubordinateBus;
161 BUS_HANDLER *BusHandler;
162 BOOLEAN BaseBus;
163 BOOLEAN Fake;
164 BOOLEAN ChildDelete;
165 BOOLEAN Scanned;
166 BOOLEAN ArbitersInitialized;
167 BOOLEAN BrokenVideoHackApplied;
168 BOOLEAN Hibernated;
169 PCI_POWER_STATE PowerState;
170 SINGLE_LIST_ENTRY SecondaryExtension;
171 LONG ChildWaitWakeCount;
172 PPCI_COMMON_CONFIG PreservedConfig;
173 PCI_LOCK Lock;
174 struct
175 {
176 BOOLEAN Acquired;
177 BOOLEAN CacheLineSize;
178 BOOLEAN LatencyTimer;
179 BOOLEAN EnablePERR;
180 BOOLEAN EnableSERR;
181 } HotPlugParameters;
182 LONG BusHackFlags;
183 } PCI_FDO_EXTENSION, *PPCI_FDO_EXTENSION;
184
185 //
186 // IRP Dispatch Function Type
187 //
188 typedef NTSTATUS (NTAPI *PCI_DISPATCH_FUNCTION)(
189 IN PIRP Irp,
190 IN PIO_STACK_LOCATION IoStackLocation,
191 IN PPCI_FDO_EXTENSION DeviceExtension
192 );
193
194 //
195 // IRP Dispatch Minor Table
196 //
197 typedef struct _PCI_MN_DISPATCH_TABLE
198 {
199 PCI_DISPATCH_STYLE DispatchStyle;
200 PCI_DISPATCH_FUNCTION DispatchFunction;
201 } PCI_MN_DISPATCH_TABLE, *PPCI_MN_DISPATCH_TABLE;
202
203 //
204 // IRP Dispatch Major Table
205 //
206 typedef struct _PCI_MJ_DISPATCH_TABLE
207 {
208 ULONG PnpIrpMaximumMinorFunction;
209 PPCI_MN_DISPATCH_TABLE PnpIrpDispatchTable;
210 ULONG PowerIrpMaximumMinorFunction;
211 PPCI_MN_DISPATCH_TABLE PowerIrpDispatchTable;
212 PCI_DISPATCH_STYLE SystemControlIrpDispatchStyle;
213 PCI_DISPATCH_FUNCTION SystemControlIrpDispatchFunction;
214 PCI_DISPATCH_STYLE OtherIrpDispatchStyle;
215 PCI_DISPATCH_FUNCTION OtherIrpDispatchFunction;
216 } PCI_MJ_DISPATCH_TABLE, *PPCI_MJ_DISPATCH_TABLE;
217
218 //
219 // Generic PCI Interface Constructor and Initializer
220 //
221 struct _PCI_INTERFACE;
222 typedef NTSTATUS (NTAPI *PCI_INTERFACE_CONSTRUCTOR)(
223 IN PPCI_FDO_EXTENSION DeviceExtension,
224 IN PVOID Instance,
225 IN PVOID InterfaceData,
226 IN USHORT Version,
227 IN USHORT Size,
228 IN PINTERFACE Interface
229 );
230
231 typedef NTSTATUS (NTAPI *PCI_INTERFACE_INITIALIZER)(
232 IN PVOID Instance
233 );
234
235 //
236 // Generic PCI Interface (Interface, Translator, Arbiter)
237 //
238 typedef struct _PCI_INTERFACE
239 {
240 LPGUID InterfaceType;
241 USHORT MinSize;
242 USHORT MinVersion;
243 USHORT MaxVersion;
244 USHORT Flags;
245 LONG ReferenceCount;
246 PCI_SIGNATURE Signature;
247 PCI_INTERFACE_CONSTRUCTOR Constructor;
248 PCI_INTERFACE_INITIALIZER Initializer;
249 } PCI_INTERFACE, *PPCI_INTERFACE;
250
251 //
252 // Generic Secondary Extension Instance Header (Interface, Translator, Arbiter)
253 //
254 typedef struct PCI_SECONDARY_EXTENSION
255 {
256 SINGLE_LIST_ENTRY List;
257 PCI_SIGNATURE ExtensionType;
258 PVOID Destructor;
259 } PCI_SECONDARY_EXTENSION, *PPCI_SECONDARY_EXTENSION;
260
261 //
262 // PCI Arbiter Instance
263 //
264 typedef struct PCI_ARBITER_INSTANCE
265 {
266 PCI_SECONDARY_EXTENSION Header;
267 PPCI_INTERFACE Interface;
268 PPCI_FDO_EXTENSION BusFdoExtension;
269 WCHAR InstanceName[24];
270 //ARBITER_INSTANCE CommonInstance; FIXME: Need Arbiter Headers
271 } PCI_ARBITER_INSTANCE, *PPCI_ARBITER_INSTANCE;
272
273 //
274 // IRP Dispatch Routines
275 //
276 NTSTATUS
277 NTAPI
278 PciDispatchIrp(
279 IN PDEVICE_OBJECT DeviceObject,
280 IN PIRP Irp
281 );
282
283 NTSTATUS
284 NTAPI
285 PciIrpNotSupported(
286 IN PIRP Irp,
287 IN PIO_STACK_LOCATION IoStackLocation,
288 IN PPCI_FDO_EXTENSION DeviceExtension
289 );
290
291 //
292 // Bus FDO Routines
293 //
294 NTSTATUS
295 NTAPI
296 PciAddDevice(
297 IN PDRIVER_OBJECT DriverObject,
298 IN PDEVICE_OBJECT PhysicalDeviceObject
299 );
300
301 //
302 // HAL Callback/Hook Routines
303 //
304 VOID
305 NTAPI
306 PciHookHal(
307 VOID
308 );
309
310 //
311 // PCI Verifier Routines
312 //
313 VOID
314 NTAPI
315 PciVerifierInit(
316 IN PDRIVER_OBJECT DriverObject
317 );
318
319 //
320 // Utility Routines
321 //
322 BOOLEAN
323 NTAPI
324 PciStringToUSHORT(
325 IN PWCHAR String,
326 OUT PUSHORT Value
327 );
328
329 BOOLEAN
330 NTAPI
331 PciIsDatacenter(
332 VOID
333 );
334
335 NTSTATUS
336 NTAPI
337 PciBuildDefaultExclusionLists(
338 VOID
339 );
340
341 BOOLEAN
342 NTAPI
343 PciUnicodeStringStrStr(
344 IN PUNICODE_STRING InputString,
345 IN PCUNICODE_STRING EqualString,
346 IN BOOLEAN CaseInSensitive
347 );
348
349 BOOLEAN
350 NTAPI
351 PciOpenKey(
352 IN PWCHAR KeyName,
353 IN HANDLE RootKey,
354 IN ACCESS_MASK DesiredAccess,
355 OUT PHANDLE KeyHandle,
356 OUT PNTSTATUS KeyStatus
357 );
358
359 NTSTATUS
360 NTAPI
361 PciGetRegistryValue(
362 IN PWCHAR ValueName,
363 IN PWCHAR KeyName,
364 IN HANDLE RootHandle,
365 IN ULONG Type,
366 OUT PVOID *OutputBuffer,
367 OUT PULONG OutputLength
368 );
369
370 PPCI_FDO_EXTENSION
371 NTAPI
372 PciFindParentPciFdoExtension(
373 IN PDEVICE_OBJECT DeviceObject,
374 IN PKEVENT Lock
375 );
376
377 VOID
378 NTAPI
379 PciInsertEntryAtTail(
380 IN PSINGLE_LIST_ENTRY ListHead,
381 IN PPCI_FDO_EXTENSION DeviceExtension,
382 IN PKEVENT Lock
383 );
384
385 NTSTATUS
386 NTAPI
387 PciGetDeviceProperty(
388 IN PDEVICE_OBJECT DeviceObject,
389 IN DEVICE_REGISTRY_PROPERTY DeviceProperty,
390 OUT PVOID *OutputBuffer
391 );
392
393 NTSTATUS
394 NTAPI
395 PciSendIoctl(
396 IN PDEVICE_OBJECT DeviceObject,
397 IN ULONG IoControlCode,
398 IN PVOID InputBuffer,
399 IN ULONG InputBufferLength,
400 IN PVOID OutputBuffer,
401 IN ULONG OutputBufferLength
402 );
403
404 VOID
405 NTAPI
406 PcipLinkSecondaryExtension(
407 IN PSINGLE_LIST_ENTRY List,
408 IN PVOID Lock,
409 IN PPCI_SECONDARY_EXTENSION SecondaryExtension,
410 IN PCI_SIGNATURE ExtensionType,
411 IN PVOID Destructor
412 );
413
414 //
415 // Configuration Routines
416 //
417 NTSTATUS
418 NTAPI
419 PciGetConfigHandlers(
420 IN PPCI_FDO_EXTENSION FdoExtension
421 );
422
423 //
424 // State Machine Logic Transition Routines
425 //
426 VOID
427 NTAPI
428 PciInitializeState(
429 IN PPCI_FDO_EXTENSION DeviceExtension
430 );
431
432 //
433 // Arbiter Support
434 //
435 NTSTATUS
436 NTAPI
437 PciInitializeArbiters(
438 IN PPCI_FDO_EXTENSION FdoExtension
439 );
440
441 //
442 // External Resources
443 //
444 extern SINGLE_LIST_ENTRY PciFdoExtensionListHead;
445 extern KEVENT PciGlobalLock;
446 extern PPCI_INTERFACE PciInterfaces[];
447
448 /* EOF */