pci.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  1. /*++
  2. Copyright (c) 2012 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. pci.h
  5. Abstract:
  6. This header contains PCI device interfaces.
  7. Author:
  8. Evan Green 19-Sep-2012
  9. --*/
  10. //
  11. // ------------------------------------------------------------------- Includes
  12. //
  13. //
  14. // ---------------------------------------------------------------- Definitions
  15. //
  16. //
  17. // Interface UUID for PCI Configuration space access.
  18. //
  19. #define UUID_PCI_CONFIG_ACCESS \
  20. {{0x20656854, 0x646F6F77, 0x72612073, 0x6F6C2065}}
  21. //
  22. // Interface UUID for PCI Configuration space access to a specific device.
  23. //
  24. #define UUID_PCI_CONFIG_ACCESS_SPECIFIC \
  25. {{0x796C6576, 0x72616420, 0x6E61206b, 0x65642064}}
  26. //
  27. // Interface UUID for PCI MSI and MSI-X access.
  28. //
  29. #define UUID_PCI_MESSAGE_SIGNALED_INTERRUPTS \
  30. {{0x5BAAFA00, 0x079911E4, 0x9EEA20C9, 0xD0BFFAF6}}
  31. //
  32. // Define the PCI MSI/MSI-X information version.
  33. //
  34. #define PCI_MSI_INTERFACE_INFORMATION_VERSION 1
  35. //
  36. // Define the PCI MSI/MSI-X flags.
  37. //
  38. #define PCI_MSI_INTERFACE_FLAG_ENABLED 0x00000001
  39. #define PCI_MSI_INTERFACE_FLAG_64_BIT_CAPABLE 0x00000002
  40. #define PCI_MSI_INTERFACE_FLAG_MASKABLE 0x00000004
  41. #define PCI_MSI_INTERFACE_FLAG_GLOBAL_MASK 0x00000008
  42. //
  43. // ------------------------------------------------------ Data Type Definitions
  44. //
  45. //
  46. // PCI Configuration Access interface.
  47. //
  48. typedef
  49. KSTATUS
  50. (*PREAD_PCI_CONFIG) (
  51. PVOID DeviceToken,
  52. ULONG Offset,
  53. ULONG AccessSize,
  54. PULONGLONG Value
  55. );
  56. /*++
  57. Routine Description:
  58. This routine reads from a device's PCI configuration space.
  59. Arguments:
  60. DeviceToken - Supplies the device token supplied when the interface was
  61. acquired.
  62. Offset - Supplies the offset in bytes into the PCI configuration space to
  63. read.
  64. AccessSize - Supplies the size of the access to make. Valid values are 1,
  65. 2, 4, and 8.
  66. Value - Supplies a pointer where the value read from PCI configuration
  67. space will be returned on success.
  68. Return Value:
  69. Status code.
  70. --*/
  71. typedef
  72. KSTATUS
  73. (*PWRITE_PCI_CONFIG) (
  74. PVOID DeviceToken,
  75. ULONG Offset,
  76. ULONG AccessSize,
  77. ULONGLONG Value
  78. );
  79. /*++
  80. Routine Description:
  81. This routine writes to a device's PCI configuration space.
  82. Arguments:
  83. DeviceToken - Supplies the device token supplied when the interface was
  84. acquired.
  85. Offset - Supplies the offset in bytes into the PCI configuration space to
  86. write.
  87. AccessSize - Supplies the size of the access to make. Valid values are 1,
  88. 2, 4, and 8.
  89. Value - Supplies the value to write into PCI configuration space.
  90. Return Value:
  91. Status code.
  92. --*/
  93. typedef
  94. KSTATUS
  95. (*PREAD_SPECIFIC_PCI_CONFIG) (
  96. PVOID DeviceToken,
  97. ULONG BusNumber,
  98. ULONG DeviceNumber,
  99. ULONG FunctionNumber,
  100. ULONG Offset,
  101. ULONG AccessSize,
  102. PULONGLONG Value
  103. );
  104. /*++
  105. Routine Description:
  106. This routine reads from a specific device's PCI configuration space.
  107. Arguments:
  108. DeviceToken - Supplies the device token supplied when the interface was
  109. acquired.
  110. BusNumber - Supplies the bus number of the device whose PCI configuration
  111. space should be read from.
  112. DeviceNumber - Supplies the device number of the device whose PCI
  113. configuration space should be read from.
  114. FunctionNumber - Supplies the function number of the device whose PCI
  115. configuration space should be read from.
  116. Offset - Supplies the offset in bytes into the PCI configuration space to
  117. read.
  118. AccessSize - Supplies the size of the access to make. Valid values are 1,
  119. 2, 4, and 8.
  120. Value - Supplies a pointer where the value read from PCI configuration
  121. space will be returned on success.
  122. Return Value:
  123. Status code.
  124. --*/
  125. typedef
  126. KSTATUS
  127. (*PWRITE_SPECIFIC_PCI_CONFIG) (
  128. PVOID DeviceToken,
  129. ULONG BusNumber,
  130. ULONG DeviceNumber,
  131. ULONG FunctionNumber,
  132. ULONG Offset,
  133. ULONG AccessSize,
  134. ULONGLONG Value
  135. );
  136. /*++
  137. Routine Description:
  138. This routine writes to a specific device's PCI configuration space.
  139. Arguments:
  140. DeviceToken - Supplies the device token supplied when the interface was
  141. acquired.
  142. BusNumber - Supplies the bus number of the device whose PCI configuration
  143. space should be written to.
  144. DeviceNumber - Supplies the device number of the device whose PCI
  145. configuration space should be written to.
  146. FunctionNumber - Supplies the function number of the device whose PCI
  147. configuration space should be written to.
  148. Offset - Supplies the offset in bytes into the PCI configuration space to
  149. write.
  150. AccessSize - Supplies the size of the access to make. Valid values are 1,
  151. 2, 4, and 8.
  152. Value - Supplies the value to write into PCI configuration space.
  153. Return Value:
  154. Status code.
  155. --*/
  156. typedef enum _PCI_MSI_TYPE {
  157. PciMsiTypeInvalid,
  158. PciMsiTypeBasic,
  159. PciMsiTypeExtended,
  160. PciMsiTypeMax
  161. } PCI_MSI_TYPE, *PPCI_MSI_TYPE;
  162. /*++
  163. Structure Description:
  164. This structure defines the message signaled interrupt information that can
  165. be queried or set.
  166. Members:
  167. Version - Stores the version of the PCI MSI information structure.
  168. MsiType - Stores the type of MSI data to be set or returned.
  169. Flags - Stores a bitmask of PCI MSI flags. See PCI_MSI_INTERFACE_FLAG_*.
  170. VectorCount - Stores the number of vectors to enable for the PCI device.
  171. On a query request, it returns the number of vectors currenty enabled.
  172. This value is read only for MSI-X.
  173. MaxVectorCount - Stores the maximum number of vectors that can be used on
  174. the PCI device. This value is read-only.
  175. --*/
  176. typedef struct _PCI_MSI_INFORMATION {
  177. ULONG Version;
  178. PCI_MSI_TYPE MsiType;
  179. ULONG Flags;
  180. ULONGLONG VectorCount;
  181. ULONGLONG MaxVectorCount;
  182. } PCI_MSI_INFORMATION, *PPCI_MSI_INFORMATION;
  183. typedef
  184. KSTATUS
  185. (*PMSI_GET_SET_INFORMATION) (
  186. PVOID DeviceToken,
  187. PPCI_MSI_INFORMATION Information,
  188. BOOL Set
  189. );
  190. /*++
  191. Routine Description:
  192. This routine gets or sets MSI/MSI-X information for the given PCI device.
  193. Returned information includes whether or not MSI/MSI-X is enabled, uses
  194. 64-bit addresses, is maskable, etc. Information to set includes enabling
  195. and disabling MSI/MSI-X, the MSI vector count, and the MSI-X global mask.
  196. Arguments:
  197. DeviceToken - Supplies the device token supplied when the interface was
  198. acquired.
  199. Information - Supplies a pointer to a structure that either receives the
  200. requested information or contains the information to set. In both
  201. cases, the caller should specify the structure version and the MSI
  202. type - basic (MSI) or extended (MSI-X) - before passing it to the
  203. routine.
  204. Set - Supplies a boolean indicating whether to get or set the MSI/MSI-X
  205. information.
  206. Return Value:
  207. Status code.
  208. --*/
  209. typedef
  210. KSTATUS
  211. (*PMSI_SET_VECTORS) (
  212. PVOID DeviceToken,
  213. PCI_MSI_TYPE MsiType,
  214. ULONGLONG Vector,
  215. ULONGLONG VectorIndex,
  216. ULONGLONG VectorCount,
  217. PPROCESSOR_SET Processors
  218. );
  219. /*++
  220. Routine Description:
  221. This routine sets the address and data for the given contiguous MSI/MSI-X
  222. vectors.
  223. Arguments:
  224. DeviceToken - Supplies the device token supplied when the interface was
  225. acquired.
  226. MsiType - Supplies the type of the MSI vector.
  227. Vector - Supplies the starting vector to be set at the given vector index.
  228. VectorIndex - Supplies the index into the vector table where this vector
  229. information should be written. This is only valid for MSI-X.
  230. VectorCount - Supplies the number of contiguous vectors to set starting at
  231. the given vector and index.
  232. Processors - Supplies the set of processors that the MSIs should utilize.
  233. Return Value:
  234. Status code.
  235. --*/
  236. typedef
  237. KSTATUS
  238. (*PMSI_MASK_VECTORS) (
  239. PVOID DeviceToken,
  240. PCI_MSI_TYPE MsiType,
  241. ULONGLONG VectorIndex,
  242. ULONGLONG VectorCount,
  243. BOOL MaskVector
  244. );
  245. /*++
  246. Routine Description:
  247. This routine masks or unmasks a set of contiguous MSI/MSI-X vectors for the
  248. given PCI device.
  249. Arguments:
  250. DeviceToken - Supplies the device token supplied when the interface was
  251. acquired.
  252. MsiType - Supplies the type of the MSI vector.
  253. VectorIndex - Supplies the starting index of the vectors that are to be
  254. masked or unmasked.
  255. VectorCount - Supplies the number fo contiguous vectors to mask or unmask
  256. starting at the given index.
  257. MaskVectors - Supplies a boolean indicating whether the vector should be
  258. masked (TRUE) or unmasked (FALSE).
  259. Return Value:
  260. Status code.
  261. --*/
  262. typedef
  263. KSTATUS
  264. (*PMSI_IS_VECTOR_MASKED) (
  265. PVOID DeviceToken,
  266. PCI_MSI_TYPE MsiType,
  267. ULONGLONG VectorIndex,
  268. PBOOL Masked
  269. );
  270. /*++
  271. Routine Description:
  272. This routine determines whether or not an MSI/MSI-X vector for the given
  273. PCI device is masked.
  274. Arguments:
  275. DeviceToken - Supplies the device token supplied when the interface was
  276. acquired.
  277. MsiType - Supplies the type of the MSI vector.
  278. VectorIndex - Supplies the index of the vector whose masked state is to be
  279. returned.
  280. Masked - Supplies a pointer to a boolean that receives whether or not the
  281. vector is masked.
  282. Return Value:
  283. Status code.
  284. --*/
  285. typedef
  286. KSTATUS
  287. (*PMSI_IS_VECTOR_PENDING) (
  288. PVOID DeviceToken,
  289. PCI_MSI_TYPE MsiType,
  290. ULONGLONG VectorIndex,
  291. PBOOL Pending
  292. );
  293. /*++
  294. Routine Description:
  295. This routine determines whether or not an MSI/MSI-X vector for the given
  296. PCI device is pending.
  297. Arguments:
  298. DeviceToken - Supplies the device token supplied when the interface was
  299. acquired.
  300. MsiType - Supplies the type of the MSI vector.
  301. VectorIndex - Supplies the index of the vector whose pending state is to be
  302. returned.
  303. Pending - Supplies a pointer to a boolean that receives whether or not the
  304. vector has a pending interrupt.
  305. Return Value:
  306. Status code.
  307. --*/
  308. /*++
  309. Structure Description:
  310. This structure defines the interface for a device to access its PCI
  311. configuration space.
  312. Members:
  313. ReadPciConfig - Stores a pointer to a function that can be used to read
  314. PCI configuration space.
  315. WritePciConfig - Stores a pointer to a function that can be used to write
  316. to PCI configuration space.
  317. DeviceToken - Stores an opaque token passed to the read and write
  318. functions that uniquely identifies the device.
  319. --*/
  320. typedef struct _INTERFACE_PCI_CONFIG_ACCESS {
  321. PREAD_PCI_CONFIG ReadPciConfig;
  322. PWRITE_PCI_CONFIG WritePciConfig;
  323. PVOID DeviceToken;
  324. } INTERFACE_PCI_CONFIG_ACCESS, *PINTERFACE_PCI_CONFIG_ACCESS;
  325. /*++
  326. Structure Description:
  327. This structure defines the interface exposed by a PCI bus or bridge that
  328. allows access to a specific device's PCI configuration space.
  329. Members:
  330. ReadPciConfig - Stores a pointer to a function that can be used to read
  331. PCI configuration space.
  332. WritePciConfig - Stores a pointer to a function that can be used to write
  333. to PCI configuration space.
  334. DeviceToken - Stores an opaque token passed to the read and write
  335. functions that uniquely identifies the device.
  336. --*/
  337. typedef struct _INTERFACE_SPECIFIC_PCI_CONFIG_ACCESS {
  338. PREAD_SPECIFIC_PCI_CONFIG ReadPciConfig;
  339. PWRITE_SPECIFIC_PCI_CONFIG WritePciConfig;
  340. PVOID DeviceToken;
  341. } INTERFACE_SPECIFIC_PCI_CONFIG_ACCESS, *PINTERFACE_SPECIFIC_PCI_CONFIG_ACCESS;
  342. /*++
  343. Structure Description:
  344. This structure defines the interface for a PCI device to access its MSI and
  345. MSI-X configuration information, if supported.
  346. Members:
  347. GetSetInformation - Stores a pointer to a function that can be used to
  348. get or set the MSI or MSI-X information. Includes the ability to enable
  349. MSI/MSI-X.
  350. SetVectors - Stores a pointer to a function that can be used to configure a
  351. contiguous set of MSI/MSI-X vectors.
  352. MaskVectors - Stores a pointer to a function that can be used to mask or
  353. unmask a contiguous set of MSI or MSI-X vectors.
  354. IsVectorMasked - Stores a pointer to a function that can be used to
  355. determine whether or not a given vector is masked.
  356. IsVectorPending - Stores a pointer to a function that can be used to
  357. determine whether or not a given vector is pending.
  358. DeviceToken - Stores an oqaque token passed to the query and set functions
  359. that uniquely identifies the device.
  360. --*/
  361. typedef struct _INTERFACE_PCI_MSI {
  362. PMSI_GET_SET_INFORMATION GetSetInformation;
  363. PMSI_SET_VECTORS SetVectors;
  364. PMSI_MASK_VECTORS MaskVectors;
  365. PMSI_IS_VECTOR_MASKED IsVectorMasked;
  366. PMSI_IS_VECTOR_PENDING IsVectorPending;
  367. PVOID DeviceToken;
  368. } INTERFACE_PCI_MSI, *PINTERFACE_PCI_MSI;
  369. //
  370. // -------------------------------------------------------------------- Globals
  371. //
  372. //
  373. // -------------------------------------------------------- Function Prototypes
  374. //