pci.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768
  1. /*++
  2. Copyright (c) 2012 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. pci.h
  5. Abstract:
  6. This header contains definitions for the PCI (Peripheral Component
  7. Interconnect) driver.
  8. Author:
  9. Evan Green 17-Sep-2012
  10. --*/
  11. //
  12. // ------------------------------------------------------------------- Includes
  13. //
  14. #include <minoca/kernel/driver.h>
  15. #include <minoca/intrface/acpi.h>
  16. #include <minoca/intrface/pci.h>
  17. //
  18. // --------------------------------------------------------------------- Macros
  19. //
  20. //
  21. // This macro returns the PCI class codes from the 4-byte register.
  22. //
  23. #define PCI_CLASS_CODE(_Register) (((_Register) >> 24) & 0x000000FF)
  24. #define PCI_SUBCLASS_AND_INTERFACE(_Register) (((_Register) >> 8) & 0x0000FFFF)
  25. //
  26. // ---------------------------------------------------------------- Definitions
  27. //
  28. #define PCI_ALLOCATION_TAG 0x21696350 // '!icP'
  29. #define PCI_BUS_ID "PNP0A03"
  30. #define PCI_EXPRESS_BUS_ID "PNP0A08"
  31. #define PCI_BRIDGE_CLASS_ID "PCIBridge"
  32. #define PCI_SUBTRACTIVE_BRIDGE_CLASS_ID "PCIBridgeSubtractive"
  33. #define PCI_DEVICE_ID_FORMAT "VEN_%04X&DEV_%04X"
  34. #define PCI_DEVICE_ID_SIZE 18
  35. #define MAX_PCI_FUNCTION 7
  36. #define MAX_PCI_DEVICE 32
  37. #define MAX_PCI_DEVICES ((MAX_PCI_FUNCTION + 1) * (MAX_PCI_DEVICE + 1))
  38. #define PCI_INVALID_VENDOR_ID 0xFFFF
  39. #define PCI_INITIAL_CHILD_COUNT 10
  40. #define PCI_ROOT_CONFIG_ADDRESS 0xCF8
  41. #define PCI_ROOT_CONFIG_DATA 0xCFC
  42. #define PCI_BRIDGE_CLASS_CODE 0x06040000
  43. #define PCI_SUBTRACTIVE_BRIDGE_CLASS_CODE 0x06040100
  44. //
  45. // PCI Configuration Space definitions.
  46. //
  47. #define PCI_ID_OFFSET 0x00
  48. #define PCI_VENDOR_ID_MASK 0x0000FFFF
  49. #define PCI_DEVICE_ID_SHIFT 16
  50. #define PCI_DEVICE_ID_MASK 0xFFFF0000
  51. #define PCI_CONTROL_OFFSET 0x04
  52. #define PCI_STATUS_OFFSET 0x04
  53. #define PCI_STATUS_MASK 0xFFFF0000
  54. #define PCI_STATUS_SHIFT 16
  55. #define PCI_CLASS_CODE_OFFSET 0x08
  56. #define PCI_CLASS_CODE_MASK 0xFFFFFF00
  57. #define PCI_HEADER_TYPE_OFFSET 0x0C
  58. #define PCI_HEADER_TYPE_MASK 0x00FF0000
  59. #define PCI_HEADER_TYPE_SHIFT 16
  60. #define PCI_BAR_OFFSET 0x10
  61. #define PCI_BAR_COUNT 6
  62. #define PCI_DEFAULT_CAPABILITIES_POINTER_OFFSET 0x34
  63. #define PCI_ALTERNATE_CAPABILITIES_POINTER_OFFSET 0x14
  64. #define PCI_INTERRUPT_LINE_OFFSET 0x3C
  65. #define PCI_BRIDGE_BUS_NUMBERS_OFFSET 0x18
  66. #define PCI_BRIDGE_IO_BAR_OFFSET 0x1C
  67. #define PCI_BRIDGE_MEMORY_BAR_OFFSET 0x20
  68. #define PCI_BRIDGE_PREFETCHABLE_MEMORY_BAR_OFFSET 0x24
  69. #define PCI_BRIDGE_PREFETCHABLE_MEMORY_BASE_HIGH_OFFSET 0x28
  70. #define PCI_BRIDGE_PREFETCHABLE_MEMORY_LIMIT_HIGH_OFFSET 0x2C
  71. #define PCI_BRIDGE_IO_HIGH_BAR_OFFSET 0x30
  72. #define PCI_BRIDGE_BUS_MASK 0x000000FF
  73. #define PCI_BRIDGE_SECONDARY_BUS_SHIFT 8
  74. #define PCI_BRIDGE_SECONDARY_BUS_MASK 0x0000FF00
  75. #define PCI_BRIDGE_SUBORDINATE_BUS_SHIFT 16
  76. #define PCI_BRIDGE_SUBORDINATE_BUS_MASK 0x00FF0000
  77. #define PCI_BRIDGE_SECONDARY_LATENCY_TIMER_MASK 0xFF000000
  78. #define PCI_BRIDGE_IO_BASE_DECODE_MASK 0x000F
  79. #define PCI_BRIDGE_IO_BASE_DECODE_32_BIT 0x0001
  80. #define PCI_BRIDGE_IO_BASE_MASK 0x00F0
  81. #define PCI_BRIDGE_IO_LIMIT_DECODE_MASK 0x0F00
  82. #define PCI_BRIDGE_IO_LIMIT_DECODE_32_BIT 0x0100
  83. #define PCI_BRIDGE_IO_LIMIT_MASK 0xF000
  84. #define PCI_BRIDGE_IO_BASE_ADDRESS_SHIFT 8
  85. #define PCI_BRIDGE_IO_BASE_HIGH_MASK 0x0000FFFF
  86. #define PCI_BRIDGE_IO_LIMIT_HIGH_MASK 0xFFFF0000
  87. #define PCI_BRIDGE_IO_BASE_HIGH_ADDRESS_SHIFT 16
  88. #define PCI_BRIDGE_MEMORY_BASE_MASK 0x0000FFF0
  89. #define PCI_BRIDGE_MEMORY_BASE_ADDRESS_SHIFT 16
  90. #define PCI_BRIDGE_MEMORY_LIMIT_MASK 0xFFF00000
  91. #define PCI_BRIDGE_PREFETCHABLE_MEMORY_BASE_DECODE_MASK 0x0000000F
  92. #define PCI_BRIDGE_PREFETCHABLE_MEMORY_BASE_DECODE_64_BIT 0x00000001
  93. #define PCI_BRIDGE_PREFETCHABLE_MEMORY_BASE_MASK 0x0000FFF0
  94. #define PCI_BRIDGE_PREFETCHABLE_MEMORY_BASE_ADDRESS_SHIFT 16
  95. #define PCI_BRIDGE_PREFETCHABLE_MEMORY_LIMIT_MASK 0xFFF00000
  96. #define PCI_BRIDGE_PREFETCHABLE_MEMORY_LIMIT_DECODE_MASK 0x000F0000
  97. #define PCI_BRIDGE_PREFETCHABLE_MEMORY_LIMIT_DECODE_64_BIT 0x00010000
  98. #define PCI_BRIDGE_PREFETCHABLE_MEMORY_HIGH_ADDRESS_SHIFT 32
  99. #define PCI_BRIDGE_IO_GRANULARITY 4096
  100. #define PCI_BRIDGE_MEMORY_GRANULARITY (1024 * 1024)
  101. //
  102. // PCI Control register definitions.
  103. //
  104. #define PCI_CONTROL_IO_DECODE_ENABLED 0x0001
  105. #define PCI_CONTROL_MEMORY_DECODE_ENABLED 0x0002
  106. #define PCI_CONTROL_BUS_MASTER_ENABLED 0x0004
  107. #define PCI_CONTROL_SPECIAL_CYCLES_ENABLED 0x0008
  108. #define PCI_CONTROL_WRITE_INVALIDATE_ENABLED 0x0010
  109. #define PCI_CONTROL_VGA_PALETTE_SNOOP_ENABLED 0x0020
  110. #define PCI_CONTROL_PARITY_ERROR_RESPONSE_ENABLED 0x0040
  111. #define PCI_CONTROL_STEPPING_CONTROL_ENABLED 0x0080
  112. #define PCI_CONTROL_SERR_ENABLED 0x0100
  113. #define PCI_CONTROL_FAST_BACK_TO_BACK_ENABLED 0x0200
  114. #define PCI_CONTROL_INTERRUPT_DISABLE 0x0400
  115. //
  116. // PCI Status register definitions.
  117. //
  118. #define PCI_STATUS_INTERRUPT_ASSERTED 0x0008
  119. #define PCI_STATUS_CAPABILITIES_LIST 0x0010
  120. #define PCI_STATUS_66MHZ_CAPABLE 0x0020
  121. #define PCI_STATUS_FAST_BACK_TO_BACK_CAPABLE 0x0080
  122. #define PCI_STATUS_MASTER_DATA_PARITY_ERROR 0x0100
  123. #define PCI_STATUS_DEVSEL_TIMING_MASK 0x0600
  124. #define PCI_STATUS_DEVSEL_TIMING_SHIFT 9
  125. #define PCI_STATUS_DEVSEL_FAST 0x0
  126. #define PCI_STATUS_DEVSEL_MEDIUM 0x1
  127. #define PCI_STATUS_DEVSEL_SLOW 0x2
  128. #define PCI_STATUS_TARGET_ABORT_SIGNALED 0x0800
  129. #define PCI_STATUS_TARGET_ABORT_RECEIVED 0x1000
  130. #define PCI_STATUS_MASTER_ABORT_RECEIVED 0x2000
  131. #define PCI_STATUS_SYSTEM_ERROR_SIGNALED 0x4000
  132. #define PCI_STATUS_PARITY_ERROR_DETECTED 0x8000
  133. //
  134. // PCI Base Address Register bit definitions.
  135. //
  136. #define PCI_BAR_MEMORY_FLAGS_MASK 0x0000000FULL
  137. #define PCI_BAR_IO_FLAGS_MASK 0x00000003
  138. #define PCI_BAR_IO_SPACE 0x00000001
  139. #define PCI_BAR_MEMORY_SIZE_MASK 0x0000006
  140. #define PCI_BAR_MEMORY_32_BIT 0x00000000
  141. #define PCI_BAR_MEMORY_1MB 0x00000002
  142. #define PCI_BAR_MEMORY_64_BIT 0x00000004
  143. #define PCI_BAR_MEMORY_PREFETCHABLE 0x00000008
  144. //
  145. // PCI classes.
  146. //
  147. #define PCI_CLASS_UNKNOWN 0x00
  148. #define PCI_CLASS_MASS_STORAGE 0x01
  149. #define PCI_CLASS_NETWORK 0x02
  150. #define PCI_CLASS_DISPLAY 0x03
  151. #define PCI_CLASS_MULTIMEDIA 0x04
  152. #define PCI_CLASS_MEMORY 0x05
  153. #define PCI_CLASS_BRIDGE 0x06
  154. #define PCI_CLASS_SIMPLE_COMMUNICATION 0x07
  155. #define PCI_CLASS_GENERAL_PERIPHERAL 0x08
  156. #define PCI_CLASS_INPUT 0x09
  157. #define PCI_CLASS_DOCKING_STATION 0x0A
  158. #define PCI_CLASS_PROCESSOR 0x0B
  159. #define PCI_CLASS_SERIAL_BUS 0x0C
  160. #define PCI_CLASS_WIRELESS 0x0D
  161. #define PCI_CLASS_INTELLIGENT_IO 0x0E
  162. #define PCI_CLASS_SATELLITE_COMMUNICATION 0x0F
  163. #define PCI_CLASS_ENCRYPTION 0x10
  164. #define PCI_CLASS_DATA_ACQUISITION 0x11
  165. #define PCI_CLASS_VENDOR 0xFF
  166. //
  167. // PCI subclasses (and interfaces).
  168. //
  169. #define PCI_CLASS_UNKNOWN_NON_VGA 0x0000
  170. #define PCI_CLASS_UNKNOWN_VGA 0x0100
  171. #define PCI_CLASS_MASS_STORAGE_IDE_MASK 0xFF00
  172. #define PCI_CLASS_MASS_STORAGE_IDE 0x0100
  173. #define PCI_CLASS_BRIDGE_ISA 0x0100
  174. #define PCI_CLASS_BRIDGE_PCI 0x0400
  175. #define PCI_CLASS_BRIDGE_PCI_SUBTRACTIVE 0x0401
  176. #define PCI_CLASS_SIMPLE_COMMUNICATION_XT_UART 0x0000
  177. #define PCI_CLASS_SIMPLE_COMMUNICATION_16450 0x0001
  178. #define PCI_CLASS_SIMPLE_COMMUNICATION_16550 0x0002
  179. #define PCI_CLASS_SIMPLE_COMMUNICATION_PARALLEL 0x0100
  180. #define PCI_CLASS_SIMPLE_COMMUNICATION_BIDIRECTIONAL_PARALLEL 0x0101
  181. #define PCI_CLASS_SIMPLE_COMMUNICATION_ECP_PARALLEL 0x0102
  182. #define PCI_CLASS_SIMPLE_COMMUNICATION_OTHER 0x8000
  183. #define PCI_CLASS_SERIAL_BUS_USB_UHCI 0x0300
  184. #define PCI_CLASS_SERIAL_BUS_USB_OHCI 0x0310
  185. #define PCI_CLASS_SERIAL_BUS_USB_EHCI 0x0320
  186. #define PCI_CLASS_GENERAL_SD_HOST_NO_DMA 0x0500
  187. #define PCI_CLASS_GENERAL_SD_HOST 0x0501
  188. //
  189. // Header type definitions.
  190. //
  191. #define PCI_HEADER_TYPE_STANDARD 0x00
  192. #define PCI_HEADER_TYPE_PCI_TO_PCI_BRIDGE 0x01
  193. #define PCI_HEADER_TYPE_CARDBUS_BRIDGE 0x02
  194. #define PCI_HEADER_TYPE_VALUE_MASK 0x7F
  195. //
  196. // Header type flags.
  197. //
  198. #define PCI_HEADER_TYPE_FLAG_MULTIPLE_FUNCTIONS 0x80
  199. //
  200. // Define the PCI capability pointer mask. The bottom two bits are reserved.
  201. //
  202. #define PCI_CAPABILITY_POINTER_MASK 0xFC
  203. //
  204. // PCI capability list definitions.
  205. //
  206. #define PCI_CAPABILITY_LIST_ID_MASK 0x00FF
  207. #define PCI_CAPABILITY_LIST_ID_SHIFT 0
  208. #define PCI_CAPABILITY_LIST_NEXT_POINTER_MASK 0xFF00
  209. #define PCI_CAPABILITY_LIST_NEXT_POINTER_SHIFT 8
  210. //
  211. // PCI capability definitions.
  212. //
  213. #define PCI_CAPABILITY_POWER_MANAGEMENT_INTERFACE 0x01
  214. #define PCI_CAPABILITY_ACCELERATED_GRAPHICS_PORT 0x02
  215. #define PCI_CAPABILITY_VITAL_PRODUCT_DATA 0x03
  216. #define PCI_CAPABILITY_SLOT_IDENTIFICATION 0x04
  217. #define PCI_CAPABILITY_MSI 0x05
  218. #define PCI_CAPABILITY_COMPACT_PCI_HOT_SWAP 0x06
  219. #define PCI_CAPABILITY_PCI_X 0x07
  220. #define PCI_CAPABILITY_HYPER_TRANSPORT 0x08
  221. #define PCI_CAPABILITY_VENDOR_SPECIFIC 0x09
  222. #define PCI_CAPABILITY_DEBUG_PORT 0x0A
  223. #define PCI_CAPABILITY_COMPACT_PCI_CONTROL 0x0B
  224. #define PCI_CAPABILITY_HOT_PLUG 0x0C
  225. #define PCI_CAPABILITY_BRIDGE_SUBSYSTEM_VENDOR_ID 0x0D
  226. #define PCI_CAPABILITY_ACCELERATED_GRAPHICS_PORT_8X 0x0E
  227. #define PCI_CAPABILITY_SECURE_DEVICE 0x0F
  228. #define PCI_CAPABILITY_PCI_EXPRESS 0x10
  229. #define PCI_CAPABILITY_MSI_X 0x11
  230. //
  231. // Define the PCI MSI flags.
  232. //
  233. #define PCI_MSI_FLAG_64_BIT_CAPABLE 0x00000001
  234. #define PCI_MSI_FLAG_MASKABLE 0x00000002
  235. //
  236. // ------------------------------------------------------ Data Type Definitions
  237. //
  238. typedef
  239. ULONGLONG
  240. (*PPCI_READ_CONFIG) (
  241. UCHAR Bus,
  242. UCHAR Device,
  243. UCHAR Function,
  244. ULONG Register,
  245. ULONG AccessSize
  246. );
  247. /*++
  248. Routine Description:
  249. This routine reads from PCI Configuration Space.
  250. Arguments:
  251. Bus - Supplies the bus number to read from.
  252. Device - Supplies the device number to read from. Valid values are 0 to 31.
  253. Function - Supplies the PCI function to read from. Valid values are 0 to 7.
  254. Register - Supplies the configuration register to read from.
  255. AccessSize - Supplies the size of the access to make. Valid values are 1,
  256. 2, 4, and 8.
  257. Return Value:
  258. Returns the value read from the bus, or 0xFFFFFFFF on error.
  259. --*/
  260. typedef
  261. VOID
  262. (*PPCI_WRITE_CONFIG) (
  263. UCHAR Bus,
  264. UCHAR Device,
  265. UCHAR Function,
  266. ULONG Register,
  267. ULONG AccessSize,
  268. ULONGLONG Value
  269. );
  270. /*++
  271. Routine Description:
  272. This routine writes to PCI Configuration Space.
  273. Arguments:
  274. Bus - Supplies the bus number to write to.
  275. Device - Supplies the device number to write to. Valid values are 0 to 31.
  276. Function - Supplies the PCI function to write to. Valid values are 0 to 7.
  277. Register - Supplies the configuration register to write to.
  278. AccessSize - Supplies the size of the access to make. Valid values are 1,
  279. 2, 4, and 8.
  280. Value - Supplies the value to write to the register.
  281. Return Value:
  282. None.
  283. --*/
  284. /*++
  285. Structure Description:
  286. This structure defines a PCI child device.
  287. Members:
  288. DeviceNumber - Stores the device/slot number on the parent bus.
  289. Function - Stores the function number on the bus.
  290. VendorId - Stores the Vendor ID of the device.
  291. DeviceId - Stores the Device ID.
  292. --*/
  293. typedef struct _PCI_CHILD {
  294. UCHAR DeviceNumber;
  295. UCHAR Function;
  296. USHORT VendorId;
  297. USHORT DeviceId;
  298. } PCI_CHILD, *PPCI_CHILD;
  299. //
  300. // This enum is a touch confusing, in that when the device type is function,
  301. // then PCI acts as the bus driver. When the device type is bus or bridge, PCI
  302. // is acting as the functional driver.
  303. //
  304. typedef enum _PCI_DEVICE_TYPE {
  305. PciDeviceInvalid,
  306. PciDeviceBus,
  307. PciDeviceBridge,
  308. PciDeviceFunction,
  309. } PCI_DEVICE_TYPE, *PPCI_DEVICE_TYPE;
  310. /*++
  311. Structure Description:
  312. This structure defines the set of PCI Base Address Registers, also known as
  313. BARs.
  314. Members:
  315. U - Stores the union of six 32 bit BARs or three 64 bit BARs.
  316. --*/
  317. typedef struct _PCI_BASE_ADDRESS_REGISTER_SET {
  318. union {
  319. ULONG Bar32[PCI_BAR_COUNT];
  320. ULONGLONG Bar64[PCI_BAR_COUNT / 2];
  321. } U;
  322. } PCI_BASE_ADDRESS_REGISTER_SET, *PPCI_BASE_ADDRESS_REGISTER_SET;
  323. /*++
  324. Structure Description:
  325. This structure defines a PCI device's MSI/MSI-X context.
  326. Members:
  327. MsiOffset - Stores the offset into configuration space of the MSI
  328. capability. A value of 0 indicates that it does not exist.
  329. MsiXOffset - Stores the offset into configuration space of the MSI-X
  330. capability. A value of 0 indicates that it does not exist.
  331. MsiFlags - Stores a bitmask of PCI MSI flags. See PCI_MSI_FLAG_* for
  332. definitions.
  333. MsiVectorCount - Stores the number of MSI vectors currently in use.
  334. MsiMaxVectorCount - Stores the maximum number of MSI vectors supported by
  335. the device.
  336. MsiXVectorCount - Stores the number of MSI-X vectors currently in use.
  337. MsiXMaxVectorCount - Stores the maximum number of MSI-X vectors supported
  338. by the device.
  339. MsiXTable - Stores a pointer to the mapped MSI-X vector table.
  340. MsiXPendingArray - Stores a pointer to the mapped MSI-X pending bit array.
  341. MsiXTablePhysicalAddress - Stores the physical address of the MSI-X vector
  342. table.
  343. MsiXPendingArrayPhysicalAddress - Stores the physical address of the MSI-X
  344. pending bit array.
  345. Interface - Stores a pointer to the MSI/MSI-X interface.
  346. --*/
  347. typedef struct _PCI_MSI_CONTEXT {
  348. UCHAR MsiOffset;
  349. UCHAR MsiXOffset;
  350. ULONG MsiFlags;
  351. ULONGLONG MsiVectorCount;
  352. ULONGLONG MsiMaxVectorCount;
  353. ULONGLONG MsiXVectorCount;
  354. ULONGLONG MsiXMaxVectorCount;
  355. volatile PVOID MsiXTable;
  356. volatile PVOID MsiXPendingArray;
  357. PHYSICAL_ADDRESS MsiXTablePhysicalAddress;
  358. PHYSICAL_ADDRESS MsiXPendingArrayPhysicalAddress;
  359. PINTERFACE_PCI_MSI Interface;
  360. } PCI_MSI_CONTEXT, *PPCI_MSI_CONTEXT;
  361. typedef struct _PCI_DEVICE PCI_DEVICE, *PPCI_DEVICE;
  362. /*++
  363. Structure Description:
  364. This structure defines a PCI device.
  365. Members:
  366. Type - Stores which genre of PCI device this is.
  367. BusNumber - Stores the number of this device's PCI bus.
  368. DeviceNumber - Stores the slot number of this device.
  369. FunctionNumber - Stores the function number of this device.
  370. InterruptPin - Stores the interrupt pin that the function uses. This value
  371. comes from read-only configuration space.
  372. DeviceIsBridge - Stores a boolean indicating whether or not the device is a
  373. PCI bridge.
  374. ClassCode - Stores the class code of the device.
  375. Parent - Stores a pointer to the parent PCI device if there is one.
  376. Children - Stores an array allocated in paged pool of the device's children,
  377. if this device is a root bus or PCI bridge.
  378. ChildrenData - Stores an array allocated in paged pool of information about
  379. the device's children. This array parallels the Children array.
  380. ChildCount - Stores the number of children in the array.
  381. ChildSize - Stores the size of the children array, in elements.
  382. ReadConfig - Stores a pointer to a function used to read from configuration
  383. space for buses.
  384. WriteConfig - Stores a pointer to a function used to write to configuration
  385. space for buses.
  386. BarsRead - Stores a boolean indicating if the device's BARs have been read
  387. yet.
  388. BootConfiguration - Stores the state of the BARs as configured by the BIOS.
  389. BootControlRegister - Stores the value of the control register when the
  390. system was booted.
  391. AddressDecodeBits - Stores the values of the BARs after writing all ones
  392. to them and reading them back to see which ones stick.
  393. BarCount - Stores one higher than the index of the highest valid BAR.
  394. PciConfigInterface - Stores a pointer to the config interface.
  395. AcpiBusAddressInterface - Stores a pointer to the ACPI interface.
  396. SpecificPciConfigInterface - Stores a pointer to the specific PCI config
  397. space access interface.
  398. MsiContext - Stores a pointer to the MSI/MSI-X context if the device
  399. supports message based interrupts.
  400. --*/
  401. struct _PCI_DEVICE {
  402. PCI_DEVICE_TYPE Type;
  403. UCHAR BusNumber;
  404. UCHAR DeviceNumber;
  405. UCHAR FunctionNumber;
  406. UCHAR InterruptPin;
  407. BOOL DeviceIsBridge;
  408. ULONG ClassCode;
  409. PPCI_DEVICE Parent;
  410. PDEVICE *Children;
  411. PPCI_CHILD *ChildrenData;
  412. ULONG ChildCount;
  413. ULONG ChildSize;
  414. PPCI_READ_CONFIG ReadConfig;
  415. PPCI_WRITE_CONFIG WriteConfig;
  416. BOOL BarsRead;
  417. PCI_BASE_ADDRESS_REGISTER_SET BootConfiguration;
  418. USHORT BootControlRegister;
  419. PCI_BASE_ADDRESS_REGISTER_SET AddressDecodeBits;
  420. ULONG BarCount;
  421. PINTERFACE_PCI_CONFIG_ACCESS PciConfigInterface;
  422. PINTERFACE_ACPI_BUS_ADDRESS AcpiBusAddressInterface;
  423. PINTERFACE_SPECIFIC_PCI_CONFIG_ACCESS SpecificPciConfigInterface;
  424. PPCI_MSI_CONTEXT MsiContext;
  425. };
  426. /*++
  427. Structure Description:
  428. This structure defines the interface for returning a device's PCI bus
  429. driver's device structure. This is used internally by PCI to create a
  430. complete device tree.
  431. Members:
  432. BusDevice - Stores a pointer to the bus driver context.
  433. --*/
  434. typedef struct _INTERFACE_PCI_BUS_DEVICE {
  435. PVOID BusDevice;
  436. } INTERFACE_PCI_BUS_DEVICE, *PINTERFACE_PCI_BUS_DEVICE;
  437. //
  438. // -------------------------------------------------------------------- Globals
  439. //
  440. extern PDRIVER PciDriver;
  441. //
  442. // Store the UUID of the PCI MSI and MSI-X access.
  443. //
  444. extern UUID PciMessageSignaledInterruptsUuid;
  445. //
  446. // -------------------------------------------------------- Function Prototypes
  447. //
  448. ULONGLONG
  449. PcipRootReadConfig (
  450. UCHAR Bus,
  451. UCHAR Device,
  452. UCHAR Function,
  453. ULONG Register,
  454. ULONG AccessSize
  455. );
  456. /*++
  457. Routine Description:
  458. This routine reads from PCI Configuration Space on the root PCI bus.
  459. Arguments:
  460. Bus - Supplies the bus number to read from.
  461. Device - Supplies the device number to read from. Valid values are 0 to 31.
  462. Function - Supplies the PCI function to read from. Valid values are 0 to 7.
  463. Register - Supplies the configuration register to read from.
  464. AccessSize - Supplies the size of the access to make. Valid values are 1,
  465. 2, 4, and 8.
  466. Return Value:
  467. Returns the value read from the bus, or 0xFFFFFFFF on error.
  468. --*/
  469. VOID
  470. PcipRootWriteConfig (
  471. UCHAR Bus,
  472. UCHAR Device,
  473. UCHAR Function,
  474. ULONG Register,
  475. ULONG AccessSize,
  476. ULONGLONG Value
  477. );
  478. /*++
  479. Routine Description:
  480. This routine writes to PCI Configuration Space on the PCI root bus.
  481. Arguments:
  482. Bus - Supplies the bus number to write to.
  483. Device - Supplies the device number to write to. Valid values are 0 to 31.
  484. Function - Supplies the PCI function to write to. Valid values are 0 to 7.
  485. Register - Supplies the configuration register to write to.
  486. AccessSize - Supplies the size of the access to make. Valid values are 1,
  487. 2, 4, and 8.
  488. Value - Supplies the value to write to the register.
  489. Return Value:
  490. None.
  491. --*/
  492. KSTATUS
  493. PcipMsiCreateContextAndInterface (
  494. PDEVICE Device,
  495. PPCI_DEVICE PciDevice
  496. );
  497. /*++
  498. Routine Description:
  499. This routine initializes the MSI/MSI-X context and interface for the given
  500. PCI device.
  501. Arguments:
  502. Device - Supplies a pointer to the device in need of an MSI/MSI-X context
  503. and interface.
  504. PciDevice - Supplies a pointer to the PCI device context.
  505. Return Value:
  506. Status code.
  507. --*/
  508. VOID
  509. PcipMsiDestroyContextAndInterface (
  510. PDEVICE Device,
  511. PPCI_DEVICE PciDevice
  512. );
  513. /*++
  514. Routine Description:
  515. This routine destroys the given PCI device's MSI context and interface if
  516. they exist.
  517. Arguments:
  518. Device - Supplies a pointer to the device whose MSI/MSI-x context and
  519. interface is to be destroyed.
  520. PciDevice - Supplies a pointer to the PCI device context.
  521. Return Value:
  522. None.
  523. --*/
  524. VOID
  525. PcipGetMsiXBarInformation (
  526. PPCI_DEVICE PciDevice,
  527. PULONG TableBarIndex,
  528. PULONG TableOffset,
  529. PULONG PendingArrayBarIndex,
  530. PULONG PendingArrayOffset
  531. );
  532. /*++
  533. Routine Description:
  534. This routine gets the BAR information for the MSI-X table and pending bit
  535. array out of PCI configuration space.
  536. Arguments:
  537. PciDevice - Supplies a pointer to the PCI device context.
  538. TableBarIndex - Supplies a pointer that receives the index of the BAR
  539. within which the MSI-X table resides.
  540. TableOffset - Supplies a pointer that receives the offset within the BAR
  541. of the MSI-X table.
  542. PendingArrayBarIndex - Supplies a pointer that receives the index of the
  543. BAR within which the MSI-X pending bit array resides.
  544. PendingArrayOffset - Supplies a pointer that receives the offset within the
  545. BAR of the MSI-X pending bit array.
  546. Return Value:
  547. None.
  548. --*/