4xx_pcie.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877
  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. /*
  368. * test-only:
  369. * This needs some testing and perhaps changes for
  370. * endpoint configuration. Probably no PHY reset at all, etc.
  371. * sr, 2007-10-03
  372. */
  373. if (rootport)
  374. val = 0x00401000;
  375. else
  376. val = 0x00101000;
  377. SDR_WRITE(SDRN_PESDR_DLPSET(port), val);
  378. SDR_WRITE(SDRN_PESDR_UTLSET1(port), 0x20222222);
  379. SDR_WRITE(SDRN_PESDR_UTLSET2(port), 0x01110000);
  380. SDR_WRITE(SDRN_PESDR_PHYSET1(port), 0x720F0000);
  381. SDR_WRITE(SDRN_PESDR_PHYSET2(port), 0x70600003);
  382. /* Assert the PE0_PHY reset */
  383. SDR_WRITE(SDRN_PESDR_RCSSET(port), 0x01010000);
  384. udelay(1000);
  385. /* deassert the PE0_hotreset */
  386. SDR_WRITE(SDRN_PESDR_RCSSET(port), 0x01101000);
  387. /* poll for phy !reset */
  388. while (!(SDR_READ(SDRN_PESDR_PHYSTA(port)) & 0x00001000))
  389. ;
  390. /* deassert the PE0_gpl_utl_reset */
  391. SDR_WRITE(SDRN_PESDR_RCSSET(port), 0x00101000);
  392. if (port == 0)
  393. mtdcr(DCRN_PEGPL_CFG(PCIE0), 0x10000000); /* guarded on */
  394. else
  395. mtdcr(DCRN_PEGPL_CFG(PCIE1), 0x10000000); /* guarded on */
  396. return 0;
  397. }
  398. #endif /* CONFIG_405EX */
  399. int ppc4xx_init_pcie_port_hw(int port, int rootport)
  400. __attribute__((weak, alias("__ppc4xx_init_pcie_port_hw")));
  401. /*
  402. * We map PCI Express configuration access into the 512MB regions
  403. *
  404. * NOTICE: revB is very strict about PLB real addressess and ranges to
  405. * be mapped for config space; it seems to only work with d_nnnn_nnnn
  406. * range (hangs the core upon config transaction attempts when set
  407. * otherwise) while revA uses c_nnnn_nnnn.
  408. *
  409. * For revA:
  410. * PCIE0: 0xc_4000_0000
  411. * PCIE1: 0xc_8000_0000
  412. * PCIE2: 0xc_c000_0000
  413. *
  414. * For revB:
  415. * PCIE0: 0xd_0000_0000
  416. * PCIE1: 0xd_2000_0000
  417. * PCIE2: 0xd_4000_0000
  418. *
  419. * For 405EX:
  420. * PCIE0: 0xa000_0000
  421. * PCIE1: 0xc000_0000
  422. */
  423. static inline u64 ppc4xx_get_cfgaddr(int port)
  424. {
  425. #if defined(CONFIG_405EX)
  426. if (port == 0)
  427. return (u64)CFG_PCIE0_CFGBASE;
  428. else
  429. return (u64)CFG_PCIE1_CFGBASE;
  430. #endif
  431. #if defined(CONFIG_440SPE)
  432. if (ppc440spe_revB()) {
  433. switch (port) {
  434. default: /* to satisfy compiler */
  435. case 0:
  436. return 0x0000000d00000000ULL;
  437. case 1:
  438. return 0x0000000d20000000ULL;
  439. case 2:
  440. return 0x0000000d40000000ULL;
  441. }
  442. } else {
  443. switch (port) {
  444. default: /* to satisfy compiler */
  445. case 0:
  446. return 0x0000000c40000000ULL;
  447. case 1:
  448. return 0x0000000c80000000ULL;
  449. case 2:
  450. return 0x0000000cc0000000ULL;
  451. }
  452. }
  453. #endif
  454. }
  455. /*
  456. * 4xx boards as end point and root point setup
  457. * and
  458. * testing inbound and out bound windows
  459. *
  460. * 4xx boards can be plugged into another 4xx boards or you can get PCI-E
  461. * cable which can be used to setup loop back from one port to another port.
  462. * Please rememeber that unless there is a endpoint plugged in to root port it
  463. * will not initialize. It is the same in case of endpoint , unless there is
  464. * root port attached it will not initialize.
  465. *
  466. * In this release of software all the PCI-E ports are configured as either
  467. * endpoint or rootpoint.In future we will have support for selective ports
  468. * setup as endpoint and root point in single board.
  469. *
  470. * Once your board came up as root point , you can verify by reading
  471. * /proc/bus/pci/devices. Where you can see the configuration registers
  472. * of end point device attached to the port.
  473. *
  474. * Enpoint cofiguration can be verified by connecting 4xx board to any
  475. * host or another 4xx board. Then try to scan the device. In case of
  476. * linux use "lspci" or appripriate os command.
  477. *
  478. * How do I verify the inbound and out bound windows ? (4xx to 4xx)
  479. * in this configuration inbound and outbound windows are setup to access
  480. * sram memroy area. SRAM is at 0x4 0000 0000 , on PLB bus. This address
  481. * is mapped at 0x90000000. From u-boot prompt write data 0xb000 0000,
  482. * This is waere your POM(PLB out bound memory window) mapped. then
  483. * read the data from other 4xx board's u-boot prompt at address
  484. * 0x9000 0000(SRAM). Data should match.
  485. * In case of inbound , write data to u-boot command prompt at 0xb000 0000
  486. * which is mapped to 0x4 0000 0000. Now on rootpoint yucca u-boot prompt check
  487. * data at 0x9000 0000(SRAM).Data should match.
  488. */
  489. int ppc4xx_init_pcie_port(int port, int rootport)
  490. {
  491. static int core_init;
  492. volatile u32 val = 0;
  493. int attempts;
  494. u64 addr;
  495. u32 low, high;
  496. if (!core_init) {
  497. ++core_init;
  498. if (ppc4xx_init_pcie())
  499. return -1;
  500. }
  501. /*
  502. * Initialize various parts of the PCI Express core for our port
  503. */
  504. ppc4xx_init_pcie_port_hw(port, rootport);
  505. /*
  506. * Notice: the following delay has critical impact on device
  507. * initialization - if too short (<50ms) the link doesn't get up.
  508. */
  509. mdelay(100);
  510. val = SDR_READ(SDRN_PESDR_RCSSTS(port));
  511. if (val & (1 << 20)) {
  512. printf("PCIE%d: PGRST failed %08x\n", port, val);
  513. return -1;
  514. }
  515. /*
  516. * Verify link is up
  517. */
  518. val = SDR_READ(SDRN_PESDR_LOOP(port));
  519. if (!(val & 0x00001000)) {
  520. printf("PCIE%d: link is not up.\n", port);
  521. return -1;
  522. }
  523. /*
  524. * Setup UTL registers - but only on revA!
  525. * We use default settings for revB chip.
  526. */
  527. if (!ppc440spe_revB())
  528. ppc4xx_setup_utl(port);
  529. /*
  530. * We map PCI Express configuration access into the 512MB regions
  531. */
  532. addr = ppc4xx_get_cfgaddr(port);
  533. low = (u32)(addr & 0x00000000ffffffff);
  534. high = (u32)(addr >> 32);
  535. switch (port) {
  536. case 0:
  537. mtdcr(DCRN_PEGPL_CFGBAH(PCIE0), high);
  538. mtdcr(DCRN_PEGPL_CFGBAL(PCIE0), low);
  539. mtdcr(DCRN_PEGPL_CFGMSK(PCIE0), 0xe0000001); /* 512MB region, valid */
  540. break;
  541. case 1:
  542. mtdcr(DCRN_PEGPL_CFGBAH(PCIE1), high);
  543. mtdcr(DCRN_PEGPL_CFGBAL(PCIE1), low);
  544. mtdcr(DCRN_PEGPL_CFGMSK(PCIE1), 0xe0000001); /* 512MB region, valid */
  545. break;
  546. case 2:
  547. mtdcr(DCRN_PEGPL_CFGBAH(PCIE2), high);
  548. mtdcr(DCRN_PEGPL_CFGBAL(PCIE2), low);
  549. mtdcr(DCRN_PEGPL_CFGMSK(PCIE2), 0xe0000001); /* 512MB region, valid */
  550. break;
  551. }
  552. /*
  553. * Check for VC0 active and assert RDY.
  554. */
  555. attempts = 10;
  556. while(!(SDR_READ(SDRN_PESDR_RCSSTS(port)) & (1 << 16))) {
  557. if (!(attempts--)) {
  558. printf("PCIE%d: VC0 not active\n", port);
  559. return -1;
  560. }
  561. mdelay(1000);
  562. }
  563. SDR_WRITE(SDRN_PESDR_RCSSET(port),
  564. SDR_READ(SDRN_PESDR_RCSSET(port)) | 1 << 20);
  565. mdelay(100);
  566. return 0;
  567. }
  568. int ppc4xx_init_pcie_rootport(int port)
  569. {
  570. return ppc4xx_init_pcie_port(port, 1);
  571. }
  572. int ppc4xx_init_pcie_endport(int port)
  573. {
  574. return ppc4xx_init_pcie_port(port, 0);
  575. }
  576. void ppc4xx_setup_pcie_rootpoint(struct pci_controller *hose, int port)
  577. {
  578. volatile void *mbase = NULL;
  579. volatile void *rmbase = NULL;
  580. pci_set_ops(hose,
  581. pcie_read_config_byte,
  582. pcie_read_config_word,
  583. pcie_read_config_dword,
  584. pcie_write_config_byte,
  585. pcie_write_config_word,
  586. pcie_write_config_dword);
  587. switch (port) {
  588. case 0:
  589. mbase = (u32 *)CFG_PCIE0_XCFGBASE;
  590. rmbase = (u32 *)CFG_PCIE0_CFGBASE;
  591. hose->cfg_data = (u8 *)CFG_PCIE0_CFGBASE;
  592. break;
  593. case 1:
  594. mbase = (u32 *)CFG_PCIE1_XCFGBASE;
  595. rmbase = (u32 *)CFG_PCIE1_CFGBASE;
  596. hose->cfg_data = (u8 *)CFG_PCIE1_CFGBASE;
  597. break;
  598. case 2:
  599. mbase = (u32 *)CFG_PCIE2_XCFGBASE;
  600. rmbase = (u32 *)CFG_PCIE2_CFGBASE;
  601. hose->cfg_data = (u8 *)CFG_PCIE2_CFGBASE;
  602. break;
  603. }
  604. /*
  605. * Set bus numbers on our root port
  606. */
  607. out_8((u8 *)mbase + PCI_PRIMARY_BUS, 0);
  608. out_8((u8 *)mbase + PCI_SECONDARY_BUS, 1);
  609. out_8((u8 *)mbase + PCI_SUBORDINATE_BUS, 1);
  610. /*
  611. * Set up outbound translation to hose->mem_space from PLB
  612. * addresses at an offset of 0xd_0000_0000. We set the low
  613. * bits of the mask to 11 to turn off splitting into 8
  614. * subregions and to enable the outbound translation.
  615. */
  616. out_le32(mbase + PECFG_POM0LAH, 0x00000000);
  617. out_le32(mbase + PECFG_POM0LAL, 0x00000000);
  618. switch (port) {
  619. case 0:
  620. mtdcr(DCRN_PEGPL_OMR1BAH(PCIE0), 0x0000000d);
  621. mtdcr(DCRN_PEGPL_OMR1BAL(PCIE0), CFG_PCIE_MEMBASE +
  622. port * CFG_PCIE_MEMSIZE);
  623. mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE0), 0x7fffffff);
  624. mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE0),
  625. ~(CFG_PCIE_MEMSIZE - 1) | 3);
  626. break;
  627. case 1:
  628. mtdcr(DCRN_PEGPL_OMR1BAH(PCIE1), 0x0000000d);
  629. mtdcr(DCRN_PEGPL_OMR1BAL(PCIE1), CFG_PCIE_MEMBASE +
  630. port * CFG_PCIE_MEMSIZE);
  631. mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE1), 0x7fffffff);
  632. mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE1),
  633. ~(CFG_PCIE_MEMSIZE - 1) | 3);
  634. break;
  635. case 2:
  636. mtdcr(DCRN_PEGPL_OMR1BAH(PCIE2), 0x0000000d);
  637. mtdcr(DCRN_PEGPL_OMR1BAL(PCIE2), CFG_PCIE_MEMBASE +
  638. port * CFG_PCIE_MEMSIZE);
  639. mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE2), 0x7fffffff);
  640. mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE2),
  641. ~(CFG_PCIE_MEMSIZE - 1) | 3);
  642. break;
  643. }
  644. /* Set up 16GB inbound memory window at 0 */
  645. out_le32(mbase + PCI_BASE_ADDRESS_0, 0);
  646. out_le32(mbase + PCI_BASE_ADDRESS_1, 0);
  647. out_le32(mbase + PECFG_BAR0HMPA, 0x7fffffc);
  648. out_le32(mbase + PECFG_BAR0LMPA, 0);
  649. out_le32(mbase + PECFG_PIM01SAH, 0xffff0000);
  650. out_le32(mbase + PECFG_PIM01SAL, 0x00000000);
  651. out_le32(mbase + PECFG_PIM0LAL, 0);
  652. out_le32(mbase + PECFG_PIM0LAH, 0);
  653. out_le32(mbase + PECFG_PIM1LAL, 0x00000000);
  654. out_le32(mbase + PECFG_PIM1LAH, 0x00000004);
  655. out_le32(mbase + PECFG_PIMEN, 0x1);
  656. /* Enable I/O, Mem, and Busmaster cycles */
  657. out_le16((u16 *)(mbase + PCI_COMMAND),
  658. in_le16((u16 *)(mbase + PCI_COMMAND)) |
  659. PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
  660. /* Set Device and Vendor Id */
  661. switch (port) {
  662. case 0:
  663. out_le16(mbase + 0x200, 0xaaa0);
  664. out_le16(mbase + 0x202, 0xbed0);
  665. break;
  666. case 1:
  667. out_le16(mbase + 0x200, 0xaaa1);
  668. out_le16(mbase + 0x202, 0xbed1);
  669. break;
  670. case 2:
  671. out_le16(mbase + 0x200, 0xaaa2);
  672. out_le16(mbase + 0x202, 0xbed2);
  673. break;
  674. default:
  675. out_le16(mbase + 0x200, 0xaaa3);
  676. out_le16(mbase + 0x202, 0xbed3);
  677. }
  678. /* Set Class Code to PCI-PCI bridge and Revision Id to 1 */
  679. out_le32(mbase + 0x208, 0x06040001);
  680. printf("PCIE:%d successfully set as rootpoint\n", port);
  681. }
  682. int ppc4xx_setup_pcie_endpoint(struct pci_controller *hose, int port)
  683. {
  684. volatile void *mbase = NULL;
  685. int attempts = 0;
  686. pci_set_ops(hose,
  687. pcie_read_config_byte,
  688. pcie_read_config_word,
  689. pcie_read_config_dword,
  690. pcie_write_config_byte,
  691. pcie_write_config_word,
  692. pcie_write_config_dword);
  693. switch (port) {
  694. case 0:
  695. mbase = (u32 *)CFG_PCIE0_XCFGBASE;
  696. hose->cfg_data = (u8 *)CFG_PCIE0_CFGBASE;
  697. break;
  698. case 1:
  699. mbase = (u32 *)CFG_PCIE1_XCFGBASE;
  700. hose->cfg_data = (u8 *)CFG_PCIE1_CFGBASE;
  701. break;
  702. case 2:
  703. mbase = (u32 *)CFG_PCIE2_XCFGBASE;
  704. hose->cfg_data = (u8 *)CFG_PCIE2_CFGBASE;
  705. break;
  706. }
  707. /*
  708. * Set up outbound translation to hose->mem_space from PLB
  709. * addresses at an offset of 0xd_0000_0000. We set the low
  710. * bits of the mask to 11 to turn off splitting into 8
  711. * subregions and to enable the outbound translation.
  712. */
  713. out_le32(mbase + PECFG_POM0LAH, 0x00001ff8);
  714. out_le32(mbase + PECFG_POM0LAL, 0x00001000);
  715. switch (port) {
  716. case 0:
  717. mtdcr(DCRN_PEGPL_OMR1BAH(PCIE0), 0x0000000d);
  718. mtdcr(DCRN_PEGPL_OMR1BAL(PCIE0), CFG_PCIE_MEMBASE +
  719. port * CFG_PCIE_MEMSIZE);
  720. mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE0), 0x7fffffff);
  721. mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE0),
  722. ~(CFG_PCIE_MEMSIZE - 1) | 3);
  723. break;
  724. case 1:
  725. mtdcr(DCRN_PEGPL_OMR1BAH(PCIE1), 0x0000000d);
  726. mtdcr(DCRN_PEGPL_OMR1BAL(PCIE1), CFG_PCIE_MEMBASE +
  727. port * CFG_PCIE_MEMSIZE);
  728. mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE1), 0x7fffffff);
  729. mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE1),
  730. ~(CFG_PCIE_MEMSIZE - 1) | 3);
  731. break;
  732. case 2:
  733. mtdcr(DCRN_PEGPL_OMR1BAH(PCIE2), 0x0000000d);
  734. mtdcr(DCRN_PEGPL_OMR1BAL(PCIE2), CFG_PCIE_MEMBASE +
  735. port * CFG_PCIE_MEMSIZE);
  736. mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE2), 0x7fffffff);
  737. mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE2),
  738. ~(CFG_PCIE_MEMSIZE - 1) | 3);
  739. break;
  740. }
  741. /* Set up 16GB inbound memory window at 0 */
  742. out_le32(mbase + PCI_BASE_ADDRESS_0, 0);
  743. out_le32(mbase + PCI_BASE_ADDRESS_1, 0);
  744. out_le32(mbase + PECFG_BAR0HMPA, 0x7fffffc);
  745. out_le32(mbase + PECFG_BAR0LMPA, 0);
  746. out_le32(mbase + PECFG_PIM0LAL, 0x00000000);
  747. out_le32(mbase + PECFG_PIM0LAH, 0x00000004); /* pointing to SRAM */
  748. out_le32(mbase + PECFG_PIMEN, 0x1);
  749. /* Enable I/O, Mem, and Busmaster cycles */
  750. out_le16((u16 *)(mbase + PCI_COMMAND),
  751. in_le16((u16 *)(mbase + PCI_COMMAND)) |
  752. PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
  753. out_le16(mbase + 0x200,0xcaad); /* Setting vendor ID */
  754. out_le16(mbase + 0x202,0xfeed); /* Setting device ID */
  755. attempts = 10;
  756. while(!(SDR_READ(SDRN_PESDR_RCSSTS(port)) & (1 << 8))) {
  757. if (!(attempts--)) {
  758. printf("PCIE%d: BME not active\n", port);
  759. return -1;
  760. }
  761. mdelay(1000);
  762. }
  763. printf("PCIE:%d successfully set as endpoint\n",port);
  764. return 0;
  765. }
  766. #endif /* CONFIG_440SPE && CONFIG_PCI */