4xx_pcie.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871
  1. /*
  2. * (C) Copyright 2006 - 2007
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * Copyright (c) 2005 Cisco Systems. All rights reserved.
  6. * Roland Dreier <rolandd@cisco.com>
  7. *
  8. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. */
  22. #include <asm/processor.h>
  23. #include <asm-ppc/io.h>
  24. #include <ppc4xx.h>
  25. #include <common.h>
  26. #include <pci.h>
  27. #if defined(CONFIG_440SPE) && defined(CONFIG_PCI)
  28. #include <asm/4xx_pcie.h>
  29. enum {
  30. PTYPE_ENDPOINT = 0x0,
  31. PTYPE_LEGACY_ENDPOINT = 0x1,
  32. PTYPE_ROOT_PORT = 0x4,
  33. LNKW_X1 = 0x1,
  34. LNKW_X4 = 0x4,
  35. LNKW_X8 = 0x8
  36. };
  37. static u8* pcie_get_base(struct pci_controller *hose, unsigned int devfn)
  38. {
  39. u8 *base = (u8*)hose->cfg_data;
  40. /* use local configuration space for the first bus */
  41. if (PCI_BUS(devfn) == 0) {
  42. if (hose->cfg_data == (u8*)CFG_PCIE0_CFGBASE)
  43. base = (u8*)CFG_PCIE0_XCFGBASE;
  44. if (hose->cfg_data == (u8*)CFG_PCIE1_CFGBASE)
  45. base = (u8*)CFG_PCIE1_XCFGBASE;
  46. if (hose->cfg_data == (u8*)CFG_PCIE2_CFGBASE)
  47. base = (u8*)CFG_PCIE2_XCFGBASE;
  48. }
  49. return base;
  50. }
  51. static void pcie_dmer_disable(void)
  52. {
  53. mtdcr (DCRN_PEGPL_CFG(DCRN_PCIE0_BASE),
  54. mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE0_BASE)) | GPL_DMER_MASK_DISA);
  55. mtdcr (DCRN_PEGPL_CFG(DCRN_PCIE1_BASE),
  56. mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE1_BASE)) | GPL_DMER_MASK_DISA);
  57. mtdcr (DCRN_PEGPL_CFG(DCRN_PCIE2_BASE),
  58. mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE2_BASE)) | GPL_DMER_MASK_DISA);
  59. }
  60. static void pcie_dmer_enable(void)
  61. {
  62. mtdcr (DCRN_PEGPL_CFG (DCRN_PCIE0_BASE),
  63. mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE0_BASE)) & ~GPL_DMER_MASK_DISA);
  64. mtdcr (DCRN_PEGPL_CFG (DCRN_PCIE1_BASE),
  65. mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE1_BASE)) & ~GPL_DMER_MASK_DISA);
  66. mtdcr (DCRN_PEGPL_CFG (DCRN_PCIE2_BASE),
  67. mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE2_BASE)) & ~GPL_DMER_MASK_DISA);
  68. }
  69. static int pcie_read_config(struct pci_controller *hose, unsigned int devfn,
  70. int offset, int len, u32 *val) {
  71. u8 *address;
  72. *val = 0;
  73. /*
  74. * Bus numbers are relative to hose->first_busno
  75. */
  76. devfn -= PCI_BDF(hose->first_busno, 0, 0);
  77. /*
  78. * NOTICE: configuration space ranges are currenlty mapped only for
  79. * the first 16 buses, so such limit must be imposed. In case more
  80. * buses are required the TLB settings in board/amcc/<board>/init.S
  81. * need to be altered accordingly (one bus takes 1 MB of memory space).
  82. */
  83. if (PCI_BUS(devfn) >= 16)
  84. return 0;
  85. /*
  86. * Only single device/single function is supported for the primary and
  87. * secondary buses of the 440SPe host bridge.
  88. */
  89. if ((!((PCI_FUNC(devfn) == 0) && (PCI_DEV(devfn) == 0))) &&
  90. ((PCI_BUS(devfn) == 0) || (PCI_BUS(devfn) == 1)))
  91. return 0;
  92. address = pcie_get_base(hose, devfn);
  93. offset += devfn << 4;
  94. /*
  95. * Reading from configuration space of non-existing device can
  96. * generate transaction errors. For the read duration we suppress
  97. * assertion of machine check exceptions to avoid those.
  98. */
  99. pcie_dmer_disable ();
  100. switch (len) {
  101. case 1:
  102. *val = in_8(hose->cfg_data + offset);
  103. break;
  104. case 2:
  105. *val = in_le16((u16 *)(hose->cfg_data + offset));
  106. break;
  107. default:
  108. *val = in_le32((u32*)(hose->cfg_data + offset));
  109. break;
  110. }
  111. pcie_dmer_enable ();
  112. return 0;
  113. }
  114. static int pcie_write_config(struct pci_controller *hose, unsigned int devfn,
  115. int offset, int len, u32 val) {
  116. u8 *address;
  117. /*
  118. * Bus numbers are relative to hose->first_busno
  119. */
  120. devfn -= PCI_BDF(hose->first_busno, 0, 0);
  121. /*
  122. * Same constraints as in pcie_read_config().
  123. */
  124. if (PCI_BUS(devfn) >= 16)
  125. return 0;
  126. if ((!((PCI_FUNC(devfn) == 0) && (PCI_DEV(devfn) == 0))) &&
  127. ((PCI_BUS(devfn) == 0) || (PCI_BUS(devfn) == 1)))
  128. return 0;
  129. address = pcie_get_base(hose, devfn);
  130. offset += devfn << 4;
  131. /*
  132. * Suppress MCK exceptions, similar to pcie_read_config()
  133. */
  134. pcie_dmer_disable ();
  135. switch (len) {
  136. case 1:
  137. out_8(hose->cfg_data + offset, val);
  138. break;
  139. case 2:
  140. out_le16((u16 *)(hose->cfg_data + offset), val);
  141. break;
  142. default:
  143. out_le32((u32 *)(hose->cfg_data + offset), val);
  144. break;
  145. }
  146. pcie_dmer_enable ();
  147. return 0;
  148. }
  149. int pcie_read_config_byte(struct pci_controller *hose,pci_dev_t dev,int offset,u8 *val)
  150. {
  151. u32 v;
  152. int rv;
  153. rv = pcie_read_config(hose, dev, offset, 1, &v);
  154. *val = (u8)v;
  155. return rv;
  156. }
  157. int pcie_read_config_word(struct pci_controller *hose,pci_dev_t dev,int offset,u16 *val)
  158. {
  159. u32 v;
  160. int rv;
  161. rv = pcie_read_config(hose, dev, offset, 2, &v);
  162. *val = (u16)v;
  163. return rv;
  164. }
  165. int pcie_read_config_dword(struct pci_controller *hose,pci_dev_t dev,int offset,u32 *val)
  166. {
  167. u32 v;
  168. int rv;
  169. rv = pcie_read_config(hose, dev, offset, 3, &v);
  170. *val = (u32)v;
  171. return rv;
  172. }
  173. int pcie_write_config_byte(struct pci_controller *hose,pci_dev_t dev,int offset,u8 val)
  174. {
  175. return pcie_write_config(hose,(u32)dev,offset,1,val);
  176. }
  177. int pcie_write_config_word(struct pci_controller *hose,pci_dev_t dev,int offset,u16 val)
  178. {
  179. return pcie_write_config(hose,(u32)dev,offset,2,(u32 )val);
  180. }
  181. int pcie_write_config_dword(struct pci_controller *hose,pci_dev_t dev,int offset,u32 val)
  182. {
  183. return pcie_write_config(hose,(u32)dev,offset,3,(u32 )val);
  184. }
  185. static void ppc4xx_setup_utl(u32 port) {
  186. volatile void *utl_base = NULL;
  187. /*
  188. * Map UTL registers
  189. */
  190. switch (port) {
  191. case 0:
  192. mtdcr(DCRN_PEGPL_REGBAH(PCIE0), 0x0000000c);
  193. mtdcr(DCRN_PEGPL_REGBAL(PCIE0), 0x20000000);
  194. mtdcr(DCRN_PEGPL_REGMSK(PCIE0), 0x00007001);
  195. mtdcr(DCRN_PEGPL_SPECIAL(PCIE0), 0x68782800);
  196. break;
  197. case 1:
  198. mtdcr(DCRN_PEGPL_REGBAH(PCIE1), 0x0000000c);
  199. mtdcr(DCRN_PEGPL_REGBAL(PCIE1), 0x20001000);
  200. mtdcr(DCRN_PEGPL_REGMSK(PCIE1), 0x00007001);
  201. mtdcr(DCRN_PEGPL_SPECIAL(PCIE1), 0x68782800);
  202. break;
  203. case 2:
  204. mtdcr(DCRN_PEGPL_REGBAH(PCIE2), 0x0000000c);
  205. mtdcr(DCRN_PEGPL_REGBAL(PCIE2), 0x20002000);
  206. mtdcr(DCRN_PEGPL_REGMSK(PCIE2), 0x00007001);
  207. mtdcr(DCRN_PEGPL_SPECIAL(PCIE2), 0x68782800);
  208. break;
  209. }
  210. utl_base = (unsigned int *)(CFG_PCIE_BASE + 0x1000 * port);
  211. /*
  212. * Set buffer allocations and then assert VRB and TXE.
  213. */
  214. out_be32(utl_base + PEUTL_OUTTR, 0x08000000);
  215. out_be32(utl_base + PEUTL_INTR, 0x02000000);
  216. out_be32(utl_base + PEUTL_OPDBSZ, 0x10000000);
  217. out_be32(utl_base + PEUTL_PBBSZ, 0x53000000);
  218. out_be32(utl_base + PEUTL_IPHBSZ, 0x08000000);
  219. out_be32(utl_base + PEUTL_IPDBSZ, 0x10000000);
  220. out_be32(utl_base + PEUTL_RCIRQEN, 0x00f00000);
  221. out_be32(utl_base + PEUTL_PCTL, 0x80800066);
  222. }
  223. static int check_error(void)
  224. {
  225. u32 valPE0, valPE1, valPE2;
  226. int err = 0;
  227. /* SDR0_PEGPLLLCT1 reset */
  228. if (!(valPE0 = SDR_READ(PESDR0_PLLLCT1) & 0x01000000)) {
  229. printf("PCIE: SDR0_PEGPLLLCT1 reset error 0x%x\n", valPE0);
  230. }
  231. valPE0 = SDR_READ(PESDR0_RCSSET);
  232. valPE1 = SDR_READ(PESDR1_RCSSET);
  233. valPE2 = SDR_READ(PESDR2_RCSSET);
  234. /* SDR0_PExRCSSET rstgu */
  235. if (!(valPE0 & 0x01000000) ||
  236. !(valPE1 & 0x01000000) ||
  237. !(valPE2 & 0x01000000)) {
  238. printf("PCIE: SDR0_PExRCSSET rstgu error\n");
  239. err = -1;
  240. }
  241. /* SDR0_PExRCSSET rstdl */
  242. if (!(valPE0 & 0x00010000) ||
  243. !(valPE1 & 0x00010000) ||
  244. !(valPE2 & 0x00010000)) {
  245. printf("PCIE: SDR0_PExRCSSET rstdl error\n");
  246. err = -1;
  247. }
  248. /* SDR0_PExRCSSET rstpyn */
  249. if ((valPE0 & 0x00001000) ||
  250. (valPE1 & 0x00001000) ||
  251. (valPE2 & 0x00001000)) {
  252. printf("PCIE: SDR0_PExRCSSET rstpyn error\n");
  253. err = -1;
  254. }
  255. /* SDR0_PExRCSSET hldplb */
  256. if ((valPE0 & 0x10000000) ||
  257. (valPE1 & 0x10000000) ||
  258. (valPE2 & 0x10000000)) {
  259. printf("PCIE: SDR0_PExRCSSET hldplb error\n");
  260. err = -1;
  261. }
  262. /* SDR0_PExRCSSET rdy */
  263. if ((valPE0 & 0x00100000) ||
  264. (valPE1 & 0x00100000) ||
  265. (valPE2 & 0x00100000)) {
  266. printf("PCIE: SDR0_PExRCSSET rdy error\n");
  267. err = -1;
  268. }
  269. /* SDR0_PExRCSSET shutdown */
  270. if ((valPE0 & 0x00000100) ||
  271. (valPE1 & 0x00000100) ||
  272. (valPE2 & 0x00000100)) {
  273. printf("PCIE: SDR0_PExRCSSET shutdown error\n");
  274. err = -1;
  275. }
  276. return err;
  277. }
  278. /*
  279. * Initialize PCI Express core
  280. */
  281. int ppc4xx_init_pcie(void)
  282. {
  283. int time_out = 20;
  284. /* Set PLL clock receiver to LVPECL */
  285. SDR_WRITE(PESDR0_PLLLCT1, SDR_READ(PESDR0_PLLLCT1) | 1 << 28);
  286. if (check_error())
  287. return -1;
  288. if (!(SDR_READ(PESDR0_PLLLCT2) & 0x10000))
  289. {
  290. printf("PCIE: PESDR_PLLCT2 resistance calibration failed (0x%08x)\n",
  291. SDR_READ(PESDR0_PLLLCT2));
  292. return -1;
  293. }
  294. /* De-assert reset of PCIe PLL, wait for lock */
  295. SDR_WRITE(PESDR0_PLLLCT1, SDR_READ(PESDR0_PLLLCT1) & ~(1 << 24));
  296. udelay(3);
  297. while (time_out) {
  298. if (!(SDR_READ(PESDR0_PLLLCT3) & 0x10000000)) {
  299. time_out--;
  300. udelay(1);
  301. } else
  302. break;
  303. }
  304. if (!time_out) {
  305. printf("PCIE: VCO output not locked\n");
  306. return -1;
  307. }
  308. return 0;
  309. }
  310. /*
  311. * Board-specific pcie initialization
  312. * Platform code can reimplement ppc4xx_init_pcie_port_hw() if needed
  313. */
  314. /*
  315. * Initialize various parts of the PCI Express core for our port:
  316. *
  317. * - Set as a root port and enable max width
  318. * (PXIE0 -> X8, PCIE1 and PCIE2 -> X4).
  319. * - Set up UTL configuration.
  320. * - Increase SERDES drive strength to levels suggested by AMCC.
  321. * - De-assert RSTPYN, RSTDL and RSTGU.
  322. *
  323. * NOTICE for 440SPE revB chip: PESDRn_UTLSET2 is not set - we leave it
  324. * with default setting 0x11310000. The register has new fields,
  325. * PESDRn_UTLSET2[LKINE] in particular: clearing it leads to PCIE core
  326. * hang.
  327. */
  328. #if defined(CONFIG_440SPE)
  329. int __ppc4xx_init_pcie_port_hw(int port, int rootport)
  330. {
  331. u32 val = 1 << 24;
  332. u32 utlset1;
  333. if (rootport) {
  334. val = PTYPE_ROOT_PORT << 20;
  335. utlset1 = 0x21222222;
  336. } else {
  337. val = PTYPE_LEGACY_ENDPOINT << 20;
  338. utlset1 = 0x20222222;
  339. }
  340. if (port == 0)
  341. val |= LNKW_X8 << 12;
  342. else
  343. val |= LNKW_X4 << 12;
  344. SDR_WRITE(SDRN_PESDR_DLPSET(port), val);
  345. SDR_WRITE(SDRN_PESDR_UTLSET1(port), utlset1);
  346. if (!ppc440spe_revB())
  347. SDR_WRITE(SDRN_PESDR_UTLSET2(port), 0x11000000);
  348. SDR_WRITE(SDRN_PESDR_HSSL0SET1(port), 0x35000000);
  349. SDR_WRITE(SDRN_PESDR_HSSL1SET1(port), 0x35000000);
  350. SDR_WRITE(SDRN_PESDR_HSSL2SET1(port), 0x35000000);
  351. SDR_WRITE(SDRN_PESDR_HSSL3SET1(port), 0x35000000);
  352. if (port == 0) {
  353. SDR_WRITE(PESDR0_HSSL4SET1, 0x35000000);
  354. SDR_WRITE(PESDR0_HSSL5SET1, 0x35000000);
  355. SDR_WRITE(PESDR0_HSSL6SET1, 0x35000000);
  356. SDR_WRITE(PESDR0_HSSL7SET1, 0x35000000);
  357. }
  358. SDR_WRITE(SDRN_PESDR_RCSSET(port), (SDR_READ(SDRN_PESDR_RCSSET(port)) &
  359. ~(1 << 24 | 1 << 16)) | 1 << 12);
  360. return 0;
  361. }
  362. #endif /* CONFIG_440SPE */
  363. #if defined(CONFIG_405EX)
  364. int __ppc4xx_init_pcie_port_hw(int port, int rootport)
  365. {
  366. u32 val;
  367. if (rootport)
  368. val = 0x00401000;
  369. else
  370. val = 0x00101000;
  371. SDR_WRITE(SDRN_PESDR_DLPSET(port), val);
  372. SDR_WRITE(SDRN_PESDR_UTLSET1(port), 0x20222222);
  373. SDR_WRITE(SDRN_PESDR_UTLSET2(port), 0x01110000);
  374. SDR_WRITE(SDRN_PESDR_PHYSET1(port), 0x720F0000);
  375. SDR_WRITE(SDRN_PESDR_PHYSET2(port), 0x70600003);
  376. /* Assert the PE0_PHY reset */
  377. SDR_WRITE(SDRN_PESDR_RCSSET(port), 0x01010000);
  378. udelay(1000);
  379. /* deassert the PE0_hotreset */
  380. SDR_WRITE(SDRN_PESDR_RCSSET(port), 0x01101000);
  381. /* poll for phy !reset */
  382. while (!(SDR_READ(SDRN_PESDR_PHYSTA(port)) & 0x00001000))
  383. ;
  384. /* deassert the PE0_gpl_utl_reset */
  385. SDR_WRITE(SDRN_PESDR_RCSSET(port), 0x00101000);
  386. if (port == 0)
  387. mtdcr(DCRN_PEGPL_CFG(PCIE0), 0x10000000); /* guarded on */
  388. else
  389. mtdcr(DCRN_PEGPL_CFG(PCIE1), 0x10000000); /* guarded on */
  390. return 0;
  391. }
  392. #endif /* CONFIG_405EX */
  393. int ppc4xx_init_pcie_port_hw(int port, int rootport)
  394. __attribute__((weak, alias("__ppc4xx_init_pcie_port_hw")));
  395. /*
  396. * We map PCI Express configuration access into the 512MB regions
  397. *
  398. * NOTICE: revB is very strict about PLB real addressess and ranges to
  399. * be mapped for config space; it seems to only work with d_nnnn_nnnn
  400. * range (hangs the core upon config transaction attempts when set
  401. * otherwise) while revA uses c_nnnn_nnnn.
  402. *
  403. * For revA:
  404. * PCIE0: 0xc_4000_0000
  405. * PCIE1: 0xc_8000_0000
  406. * PCIE2: 0xc_c000_0000
  407. *
  408. * For revB:
  409. * PCIE0: 0xd_0000_0000
  410. * PCIE1: 0xd_2000_0000
  411. * PCIE2: 0xd_4000_0000
  412. *
  413. * For 405EX:
  414. * PCIE0: 0xa000_0000
  415. * PCIE1: 0xc000_0000
  416. */
  417. static inline u64 ppc4xx_get_cfgaddr(int port)
  418. {
  419. #if defined(CONFIG_405EX)
  420. if (port == 0)
  421. return (u64)CFG_PCIE0_CFGBASE;
  422. else
  423. return (u64)CFG_PCIE1_CFGBASE;
  424. #endif
  425. #if defined(CONFIG_440SPE)
  426. if (ppc440spe_revB()) {
  427. switch (port) {
  428. default: /* to satisfy compiler */
  429. case 0:
  430. return 0x0000000d00000000ULL;
  431. case 1:
  432. return 0x0000000d20000000ULL;
  433. case 2:
  434. return 0x0000000d40000000ULL;
  435. }
  436. } else {
  437. switch (port) {
  438. default: /* to satisfy compiler */
  439. case 0:
  440. return 0x0000000c40000000ULL;
  441. case 1:
  442. return 0x0000000c80000000ULL;
  443. case 2:
  444. return 0x0000000cc0000000ULL;
  445. }
  446. }
  447. #endif
  448. }
  449. /*
  450. * 4xx boards as end point and root point setup
  451. * and
  452. * testing inbound and out bound windows
  453. *
  454. * 4xx boards can be plugged into another 4xx boards or you can get PCI-E
  455. * cable which can be used to setup loop back from one port to another port.
  456. * Please rememeber that unless there is a endpoint plugged in to root port it
  457. * will not initialize. It is the same in case of endpoint , unless there is
  458. * root port attached it will not initialize.
  459. *
  460. * In this release of software all the PCI-E ports are configured as either
  461. * endpoint or rootpoint.In future we will have support for selective ports
  462. * setup as endpoint and root point in single board.
  463. *
  464. * Once your board came up as root point , you can verify by reading
  465. * /proc/bus/pci/devices. Where you can see the configuration registers
  466. * of end point device attached to the port.
  467. *
  468. * Enpoint cofiguration can be verified by connecting 4xx board to any
  469. * host or another 4xx board. Then try to scan the device. In case of
  470. * linux use "lspci" or appripriate os command.
  471. *
  472. * How do I verify the inbound and out bound windows ? (4xx to 4xx)
  473. * in this configuration inbound and outbound windows are setup to access
  474. * sram memroy area. SRAM is at 0x4 0000 0000 , on PLB bus. This address
  475. * is mapped at 0x90000000. From u-boot prompt write data 0xb000 0000,
  476. * This is waere your POM(PLB out bound memory window) mapped. then
  477. * read the data from other 4xx board's u-boot prompt at address
  478. * 0x9000 0000(SRAM). Data should match.
  479. * In case of inbound , write data to u-boot command prompt at 0xb000 0000
  480. * which is mapped to 0x4 0000 0000. Now on rootpoint yucca u-boot prompt check
  481. * data at 0x9000 0000(SRAM).Data should match.
  482. */
  483. int ppc4xx_init_pcie_port(int port, int rootport)
  484. {
  485. static int core_init;
  486. volatile u32 val = 0;
  487. int attempts;
  488. u64 addr;
  489. u32 low, high;
  490. if (!core_init) {
  491. ++core_init;
  492. if (ppc4xx_init_pcie())
  493. return -1;
  494. }
  495. /*
  496. * Initialize various parts of the PCI Express core for our port
  497. */
  498. ppc4xx_init_pcie_port_hw(port, rootport);
  499. /*
  500. * Notice: the following delay has critical impact on device
  501. * initialization - if too short (<50ms) the link doesn't get up.
  502. */
  503. mdelay(100);
  504. val = SDR_READ(SDRN_PESDR_RCSSTS(sdr_base(port)));
  505. if (val & (1 << 20)) {
  506. printf("PCIE%d: PGRST failed %08x\n", port, val);
  507. return -1;
  508. }
  509. /*
  510. * Verify link is up
  511. */
  512. val = SDR_READ(SDRN_PESDR_LOOP(sdr_base(port)));
  513. if (!(val & 0x00001000)) {
  514. printf("PCIE%d: link is not up.\n", port);
  515. return -1;
  516. }
  517. /*
  518. * Setup UTL registers - but only on revA!
  519. * We use default settings for revB chip.
  520. */
  521. if (!ppc440spe_revB())
  522. ppc4xx_setup_utl(port);
  523. /*
  524. * We map PCI Express configuration access into the 512MB regions
  525. */
  526. addr = ppc4xx_get_cfgaddr(port);
  527. low = (u32)(addr & 0x00000000ffffffff);
  528. high = (u32)(addr >> 32);
  529. switch (port) {
  530. case 0:
  531. mtdcr(DCRN_PEGPL_CFGBAH(PCIE0), high);
  532. mtdcr(DCRN_PEGPL_CFGBAL(PCIE0), low);
  533. mtdcr(DCRN_PEGPL_CFGMSK(PCIE0), 0xe0000001); /* 512MB region, valid */
  534. break;
  535. case 1:
  536. mtdcr(DCRN_PEGPL_CFGBAH(PCIE1), high);
  537. mtdcr(DCRN_PEGPL_CFGBAL(PCIE1), low);
  538. mtdcr(DCRN_PEGPL_CFGMSK(PCIE1), 0xe0000001); /* 512MB region, valid */
  539. break;
  540. case 2:
  541. mtdcr(DCRN_PEGPL_CFGBAH(PCIE2), high);
  542. mtdcr(DCRN_PEGPL_CFGBAL(PCIE2), low);
  543. mtdcr(DCRN_PEGPL_CFGMSK(PCIE2), 0xe0000001); /* 512MB region, valid */
  544. break;
  545. }
  546. /*
  547. * Check for VC0 active and assert RDY.
  548. */
  549. attempts = 10;
  550. while(!(SDR_READ(SDRN_PESDR_RCSSTS(sdr_base(port))) & (1 << 16))) {
  551. if (!(attempts--)) {
  552. printf("PCIE%d: VC0 not active\n", port);
  553. return -1;
  554. }
  555. mdelay(1000);
  556. }
  557. SDR_WRITE(SDRN_PESDR_RCSSET(sdr_base(port)),
  558. SDR_READ(SDRN_PESDR_RCSSET(sdr_base(port))) | 1 << 20);
  559. mdelay(100);
  560. return 0;
  561. }
  562. int ppc4xx_init_pcie_rootport(int port)
  563. {
  564. return ppc4xx_init_pcie_port(port, 1);
  565. }
  566. int ppc4xx_init_pcie_endport(int port)
  567. {
  568. return ppc4xx_init_pcie_port(port, 0);
  569. }
  570. void ppc4xx_setup_pcie_rootpoint(struct pci_controller *hose, int port)
  571. {
  572. volatile void *mbase = NULL;
  573. volatile void *rmbase = NULL;
  574. pci_set_ops(hose,
  575. pcie_read_config_byte,
  576. pcie_read_config_word,
  577. pcie_read_config_dword,
  578. pcie_write_config_byte,
  579. pcie_write_config_word,
  580. pcie_write_config_dword);
  581. switch (port) {
  582. case 0:
  583. mbase = (u32 *)CFG_PCIE0_XCFGBASE;
  584. rmbase = (u32 *)CFG_PCIE0_CFGBASE;
  585. hose->cfg_data = (u8 *)CFG_PCIE0_CFGBASE;
  586. break;
  587. case 1:
  588. mbase = (u32 *)CFG_PCIE1_XCFGBASE;
  589. rmbase = (u32 *)CFG_PCIE1_CFGBASE;
  590. hose->cfg_data = (u8 *)CFG_PCIE1_CFGBASE;
  591. break;
  592. case 2:
  593. mbase = (u32 *)CFG_PCIE2_XCFGBASE;
  594. rmbase = (u32 *)CFG_PCIE2_CFGBASE;
  595. hose->cfg_data = (u8 *)CFG_PCIE2_CFGBASE;
  596. break;
  597. }
  598. /*
  599. * Set bus numbers on our root port
  600. */
  601. out_8((u8 *)mbase + PCI_PRIMARY_BUS, 0);
  602. out_8((u8 *)mbase + PCI_SECONDARY_BUS, 1);
  603. out_8((u8 *)mbase + PCI_SUBORDINATE_BUS, 1);
  604. /*
  605. * Set up outbound translation to hose->mem_space from PLB
  606. * addresses at an offset of 0xd_0000_0000. We set the low
  607. * bits of the mask to 11 to turn off splitting into 8
  608. * subregions and to enable the outbound translation.
  609. */
  610. out_le32(mbase + PECFG_POM0LAH, 0x00000000);
  611. out_le32(mbase + PECFG_POM0LAL, 0x00000000);
  612. switch (port) {
  613. case 0:
  614. mtdcr(DCRN_PEGPL_OMR1BAH(PCIE0), 0x0000000d);
  615. mtdcr(DCRN_PEGPL_OMR1BAL(PCIE0), CFG_PCIE_MEMBASE +
  616. port * CFG_PCIE_MEMSIZE);
  617. mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE0), 0x7fffffff);
  618. mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE0),
  619. ~(CFG_PCIE_MEMSIZE - 1) | 3);
  620. break;
  621. case 1:
  622. mtdcr(DCRN_PEGPL_OMR1BAH(PCIE1), 0x0000000d);
  623. mtdcr(DCRN_PEGPL_OMR1BAL(PCIE1), CFG_PCIE_MEMBASE +
  624. port * CFG_PCIE_MEMSIZE);
  625. mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE1), 0x7fffffff);
  626. mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE1),
  627. ~(CFG_PCIE_MEMSIZE - 1) | 3);
  628. break;
  629. case 2:
  630. mtdcr(DCRN_PEGPL_OMR1BAH(PCIE2), 0x0000000d);
  631. mtdcr(DCRN_PEGPL_OMR1BAL(PCIE2), CFG_PCIE_MEMBASE +
  632. port * CFG_PCIE_MEMSIZE);
  633. mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE2), 0x7fffffff);
  634. mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE2),
  635. ~(CFG_PCIE_MEMSIZE - 1) | 3);
  636. break;
  637. }
  638. /* Set up 16GB inbound memory window at 0 */
  639. out_le32(mbase + PCI_BASE_ADDRESS_0, 0);
  640. out_le32(mbase + PCI_BASE_ADDRESS_1, 0);
  641. out_le32(mbase + PECFG_BAR0HMPA, 0x7fffffc);
  642. out_le32(mbase + PECFG_BAR0LMPA, 0);
  643. out_le32(mbase + PECFG_PIM01SAH, 0xffff0000);
  644. out_le32(mbase + PECFG_PIM01SAL, 0x00000000);
  645. out_le32(mbase + PECFG_PIM0LAL, 0);
  646. out_le32(mbase + PECFG_PIM0LAH, 0);
  647. out_le32(mbase + PECFG_PIM1LAL, 0x00000000);
  648. out_le32(mbase + PECFG_PIM1LAH, 0x00000004);
  649. out_le32(mbase + PECFG_PIMEN, 0x1);
  650. /* Enable I/O, Mem, and Busmaster cycles */
  651. out_le16((u16 *)(mbase + PCI_COMMAND),
  652. in_le16((u16 *)(mbase + PCI_COMMAND)) |
  653. PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
  654. /* Set Device and Vendor Id */
  655. switch (port) {
  656. case 0:
  657. out_le16(mbase + 0x200, 0xaaa0);
  658. out_le16(mbase + 0x202, 0xbed0);
  659. break;
  660. case 1:
  661. out_le16(mbase + 0x200, 0xaaa1);
  662. out_le16(mbase + 0x202, 0xbed1);
  663. break;
  664. case 2:
  665. out_le16(mbase + 0x200, 0xaaa2);
  666. out_le16(mbase + 0x202, 0xbed2);
  667. break;
  668. default:
  669. out_le16(mbase + 0x200, 0xaaa3);
  670. out_le16(mbase + 0x202, 0xbed3);
  671. }
  672. /* Set Class Code to PCI-PCI bridge and Revision Id to 1 */
  673. out_le32(mbase + 0x208, 0x06040001);
  674. printf("PCIE:%d successfully set as rootpoint\n", port);
  675. }
  676. int ppc4xx_setup_pcie_endpoint(struct pci_controller *hose, int port)
  677. {
  678. volatile void *mbase = NULL;
  679. int attempts = 0;
  680. pci_set_ops(hose,
  681. pcie_read_config_byte,
  682. pcie_read_config_word,
  683. pcie_read_config_dword,
  684. pcie_write_config_byte,
  685. pcie_write_config_word,
  686. pcie_write_config_dword);
  687. switch (port) {
  688. case 0:
  689. mbase = (u32 *)CFG_PCIE0_XCFGBASE;
  690. hose->cfg_data = (u8 *)CFG_PCIE0_CFGBASE;
  691. break;
  692. case 1:
  693. mbase = (u32 *)CFG_PCIE1_XCFGBASE;
  694. hose->cfg_data = (u8 *)CFG_PCIE1_CFGBASE;
  695. break;
  696. case 2:
  697. mbase = (u32 *)CFG_PCIE2_XCFGBASE;
  698. hose->cfg_data = (u8 *)CFG_PCIE2_CFGBASE;
  699. break;
  700. }
  701. /*
  702. * Set up outbound translation to hose->mem_space from PLB
  703. * addresses at an offset of 0xd_0000_0000. We set the low
  704. * bits of the mask to 11 to turn off splitting into 8
  705. * subregions and to enable the outbound translation.
  706. */
  707. out_le32(mbase + PECFG_POM0LAH, 0x00001ff8);
  708. out_le32(mbase + PECFG_POM0LAL, 0x00001000);
  709. switch (port) {
  710. case 0:
  711. mtdcr(DCRN_PEGPL_OMR1BAH(PCIE0), 0x0000000d);
  712. mtdcr(DCRN_PEGPL_OMR1BAL(PCIE0), CFG_PCIE_MEMBASE +
  713. port * CFG_PCIE_MEMSIZE);
  714. mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE0), 0x7fffffff);
  715. mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE0),
  716. ~(CFG_PCIE_MEMSIZE - 1) | 3);
  717. break;
  718. case 1:
  719. mtdcr(DCRN_PEGPL_OMR1BAH(PCIE1), 0x0000000d);
  720. mtdcr(DCRN_PEGPL_OMR1BAL(PCIE1), CFG_PCIE_MEMBASE +
  721. port * CFG_PCIE_MEMSIZE);
  722. mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE1), 0x7fffffff);
  723. mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE1),
  724. ~(CFG_PCIE_MEMSIZE - 1) | 3);
  725. break;
  726. case 2:
  727. mtdcr(DCRN_PEGPL_OMR1BAH(PCIE2), 0x0000000d);
  728. mtdcr(DCRN_PEGPL_OMR1BAL(PCIE2), CFG_PCIE_MEMBASE +
  729. port * CFG_PCIE_MEMSIZE);
  730. mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE2), 0x7fffffff);
  731. mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE2),
  732. ~(CFG_PCIE_MEMSIZE - 1) | 3);
  733. break;
  734. }
  735. /* Set up 16GB inbound memory window at 0 */
  736. out_le32(mbase + PCI_BASE_ADDRESS_0, 0);
  737. out_le32(mbase + PCI_BASE_ADDRESS_1, 0);
  738. out_le32(mbase + PECFG_BAR0HMPA, 0x7fffffc);
  739. out_le32(mbase + PECFG_BAR0LMPA, 0);
  740. out_le32(mbase + PECFG_PIM0LAL, 0x00000000);
  741. out_le32(mbase + PECFG_PIM0LAH, 0x00000004); /* pointing to SRAM */
  742. out_le32(mbase + PECFG_PIMEN, 0x1);
  743. /* Enable I/O, Mem, and Busmaster cycles */
  744. out_le16((u16 *)(mbase + PCI_COMMAND),
  745. in_le16((u16 *)(mbase + PCI_COMMAND)) |
  746. PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
  747. out_le16(mbase + 0x200,0xcaad); /* Setting vendor ID */
  748. out_le16(mbase + 0x202,0xfeed); /* Setting device ID */
  749. attempts = 10;
  750. while(!(SDR_READ(SDRN_PESDR_RCSSTS(sdr_base(port))) & (1 << 8))) {
  751. if (!(attempts--)) {
  752. printf("PCIE%d: BME not active\n", port);
  753. return -1;
  754. }
  755. mdelay(1000);
  756. }
  757. printf("PCIE:%d successfully set as endpoint\n",port);
  758. return 0;
  759. }
  760. #endif /* CONFIG_440SPE && CONFIG_PCI */