4xx_pcie.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. /*
  2. * Copyright (c) 2005 Cisco Systems. All rights reserved.
  3. * Roland Dreier <rolandd@cisco.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation; either version 2 of the License, or (at your
  8. * option) any later version.
  9. */
  10. #ifndef __4XX_PCIE_H
  11. #define __4XX_PCIE_H
  12. #include <ppc4xx.h>
  13. #include <pci.h>
  14. #define DCRN_SDR0_CFGADDR 0x00e
  15. #define DCRN_SDR0_CFGDATA 0x00f
  16. #if defined(CONFIG_440SPE)
  17. #define CONFIG_SYS_PCIE_NR_PORTS 3
  18. #define CONFIG_SYS_PCIE_ADDR_HIGH 0x0000000d
  19. #define DCRN_PCIE0_BASE 0x100
  20. #define DCRN_PCIE1_BASE 0x120
  21. #define DCRN_PCIE2_BASE 0x140
  22. #define PCIE0_SDR 0x300
  23. #define PCIE1_SDR 0x340
  24. #define PCIE2_SDR 0x370
  25. #endif
  26. #if defined(CONFIG_460EX) || defined(CONFIG_460GT)
  27. #define CONFIG_SYS_PCIE_NR_PORTS 2
  28. #define CONFIG_SYS_PCIE_ADDR_HIGH 0x0000000d
  29. #define DCRN_PCIE0_BASE 0x100
  30. #define DCRN_PCIE1_BASE 0x120
  31. #define PCIE0_SDR 0x300
  32. #define PCIE1_SDR 0x340
  33. #endif
  34. #if defined(CONFIG_405EX)
  35. #define CONFIG_SYS_PCIE_NR_PORTS 2
  36. #define CONFIG_SYS_PCIE_ADDR_HIGH 0x00000000
  37. #define DCRN_PCIE0_BASE 0x040
  38. #define DCRN_PCIE1_BASE 0x060
  39. #define PCIE0_SDR 0x400
  40. #define PCIE1_SDR 0x440
  41. #endif
  42. #define PCIE0 DCRN_PCIE0_BASE
  43. #define PCIE1 DCRN_PCIE1_BASE
  44. #define PCIE2 DCRN_PCIE2_BASE
  45. #define DCRN_PEGPL_CFGBAH(base) (base + 0x00)
  46. #define DCRN_PEGPL_CFGBAL(base) (base + 0x01)
  47. #define DCRN_PEGPL_CFGMSK(base) (base + 0x02)
  48. #define DCRN_PEGPL_MSGBAH(base) (base + 0x03)
  49. #define DCRN_PEGPL_MSGBAL(base) (base + 0x04)
  50. #define DCRN_PEGPL_MSGMSK(base) (base + 0x05)
  51. #define DCRN_PEGPL_OMR1BAH(base) (base + 0x06)
  52. #define DCRN_PEGPL_OMR1BAL(base) (base + 0x07)
  53. #define DCRN_PEGPL_OMR1MSKH(base) (base + 0x08)
  54. #define DCRN_PEGPL_OMR1MSKL(base) (base + 0x09)
  55. #define DCRN_PEGPL_REGBAH(base) (base + 0x12)
  56. #define DCRN_PEGPL_REGBAL(base) (base + 0x13)
  57. #define DCRN_PEGPL_REGMSK(base) (base + 0x14)
  58. #define DCRN_PEGPL_SPECIAL(base) (base + 0x15)
  59. #define DCRN_PEGPL_CFG(base) (base + 0x16)
  60. /*
  61. * System DCRs (SDRs)
  62. */
  63. #define PESDR0_PLLLCT1 0x03a0
  64. #define PESDR0_PLLLCT2 0x03a1
  65. #define PESDR0_PLLLCT3 0x03a2
  66. /* common regs, at for all 4xx with PCIe core */
  67. #define SDRN_PESDR_UTLSET1(n) (sdr_base(n) + 0x00)
  68. #define SDRN_PESDR_UTLSET2(n) (sdr_base(n) + 0x01)
  69. #define SDRN_PESDR_DLPSET(n) (sdr_base(n) + 0x02)
  70. #define SDRN_PESDR_LOOP(n) (sdr_base(n) + 0x03)
  71. #define SDRN_PESDR_RCSSET(n) (sdr_base(n) + 0x04)
  72. #define SDRN_PESDR_RCSSTS(n) (sdr_base(n) + 0x05)
  73. #if defined(CONFIG_440SPE)
  74. #define SDRN_PESDR_HSSL0SET1(n) (sdr_base(n) + 0x06)
  75. #define SDRN_PESDR_HSSL0SET2(n) (sdr_base(n) + 0x07)
  76. #define SDRN_PESDR_HSSL0STS(n) (sdr_base(n) + 0x08)
  77. #define SDRN_PESDR_HSSL1SET1(n) (sdr_base(n) + 0x09)
  78. #define SDRN_PESDR_HSSL1SET2(n) (sdr_base(n) + 0x0a)
  79. #define SDRN_PESDR_HSSL1STS(n) (sdr_base(n) + 0x0b)
  80. #define SDRN_PESDR_HSSL2SET1(n) (sdr_base(n) + 0x0c)
  81. #define SDRN_PESDR_HSSL2SET2(n) (sdr_base(n) + 0x0d)
  82. #define SDRN_PESDR_HSSL2STS(n) (sdr_base(n) + 0x0e)
  83. #define SDRN_PESDR_HSSL3SET1(n) (sdr_base(n) + 0x0f)
  84. #define SDRN_PESDR_HSSL3SET2(n) (sdr_base(n) + 0x10)
  85. #define SDRN_PESDR_HSSL3STS(n) (sdr_base(n) + 0x11)
  86. #define PESDR0_UTLSET1 0x0300
  87. #define PESDR0_UTLSET2 0x0301
  88. #define PESDR0_DLPSET 0x0302
  89. #define PESDR0_LOOP 0x0303
  90. #define PESDR0_RCSSET 0x0304
  91. #define PESDR0_RCSSTS 0x0305
  92. #define PESDR0_HSSL0SET1 0x0306
  93. #define PESDR0_HSSL0SET2 0x0307
  94. #define PESDR0_HSSL0STS 0x0308
  95. #define PESDR0_HSSL1SET1 0x0309
  96. #define PESDR0_HSSL1SET2 0x030a
  97. #define PESDR0_HSSL1STS 0x030b
  98. #define PESDR0_HSSL2SET1 0x030c
  99. #define PESDR0_HSSL2SET2 0x030d
  100. #define PESDR0_HSSL2STS 0x030e
  101. #define PESDR0_HSSL3SET1 0x030f
  102. #define PESDR0_HSSL3SET2 0x0310
  103. #define PESDR0_HSSL3STS 0x0311
  104. #define PESDR0_HSSL4SET1 0x0312
  105. #define PESDR0_HSSL4SET2 0x0313
  106. #define PESDR0_HSSL4STS 0x0314
  107. #define PESDR0_HSSL5SET1 0x0315
  108. #define PESDR0_HSSL5SET2 0x0316
  109. #define PESDR0_HSSL5STS 0x0317
  110. #define PESDR0_HSSL6SET1 0x0318
  111. #define PESDR0_HSSL6SET2 0x0319
  112. #define PESDR0_HSSL6STS 0x031a
  113. #define PESDR0_HSSL7SET1 0x031b
  114. #define PESDR0_HSSL7SET2 0x031c
  115. #define PESDR0_HSSL7STS 0x031d
  116. #define PESDR0_HSSCTLSET 0x031e
  117. #define PESDR0_LANE_ABCD 0x031f
  118. #define PESDR0_LANE_EFGH 0x0320
  119. #define PESDR1_UTLSET1 0x0340
  120. #define PESDR1_UTLSET2 0x0341
  121. #define PESDR1_DLPSET 0x0342
  122. #define PESDR1_LOOP 0x0343
  123. #define PESDR1_RCSSET 0x0344
  124. #define PESDR1_RCSSTS 0x0345
  125. #define PESDR1_HSSL0SET1 0x0346
  126. #define PESDR1_HSSL0SET2 0x0347
  127. #define PESDR1_HSSL0STS 0x0348
  128. #define PESDR1_HSSL1SET1 0x0349
  129. #define PESDR1_HSSL1SET2 0x034a
  130. #define PESDR1_HSSL1STS 0x034b
  131. #define PESDR1_HSSL2SET1 0x034c
  132. #define PESDR1_HSSL2SET2 0x034d
  133. #define PESDR1_HSSL2STS 0x034e
  134. #define PESDR1_HSSL3SET1 0x034f
  135. #define PESDR1_HSSL3SET2 0x0350
  136. #define PESDR1_HSSL3STS 0x0351
  137. #define PESDR1_HSSCTLSET 0x0352
  138. #define PESDR1_LANE_ABCD 0x0353
  139. #define PESDR2_UTLSET1 0x0370
  140. #define PESDR2_UTLSET2 0x0371
  141. #define PESDR2_DLPSET 0x0372
  142. #define PESDR2_LOOP 0x0373
  143. #define PESDR2_RCSSET 0x0374
  144. #define PESDR2_RCSSTS 0x0375
  145. #define PESDR2_HSSL0SET1 0x0376
  146. #define PESDR2_HSSL0SET2 0x0377
  147. #define PESDR2_HSSL0STS 0x0378
  148. #define PESDR2_HSSL1SET1 0x0379
  149. #define PESDR2_HSSL1SET2 0x037a
  150. #define PESDR2_HSSL1STS 0x037b
  151. #define PESDR2_HSSL2SET1 0x037c
  152. #define PESDR2_HSSL2SET2 0x037d
  153. #define PESDR2_HSSL2STS 0x037e
  154. #define PESDR2_HSSL3SET1 0x037f
  155. #define PESDR2_HSSL3SET2 0x0380
  156. #define PESDR2_HSSL3STS 0x0381
  157. #define PESDR2_HSSCTLSET 0x0382
  158. #define PESDR2_LANE_ABCD 0x0383
  159. #elif defined(CONFIG_405EX)
  160. #define SDRN_PESDR_PHYSET1(n) (sdr_base(n) + 0x06)
  161. #define SDRN_PESDR_PHYSET2(n) (sdr_base(n) + 0x07)
  162. #define SDRN_PESDR_BIST(n) (sdr_base(n) + 0x08)
  163. #define SDRN_PESDR_LPB(n) (sdr_base(n) + 0x0b)
  164. #define SDRN_PESDR_PHYSTA(n) (sdr_base(n) + 0x0c)
  165. #define PESDR0_UTLSET1 0x0400
  166. #define PESDR0_UTLSET2 0x0401
  167. #define PESDR0_DLPSET 0x0402
  168. #define PESDR0_LOOP 0x0403
  169. #define PESDR0_RCSSET 0x0404
  170. #define PESDR0_RCSSTS 0x0405
  171. #define PESDR0_PHYSET1 0x0406
  172. #define PESDR0_PHYSET2 0x0407
  173. #define PESDR0_BIST 0x0408
  174. #define PESDR0_LPB 0x040B
  175. #define PESDR0_PHYSTA 0x040C
  176. #define PESDR1_UTLSET1 0x0440
  177. #define PESDR1_UTLSET2 0x0441
  178. #define PESDR1_DLPSET 0x0442
  179. #define PESDR1_LOOP 0x0443
  180. #define PESDR1_RCSSET 0x0444
  181. #define PESDR1_RCSSTS 0x0445
  182. #define PESDR1_PHYSET1 0x0446
  183. #define PESDR1_PHYSET2 0x0447
  184. #define PESDR1_BIST 0x0448
  185. #define PESDR1_LPB 0x044B
  186. #define PESDR1_PHYSTA 0x044C
  187. #elif defined(CONFIG_460EX) || defined(CONFIG_460GT)
  188. #define PESDR0_L0BIST 0x0308 /* PE0 L0 built in self test */
  189. #define PESDR0_L0BISTSTS 0x0309 /* PE0 L0 built in self test status */
  190. #define PESDR0_L0CDRCTL 0x030A /* PE0 L0 CDR control */
  191. #define PESDR0_L0DRV 0x030B /* PE0 L0 drive */
  192. #define PESDR0_L0REC 0x030C /* PE0 L0 receiver */
  193. #define PESDR0_L0LPB 0x030D /* PE0 L0 loopback */
  194. #define PESDR0_L0CLK 0x030E /* PE0 L0 clocking */
  195. #define PESDR0_PHY_CTL_RST 0x030F /* PE0 PHY control reset */
  196. #define PESDR0_RSTSTA 0x0310 /* PE0 reset status */
  197. #define PESDR0_OBS 0x0311 /* PE0 observation register */
  198. #define PESDR0_L0ERRC 0x0320 /* PE0 L0 error counter */
  199. #define PESDR1_L0BIST 0x0348 /* PE1 L0 built in self test */
  200. #define PESDR1_L1BIST 0x0349 /* PE1 L1 built in self test */
  201. #define PESDR1_L2BIST 0x034A /* PE1 L2 built in self test */
  202. #define PESDR1_L3BIST 0x034B /* PE1 L3 built in self test */
  203. #define PESDR1_L0BISTSTS 0x034C /* PE1 L0 built in self test status */
  204. #define PESDR1_L1BISTSTS 0x034D /* PE1 L1 built in self test status */
  205. #define PESDR1_L2BISTSTS 0x034E /* PE1 L2 built in self test status */
  206. #define PESDR1_L3BISTSTS 0x034F /* PE1 L3 built in self test status */
  207. #define PESDR1_L0CDRCTL 0x0350 /* PE1 L0 CDR control */
  208. #define PESDR1_L1CDRCTL 0x0351 /* PE1 L1 CDR control */
  209. #define PESDR1_L2CDRCTL 0x0352 /* PE1 L2 CDR control */
  210. #define PESDR1_L3CDRCTL 0x0353 /* PE1 L3 CDR control */
  211. #define PESDR1_L0DRV 0x0354 /* PE1 L0 drive */
  212. #define PESDR1_L1DRV 0x0355 /* PE1 L1 drive */
  213. #define PESDR1_L2DRV 0x0356 /* PE1 L2 drive */
  214. #define PESDR1_L3DRV 0x0357 /* PE1 L3 drive */
  215. #define PESDR1_L0REC 0x0358 /* PE1 L0 receiver */
  216. #define PESDR1_L1REC 0x0359 /* PE1 L1 receiver */
  217. #define PESDR1_L2REC 0x035A /* PE1 L2 receiver */
  218. #define PESDR1_L3REC 0x035B /* PE1 L3 receiver */
  219. #define PESDR1_L0LPB 0x035C /* PE1 L0 loopback */
  220. #define PESDR1_L1LPB 0x035D /* PE1 L1 loopback */
  221. #define PESDR1_L2LPB 0x035E /* PE1 L2 loopback */
  222. #define PESDR1_L3LPB 0x035F /* PE1 L3 loopback */
  223. #define PESDR1_L0CLK 0x0360 /* PE1 L0 clocking */
  224. #define PESDR1_L1CLK 0x0361 /* PE1 L1 clocking */
  225. #define PESDR1_L2CLK 0x0362 /* PE1 L2 clocking */
  226. #define PESDR1_L3CLK 0x0363 /* PE1 L3 clocking */
  227. #define PESDR1_PHY_CTL_RST 0x0364 /* PE1 PHY control reset */
  228. #define PESDR1_RSTSTA 0x0365 /* PE1 reset status */
  229. #define PESDR1_OBS 0x0366 /* PE1 observation register */
  230. #define PESDR1_L0ERRC 0x0368 /* PE1 L0 error counter */
  231. #define PESDR1_L1ERRC 0x0369 /* PE1 L1 error counter */
  232. #define PESDR1_L2ERRC 0x036A /* PE1 L2 error counter */
  233. #define PESDR1_L3ERRC 0x036B /* PE1 L3 error counter */
  234. #define PESDR0_IHS1 0x036C /* PE interrupt handler interfact setting 1 */
  235. #define PESDR0_IHS2 0x036D /* PE interrupt handler interfact setting 2 */
  236. #endif
  237. /* SDR Bit Mappings */
  238. #define PESDRx_RCSSET_HLDPLB 0x10000000
  239. #define PESDRx_RCSSET_RSTGU 0x01000000
  240. #define PESDRx_RCSSET_RDY 0x00100000
  241. #define PESDRx_RCSSET_RSTDL 0x00010000
  242. #define PESDRx_RCSSET_RSTPYN 0x00001000
  243. #define PESDRx_RCSSTS_PLBIDL 0x10000000
  244. #define PESDRx_RCSSTS_HRSTRQ 0x01000000
  245. #define PESDRx_RCSSTS_PGRST 0x00100000
  246. #define PESDRx_RCSSTS_VC0ACT 0x00010000
  247. #define PESDRx_RCSSTS_BMEN 0x00000100
  248. /*
  249. * UTL register offsets
  250. */
  251. #define PEUTL_PBCTL 0x00
  252. #define PEUTL_PBBSZ 0x20
  253. #define PEUTL_OPDBSZ 0x68
  254. #define PEUTL_IPHBSZ 0x70
  255. #define PEUTL_IPDBSZ 0x78
  256. #define PEUTL_OUTTR 0x90
  257. #define PEUTL_INTR 0x98
  258. #define PEUTL_PCTL 0xa0
  259. #define PEUTL_RCSTA 0xb0
  260. #define PEUTL_RCIRQEN 0xb8
  261. /*
  262. * Config space register offsets
  263. */
  264. #define PECFG_BAR0LMPA 0x210
  265. #define PECFG_BAR0HMPA 0x214
  266. #define PECFG_BAR1MPA 0x218
  267. #define PECFG_BAR2LMPA 0x220
  268. #define PECFG_BAR2HMPA 0x224
  269. #define PECFG_PIMEN 0x33c
  270. #define PECFG_PIM0LAL 0x340
  271. #define PECFG_PIM0LAH 0x344
  272. #define PECFG_PIM1LAL 0x348
  273. #define PECFG_PIM1LAH 0x34c
  274. #define PECFG_PIM01SAL 0x350
  275. #define PECFG_PIM01SAH 0x354
  276. #define PECFG_POM0LAL 0x380
  277. #define PECFG_POM0LAH 0x384
  278. #define SDR_READ(offset) ({\
  279. mtdcr(DCRN_SDR0_CFGADDR, offset); \
  280. mfdcr(DCRN_SDR0_CFGDATA);})
  281. #define SDR_WRITE(offset, data) ({\
  282. mtdcr(DCRN_SDR0_CFGADDR, offset); \
  283. mtdcr(DCRN_SDR0_CFGDATA,data);})
  284. #define GPL_DMER_MASK_DISA 0x02000000
  285. #define U64_TO_U32_LOW(val) ((u32)((val) & 0x00000000ffffffffULL))
  286. #define U64_TO_U32_HIGH(val) ((u32)((val) >> 32))
  287. /*
  288. * Prototypes
  289. */
  290. int ppc4xx_init_pcie(void);
  291. int ppc4xx_init_pcie_rootport(int port);
  292. int ppc4xx_init_pcie_endport(int port);
  293. void ppc4xx_setup_pcie_rootpoint(struct pci_controller *hose, int port);
  294. int ppc4xx_setup_pcie_endpoint(struct pci_controller *hose, int port);
  295. int pcie_hose_scan(struct pci_controller *hose, int bus);
  296. /*
  297. * Function to determine root port or endport from env variable.
  298. */
  299. static inline int is_end_point(int port)
  300. {
  301. char s[10], *tk;
  302. char *pcie_mode = getenv("pcie_mode");
  303. if (pcie_mode == NULL)
  304. return 0;
  305. strcpy(s, pcie_mode);
  306. tk = strtok(s, ":");
  307. switch (port) {
  308. case 0:
  309. if (tk != NULL) {
  310. if (!(strcmp(tk, "ep") && strcmp(tk, "EP")))
  311. return 1;
  312. else
  313. return 0;
  314. }
  315. else
  316. return 0;
  317. case 1:
  318. tk = strtok(NULL, ":");
  319. if (tk != NULL) {
  320. if (!(strcmp(tk, "ep") && strcmp(tk, "EP")))
  321. return 1;
  322. else
  323. return 0;
  324. }
  325. else
  326. return 0;
  327. case 2:
  328. tk = strtok(NULL, ":");
  329. if (tk != NULL)
  330. tk = strtok(NULL, ":");
  331. if (tk != NULL) {
  332. if (!(strcmp(tk, "ep") && strcmp(tk, "EP")))
  333. return 1;
  334. else
  335. return 0;
  336. }
  337. else
  338. return 0;
  339. }
  340. return 0;
  341. }
  342. static inline void mdelay(int n)
  343. {
  344. u32 ms = n;
  345. while (ms--)
  346. udelay(1000);
  347. }
  348. #if defined(PCIE0_SDR)
  349. static inline u32 sdr_base(int port)
  350. {
  351. switch (port) {
  352. default: /* to satisfy compiler */
  353. case 0:
  354. return PCIE0_SDR;
  355. case 1:
  356. return PCIE1_SDR;
  357. #if CONFIG_SYS_PCIE_NR_PORTS > 2
  358. case 2:
  359. return PCIE2_SDR;
  360. #endif
  361. }
  362. }
  363. #endif /* defined(PCIE0_SDR) */
  364. #endif /* __4XX_PCIE_H */