fsl_pci_init.c 20 KB

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