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 27KB

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