pcicfg.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. /*
  2. * pcicfg.h: PCI configuration constants and structures.
  3. *
  4. * Portions of this code are copyright (c) 2020 Cypress Semiconductor Corporation
  5. *
  6. * Copyright (C) 1999-2020, Broadcom Corporation
  7. *
  8. * Unless you and Broadcom execute a separate written software license
  9. * agreement governing use of this software, this software is licensed to you
  10. * under the terms of the GNU General Public License version 2 (the "GPL"),
  11. * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  12. * following added to such license:
  13. *
  14. * As a special exception, the copyright holders of this software give you
  15. * permission to link this software with independent modules, and to copy and
  16. * distribute the resulting executable under terms of your choice, provided that
  17. * you also meet, for each linked independent module, the terms and conditions of
  18. * the license of that module. An independent module is a module which is not
  19. * derived from this software. The special exception does not apply to any
  20. * modifications of the software.
  21. *
  22. * Notwithstanding the above, under no circumstances may you combine this
  23. * software in any way with any other Broadcom software provided under a license
  24. * other than the GPL, without Broadcom's express prior written consent.
  25. *
  26. *
  27. * <<Broadcom-WL-IPTag/Open:>>
  28. *
  29. * $Id: pcicfg.h 690133 2017-03-14 21:02:02Z $
  30. */
  31. #ifndef _h_pcicfg_
  32. #define _h_pcicfg_
  33. /* pci config status reg has a bit to indicate that capability ptr is present */
  34. #define PCI_CAPPTR_PRESENT 0x0010
  35. /* A structure for the config registers is nice, but in most
  36. * systems the config space is not memory mapped, so we need
  37. * field offsetts. :-(
  38. */
  39. #define PCI_CFG_VID 0
  40. #define PCI_CFG_DID 2
  41. #define PCI_CFG_CMD 4
  42. #define PCI_CFG_STAT 6
  43. #define PCI_CFG_REV 8
  44. #define PCI_CFG_PROGIF 9
  45. #define PCI_CFG_SUBCL 0xa
  46. #define PCI_CFG_BASECL 0xb
  47. #define PCI_CFG_CLSZ 0xc
  48. #define PCI_CFG_LATTIM 0xd
  49. #define PCI_CFG_HDR 0xe
  50. #define PCI_CFG_BIST 0xf
  51. #define PCI_CFG_BAR0 0x10
  52. /*
  53. * TODO: PCI_CFG_BAR1 is wrongly defined to be 0x14 whereas it should be
  54. * 0x18 as per the PCIe full dongle spec. Need to modify the values below
  55. * correctly at a later point of time
  56. */
  57. #define PCI_CFG_BAR1 0x14
  58. #define PCI_CFG_BAR2 0x18
  59. #define PCI_CFG_BAR3 0x1c
  60. #define PCI_CFG_BAR4 0x20
  61. #define PCI_CFG_BAR5 0x24
  62. #define PCI_CFG_CIS 0x28
  63. #define PCI_CFG_SVID 0x2c
  64. #define PCI_CFG_SSID 0x2e
  65. #define PCI_CFG_ROMBAR 0x30
  66. #define PCI_CFG_CAPPTR 0x34
  67. #define PCI_CFG_INT 0x3c
  68. #define PCI_CFG_PIN 0x3d
  69. #define PCI_CFG_MINGNT 0x3e
  70. #define PCI_CFG_MAXLAT 0x3f
  71. #define PCI_CFG_DEVCTRL 0xd8
  72. #define PCI_CFG_TLCNTRL_5 0x814
  73. /* PCI CAPABILITY DEFINES */
  74. #define PCI_CAP_POWERMGMTCAP_ID 0x01
  75. #define PCI_CAP_MSICAP_ID 0x05
  76. #define PCI_CAP_VENDSPEC_ID 0x09
  77. #define PCI_CAP_PCIECAP_ID 0x10
  78. #define PCI_CAP_MSIXCAP_ID 0x11
  79. /* Data structure to define the Message Signalled Interrupt facility
  80. * Valid for PCI and PCIE configurations
  81. */
  82. typedef struct _pciconfig_cap_msi {
  83. uint8 capID;
  84. uint8 nextptr;
  85. uint16 msgctrl;
  86. uint32 msgaddr;
  87. } pciconfig_cap_msi;
  88. #define MSI_ENABLE 0x1 /* bit 0 of msgctrl */
  89. /* Data structure to define the Power managment facility
  90. * Valid for PCI and PCIE configurations
  91. */
  92. typedef struct _pciconfig_cap_pwrmgmt {
  93. uint8 capID;
  94. uint8 nextptr;
  95. uint16 pme_cap;
  96. uint16 pme_sts_ctrl;
  97. uint8 pme_bridge_ext;
  98. uint8 data;
  99. } pciconfig_cap_pwrmgmt;
  100. #define PME_CAP_PM_STATES (0x1f << 27) /* Bits 31:27 states that can generate PME */
  101. #define PME_CSR_OFFSET 0x4 /* 4-bytes offset */
  102. #define PME_CSR_PME_EN (1 << 8) /* Bit 8 Enable generating of PME */
  103. #define PME_CSR_PME_STAT (1 << 15) /* Bit 15 PME got asserted */
  104. /* Data structure to define the PCIE capability */
  105. typedef struct _pciconfig_cap_pcie {
  106. uint8 capID;
  107. uint8 nextptr;
  108. uint16 pcie_cap;
  109. uint32 dev_cap;
  110. uint16 dev_ctrl;
  111. uint16 dev_status;
  112. uint32 link_cap;
  113. uint16 link_ctrl;
  114. uint16 link_status;
  115. uint32 slot_cap;
  116. uint16 slot_ctrl;
  117. uint16 slot_status;
  118. uint16 root_ctrl;
  119. uint16 root_cap;
  120. uint32 root_status;
  121. } pciconfig_cap_pcie;
  122. /* PCIE Enhanced CAPABILITY DEFINES */
  123. #define PCIE_EXTCFG_OFFSET 0x100
  124. #define PCIE_ADVERRREP_CAPID 0x0001
  125. #define PCIE_VC_CAPID 0x0002
  126. #define PCIE_DEVSNUM_CAPID 0x0003
  127. #define PCIE_PWRBUDGET_CAPID 0x0004
  128. /* PCIE Extended configuration */
  129. #define PCIE_ADV_CORR_ERR_MASK 0x114
  130. #define PCIE_ADV_CORR_ERR_MASK_OFFSET 0x14
  131. #define CORR_ERR_RE (1 << 0) /* Receiver */
  132. #define CORR_ERR_BT (1 << 6) /* Bad TLP */
  133. #define CORR_ERR_BD (1 << 7) /* Bad DLLP */
  134. #define CORR_ERR_RR (1 << 8) /* REPLAY_NUM rollover */
  135. #define CORR_ERR_RT (1 << 12) /* Reply timer timeout */
  136. #define CORR_ERR_AE (1 << 13) /* Adviosry Non-Fital Error Mask */
  137. #define ALL_CORR_ERRORS (CORR_ERR_RE | CORR_ERR_BT | CORR_ERR_BD | \
  138. CORR_ERR_RR | CORR_ERR_RT)
  139. /* PCIE Root Control Register bits (Host mode only) */
  140. #define PCIE_RC_CORR_SERR_EN 0x0001
  141. #define PCIE_RC_NONFATAL_SERR_EN 0x0002
  142. #define PCIE_RC_FATAL_SERR_EN 0x0004
  143. #define PCIE_RC_PME_INT_EN 0x0008
  144. #define PCIE_RC_CRS_EN 0x0010
  145. /* PCIE Root Capability Register bits (Host mode only) */
  146. #define PCIE_RC_CRS_VISIBILITY 0x0001
  147. /* PCIe PMCSR Register bits */
  148. #define PCIE_PMCSR_PMESTAT 0x8000
  149. /* Header to define the PCIE specific capabilities in the extended config space */
  150. typedef struct _pcie_enhanced_caphdr {
  151. uint16 capID;
  152. uint16 cap_ver : 4;
  153. uint16 next_ptr : 12;
  154. } pcie_enhanced_caphdr;
  155. #define PCIE_CFG_PMCSR 0x4C
  156. #define PCI_BAR0_WIN 0x80 /* backplane addres space accessed by BAR0 */
  157. #define PCI_BAR1_WIN 0x84 /* backplane addres space accessed by BAR1 */
  158. #define PCI_SPROM_CONTROL 0x88 /* sprom property control */
  159. #define PCIE_CFG_SUBSYSTEM_CONTROL 0x88 /* used as subsystem control in PCIE devices */
  160. #define PCI_BAR1_CONTROL 0x8c /* BAR1 region burst control */
  161. #define PCI_INT_STATUS 0x90 /* PCI and other cores interrupts */
  162. #define PCI_INT_MASK 0x94 /* mask of PCI and other cores interrupts */
  163. #define PCI_TO_SB_MB 0x98 /* signal backplane interrupts */
  164. #define PCI_BACKPLANE_ADDR 0xa0 /* address an arbitrary location on the system backplane */
  165. #define PCI_BACKPLANE_DATA 0xa4 /* data at the location specified by above address */
  166. #define PCI_CLK_CTL_ST 0xa8 /* pci config space clock control/status (>=rev14) */
  167. #define PCI_BAR0_WIN2 0xac /* backplane addres space accessed by second 4KB of BAR0 */
  168. #define PCI_GPIO_IN 0xb0 /* pci config space gpio input (>=rev3) */
  169. #define PCIE_CFG_DEVICE_CAPABILITY 0xb0 /* used as device capability in PCIE devices */
  170. #define PCI_GPIO_OUT 0xb4 /* pci config space gpio output (>=rev3) */
  171. #define PCIE_CFG_DEVICE_CONTROL 0xb4 /* 0xb4 is used as device control in PCIE devices */
  172. #define PCIE_DC_AER_CORR_EN (1u << 0u)
  173. #define PCIE_DC_AER_NON_FATAL_EN (1u << 1u)
  174. #define PCIE_DC_AER_FATAL_EN (1u << 2u)
  175. #define PCIE_DC_AER_UNSUP_EN (1u << 3u)
  176. #define PCI_BAR0_WIN2_OFFSET 0x1000u
  177. #define PCIE2_BAR0_CORE2_WIN2_OFFSET 0x5000u
  178. #define PCI_GPIO_OUTEN 0xb8 /* pci config space gpio output enable (>=rev3) */
  179. #define PCI_L1SS_CTRL2 0x24c /* The L1 PM Substates Control register */
  180. /* Private Registers */
  181. #define PCI_STAT_CTRL 0xa80
  182. #define PCI_L0_EVENTCNT 0xa84
  183. #define PCI_L0_STATETMR 0xa88
  184. #define PCI_L1_EVENTCNT 0xa8c
  185. #define PCI_L1_STATETMR 0xa90
  186. #define PCI_L1_1_EVENTCNT 0xa94
  187. #define PCI_L1_1_STATETMR 0xa98
  188. #define PCI_L1_2_EVENTCNT 0xa9c
  189. #define PCI_L1_2_STATETMR 0xaa0
  190. #define PCI_L2_EVENTCNT 0xaa4
  191. #define PCI_L2_STATETMR 0xaa8
  192. #define PCI_LINK_STATUS 0x4dc
  193. #define PCI_LINK_SPEED_MASK (15u << 0u)
  194. #define PCI_LINK_SPEED_SHIFT (0)
  195. #define PCIE_LNK_SPEED_GEN1 0x1
  196. #define PCIE_LNK_SPEED_GEN2 0x2
  197. #define PCIE_LNK_SPEED_GEN3 0x3
  198. #define PCI_PL_SPARE 0x1808 /* Config to Increase external clkreq deasserted minimum time */
  199. #define PCI_CONFIG_EXT_CLK_MIN_TIME_MASK (1u << 31u)
  200. #define PCI_CONFIG_EXT_CLK_MIN_TIME_SHIFT (31)
  201. #define PCI_ADV_ERR_CAP 0x100
  202. #define PCI_UC_ERR_STATUS 0x104
  203. #define PCI_UNCORR_ERR_MASK 0x108
  204. #define PCI_UCORR_ERR_SEVR 0x10c
  205. #define PCI_CORR_ERR_STATUS 0x110
  206. #define PCI_CORR_ERR_MASK 0x114
  207. #define PCI_ERR_CAP_CTRL 0x118
  208. #define PCI_TLP_HDR_LOG1 0x11c
  209. #define PCI_TLP_HDR_LOG2 0x120
  210. #define PCI_TLP_HDR_LOG3 0x124
  211. #define PCI_TLP_HDR_LOG4 0x128
  212. #define PCI_TL_CTRL_5 0x814
  213. #define PCI_TL_HDR_FC_ST 0x980
  214. #define PCI_TL_TGT_CRDT_ST 0x990
  215. #define PCI_TL_SMLOGIC_ST 0x998
  216. #define PCI_DL_ATTN_VEC 0x1040
  217. #define PCI_DL_STATUS 0x1048
  218. #define PCI_PHY_CTL_0 0x1800
  219. #define PCI_SLOW_PMCLK_EXT_RLOCK (1 << 7)
  220. #define PCI_LINK_STATE_DEBUG 0x1c24
  221. #define PCI_RECOVERY_HIST 0x1ce4
  222. #define PCI_PHY_LTSSM_HIST_0 0x1cec
  223. #define PCI_PHY_LTSSM_HIST_1 0x1cf0
  224. #define PCI_PHY_LTSSM_HIST_2 0x1cf4
  225. #define PCI_PHY_LTSSM_HIST_3 0x1cf8
  226. #define PCI_PHY_DBG_CLKREG_0 0x1e10
  227. #define PCI_PHY_DBG_CLKREG_1 0x1e14
  228. #define PCI_PHY_DBG_CLKREG_2 0x1e18
  229. #define PCI_PHY_DBG_CLKREG_3 0x1e1c
  230. /* Bit settings for PCIE_CFG_SUBSYSTEM_CONTROL register */
  231. #define PCIE_BAR1COHERENTACCEN_BIT 8
  232. #define PCIE_BAR2COHERENTACCEN_BIT 9
  233. #define PCIE_SSRESET_STATUS_BIT 13
  234. #define PCIE_SSRESET_DISABLE_BIT 14
  235. #define PCIE_SSRESET_DIS_ENUM_RST_BIT 15
  236. #define PCIE_BARCOHERENTACCEN_MASK 0x300
  237. /* Bit settings for PCI_UC_ERR_STATUS register */
  238. #define PCI_UC_ERR_URES (1 << 20) /* Unsupported Request Error Status */
  239. #define PCI_UC_ERR_ECRCS (1 << 19) /* ECRC Error Status */
  240. #define PCI_UC_ERR_MTLPS (1 << 18) /* Malformed TLP Status */
  241. #define PCI_UC_ERR_ROS (1 << 17) /* Receiver Overflow Status */
  242. #define PCI_UC_ERR_UCS (1 << 16) /* Unexpected Completion Status */
  243. #define PCI_UC_ERR_CAS (1 << 15) /* Completer Abort Status */
  244. #define PCI_UC_ERR_CTS (1 << 14) /* Completer Timeout Status */
  245. #define PCI_UC_ERR_FCPES (1 << 13) /* Flow Control Protocol Error Status */
  246. #define PCI_UC_ERR_PTLPS (1 << 12) /* Poisoned TLP Status */
  247. #define PCI_UC_ERR_DLPES (1 << 4) /* Data Link Protocol Error Status */
  248. #define PCI_DL_STATUS_PHY_LINKUP (1 << 13) /* Status of LINK */
  249. #define PCI_PMCR_REFUP 0x1814 /* Trefup time */
  250. #define PCI_PMCR_TREFUP_LO_MASK 0x3f
  251. #define PCI_PMCR_TREFUP_LO_SHIFT 24
  252. #define PCI_PMCR_TREFUP_LO_BITS 6
  253. #define PCI_PMCR_TREFUP_HI_MASK 0xf
  254. #define PCI_PMCR_TREFUP_HI_SHIFT 5
  255. #define PCI_PMCR_TREFUP_HI_BITS 4
  256. #define PCI_PMCR_TREFUP_MAX 0x400
  257. #define PCI_PMCR_TREFUP_MAX_SCALE 0x2000
  258. #define PCI_PMCR_REFUP_EXT 0x1818 /* Trefup extend Max */
  259. #define PCI_PMCR_TREFUP_EXT_SHIFT 22
  260. #define PCI_PMCR_TREFUP_EXT_SCALE 3
  261. #define PCI_PMCR_TREFUP_EXT_ON 1
  262. #define PCI_PMCR_TREFUP_EXT_OFF 0
  263. #define PCI_TPOWER_SCALE_MASK 0x3
  264. #define PCI_TPOWER_SCALE_SHIFT 3 /* 0:1 is scale and 2 is rsvd */
  265. #define PCI_BAR0_SHADOW_OFFSET (2 * 1024) /* bar0 + 2K accesses sprom shadow (in pci core) */
  266. #define PCI_BAR0_SPROM_OFFSET (4 * 1024) /* bar0 + 4K accesses external sprom */
  267. #define PCI_BAR0_PCIREGS_OFFSET (6 * 1024) /* bar0 + 6K accesses pci core registers */
  268. #define PCI_BAR0_PCISBR_OFFSET (4 * 1024) /* pci core SB registers are at the end of the
  269. * 8KB window, so their address is the "regular"
  270. * address plus 4K
  271. */
  272. /*
  273. * PCIE GEN2 changed some of the above locations for
  274. * Bar0WrapperBase, SecondaryBAR0Window and SecondaryBAR0WrapperBase
  275. * BAR0 maps 32K of register space
  276. */
  277. #define PCIE2_BAR0_WIN2 0x70 /* backplane addres space accessed by second 4KB of BAR0 */
  278. #define PCIE2_BAR0_CORE2_WIN 0x74 /* backplane addres space accessed by second 4KB of BAR0 */
  279. #define PCIE2_BAR0_CORE2_WIN2 0x78 /* backplane addres space accessed by second 4KB of BAR0 */
  280. #define PCIE2_BAR0_WINSZ 0x8000
  281. #define PCI_BAR0_WIN2_OFFSET 0x1000u
  282. #define PCI_CORE_ENUM_OFFSET 0x2000u
  283. #define PCI_CC_CORE_ENUM_OFFSET 0x3000u
  284. #define PCI_SEC_BAR0_WIN_OFFSET 0x4000u
  285. #define PCI_SEC_BAR0_WRAP_OFFSET 0x5000u
  286. #define PCI_CORE_ENUM2_OFFSET 0x6000u
  287. #define PCI_CC_CORE_ENUM2_OFFSET 0x7000u
  288. #define PCI_LAST_OFFSET 0x8000u
  289. #define PCI_BAR0_WINSZ (16 * 1024) /* bar0 window size Match with corerev 13 */
  290. /* On pci corerev >= 13 and all pcie, the bar0 is now 16KB and it maps: */
  291. #define PCI_16KB0_PCIREGS_OFFSET (8 * 1024) /* bar0 + 8K accesses pci/pcie core registers */
  292. #define PCI_16KB0_CCREGS_OFFSET (12 * 1024) /* bar0 + 12K accesses chipc core registers */
  293. #define PCI_16KBB0_WINSZ (16 * 1024) /* bar0 window size */
  294. #define PCI_SECOND_BAR0_OFFSET (16 * 1024) /* secondary bar 0 window */
  295. /* On AI chips we have a second window to map DMP regs are mapped: */
  296. #define PCI_16KB0_WIN2_OFFSET (4 * 1024) /* bar0 + 4K is "Window 2" */
  297. /* PCI_INT_STATUS */
  298. #define PCI_SBIM_STATUS_SERR 0x4 /* backplane SBErr interrupt status */
  299. /* PCI_INT_MASK */
  300. #define PCI_SBIM_SHIFT 8 /* backplane core interrupt mask bits offset */
  301. #define PCI_SBIM_MASK 0xff00 /* backplane core interrupt mask */
  302. #define PCI_SBIM_MASK_SERR 0x4 /* backplane SBErr interrupt mask */
  303. #define PCI_CTO_INT_SHIFT 16 /* backplane SBErr interrupt mask */
  304. #define PCI_CTO_INT_MASK (1 << PCI_CTO_INT_SHIFT) /* backplane SBErr interrupt mask */
  305. /* PCI_SPROM_CONTROL */
  306. #define SPROM_SZ_MSK 0x02 /* SPROM Size Mask */
  307. #define SPROM_LOCKED 0x08 /* SPROM Locked */
  308. #define SPROM_BLANK 0x04 /* indicating a blank SPROM */
  309. #define SPROM_WRITEEN 0x10 /* SPROM write enable */
  310. #define SPROM_BOOTROM_WE 0x20 /* external bootrom write enable */
  311. #define SPROM_BACKPLANE_EN 0x40 /* Enable indirect backplane access */
  312. #define SPROM_OTPIN_USE 0x80 /* device OTP In use */
  313. #define SPROM_CFG_TO_SB_RST 0x400 /* backplane reset */
  314. /* Bits in PCI command and status regs */
  315. #define PCI_CMD_IO 0x00000001 /* I/O enable */
  316. #define PCI_CMD_MEMORY 0x00000002 /* Memory enable */
  317. #define PCI_CMD_MASTER 0x00000004 /* Master enable */
  318. #define PCI_CMD_SPECIAL 0x00000008 /* Special cycles enable */
  319. #define PCI_CMD_INVALIDATE 0x00000010 /* Invalidate? */
  320. #define PCI_CMD_VGA_PAL 0x00000040 /* VGA Palate */
  321. #define PCI_STAT_TA 0x08000000 /* target abort status */
  322. /* Header types */
  323. #define PCI_HEADER_MULTI 0x80
  324. #define PCI_HEADER_MASK 0x7f
  325. typedef enum {
  326. PCI_HEADER_NORMAL,
  327. PCI_HEADER_BRIDGE,
  328. PCI_HEADER_CARDBUS
  329. } pci_header_types;
  330. #define PCI_CONFIG_SPACE_SIZE 256
  331. #define DWORD_ALIGN(x) (x & ~(0x03))
  332. #define BYTE_POS(x) (x & 0x3)
  333. #define WORD_POS(x) (x & 0x1)
  334. #define BYTE_SHIFT(x) (8 * BYTE_POS(x))
  335. #define WORD_SHIFT(x) (16 * WORD_POS(x))
  336. #define BYTE_VAL(a, x) ((a >> BYTE_SHIFT(x)) & 0xFF)
  337. #define WORD_VAL(a, x) ((a >> WORD_SHIFT(x)) & 0xFFFF)
  338. #define read_pci_cfg_byte(a) \
  339. (BYTE_VAL(OSL_PCI_READ_CONFIG(osh, DWORD_ALIGN(a), 4), a) & 0xff)
  340. #define read_pci_cfg_word(a) \
  341. (WORD_VAL(OSL_PCI_READ_CONFIG(osh, DWORD_ALIGN(a), 4), a) & 0xffff)
  342. #define write_pci_cfg_byte(a, val) do { \
  343. uint32 tmpval; \
  344. tmpval = (OSL_PCI_READ_CONFIG(osh, DWORD_ALIGN(a), 4) & ~0xFF << BYTE_POS(a)) | \
  345. val << BYTE_POS(a); \
  346. OSL_PCI_WRITE_CONFIG(osh, DWORD_ALIGN(a), 4, tmpval); \
  347. } while (0)
  348. #define write_pci_cfg_word(a, val) do { \
  349. uint32 tmpval; \
  350. tmpval = (OSL_PCI_READ_CONFIG(osh, DWORD_ALIGN(a), 4) & ~0xFFFF << WORD_POS(a)) | \
  351. val << WORD_POS(a); \
  352. OSL_PCI_WRITE_CONFIG(osh, DWORD_ALIGN(a), 4, tmpval); \
  353. } while (0)
  354. #endif /* _h_pcicfg_ */