Source code of Windows XP (NT5)
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.

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