4xx_pcie.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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_405EX)
  26. #define CFG_PCIE_NR_PORTS 2
  27. #define CFG_PCIE_ADDR_HIGH 0x00000000
  28. #define DCRN_PCIE0_BASE 0x040
  29. #define DCRN_PCIE1_BASE 0x060
  30. #define PCIE0_SDR 0x400
  31. #define PCIE1_SDR 0x440
  32. #endif
  33. #define PCIE0 DCRN_PCIE0_BASE
  34. #define PCIE1 DCRN_PCIE1_BASE
  35. #define PCIE2 DCRN_PCIE2_BASE
  36. #define DCRN_PEGPL_CFGBAH(base) (base + 0x00)
  37. #define DCRN_PEGPL_CFGBAL(base) (base + 0x01)
  38. #define DCRN_PEGPL_CFGMSK(base) (base + 0x02)
  39. #define DCRN_PEGPL_MSGBAH(base) (base + 0x03)
  40. #define DCRN_PEGPL_MSGBAL(base) (base + 0x04)
  41. #define DCRN_PEGPL_MSGMSK(base) (base + 0x05)
  42. #define DCRN_PEGPL_OMR1BAH(base) (base + 0x06)
  43. #define DCRN_PEGPL_OMR1BAL(base) (base + 0x07)
  44. #define DCRN_PEGPL_OMR1MSKH(base) (base + 0x08)
  45. #define DCRN_PEGPL_OMR1MSKL(base) (base + 0x09)
  46. #define DCRN_PEGPL_REGBAH(base) (base + 0x12)
  47. #define DCRN_PEGPL_REGBAL(base) (base + 0x13)
  48. #define DCRN_PEGPL_REGMSK(base) (base + 0x14)
  49. #define DCRN_PEGPL_SPECIAL(base) (base + 0x15)
  50. #define DCRN_PEGPL_CFG(base) (base + 0x16)
  51. /*
  52. * System DCRs (SDRs)
  53. */
  54. #define PESDR0_PLLLCT1 0x03a0
  55. #define PESDR0_PLLLCT2 0x03a1
  56. #define PESDR0_PLLLCT3 0x03a2
  57. /* common regs, at least for 405EX and 440SPe */
  58. #define SDRN_PESDR_UTLSET1(n) (sdr_base(n) + 0x00)
  59. #define SDRN_PESDR_UTLSET2(n) (sdr_base(n) + 0x01)
  60. #define SDRN_PESDR_DLPSET(n) (sdr_base(n) + 0x02)
  61. #define SDRN_PESDR_LOOP(n) (sdr_base(n) + 0x03)
  62. #define SDRN_PESDR_RCSSET(n) (sdr_base(n) + 0x04)
  63. #define SDRN_PESDR_RCSSTS(n) (sdr_base(n) + 0x05)
  64. #if defined(CONFIG_440SPE)
  65. #define SDRN_PESDR_HSSL0SET1(n) (sdr_base(n) + 0x06)
  66. #define SDRN_PESDR_HSSL0SET2(n) (sdr_base(n) + 0x07)
  67. #define SDRN_PESDR_HSSL0STS(n) (sdr_base(n) + 0x08)
  68. #define SDRN_PESDR_HSSL1SET1(n) (sdr_base(n) + 0x09)
  69. #define SDRN_PESDR_HSSL1SET2(n) (sdr_base(n) + 0x0a)
  70. #define SDRN_PESDR_HSSL1STS(n) (sdr_base(n) + 0x0b)
  71. #define SDRN_PESDR_HSSL2SET1(n) (sdr_base(n) + 0x0c)
  72. #define SDRN_PESDR_HSSL2SET2(n) (sdr_base(n) + 0x0d)
  73. #define SDRN_PESDR_HSSL2STS(n) (sdr_base(n) + 0x0e)
  74. #define SDRN_PESDR_HSSL3SET1(n) (sdr_base(n) + 0x0f)
  75. #define SDRN_PESDR_HSSL3SET2(n) (sdr_base(n) + 0x10)
  76. #define SDRN_PESDR_HSSL3STS(n) (sdr_base(n) + 0x11)
  77. #define PESDR0_UTLSET1 0x0300
  78. #define PESDR0_UTLSET2 0x0301
  79. #define PESDR0_DLPSET 0x0302
  80. #define PESDR0_LOOP 0x0303
  81. #define PESDR0_RCSSET 0x0304
  82. #define PESDR0_RCSSTS 0x0305
  83. #define PESDR0_HSSL0SET1 0x0306
  84. #define PESDR0_HSSL0SET2 0x0307
  85. #define PESDR0_HSSL0STS 0x0308
  86. #define PESDR0_HSSL1SET1 0x0309
  87. #define PESDR0_HSSL1SET2 0x030a
  88. #define PESDR0_HSSL1STS 0x030b
  89. #define PESDR0_HSSL2SET1 0x030c
  90. #define PESDR0_HSSL2SET2 0x030d
  91. #define PESDR0_HSSL2STS 0x030e
  92. #define PESDR0_HSSL3SET1 0x030f
  93. #define PESDR0_HSSL3SET2 0x0310
  94. #define PESDR0_HSSL3STS 0x0311
  95. #define PESDR0_HSSL4SET1 0x0312
  96. #define PESDR0_HSSL4SET2 0x0313
  97. #define PESDR0_HSSL4STS 0x0314
  98. #define PESDR0_HSSL5SET1 0x0315
  99. #define PESDR0_HSSL5SET2 0x0316
  100. #define PESDR0_HSSL5STS 0x0317
  101. #define PESDR0_HSSL6SET1 0x0318
  102. #define PESDR0_HSSL6SET2 0x0319
  103. #define PESDR0_HSSL6STS 0x031a
  104. #define PESDR0_HSSL7SET1 0x031b
  105. #define PESDR0_HSSL7SET2 0x031c
  106. #define PESDR0_HSSL7STS 0x031d
  107. #define PESDR0_HSSCTLSET 0x031e
  108. #define PESDR0_LANE_ABCD 0x031f
  109. #define PESDR0_LANE_EFGH 0x0320
  110. #define PESDR1_UTLSET1 0x0340
  111. #define PESDR1_UTLSET2 0x0341
  112. #define PESDR1_DLPSET 0x0342
  113. #define PESDR1_LOOP 0x0343
  114. #define PESDR1_RCSSET 0x0344
  115. #define PESDR1_RCSSTS 0x0345
  116. #define PESDR1_HSSL0SET1 0x0346
  117. #define PESDR1_HSSL0SET2 0x0347
  118. #define PESDR1_HSSL0STS 0x0348
  119. #define PESDR1_HSSL1SET1 0x0349
  120. #define PESDR1_HSSL1SET2 0x034a
  121. #define PESDR1_HSSL1STS 0x034b
  122. #define PESDR1_HSSL2SET1 0x034c
  123. #define PESDR1_HSSL2SET2 0x034d
  124. #define PESDR1_HSSL2STS 0x034e
  125. #define PESDR1_HSSL3SET1 0x034f
  126. #define PESDR1_HSSL3SET2 0x0350
  127. #define PESDR1_HSSL3STS 0x0351
  128. #define PESDR1_HSSCTLSET 0x0352
  129. #define PESDR1_LANE_ABCD 0x0353
  130. #define PESDR2_UTLSET1 0x0370
  131. #define PESDR2_UTLSET2 0x0371
  132. #define PESDR2_DLPSET 0x0372
  133. #define PESDR2_LOOP 0x0373
  134. #define PESDR2_RCSSET 0x0374
  135. #define PESDR2_RCSSTS 0x0375
  136. #define PESDR2_HSSL0SET1 0x0376
  137. #define PESDR2_HSSL0SET2 0x0377
  138. #define PESDR2_HSSL0STS 0x0378
  139. #define PESDR2_HSSL1SET1 0x0379
  140. #define PESDR2_HSSL1SET2 0x037a
  141. #define PESDR2_HSSL1STS 0x037b
  142. #define PESDR2_HSSL2SET1 0x037c
  143. #define PESDR2_HSSL2SET2 0x037d
  144. #define PESDR2_HSSL2STS 0x037e
  145. #define PESDR2_HSSL3SET1 0x037f
  146. #define PESDR2_HSSL3SET2 0x0380
  147. #define PESDR2_HSSL3STS 0x0381
  148. #define PESDR2_HSSCTLSET 0x0382
  149. #define PESDR2_LANE_ABCD 0x0383
  150. #elif defined(CONFIG_405EX)
  151. #define SDRN_PESDR_PHYSET1(n) (sdr_base(n) + 0x06)
  152. #define SDRN_PESDR_PHYSET2(n) (sdr_base(n) + 0x07)
  153. #define SDRN_PESDR_BIST(n) (sdr_base(n) + 0x08)
  154. #define SDRN_PESDR_LPB(n) (sdr_base(n) + 0x0b)
  155. #define SDRN_PESDR_PHYSTA(n) (sdr_base(n) + 0x0c)
  156. #define PESDR0_UTLSET1 0x0400
  157. #define PESDR0_UTLSET2 0x0401
  158. #define PESDR0_DLPSET 0x0402
  159. #define PESDR0_LOOP 0x0403
  160. #define PESDR0_RCSSET 0x0404
  161. #define PESDR0_RCSSTS 0x0405
  162. #define PESDR0_PHYSET1 0x0406
  163. #define PESDR0_PHYSET2 0x0407
  164. #define PESDR0_BIST 0x0408
  165. #define PESDR0_LPB 0x040B
  166. #define PESDR0_PHYSTA 0x040C
  167. #define PESDR1_UTLSET1 0x0440
  168. #define PESDR1_UTLSET2 0x0441
  169. #define PESDR1_DLPSET 0x0442
  170. #define PESDR1_LOOP 0x0443
  171. #define PESDR1_RCSSET 0x0444
  172. #define PESDR1_RCSSTS 0x0445
  173. #define PESDR1_PHYSET1 0x0446
  174. #define PESDR1_PHYSET2 0x0447
  175. #define PESDR1_BIST 0x0448
  176. #define PESDR1_LPB 0x044B
  177. #define PESDR1_PHYSTA 0x044C
  178. #endif
  179. /*
  180. * UTL register offsets
  181. */
  182. #define PEUTL_PBCTL 0x00
  183. #define PEUTL_PBBSZ 0x20
  184. #define PEUTL_OPDBSZ 0x68
  185. #define PEUTL_IPHBSZ 0x70
  186. #define PEUTL_IPDBSZ 0x78
  187. #define PEUTL_OUTTR 0x90
  188. #define PEUTL_INTR 0x98
  189. #define PEUTL_PCTL 0xa0
  190. #define PEUTL_RCSTA 0xb0
  191. #define PEUTL_RCIRQEN 0xb8
  192. /*
  193. * Config space register offsets
  194. */
  195. #define PECFG_BAR0LMPA 0x210
  196. #define PECFG_BAR0HMPA 0x214
  197. #define PECFG_BAR1MPA 0x218
  198. #define PECFG_BAR2LMPA 0x220
  199. #define PECFG_BAR2HMPA 0x224
  200. #define PECFG_PIMEN 0x33c
  201. #define PECFG_PIM0LAL 0x340
  202. #define PECFG_PIM0LAH 0x344
  203. #define PECFG_PIM1LAL 0x348
  204. #define PECFG_PIM1LAH 0x34c
  205. #define PECFG_PIM01SAL 0x350
  206. #define PECFG_PIM01SAH 0x354
  207. #define PECFG_POM0LAL 0x380
  208. #define PECFG_POM0LAH 0x384
  209. #define SDR_READ(offset) ({\
  210. mtdcr(DCRN_SDR0_CFGADDR, offset); \
  211. mfdcr(DCRN_SDR0_CFGDATA);})
  212. #define SDR_WRITE(offset, data) ({\
  213. mtdcr(DCRN_SDR0_CFGADDR, offset); \
  214. mtdcr(DCRN_SDR0_CFGDATA,data);})
  215. #define GPL_DMER_MASK_DISA 0x02000000
  216. #define U64_TO_U32_LOW(val) ((u32)((val) & 0x00000000ffffffffULL))
  217. #define U64_TO_U32_HIGH(val) ((u32)((val) >> 32))
  218. /*
  219. * Prototypes
  220. */
  221. int ppc4xx_init_pcie(void);
  222. int ppc4xx_init_pcie_rootport(int port);
  223. int ppc4xx_init_pcie_endport(int port);
  224. void ppc4xx_setup_pcie_rootpoint(struct pci_controller *hose, int port);
  225. int ppc4xx_setup_pcie_endpoint(struct pci_controller *hose, int port);
  226. int pcie_hose_scan(struct pci_controller *hose, int bus);
  227. /*
  228. * Function to determine root port or endport from env variable.
  229. */
  230. static inline int is_end_point(int port)
  231. {
  232. char s[10], *tk;
  233. char *pcie_mode = getenv("pcie_mode");
  234. if (pcie_mode == NULL)
  235. return 0;
  236. strcpy(s, pcie_mode);
  237. tk = strtok(s, ":");
  238. switch (port) {
  239. case 0:
  240. if (tk != NULL) {
  241. if (!(strcmp(tk, "ep") && strcmp(tk, "EP")))
  242. return 1;
  243. else
  244. return 0;
  245. }
  246. else
  247. return 0;
  248. case 1:
  249. tk = strtok(NULL, ":");
  250. if (tk != NULL) {
  251. if (!(strcmp(tk, "ep") && strcmp(tk, "EP")))
  252. return 1;
  253. else
  254. return 0;
  255. }
  256. else
  257. return 0;
  258. case 2:
  259. tk = strtok(NULL, ":");
  260. if (tk != NULL)
  261. tk = strtok(NULL, ":");
  262. if (tk != NULL) {
  263. if (!(strcmp(tk, "ep") && strcmp(tk, "EP")))
  264. return 1;
  265. else
  266. return 0;
  267. }
  268. else
  269. return 0;
  270. }
  271. return 0;
  272. }
  273. static inline void mdelay(int n)
  274. {
  275. u32 ms = n;
  276. while (ms--)
  277. udelay(1000);
  278. }
  279. static inline u32 sdr_base(int port)
  280. {
  281. switch (port) {
  282. default: /* to satisfy compiler */
  283. case 0:
  284. return PCIE0_SDR;
  285. case 1:
  286. return PCIE1_SDR;
  287. #if CFG_PCIE_NR_PORTS > 2
  288. case 2:
  289. return PCIE2_SDR;
  290. #endif
  291. }
  292. }
  293. #endif /* __4XX_PCIE_H */