4xx_pcie.h 12 KB

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