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.

Pci22.h 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869
  1. /** @file
  2. Support for PCI 2.2 standard.
  3. This file includes the definitions in the following specifications,
  4. PCI Local Bus Specification, 2.2
  5. PCI-to-PCI Bridge Architecture Specification, Revision 1.2
  6. PC Card Standard, 8.0
  7. PCI Power Management Interface Specifiction, Revision 1.2
  8. Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
  9. Copyright (c) 2014 - 2015, Hewlett-Packard Development Company, L.P.<BR>
  10. This program and the accompanying materials
  11. are licensed and made available under the terms and conditions of the BSD License
  12. which accompanies this distribution. The full text of the license may be found at
  13. http://opensource.org/licenses/bsd-license.php
  14. THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
  15. WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
  16. **/
  17. #ifndef _PCI22_H_
  18. #define _PCI22_H_
  19. FILE_LICENCE ( BSD3 );
  20. #define PCI_MAX_BUS 255
  21. #define PCI_MAX_DEVICE 31
  22. #define PCI_MAX_FUNC 7
  23. #pragma pack(1)
  24. ///
  25. /// Common header region in PCI Configuration Space
  26. /// Section 6.1, PCI Local Bus Specification, 2.2
  27. ///
  28. typedef struct {
  29. UINT16 VendorId;
  30. UINT16 DeviceId;
  31. UINT16 Command;
  32. UINT16 Status;
  33. UINT8 RevisionID;
  34. UINT8 ClassCode[3];
  35. UINT8 CacheLineSize;
  36. UINT8 LatencyTimer;
  37. UINT8 HeaderType;
  38. UINT8 BIST;
  39. } PCI_DEVICE_INDEPENDENT_REGION;
  40. ///
  41. /// PCI Device header region in PCI Configuration Space
  42. /// Section 6.1, PCI Local Bus Specification, 2.2
  43. ///
  44. typedef struct {
  45. UINT32 Bar[6];
  46. UINT32 CISPtr;
  47. UINT16 SubsystemVendorID;
  48. UINT16 SubsystemID;
  49. UINT32 ExpansionRomBar;
  50. UINT8 CapabilityPtr;
  51. UINT8 Reserved1[3];
  52. UINT32 Reserved2;
  53. UINT8 InterruptLine;
  54. UINT8 InterruptPin;
  55. UINT8 MinGnt;
  56. UINT8 MaxLat;
  57. } PCI_DEVICE_HEADER_TYPE_REGION;
  58. ///
  59. /// PCI Device Configuration Space
  60. /// Section 6.1, PCI Local Bus Specification, 2.2
  61. ///
  62. typedef struct {
  63. PCI_DEVICE_INDEPENDENT_REGION Hdr;
  64. PCI_DEVICE_HEADER_TYPE_REGION Device;
  65. } PCI_TYPE00;
  66. ///
  67. /// PCI-PCI Bridge header region in PCI Configuration Space
  68. /// Section 3.2, PCI-PCI Bridge Architecture, Version 1.2
  69. ///
  70. typedef struct {
  71. UINT32 Bar[2];
  72. UINT8 PrimaryBus;
  73. UINT8 SecondaryBus;
  74. UINT8 SubordinateBus;
  75. UINT8 SecondaryLatencyTimer;
  76. UINT8 IoBase;
  77. UINT8 IoLimit;
  78. UINT16 SecondaryStatus;
  79. UINT16 MemoryBase;
  80. UINT16 MemoryLimit;
  81. UINT16 PrefetchableMemoryBase;
  82. UINT16 PrefetchableMemoryLimit;
  83. UINT32 PrefetchableBaseUpper32;
  84. UINT32 PrefetchableLimitUpper32;
  85. UINT16 IoBaseUpper16;
  86. UINT16 IoLimitUpper16;
  87. UINT8 CapabilityPtr;
  88. UINT8 Reserved[3];
  89. UINT32 ExpansionRomBAR;
  90. UINT8 InterruptLine;
  91. UINT8 InterruptPin;
  92. UINT16 BridgeControl;
  93. } PCI_BRIDGE_CONTROL_REGISTER;
  94. ///
  95. /// PCI-to-PCI Bridge Configuration Space
  96. /// Section 3.2, PCI-PCI Bridge Architecture, Version 1.2
  97. ///
  98. typedef struct {
  99. PCI_DEVICE_INDEPENDENT_REGION Hdr;
  100. PCI_BRIDGE_CONTROL_REGISTER Bridge;
  101. } PCI_TYPE01;
  102. typedef union {
  103. PCI_TYPE00 Device;
  104. PCI_TYPE01 Bridge;
  105. } PCI_TYPE_GENERIC;
  106. ///
  107. /// CardBus Conroller Configuration Space,
  108. /// Section 4.5.1, PC Card Standard. 8.0
  109. ///
  110. typedef struct {
  111. UINT32 CardBusSocketReg; ///< Cardus Socket/ExCA Base
  112. UINT8 Cap_Ptr;
  113. UINT8 Reserved;
  114. UINT16 SecondaryStatus; ///< Secondary Status
  115. UINT8 PciBusNumber; ///< PCI Bus Number
  116. UINT8 CardBusBusNumber; ///< CardBus Bus Number
  117. UINT8 SubordinateBusNumber; ///< Subordinate Bus Number
  118. UINT8 CardBusLatencyTimer; ///< CardBus Latency Timer
  119. UINT32 MemoryBase0; ///< Memory Base Register 0
  120. UINT32 MemoryLimit0; ///< Memory Limit Register 0
  121. UINT32 MemoryBase1;
  122. UINT32 MemoryLimit1;
  123. UINT32 IoBase0;
  124. UINT32 IoLimit0; ///< I/O Base Register 0
  125. UINT32 IoBase1; ///< I/O Limit Register 0
  126. UINT32 IoLimit1;
  127. UINT8 InterruptLine; ///< Interrupt Line
  128. UINT8 InterruptPin; ///< Interrupt Pin
  129. UINT16 BridgeControl; ///< Bridge Control
  130. } PCI_CARDBUS_CONTROL_REGISTER;
  131. //
  132. // Definitions of PCI class bytes and manipulation macros.
  133. //
  134. #define PCI_CLASS_OLD 0x00
  135. #define PCI_CLASS_OLD_OTHER 0x00
  136. #define PCI_CLASS_OLD_VGA 0x01
  137. #define PCI_CLASS_MASS_STORAGE 0x01
  138. #define PCI_CLASS_MASS_STORAGE_SCSI 0x00
  139. #define PCI_CLASS_MASS_STORAGE_IDE 0x01
  140. #define PCI_CLASS_MASS_STORAGE_FLOPPY 0x02
  141. #define PCI_CLASS_MASS_STORAGE_IPI 0x03
  142. #define PCI_CLASS_MASS_STORAGE_RAID 0x04
  143. #define PCI_CLASS_MASS_STORAGE_OTHER 0x80
  144. #define PCI_CLASS_NETWORK 0x02
  145. #define PCI_CLASS_NETWORK_ETHERNET 0x00
  146. #define PCI_CLASS_NETWORK_TOKENRING 0x01
  147. #define PCI_CLASS_NETWORK_FDDI 0x02
  148. #define PCI_CLASS_NETWORK_ATM 0x03
  149. #define PCI_CLASS_NETWORK_ISDN 0x04
  150. #define PCI_CLASS_NETWORK_OTHER 0x80
  151. #define PCI_CLASS_DISPLAY 0x03
  152. #define PCI_CLASS_DISPLAY_VGA 0x00
  153. #define PCI_IF_VGA_VGA 0x00
  154. #define PCI_IF_VGA_8514 0x01
  155. #define PCI_CLASS_DISPLAY_XGA 0x01
  156. #define PCI_CLASS_DISPLAY_3D 0x02
  157. #define PCI_CLASS_DISPLAY_OTHER 0x80
  158. #define PCI_CLASS_MEDIA 0x04
  159. #define PCI_CLASS_MEDIA_VIDEO 0x00
  160. #define PCI_CLASS_MEDIA_AUDIO 0x01
  161. #define PCI_CLASS_MEDIA_TELEPHONE 0x02
  162. #define PCI_CLASS_MEDIA_OTHER 0x80
  163. #define PCI_CLASS_MEMORY_CONTROLLER 0x05
  164. #define PCI_CLASS_MEMORY_RAM 0x00
  165. #define PCI_CLASS_MEMORY_FLASH 0x01
  166. #define PCI_CLASS_MEMORY_OTHER 0x80
  167. #define PCI_CLASS_BRIDGE 0x06
  168. #define PCI_CLASS_BRIDGE_HOST 0x00
  169. #define PCI_CLASS_BRIDGE_ISA 0x01
  170. #define PCI_CLASS_BRIDGE_EISA 0x02
  171. #define PCI_CLASS_BRIDGE_MCA 0x03
  172. #define PCI_CLASS_BRIDGE_P2P 0x04
  173. #define PCI_IF_BRIDGE_P2P 0x00
  174. #define PCI_IF_BRIDGE_P2P_SUBTRACTIVE 0x01
  175. #define PCI_CLASS_BRIDGE_PCMCIA 0x05
  176. #define PCI_CLASS_BRIDGE_NUBUS 0x06
  177. #define PCI_CLASS_BRIDGE_CARDBUS 0x07
  178. #define PCI_CLASS_BRIDGE_RACEWAY 0x08
  179. #define PCI_CLASS_BRIDGE_OTHER 0x80
  180. #define PCI_CLASS_BRIDGE_ISA_PDECODE 0x80
  181. #define PCI_CLASS_SCC 0x07 ///< Simple communications controllers
  182. #define PCI_SUBCLASS_SERIAL 0x00
  183. #define PCI_IF_GENERIC_XT 0x00
  184. #define PCI_IF_16450 0x01
  185. #define PCI_IF_16550 0x02
  186. #define PCI_IF_16650 0x03
  187. #define PCI_IF_16750 0x04
  188. #define PCI_IF_16850 0x05
  189. #define PCI_IF_16950 0x06
  190. #define PCI_SUBCLASS_PARALLEL 0x01
  191. #define PCI_IF_PARALLEL_PORT 0x00
  192. #define PCI_IF_BI_DIR_PARALLEL_PORT 0x01
  193. #define PCI_IF_ECP_PARALLEL_PORT 0x02
  194. #define PCI_IF_1284_CONTROLLER 0x03
  195. #define PCI_IF_1284_DEVICE 0xFE
  196. #define PCI_SUBCLASS_MULTIPORT_SERIAL 0x02
  197. #define PCI_SUBCLASS_MODEM 0x03
  198. #define PCI_IF_GENERIC_MODEM 0x00
  199. #define PCI_IF_16450_MODEM 0x01
  200. #define PCI_IF_16550_MODEM 0x02
  201. #define PCI_IF_16650_MODEM 0x03
  202. #define PCI_IF_16750_MODEM 0x04
  203. #define PCI_SUBCLASS_SCC_OTHER 0x80
  204. #define PCI_CLASS_SYSTEM_PERIPHERAL 0x08
  205. #define PCI_SUBCLASS_PIC 0x00
  206. #define PCI_IF_8259_PIC 0x00
  207. #define PCI_IF_ISA_PIC 0x01
  208. #define PCI_IF_EISA_PIC 0x02
  209. #define PCI_IF_APIC_CONTROLLER 0x10 ///< I/O APIC interrupt controller , 32 bye none-prefectable memory.
  210. #define PCI_IF_APIC_CONTROLLER2 0x20
  211. #define PCI_SUBCLASS_DMA 0x01
  212. #define PCI_IF_8237_DMA 0x00
  213. #define PCI_IF_ISA_DMA 0x01
  214. #define PCI_IF_EISA_DMA 0x02
  215. #define PCI_SUBCLASS_TIMER 0x02
  216. #define PCI_IF_8254_TIMER 0x00
  217. #define PCI_IF_ISA_TIMER 0x01
  218. #define PCI_IF_EISA_TIMER 0x02
  219. #define PCI_SUBCLASS_RTC 0x03
  220. #define PCI_IF_GENERIC_RTC 0x00
  221. #define PCI_IF_ISA_RTC 0x01
  222. #define PCI_SUBCLASS_PNP_CONTROLLER 0x04 ///< HotPlug Controller
  223. #define PCI_SUBCLASS_PERIPHERAL_OTHER 0x80
  224. #define PCI_CLASS_INPUT_DEVICE 0x09
  225. #define PCI_SUBCLASS_KEYBOARD 0x00
  226. #define PCI_SUBCLASS_PEN 0x01
  227. #define PCI_SUBCLASS_MOUSE_CONTROLLER 0x02
  228. #define PCI_SUBCLASS_SCAN_CONTROLLER 0x03
  229. #define PCI_SUBCLASS_GAMEPORT 0x04
  230. #define PCI_IF_GAMEPORT 0x00
  231. #define PCI_IF_GAMEPORT1 0x10
  232. #define PCI_SUBCLASS_INPUT_OTHER 0x80
  233. #define PCI_CLASS_DOCKING_STATION 0x0A
  234. #define PCI_SUBCLASS_DOCKING_GENERIC 0x00
  235. #define PCI_SUBCLASS_DOCKING_OTHER 0x80
  236. #define PCI_CLASS_PROCESSOR 0x0B
  237. #define PCI_SUBCLASS_PROC_386 0x00
  238. #define PCI_SUBCLASS_PROC_486 0x01
  239. #define PCI_SUBCLASS_PROC_PENTIUM 0x02
  240. #define PCI_SUBCLASS_PROC_ALPHA 0x10
  241. #define PCI_SUBCLASS_PROC_POWERPC 0x20
  242. #define PCI_SUBCLASS_PROC_MIPS 0x30
  243. #define PCI_SUBCLASS_PROC_CO_PORC 0x40 ///< Co-Processor
  244. #define PCI_CLASS_SERIAL 0x0C
  245. #define PCI_CLASS_SERIAL_FIREWIRE 0x00
  246. #define PCI_IF_1394 0x00
  247. #define PCI_IF_1394_OPEN_HCI 0x10
  248. #define PCI_CLASS_SERIAL_ACCESS_BUS 0x01
  249. #define PCI_CLASS_SERIAL_SSA 0x02
  250. #define PCI_CLASS_SERIAL_USB 0x03
  251. #define PCI_IF_UHCI 0x00
  252. #define PCI_IF_OHCI 0x10
  253. #define PCI_IF_USB_OTHER 0x80
  254. #define PCI_IF_USB_DEVICE 0xFE
  255. #define PCI_CLASS_SERIAL_FIBRECHANNEL 0x04
  256. #define PCI_CLASS_SERIAL_SMB 0x05
  257. #define PCI_CLASS_WIRELESS 0x0D
  258. #define PCI_SUBCLASS_IRDA 0x00
  259. #define PCI_SUBCLASS_IR 0x01
  260. #define PCI_SUBCLASS_RF 0x10
  261. #define PCI_SUBCLASS_WIRELESS_OTHER 0x80
  262. #define PCI_CLASS_INTELLIGENT_IO 0x0E
  263. #define PCI_CLASS_SATELLITE 0x0F
  264. #define PCI_SUBCLASS_TV 0x01
  265. #define PCI_SUBCLASS_AUDIO 0x02
  266. #define PCI_SUBCLASS_VOICE 0x03
  267. #define PCI_SUBCLASS_DATA 0x04
  268. #define PCI_SECURITY_CONTROLLER 0x10 ///< Encryption and decryption controller
  269. #define PCI_SUBCLASS_NET_COMPUT 0x00
  270. #define PCI_SUBCLASS_ENTERTAINMENT 0x10
  271. #define PCI_SUBCLASS_SECURITY_OTHER 0x80
  272. #define PCI_CLASS_DPIO 0x11
  273. #define PCI_SUBCLASS_DPIO 0x00
  274. #define PCI_SUBCLASS_DPIO_OTHER 0x80
  275. /**
  276. Macro that checks whether the Base Class code of device matched.
  277. @param _p Specified device.
  278. @param c Base Class code needs matching.
  279. @retval TRUE Base Class code matches the specified device.
  280. @retval FALSE Base Class code doesn't match the specified device.
  281. **/
  282. #define IS_CLASS1(_p, c) ((_p)->Hdr.ClassCode[2] == (c))
  283. /**
  284. Macro that checks whether the Base Class code and Sub-Class code of device matched.
  285. @param _p Specified device.
  286. @param c Base Class code needs matching.
  287. @param s Sub-Class code needs matching.
  288. @retval TRUE Base Class code and Sub-Class code match the specified device.
  289. @retval FALSE Base Class code and Sub-Class code don't match the specified device.
  290. **/
  291. #define IS_CLASS2(_p, c, s) (IS_CLASS1 (_p, c) && ((_p)->Hdr.ClassCode[1] == (s)))
  292. /**
  293. Macro that checks whether the Base Class code, Sub-Class code and Interface code of device matched.
  294. @param _p Specified device.
  295. @param c Base Class code needs matching.
  296. @param s Sub-Class code needs matching.
  297. @param p Interface code needs matching.
  298. @retval TRUE Base Class code, Sub-Class code and Interface code match the specified device.
  299. @retval FALSE Base Class code, Sub-Class code and Interface code don't match the specified device.
  300. **/
  301. #define IS_CLASS3(_p, c, s, p) (IS_CLASS2 (_p, c, s) && ((_p)->Hdr.ClassCode[0] == (p)))
  302. /**
  303. Macro that checks whether device is a display controller.
  304. @param _p Specified device.
  305. @retval TRUE Device is a display controller.
  306. @retval FALSE Device is not a display controller.
  307. **/
  308. #define IS_PCI_DISPLAY(_p) IS_CLASS1 (_p, PCI_CLASS_DISPLAY)
  309. /**
  310. Macro that checks whether device is a VGA-compatible controller.
  311. @param _p Specified device.
  312. @retval TRUE Device is a VGA-compatible controller.
  313. @retval FALSE Device is not a VGA-compatible controller.
  314. **/
  315. #define IS_PCI_VGA(_p) IS_CLASS3 (_p, PCI_CLASS_DISPLAY, PCI_CLASS_DISPLAY_VGA, PCI_IF_VGA_VGA)
  316. /**
  317. Macro that checks whether device is an 8514-compatible controller.
  318. @param _p Specified device.
  319. @retval TRUE Device is an 8514-compatible controller.
  320. @retval FALSE Device is not an 8514-compatible controller.
  321. **/
  322. #define IS_PCI_8514(_p) IS_CLASS3 (_p, PCI_CLASS_DISPLAY, PCI_CLASS_DISPLAY_VGA, PCI_IF_VGA_8514)
  323. /**
  324. Macro that checks whether device is built before the Class Code field was defined.
  325. @param _p Specified device.
  326. @retval TRUE Device is an old device.
  327. @retval FALSE Device is not an old device.
  328. **/
  329. #define IS_PCI_OLD(_p) IS_CLASS1 (_p, PCI_CLASS_OLD)
  330. /**
  331. Macro that checks whether device is a VGA-compatible device built before the Class Code field was defined.
  332. @param _p Specified device.
  333. @retval TRUE Device is an old VGA-compatible device.
  334. @retval FALSE Device is not an old VGA-compatible device.
  335. **/
  336. #define IS_PCI_OLD_VGA(_p) IS_CLASS2 (_p, PCI_CLASS_OLD, PCI_CLASS_OLD_VGA)
  337. /**
  338. Macro that checks whether device is an IDE controller.
  339. @param _p Specified device.
  340. @retval TRUE Device is an IDE controller.
  341. @retval FALSE Device is not an IDE controller.
  342. **/
  343. #define IS_PCI_IDE(_p) IS_CLASS2 (_p, PCI_CLASS_MASS_STORAGE, PCI_CLASS_MASS_STORAGE_IDE)
  344. /**
  345. Macro that checks whether device is a SCSI bus controller.
  346. @param _p Specified device.
  347. @retval TRUE Device is a SCSI bus controller.
  348. @retval FALSE Device is not a SCSI bus controller.
  349. **/
  350. #define IS_PCI_SCSI(_p) IS_CLASS2 (_p, PCI_CLASS_MASS_STORAGE, PCI_CLASS_MASS_STORAGE_SCSI)
  351. /**
  352. Macro that checks whether device is a RAID controller.
  353. @param _p Specified device.
  354. @retval TRUE Device is a RAID controller.
  355. @retval FALSE Device is not a RAID controller.
  356. **/
  357. #define IS_PCI_RAID(_p) IS_CLASS2 (_p, PCI_CLASS_MASS_STORAGE, PCI_CLASS_MASS_STORAGE_RAID)
  358. /**
  359. Macro that checks whether device is an ISA bridge.
  360. @param _p Specified device.
  361. @retval TRUE Device is an ISA bridge.
  362. @retval FALSE Device is not an ISA bridge.
  363. **/
  364. #define IS_PCI_LPC(_p) IS_CLASS2 (_p, PCI_CLASS_BRIDGE, PCI_CLASS_BRIDGE_ISA)
  365. /**
  366. Macro that checks whether device is a PCI-to-PCI bridge.
  367. @param _p Specified device.
  368. @retval TRUE Device is a PCI-to-PCI bridge.
  369. @retval FALSE Device is not a PCI-to-PCI bridge.
  370. **/
  371. #define IS_PCI_P2P(_p) IS_CLASS3 (_p, PCI_CLASS_BRIDGE, PCI_CLASS_BRIDGE_P2P, PCI_IF_BRIDGE_P2P)
  372. /**
  373. Macro that checks whether device is a Subtractive Decode PCI-to-PCI bridge.
  374. @param _p Specified device.
  375. @retval TRUE Device is a Subtractive Decode PCI-to-PCI bridge.
  376. @retval FALSE Device is not a Subtractive Decode PCI-to-PCI bridge.
  377. **/
  378. #define IS_PCI_P2P_SUB(_p) IS_CLASS3 (_p, PCI_CLASS_BRIDGE, PCI_CLASS_BRIDGE_P2P, PCI_IF_BRIDGE_P2P_SUBTRACTIVE)
  379. /**
  380. Macro that checks whether device is a 16550-compatible serial controller.
  381. @param _p Specified device.
  382. @retval TRUE Device is a 16550-compatible serial controller.
  383. @retval FALSE Device is not a 16550-compatible serial controller.
  384. **/
  385. #define IS_PCI_16550_SERIAL(_p) IS_CLASS3 (_p, PCI_CLASS_SCC, PCI_SUBCLASS_SERIAL, PCI_IF_16550)
  386. /**
  387. Macro that checks whether device is a Universal Serial Bus controller.
  388. @param _p Specified device.
  389. @retval TRUE Device is a Universal Serial Bus controller.
  390. @retval FALSE Device is not a Universal Serial Bus controller.
  391. **/
  392. #define IS_PCI_USB(_p) IS_CLASS2 (_p, PCI_CLASS_SERIAL, PCI_CLASS_SERIAL_USB)
  393. //
  394. // the definition of Header Type
  395. //
  396. #define HEADER_TYPE_DEVICE 0x00
  397. #define HEADER_TYPE_PCI_TO_PCI_BRIDGE 0x01
  398. #define HEADER_TYPE_CARDBUS_BRIDGE 0x02
  399. #define HEADER_TYPE_MULTI_FUNCTION 0x80
  400. //
  401. // Mask of Header type
  402. //
  403. #define HEADER_LAYOUT_CODE 0x7f
  404. /**
  405. Macro that checks whether device is a PCI-PCI bridge.
  406. @param _p Specified device.
  407. @retval TRUE Device is a PCI-PCI bridge.
  408. @retval FALSE Device is not a PCI-PCI bridge.
  409. **/
  410. #define IS_PCI_BRIDGE(_p) (((_p)->Hdr.HeaderType & HEADER_LAYOUT_CODE) == (HEADER_TYPE_PCI_TO_PCI_BRIDGE))
  411. /**
  412. Macro that checks whether device is a CardBus bridge.
  413. @param _p Specified device.
  414. @retval TRUE Device is a CardBus bridge.
  415. @retval FALSE Device is not a CardBus bridge.
  416. **/
  417. #define IS_CARDBUS_BRIDGE(_p) (((_p)->Hdr.HeaderType & HEADER_LAYOUT_CODE) == (HEADER_TYPE_CARDBUS_BRIDGE))
  418. /**
  419. Macro that checks whether device is a multiple functions device.
  420. @param _p Specified device.
  421. @retval TRUE Device is a multiple functions device.
  422. @retval FALSE Device is not a multiple functions device.
  423. **/
  424. #define IS_PCI_MULTI_FUNC(_p) ((_p)->Hdr.HeaderType & HEADER_TYPE_MULTI_FUNCTION)
  425. ///
  426. /// Rom Base Address in Bridge, defined in PCI-to-PCI Bridge Architecure Specification,
  427. ///
  428. #define PCI_BRIDGE_ROMBAR 0x38
  429. #define PCI_MAX_BAR 0x0006
  430. #define PCI_MAX_CONFIG_OFFSET 0x0100
  431. #define PCI_VENDOR_ID_OFFSET 0x00
  432. #define PCI_DEVICE_ID_OFFSET 0x02
  433. #define PCI_COMMAND_OFFSET 0x04
  434. #define PCI_PRIMARY_STATUS_OFFSET 0x06
  435. #define PCI_REVISION_ID_OFFSET 0x08
  436. #define PCI_CLASSCODE_OFFSET 0x09
  437. #define PCI_CACHELINE_SIZE_OFFSET 0x0C
  438. #define PCI_LATENCY_TIMER_OFFSET 0x0D
  439. #define PCI_HEADER_TYPE_OFFSET 0x0E
  440. #define PCI_BIST_OFFSET 0x0F
  441. #define PCI_BASE_ADDRESSREG_OFFSET 0x10
  442. #define PCI_CARDBUS_CIS_OFFSET 0x28
  443. #define PCI_SVID_OFFSET 0x2C ///< SubSystem Vendor id
  444. #define PCI_SUBSYSTEM_VENDOR_ID_OFFSET 0x2C
  445. #define PCI_SID_OFFSET 0x2E ///< SubSystem ID
  446. #define PCI_SUBSYSTEM_ID_OFFSET 0x2E
  447. #define PCI_EXPANSION_ROM_BASE 0x30
  448. #define PCI_CAPBILITY_POINTER_OFFSET 0x34
  449. #define PCI_INT_LINE_OFFSET 0x3C ///< Interrupt Line Register
  450. #define PCI_INT_PIN_OFFSET 0x3D ///< Interrupt Pin Register
  451. #define PCI_MAXGNT_OFFSET 0x3E ///< Max Grant Register
  452. #define PCI_MAXLAT_OFFSET 0x3F ///< Max Latency Register
  453. //
  454. // defined in PCI-to-PCI Bridge Architecture Specification
  455. //
  456. #define PCI_BRIDGE_PRIMARY_BUS_REGISTER_OFFSET 0x18
  457. #define PCI_BRIDGE_SECONDARY_BUS_REGISTER_OFFSET 0x19
  458. #define PCI_BRIDGE_SUBORDINATE_BUS_REGISTER_OFFSET 0x1a
  459. #define PCI_BRIDGE_SECONDARY_LATENCY_TIMER_OFFSET 0x1b
  460. #define PCI_BRIDGE_STATUS_REGISTER_OFFSET 0x1E
  461. #define PCI_BRIDGE_CONTROL_REGISTER_OFFSET 0x3E
  462. ///
  463. /// Interrupt Line "Unknown" or "No connection" value defined for x86 based system
  464. ///
  465. #define PCI_INT_LINE_UNKNOWN 0xFF
  466. ///
  467. /// PCI Access Data Format
  468. ///
  469. typedef union {
  470. struct {
  471. UINT32 Reg : 8;
  472. UINT32 Func : 3;
  473. UINT32 Dev : 5;
  474. UINT32 Bus : 8;
  475. UINT32 Reserved : 7;
  476. UINT32 Enable : 1;
  477. } Bits;
  478. UINT32 Uint32;
  479. } PCI_CONFIG_ACCESS_CF8;
  480. #pragma pack()
  481. #define EFI_PCI_COMMAND_IO_SPACE BIT0 ///< 0x0001
  482. #define EFI_PCI_COMMAND_MEMORY_SPACE BIT1 ///< 0x0002
  483. #define EFI_PCI_COMMAND_BUS_MASTER BIT2 ///< 0x0004
  484. #define EFI_PCI_COMMAND_SPECIAL_CYCLE BIT3 ///< 0x0008
  485. #define EFI_PCI_COMMAND_MEMORY_WRITE_AND_INVALIDATE BIT4 ///< 0x0010
  486. #define EFI_PCI_COMMAND_VGA_PALETTE_SNOOP BIT5 ///< 0x0020
  487. #define EFI_PCI_COMMAND_PARITY_ERROR_RESPOND BIT6 ///< 0x0040
  488. #define EFI_PCI_COMMAND_STEPPING_CONTROL BIT7 ///< 0x0080
  489. #define EFI_PCI_COMMAND_SERR BIT8 ///< 0x0100
  490. #define EFI_PCI_COMMAND_FAST_BACK_TO_BACK BIT9 ///< 0x0200
  491. //
  492. // defined in PCI-to-PCI Bridge Architecture Specification
  493. //
  494. #define EFI_PCI_BRIDGE_CONTROL_PARITY_ERROR_RESPONSE BIT0 ///< 0x0001
  495. #define EFI_PCI_BRIDGE_CONTROL_SERR BIT1 ///< 0x0002
  496. #define EFI_PCI_BRIDGE_CONTROL_ISA BIT2 ///< 0x0004
  497. #define EFI_PCI_BRIDGE_CONTROL_VGA BIT3 ///< 0x0008
  498. #define EFI_PCI_BRIDGE_CONTROL_VGA_16 BIT4 ///< 0x0010
  499. #define EFI_PCI_BRIDGE_CONTROL_MASTER_ABORT BIT5 ///< 0x0020
  500. #define EFI_PCI_BRIDGE_CONTROL_RESET_SECONDARY_BUS BIT6 ///< 0x0040
  501. #define EFI_PCI_BRIDGE_CONTROL_FAST_BACK_TO_BACK BIT7 ///< 0x0080
  502. #define EFI_PCI_BRIDGE_CONTROL_PRIMARY_DISCARD_TIMER BIT8 ///< 0x0100
  503. #define EFI_PCI_BRIDGE_CONTROL_SECONDARY_DISCARD_TIMER BIT9 ///< 0x0200
  504. #define EFI_PCI_BRIDGE_CONTROL_TIMER_STATUS BIT10 ///< 0x0400
  505. #define EFI_PCI_BRIDGE_CONTROL_DISCARD_TIMER_SERR BIT11 ///< 0x0800
  506. //
  507. // Following are the PCI-CARDBUS bridge control bit, defined in PC Card Standard
  508. //
  509. #define EFI_PCI_BRIDGE_CONTROL_IREQINT_ENABLE BIT7 ///< 0x0080
  510. #define EFI_PCI_BRIDGE_CONTROL_RANGE0_MEMORY_TYPE BIT8 ///< 0x0100
  511. #define EFI_PCI_BRIDGE_CONTROL_RANGE1_MEMORY_TYPE BIT9 ///< 0x0200
  512. #define EFI_PCI_BRIDGE_CONTROL_WRITE_POSTING_ENABLE BIT10 ///< 0x0400
  513. //
  514. // Following are the PCI status control bit
  515. //
  516. #define EFI_PCI_STATUS_CAPABILITY BIT4 ///< 0x0010
  517. #define EFI_PCI_STATUS_66MZ_CAPABLE BIT5 ///< 0x0020
  518. #define EFI_PCI_FAST_BACK_TO_BACK_CAPABLE BIT7 ///< 0x0080
  519. #define EFI_PCI_MASTER_DATA_PARITY_ERROR BIT8 ///< 0x0100
  520. ///
  521. /// defined in PC Card Standard
  522. ///
  523. #define EFI_PCI_CARDBUS_BRIDGE_CAPABILITY_PTR 0x14
  524. #pragma pack(1)
  525. //
  526. // PCI Capability List IDs and records
  527. //
  528. #define EFI_PCI_CAPABILITY_ID_PMI 0x01
  529. #define EFI_PCI_CAPABILITY_ID_AGP 0x02
  530. #define EFI_PCI_CAPABILITY_ID_VPD 0x03
  531. #define EFI_PCI_CAPABILITY_ID_SLOTID 0x04
  532. #define EFI_PCI_CAPABILITY_ID_MSI 0x05
  533. #define EFI_PCI_CAPABILITY_ID_HOTPLUG 0x06
  534. #define EFI_PCI_CAPABILITY_ID_SHPC 0x0C
  535. ///
  536. /// Capabilities List Header
  537. /// Section 6.7, PCI Local Bus Specification, 2.2
  538. ///
  539. typedef struct {
  540. UINT8 CapabilityID;
  541. UINT8 NextItemPtr;
  542. } EFI_PCI_CAPABILITY_HDR;
  543. ///
  544. /// PMC - Power Management Capabilities
  545. /// Section 3.2.3, PCI Power Management Interface Specifiction, Revision 1.2
  546. ///
  547. typedef union {
  548. struct {
  549. UINT16 Version : 3;
  550. UINT16 PmeClock : 1;
  551. UINT16 Reserved : 1;
  552. UINT16 DeviceSpecificInitialization : 1;
  553. UINT16 AuxCurrent : 3;
  554. UINT16 D1Support : 1;
  555. UINT16 D2Support : 1;
  556. UINT16 PmeSupport : 5;
  557. } Bits;
  558. UINT16 Data;
  559. } EFI_PCI_PMC;
  560. #define EFI_PCI_PMC_D3_COLD_MASK (BIT15)
  561. ///
  562. /// PMCSR - Power Management Control/Status
  563. /// Section 3.2.4, PCI Power Management Interface Specifiction, Revision 1.2
  564. ///
  565. typedef union {
  566. struct {
  567. UINT16 PowerState : 2;
  568. UINT16 ReservedForPciExpress : 1;
  569. UINT16 NoSoftReset : 1;
  570. UINT16 Reserved : 4;
  571. UINT16 PmeEnable : 1;
  572. UINT16 DataSelect : 4;
  573. UINT16 DataScale : 2;
  574. UINT16 PmeStatus : 1;
  575. } Bits;
  576. UINT16 Data;
  577. } EFI_PCI_PMCSR;
  578. #define PCI_POWER_STATE_D0 0
  579. #define PCI_POWER_STATE_D1 1
  580. #define PCI_POWER_STATE_D2 2
  581. #define PCI_POWER_STATE_D3_HOT 3
  582. ///
  583. /// PMCSR_BSE - PMCSR PCI-to-PCI Bridge Support Extensions
  584. /// Section 3.2.5, PCI Power Management Interface Specifiction, Revision 1.2
  585. ///
  586. typedef union {
  587. struct {
  588. UINT8 Reserved : 6;
  589. UINT8 B2B3 : 1;
  590. UINT8 BusPowerClockControl : 1;
  591. } Bits;
  592. UINT8 Uint8;
  593. } EFI_PCI_PMCSR_BSE;
  594. ///
  595. /// Power Management Register Block Definition
  596. /// Section 3.2, PCI Power Management Interface Specifiction, Revision 1.2
  597. ///
  598. typedef struct {
  599. EFI_PCI_CAPABILITY_HDR Hdr;
  600. EFI_PCI_PMC PMC;
  601. EFI_PCI_PMCSR PMCSR;
  602. EFI_PCI_PMCSR_BSE BridgeExtention;
  603. UINT8 Data;
  604. } EFI_PCI_CAPABILITY_PMI;
  605. ///
  606. /// A.G.P Capability
  607. /// Section 6.1.4, Accelerated Graphics Port Interface Specification, Revision 1.0
  608. ///
  609. typedef struct {
  610. EFI_PCI_CAPABILITY_HDR Hdr;
  611. UINT8 Rev;
  612. UINT8 Reserved;
  613. UINT32 Status;
  614. UINT32 Command;
  615. } EFI_PCI_CAPABILITY_AGP;
  616. ///
  617. /// VPD Capability Structure
  618. /// Appendix I, PCI Local Bus Specification, 2.2
  619. ///
  620. typedef struct {
  621. EFI_PCI_CAPABILITY_HDR Hdr;
  622. UINT16 AddrReg;
  623. UINT32 DataReg;
  624. } EFI_PCI_CAPABILITY_VPD;
  625. ///
  626. /// Slot Numbering Capabilities Register
  627. /// Section 3.2.6, PCI-to-PCI Bridge Architeture Specification, Revision 1.2
  628. ///
  629. typedef struct {
  630. EFI_PCI_CAPABILITY_HDR Hdr;
  631. UINT8 ExpnsSlotReg;
  632. UINT8 ChassisNo;
  633. } EFI_PCI_CAPABILITY_SLOTID;
  634. ///
  635. /// Message Capability Structure for 32-bit Message Address
  636. /// Section 6.8.1, PCI Local Bus Specification, 2.2
  637. ///
  638. typedef struct {
  639. EFI_PCI_CAPABILITY_HDR Hdr;
  640. UINT16 MsgCtrlReg;
  641. UINT32 MsgAddrReg;
  642. UINT16 MsgDataReg;
  643. } EFI_PCI_CAPABILITY_MSI32;
  644. ///
  645. /// Message Capability Structure for 64-bit Message Address
  646. /// Section 6.8.1, PCI Local Bus Specification, 2.2
  647. ///
  648. typedef struct {
  649. EFI_PCI_CAPABILITY_HDR Hdr;
  650. UINT16 MsgCtrlReg;
  651. UINT32 MsgAddrRegLsdw;
  652. UINT32 MsgAddrRegMsdw;
  653. UINT16 MsgDataReg;
  654. } EFI_PCI_CAPABILITY_MSI64;
  655. ///
  656. /// Capability EFI_PCI_CAPABILITY_ID_HOTPLUG,
  657. /// CompactPCI Hot Swap Specification PICMG 2.1, R1.0
  658. ///
  659. typedef struct {
  660. EFI_PCI_CAPABILITY_HDR Hdr;
  661. ///
  662. /// not finished - fields need to go here
  663. ///
  664. } EFI_PCI_CAPABILITY_HOTPLUG;
  665. #define PCI_BAR_IDX0 0x00
  666. #define PCI_BAR_IDX1 0x01
  667. #define PCI_BAR_IDX2 0x02
  668. #define PCI_BAR_IDX3 0x03
  669. #define PCI_BAR_IDX4 0x04
  670. #define PCI_BAR_IDX5 0x05
  671. ///
  672. /// EFI PCI Option ROM definitions
  673. ///
  674. #define EFI_ROOT_BRIDGE_LIST 'eprb'
  675. #define EFI_PCI_EXPANSION_ROM_HEADER_EFISIGNATURE 0x0EF1 ///< defined in UEFI Spec.
  676. #define PCI_EXPANSION_ROM_HEADER_SIGNATURE 0xaa55
  677. #define PCI_DATA_STRUCTURE_SIGNATURE SIGNATURE_32 ('P', 'C', 'I', 'R')
  678. #define PCI_CODE_TYPE_PCAT_IMAGE 0x00
  679. #define EFI_PCI_EXPANSION_ROM_HEADER_COMPRESSED 0x0001 ///< defined in UEFI spec.
  680. ///
  681. /// Standard PCI Expansion ROM Header
  682. /// Section 13.4.2, Unified Extensible Firmware Interface Specification, Version 2.1
  683. ///
  684. typedef struct {
  685. UINT16 Signature; ///< 0xaa55
  686. UINT8 Reserved[0x16];
  687. UINT16 PcirOffset;
  688. } PCI_EXPANSION_ROM_HEADER;
  689. ///
  690. /// Legacy ROM Header Extensions
  691. /// Section 6.3.3.1, PCI Local Bus Specification, 2.2
  692. ///
  693. typedef struct {
  694. UINT16 Signature; ///< 0xaa55
  695. UINT8 Size512;
  696. UINT8 InitEntryPoint[3];
  697. UINT8 Reserved[0x12];
  698. UINT16 PcirOffset;
  699. } EFI_LEGACY_EXPANSION_ROM_HEADER;
  700. ///
  701. /// PCI Data Structure Format
  702. /// Section 6.3.1.2, PCI Local Bus Specification, 2.2
  703. ///
  704. typedef struct {
  705. UINT32 Signature; ///< "PCIR"
  706. UINT16 VendorId;
  707. UINT16 DeviceId;
  708. UINT16 Reserved0;
  709. UINT16 Length;
  710. UINT8 Revision;
  711. UINT8 ClassCode[3];
  712. UINT16 ImageLength;
  713. UINT16 CodeRevision;
  714. UINT8 CodeType;
  715. UINT8 Indicator;
  716. UINT16 Reserved1;
  717. } PCI_DATA_STRUCTURE;
  718. ///
  719. /// EFI PCI Expansion ROM Header
  720. /// Section 13.4.2, Unified Extensible Firmware Interface Specification, Version 2.1
  721. ///
  722. typedef struct {
  723. UINT16 Signature; ///< 0xaa55
  724. UINT16 InitializationSize;
  725. UINT32 EfiSignature; ///< 0x0EF1
  726. UINT16 EfiSubsystem;
  727. UINT16 EfiMachineType;
  728. UINT16 CompressionType;
  729. UINT8 Reserved[8];
  730. UINT16 EfiImageHeaderOffset;
  731. UINT16 PcirOffset;
  732. } EFI_PCI_EXPANSION_ROM_HEADER;
  733. typedef union {
  734. UINT8 *Raw;
  735. PCI_EXPANSION_ROM_HEADER *Generic;
  736. EFI_PCI_EXPANSION_ROM_HEADER *Efi;
  737. EFI_LEGACY_EXPANSION_ROM_HEADER *PcAt;
  738. } EFI_PCI_ROM_HEADER;
  739. #pragma pack()
  740. #endif