Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2406 lines
60 KiB

  1. /*++
  2. Copyright (c) 1996-2000 Microsoft Corporation
  3. Module Name:
  4. pcip.h
  5. Abstract:
  6. This module contains local definitions for PCI.SYS.
  7. Author:
  8. Andrew Thornton (andrewth) 25-Jan-2000
  9. Revision History:
  10. --*/
  11. #if !defined(_PCIP_H)
  12. #define _PCIP_H
  13. //
  14. // Disable warnings of features used by the standard headers
  15. //
  16. // Disable warning C4214: nonstandard extension used : bit field types other than int
  17. // Disable warning C4201: nonstandard extension used : nameless struct/union
  18. // Disable warning C4115: named type definition in parentheses
  19. // Disable warning C4127: conditional expression is constant
  20. //
  21. #pragma warning(disable:4214 4201 4115 4127)
  22. #define _NTDRIVER_
  23. #define _NTSRV_
  24. #define _NTDDK_
  25. #define InitSafeBootMode TempInitSafeBootMode
  26. #include "ntos.h"
  27. #undef InitSafeBootMode
  28. #include "strsafe.h"
  29. #include "pci.h"
  30. #include "wdmguid.h"
  31. #include "zwapi.h"
  32. #include "pciirqmp.h"
  33. #include "arbiter.h"
  34. #include "acpiioct.h"
  35. #include "pciintrf.h"
  36. #include "pcicodes.h"
  37. #include "pciverifier.h"
  38. #include "acpitabl.h"
  39. //
  40. // regstr.h uses things of type WORD, which isn't around in kernel mode.
  41. //
  42. #define _IN_KERNEL_
  43. #include "regstr.h"
  44. //
  45. // Pragmas to disable /W4 warnings so PCI can be compiled /W4
  46. //
  47. // Disable warning C4057; X differs in indirection to slightly different base types from Y
  48. // Disable warning C4244; '+='/'-=' : conversion from 'int' to 'X', possible loss of data
  49. // Disable warning C4100: 'X' : unreferenced formal parameter
  50. #pragma warning(disable: 4057 4244 4100)
  51. //
  52. // It seems that anything to do with the definitions of GUIDs is
  53. // bogus.
  54. //
  55. typedef const GUID * PGUID;
  56. #define PciCompareGuid(a,b) \
  57. (RtlEqualMemory((PVOID)(a), (PVOID)(b), sizeof(GUID)))
  58. //
  59. // Internal constants.
  60. //
  61. #define PCI_CM_RESOURCE_VERSION 1
  62. #define PCI_CM_RESOURCE_REVISION 1
  63. #define PCI_MAX_CONFIG_TYPE (PCI_CARDBUS_BRIDGE_TYPE)
  64. //
  65. // Internal bug codes.
  66. //
  67. #define PCI_BUGCODE_TOO_MANY_CONFIG_GUESSES 0xdead0010
  68. //
  69. // Internal Controls
  70. //
  71. #define PCI_BOOT_CONFIG_PREFERRED 1
  72. #define PCIIDE_HACKS 1
  73. #define PCI_NT50_BETA1_HACKS 1
  74. #define PCI_DISABLE_LAST_CHANCE_INTERFACES 1
  75. #define MSI_SUPPORTED 0
  76. #define PCI_NO_MOVE_MODEM_IN_TOSHIBA 1
  77. //
  78. // Systemwide hack flags. These flags are a bitmask that can be set to zero so
  79. // as to eliminate support for the hack.
  80. //
  81. #define PCIFLAG_IGNORE_PREFETCHABLE_MEMORY_AT_ROOT_HACK 0x00000001
  82. //
  83. // Video Hacks
  84. //
  85. #define PCI_S3_HACKS 1
  86. #define PCI_CIRRUS_54XX_HACK 1
  87. #define PCI_IS_ATI_M1(_PdoExtension) \
  88. ((_PdoExtension)->VendorId == 0x1002 \
  89. && ((_PdoExtension)->DeviceId == 0x4C42 \
  90. || (_PdoExtension)->DeviceId == 0x4C44 \
  91. || (_PdoExtension)->DeviceId == 0x4C49 \
  92. || (_PdoExtension)->DeviceId == 0x4C4D \
  93. || (_PdoExtension)->DeviceId == 0x4C4E \
  94. || (_PdoExtension)->DeviceId == 0x4C50 \
  95. || (_PdoExtension)->DeviceId == 0x4C51 \
  96. || (_PdoExtension)->DeviceId == 0x4C52 \
  97. || (_PdoExtension)->DeviceId == 0x4C53))
  98. #define INTEL_ICH_HACKS 1
  99. #if INTEL_ICH_HACKS
  100. #define PCI_IS_INTEL_ICH(_PdoExtension) \
  101. ((_PdoExtension)->VendorId == 0x8086 \
  102. && ((_PdoExtension)->DeviceId == 0x2418 \
  103. || (_PdoExtension)->DeviceId == 0x2428 \
  104. || (_PdoExtension)->DeviceId == 0x244E \
  105. || (_PdoExtension)->DeviceId == 0x2448))
  106. #else
  107. #define PCI_IS_INTEL_ICH(_PdoExtension) FALSE
  108. #endif
  109. //
  110. // Translatable resources
  111. //
  112. #define ADDRESS_SPACE_MEMORY 0x0
  113. #define ADDRESS_SPACE_PORT 0x1
  114. #define ADDRESS_SPACE_USER_MEMORY 0x2
  115. #define ADDRESS_SPACE_USER_PORT 0x3
  116. #define ADDRESS_SPACE_DENSE_MEMORY 0x4
  117. #define ADDRESS_SPACE_USER_DENSE_MEMORY 0x6
  118. //
  119. // Add our tag signature
  120. //
  121. #ifdef ExAllocatePool
  122. #undef ExAllocatePool
  123. #endif
  124. #define ExAllocatePool( t, s ) ExAllocatePoolWithTag( (t), (s), 'BicP' )
  125. //
  126. // Lock and Unlock
  127. //
  128. typedef struct _PCI_LOCK {
  129. KSPIN_LOCK Atom;
  130. KIRQL OldIrql;
  131. #if DBG
  132. PUCHAR File;
  133. ULONG Line;
  134. #endif
  135. } PCI_LOCK, *PPCI_LOCK;
  136. #if DBG
  137. #define PCI_LOCK_OBJECT(x) \
  138. (x)->Lock.File = __FILE__, \
  139. (x)->Lock.Line = __LINE__, \
  140. KeAcquireSpinLock(&(x)->Lock.Atom, &(x)->Lock.OldIrql)
  141. #else
  142. #define PCI_LOCK_OBJECT(x) \
  143. KeAcquireSpinLock(&(x)->Lock.Atom, &(x)->Lock.OldIrql)
  144. #endif
  145. #define PCI_UNLOCK_OBJECT(x) \
  146. KeReleaseSpinLock(&(x)->Lock.Atom, (x)->Lock.OldIrql)
  147. #define PciAcquireGlobalLock() \
  148. ExAcquireFastMutex(&PciGlobalLock)
  149. #define PciReleaseGlobalLock() \
  150. ExReleaseFastMutex(&PciGlobalLock)
  151. //
  152. // PCM_PARTIAL_RESOURCE_DESCRIPTOR
  153. // PciFirstCmResource(
  154. // PCM_RESOURCE_LIST List
  155. // )
  156. //
  157. // Routine Description:
  158. //
  159. // Returns the address of the first CM PARTIAL RESOURCE DESCRIPTOR
  160. // in the given CM RESOURCE LIST.
  161. //
  162. #define PciFirstCmResource(x) \
  163. (x)->List[0].PartialResourceList.PartialDescriptors
  164. //
  165. // ULONG
  166. // PciGetConfigurationType(
  167. // PPCI_COMMON_CONFIG x
  168. // )
  169. //
  170. // Routine Description:
  171. //
  172. // Returns the configuration type subfield from the HeaderType
  173. // field in PCI Configuration Space.
  174. //
  175. #define PciGetConfigurationType(x) PCI_CONFIGURATION_TYPE(x)
  176. //
  177. // PPCI_FDO_EXTENSION
  178. // PCI_PARENT_FDO(
  179. // PPCI_PDO_EXTENSION x
  180. // )
  181. //
  182. // Routine Description:
  183. //
  184. // Returns a pointer to the FDO extension that created PDO x as a result
  185. // of enumeration. That is, the FDO extension of the bus that owns this
  186. // device.
  187. //
  188. #define PCI_PARENT_FDOX(x) ((x)->ParentFdoExtension)
  189. //
  190. // PPCI_FDO_EXTENSION
  191. // PCI_ROOT_FDOX(
  192. // PPCI_PDO_EXTENSION x
  193. // )
  194. //
  195. // Routine Description:
  196. //
  197. // Returns a pointer to the FDO extension for the root bus (CPU-PCI Bridge)
  198. // that this device is situated under.
  199. //
  200. #define PCI_ROOT_FDOX(x) ((x)->ParentFdoExtension->BusRootFdoExtension)
  201. //
  202. // PDEVICE_OBJECT
  203. // PCI_PARENT_PDO(
  204. // PPCI_PDO_EXTENSION x
  205. // )
  206. //
  207. // Routine Description:
  208. //
  209. // Returns a pointer to the PDO for the parent bus.
  210. //
  211. #define PCI_PARENT_PDO(x) ((x)->ParentFdoExtension->PhysicalDeviceObject)
  212. //
  213. // PPCI_PDO_EXTENSION
  214. // PCI_BRIDGE_PDO(
  215. // PPCI_FDO_EXTENSION x
  216. // )
  217. //
  218. // Routine Description:
  219. //
  220. // Returns a pointer to the PDO for the bridge given its FDO
  221. //
  222. #define PCI_BRIDGE_PDO(x) ((PPCI_PDO_EXTENSION)((x)->PhysicalDeviceObject->DeviceExtension))
  223. //
  224. // PPCI_FDO_EXTENSION
  225. // PCI_BRIDGE_FDO(
  226. // PPCI_PDO_EXTENSION x
  227. // )
  228. //
  229. // Routine Description:
  230. //
  231. // Returns a pointer to the FDO for the bridge given its PDO
  232. //
  233. #define PCI_BRIDGE_FDO(x) ((PPCI_FDO_EXTENSION)((x)->BridgeFdoExtension))
  234. //
  235. // BOOLEAN
  236. // PCI_IS_ROOT_FDO(
  237. // PPCI_FDO_EXTENSION x
  238. // )
  239. //
  240. // Routine Description:
  241. //
  242. // Returns TRUE if x is an FDO for a PCI ROOT bus.
  243. //
  244. #define PCI_IS_ROOT_FDO(x) ((BOOLEAN)((x) == (x)->BusRootFdoExtension))
  245. //
  246. // BOOLEAN
  247. // PCI_PDO_ON_ROOT(
  248. // PPCI_PDO_EXTENSION x
  249. // )
  250. //
  251. // Routine Description:
  252. //
  253. #define PCI_PDO_ON_ROOT(x) ((BOOLEAN)PCI_IS_ROOT_FDO(PCI_PARENT_FDOX(x)))
  254. //
  255. // UCHAR
  256. // PCI_DEVFUNC(
  257. // PPCI_PDO_EXTENSION x
  258. // )
  259. //
  260. // Routine Description:
  261. //
  262. // Returns the 5 bit device number and 3 bit function number for this
  263. // device as a single 8 bit quantity.
  264. //
  265. #define PCI_DEVFUNC(x) (((x)->Slot.u.bits.DeviceNumber << 3) | \
  266. (x)->Slot.u.bits.FunctionNumber)
  267. //
  268. //
  269. // VOID
  270. // PciConstStringToUnicodeString(
  271. // OUT PUNICODE_STRING u,
  272. // IN PCWSTR p
  273. // )
  274. //
  275. //
  276. #define PciConstStringToUnicodeString(u, p) \
  277. (u)->Length = ((u)->MaximumLength = sizeof((p))) - sizeof(WCHAR); \
  278. (u)->Buffer = (p)
  279. //
  280. // Name of the volative key under the DeviceParameters key where data that needs
  281. // to be persistent accross removes, but NOT reboots is stored
  282. //
  283. #define BIOS_CONFIG_KEY_NAME L"BiosConfig"
  284. //
  285. // Assert this is a device object created by PCI
  286. //
  287. #define ASSERT_PCI_DEVICE_OBJECT(_DeviceObject) \
  288. PCI_ASSERT((_DeviceObject)->DriverObject == PciDriverObject)
  289. #define ASSERT_MUTEX_HELD(x)
  290. //
  291. // IRPs can be handled the following ways
  292. //
  293. typedef enum _PCI_DISPATCH_STYLE {
  294. IRP_COMPLETE, // Complete IRP, adjust status as neccessary
  295. IRP_DOWNWARD, // Dispatch on the way down, adjust status as neccessary
  296. IRP_UPWARD, // Dispatch on the way up, adjust status as neccessary
  297. IRP_DISPATCH // Dispatch downward, don't touch afterwards
  298. } PCI_DISPATCH_STYLE;
  299. //
  300. // The following routines are dispatched to depending on header type.
  301. //
  302. typedef
  303. VOID
  304. (*PMASSAGEHEADERFORLIMITSDETERMINATION)(
  305. IN struct _PCI_CONFIGURABLE_OBJECT *This
  306. );
  307. typedef
  308. VOID
  309. (*PSAVELIMITS)(
  310. IN struct _PCI_CONFIGURABLE_OBJECT *This
  311. );
  312. typedef
  313. VOID
  314. (*PSAVECURRENTSETTINGS)(
  315. IN struct _PCI_CONFIGURABLE_OBJECT *This
  316. );
  317. typedef
  318. VOID
  319. (*PRESTORECURRENT)(
  320. IN struct _PCI_CONFIGURABLE_OBJECT *This
  321. );
  322. typedef
  323. VOID
  324. (*PCHANGERESOURCESETTINGS)(
  325. IN struct _PCI_PDO_EXTENSION * PdoExtension,
  326. IN PPCI_COMMON_CONFIG CommonConfig
  327. );
  328. typedef
  329. VOID
  330. (*PGETADDITIONALRESOURCEDESCRIPTORS)(
  331. IN struct _PCI_PDO_EXTENSION * PdoExtension,
  332. IN PPCI_COMMON_CONFIG CommonConfig,
  333. IN PIO_RESOURCE_DESCRIPTOR Resource
  334. );
  335. typedef
  336. NTSTATUS
  337. (*PRESETDEVICE)(
  338. IN struct _PCI_PDO_EXTENSION * PdoExtension,
  339. IN PPCI_COMMON_CONFIG CommonConfig
  340. );
  341. typedef struct {
  342. PMASSAGEHEADERFORLIMITSDETERMINATION MassageHeaderForLimitsDetermination;
  343. PRESTORECURRENT RestoreCurrent;
  344. PSAVELIMITS SaveLimits;
  345. PSAVECURRENTSETTINGS SaveCurrentSettings;
  346. PCHANGERESOURCESETTINGS ChangeResourceSettings;
  347. PGETADDITIONALRESOURCEDESCRIPTORS GetAdditionalResourceDescriptors;
  348. PRESETDEVICE ResetDevice;
  349. } PCI_CONFIGURATOR, *PPCI_CONFIGURATOR;
  350. //
  351. // Internal structure definitions follow
  352. //
  353. typedef enum {
  354. PciBridgeIo = 0x10,
  355. PciBridgeMem,
  356. PciBridgePrefetch,
  357. PciBridgeMaxPassThru
  358. } PCI_BRIDGE_PASSTHRU;
  359. typedef enum {
  360. //
  361. // Device Object Extension Types
  362. //
  363. PciPdoExtensionType = 'icP0',
  364. PciFdoExtensionType,
  365. //
  366. // Arbitration Types. (These are also secondary extensions).
  367. //
  368. PciArb_Io,
  369. PciArb_Memory,
  370. PciArb_Interrupt,
  371. PciArb_BusNumber,
  372. //
  373. // Translation Types. (These are also secondary extensions).
  374. //
  375. PciTrans_Interrupt,
  376. //
  377. // Other exposed interfaces.
  378. //
  379. PciInterface_BusHandler,
  380. PciInterface_IntRouteHandler,
  381. PciInterface_PciCb,
  382. PciInterface_LegacyDeviceDetection,
  383. PciInterface_PmeHandler,
  384. PciInterface_DevicePresent,
  385. PciInterface_NativeIde,
  386. PciInterface_Location,
  387. PciInterface_AgpTarget
  388. } PCI_SIGNATURE;
  389. #define PCI_EXTENSIONTYPE_FDO PciFdoExtensionType
  390. #define PCI_EXTENSIONTYPE_PDO PciPdoExtensionType
  391. typedef enum {
  392. PciTypeUnknown,
  393. PciTypeHostBridge,
  394. PciTypePciBridge,
  395. PciTypeCardbusBridge,
  396. PciTypeDevice
  397. } PCI_OBJECT_TYPE;
  398. typedef enum {
  399. PciPrivateUndefined,
  400. PciPrivateBar,
  401. PciPrivateIsaBar,
  402. PciPrivateSkipList
  403. } PCI_PRIVATE_RESOURCE_TYPES;
  404. typedef
  405. VOID
  406. (*PSECONDARYEXTENSIONDESTRUCTOR)(
  407. IN PVOID Extension
  408. );
  409. typedef struct {
  410. SINGLE_LIST_ENTRY List;
  411. PCI_SIGNATURE ExtensionType;
  412. PSECONDARYEXTENSIONDESTRUCTOR Destructor;
  413. } PCI_SECONDARY_EXTENSION, *PPCI_SECONDARY_EXTENSION;
  414. //
  415. // Define a structure to contain current and limit settings
  416. // for any (currently defined) PCI header type.
  417. //
  418. // Currently type 0 defines the greatest number of possible
  419. // resources but we shall do it programmatically anyway.
  420. //
  421. // Type 0 and type 1 also have a ROM base address, additionally,
  422. // type 1 has three ranges that aren't included in its address
  423. // count but should be.
  424. //
  425. #define PCI_TYPE0_RANGE_COUNT ((PCI_TYPE0_ADDRESSES) + 1)
  426. #define PCI_TYPE1_RANGE_COUNT ((PCI_TYPE1_ADDRESSES) + 4)
  427. #define PCI_TYPE2_RANGE_COUNT ((PCI_TYPE2_ADDRESSES) + 1)
  428. #if PCI_TYPE0_RANGE_COUNT > PCI_TYPE1_RANGE_COUNT
  429. #if PCI_TYPE0_RANGE_COUNT > PCI_TYPE2_RANGE_COUNT
  430. #define PCI_MAX_RANGE_COUNT PCI_TYPE0_RANGE_COUNT
  431. #else
  432. #define PCI_MAX_RANGE_COUNT PCI_TYPE2_RANGE_COUNT
  433. #endif
  434. #else
  435. #if PCI_TYPE1_RANGE_COUNT > PCI_TYPE2_RANGE_COUNT
  436. #define PCI_MAX_RANGE_COUNT PCI_TYPE1_RANGE_COUNT
  437. #else
  438. #define PCI_MAX_RANGE_COUNT PCI_TYPE2_RANGE_COUNT
  439. #endif
  440. #endif
  441. typedef union {
  442. struct {
  443. UCHAR Spare[4];
  444. } type0;
  445. struct {
  446. UCHAR PrimaryBus;
  447. UCHAR SecondaryBus;
  448. UCHAR SubordinateBus;
  449. BOOLEAN SubtractiveDecode:1;
  450. BOOLEAN IsaBitSet:1;
  451. BOOLEAN VgaBitSet:1;
  452. BOOLEAN WeChangedBusNumbers:1;
  453. BOOLEAN IsaBitRequired:1;
  454. } type1;
  455. struct {
  456. UCHAR PrimaryBus;
  457. UCHAR SecondaryBus;
  458. UCHAR SubordinateBus;
  459. BOOLEAN SubtractiveDecode:1;
  460. BOOLEAN IsaBitSet:1;
  461. BOOLEAN VgaBitSet:1;
  462. BOOLEAN WeChangedBusNumbers:1;
  463. BOOLEAN IsaBitRequired:1;
  464. } type2;
  465. } PCI_HEADER_TYPE_DEPENDENT;
  466. typedef struct {
  467. IO_RESOURCE_DESCRIPTOR Limit[PCI_MAX_RANGE_COUNT];
  468. CM_PARTIAL_RESOURCE_DESCRIPTOR Current[PCI_MAX_RANGE_COUNT];
  469. } PCI_FUNCTION_RESOURCES, *PPCI_FUNCTION_RESOURCES;
  470. //
  471. // Indices for the PCI_FUNCTION_RESOURCES arrays for different header types
  472. //
  473. #define PCI_DEVICE_BAR_0 0
  474. #define PCI_DEVICE_BAR_1 1
  475. #define PCI_DEVICE_BAR_2 2
  476. #define PCI_DEVICE_BAR_3 3
  477. #define PCI_DEVICE_BAR_4 4
  478. #define PCI_DEVICE_BAR_5 5
  479. #define PCI_DEVICE_BAR_ROM 6
  480. #define PCI_BRIDGE_BAR_0 0
  481. #define PCI_BRIDGE_BAR_1 1
  482. #define PCI_BRIDGE_IO_WINDOW 2
  483. #define PCI_BRIDGE_MEMORY_WINDOW 3
  484. #define PCI_BRIDGE_PREFETCH_WINDOW 4
  485. #define PCI_BRIDGE_BAR_ROM 5
  486. #define PCI_CARDBUS_SOCKET_BAR 0
  487. #define PCI_CARDBUS_MEMORY_WINDOW_0 1
  488. #define PCI_CARDBUS_MEMORY_WINDOW_1 2
  489. #define PCI_CARDBUS_IO_WINDOW_0 3
  490. #define PCI_CARDBUS_IO_WINDOW_1 4
  491. #define PCI_CARDBUS_LEGACY_BAR 5 // Not used
  492. typedef struct {
  493. ULONGLONG Total;
  494. ULONG Alignment;
  495. } PCI_RESOURCE_ACCUMULATOR, *PPCI_RESOURCE_ACCUMULATOR;
  496. typedef struct {
  497. SYSTEM_POWER_STATE CurrentSystemState;
  498. DEVICE_POWER_STATE CurrentDeviceState;
  499. SYSTEM_POWER_STATE SystemWakeLevel;
  500. DEVICE_POWER_STATE DeviceWakeLevel;
  501. DEVICE_POWER_STATE SystemStateMapping[PowerSystemMaximum];
  502. PIRP WaitWakeIrp;
  503. PDRIVER_CANCEL SavedCancelRoutine;
  504. // device usage...
  505. LONG Paging;
  506. LONG Hibernate;
  507. LONG CrashDump;
  508. } PCI_POWER_STATE, *PPCI_POWER_STATE;
  509. typedef struct _PCI_PDO_EXTENSION *PPCI_PDO_EXTENSION;
  510. typedef struct _PCI_FDO_EXTENSION *PPCI_FDO_EXTENSION;
  511. typedef struct _PCI_COMMON_EXTENSION *PPCI_COMMON_EXTENSION;
  512. //
  513. // This is an Irp Dispatch Handler for PCI
  514. //
  515. typedef NTSTATUS (*PCI_MN_DISPATCH_FUNCTION) (
  516. IN PIRP Irp,
  517. IN PIO_STACK_LOCATION IrpSp,
  518. IN PPCI_COMMON_EXTENSION DeviceExtension
  519. );
  520. typedef struct _PCI_MN_DISPATCH_TABLE {
  521. PCI_DISPATCH_STYLE DispatchStyle;
  522. PCI_MN_DISPATCH_FUNCTION DispatchFunction;
  523. } PCI_MN_DISPATCH_TABLE, *PPCI_MN_DISPATCH_TABLE;
  524. //
  525. // This is a table that contains everything neccessary to handle Power, PnP,
  526. // and other IRPs.
  527. //
  528. typedef struct _PCI_MJ_DISPATCH_TABLE {
  529. ULONG PnpIrpMaximumMinorFunction;
  530. PPCI_MN_DISPATCH_TABLE PnpIrpDispatchTable;
  531. ULONG PowerIrpMaximumMinorFunction;
  532. PPCI_MN_DISPATCH_TABLE PowerIrpDispatchTable;
  533. PCI_DISPATCH_STYLE SystemControlIrpDispatchStyle;
  534. PCI_MN_DISPATCH_FUNCTION SystemControlIrpDispatchFunction;
  535. PCI_DISPATCH_STYLE OtherIrpDispatchStyle;
  536. PCI_MN_DISPATCH_FUNCTION OtherIrpDispatchFunction;
  537. } PCI_MJ_DISPATCH_TABLE, *PPCI_MJ_DISPATCH_TABLE;
  538. typedef
  539. VOID
  540. (*PCRITICALROUTINE)(
  541. IN PVOID Extension,
  542. IN PVOID Context
  543. );
  544. typedef struct _PCI_CRITICAL_ROUTINE_CONTEXT {
  545. volatile LONG Gate;
  546. volatile LONG Barrier;
  547. PCRITICALROUTINE Routine;
  548. PVOID Extension;
  549. PVOID Context;
  550. } PCI_CRITICAL_ROUTINE_CONTEXT, *PPCI_CRITICAL_ROUTINE_CONTEXT;
  551. //
  552. // Structure used for storing MSI routing info
  553. // in the PDO extention.
  554. //
  555. typedef struct _PCI_MSI_INFO {
  556. ULONG_PTR MessageAddress;
  557. UCHAR CapabilityOffset;
  558. USHORT MessageData;
  559. } PCI_MSI_INFO, *PPCI_MSI_INFO;
  560. //
  561. // This much must be common to both the PDO and FDO extensions.
  562. //
  563. typedef struct _PCI_COMMON_EXTENSION {
  564. PVOID Next;
  565. PCI_SIGNATURE ExtensionType;
  566. PPCI_MJ_DISPATCH_TABLE IrpDispatchTable;
  567. UCHAR DeviceState;
  568. UCHAR TentativeNextState;
  569. FAST_MUTEX SecondaryExtMutex;
  570. } PCI_COMMON_EXTENSION;
  571. typedef struct _PCI_PDO_EXTENSION{
  572. PPCI_PDO_EXTENSION Next;
  573. PCI_SIGNATURE ExtensionType;
  574. PPCI_MJ_DISPATCH_TABLE IrpDispatchTable;
  575. UCHAR DeviceState;
  576. UCHAR TentativeNextState;
  577. FAST_MUTEX SecondaryExtMutex;
  578. PCI_SLOT_NUMBER Slot;
  579. PDEVICE_OBJECT PhysicalDeviceObject;
  580. PPCI_FDO_EXTENSION ParentFdoExtension;
  581. SINGLE_LIST_ENTRY SecondaryExtension;
  582. ULONG BusInterfaceReferenceCount;
  583. ULONG AgpInterfaceReferenceCount;
  584. USHORT VendorId;
  585. USHORT DeviceId;
  586. USHORT SubsystemVendorId;
  587. USHORT SubsystemId;
  588. UCHAR RevisionId;
  589. UCHAR ProgIf;
  590. UCHAR SubClass;
  591. UCHAR BaseClass;
  592. UCHAR AdditionalResourceCount;
  593. UCHAR AdjustedInterruptLine;
  594. UCHAR InterruptPin;
  595. UCHAR RawInterruptLine;
  596. UCHAR CapabilitiesPtr;
  597. UCHAR SavedLatencyTimer;
  598. UCHAR SavedCacheLineSize;
  599. UCHAR HeaderType;
  600. BOOLEAN NotPresent;
  601. BOOLEAN ReportedMissing;
  602. BOOLEAN ExpectedWritebackFailure;
  603. BOOLEAN NoTouchPmeEnable;
  604. BOOLEAN LegacyDriver;
  605. BOOLEAN UpdateHardware;
  606. BOOLEAN MovedDevice;
  607. BOOLEAN DisablePowerDown;
  608. BOOLEAN NeedsHotPlugConfiguration;
  609. BOOLEAN IDEInNativeMode;
  610. BOOLEAN BIOSAllowsIDESwitchToNativeMode; // NATA method said it was OK
  611. BOOLEAN IoSpaceUnderNativeIdeControl;
  612. BOOLEAN OnDebugPath; // Includes headless port
  613. #if MSI_SUPPORTED
  614. BOOLEAN CapableMSI;
  615. PCI_MSI_INFO MsiInfo;
  616. #endif // MSI_SUPPORTED
  617. PCI_POWER_STATE PowerState;
  618. PCI_HEADER_TYPE_DEPENDENT Dependent;
  619. ULONGLONG HackFlags;
  620. PPCI_FUNCTION_RESOURCES Resources;
  621. PPCI_FDO_EXTENSION BridgeFdoExtension;
  622. PPCI_PDO_EXTENSION NextBridge;
  623. PPCI_PDO_EXTENSION NextHashEntry;
  624. PCI_LOCK Lock;
  625. PCI_PMC PowerCapabilities;
  626. UCHAR TargetAgpCapabilityId;
  627. USHORT CommandEnables; // What we want to enable for this device
  628. USHORT InitialCommand; // How we found the command register
  629. } PCI_PDO_EXTENSION;
  630. #define ASSERT_PCI_PDO_EXTENSION(x) \
  631. PCI_ASSERT((x)->ExtensionType == PciPdoExtensionType)
  632. typedef struct _PCI_FDO_EXTENSION{
  633. SINGLE_LIST_ENTRY List; // List of pci.sys's FDOs
  634. PCI_SIGNATURE ExtensionType; // PciFdoExtensionType
  635. PPCI_MJ_DISPATCH_TABLE IrpDispatchTable; // Irp Dispatch Table to use.
  636. UCHAR DeviceState;
  637. UCHAR TentativeNextState;
  638. FAST_MUTEX SecondaryExtMutex;
  639. PDEVICE_OBJECT PhysicalDeviceObject; // PDO passed into AddDevice()
  640. PDEVICE_OBJECT FunctionalDeviceObject;// FDO that points here
  641. PDEVICE_OBJECT AttachedDeviceObject; // next DO in chain.
  642. FAST_MUTEX ChildListMutex;
  643. PPCI_PDO_EXTENSION ChildPdoList;
  644. PPCI_FDO_EXTENSION BusRootFdoExtension; // points to top of this tree
  645. PPCI_FDO_EXTENSION ParentFdoExtension; // points to the parent bridge
  646. PPCI_PDO_EXTENSION ChildBridgePdoList;
  647. PPCI_BUS_INTERFACE_STANDARD PciBusInterface; // Only for a root
  648. UCHAR MaxSubordinateBus; // Only for a root
  649. PBUS_HANDLER BusHandler;
  650. UCHAR BaseBus; // Bus number for THIS bus
  651. BOOLEAN Fake; // True if not a real FDOx
  652. BOOLEAN Scanned; // True is bus enumerated
  653. BOOLEAN ArbitersInitialized;
  654. BOOLEAN BrokenVideoHackApplied;
  655. BOOLEAN Hibernated;
  656. PCI_POWER_STATE PowerState;
  657. SINGLE_LIST_ENTRY SecondaryExtension;
  658. ULONG ChildWaitWakeCount;
  659. #if INTEL_ICH_HACKS
  660. PPCI_COMMON_CONFIG IchHackConfig;
  661. #endif
  662. PCI_LOCK Lock;
  663. //
  664. // Information from ACPI _HPP to apply to hot plugged cards,
  665. // Acquired indicates the rest are valid.
  666. //
  667. struct {
  668. BOOLEAN Acquired;
  669. UCHAR CacheLineSize;
  670. UCHAR LatencyTimer;
  671. BOOLEAN EnablePERR;
  672. BOOLEAN EnableSERR;
  673. } HotPlugParameters;
  674. ULONG BusHackFlags; // see PCI_BUS_HACK_*
  675. } PCI_FDO_EXTENSION;
  676. #define ASSERT_PCI_FDO_EXTENSION(x) \
  677. PCI_ASSERT((x)->ExtensionType == PciFdoExtensionType)
  678. typedef struct _PCI_CONFIGURABLE_OBJECT {
  679. PPCI_PDO_EXTENSION PdoExtension;
  680. PPCI_COMMON_CONFIG Current;
  681. PPCI_COMMON_CONFIG Working;
  682. PPCI_CONFIGURATOR Configurator;
  683. ULONG PrivateData;
  684. USHORT Status;
  685. USHORT Command;
  686. } PCI_CONFIGURABLE_OBJECT, *PPCI_CONFIGURABLE_OBJECT;
  687. typedef struct _PCI_ASSIGNED_RESOURCE_EXTENSION {
  688. ULONG ResourceIdentifier;
  689. } PCI_ASSIGNED_RESOURCE_EXTENSION, *PPCI_ASSIGNED_RESOURCE_EXTENSION;
  690. //
  691. // The PCI_COMMON_CONFIG includes the 192 bytes of device specific
  692. // data. The following structure is used to get only the first 64
  693. // bytes which is all we care about most of the time anyway. We cast
  694. // to PCI_COMMON_CONFIG to get at the actual fields.
  695. //
  696. typedef struct {
  697. ULONG Reserved[PCI_COMMON_HDR_LENGTH/sizeof(ULONG)];
  698. } PCI_COMMON_HEADER, *PPCI_COMMON_HEADER;
  699. //
  700. // In order to be able to arbitrate interrupts for device with
  701. // legacy drivers, we have to do some bookkeeping.
  702. //
  703. typedef struct {
  704. SINGLE_LIST_ENTRY List;
  705. PDEVICE_OBJECT LegacyDeviceObject;
  706. ULONG Bus;
  707. ULONG PciSlot;
  708. UCHAR InterruptLine;
  709. UCHAR InterruptPin;
  710. UCHAR ClassCode;
  711. UCHAR SubClassCode;
  712. PDEVICE_OBJECT ParentPdo;
  713. ROUTING_TOKEN RoutingToken;
  714. PPCI_PDO_EXTENSION PdoExtension;
  715. } LEGACY_DEVICE, *PLEGACY_DEVICE;
  716. extern PLEGACY_DEVICE PciLegacyDeviceHead;
  717. #define PCI_HACK_FLAG_SUBSYSTEM 0x01
  718. #define PCI_HACK_FLAG_REVISION 0x02
  719. typedef struct _PCI_HACK_TABLE_ENTRY {
  720. USHORT VendorID;
  721. USHORT DeviceID;
  722. USHORT SubVendorID;
  723. USHORT SubSystemID;
  724. ULONGLONG HackFlags;
  725. UCHAR RevisionID;
  726. UCHAR Flags;
  727. } PCI_HACK_TABLE_ENTRY, *PPCI_HACK_TABLE_ENTRY;
  728. typedef struct _ARBITER_MEMORY_EXTENSION {
  729. //
  730. // Indicates that this arbiter will arbitrate prefetchable memory
  731. //
  732. BOOLEAN PrefetchablePresent;
  733. //
  734. // Indicates that this arbiter has been initialized
  735. //
  736. BOOLEAN Initialized;
  737. //
  738. // The number of prefetchable ranges
  739. //
  740. USHORT PrefetchableCount;
  741. //
  742. // The allocation ordering list to be used for prefetchable memory
  743. //
  744. ARBITER_ORDERING_LIST PrefetchableOrdering;
  745. //
  746. // The allocation ordering list to be used for standard memory
  747. //
  748. ARBITER_ORDERING_LIST NonprefetchableOrdering;
  749. //
  750. // The original memory allocation ordering (from the registry)
  751. //
  752. ARBITER_ORDERING_LIST OriginalOrdering;
  753. } ARBITER_MEMORY_EXTENSION, *PARBITER_MEMORY_EXTENSION;
  754. NTSTATUS
  755. PciCacheLegacyDeviceRouting(
  756. IN PDEVICE_OBJECT LegacyDO,
  757. IN ULONG Bus,
  758. IN ULONG PciSlot,
  759. IN UCHAR InterruptLine,
  760. IN UCHAR InterruptPin,
  761. IN UCHAR ClassCode,
  762. IN UCHAR SubClassCode,
  763. IN PDEVICE_OBJECT ParentPdo,
  764. IN PPCI_PDO_EXTENSION PdoExtension,
  765. OUT PDEVICE_OBJECT *OldLegacyDO
  766. );
  767. //
  768. // Global data declarations follow
  769. //
  770. extern PDRIVER_OBJECT PciDriverObject;
  771. extern UNICODE_STRING PciServiceRegistryPath;
  772. extern SINGLE_LIST_ENTRY PciFdoExtensionListHead;
  773. extern FAST_MUTEX PciGlobalLock;
  774. extern FAST_MUTEX PciBusLock;
  775. extern LONG PciRootBusCount;
  776. extern BOOLEAN PciAssignBusNumbers;
  777. extern PPCI_FDO_EXTENSION PciRootExtensions;
  778. extern RTL_RANGE_LIST PciIsaBitExclusionList;
  779. extern RTL_RANGE_LIST PciVgaAndIsaBitExclusionList;
  780. extern ULONG PciSystemWideHackFlags;
  781. extern ULONG PciEnableNativeModeATA;
  782. extern PPCI_HACK_TABLE_ENTRY PciHackTable;
  783. extern BOOLEAN PciRunningDatacenter;
  784. //
  785. // Watchdog timer resource table
  786. //
  787. extern PWATCHDOG_TIMER_RESOURCE_TABLE WdTable;
  788. // arb_comn.h
  789. #define INSTANCE_NAME_LENGTH 24
  790. typedef struct _PCI_ARBITER_INSTANCE {
  791. //
  792. // Standard secondary extension header
  793. //
  794. PCI_SECONDARY_EXTENSION Header;
  795. //
  796. // Back pointer to the interface we are a context of
  797. //
  798. struct _PCI_INTERFACE *Interface;
  799. //
  800. // Pointer to owning device object (extension).
  801. //
  802. PPCI_FDO_EXTENSION BusFdoExtension;
  803. //
  804. // Arbiter description.
  805. //
  806. WCHAR InstanceName[INSTANCE_NAME_LENGTH];
  807. //
  808. // The common instance data
  809. //
  810. ARBITER_INSTANCE CommonInstance;
  811. } PCI_ARBITER_INSTANCE, *PPCI_ARBITER_INSTANCE;
  812. NTSTATUS
  813. PciArbiterInitializeInterface(
  814. IN PVOID DeviceExtension,
  815. IN PCI_SIGNATURE DesiredInterface,
  816. IN OUT PARBITER_INTERFACE ArbiterInterface
  817. );
  818. NTSTATUS
  819. PciInitializeArbiterRanges(
  820. IN PPCI_FDO_EXTENSION FdoExtension,
  821. IN PCM_RESOURCE_LIST ResourceList
  822. );
  823. NTSTATUS
  824. PciInitializeArbiters(
  825. IN PVOID DeviceExtension
  826. );
  827. VOID
  828. PciReferenceArbiter(
  829. IN PVOID Context
  830. );
  831. VOID
  832. PciDereferenceArbiter(
  833. IN PVOID Context
  834. );
  835. VOID
  836. ario_ApplyBrokenVideoHack(
  837. IN PPCI_FDO_EXTENSION FdoExtension
  838. );
  839. // busno.h
  840. BOOLEAN
  841. PciAreBusNumbersConfigured(
  842. IN PPCI_PDO_EXTENSION Bridge
  843. );
  844. VOID
  845. PciConfigureBusNumbers(
  846. PPCI_FDO_EXTENSION Parent
  847. );
  848. VOID
  849. PciSetBusNumbers(
  850. IN PPCI_PDO_EXTENSION PdoExtension,
  851. IN UCHAR Primary,
  852. IN UCHAR Secondary,
  853. IN UCHAR Subordinate
  854. );
  855. // cardbus.h
  856. VOID
  857. Cardbus_MassageHeaderForLimitsDetermination(
  858. IN PPCI_CONFIGURABLE_OBJECT This
  859. );
  860. VOID
  861. Cardbus_RestoreCurrent(
  862. IN PPCI_CONFIGURABLE_OBJECT This
  863. );
  864. VOID
  865. Cardbus_SaveLimits(
  866. IN PPCI_CONFIGURABLE_OBJECT This
  867. );
  868. VOID
  869. Cardbus_SaveCurrentSettings(
  870. IN PPCI_CONFIGURABLE_OBJECT This
  871. );
  872. VOID
  873. Cardbus_ChangeResourceSettings(
  874. IN PPCI_PDO_EXTENSION PdoExtension,
  875. IN PPCI_COMMON_CONFIG CommonConfig
  876. );
  877. VOID
  878. Cardbus_GetAdditionalResourceDescriptors(
  879. IN PPCI_PDO_EXTENSION PdoExtension,
  880. IN PPCI_COMMON_CONFIG CommonConfig,
  881. IN PIO_RESOURCE_DESCRIPTOR Resource
  882. );
  883. NTSTATUS
  884. Cardbus_ResetDevice(
  885. IN PPCI_PDO_EXTENSION PdoExtension,
  886. IN PPCI_COMMON_CONFIG CommonConfig
  887. );
  888. // config.h
  889. VOID
  890. PciReadDeviceConfig(
  891. IN PPCI_PDO_EXTENSION Pdo,
  892. IN PVOID Buffer,
  893. IN ULONG Offset,
  894. IN ULONG Length
  895. );
  896. VOID
  897. PciWriteDeviceConfig(
  898. IN PPCI_PDO_EXTENSION Pdo,
  899. IN PVOID Buffer,
  900. IN ULONG Offset,
  901. IN ULONG Length
  902. );
  903. VOID
  904. PciReadSlotConfig(
  905. IN PPCI_FDO_EXTENSION ParentFdo,
  906. IN PCI_SLOT_NUMBER SlotNumber,
  907. IN PVOID Buffer,
  908. IN ULONG Offset,
  909. IN ULONG Length
  910. );
  911. VOID
  912. PciWriteSlotConfig(
  913. IN PPCI_FDO_EXTENSION ParentFdo,
  914. IN PCI_SLOT_NUMBER SlotNumber,
  915. IN PVOID Buffer,
  916. IN ULONG Offset,
  917. IN ULONG Length
  918. );
  919. UCHAR
  920. PciGetAdjustedInterruptLine(
  921. IN PPCI_PDO_EXTENSION Pdo
  922. );
  923. NTSTATUS
  924. PciExternalReadDeviceConfig(
  925. IN PPCI_PDO_EXTENSION Pdo,
  926. IN PVOID Buffer,
  927. IN ULONG Offset,
  928. IN ULONG Length
  929. );
  930. NTSTATUS
  931. PciExternalWriteDeviceConfig(
  932. IN PPCI_PDO_EXTENSION Pdo,
  933. IN PVOID Buffer,
  934. IN ULONG Offset,
  935. IN ULONG Length
  936. );
  937. NTSTATUS
  938. PciGetConfigHandlers(
  939. IN PPCI_FDO_EXTENSION FdoExtension
  940. );
  941. //
  942. // Macros to access common registers in config space
  943. //
  944. //
  945. // VOID
  946. // PciGetCommandRegister(
  947. // PPCI_PDO_EXTENSION _PdoExt,
  948. // PUSHORT _Command
  949. // );
  950. //
  951. #define PciGetCommandRegister(_PdoExt, _Command) \
  952. PciReadDeviceConfig((_PdoExt), \
  953. (_Command), \
  954. FIELD_OFFSET(PCI_COMMON_CONFIG, Command), \
  955. sizeof(USHORT) \
  956. );
  957. //
  958. // VOID
  959. // PciSetCommandRegister(
  960. // PPCI_PDO_EXTENSION _PdoExt,
  961. // USHORT _Command
  962. // );
  963. //
  964. #define PciSetCommandRegister(_PdoExt, _Command) \
  965. PciWriteDeviceConfig((_PdoExt), \
  966. &(_Command), \
  967. FIELD_OFFSET(PCI_COMMON_CONFIG, Command), \
  968. sizeof(USHORT) \
  969. );
  970. // BOOLEAN
  971. // BITS_SET(
  972. // IN USHORT C
  973. // IN USHORT F
  974. // )
  975. //
  976. #define BITS_SET(C,F) ((BOOLEAN)(((C) & (F)) == (F)))
  977. // BOOLEAN
  978. // ANY_BITS_SET(
  979. // IN USHORT C
  980. // IN USHORT F
  981. // )
  982. //
  983. #define ANY_BITS_SET(C,F) ((BOOLEAN)(((C) & (F)) != 0))
  984. //
  985. // VOID
  986. // PciGetConfigData(
  987. // IN PPCI_PDO_EXTENSION PdoExtension,
  988. // OUT PPCI_COMMON_CONFIG PciConfig
  989. // )
  990. //
  991. #define PciGetConfigData(_PdoExtension, _PciConfig) \
  992. PciReadDeviceConfig((_PdoExtension), \
  993. (_PciConfig), \
  994. 0, \
  995. PCI_COMMON_HDR_LENGTH \
  996. );
  997. //
  998. // VOID
  999. // PciSetConfigData(
  1000. // IN PPCI_PDO_EXTENSION PdoExtension,
  1001. // OUT PPCI_COMMON_CONFIG PciConfig
  1002. // )
  1003. //
  1004. #define PciSetConfigData(_PdoExtension, _PciConfig) \
  1005. PciWriteDeviceConfig((_PdoExtension), \
  1006. (_PciConfig), \
  1007. 0, \
  1008. PCI_COMMON_HDR_LENGTH \
  1009. );
  1010. // debug.c
  1011. typedef enum {
  1012. PciDbgAlways = 0x00000000, // unconditionally
  1013. PciDbgInformative = 0x00000001,
  1014. PciDbgVerbose = 0x00000003,
  1015. PciDbgPrattling = 0x00000007,
  1016. PciDbgPnpIrpsFdo = 0x00000100, // PnP IRPs at FDO
  1017. PciDbgPnpIrpsPdo = 0x00000200, // PnP IRPs at PDO
  1018. PciDbgPoIrpsFdo = 0x00000400, // PO IRPs at FDO
  1019. PciDbgPoIrpsPdo = 0x00000800, // PO IRPs at PDO
  1020. PciDbgAddDevice = 0x00001000, // AddDevice info
  1021. PciDbgAddDeviceRes = 0x00002000, // bus initial resource info
  1022. PciDbgWaitWake = 0x00008000, // noisy debug for wait wake
  1023. PciDbgQueryCap = 0x00010000, // Dump QueryCapabilities
  1024. PciDbgCardBus = 0x00020000, // CardBus FDOish behavior
  1025. PciDbgROM = 0x00040000, // access to device ROM
  1026. PciDbgConfigParam = 0x00080000, // Setting config parameters
  1027. PciDbgBusNumbers = 0x00100000, // checking and assigning bus numbers
  1028. PciDbgResReqList = 0x01000000, // generated resource requirements
  1029. PciDbgCmResList = 0x02000000, // generated CM Resource lists
  1030. PciDbgSetResChange = 0x04000000, // SetResources iff changing
  1031. PciDbgSetRes = 0x08000000, // SetResources
  1032. PciDbgObnoxious = 0x7fffffff // anything
  1033. } PCI_DEBUG_LEVEL;
  1034. #if DBG
  1035. #define PCI_DEBUGGING_OKAY() \
  1036. (KeGetCurrentIrql() < IPI_LEVEL)
  1037. #define PCI_ASSERT \
  1038. if (PCI_DEBUGGING_OKAY()) ASSERT
  1039. #define PCI_ASSERTMSG \
  1040. if (PCI_DEBUGGING_OKAY()) ASSERTMSG
  1041. extern PCI_DEBUG_LEVEL PciDebug;
  1042. #define PCI_DEBUG_BUFFER_SIZE 256
  1043. #define PciDebugPrint PciDebugPrintIfLevel
  1044. #else
  1045. #define PciDebugPrint if(0)
  1046. #define PCI_ASSERT(exp)
  1047. #define PCI_ASSERTMSG(msg,exp)
  1048. #endif
  1049. VOID
  1050. PciDebugDumpCommonConfig(
  1051. IN PPCI_COMMON_CONFIG CommonConfig
  1052. );
  1053. VOID
  1054. PciDebugDumpQueryCapabilities(
  1055. IN PDEVICE_CAPABILITIES C
  1056. );
  1057. VOID
  1058. PciDebugHit(
  1059. ULONG StopOnBit
  1060. );
  1061. PUCHAR
  1062. PciDebugPnpIrpTypeToText(
  1063. ULONG IrpMinorCode
  1064. );
  1065. PUCHAR
  1066. PciDebugPoIrpTypeToText(
  1067. ULONG IrpMinorCode
  1068. );
  1069. VOID
  1070. PciDebugPrintIfLevel(
  1071. PCI_DEBUG_LEVEL DebugPrintLevel,
  1072. PCCHAR DebugMessage,
  1073. ...
  1074. );
  1075. VOID
  1076. PciDebugPrintf(
  1077. PCCHAR DebugMessage,
  1078. ...
  1079. );
  1080. VOID
  1081. PciDebugPrintCmResList(
  1082. PCI_DEBUG_LEVEL DebugPrintLevel,
  1083. IN PCM_RESOURCE_LIST ResourceList
  1084. );
  1085. VOID
  1086. PciDebugPrintIoResource(
  1087. IN PIO_RESOURCE_DESCRIPTOR Descriptor
  1088. );
  1089. VOID
  1090. PciDebugPrintIoResReqList(
  1091. IN PIO_RESOURCE_REQUIREMENTS_LIST List
  1092. );
  1093. VOID
  1094. PciDebugPrintPartialResource(
  1095. PCI_DEBUG_LEVEL DebugPrintLevel,
  1096. IN PCM_PARTIAL_RESOURCE_DESCRIPTOR D
  1097. );
  1098. // device.h
  1099. VOID
  1100. Device_MassageHeaderForLimitsDetermination(
  1101. IN PPCI_CONFIGURABLE_OBJECT This
  1102. );
  1103. VOID
  1104. Device_RestoreCurrent(
  1105. IN PPCI_CONFIGURABLE_OBJECT This
  1106. );
  1107. VOID
  1108. Device_SaveLimits(
  1109. IN PPCI_CONFIGURABLE_OBJECT This
  1110. );
  1111. VOID
  1112. Device_SaveCurrentSettings(
  1113. IN PPCI_CONFIGURABLE_OBJECT This
  1114. );
  1115. VOID
  1116. Device_ChangeResourceSettings(
  1117. IN PPCI_PDO_EXTENSION PdoExtension,
  1118. IN PPCI_COMMON_CONFIG CommonConfig
  1119. );
  1120. VOID
  1121. Device_GetAdditionalResourceDescriptors(
  1122. IN PPCI_PDO_EXTENSION PdoExtension,
  1123. IN PPCI_COMMON_CONFIG CommonConfig,
  1124. IN PIO_RESOURCE_DESCRIPTOR Resource
  1125. );
  1126. NTSTATUS
  1127. Device_ResetDevice(
  1128. IN PPCI_PDO_EXTENSION PdoExtension,
  1129. IN PPCI_COMMON_CONFIG CommonConfig
  1130. );
  1131. // dispatch.h
  1132. //
  1133. // This is the dispatch table for normal PDO's.
  1134. //
  1135. extern PCI_MJ_DISPATCH_TABLE PciPdoDispatchTable;
  1136. NTSTATUS
  1137. PciDispatchIrp(
  1138. IN PDEVICE_OBJECT DeviceObject,
  1139. IN PIRP Irp
  1140. );
  1141. NTSTATUS
  1142. PciPassIrpFromFdoToPdo(
  1143. PPCI_COMMON_EXTENSION DeviceExtension,
  1144. PIRP Irp
  1145. );
  1146. NTSTATUS
  1147. PciCallDownIrpStack(
  1148. PPCI_COMMON_EXTENSION DeviceExtension,
  1149. PIRP Irp
  1150. );
  1151. NTSTATUS
  1152. PciIrpNotSupported(
  1153. IN PIRP Irp,
  1154. IN PIO_STACK_LOCATION IrpSp,
  1155. IN PPCI_COMMON_EXTENSION DeviceExtension
  1156. );
  1157. NTSTATUS
  1158. PciIrpInvalidDeviceRequest(
  1159. IN PIRP Irp,
  1160. IN PIO_STACK_LOCATION IrpSp,
  1161. IN PPCI_COMMON_EXTENSION DeviceExtension
  1162. );
  1163. // enum.h
  1164. PIO_RESOURCE_REQUIREMENTS_LIST
  1165. PciAllocateIoRequirementsList(
  1166. IN ULONG ResourceCount,
  1167. IN ULONG BusNumber,
  1168. IN ULONG SlotNumber
  1169. );
  1170. BOOLEAN
  1171. PciComputeNewCurrentSettings(
  1172. IN PPCI_PDO_EXTENSION PdoExtension,
  1173. IN PCM_RESOURCE_LIST ResourceList
  1174. );
  1175. NTSTATUS
  1176. PciQueryDeviceRelations(
  1177. IN PPCI_FDO_EXTENSION FdoExtension,
  1178. OUT PDEVICE_RELATIONS *DeviceRelations
  1179. );
  1180. NTSTATUS
  1181. PciQueryRequirements(
  1182. IN PPCI_PDO_EXTENSION PdoExtension,
  1183. OUT PIO_RESOURCE_REQUIREMENTS_LIST *RequirementsList
  1184. );
  1185. NTSTATUS
  1186. PciQueryResources(
  1187. IN PPCI_PDO_EXTENSION PdoExtension,
  1188. OUT PCM_RESOURCE_LIST *ResourceList
  1189. );
  1190. NTSTATUS
  1191. PciQueryTargetDeviceRelations(
  1192. IN PPCI_PDO_EXTENSION PdoExtension,
  1193. IN OUT PDEVICE_RELATIONS *PDeviceRelations
  1194. );
  1195. NTSTATUS
  1196. PciQueryEjectionRelations(
  1197. IN PPCI_PDO_EXTENSION PdoExtension,
  1198. IN OUT PDEVICE_RELATIONS *PDeviceRelations
  1199. );
  1200. NTSTATUS
  1201. PciScanHibernatedBus(
  1202. IN PPCI_FDO_EXTENSION FdoExtension
  1203. );
  1204. NTSTATUS
  1205. PciSetResources(
  1206. IN PPCI_PDO_EXTENSION PdoExtension,
  1207. IN BOOLEAN PowerOn,
  1208. IN BOOLEAN StartDeviceIrp
  1209. );
  1210. VOID
  1211. PciUpdateHardware(
  1212. IN PPCI_PDO_EXTENSION PdoExtension,
  1213. IN PPCI_COMMON_CONFIG Config
  1214. );
  1215. BOOLEAN
  1216. PciIsSameDevice(
  1217. IN PPCI_PDO_EXTENSION PdoExtension
  1218. );
  1219. NTSTATUS
  1220. PciBuildRequirementsList(
  1221. IN PPCI_PDO_EXTENSION PdoExtension,
  1222. IN PPCI_COMMON_CONFIG CurrentConfig,
  1223. OUT PIO_RESOURCE_REQUIREMENTS_LIST *FinalReqList
  1224. );
  1225. // fdo.h
  1226. NTSTATUS
  1227. PciFdoIrpQueryDeviceRelations(
  1228. IN PIRP Irp,
  1229. IN PIO_STACK_LOCATION IrpSp,
  1230. IN PPCI_COMMON_EXTENSION DeviceExtension
  1231. );
  1232. NTSTATUS
  1233. PciAddDevice(
  1234. IN PDRIVER_OBJECT DriverObject,
  1235. IN PDEVICE_OBJECT PhysicalDeviceObject
  1236. );
  1237. VOID
  1238. PciInitializeFdoExtensionCommonFields(
  1239. IN PPCI_FDO_EXTENSION FdoExtension,
  1240. IN PDEVICE_OBJECT Fdo,
  1241. IN PDEVICE_OBJECT Pdo
  1242. );
  1243. // hookhal.c
  1244. VOID
  1245. PciHookHal(
  1246. VOID
  1247. );
  1248. VOID
  1249. PciUnhookHal(
  1250. VOID
  1251. );
  1252. // id.h
  1253. PWSTR
  1254. PciGetDeviceDescriptionMessage(
  1255. IN UCHAR BaseClass,
  1256. IN UCHAR SubClass
  1257. );
  1258. NTSTATUS
  1259. PciQueryId(
  1260. IN PPCI_PDO_EXTENSION PdoExtension,
  1261. IN BUS_QUERY_ID_TYPE IdType,
  1262. IN OUT PWSTR *BusQueryId
  1263. );
  1264. NTSTATUS
  1265. PciQueryDeviceText(
  1266. IN PPCI_PDO_EXTENSION PdoExtension,
  1267. IN DEVICE_TEXT_TYPE TextType,
  1268. IN LCID LocaleId,
  1269. IN OUT PWSTR *DeviceText
  1270. );
  1271. // interface.h
  1272. #define PCIIF_PDO 0x01 // Interface can be used by a PDO
  1273. #define PCIIF_FDO 0x02 // Interface can be used by an FDO
  1274. #define PCIIF_ROOT 0x04 // Interface can be used only at by the root.
  1275. typedef
  1276. NTSTATUS
  1277. (*PPCI_INTERFACE_CONSTRUCTOR)(
  1278. PVOID DeviceExtension,
  1279. PVOID PciInterface,
  1280. PVOID InterfaceSpecificData,
  1281. USHORT Version,
  1282. USHORT Size,
  1283. PINTERFACE InterfaceReturn
  1284. );
  1285. typedef
  1286. NTSTATUS
  1287. (*PPCI_INTERFACE_INITIALIZER)(
  1288. PPCI_ARBITER_INSTANCE Instance
  1289. );
  1290. typedef struct _PCI_INTERFACE {
  1291. PGUID InterfaceType;
  1292. USHORT MinSize;
  1293. USHORT MinVersion;
  1294. USHORT MaxVersion;
  1295. USHORT Flags;
  1296. LONG ReferenceCount;
  1297. PCI_SIGNATURE Signature;
  1298. PPCI_INTERFACE_CONSTRUCTOR Constructor;
  1299. PPCI_INTERFACE_INITIALIZER Initializer;
  1300. } PCI_INTERFACE, *PPCI_INTERFACE;
  1301. NTSTATUS
  1302. PciQueryInterface(
  1303. IN PVOID DeviceExtension,
  1304. IN PGUID InterfaceType,
  1305. IN USHORT Size,
  1306. IN USHORT Version,
  1307. IN PVOID InterfaceSpecificData,
  1308. IN OUT PINTERFACE Interface,
  1309. IN BOOLEAN LastChance
  1310. );
  1311. extern PPCI_INTERFACE PciInterfaces[];
  1312. // pdo.h
  1313. NTSTATUS
  1314. PciPdoCreate(
  1315. IN PPCI_FDO_EXTENSION FdoExtension,
  1316. IN PCI_SLOT_NUMBER Slot,
  1317. OUT PDEVICE_OBJECT *PhysicalDeviceObject
  1318. );
  1319. VOID
  1320. PciPdoDestroy(
  1321. IN PDEVICE_OBJECT PhysicalDeviceObject
  1322. );
  1323. // pmeintf.h
  1324. VOID
  1325. PciPmeAdjustPmeEnable(
  1326. IN PPCI_PDO_EXTENSION PdoExtension,
  1327. IN BOOLEAN Enable,
  1328. IN BOOLEAN ClearStatusOnly
  1329. );
  1330. VOID
  1331. PciPmeGetInformation(
  1332. IN PDEVICE_OBJECT Pdo,
  1333. OUT PBOOLEAN PmeCapable,
  1334. OUT PBOOLEAN PmeStatus,
  1335. OUT PBOOLEAN PmeEnable
  1336. );
  1337. // power.h
  1338. NTSTATUS
  1339. PciPdoIrpQueryPower(
  1340. IN PIRP Irp,
  1341. IN PIO_STACK_LOCATION IrpSp,
  1342. IN PPCI_COMMON_EXTENSION DeviceExtension
  1343. );
  1344. NTSTATUS
  1345. PciPdoSetPowerState (
  1346. IN PIRP Irp,
  1347. IN PIO_STACK_LOCATION IrpStack,
  1348. IN PPCI_COMMON_EXTENSION DeviceExtension
  1349. );
  1350. NTSTATUS
  1351. PciPdoWaitWake (
  1352. IN PIRP Irp,
  1353. IN PIO_STACK_LOCATION IrpSp,
  1354. IN PPCI_COMMON_EXTENSION DeviceExtension
  1355. );
  1356. VOID
  1357. PciPdoWaitWakeCancelRoutine(
  1358. IN PDEVICE_OBJECT DeviceObject,
  1359. IN OUT PIRP Irp
  1360. );
  1361. NTSTATUS
  1362. PciFdoIrpQueryPower(
  1363. IN PIRP Irp,
  1364. IN PIO_STACK_LOCATION IrpSp,
  1365. IN PPCI_COMMON_EXTENSION DeviceExtension
  1366. );
  1367. NTSTATUS
  1368. PciFdoSetPowerState(
  1369. IN PIRP Irp,
  1370. IN PIO_STACK_LOCATION IrpSp,
  1371. IN PPCI_COMMON_EXTENSION DeviceExtension
  1372. );
  1373. NTSTATUS
  1374. PciFdoWaitWake(
  1375. IN PIRP Irp,
  1376. IN PIO_STACK_LOCATION IrpSp,
  1377. IN PPCI_COMMON_EXTENSION DeviceExtension
  1378. );
  1379. NTSTATUS
  1380. PciSetPowerManagedDevicePowerState(
  1381. IN PPCI_PDO_EXTENSION PdoExtension,
  1382. IN DEVICE_POWER_STATE DeviceState,
  1383. IN BOOLEAN RefreshConfigSpace
  1384. );
  1385. // ppbridge.h
  1386. VOID
  1387. PPBridge_MassageHeaderForLimitsDetermination(
  1388. IN PPCI_CONFIGURABLE_OBJECT This
  1389. );
  1390. VOID
  1391. PPBridge_RestoreCurrent(
  1392. IN PPCI_CONFIGURABLE_OBJECT This
  1393. );
  1394. VOID
  1395. PPBridge_SaveLimits(
  1396. IN PPCI_CONFIGURABLE_OBJECT This
  1397. );
  1398. VOID
  1399. PPBridge_SaveCurrentSettings(
  1400. IN PPCI_CONFIGURABLE_OBJECT This
  1401. );
  1402. VOID
  1403. PPBridge_ChangeResourceSettings(
  1404. IN PPCI_PDO_EXTENSION PdoExtension,
  1405. IN PPCI_COMMON_CONFIG CommonConfig
  1406. );
  1407. VOID
  1408. PPBridge_GetAdditionalResourceDescriptors(
  1409. IN PPCI_PDO_EXTENSION PdoExtension,
  1410. IN PPCI_COMMON_CONFIG CommonConfig,
  1411. IN PIO_RESOURCE_DESCRIPTOR Resource
  1412. );
  1413. NTSTATUS
  1414. PPBridge_ResetDevice(
  1415. IN PPCI_PDO_EXTENSION PdoExtension,
  1416. IN PPCI_COMMON_CONFIG CommonConfig
  1417. );
  1418. // romimage.h
  1419. NTSTATUS
  1420. PciReadRomImage(
  1421. IN PPCI_PDO_EXTENSION PdoExtension,
  1422. IN ULONG WhichSpace,
  1423. OUT PVOID Buffer,
  1424. IN ULONG Offset,
  1425. IN OUT PULONG LENGTH
  1426. );
  1427. // state.h
  1428. //
  1429. // Note - State.c depends on the order of these.
  1430. //
  1431. typedef enum {
  1432. PciNotStarted = 0,
  1433. PciStarted,
  1434. PciDeleted,
  1435. PciStopped,
  1436. PciSurpriseRemoved,
  1437. PciSynchronizedOperation,
  1438. PciMaxObjectState
  1439. } PCI_OBJECT_STATE;
  1440. VOID
  1441. PciInitializeState(
  1442. IN PPCI_COMMON_EXTENSION DeviceExtension
  1443. );
  1444. NTSTATUS
  1445. PciBeginStateTransition(
  1446. IN PPCI_COMMON_EXTENSION DeviceExtension,
  1447. IN PCI_OBJECT_STATE NewState
  1448. );
  1449. VOID
  1450. PciCommitStateTransition(
  1451. IN PPCI_COMMON_EXTENSION DeviceExtension,
  1452. IN PCI_OBJECT_STATE NewState
  1453. );
  1454. NTSTATUS
  1455. PciCancelStateTransition(
  1456. IN PPCI_COMMON_EXTENSION DeviceExtension,
  1457. IN PCI_OBJECT_STATE StateNotEntered
  1458. );
  1459. BOOLEAN
  1460. PciIsInTransitionToState(
  1461. IN PPCI_COMMON_EXTENSION DeviceExtension,
  1462. IN PCI_OBJECT_STATE NextState
  1463. );
  1464. /*
  1465. NTSTATUS
  1466. PciBeginStateTransitionIfNotBegun(
  1467. IN PPCI_COMMON_EXTENSION DeviceExtension,
  1468. IN PCI_OBJECT_STATE StateToEnter
  1469. );
  1470. */
  1471. #define PCI_ACQUIRE_STATE_LOCK(Extension) \
  1472. PciBeginStateTransition((PPCI_COMMON_EXTENSION) (Extension), \
  1473. PciSynchronizedOperation)
  1474. #define PCI_RELEASE_STATE_LOCK(Extension) \
  1475. PciCancelStateTransition((PPCI_COMMON_EXTENSION) (Extension), \
  1476. PciSynchronizedOperation)
  1477. // tr_comn.h
  1478. typedef struct _PCI_TRANSLATOR_INSTANCE {
  1479. PTRANSLATOR_INTERFACE Interface;
  1480. ULONG ReferenceCount;
  1481. PPCI_FDO_EXTENSION FdoExtension;
  1482. } PCI_TRANSLATOR_INSTANCE, *PPCI_TRANSLATOR_INSTANCE;
  1483. #define PCI_TRANSLATOR_INSTANCE_TO_CONTEXT(x) ((PVOID)(x))
  1484. #define PCI_TRANSLATOR_CONTEXT_TO_INSTANCE(x) ((PPCI_TRANSLATOR_INSTANCE)(x))
  1485. VOID
  1486. PciReferenceTranslator(
  1487. IN PVOID Context
  1488. );
  1489. VOID
  1490. PciDereferenceTranslator(
  1491. IN PVOID Context
  1492. );
  1493. // usage.h
  1494. NTSTATUS
  1495. PciLocalDeviceUsage (
  1496. IN PPCI_POWER_STATE PowerState,
  1497. IN PIRP Irp
  1498. );
  1499. NTSTATUS
  1500. PciPdoDeviceUsage (
  1501. IN PPCI_PDO_EXTENSION pdoExtension,
  1502. IN PIRP Irp
  1503. );
  1504. // utils.h
  1505. NTSTATUS
  1506. PciAssignSlotResources(
  1507. IN PUNICODE_STRING RegistryPath,
  1508. IN PUNICODE_STRING DriverClassName OPTIONAL,
  1509. IN PDRIVER_OBJECT DriverObject,
  1510. IN PDEVICE_OBJECT DeviceObject OPTIONAL,
  1511. IN INTERFACE_TYPE BusType,
  1512. IN ULONG BusNumber,
  1513. IN ULONG SlotNumber,
  1514. IN OUT PCM_RESOURCE_LIST *AllocatedResources
  1515. );
  1516. PCI_OBJECT_TYPE
  1517. PciClassifyDeviceType(
  1518. PPCI_PDO_EXTENSION PdoExtension
  1519. );
  1520. // VOID
  1521. // PciCompleteRequest(
  1522. // IN OUT PIRP Irp,
  1523. // IN NTSTATUS Status
  1524. // );
  1525. #define PciCompleteRequest(_Irp_,_Status_) \
  1526. { \
  1527. (_Irp_)->IoStatus.Status = (_Status_); \
  1528. IoCompleteRequest((_Irp_), IO_NO_INCREMENT); \
  1529. }
  1530. BOOLEAN
  1531. PciCreateIoDescriptorFromBarLimit(
  1532. IN PIO_RESOURCE_DESCRIPTOR Descriptor,
  1533. IN PULONG BaseAddress,
  1534. IN BOOLEAN Rom
  1535. );
  1536. BOOLEAN
  1537. PciIsCriticalDeviceClass(
  1538. IN UCHAR BaseClass,
  1539. IN UCHAR SubClass
  1540. );
  1541. #define PCI_CAN_DISABLE_VIDEO_DECODES 0x00000001
  1542. BOOLEAN
  1543. PciCanDisableDecodes(
  1544. IN PPCI_PDO_EXTENSION PdoExtension OPTIONAL,
  1545. IN PPCI_COMMON_CONFIG Config OPTIONAL,
  1546. IN ULONGLONG HackFlags,
  1547. IN ULONG Flags
  1548. );
  1549. VOID
  1550. PciDecodeEnable(
  1551. IN PPCI_PDO_EXTENSION PdoExtension,
  1552. IN BOOLEAN EnableOperation,
  1553. IN PUSHORT ExistingCommand OPTIONAL
  1554. );
  1555. PCM_PARTIAL_RESOURCE_DESCRIPTOR
  1556. PciFindDescriptorInCmResourceList(
  1557. IN CM_RESOURCE_TYPE DescriptorType,
  1558. IN PCM_RESOURCE_LIST ResourceList,
  1559. IN PCM_PARTIAL_RESOURCE_DESCRIPTOR PreviousHit
  1560. );
  1561. PPCI_FDO_EXTENSION
  1562. PciFindParentPciFdoExtension(
  1563. PDEVICE_OBJECT PhysicalDeviceObject,
  1564. IN PFAST_MUTEX Mutex
  1565. );
  1566. PPCI_PDO_EXTENSION
  1567. PciFindPdoByFunction(
  1568. IN PPCI_FDO_EXTENSION FdoExtension,
  1569. IN PCI_SLOT_NUMBER Slot,
  1570. IN PPCI_COMMON_CONFIG Config
  1571. );
  1572. PVOID
  1573. PciFindNextSecondaryExtension(
  1574. IN PSINGLE_LIST_ENTRY ListEntry,
  1575. IN PCI_SIGNATURE DesiredType
  1576. );
  1577. #define PciFindSecondaryExtension(X,TYPE) \
  1578. PciFindNextSecondaryExtension((X)->SecondaryExtension.Next, TYPE)
  1579. VOID
  1580. PcipLinkSecondaryExtension(
  1581. IN PSINGLE_LIST_ENTRY ListHead,
  1582. IN PFAST_MUTEX Mutex,
  1583. IN PVOID NewExtension,
  1584. IN PCI_SIGNATURE Type,
  1585. IN PSECONDARYEXTENSIONDESTRUCTOR Destructor
  1586. );
  1587. #define PciLinkSecondaryExtension(X,X2,T,D) \
  1588. PcipLinkSecondaryExtension(&(X)->SecondaryExtension, \
  1589. &(X)->SecondaryExtMutex, \
  1590. X2, \
  1591. T, \
  1592. D)
  1593. VOID
  1594. PcipDestroySecondaryExtension(
  1595. IN PSINGLE_LIST_ENTRY ListHead,
  1596. IN PFAST_MUTEX Mutex,
  1597. IN PVOID Extension
  1598. );
  1599. ULONGLONG
  1600. PciGetHackFlags(
  1601. IN USHORT VendorID,
  1602. IN USHORT DeviceID,
  1603. IN USHORT SubVendorID,
  1604. IN USHORT SubSystemID,
  1605. IN UCHAR RevisionID
  1606. );
  1607. NTSTATUS
  1608. PciGetDeviceProperty(
  1609. IN PDEVICE_OBJECT PhysicalDeviceObject,
  1610. IN DEVICE_REGISTRY_PROPERTY DeviceProperty,
  1611. OUT PVOID *PropertyBuffer
  1612. );
  1613. NTSTATUS
  1614. PciGetInterruptAssignment(
  1615. IN PPCI_PDO_EXTENSION PdoExtension,
  1616. OUT ULONG *Minimum,
  1617. OUT ULONG *Maximum
  1618. );
  1619. ULONG
  1620. PciGetLengthFromBar(
  1621. ULONG BaseAddressRegister
  1622. );
  1623. NTSTATUS
  1624. PciGetRegistryValue(
  1625. IN PWSTR ValueName,
  1626. IN PWSTR KeyName,
  1627. IN HANDLE ParentHandle,
  1628. IN ULONG Type,
  1629. OUT PVOID *Buffer,
  1630. OUT PULONG Length
  1631. );
  1632. VOID
  1633. PciInsertEntryAtTail(
  1634. IN PSINGLE_LIST_ENTRY ListHead,
  1635. IN PSINGLE_LIST_ENTRY NewEntry,
  1636. IN PFAST_MUTEX Mutex
  1637. );
  1638. VOID
  1639. PciInsertEntryAtHead(
  1640. IN PSINGLE_LIST_ENTRY ListHead,
  1641. IN PSINGLE_LIST_ENTRY NewEntry,
  1642. IN PFAST_MUTEX Mutex
  1643. );
  1644. PCM_PARTIAL_RESOURCE_DESCRIPTOR
  1645. PciNextPartialDescriptor(
  1646. PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor
  1647. );
  1648. BOOLEAN
  1649. PciOpenKey(
  1650. IN PWSTR KeyName,
  1651. IN HANDLE ParentHandle,
  1652. IN ACCESS_MASK Access,
  1653. OUT PHANDLE ChildHandle,
  1654. OUT PNTSTATUS Status
  1655. );
  1656. NTSTATUS
  1657. PciQueryBusInformation(
  1658. IN PPCI_PDO_EXTENSION PdoExtension,
  1659. IN PPNP_BUS_INFORMATION *BusInformation
  1660. );
  1661. NTSTATUS
  1662. PciQueryLegacyBusInformation(
  1663. IN PPCI_FDO_EXTENSION FdoExtension,
  1664. IN PLEGACY_BUS_INFORMATION *BusInformation
  1665. );
  1666. NTSTATUS
  1667. PciQueryCapabilities(
  1668. IN PPCI_PDO_EXTENSION PdoExtension,
  1669. IN PDEVICE_CAPABILITIES Capabilities
  1670. );
  1671. NTSTATUS
  1672. PciRangeListFromResourceList(
  1673. IN PPCI_FDO_EXTENSION FdoExtension,
  1674. IN PCM_RESOURCE_LIST ResourceList,
  1675. IN CM_RESOURCE_TYPE DesiredType,
  1676. IN BOOLEAN Complement,
  1677. IN PRTL_RANGE_LIST ResultRange
  1678. );
  1679. UCHAR
  1680. PciReadDeviceCapability(
  1681. IN PPCI_PDO_EXTENSION PdoExtension,
  1682. IN UCHAR Offset,
  1683. IN UCHAR Id,
  1684. IN OUT PVOID Buffer,
  1685. IN ULONG Length
  1686. );
  1687. VOID
  1688. PciRemoveEntryFromList(
  1689. IN PSINGLE_LIST_ENTRY ListHead,
  1690. IN PSINGLE_LIST_ENTRY OldEntry,
  1691. IN PFAST_MUTEX Mutex
  1692. );
  1693. PPCI_PDO_EXTENSION
  1694. PciFindPdoByLocation(
  1695. IN ULONG BusNumber,
  1696. IN PCI_SLOT_NUMBER Slot
  1697. );
  1698. NTSTATUS
  1699. PciBuildDefaultExclusionLists(
  1700. VOID
  1701. );
  1702. NTSTATUS
  1703. PciExcludeRangesFromWindow(
  1704. IN ULONGLONG Start,
  1705. IN ULONGLONG End,
  1706. IN PRTL_RANGE_LIST ArbiterRanges,
  1707. IN PRTL_RANGE_LIST ExclusionRanges
  1708. );
  1709. NTSTATUS
  1710. PciSaveBiosConfig(
  1711. IN PPCI_PDO_EXTENSION PdoExtension,
  1712. IN PPCI_COMMON_CONFIG Config
  1713. );
  1714. NTSTATUS
  1715. PciGetBiosConfig(
  1716. IN PPCI_PDO_EXTENSION PdoExtension,
  1717. IN PPCI_COMMON_CONFIG Config
  1718. );
  1719. BOOLEAN
  1720. PciStringToUSHORT(
  1721. IN PWCHAR String,
  1722. OUT PUSHORT Result
  1723. );
  1724. NTSTATUS
  1725. PciSendIoctl(
  1726. IN PDEVICE_OBJECT Device,
  1727. IN ULONG IoctlCode,
  1728. IN PVOID InputBuffer OPTIONAL,
  1729. IN ULONG InputBufferLength,
  1730. IN PVOID OutputBuffer OPTIONAL,
  1731. IN ULONG OutputBufferLength
  1732. );
  1733. BOOLEAN
  1734. PciIsOnVGAPath(
  1735. IN PPCI_PDO_EXTENSION Pdo
  1736. );
  1737. BOOLEAN
  1738. PciIsSlotPresentInParentMethod(
  1739. IN PPCI_PDO_EXTENSION Pdo,
  1740. IN ULONG Method
  1741. );
  1742. NTSTATUS
  1743. PciUpdateLegacyHardwareDescription(
  1744. IN PPCI_FDO_EXTENSION Fdo
  1745. );
  1746. NTSTATUS
  1747. PciWriteDeviceSpace(
  1748. IN PPCI_PDO_EXTENSION PdoExtension,
  1749. IN ULONG WhichSpace,
  1750. IN PVOID Buffer,
  1751. IN ULONG Offset,
  1752. IN ULONG Length,
  1753. OUT PULONG LengthWritten
  1754. );
  1755. NTSTATUS
  1756. PciReadDeviceSpace(
  1757. IN PPCI_PDO_EXTENSION PdoExtension,
  1758. IN ULONG WhichSpace,
  1759. IN PVOID Buffer,
  1760. IN ULONG Offset,
  1761. IN ULONG Length,
  1762. OUT PULONG LengthRead
  1763. );
  1764. BOOLEAN
  1765. PciIsSuiteVersion(
  1766. IN USHORT Version
  1767. );
  1768. BOOLEAN
  1769. PciIsDatacenter(
  1770. );
  1771. ULONG_PTR
  1772. PciExecuteCriticalSystemRoutine(
  1773. IN ULONG_PTR Context
  1774. );
  1775. BOOLEAN
  1776. PciUnicodeStringStrStr(
  1777. IN PUNICODE_STRING SearchString,
  1778. IN PUNICODE_STRING SubString,
  1779. IN BOOLEAN CaseInsensitive
  1780. );
  1781. //
  1782. // Programming Interface encodings for PCI IDE Controllers
  1783. // BaseClass = 1, SubClass = 1
  1784. //
  1785. #define PCI_IDE_PRIMARY_NATIVE_MODE 0x01
  1786. #define PCI_IDE_PRIMARY_MODE_CHANGEABLE 0x02
  1787. #define PCI_IDE_SECONDARY_NATIVE_MODE 0x04
  1788. #define PCI_IDE_SECONDARY_MODE_CHANGEABLE 0x08
  1789. #define PCI_IS_LEGACY_IDE_CONTROLLER(_Config) \
  1790. ((_Config)->BaseClass == PCI_CLASS_MASS_STORAGE_CTLR \
  1791. && (_Config)->SubClass == PCI_SUBCLASS_MSC_IDE_CTLR \
  1792. && !BITS_SET((_Config)->ProgIf, (PCI_IDE_PRIMARY_NATIVE_MODE \
  1793. | PCI_IDE_SECONDARY_NATIVE_MODE)))
  1794. #define PCI_IS_NATIVE_IDE_CONTROLLER(_Config) \
  1795. ((_Config)->BaseClass == PCI_CLASS_MASS_STORAGE_CTLR \
  1796. && (_Config)->SubClass == PCI_SUBCLASS_MSC_IDE_CTLR \
  1797. && BITS_SET((_Config)->ProgIf, (PCI_IDE_PRIMARY_NATIVE_MODE \
  1798. | PCI_IDE_SECONDARY_NATIVE_MODE)))
  1799. #define PCI_IS_NATIVE_CAPABLE_IDE_CONTROLLER(_Config) \
  1800. ((_Config)->BaseClass == PCI_CLASS_MASS_STORAGE_CTLR \
  1801. && (_Config)->SubClass == PCI_SUBCLASS_MSC_IDE_CTLR \
  1802. && BITS_SET((_Config)->ProgIf, (PCI_IDE_PRIMARY_MODE_CHANGEABLE \
  1803. | PCI_IDE_SECONDARY_MODE_CHANGEABLE)))
  1804. //
  1805. // _HPP method for HotPlugParameters
  1806. //
  1807. // Method (_HPP, 0) {
  1808. // Return (Package(){
  1809. // 0x00000008, // CacheLineSize in DWORDS
  1810. // 0x00000040, // LatencyTimer in PCI clocks
  1811. // 0x00000001, // Enable SERR (Boolean)
  1812. // 0x00000001 // Enable PERR (Boolean)
  1813. // })
  1814. //
  1815. #define PCI_HPP_CACHE_LINE_SIZE_INDEX 0
  1816. #define PCI_HPP_LATENCY_TIMER_INDEX 1
  1817. #define PCI_HPP_ENABLE_SERR_INDEX 2
  1818. #define PCI_HPP_ENABLE_PERR_INDEX 3
  1819. #define PCI_HPP_PACKAGE_COUNT 4
  1820. //
  1821. // Support for kernel debugger and headless ports that can't be turned off
  1822. // This is retrieved from the registry in DriverEntry and thus the bus numbers
  1823. // are how the firmware configured the machine and not necessarily the current
  1824. // settings. Luckily we saved away the BIOS config in the registry.
  1825. //
  1826. typedef struct _PCI_DEBUG_PORT {
  1827. ULONG Bus;
  1828. PCI_SLOT_NUMBER Slot;
  1829. } PCI_DEBUG_PORT, *PPCI_DEBUG_PORT;
  1830. extern PCI_DEBUG_PORT PciDebugPorts[];
  1831. extern ULONG PciDebugPortsCount;
  1832. BOOLEAN
  1833. PciIsDeviceOnDebugPath(
  1834. IN PPCI_PDO_EXTENSION Pdo
  1835. );
  1836. //
  1837. // Cardbus has extra configuration information beyond the common
  1838. // header.
  1839. //
  1840. typedef struct _TYPE2EXTRAS {
  1841. USHORT SubVendorID;
  1842. USHORT SubSystemID;
  1843. ULONG LegacyModeBaseAddress;
  1844. } TYPE2EXTRAS;
  1845. #define CARDBUS_LMBA_OFFSET \
  1846. (ULONG)(FIELD_OFFSET(PCI_COMMON_CONFIG, DeviceSpecific) + \
  1847. FIELD_OFFSET(TYPE2EXTRAS, LegacyModeBaseAddress))
  1848. //
  1849. // Hack flags for PCI devices (PDO)
  1850. //
  1851. #define PCI_HACK_NO_VIDEO_IRQ 0x0000000000000001L
  1852. #define PCI_HACK_PCMCIA_WANT_IRQ 0x0000000000000002L
  1853. #define PCI_HACK_DUAL_IDE 0x0000000000000004L
  1854. #define PCI_HACK_NO_ENUM_AT_ALL 0x0000000000000008L
  1855. #define PCI_HACK_ENUM_NO_RESOURCE 0x0000000000000010L
  1856. #define PCI_HACK_NEED_DWORD_ACCESS 0x0000000000000020L
  1857. #define PCI_HACK_SINGLE_FUNCTION 0x0000000000000040L
  1858. #define PCI_HACK_ALWAYS_ENABLED 0x0000000000000080L
  1859. #define PCI_HACK_IS_IDE 0x0000000000000100L
  1860. #define PCI_HACK_IS_VIDEO 0x0000000000000200L
  1861. #define PCI_HACK_FAIL_START 0x0000000000000400L
  1862. #define PCI_HACK_GHOST 0x0000000000000800L
  1863. #define PCI_HACK_DOUBLE_DECKER 0x0000000000001000L
  1864. #define PCI_HACK_ONE_CHILD 0x0000000000002000L
  1865. #define PCI_HACK_PRESERVE_COMMAND 0x0000000000004000L
  1866. #define PCI_HACK_IS_VGA 0x0000000000008000L
  1867. #define PCI_HACK_CB_SHARE_CMD_BITS 0x0000000000010000L
  1868. #define PCI_HACK_STRAIGHT_IRQ_ROUTING 0x0000000000020000L
  1869. #define PCI_HACK_SUBTRACTIVE_DECODE 0x0000000000040000L
  1870. #define PCI_HACK_FDMA_ISA 0x0000000000080000L
  1871. #define PCI_HACK_EXCLUSIVE 0x0000000000100000L
  1872. #define PCI_HACK_EDGE 0x0000000000200000L
  1873. #define PCI_HACK_NO_SUBSYSTEM 0x0000000000400000L
  1874. #define PCI_HACK_NO_WPE 0x0000000000800000L
  1875. #define PCI_HACK_OLD_ID 0x0000000001000000L
  1876. #define PCI_HACK_DONT_SHRINK_BRIDGE 0x0000000002000000L
  1877. #define PCI_HACK_TURN_OFF_PARITY 0x0000000004000000L
  1878. #define PCI_HACK_NO_NON_PCI_CHILD_BAR 0x0000000008000000L
  1879. #define PCI_HACK_NO_ENUM_WITH_DISABLE 0x0000000010000000L
  1880. #define PCI_HACK_NO_PM_CAPS 0x0000000020000000L
  1881. #define PCI_HACK_NO_DISABLE_DECODES 0x0000000040000000L
  1882. #define PCI_HACK_NO_SUBSYSTEM_AFTER_D3 0x0000000080000000L
  1883. #define PCI_HACK_VIDEO_LEGACY_DECODE 0x0000000100000000L
  1884. #define PCI_HACK_FAKE_CLASS_CODE 0x0000000200000000L
  1885. #define PCI_HACK_RESET_BRIDGE_ON_POWERUP 0x0000000400000000L
  1886. #define PCI_HACK_BAD_NATIVE_IDE 0x0000000800000000L
  1887. #define PCI_HACK_FAIL_QUERY_REMOVE 0x0000001000000000L
  1888. #define PCI_HACK_CRITICAL_DEVICE 0x0000002000000000L
  1889. #define PCI_HACK_OVERRIDE_CRITICAL_DEVICE 0x0000004000000000L
  1890. //
  1891. // Hack flags for PCI busses (FDO)
  1892. // NB: These are not currently applied to cardbus bridges
  1893. //
  1894. //
  1895. // PCI_BUS_HACK_LOCK_RESOURCES - prevent devices on *this* bus from
  1896. // being moved. If a BAR are unconfigured it will still be assigned
  1897. // resources from what is available on the bus. If the BAR is
  1898. // configured only those resources if available will be assigned, if
  1899. // not available the the device will fail CM_PROBLEM_RESOURCE_CONFLICT.
  1900. //
  1901. // Putting /PCILOCK in boot.ini applies this to all devices in the system.
  1902. //
  1903. #define PCI_BUS_HACK_LOCK_RESOURCES 0x00000001
  1904. //
  1905. // Random useful macros
  1906. //
  1907. #ifndef FIELD_SIZE
  1908. #define FIELD_SIZE(type, field) (sizeof(((type *)0)->field))
  1909. #endif
  1910. //
  1911. // This macro computes if a range of bytes with configuration
  1912. // space from offset for length bytes will intersect with the
  1913. // any of the fields between field1 and field2 as defined in
  1914. // PCI_COMMON_CONFIG
  1915. //
  1916. #define INTERSECT_CONFIG_FIELD_RANGE(offset, length, field1, field2) \
  1917. INTERSECT((offset), \
  1918. (offset) + (length) - 1, \
  1919. FIELD_OFFSET(PCI_COMMON_CONFIG, field1), \
  1920. FIELD_OFFSET(PCI_COMMON_CONFIG, field2) \
  1921. + FIELD_SIZE(PCI_COMMON_CONFIG, field2) - 1 \
  1922. )
  1923. //
  1924. // This macro computes if a range of bytes with configuration
  1925. // space from offset for length bytes will intersect with
  1926. // field as defined in PCI_COMMON_CONFIG
  1927. //
  1928. #define INTERSECT_CONFIG_FIELD(offset, length, field) \
  1929. INTERSECT_CONFIG_FIELD_RANGE(offset, length, field, field)
  1930. #endif