fsl_pci_init.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  1. /*
  2. * Copyright 2007-2010 Freescale Semiconductor, Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License as published by the Free
  6. * Software Foundation; either version 2 of the License, or (at your option)
  7. * any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  17. * MA 02111-1307 USA
  18. */
  19. #include <common.h>
  20. #include <malloc.h>
  21. #include <asm/fsl_serdes.h>
  22. DECLARE_GLOBAL_DATA_PTR;
  23. /*
  24. * PCI/PCIE Controller initialization for mpc85xx/mpc86xx soc's
  25. *
  26. * Initialize controller and call the common driver/pci pci_hose_scan to
  27. * scan for bridges and devices.
  28. *
  29. * Hose fields which need to be pre-initialized by board specific code:
  30. * regions[]
  31. * first_busno
  32. *
  33. * Fields updated:
  34. * last_busno
  35. */
  36. #include <pci.h>
  37. #include <asm/io.h>
  38. #include <asm/fsl_pci.h>
  39. /* Freescale-specific PCI config registers */
  40. #define FSL_PCI_PBFR 0x44
  41. #define FSL_PCIE_CAP_ID 0x4c
  42. #define FSL_PCIE_CFG_RDY 0x4b0
  43. #define FSL_PROG_IF_AGENT 0x1
  44. void pciauto_prescan_setup_bridge(struct pci_controller *hose,
  45. pci_dev_t dev, int sub_bus);
  46. void pciauto_postscan_setup_bridge(struct pci_controller *hose,
  47. pci_dev_t dev, int sub_bus);
  48. void pciauto_config_init(struct pci_controller *hose);
  49. #ifndef CONFIG_SYS_PCI_MEMORY_BUS
  50. #define CONFIG_SYS_PCI_MEMORY_BUS 0
  51. #endif
  52. #ifndef CONFIG_SYS_PCI_MEMORY_PHYS
  53. #define CONFIG_SYS_PCI_MEMORY_PHYS 0
  54. #endif
  55. #if defined(CONFIG_SYS_PCI_64BIT) && !defined(CONFIG_SYS_PCI64_MEMORY_BUS)
  56. #define CONFIG_SYS_PCI64_MEMORY_BUS (64ull*1024*1024*1024)
  57. #endif
  58. /* Setup one inbound ATMU window.
  59. *
  60. * We let the caller decide what the window size should be
  61. */
  62. static void set_inbound_window(volatile pit_t *pi,
  63. struct pci_region *r,
  64. u64 size)
  65. {
  66. u32 sz = (__ilog2_u64(size) - 1);
  67. u32 flag = PIWAR_EN | PIWAR_LOCAL |
  68. PIWAR_READ_SNOOP | PIWAR_WRITE_SNOOP;
  69. out_be32(&pi->pitar, r->phys_start >> 12);
  70. out_be32(&pi->piwbar, r->bus_start >> 12);
  71. #ifdef CONFIG_SYS_PCI_64BIT
  72. out_be32(&pi->piwbear, r->bus_start >> 44);
  73. #else
  74. out_be32(&pi->piwbear, 0);
  75. #endif
  76. if (r->flags & PCI_REGION_PREFETCH)
  77. flag |= PIWAR_PF;
  78. out_be32(&pi->piwar, flag | sz);
  79. }
  80. int fsl_setup_hose(struct pci_controller *hose, unsigned long addr)
  81. {
  82. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) addr;
  83. /* Reset hose to make sure its in a clean state */
  84. memset(hose, 0, sizeof(struct pci_controller));
  85. pci_setup_indirect(hose, (u32)&pci->cfg_addr, (u32)&pci->cfg_data);
  86. return fsl_is_pci_agent(hose);
  87. }
  88. static int fsl_pci_setup_inbound_windows(struct pci_controller *hose,
  89. u64 out_lo, u8 pcie_cap,
  90. volatile pit_t *pi)
  91. {
  92. struct pci_region *r = hose->regions + hose->region_count;
  93. u64 sz = min((u64)gd->ram_size, (1ull << 32));
  94. phys_addr_t phys_start = CONFIG_SYS_PCI_MEMORY_PHYS;
  95. pci_addr_t bus_start = CONFIG_SYS_PCI_MEMORY_BUS;
  96. pci_size_t pci_sz;
  97. /* we have no space available for inbound memory mapping */
  98. if (bus_start > out_lo) {
  99. printf ("no space for inbound mapping of memory\n");
  100. return 0;
  101. }
  102. /* limit size */
  103. if ((bus_start + sz) > out_lo) {
  104. sz = out_lo - bus_start;
  105. debug ("limiting size to %llx\n", sz);
  106. }
  107. pci_sz = 1ull << __ilog2_u64(sz);
  108. /*
  109. * we can overlap inbound/outbound windows on PCI-E since RX & TX
  110. * links a separate
  111. */
  112. if ((pcie_cap == PCI_CAP_ID_EXP) && (pci_sz < sz)) {
  113. debug ("R0 bus_start: %llx phys_start: %llx size: %llx\n",
  114. (u64)bus_start, (u64)phys_start, (u64)sz);
  115. pci_set_region(r, bus_start, phys_start, sz,
  116. PCI_REGION_MEM | PCI_REGION_SYS_MEMORY |
  117. PCI_REGION_PREFETCH);
  118. /* if we aren't an exact power of two match, pci_sz is smaller
  119. * round it up to the next power of two. We report the actual
  120. * size to pci region tracking.
  121. */
  122. if (pci_sz != sz)
  123. sz = 2ull << __ilog2_u64(sz);
  124. set_inbound_window(pi--, r++, sz);
  125. sz = 0; /* make sure we dont set the R2 window */
  126. } else {
  127. debug ("R0 bus_start: %llx phys_start: %llx size: %llx\n",
  128. (u64)bus_start, (u64)phys_start, (u64)pci_sz);
  129. pci_set_region(r, bus_start, phys_start, pci_sz,
  130. PCI_REGION_MEM | PCI_REGION_SYS_MEMORY |
  131. PCI_REGION_PREFETCH);
  132. set_inbound_window(pi--, r++, pci_sz);
  133. sz -= pci_sz;
  134. bus_start += pci_sz;
  135. phys_start += pci_sz;
  136. pci_sz = 1ull << __ilog2_u64(sz);
  137. if (sz) {
  138. debug ("R1 bus_start: %llx phys_start: %llx size: %llx\n",
  139. (u64)bus_start, (u64)phys_start, (u64)pci_sz);
  140. pci_set_region(r, bus_start, phys_start, pci_sz,
  141. PCI_REGION_MEM | PCI_REGION_SYS_MEMORY |
  142. PCI_REGION_PREFETCH);
  143. set_inbound_window(pi--, r++, pci_sz);
  144. sz -= pci_sz;
  145. bus_start += pci_sz;
  146. phys_start += pci_sz;
  147. }
  148. }
  149. #if defined(CONFIG_PHYS_64BIT) && defined(CONFIG_SYS_PCI_64BIT)
  150. /*
  151. * On 64-bit capable systems, set up a mapping for all of DRAM
  152. * in high pci address space.
  153. */
  154. pci_sz = 1ull << __ilog2_u64(gd->ram_size);
  155. /* round up to the next largest power of two */
  156. if (gd->ram_size > pci_sz)
  157. pci_sz = 1ull << (__ilog2_u64(gd->ram_size) + 1);
  158. debug ("R64 bus_start: %llx phys_start: %llx size: %llx\n",
  159. (u64)CONFIG_SYS_PCI64_MEMORY_BUS,
  160. (u64)CONFIG_SYS_PCI_MEMORY_PHYS,
  161. (u64)pci_sz);
  162. pci_set_region(r,
  163. CONFIG_SYS_PCI64_MEMORY_BUS,
  164. CONFIG_SYS_PCI_MEMORY_PHYS,
  165. pci_sz,
  166. PCI_REGION_MEM | PCI_REGION_SYS_MEMORY |
  167. PCI_REGION_PREFETCH);
  168. set_inbound_window(pi--, r++, pci_sz);
  169. #else
  170. pci_sz = 1ull << __ilog2_u64(sz);
  171. if (sz) {
  172. debug ("R2 bus_start: %llx phys_start: %llx size: %llx\n",
  173. (u64)bus_start, (u64)phys_start, (u64)pci_sz);
  174. pci_set_region(r, bus_start, phys_start, pci_sz,
  175. PCI_REGION_MEM | PCI_REGION_SYS_MEMORY |
  176. PCI_REGION_PREFETCH);
  177. sz -= pci_sz;
  178. bus_start += pci_sz;
  179. phys_start += pci_sz;
  180. set_inbound_window(pi--, r++, pci_sz);
  181. }
  182. #endif
  183. #ifdef CONFIG_PHYS_64BIT
  184. if (sz && (((u64)gd->ram_size) < (1ull << 32)))
  185. printf("Was not able to map all of memory via "
  186. "inbound windows -- %lld remaining\n", sz);
  187. #endif
  188. hose->region_count = r - hose->regions;
  189. return 1;
  190. }
  191. void fsl_pci_init(struct pci_controller *hose, struct fsl_pci_info *pci_info)
  192. {
  193. u32 cfg_addr = (u32)&((ccsr_fsl_pci_t *)pci_info->regs)->cfg_addr;
  194. u32 cfg_data = (u32)&((ccsr_fsl_pci_t *)pci_info->regs)->cfg_data;
  195. u16 temp16;
  196. u32 temp32;
  197. int enabled, r, inbound = 0;
  198. u16 ltssm;
  199. u8 temp8, pcie_cap;
  200. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *)cfg_addr;
  201. struct pci_region *reg = hose->regions + hose->region_count;
  202. pci_dev_t dev = PCI_BDF(hose->first_busno, 0, 0);
  203. /* Initialize ATMU registers based on hose regions and flags */
  204. volatile pot_t *po = &pci->pot[1]; /* skip 0 */
  205. volatile pit_t *pi = &pci->pit[2]; /* ranges from: 3 to 1 */
  206. u64 out_hi = 0, out_lo = -1ULL;
  207. u32 pcicsrbar, pcicsrbar_sz;
  208. pci_setup_indirect(hose, cfg_addr, cfg_data);
  209. /* Handle setup of outbound windows first */
  210. for (r = 0; r < hose->region_count; r++) {
  211. unsigned long flags = hose->regions[r].flags;
  212. u32 sz = (__ilog2_u64((u64)hose->regions[r].size) - 1);
  213. flags &= PCI_REGION_SYS_MEMORY|PCI_REGION_TYPE;
  214. if (flags != PCI_REGION_SYS_MEMORY) {
  215. u64 start = hose->regions[r].bus_start;
  216. u64 end = start + hose->regions[r].size;
  217. out_be32(&po->powbar, hose->regions[r].phys_start >> 12);
  218. out_be32(&po->potar, start >> 12);
  219. #ifdef CONFIG_SYS_PCI_64BIT
  220. out_be32(&po->potear, start >> 44);
  221. #else
  222. out_be32(&po->potear, 0);
  223. #endif
  224. if (hose->regions[r].flags & PCI_REGION_IO) {
  225. out_be32(&po->powar, POWAR_EN | sz |
  226. POWAR_IO_READ | POWAR_IO_WRITE);
  227. } else {
  228. out_be32(&po->powar, POWAR_EN | sz |
  229. POWAR_MEM_READ | POWAR_MEM_WRITE);
  230. out_lo = min(start, out_lo);
  231. out_hi = max(end, out_hi);
  232. }
  233. po++;
  234. }
  235. }
  236. debug("Outbound memory range: %llx:%llx\n", out_lo, out_hi);
  237. /* setup PCSRBAR/PEXCSRBAR */
  238. pci_hose_write_config_dword(hose, dev, PCI_BASE_ADDRESS_0, 0xffffffff);
  239. pci_hose_read_config_dword (hose, dev, PCI_BASE_ADDRESS_0, &pcicsrbar_sz);
  240. pcicsrbar_sz = ~pcicsrbar_sz + 1;
  241. if (out_hi < (0x100000000ull - pcicsrbar_sz) ||
  242. (out_lo > 0x100000000ull))
  243. pcicsrbar = 0x100000000ull - pcicsrbar_sz;
  244. else
  245. pcicsrbar = (out_lo - pcicsrbar_sz) & -pcicsrbar_sz;
  246. pci_hose_write_config_dword(hose, dev, PCI_BASE_ADDRESS_0, pcicsrbar);
  247. out_lo = min(out_lo, (u64)pcicsrbar);
  248. debug("PCICSRBAR @ 0x%x\n", pcicsrbar);
  249. pci_set_region(reg++, pcicsrbar, CONFIG_SYS_CCSRBAR_PHYS,
  250. pcicsrbar_sz, PCI_REGION_SYS_MEMORY);
  251. hose->region_count++;
  252. /* see if we are a PCIe or PCI controller */
  253. pci_hose_read_config_byte(hose, dev, FSL_PCIE_CAP_ID, &pcie_cap);
  254. /* inbound */
  255. inbound = fsl_pci_setup_inbound_windows(hose, out_lo, pcie_cap, pi);
  256. for (r = 0; r < hose->region_count; r++)
  257. debug("PCI reg:%d %016llx:%016llx %016llx %08x\n", r,
  258. (u64)hose->regions[r].phys_start,
  259. hose->regions[r].bus_start,
  260. hose->regions[r].size,
  261. hose->regions[r].flags);
  262. pci_register_hose(hose);
  263. pciauto_config_init(hose); /* grab pci_{mem,prefetch,io} */
  264. hose->current_busno = hose->first_busno;
  265. out_be32(&pci->pedr, 0xffffffff); /* Clear any errors */
  266. out_be32(&pci->peer, ~0x20140); /* Enable All Error Interupts except
  267. * - Master abort (pci)
  268. * - Master PERR (pci)
  269. * - ICCA (PCIe)
  270. */
  271. pci_hose_read_config_dword(hose, dev, PCI_DCR, &temp32);
  272. temp32 |= 0xf000e; /* set URR, FER, NFER (but not CER) */
  273. pci_hose_write_config_dword(hose, dev, PCI_DCR, temp32);
  274. if (pcie_cap == PCI_CAP_ID_EXP) {
  275. pci_hose_read_config_word(hose, dev, PCI_LTSSM, &ltssm);
  276. enabled = ltssm >= PCI_LTSSM_L0;
  277. #ifdef CONFIG_FSL_PCIE_RESET
  278. if (ltssm == 1) {
  279. int i;
  280. debug("....PCIe link error. " "LTSSM=0x%02x.", ltssm);
  281. /* assert PCIe reset */
  282. setbits_be32(&pci->pdb_stat, 0x08000000);
  283. (void) in_be32(&pci->pdb_stat);
  284. udelay(100);
  285. debug(" Asserting PCIe reset @%x = %x\n",
  286. &pci->pdb_stat, in_be32(&pci->pdb_stat));
  287. /* clear PCIe reset */
  288. clrbits_be32(&pci->pdb_stat, 0x08000000);
  289. asm("sync;isync");
  290. for (i=0; i<100 && ltssm < PCI_LTSSM_L0; i++) {
  291. pci_hose_read_config_word(hose, dev, PCI_LTSSM,
  292. &ltssm);
  293. udelay(1000);
  294. debug("....PCIe link error. "
  295. "LTSSM=0x%02x.\n", ltssm);
  296. }
  297. enabled = ltssm >= PCI_LTSSM_L0;
  298. /* we need to re-write the bar0 since a reset will
  299. * clear it
  300. */
  301. pci_hose_write_config_dword(hose, dev,
  302. PCI_BASE_ADDRESS_0, pcicsrbar);
  303. }
  304. #endif
  305. if (!enabled) {
  306. /* Let the user know there's no PCIe link */
  307. printf("no link, regs @ 0x%lx\n", pci_info->regs);
  308. hose->last_busno = hose->first_busno;
  309. return;
  310. }
  311. out_be32(&pci->pme_msg_det, 0xffffffff);
  312. out_be32(&pci->pme_msg_int_en, 0xffffffff);
  313. /* Print the negotiated PCIe link width */
  314. pci_hose_read_config_word(hose, dev, PCI_LSR, &temp16);
  315. printf("x%d, regs @ 0x%lx\n", (temp16 & 0x3f0 ) >> 4,
  316. pci_info->regs);
  317. hose->current_busno++; /* Start scan with secondary */
  318. pciauto_prescan_setup_bridge(hose, dev, hose->current_busno);
  319. }
  320. /* Use generic setup_device to initialize standard pci regs,
  321. * but do not allocate any windows since any BAR found (such
  322. * as PCSRBAR) is not in this cpu's memory space.
  323. */
  324. pciauto_setup_device(hose, dev, 0, hose->pci_mem,
  325. hose->pci_prefetch, hose->pci_io);
  326. if (inbound) {
  327. pci_hose_read_config_word(hose, dev, PCI_COMMAND, &temp16);
  328. pci_hose_write_config_word(hose, dev, PCI_COMMAND,
  329. temp16 | PCI_COMMAND_MEMORY);
  330. }
  331. #ifndef CONFIG_PCI_NOSCAN
  332. pci_hose_read_config_byte(hose, dev, PCI_CLASS_PROG, &temp8);
  333. /* Programming Interface (PCI_CLASS_PROG)
  334. * 0 == pci host or pcie root-complex,
  335. * 1 == pci agent or pcie end-point
  336. */
  337. if (!temp8) {
  338. debug(" Scanning PCI bus %02x\n",
  339. hose->current_busno);
  340. hose->last_busno = pci_hose_scan_bus(hose, hose->current_busno);
  341. } else {
  342. debug(" Not scanning PCI bus %02x. PI=%x\n",
  343. hose->current_busno, temp8);
  344. hose->last_busno = hose->current_busno;
  345. }
  346. /* if we are PCIe - update limit regs and subordinate busno
  347. * for the virtual P2P bridge
  348. */
  349. if (pcie_cap == PCI_CAP_ID_EXP) {
  350. pciauto_postscan_setup_bridge(hose, dev, hose->last_busno);
  351. }
  352. #else
  353. hose->last_busno = hose->current_busno;
  354. #endif
  355. /* Clear all error indications */
  356. if (pcie_cap == PCI_CAP_ID_EXP)
  357. out_be32(&pci->pme_msg_det, 0xffffffff);
  358. out_be32(&pci->pedr, 0xffffffff);
  359. pci_hose_read_config_word (hose, dev, PCI_DSR, &temp16);
  360. if (temp16) {
  361. pci_hose_write_config_word(hose, dev, PCI_DSR, 0xffff);
  362. }
  363. pci_hose_read_config_word (hose, dev, PCI_SEC_STATUS, &temp16);
  364. if (temp16) {
  365. pci_hose_write_config_word(hose, dev, PCI_SEC_STATUS, 0xffff);
  366. }
  367. }
  368. int fsl_is_pci_agent(struct pci_controller *hose)
  369. {
  370. u8 prog_if;
  371. pci_dev_t dev = PCI_BDF(hose->first_busno, 0, 0);
  372. pci_hose_read_config_byte(hose, dev, PCI_CLASS_PROG, &prog_if);
  373. return (prog_if == FSL_PROG_IF_AGENT);
  374. }
  375. int fsl_pci_init_port(struct fsl_pci_info *pci_info,
  376. struct pci_controller *hose, int busno)
  377. {
  378. volatile ccsr_fsl_pci_t *pci;
  379. struct pci_region *r;
  380. pci_dev_t dev = PCI_BDF(busno,0,0);
  381. u8 pcie_cap;
  382. pci = (ccsr_fsl_pci_t *) pci_info->regs;
  383. /* on non-PCIe controllers we don't have pme_msg_det so this code
  384. * should do nothing since the read will return 0
  385. */
  386. if (in_be32(&pci->pme_msg_det)) {
  387. out_be32(&pci->pme_msg_det, 0xffffffff);
  388. debug (" with errors. Clearing. Now 0x%08x",
  389. pci->pme_msg_det);
  390. }
  391. r = hose->regions + hose->region_count;
  392. /* outbound memory */
  393. pci_set_region(r++,
  394. pci_info->mem_bus,
  395. pci_info->mem_phys,
  396. pci_info->mem_size,
  397. PCI_REGION_MEM);
  398. /* outbound io */
  399. pci_set_region(r++,
  400. pci_info->io_bus,
  401. pci_info->io_phys,
  402. pci_info->io_size,
  403. PCI_REGION_IO);
  404. hose->region_count = r - hose->regions;
  405. hose->first_busno = busno;
  406. fsl_pci_init(hose, pci_info);
  407. if (fsl_is_pci_agent(hose)) {
  408. fsl_pci_config_unlock(hose);
  409. hose->last_busno = hose->first_busno;
  410. }
  411. pci_hose_read_config_byte(hose, dev, FSL_PCIE_CAP_ID, &pcie_cap);
  412. printf("PCI%s%x: Bus %02x - %02x\n", pcie_cap == PCI_CAP_ID_EXP ?
  413. "e" : "", pci_info->pci_num,
  414. hose->first_busno, hose->last_busno);
  415. return(hose->last_busno + 1);
  416. }
  417. /* Enable inbound PCI config cycles for agent/endpoint interface */
  418. void fsl_pci_config_unlock(struct pci_controller *hose)
  419. {
  420. pci_dev_t dev = PCI_BDF(hose->first_busno,0,0);
  421. u8 agent;
  422. u8 pcie_cap;
  423. u16 pbfr;
  424. pci_hose_read_config_byte(hose, dev, PCI_CLASS_PROG, &agent);
  425. if (!agent)
  426. return;
  427. pci_hose_read_config_byte(hose, dev, FSL_PCIE_CAP_ID, &pcie_cap);
  428. if (pcie_cap != 0x0) {
  429. /* PCIe - set CFG_READY bit of Configuration Ready Register */
  430. pci_hose_write_config_byte(hose, dev, FSL_PCIE_CFG_RDY, 0x1);
  431. } else {
  432. /* PCI - clear ACL bit of PBFR */
  433. pci_hose_read_config_word(hose, dev, FSL_PCI_PBFR, &pbfr);
  434. pbfr &= ~0x20;
  435. pci_hose_write_config_word(hose, dev, FSL_PCI_PBFR, pbfr);
  436. }
  437. }
  438. #if defined(CONFIG_PCIE1) || defined(CONFIG_PCIE2) || \
  439. defined(CONFIG_PCIE3) || defined(CONFIG_PCIE4)
  440. int fsl_configure_pcie(struct fsl_pci_info *info,
  441. struct pci_controller *hose,
  442. const char *connected, int busno)
  443. {
  444. int is_endpoint;
  445. set_next_law(info->mem_phys, law_size_bits(info->mem_size), info->law);
  446. set_next_law(info->io_phys, law_size_bits(info->io_size), info->law);
  447. is_endpoint = fsl_setup_hose(hose, info->regs);
  448. printf("PCIe%u: %s", info->pci_num,
  449. is_endpoint ? "Endpoint" : "Root Complex");
  450. if (connected)
  451. printf(" of %s", connected);
  452. puts(", ");
  453. return fsl_pci_init_port(info, hose, busno);
  454. }
  455. #if defined(CONFIG_FSL_CORENET)
  456. #define _DEVDISR_PCIE1 FSL_CORENET_DEVDISR_PCIE1
  457. #define _DEVDISR_PCIE2 FSL_CORENET_DEVDISR_PCIE2
  458. #define _DEVDISR_PCIE3 FSL_CORENET_DEVDISR_PCIE3
  459. #define _DEVDISR_PCIE4 FSL_CORENET_DEVDISR_PCIE4
  460. #define CONFIG_SYS_MPC8xxx_GUTS_ADDR CONFIG_SYS_MPC85xx_GUTS_ADDR
  461. #elif defined(CONFIG_MPC85xx)
  462. #define _DEVDISR_PCIE1 MPC85xx_DEVDISR_PCIE
  463. #define _DEVDISR_PCIE2 MPC85xx_DEVDISR_PCIE2
  464. #define _DEVDISR_PCIE3 MPC85xx_DEVDISR_PCIE3
  465. #define _DEVDISR_PCIE4 0
  466. #define CONFIG_SYS_MPC8xxx_GUTS_ADDR CONFIG_SYS_MPC85xx_GUTS_ADDR
  467. #elif defined(CONFIG_MPC86xx)
  468. #define _DEVDISR_PCIE1 MPC86xx_DEVDISR_PCIE1
  469. #define _DEVDISR_PCIE2 MPC86xx_DEVDISR_PCIE2
  470. #define _DEVDISR_PCIE3 0
  471. #define _DEVDISR_PCIE4 0
  472. #define CONFIG_SYS_MPC8xxx_GUTS_ADDR \
  473. (&((immap_t *)CONFIG_SYS_IMMR)->im_gur)
  474. #else
  475. #error "No defines for DEVDISR_PCIE"
  476. #endif
  477. /* Implement a dummy function for those platforms w/o SERDES */
  478. static const char *__board_serdes_name(enum srds_prtcl device)
  479. {
  480. switch (device) {
  481. #ifdef CONFIG_SYS_PCIE1_NAME
  482. case PCIE1:
  483. return CONFIG_SYS_PCIE1_NAME;
  484. #endif
  485. #ifdef CONFIG_SYS_PCIE2_NAME
  486. case PCIE2:
  487. return CONFIG_SYS_PCIE2_NAME;
  488. #endif
  489. #ifdef CONFIG_SYS_PCIE3_NAME
  490. case PCIE3:
  491. return CONFIG_SYS_PCIE3_NAME;
  492. #endif
  493. #ifdef CONFIG_SYS_PCIE4_NAME
  494. case PCIE4:
  495. return CONFIG_SYS_PCIE4_NAME;
  496. #endif
  497. default:
  498. return NULL;
  499. }
  500. return NULL;
  501. }
  502. __attribute__((weak, alias("__board_serdes_name"))) const char *
  503. board_serdes_name(enum srds_prtcl device);
  504. static u32 devdisr_mask[] = {
  505. _DEVDISR_PCIE1,
  506. _DEVDISR_PCIE2,
  507. _DEVDISR_PCIE3,
  508. _DEVDISR_PCIE4,
  509. };
  510. int fsl_pcie_init_ctrl(int busno, u32 devdisr, enum srds_prtcl dev,
  511. struct fsl_pci_info *pci_info)
  512. {
  513. struct pci_controller *hose;
  514. int num = dev - PCIE1;
  515. hose = calloc(1, sizeof(struct pci_controller));
  516. if (!hose)
  517. return busno;
  518. if (is_serdes_configured(dev) && !(devdisr & devdisr_mask[num])) {
  519. busno = fsl_configure_pcie(pci_info, hose,
  520. board_serdes_name(dev), busno);
  521. } else {
  522. printf("PCIe%d: disabled\n", num + 1);
  523. }
  524. return busno;
  525. }
  526. int fsl_pcie_init_board(int busno)
  527. {
  528. struct fsl_pci_info pci_info;
  529. ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC8xxx_GUTS_ADDR;
  530. u32 devdisr = in_be32(&gur->devdisr);
  531. #ifdef CONFIG_PCIE1
  532. SET_STD_PCIE_INFO(pci_info, 1);
  533. busno = fsl_pcie_init_ctrl(busno, devdisr, PCIE1, &pci_info);
  534. #else
  535. setbits_be32(&gur->devdisr, _DEVDISR_PCIE1); /* disable */
  536. #endif
  537. #ifdef CONFIG_PCIE2
  538. SET_STD_PCIE_INFO(pci_info, 2);
  539. busno = fsl_pcie_init_ctrl(busno, devdisr, PCIE2, &pci_info);
  540. #else
  541. setbits_be32(&gur->devdisr, _DEVDISR_PCIE2); /* disable */
  542. #endif
  543. #ifdef CONFIG_PCIE3
  544. SET_STD_PCIE_INFO(pci_info, 3);
  545. busno = fsl_pcie_init_ctrl(busno, devdisr, PCIE3, &pci_info);
  546. #else
  547. setbits_be32(&gur->devdisr, _DEVDISR_PCIE3); /* disable */
  548. #endif
  549. #ifdef CONFIG_PCIE4
  550. SET_STD_PCIE_INFO(pci_info, 4);
  551. busno = fsl_pcie_init_ctrl(busno, devdisr, PCIE4, &pci_info);
  552. #else
  553. setbits_be32(&gur->devdisr, _DEVDISR_PCIE4); /* disable */
  554. #endif
  555. return busno;
  556. }
  557. #else
  558. int fsl_pcie_init_ctrl(int busno, u32 devdisr, enum srds_prtcl dev,
  559. struct fsl_pci_info *pci_info)
  560. {
  561. return busno;
  562. }
  563. int fsl_pcie_init_board(int busno)
  564. {
  565. return busno;
  566. }
  567. #endif
  568. #ifdef CONFIG_OF_BOARD_SETUP
  569. #include <libfdt.h>
  570. #include <fdt_support.h>
  571. void ft_fsl_pci_setup(void *blob, const char *pci_compat,
  572. unsigned long ctrl_addr)
  573. {
  574. int off;
  575. u32 bus_range[2];
  576. phys_addr_t p_ctrl_addr = (phys_addr_t)ctrl_addr;
  577. struct pci_controller *hose;
  578. hose = find_hose_by_cfg_addr((void *)(ctrl_addr));
  579. /* convert ctrl_addr to true physical address */
  580. p_ctrl_addr = (phys_addr_t)ctrl_addr - CONFIG_SYS_CCSRBAR;
  581. p_ctrl_addr += CONFIG_SYS_CCSRBAR_PHYS;
  582. off = fdt_node_offset_by_compat_reg(blob, pci_compat, p_ctrl_addr);
  583. if (off < 0)
  584. return;
  585. /* We assume a cfg_addr not being set means we didn't setup the controller */
  586. if ((hose == NULL) || (hose->cfg_addr == NULL)) {
  587. fdt_del_node(blob, off);
  588. } else {
  589. bus_range[0] = 0;
  590. bus_range[1] = hose->last_busno - hose->first_busno;
  591. fdt_setprop(blob, off, "bus-range", &bus_range[0], 2*4);
  592. fdt_pci_dma_ranges(blob, off, hose);
  593. }
  594. }
  595. #endif