4xx_pcie.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173
  1. /*
  2. * (C) Copyright 2006 - 2008
  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. /* define DEBUG for debugging output (obviously ;-)) */
  23. #if 0
  24. #define DEBUG
  25. #endif
  26. #include <asm/processor.h>
  27. #include <asm-ppc/io.h>
  28. #include <ppc4xx.h>
  29. #include <common.h>
  30. #include <pci.h>
  31. #if (defined(CONFIG_440SPE) || defined(CONFIG_405EX) || \
  32. defined(CONFIG_460EX) || defined(CONFIG_460GT)) && \
  33. defined(CONFIG_PCI)
  34. #include <asm/4xx_pcie.h>
  35. enum {
  36. PTYPE_ENDPOINT = 0x0,
  37. PTYPE_LEGACY_ENDPOINT = 0x1,
  38. PTYPE_ROOT_PORT = 0x4,
  39. LNKW_X1 = 0x1,
  40. LNKW_X4 = 0x4,
  41. LNKW_X8 = 0x8
  42. };
  43. static int validate_endpoint(struct pci_controller *hose)
  44. {
  45. if (hose->cfg_data == (u8 *)CFG_PCIE0_CFGBASE)
  46. return (is_end_point(0));
  47. else if (hose->cfg_data == (u8 *)CFG_PCIE1_CFGBASE)
  48. return (is_end_point(1));
  49. #if CFG_PCIE_NR_PORTS > 2
  50. else if (hose->cfg_data == (u8 *)CFG_PCIE2_CFGBASE)
  51. return (is_end_point(2));
  52. #endif
  53. return 0;
  54. }
  55. static u8* pcie_get_base(struct pci_controller *hose, unsigned int devfn)
  56. {
  57. u8 *base = (u8*)hose->cfg_data;
  58. /* use local configuration space for the first bus */
  59. if (PCI_BUS(devfn) == 0) {
  60. if (hose->cfg_data == (u8*)CFG_PCIE0_CFGBASE)
  61. base = (u8*)CFG_PCIE0_XCFGBASE;
  62. if (hose->cfg_data == (u8*)CFG_PCIE1_CFGBASE)
  63. base = (u8*)CFG_PCIE1_XCFGBASE;
  64. #if CFG_PCIE_NR_PORTS > 2
  65. if (hose->cfg_data == (u8*)CFG_PCIE2_CFGBASE)
  66. base = (u8*)CFG_PCIE2_XCFGBASE;
  67. #endif
  68. }
  69. return base;
  70. }
  71. static void pcie_dmer_disable(void)
  72. {
  73. mtdcr (DCRN_PEGPL_CFG(DCRN_PCIE0_BASE),
  74. mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE0_BASE)) | GPL_DMER_MASK_DISA);
  75. mtdcr (DCRN_PEGPL_CFG(DCRN_PCIE1_BASE),
  76. mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE1_BASE)) | GPL_DMER_MASK_DISA);
  77. #if CFG_PCIE_NR_PORTS > 2
  78. mtdcr (DCRN_PEGPL_CFG(DCRN_PCIE2_BASE),
  79. mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE2_BASE)) | GPL_DMER_MASK_DISA);
  80. #endif
  81. }
  82. static void pcie_dmer_enable(void)
  83. {
  84. mtdcr (DCRN_PEGPL_CFG (DCRN_PCIE0_BASE),
  85. mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE0_BASE)) & ~GPL_DMER_MASK_DISA);
  86. mtdcr (DCRN_PEGPL_CFG (DCRN_PCIE1_BASE),
  87. mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE1_BASE)) & ~GPL_DMER_MASK_DISA);
  88. #if CFG_PCIE_NR_PORTS > 2
  89. mtdcr (DCRN_PEGPL_CFG (DCRN_PCIE2_BASE),
  90. mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE2_BASE)) & ~GPL_DMER_MASK_DISA);
  91. #endif
  92. }
  93. static int pcie_read_config(struct pci_controller *hose, unsigned int devfn,
  94. int offset, int len, u32 *val) {
  95. u8 *address;
  96. *val = 0;
  97. if (validate_endpoint(hose))
  98. return 0; /* No upstream config access */
  99. /*
  100. * Bus numbers are relative to hose->first_busno
  101. */
  102. devfn -= PCI_BDF(hose->first_busno, 0, 0);
  103. /*
  104. * NOTICE: configuration space ranges are currenlty mapped only for
  105. * the first 16 buses, so such limit must be imposed. In case more
  106. * buses are required the TLB settings in board/amcc/<board>/init.S
  107. * need to be altered accordingly (one bus takes 1 MB of memory space).
  108. */
  109. if (PCI_BUS(devfn) >= 16)
  110. return 0;
  111. /*
  112. * Only single device/single function is supported for the primary and
  113. * secondary buses of the 440SPe host bridge.
  114. */
  115. if ((!((PCI_FUNC(devfn) == 0) && (PCI_DEV(devfn) == 0))) &&
  116. ((PCI_BUS(devfn) == 0) || (PCI_BUS(devfn) == 1)))
  117. return 0;
  118. address = pcie_get_base(hose, devfn);
  119. offset += devfn << 4;
  120. /*
  121. * Reading from configuration space of non-existing device can
  122. * generate transaction errors. For the read duration we suppress
  123. * assertion of machine check exceptions to avoid those.
  124. */
  125. pcie_dmer_disable ();
  126. debug("%s: cfg_data=%08x offset=%08x\n", __func__, hose->cfg_data, offset);
  127. switch (len) {
  128. case 1:
  129. *val = in_8(hose->cfg_data + offset);
  130. break;
  131. case 2:
  132. *val = in_le16((u16 *)(hose->cfg_data + offset));
  133. break;
  134. default:
  135. *val = in_le32((u32*)(hose->cfg_data + offset));
  136. break;
  137. }
  138. pcie_dmer_enable ();
  139. return 0;
  140. }
  141. static int pcie_write_config(struct pci_controller *hose, unsigned int devfn,
  142. int offset, int len, u32 val) {
  143. u8 *address;
  144. if (validate_endpoint(hose))
  145. return 0; /* No upstream config access */
  146. /*
  147. * Bus numbers are relative to hose->first_busno
  148. */
  149. devfn -= PCI_BDF(hose->first_busno, 0, 0);
  150. /*
  151. * Same constraints as in pcie_read_config().
  152. */
  153. if (PCI_BUS(devfn) >= 16)
  154. return 0;
  155. if ((!((PCI_FUNC(devfn) == 0) && (PCI_DEV(devfn) == 0))) &&
  156. ((PCI_BUS(devfn) == 0) || (PCI_BUS(devfn) == 1)))
  157. return 0;
  158. address = pcie_get_base(hose, devfn);
  159. offset += devfn << 4;
  160. /*
  161. * Suppress MCK exceptions, similar to pcie_read_config()
  162. */
  163. pcie_dmer_disable ();
  164. switch (len) {
  165. case 1:
  166. out_8(hose->cfg_data + offset, val);
  167. break;
  168. case 2:
  169. out_le16((u16 *)(hose->cfg_data + offset), val);
  170. break;
  171. default:
  172. out_le32((u32 *)(hose->cfg_data + offset), val);
  173. break;
  174. }
  175. pcie_dmer_enable ();
  176. return 0;
  177. }
  178. int pcie_read_config_byte(struct pci_controller *hose,pci_dev_t dev,int offset,u8 *val)
  179. {
  180. u32 v;
  181. int rv;
  182. rv = pcie_read_config(hose, dev, offset, 1, &v);
  183. *val = (u8)v;
  184. return rv;
  185. }
  186. int pcie_read_config_word(struct pci_controller *hose,pci_dev_t dev,int offset,u16 *val)
  187. {
  188. u32 v;
  189. int rv;
  190. rv = pcie_read_config(hose, dev, offset, 2, &v);
  191. *val = (u16)v;
  192. return rv;
  193. }
  194. int pcie_read_config_dword(struct pci_controller *hose,pci_dev_t dev,int offset,u32 *val)
  195. {
  196. u32 v;
  197. int rv;
  198. rv = pcie_read_config(hose, dev, offset, 3, &v);
  199. *val = (u32)v;
  200. return rv;
  201. }
  202. int pcie_write_config_byte(struct pci_controller *hose,pci_dev_t dev,int offset,u8 val)
  203. {
  204. return pcie_write_config(hose,(u32)dev,offset,1,val);
  205. }
  206. int pcie_write_config_word(struct pci_controller *hose,pci_dev_t dev,int offset,u16 val)
  207. {
  208. return pcie_write_config(hose,(u32)dev,offset,2,(u32 )val);
  209. }
  210. int pcie_write_config_dword(struct pci_controller *hose,pci_dev_t dev,int offset,u32 val)
  211. {
  212. return pcie_write_config(hose,(u32)dev,offset,3,(u32 )val);
  213. }
  214. #if defined(CONFIG_440SPE)
  215. static void ppc4xx_setup_utl(u32 port) {
  216. volatile void *utl_base = NULL;
  217. /*
  218. * Map UTL registers
  219. */
  220. switch (port) {
  221. case 0:
  222. mtdcr(DCRN_PEGPL_REGBAH(PCIE0), 0x0000000c);
  223. mtdcr(DCRN_PEGPL_REGBAL(PCIE0), 0x20000000);
  224. mtdcr(DCRN_PEGPL_REGMSK(PCIE0), 0x00007001);
  225. mtdcr(DCRN_PEGPL_SPECIAL(PCIE0), 0x68782800);
  226. break;
  227. case 1:
  228. mtdcr(DCRN_PEGPL_REGBAH(PCIE1), 0x0000000c);
  229. mtdcr(DCRN_PEGPL_REGBAL(PCIE1), 0x20001000);
  230. mtdcr(DCRN_PEGPL_REGMSK(PCIE1), 0x00007001);
  231. mtdcr(DCRN_PEGPL_SPECIAL(PCIE1), 0x68782800);
  232. break;
  233. case 2:
  234. mtdcr(DCRN_PEGPL_REGBAH(PCIE2), 0x0000000c);
  235. mtdcr(DCRN_PEGPL_REGBAL(PCIE2), 0x20002000);
  236. mtdcr(DCRN_PEGPL_REGMSK(PCIE2), 0x00007001);
  237. mtdcr(DCRN_PEGPL_SPECIAL(PCIE2), 0x68782800);
  238. break;
  239. }
  240. utl_base = (unsigned int *)(CFG_PCIE_BASE + 0x1000 * port);
  241. /*
  242. * Set buffer allocations and then assert VRB and TXE.
  243. */
  244. out_be32(utl_base + PEUTL_OUTTR, 0x08000000);
  245. out_be32(utl_base + PEUTL_INTR, 0x02000000);
  246. out_be32(utl_base + PEUTL_OPDBSZ, 0x10000000);
  247. out_be32(utl_base + PEUTL_PBBSZ, 0x53000000);
  248. out_be32(utl_base + PEUTL_IPHBSZ, 0x08000000);
  249. out_be32(utl_base + PEUTL_IPDBSZ, 0x10000000);
  250. out_be32(utl_base + PEUTL_RCIRQEN, 0x00f00000);
  251. out_be32(utl_base + PEUTL_PCTL, 0x80800066);
  252. }
  253. static int check_error(void)
  254. {
  255. u32 valPE0, valPE1, valPE2;
  256. int err = 0;
  257. /* SDR0_PEGPLLLCT1 reset */
  258. if (!(valPE0 = SDR_READ(PESDR0_PLLLCT1) & 0x01000000))
  259. printf("PCIE: SDR0_PEGPLLLCT1 reset error 0x%x\n", valPE0);
  260. valPE0 = SDR_READ(PESDR0_RCSSET);
  261. valPE1 = SDR_READ(PESDR1_RCSSET);
  262. valPE2 = SDR_READ(PESDR2_RCSSET);
  263. /* SDR0_PExRCSSET rstgu */
  264. if (!(valPE0 & 0x01000000) ||
  265. !(valPE1 & 0x01000000) ||
  266. !(valPE2 & 0x01000000)) {
  267. printf("PCIE: SDR0_PExRCSSET rstgu error\n");
  268. err = -1;
  269. }
  270. /* SDR0_PExRCSSET rstdl */
  271. if (!(valPE0 & 0x00010000) ||
  272. !(valPE1 & 0x00010000) ||
  273. !(valPE2 & 0x00010000)) {
  274. printf("PCIE: SDR0_PExRCSSET rstdl error\n");
  275. err = -1;
  276. }
  277. /* SDR0_PExRCSSET rstpyn */
  278. if ((valPE0 & 0x00001000) ||
  279. (valPE1 & 0x00001000) ||
  280. (valPE2 & 0x00001000)) {
  281. printf("PCIE: SDR0_PExRCSSET rstpyn error\n");
  282. err = -1;
  283. }
  284. /* SDR0_PExRCSSET hldplb */
  285. if ((valPE0 & 0x10000000) ||
  286. (valPE1 & 0x10000000) ||
  287. (valPE2 & 0x10000000)) {
  288. printf("PCIE: SDR0_PExRCSSET hldplb error\n");
  289. err = -1;
  290. }
  291. /* SDR0_PExRCSSET rdy */
  292. if ((valPE0 & 0x00100000) ||
  293. (valPE1 & 0x00100000) ||
  294. (valPE2 & 0x00100000)) {
  295. printf("PCIE: SDR0_PExRCSSET rdy error\n");
  296. err = -1;
  297. }
  298. /* SDR0_PExRCSSET shutdown */
  299. if ((valPE0 & 0x00000100) ||
  300. (valPE1 & 0x00000100) ||
  301. (valPE2 & 0x00000100)) {
  302. printf("PCIE: SDR0_PExRCSSET shutdown error\n");
  303. err = -1;
  304. }
  305. return err;
  306. }
  307. /*
  308. * Initialize PCI Express core
  309. */
  310. int ppc4xx_init_pcie(void)
  311. {
  312. int time_out = 20;
  313. /* Set PLL clock receiver to LVPECL */
  314. SDR_WRITE(PESDR0_PLLLCT1, SDR_READ(PESDR0_PLLLCT1) | 1 << 28);
  315. if (check_error())
  316. return -1;
  317. if (!(SDR_READ(PESDR0_PLLLCT2) & 0x10000))
  318. {
  319. printf("PCIE: PESDR_PLLCT2 resistance calibration failed (0x%08x)\n",
  320. SDR_READ(PESDR0_PLLLCT2));
  321. return -1;
  322. }
  323. /* De-assert reset of PCIe PLL, wait for lock */
  324. SDR_WRITE(PESDR0_PLLLCT1, SDR_READ(PESDR0_PLLLCT1) & ~(1 << 24));
  325. udelay(3);
  326. while (time_out) {
  327. if (!(SDR_READ(PESDR0_PLLLCT3) & 0x10000000)) {
  328. time_out--;
  329. udelay(1);
  330. } else
  331. break;
  332. }
  333. if (!time_out) {
  334. printf("PCIE: VCO output not locked\n");
  335. return -1;
  336. }
  337. return 0;
  338. }
  339. #endif
  340. #if defined(CONFIG_460EX) || defined(CONFIG_460GT)
  341. static void ppc4xx_setup_utl(u32 port)
  342. {
  343. volatile void *utl_base = NULL;
  344. /*
  345. * Map UTL registers at 0x0801_n000 (4K 0xfff mask) PEGPLn_REGMSK
  346. */
  347. switch (port) {
  348. case 0:
  349. mtdcr(DCRN_PEGPL_REGBAH(PCIE0), U64_TO_U32_HIGH(CFG_PCIE0_UTLBASE));
  350. mtdcr(DCRN_PEGPL_REGBAL(PCIE0), U64_TO_U32_LOW(CFG_PCIE0_UTLBASE));
  351. mtdcr(DCRN_PEGPL_REGMSK(PCIE0), 0x00007001); /* BAM 11100000=4KB */
  352. mtdcr(DCRN_PEGPL_SPECIAL(PCIE0), 0);
  353. break;
  354. case 1:
  355. mtdcr(DCRN_PEGPL_REGBAH(PCIE1), U64_TO_U32_HIGH(CFG_PCIE0_UTLBASE));
  356. mtdcr(DCRN_PEGPL_REGBAL(PCIE1), U64_TO_U32_LOW(CFG_PCIE0_UTLBASE)
  357. + 0x1000);
  358. mtdcr(DCRN_PEGPL_REGMSK(PCIE1), 0x00007001); /* BAM 11100000=4KB */
  359. mtdcr(DCRN_PEGPL_SPECIAL(PCIE1), 0);
  360. break;
  361. }
  362. utl_base = (unsigned int *)(CFG_PCIE_BASE + 0x1000 * port);
  363. /*
  364. * Set buffer allocations and then assert VRB and TXE.
  365. */
  366. out_be32(utl_base + PEUTL_PBCTL, 0x0800000c); /* PLBME, CRRE */
  367. out_be32(utl_base + PEUTL_OUTTR, 0x08000000);
  368. out_be32(utl_base + PEUTL_INTR, 0x02000000);
  369. out_be32(utl_base + PEUTL_OPDBSZ, 0x04000000); /* OPD = 512 Bytes */
  370. out_be32(utl_base + PEUTL_PBBSZ, 0x00000000); /* Max 512 Bytes */
  371. out_be32(utl_base + PEUTL_IPHBSZ, 0x02000000);
  372. out_be32(utl_base + PEUTL_IPDBSZ, 0x04000000); /* IPD = 512 Bytes */
  373. out_be32(utl_base + PEUTL_RCIRQEN, 0x00f00000);
  374. out_be32(utl_base + PEUTL_PCTL, 0x80800066); /* VRB,TXE,timeout=default */
  375. }
  376. /*
  377. * TODO: double check PCI express SDR based on the latest user manual
  378. * Some registers specified here no longer exist.. has to be
  379. * updated based on the final EAS spec.
  380. */
  381. static int check_error(void)
  382. {
  383. u32 valPE0, valPE1;
  384. int err = 0;
  385. valPE0 = SDR_READ(SDRN_PESDR_RCSSET(0));
  386. valPE1 = SDR_READ(SDRN_PESDR_RCSSET(1));
  387. /* SDR0_PExRCSSET rstgu */
  388. if (!(valPE0 & PESDRx_RCSSET_RSTGU) || !(valPE1 & PESDRx_RCSSET_RSTGU)) {
  389. printf("PCIE: SDR0_PExRCSSET rstgu error\n");
  390. err = -1;
  391. }
  392. /* SDR0_PExRCSSET rstdl */
  393. if (!(valPE0 & PESDRx_RCSSET_RSTDL) || !(valPE1 & PESDRx_RCSSET_RSTDL)) {
  394. printf("PCIE: SDR0_PExRCSSET rstdl error\n");
  395. err = -1;
  396. }
  397. /* SDR0_PExRCSSET rstpyn */
  398. if ((valPE0 & PESDRx_RCSSET_RSTPYN) || (valPE1 & PESDRx_RCSSET_RSTPYN)) {
  399. printf("PCIE: SDR0_PExRCSSET rstpyn error\n");
  400. err = -1;
  401. }
  402. /* SDR0_PExRCSSET hldplb */
  403. if ((valPE0 & PESDRx_RCSSET_HLDPLB) || (valPE1 & PESDRx_RCSSET_HLDPLB)) {
  404. printf("PCIE: SDR0_PExRCSSET hldplb error\n");
  405. err = -1;
  406. }
  407. /* SDR0_PExRCSSET rdy */
  408. if ((valPE0 & PESDRx_RCSSET_RDY) || (valPE1 & PESDRx_RCSSET_RDY)) {
  409. printf("PCIE: SDR0_PExRCSSET rdy error\n");
  410. err = -1;
  411. }
  412. return err;
  413. }
  414. /*
  415. * Initialize PCI Express core as described in User Manual
  416. * TODO: double check PE SDR PLL Register with the updated user manual.
  417. */
  418. int ppc4xx_init_pcie(void)
  419. {
  420. if (check_error())
  421. return -1;
  422. return 0;
  423. }
  424. #endif /* CONFIG_460EX */
  425. #if defined(CONFIG_405EX)
  426. static void ppc4xx_setup_utl(u32 port)
  427. {
  428. u32 utl_base;
  429. /*
  430. * Map UTL registers at 0xef4f_n000 (4K 0xfff mask) PEGPLn_REGMSK
  431. */
  432. switch (port) {
  433. case 0:
  434. mtdcr(DCRN_PEGPL_REGBAH(PCIE0), 0x00000000);
  435. mtdcr(DCRN_PEGPL_REGBAL(PCIE0), CFG_PCIE0_UTLBASE);
  436. mtdcr(DCRN_PEGPL_REGMSK(PCIE0), 0x00007001); /* 4k region, valid */
  437. mtdcr(DCRN_PEGPL_SPECIAL(PCIE0), 0);
  438. break;
  439. case 1:
  440. mtdcr(DCRN_PEGPL_REGBAH(PCIE1), 0x00000000);
  441. mtdcr(DCRN_PEGPL_REGBAL(PCIE1), CFG_PCIE1_UTLBASE);
  442. mtdcr(DCRN_PEGPL_REGMSK(PCIE1), 0x00007001); /* 4k region, valid */
  443. mtdcr(DCRN_PEGPL_SPECIAL(PCIE1), 0);
  444. break;
  445. }
  446. utl_base = (port==0) ? CFG_PCIE0_UTLBASE : CFG_PCIE1_UTLBASE;
  447. /*
  448. * Set buffer allocations and then assert VRB and TXE.
  449. */
  450. out_be32((u32 *)(utl_base + PEUTL_OUTTR), 0x02000000);
  451. out_be32((u32 *)(utl_base + PEUTL_INTR), 0x02000000);
  452. out_be32((u32 *)(utl_base + PEUTL_OPDBSZ), 0x04000000);
  453. out_be32((u32 *)(utl_base + PEUTL_PBBSZ), 0x21000000);
  454. out_be32((u32 *)(utl_base + PEUTL_IPHBSZ), 0x02000000);
  455. out_be32((u32 *)(utl_base + PEUTL_IPDBSZ), 0x04000000);
  456. out_be32((u32 *)(utl_base + PEUTL_RCIRQEN), 0x00f00000);
  457. out_be32((u32 *)(utl_base + PEUTL_PCTL), 0x80800066);
  458. out_be32((u32 *)(utl_base + PEUTL_PBCTL), 0x0800000c);
  459. out_be32((u32 *)(utl_base + PEUTL_RCSTA),
  460. in_be32((u32 *)(utl_base + PEUTL_RCSTA)) | 0x000040000);
  461. }
  462. int ppc4xx_init_pcie(void)
  463. {
  464. /*
  465. * Nothing to do on 405EX
  466. */
  467. return 0;
  468. }
  469. #endif /* CONFIG_405EX */
  470. /*
  471. * Board-specific pcie initialization
  472. * Platform code can reimplement ppc4xx_init_pcie_port_hw() if needed
  473. */
  474. /*
  475. * Initialize various parts of the PCI Express core for our port:
  476. *
  477. * - Set as a root port and enable max width
  478. * (PXIE0 -> X8, PCIE1 and PCIE2 -> X4).
  479. * - Set up UTL configuration.
  480. * - Increase SERDES drive strength to levels suggested by AMCC.
  481. * - De-assert RSTPYN, RSTDL and RSTGU.
  482. *
  483. * NOTICE for 440SPE revB chip: PESDRn_UTLSET2 is not set - we leave it
  484. * with default setting 0x11310000. The register has new fields,
  485. * PESDRn_UTLSET2[LKINE] in particular: clearing it leads to PCIE core
  486. * hang.
  487. */
  488. #if defined(CONFIG_440SPE)
  489. int __ppc4xx_init_pcie_port_hw(int port, int rootport)
  490. {
  491. u32 val = 1 << 24;
  492. u32 utlset1;
  493. if (rootport) {
  494. val = PTYPE_ROOT_PORT << 20;
  495. utlset1 = 0x21222222;
  496. } else {
  497. val = PTYPE_LEGACY_ENDPOINT << 20;
  498. utlset1 = 0x20222222;
  499. }
  500. if (port == 0)
  501. val |= LNKW_X8 << 12;
  502. else
  503. val |= LNKW_X4 << 12;
  504. SDR_WRITE(SDRN_PESDR_DLPSET(port), val);
  505. SDR_WRITE(SDRN_PESDR_UTLSET1(port), utlset1);
  506. if (!ppc440spe_revB())
  507. SDR_WRITE(SDRN_PESDR_UTLSET2(port), 0x11000000);
  508. SDR_WRITE(SDRN_PESDR_HSSL0SET1(port), 0x35000000);
  509. SDR_WRITE(SDRN_PESDR_HSSL1SET1(port), 0x35000000);
  510. SDR_WRITE(SDRN_PESDR_HSSL2SET1(port), 0x35000000);
  511. SDR_WRITE(SDRN_PESDR_HSSL3SET1(port), 0x35000000);
  512. if (port == 0) {
  513. SDR_WRITE(PESDR0_HSSL4SET1, 0x35000000);
  514. SDR_WRITE(PESDR0_HSSL5SET1, 0x35000000);
  515. SDR_WRITE(PESDR0_HSSL6SET1, 0x35000000);
  516. SDR_WRITE(PESDR0_HSSL7SET1, 0x35000000);
  517. }
  518. SDR_WRITE(SDRN_PESDR_RCSSET(port), (SDR_READ(SDRN_PESDR_RCSSET(port)) &
  519. ~(1 << 24 | 1 << 16)) | 1 << 12);
  520. return 0;
  521. }
  522. #endif /* CONFIG_440SPE */
  523. #if defined(CONFIG_460EX) || defined(CONFIG_460GT)
  524. int __ppc4xx_init_pcie_port_hw(int port, int rootport)
  525. {
  526. u32 val = 1 << 24;
  527. u32 utlset1;
  528. if (rootport) {
  529. val = PTYPE_ROOT_PORT << 20;
  530. utlset1 = 0x21222222;
  531. } else {
  532. val = PTYPE_LEGACY_ENDPOINT << 20;
  533. utlset1 = 0x20222222;
  534. }
  535. if (port == 0) {
  536. val |= LNKW_X1 << 12;
  537. } else {
  538. val |= LNKW_X4 << 12;
  539. utlset1 |= 0x00101101;
  540. }
  541. SDR_WRITE(SDRN_PESDR_DLPSET(port), val);
  542. SDR_WRITE(SDRN_PESDR_UTLSET1(port), utlset1);
  543. SDR_WRITE(SDRN_PESDR_UTLSET2(port), 0x01210000);
  544. switch (port) {
  545. case 0:
  546. SDR_WRITE(PESDR0_L0CDRCTL, 0x00003230);
  547. SDR_WRITE(PESDR0_L0DRV, 0x00000136);
  548. SDR_WRITE(PESDR0_L0CLK, 0x00000006);
  549. SDR_WRITE(PESDR0_PHY_CTL_RST,0x10000000);
  550. break;
  551. case 1:
  552. SDR_WRITE(PESDR1_L0CDRCTL, 0x00003230);
  553. SDR_WRITE(PESDR1_L1CDRCTL, 0x00003230);
  554. SDR_WRITE(PESDR1_L2CDRCTL, 0x00003230);
  555. SDR_WRITE(PESDR1_L3CDRCTL, 0x00003230);
  556. SDR_WRITE(PESDR1_L0DRV, 0x00000136);
  557. SDR_WRITE(PESDR1_L1DRV, 0x00000136);
  558. SDR_WRITE(PESDR1_L2DRV, 0x00000136);
  559. SDR_WRITE(PESDR1_L3DRV, 0x00000136);
  560. SDR_WRITE(PESDR1_L0CLK, 0x00000006);
  561. SDR_WRITE(PESDR1_L1CLK, 0x00000006);
  562. SDR_WRITE(PESDR1_L2CLK, 0x00000006);
  563. SDR_WRITE(PESDR1_L3CLK, 0x00000006);
  564. SDR_WRITE(PESDR1_PHY_CTL_RST,0x10000000);
  565. break;
  566. }
  567. SDR_WRITE(SDRN_PESDR_RCSSET(port), SDR_READ(SDRN_PESDR_RCSSET(port)) |
  568. (PESDRx_RCSSET_RSTGU | PESDRx_RCSSET_RSTPYN));
  569. /* Poll for PHY reset */
  570. switch (port) {
  571. case 0:
  572. while (!(SDR_READ(PESDR0_RSTSTA) & 0x1))
  573. udelay(10);
  574. break;
  575. case 1:
  576. while (!(SDR_READ(PESDR1_RSTSTA) & 0x1))
  577. udelay(10);
  578. break;
  579. }
  580. SDR_WRITE(SDRN_PESDR_RCSSET(port),
  581. (SDR_READ(SDRN_PESDR_RCSSET(port)) &
  582. ~(PESDRx_RCSSET_RSTGU | PESDRx_RCSSET_RSTDL)) |
  583. PESDRx_RCSSET_RSTPYN);
  584. return 0;
  585. }
  586. #endif /* CONFIG_440SPE */
  587. #if defined(CONFIG_405EX)
  588. int __ppc4xx_init_pcie_port_hw(int port, int rootport)
  589. {
  590. u32 val;
  591. if (rootport)
  592. val = 0x00401000;
  593. else
  594. val = 0x00101000;
  595. SDR_WRITE(SDRN_PESDR_DLPSET(port), val);
  596. SDR_WRITE(SDRN_PESDR_UTLSET1(port), 0x00000000);
  597. SDR_WRITE(SDRN_PESDR_UTLSET2(port), 0x01010000);
  598. SDR_WRITE(SDRN_PESDR_PHYSET1(port), 0x720F0000);
  599. SDR_WRITE(SDRN_PESDR_PHYSET2(port), 0x70600003);
  600. /* Assert the PE0_PHY reset */
  601. SDR_WRITE(SDRN_PESDR_RCSSET(port), 0x01010000);
  602. udelay(1000);
  603. /* deassert the PE0_hotreset */
  604. if (is_end_point(port))
  605. SDR_WRITE(SDRN_PESDR_RCSSET(port), 0x01111000);
  606. else
  607. SDR_WRITE(SDRN_PESDR_RCSSET(port), 0x01101000);
  608. /* poll for phy !reset */
  609. while (!(SDR_READ(SDRN_PESDR_PHYSTA(port)) & 0x00001000))
  610. ;
  611. /* deassert the PE0_gpl_utl_reset */
  612. SDR_WRITE(SDRN_PESDR_RCSSET(port), 0x00101000);
  613. if (port == 0)
  614. mtdcr(DCRN_PEGPL_CFG(PCIE0), 0x10000000); /* guarded on */
  615. else
  616. mtdcr(DCRN_PEGPL_CFG(PCIE1), 0x10000000); /* guarded on */
  617. return 0;
  618. }
  619. #endif /* CONFIG_405EX */
  620. int ppc4xx_init_pcie_port_hw(int port, int rootport)
  621. __attribute__((weak, alias("__ppc4xx_init_pcie_port_hw")));
  622. /*
  623. * We map PCI Express configuration access into the 512MB regions
  624. *
  625. * NOTICE: revB is very strict about PLB real addressess and ranges to
  626. * be mapped for config space; it seems to only work with d_nnnn_nnnn
  627. * range (hangs the core upon config transaction attempts when set
  628. * otherwise) while revA uses c_nnnn_nnnn.
  629. *
  630. * For 440SPe revA:
  631. * PCIE0: 0xc_4000_0000
  632. * PCIE1: 0xc_8000_0000
  633. * PCIE2: 0xc_c000_0000
  634. *
  635. * For 440SPe revB:
  636. * PCIE0: 0xd_0000_0000
  637. * PCIE1: 0xd_2000_0000
  638. * PCIE2: 0xd_4000_0000
  639. *
  640. * For 405EX:
  641. * PCIE0: 0xa000_0000
  642. * PCIE1: 0xc000_0000
  643. *
  644. * For 460EX/GT:
  645. * PCIE0: 0xd_0000_0000
  646. * PCIE1: 0xd_2000_0000
  647. */
  648. static inline u64 ppc4xx_get_cfgaddr(int port)
  649. {
  650. #if defined(CONFIG_405EX)
  651. if (port == 0)
  652. return (u64)CFG_PCIE0_CFGBASE;
  653. else
  654. return (u64)CFG_PCIE1_CFGBASE;
  655. #endif
  656. #if defined(CONFIG_440SPE)
  657. if (ppc440spe_revB()) {
  658. switch (port) {
  659. default: /* to satisfy compiler */
  660. case 0:
  661. return 0x0000000d00000000ULL;
  662. case 1:
  663. return 0x0000000d20000000ULL;
  664. case 2:
  665. return 0x0000000d40000000ULL;
  666. }
  667. } else {
  668. switch (port) {
  669. default: /* to satisfy compiler */
  670. case 0:
  671. return 0x0000000c40000000ULL;
  672. case 1:
  673. return 0x0000000c80000000ULL;
  674. case 2:
  675. return 0x0000000cc0000000ULL;
  676. }
  677. }
  678. #endif
  679. #if defined(CONFIG_460EX) || defined(CONFIG_460GT)
  680. if (port == 0)
  681. return 0x0000000d00000000ULL;
  682. else
  683. return 0x0000000d20000000ULL;
  684. #endif
  685. }
  686. /*
  687. * 4xx boards as end point and root point setup
  688. * and
  689. * testing inbound and out bound windows
  690. *
  691. * 4xx boards can be plugged into another 4xx boards or you can get PCI-E
  692. * cable which can be used to setup loop back from one port to another port.
  693. * Please rememeber that unless there is a endpoint plugged in to root port it
  694. * will not initialize. It is the same in case of endpoint , unless there is
  695. * root port attached it will not initialize.
  696. *
  697. * In this release of software all the PCI-E ports are configured as either
  698. * endpoint or rootpoint.In future we will have support for selective ports
  699. * setup as endpoint and root point in single board.
  700. *
  701. * Once your board came up as root point , you can verify by reading
  702. * /proc/bus/pci/devices. Where you can see the configuration registers
  703. * of end point device attached to the port.
  704. *
  705. * Enpoint cofiguration can be verified by connecting 4xx board to any
  706. * host or another 4xx board. Then try to scan the device. In case of
  707. * linux use "lspci" or appripriate os command.
  708. *
  709. * How do I verify the inbound and out bound windows ? (4xx to 4xx)
  710. * in this configuration inbound and outbound windows are setup to access
  711. * sram memroy area. SRAM is at 0x4 0000 0000 , on PLB bus. This address
  712. * is mapped at 0x90000000. From u-boot prompt write data 0xb000 0000,
  713. * This is waere your POM(PLB out bound memory window) mapped. then
  714. * read the data from other 4xx board's u-boot prompt at address
  715. * 0x9000 0000(SRAM). Data should match.
  716. * In case of inbound , write data to u-boot command prompt at 0xb000 0000
  717. * which is mapped to 0x4 0000 0000. Now on rootpoint yucca u-boot prompt check
  718. * data at 0x9000 0000(SRAM).Data should match.
  719. */
  720. int ppc4xx_init_pcie_port(int port, int rootport)
  721. {
  722. static int core_init;
  723. volatile u32 val = 0;
  724. int attempts;
  725. u64 addr;
  726. u32 low, high;
  727. if (!core_init) {
  728. if (ppc4xx_init_pcie())
  729. return -1;
  730. ++core_init;
  731. }
  732. /*
  733. * Initialize various parts of the PCI Express core for our port
  734. */
  735. ppc4xx_init_pcie_port_hw(port, rootport);
  736. /*
  737. * Notice: the following delay has critical impact on device
  738. * initialization - if too short (<50ms) the link doesn't get up.
  739. */
  740. mdelay(100);
  741. val = SDR_READ(SDRN_PESDR_RCSSTS(port));
  742. if (val & (1 << 20)) {
  743. printf("PCIE%d: PGRST failed %08x\n", port, val);
  744. return -1;
  745. }
  746. /*
  747. * Verify link is up
  748. */
  749. val = SDR_READ(SDRN_PESDR_LOOP(port));
  750. if (!(val & 0x00001000)) {
  751. printf("PCIE%d: link is not up.\n", port);
  752. return -1;
  753. }
  754. /*
  755. * Setup UTL registers - but only on revA!
  756. * We use default settings for revB chip.
  757. */
  758. if (!ppc440spe_revB())
  759. ppc4xx_setup_utl(port);
  760. /*
  761. * We map PCI Express configuration access into the 512MB regions
  762. */
  763. addr = ppc4xx_get_cfgaddr(port);
  764. low = U64_TO_U32_LOW(addr);
  765. high = U64_TO_U32_HIGH(addr);
  766. switch (port) {
  767. case 0:
  768. mtdcr(DCRN_PEGPL_CFGBAH(PCIE0), high);
  769. mtdcr(DCRN_PEGPL_CFGBAL(PCIE0), low);
  770. mtdcr(DCRN_PEGPL_CFGMSK(PCIE0), 0xe0000001); /* 512MB region, valid */
  771. break;
  772. case 1:
  773. mtdcr(DCRN_PEGPL_CFGBAH(PCIE1), high);
  774. mtdcr(DCRN_PEGPL_CFGBAL(PCIE1), low);
  775. mtdcr(DCRN_PEGPL_CFGMSK(PCIE1), 0xe0000001); /* 512MB region, valid */
  776. break;
  777. #if CFG_PCIE_NR_PORTS > 2
  778. case 2:
  779. mtdcr(DCRN_PEGPL_CFGBAH(PCIE2), high);
  780. mtdcr(DCRN_PEGPL_CFGBAL(PCIE2), low);
  781. mtdcr(DCRN_PEGPL_CFGMSK(PCIE2), 0xe0000001); /* 512MB region, valid */
  782. break;
  783. #endif
  784. }
  785. /*
  786. * Check for VC0 active and assert RDY.
  787. */
  788. attempts = 10;
  789. while(!(SDR_READ(SDRN_PESDR_RCSSTS(port)) & (1 << 16))) {
  790. if (!(attempts--)) {
  791. printf("PCIE%d: VC0 not active\n", port);
  792. return -1;
  793. }
  794. mdelay(1000);
  795. }
  796. SDR_WRITE(SDRN_PESDR_RCSSET(port),
  797. SDR_READ(SDRN_PESDR_RCSSET(port)) | 1 << 20);
  798. mdelay(100);
  799. return 0;
  800. }
  801. int ppc4xx_init_pcie_rootport(int port)
  802. {
  803. return ppc4xx_init_pcie_port(port, 1);
  804. }
  805. int ppc4xx_init_pcie_endport(int port)
  806. {
  807. return ppc4xx_init_pcie_port(port, 0);
  808. }
  809. void ppc4xx_setup_pcie_rootpoint(struct pci_controller *hose, int port)
  810. {
  811. volatile void *mbase = NULL;
  812. volatile void *rmbase = NULL;
  813. pci_set_ops(hose,
  814. pcie_read_config_byte,
  815. pcie_read_config_word,
  816. pcie_read_config_dword,
  817. pcie_write_config_byte,
  818. pcie_write_config_word,
  819. pcie_write_config_dword);
  820. switch (port) {
  821. case 0:
  822. mbase = (u32 *)CFG_PCIE0_XCFGBASE;
  823. rmbase = (u32 *)CFG_PCIE0_CFGBASE;
  824. hose->cfg_data = (u8 *)CFG_PCIE0_CFGBASE;
  825. break;
  826. case 1:
  827. mbase = (u32 *)CFG_PCIE1_XCFGBASE;
  828. rmbase = (u32 *)CFG_PCIE1_CFGBASE;
  829. hose->cfg_data = (u8 *)CFG_PCIE1_CFGBASE;
  830. break;
  831. #if CFG_PCIE_NR_PORTS > 2
  832. case 2:
  833. mbase = (u32 *)CFG_PCIE2_XCFGBASE;
  834. rmbase = (u32 *)CFG_PCIE2_CFGBASE;
  835. hose->cfg_data = (u8 *)CFG_PCIE2_CFGBASE;
  836. break;
  837. #endif
  838. }
  839. /*
  840. * Set bus numbers on our root port
  841. */
  842. out_8((u8 *)mbase + PCI_PRIMARY_BUS, 0);
  843. out_8((u8 *)mbase + PCI_SECONDARY_BUS, 1);
  844. out_8((u8 *)mbase + PCI_SUBORDINATE_BUS, 1);
  845. /*
  846. * Set up outbound translation to hose->mem_space from PLB
  847. * addresses at an offset of 0xd_0000_0000. We set the low
  848. * bits of the mask to 11 to turn off splitting into 8
  849. * subregions and to enable the outbound translation.
  850. */
  851. out_le32(mbase + PECFG_POM0LAH, 0x00000000);
  852. out_le32(mbase + PECFG_POM0LAL, CFG_PCIE_MEMBASE +
  853. port * CFG_PCIE_MEMSIZE);
  854. debug("PECFG_POM0LA=%08x.%08x\n", in_le32(mbase + PECFG_POM0LAH),
  855. in_le32(mbase + PECFG_POM0LAL));
  856. switch (port) {
  857. case 0:
  858. mtdcr(DCRN_PEGPL_OMR1BAH(PCIE0), CFG_PCIE_ADDR_HIGH);
  859. mtdcr(DCRN_PEGPL_OMR1BAL(PCIE0), CFG_PCIE_MEMBASE +
  860. port * CFG_PCIE_MEMSIZE);
  861. mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE0), 0x7fffffff);
  862. mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE0),
  863. ~(CFG_PCIE_MEMSIZE - 1) | 3);
  864. debug("0:PEGPL_OMR1BA=%08x.%08x MSK=%08x.%08x\n",
  865. mfdcr(DCRN_PEGPL_OMR1BAH(PCIE0)),
  866. mfdcr(DCRN_PEGPL_OMR1BAL(PCIE0)),
  867. mfdcr(DCRN_PEGPL_OMR1MSKH(PCIE0)),
  868. mfdcr(DCRN_PEGPL_OMR1MSKL(PCIE0)));
  869. break;
  870. case 1:
  871. mtdcr(DCRN_PEGPL_OMR1BAH(PCIE1), CFG_PCIE_ADDR_HIGH);
  872. mtdcr(DCRN_PEGPL_OMR1BAL(PCIE1), CFG_PCIE_MEMBASE +
  873. port * CFG_PCIE_MEMSIZE);
  874. mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE1), 0x7fffffff);
  875. mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE1),
  876. ~(CFG_PCIE_MEMSIZE - 1) | 3);
  877. debug("1:PEGPL_OMR1BA=%08x.%08x MSK=%08x.%08x\n",
  878. mfdcr(DCRN_PEGPL_OMR1BAH(PCIE1)),
  879. mfdcr(DCRN_PEGPL_OMR1BAL(PCIE1)),
  880. mfdcr(DCRN_PEGPL_OMR1MSKH(PCIE1)),
  881. mfdcr(DCRN_PEGPL_OMR1MSKL(PCIE1)));
  882. break;
  883. #if CFG_PCIE_NR_PORTS > 2
  884. case 2:
  885. mtdcr(DCRN_PEGPL_OMR1BAH(PCIE2), CFG_PCIE_ADDR_HIGH);
  886. mtdcr(DCRN_PEGPL_OMR1BAL(PCIE2), CFG_PCIE_MEMBASE +
  887. port * CFG_PCIE_MEMSIZE);
  888. mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE2), 0x7fffffff);
  889. mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE2),
  890. ~(CFG_PCIE_MEMSIZE - 1) | 3);
  891. debug("2:PEGPL_OMR1BA=%08x.%08x MSK=%08x.%08x\n",
  892. mfdcr(DCRN_PEGPL_OMR1BAH(PCIE2)),
  893. mfdcr(DCRN_PEGPL_OMR1BAL(PCIE2)),
  894. mfdcr(DCRN_PEGPL_OMR1MSKH(PCIE2)),
  895. mfdcr(DCRN_PEGPL_OMR1MSKL(PCIE2)));
  896. break;
  897. #endif
  898. }
  899. /* Set up 16GB inbound memory window at 0 */
  900. out_le32(mbase + PCI_BASE_ADDRESS_0, 0);
  901. out_le32(mbase + PCI_BASE_ADDRESS_1, 0);
  902. out_le32(mbase + PECFG_BAR0HMPA, 0x7fffffc);
  903. out_le32(mbase + PECFG_BAR0LMPA, 0);
  904. out_le32(mbase + PECFG_PIM01SAH, 0xffff0000);
  905. out_le32(mbase + PECFG_PIM01SAL, 0x00000000);
  906. out_le32(mbase + PECFG_PIM0LAL, 0);
  907. out_le32(mbase + PECFG_PIM0LAH, 0);
  908. out_le32(mbase + PECFG_PIM1LAL, 0x00000000);
  909. out_le32(mbase + PECFG_PIM1LAH, 0x00000004);
  910. out_le32(mbase + PECFG_PIMEN, 0x1);
  911. /* Enable I/O, Mem, and Busmaster cycles */
  912. out_le16((u16 *)(mbase + PCI_COMMAND),
  913. in_le16((u16 *)(mbase + PCI_COMMAND)) |
  914. PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
  915. /* Set Device and Vendor Id */
  916. out_le16(mbase + 0x200, 0xaaa0 + port);
  917. out_le16(mbase + 0x202, 0xbed0 + port);
  918. /* Set Class Code to PCI-PCI bridge and Revision Id to 1 */
  919. out_le32(mbase + 0x208, 0x06040001);
  920. printf("PCIE%d: successfully set as root-complex\n", port);
  921. }
  922. int ppc4xx_setup_pcie_endpoint(struct pci_controller *hose, int port)
  923. {
  924. volatile void *mbase = NULL;
  925. int attempts = 0;
  926. pci_set_ops(hose,
  927. pcie_read_config_byte,
  928. pcie_read_config_word,
  929. pcie_read_config_dword,
  930. pcie_write_config_byte,
  931. pcie_write_config_word,
  932. pcie_write_config_dword);
  933. switch (port) {
  934. case 0:
  935. mbase = (u32 *)CFG_PCIE0_XCFGBASE;
  936. hose->cfg_data = (u8 *)CFG_PCIE0_CFGBASE;
  937. break;
  938. case 1:
  939. mbase = (u32 *)CFG_PCIE1_XCFGBASE;
  940. hose->cfg_data = (u8 *)CFG_PCIE1_CFGBASE;
  941. break;
  942. #if defined(CFG_PCIE2_CFGBASE)
  943. case 2:
  944. mbase = (u32 *)CFG_PCIE2_XCFGBASE;
  945. hose->cfg_data = (u8 *)CFG_PCIE2_CFGBASE;
  946. break;
  947. #endif
  948. }
  949. /*
  950. * Set up outbound translation to hose->mem_space from PLB
  951. * addresses at an offset of 0xd_0000_0000. We set the low
  952. * bits of the mask to 11 to turn off splitting into 8
  953. * subregions and to enable the outbound translation.
  954. */
  955. out_le32(mbase + PECFG_POM0LAH, 0x00001ff8);
  956. out_le32(mbase + PECFG_POM0LAL, 0x00001000);
  957. switch (port) {
  958. case 0:
  959. mtdcr(DCRN_PEGPL_OMR1BAH(PCIE0), CFG_PCIE_ADDR_HIGH);
  960. mtdcr(DCRN_PEGPL_OMR1BAL(PCIE0), CFG_PCIE_MEMBASE +
  961. port * CFG_PCIE_MEMSIZE);
  962. mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE0), 0x7fffffff);
  963. mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE0),
  964. ~(CFG_PCIE_MEMSIZE - 1) | 3);
  965. break;
  966. case 1:
  967. mtdcr(DCRN_PEGPL_OMR1BAH(PCIE1), CFG_PCIE_ADDR_HIGH);
  968. mtdcr(DCRN_PEGPL_OMR1BAL(PCIE1), CFG_PCIE_MEMBASE +
  969. port * CFG_PCIE_MEMSIZE);
  970. mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE1), 0x7fffffff);
  971. mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE1),
  972. ~(CFG_PCIE_MEMSIZE - 1) | 3);
  973. break;
  974. #if CFG_PCIE_NR_PORTS > 2
  975. case 2:
  976. mtdcr(DCRN_PEGPL_OMR1BAH(PCIE2), CFG_PCIE_ADDR_HIGH);
  977. mtdcr(DCRN_PEGPL_OMR1BAL(PCIE2), CFG_PCIE_MEMBASE +
  978. port * CFG_PCIE_MEMSIZE);
  979. mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE2), 0x7fffffff);
  980. mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE2),
  981. ~(CFG_PCIE_MEMSIZE - 1) | 3);
  982. break;
  983. #endif
  984. }
  985. /* Set up 64MB inbound memory window at 0 */
  986. out_le32(mbase + PCI_BASE_ADDRESS_0, 0);
  987. out_le32(mbase + PCI_BASE_ADDRESS_1, 0);
  988. out_le32(mbase + PECFG_PIM01SAH, 0xffffffff);
  989. out_le32(mbase + PECFG_PIM01SAL, 0xfc000000);
  990. /* Setup BAR0 */
  991. out_le32(mbase + PECFG_BAR0HMPA, 0x7fffffff);
  992. out_le32(mbase + PECFG_BAR0LMPA, 0xfc000000 | PCI_BASE_ADDRESS_MEM_TYPE_64);
  993. /* Disable BAR1 & BAR2 */
  994. out_le32(mbase + PECFG_BAR1MPA, 0);
  995. out_le32(mbase + PECFG_BAR2HMPA, 0);
  996. out_le32(mbase + PECFG_BAR2LMPA, 0);
  997. out_le32(mbase + PECFG_PIM0LAL, U64_TO_U32_LOW(CFG_PCIE_INBOUND_BASE));
  998. out_le32(mbase + PECFG_PIM0LAH, U64_TO_U32_HIGH(CFG_PCIE_INBOUND_BASE));
  999. out_le32(mbase + PECFG_PIMEN, 0x1);
  1000. /* Enable I/O, Mem, and Busmaster cycles */
  1001. out_le16((u16 *)(mbase + PCI_COMMAND),
  1002. in_le16((u16 *)(mbase + PCI_COMMAND)) |
  1003. PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
  1004. out_le16(mbase + 0x200, 0xcaad); /* Setting vendor ID */
  1005. out_le16(mbase + 0x202, 0xfeed); /* Setting device ID */
  1006. /* Set Class Code to Processor/PPC */
  1007. out_le32(mbase + 0x208, 0x0b200001);
  1008. attempts = 10;
  1009. while(!(SDR_READ(SDRN_PESDR_RCSSTS(port)) & (1 << 8))) {
  1010. if (!(attempts--)) {
  1011. printf("PCIE%d: BME not active\n", port);
  1012. return -1;
  1013. }
  1014. mdelay(1000);
  1015. }
  1016. printf("PCIE%d: successfully set as endpoint\n", port);
  1017. return 0;
  1018. }
  1019. #endif /* CONFIG_440SPE && CONFIG_PCI */