1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2007-2012 Freescale Semiconductor, Inc.
11 #include <asm/fsl_serdes.h>
13 DECLARE_GLOBAL_DATA_PTR;
16 * PCI/PCIE Controller initialization for mpc85xx/mpc86xx soc's
18 * Initialize controller and call the common driver/pci pci_hose_scan to
19 * scan for bridges and devices.
21 * Hose fields which need to be pre-initialized by board specific code:
31 #include <asm/fsl_pci.h>
33 #ifndef CONFIG_SYS_PCI_MEMORY_BUS
34 #define CONFIG_SYS_PCI_MEMORY_BUS 0
37 #ifndef CONFIG_SYS_PCI_MEMORY_PHYS
38 #define CONFIG_SYS_PCI_MEMORY_PHYS 0
41 #if defined(CONFIG_SYS_PCI_64BIT) && !defined(CONFIG_SYS_PCI64_MEMORY_BUS)
42 #define CONFIG_SYS_PCI64_MEMORY_BUS (64ull*1024*1024*1024)
45 /* Setup one inbound ATMU window.
47 * We let the caller decide what the window size should be
49 static void set_inbound_window(volatile pit_t *pi,
53 u32 sz = (__ilog2_u64(size) - 1);
54 #ifdef CONFIG_SYS_FSL_ERRATUM_A005434
57 u32 flag = PIWAR_LOCAL;
60 flag |= PIWAR_EN | PIWAR_READ_SNOOP | PIWAR_WRITE_SNOOP;
62 out_be32(&pi->pitar, r->phys_start >> 12);
63 out_be32(&pi->piwbar, r->bus_start >> 12);
64 #ifdef CONFIG_SYS_PCI_64BIT
65 out_be32(&pi->piwbear, r->bus_start >> 44);
67 out_be32(&pi->piwbear, 0);
69 if (r->flags & PCI_REGION_PREFETCH)
71 out_be32(&pi->piwar, flag | sz);
74 int fsl_setup_hose(struct pci_controller *hose, unsigned long addr)
76 volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) addr;
78 /* Reset hose to make sure its in a clean state */
79 memset(hose, 0, sizeof(struct pci_controller));
81 pci_setup_indirect(hose, (u32)&pci->cfg_addr, (u32)&pci->cfg_data);
83 return fsl_is_pci_agent(hose);
86 static int fsl_pci_setup_inbound_windows(struct pci_controller *hose,
87 u64 out_lo, u8 pcie_cap,
90 struct pci_region *r = hose->regions + hose->region_count;
91 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;
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");
104 if ((bus_start + sz) > out_lo) {
105 sz = out_lo - bus_start;
106 debug ("limiting size to %llx\n", sz);
109 pci_sz = 1ull << __ilog2_u64(sz);
111 * we can overlap inbound/outbound windows on PCI-E since RX & TX
114 if ((pcie_cap == PCI_CAP_ID_EXP) && (pci_sz < sz)) {
115 debug ("R0 bus_start: %llx phys_start: %llx size: %llx\n",
116 (u64)bus_start, (u64)phys_start, (u64)sz);
117 pci_set_region(r, bus_start, phys_start, sz,
118 PCI_REGION_MEM | PCI_REGION_SYS_MEMORY |
119 PCI_REGION_PREFETCH);
121 /* if we aren't an exact power of two match, pci_sz is smaller
122 * round it up to the next power of two. We report the actual
123 * size to pci region tracking.
126 sz = 2ull << __ilog2_u64(sz);
128 set_inbound_window(pi--, r++, sz);
129 sz = 0; /* make sure we dont set the R2 window */
131 debug ("R0 bus_start: %llx phys_start: %llx size: %llx\n",
132 (u64)bus_start, (u64)phys_start, (u64)pci_sz);
133 pci_set_region(r, bus_start, phys_start, pci_sz,
134 PCI_REGION_MEM | PCI_REGION_SYS_MEMORY |
135 PCI_REGION_PREFETCH);
136 set_inbound_window(pi--, r++, pci_sz);
140 phys_start += pci_sz;
142 pci_sz = 1ull << __ilog2_u64(sz);
144 debug ("R1 bus_start: %llx phys_start: %llx size: %llx\n",
145 (u64)bus_start, (u64)phys_start, (u64)pci_sz);
146 pci_set_region(r, bus_start, phys_start, pci_sz,
147 PCI_REGION_MEM | PCI_REGION_SYS_MEMORY |
148 PCI_REGION_PREFETCH);
149 set_inbound_window(pi--, r++, pci_sz);
152 phys_start += pci_sz;
156 #if defined(CONFIG_PHYS_64BIT) && defined(CONFIG_SYS_PCI_64BIT)
158 * On 64-bit capable systems, set up a mapping for all of DRAM
159 * in high pci address space.
161 pci_sz = 1ull << __ilog2_u64(gd->ram_size);
162 /* round up to the next largest power of two */
163 if (gd->ram_size > pci_sz)
164 pci_sz = 1ull << (__ilog2_u64(gd->ram_size) + 1);
165 debug ("R64 bus_start: %llx phys_start: %llx size: %llx\n",
166 (u64)CONFIG_SYS_PCI64_MEMORY_BUS,
167 (u64)CONFIG_SYS_PCI_MEMORY_PHYS,
170 CONFIG_SYS_PCI64_MEMORY_BUS,
171 CONFIG_SYS_PCI_MEMORY_PHYS,
173 PCI_REGION_MEM | PCI_REGION_SYS_MEMORY |
174 PCI_REGION_PREFETCH);
175 set_inbound_window(pi--, r++, pci_sz);
177 pci_sz = 1ull << __ilog2_u64(sz);
179 debug ("R2 bus_start: %llx phys_start: %llx size: %llx\n",
180 (u64)bus_start, (u64)phys_start, (u64)pci_sz);
181 pci_set_region(r, bus_start, phys_start, pci_sz,
182 PCI_REGION_MEM | PCI_REGION_SYS_MEMORY |
183 PCI_REGION_PREFETCH);
186 phys_start += pci_sz;
187 set_inbound_window(pi--, r++, pci_sz);
191 #ifdef CONFIG_PHYS_64BIT
192 if (sz && (((u64)gd->ram_size) < (1ull << 32)))
193 printf("Was not able to map all of memory via "
194 "inbound windows -- %lld remaining\n", sz);
197 hose->region_count = r - hose->regions;
202 #ifdef CONFIG_SRIO_PCIE_BOOT_MASTER
203 static void fsl_pcie_boot_master(pit_t *pi)
205 /* configure inbound window for slave's u-boot image */
206 debug("PCIEBOOT - MASTER: Inbound window for slave's image; "
207 "Local = 0x%llx, Bus = 0x%llx, Size = 0x%x\n",
208 (u64)CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_PHYS,
209 (u64)CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_BUS1,
210 CONFIG_SRIO_PCIE_BOOT_IMAGE_SIZE);
211 struct pci_region r_inbound;
212 u32 sz_inbound = __ilog2_u64(CONFIG_SRIO_PCIE_BOOT_IMAGE_SIZE)
214 pci_set_region(&r_inbound,
215 CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_BUS1,
216 CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_PHYS,
218 PCI_REGION_MEM | PCI_REGION_SYS_MEMORY);
220 set_inbound_window(pi--, &r_inbound,
221 CONFIG_SRIO_PCIE_BOOT_IMAGE_SIZE);
223 /* configure inbound window for slave's u-boot image */
224 debug("PCIEBOOT - MASTER: Inbound window for slave's image; "
225 "Local = 0x%llx, Bus = 0x%llx, Size = 0x%x\n",
226 (u64)CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_PHYS,
227 (u64)CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_BUS2,
228 CONFIG_SRIO_PCIE_BOOT_IMAGE_SIZE);
229 pci_set_region(&r_inbound,
230 CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_BUS2,
231 CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_PHYS,
233 PCI_REGION_MEM | PCI_REGION_SYS_MEMORY);
235 set_inbound_window(pi--, &r_inbound,
236 CONFIG_SRIO_PCIE_BOOT_IMAGE_SIZE);
238 /* configure inbound window for slave's ucode and ENV */
239 debug("PCIEBOOT - MASTER: Inbound window for slave's "
241 "Local = 0x%llx, Bus = 0x%llx, Size = 0x%x\n",
242 (u64)CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_MEM_PHYS,
243 (u64)CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_MEM_BUS,
244 CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_SIZE);
245 sz_inbound = __ilog2_u64(CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_SIZE)
247 pci_set_region(&r_inbound,
248 CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_MEM_BUS,
249 CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_MEM_PHYS,
251 PCI_REGION_MEM | PCI_REGION_SYS_MEMORY);
253 set_inbound_window(pi--, &r_inbound,
254 CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_SIZE);
257 static void fsl_pcie_boot_master_release_slave(int port)
259 unsigned long release_addr;
261 /* now release slave's core 0 */
264 release_addr = CONFIG_SYS_PCIE1_MEM_VIRT
265 + CONFIG_SRIO_PCIE_BOOT_BRR_OFFSET;
267 #ifdef CONFIG_SYS_PCIE2_MEM_VIRT
269 release_addr = CONFIG_SYS_PCIE2_MEM_VIRT
270 + CONFIG_SRIO_PCIE_BOOT_BRR_OFFSET;
273 #ifdef CONFIG_SYS_PCIE3_MEM_VIRT
275 release_addr = CONFIG_SYS_PCIE3_MEM_VIRT
276 + CONFIG_SRIO_PCIE_BOOT_BRR_OFFSET;
283 if (release_addr != 0) {
284 out_be32((void *)release_addr,
285 CONFIG_SRIO_PCIE_BOOT_RELEASE_MASK);
286 debug("PCIEBOOT - MASTER: "
287 "Release slave successfully! Now the slave should start up!\n");
289 debug("PCIEBOOT - MASTER: "
290 "Release slave failed!\n");
295 void fsl_pci_init(struct pci_controller *hose, struct fsl_pci_info *pci_info)
297 u32 cfg_addr = (u32)&((ccsr_fsl_pci_t *)pci_info->regs)->cfg_addr;
298 u32 cfg_data = (u32)&((ccsr_fsl_pci_t *)pci_info->regs)->cfg_data;
302 int enabled, r, inbound = 0;
310 #if defined(CONFIG_FSL_PCIE_DISABLE_ASPM)
314 volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *)cfg_addr;
315 struct pci_region *reg = hose->regions + hose->region_count;
316 pci_dev_t dev = PCI_BDF(hose->first_busno, 0, 0);
318 /* Initialize ATMU registers based on hose regions and flags */
319 volatile pot_t *po = &pci->pot[1]; /* skip 0 */
322 u64 out_hi = 0, out_lo = -1ULL;
323 u32 pcicsrbar, pcicsrbar_sz;
325 pci_setup_indirect(hose, cfg_addr, cfg_data);
328 /* Configure the PCIE controller core clock ratio */
329 pci_hose_write_config_dword(hose, dev, 0x440,
330 ((gd->bus_clk / 1000000) *
331 (16 / PEX_CCB_DIV)) / 333);
333 block_rev = in_be32(&pci->block_rev1);
334 if (PEX_IP_BLK_REV_2_2 <= block_rev) {
335 pi = &pci->pit[2]; /* 0xDC0 */
337 pi = &pci->pit[3]; /* 0xDE0 */
340 /* Handle setup of outbound windows first */
341 for (r = 0; r < hose->region_count; r++) {
342 unsigned long flags = hose->regions[r].flags;
343 u32 sz = (__ilog2_u64((u64)hose->regions[r].size) - 1);
345 flags &= PCI_REGION_SYS_MEMORY|PCI_REGION_TYPE;
346 if (flags != PCI_REGION_SYS_MEMORY) {
347 u64 start = hose->regions[r].bus_start;
348 u64 end = start + hose->regions[r].size;
350 out_be32(&po->powbar, hose->regions[r].phys_start >> 12);
351 out_be32(&po->potar, start >> 12);
352 #ifdef CONFIG_SYS_PCI_64BIT
353 out_be32(&po->potear, start >> 44);
355 out_be32(&po->potear, 0);
357 if (hose->regions[r].flags & PCI_REGION_IO) {
358 out_be32(&po->powar, POWAR_EN | sz |
359 POWAR_IO_READ | POWAR_IO_WRITE);
361 out_be32(&po->powar, POWAR_EN | sz |
362 POWAR_MEM_READ | POWAR_MEM_WRITE);
363 out_lo = min(start, out_lo);
364 out_hi = max(end, out_hi);
369 debug("Outbound memory range: %llx:%llx\n", out_lo, out_hi);
371 /* setup PCSRBAR/PEXCSRBAR */
372 pci_hose_write_config_dword(hose, dev, PCI_BASE_ADDRESS_0, 0xffffffff);
373 pci_hose_read_config_dword (hose, dev, PCI_BASE_ADDRESS_0, &pcicsrbar_sz);
374 pcicsrbar_sz = ~pcicsrbar_sz + 1;
376 if (out_hi < (0x100000000ull - pcicsrbar_sz) ||
377 (out_lo > 0x100000000ull))
378 pcicsrbar = 0x100000000ull - pcicsrbar_sz;
380 pcicsrbar = (out_lo - pcicsrbar_sz) & -pcicsrbar_sz;
381 pci_hose_write_config_dword(hose, dev, PCI_BASE_ADDRESS_0, pcicsrbar);
383 out_lo = min(out_lo, (u64)pcicsrbar);
385 debug("PCICSRBAR @ 0x%x\n", pcicsrbar);
387 pci_set_region(reg++, pcicsrbar, CONFIG_SYS_CCSRBAR_PHYS,
388 pcicsrbar_sz, PCI_REGION_SYS_MEMORY);
389 hose->region_count++;
391 /* see if we are a PCIe or PCI controller */
392 pcie_cap_pos = pci_hose_find_capability(hose, dev, PCI_CAP_ID_EXP);
393 pci_dcr = pcie_cap_pos + 0x08;
394 pci_dsr = pcie_cap_pos + 0x0a;
395 pci_lsr = pcie_cap_pos + 0x12;
397 pci_hose_read_config_byte(hose, dev, pcie_cap_pos, &pcie_cap);
399 #ifdef CONFIG_SRIO_PCIE_BOOT_MASTER
400 /* boot from PCIE --master */
401 char *s = env_get("bootmaster");
403 sprintf(pcie, "PCIE%d", pci_info->pci_num);
405 if (s && (strcmp(s, pcie) == 0)) {
406 debug("PCIEBOOT - MASTER: Master port [ %d ] for pcie boot.\n",
408 fsl_pcie_boot_master((pit_t *)pi);
411 inbound = fsl_pci_setup_inbound_windows(hose,
412 out_lo, pcie_cap, pi);
416 inbound = fsl_pci_setup_inbound_windows(hose, out_lo, pcie_cap, pi);
419 for (r = 0; r < hose->region_count; r++)
420 debug("PCI reg:%d %016llx:%016llx %016llx %08lx\n", r,
421 (u64)hose->regions[r].phys_start,
422 (u64)hose->regions[r].bus_start,
423 (u64)hose->regions[r].size,
424 hose->regions[r].flags);
426 pci_register_hose(hose);
427 pciauto_config_init(hose); /* grab pci_{mem,prefetch,io} */
428 hose->current_busno = hose->first_busno;
430 out_be32(&pci->pedr, 0xffffffff); /* Clear any errors */
431 out_be32(&pci->peer, ~0x20140); /* Enable All Error Interrupts except
432 * - Master abort (pci)
433 * - Master PERR (pci)
436 pci_hose_read_config_dword(hose, dev, pci_dcr, &temp32);
437 temp32 |= 0xf000e; /* set URR, FER, NFER (but not CER) */
438 pci_hose_write_config_dword(hose, dev, pci_dcr, temp32);
440 #if defined(CONFIG_FSL_PCIE_DISABLE_ASPM)
441 pci_lcr = pcie_cap_pos + 0x10;
443 pci_hose_read_config_dword(hose, dev, pci_lcr, &temp32);
444 temp32 &= ~0x03; /* Disable ASPM */
445 pci_hose_write_config_dword(hose, dev, pci_lcr, temp32);
448 if (pcie_cap == PCI_CAP_ID_EXP) {
449 if (block_rev >= PEX_IP_BLK_REV_3_0) {
450 #define PEX_CSR0_LTSSM_MASK 0xFC
451 #define PEX_CSR0_LTSSM_SHIFT 2
452 ltssm = (in_be32(&pci->pex_csr0)
453 & PEX_CSR0_LTSSM_MASK) >> PEX_CSR0_LTSSM_SHIFT;
454 enabled = (ltssm == 0x11) ? 1 : 0;
455 #ifdef CONFIG_FSL_PCIE_RESET
457 /* assert PCIe reset */
458 setbits_be32(&pci->pdb_stat, 0x08000000);
459 (void) in_be32(&pci->pdb_stat);
461 /* clear PCIe reset */
462 clrbits_be32(&pci->pdb_stat, 0x08000000);
464 for (i = 0; i < 100 && ltssm < PCI_LTSSM_L0; i++) {
465 pci_hose_read_config_word(hose, dev, PCI_LTSSM,
471 /* pci_hose_read_config_word(hose, dev, PCI_LTSSM, <ssm); */
472 /* enabled = ltssm >= PCI_LTSSM_L0; */
473 pci_hose_read_config_word(hose, dev, PCI_LTSSM, <ssm);
474 enabled = ltssm >= PCI_LTSSM_L0;
476 #ifdef CONFIG_FSL_PCIE_RESET
479 debug("....PCIe link error. " "LTSSM=0x%02x.", ltssm);
480 /* assert PCIe reset */
481 setbits_be32(&pci->pdb_stat, 0x08000000);
482 (void) in_be32(&pci->pdb_stat);
484 debug(" Asserting PCIe reset @%p = %x\n",
485 &pci->pdb_stat, in_be32(&pci->pdb_stat));
486 /* clear PCIe reset */
487 clrbits_be32(&pci->pdb_stat, 0x08000000);
489 for (i=0; i<100 && ltssm < PCI_LTSSM_L0; i++) {
490 pci_hose_read_config_word(hose, dev, PCI_LTSSM,
493 debug("....PCIe link error. "
494 "LTSSM=0x%02x.\n", ltssm);
496 enabled = ltssm >= PCI_LTSSM_L0;
498 /* we need to re-write the bar0 since a reset will
501 pci_hose_write_config_dword(hose, dev,
502 PCI_BASE_ADDRESS_0, pcicsrbar);
507 #ifdef CONFIG_SYS_P4080_ERRATUM_PCIE_A003
509 serdes_corenet_t *srds_regs = (void *)CONFIG_SYS_FSL_CORENET_SERDES_ADDR;
510 temp32 = in_be32(&srds_regs->srdspccr0);
512 if ((temp32 >> 28) == 3) {
515 out_be32(&srds_regs->srdspccr0, 2 << 28);
516 setbits_be32(&pci->pdb_stat, 0x08000000);
517 in_be32(&pci->pdb_stat);
519 clrbits_be32(&pci->pdb_stat, 0x08000000);
521 for (i=0; i < 100 && ltssm < PCI_LTSSM_L0; i++) {
522 pci_hose_read_config_word(hose, dev, PCI_LTSSM, <ssm);
525 enabled = ltssm >= PCI_LTSSM_L0;
530 /* Let the user know there's no PCIe link for root
531 * complex. for endpoint, the link may not setup, so
532 * print undetermined.
534 if (fsl_is_pci_agent(hose))
535 printf("undetermined, regs @ 0x%lx\n", pci_info->regs);
537 printf("no link, regs @ 0x%lx\n", pci_info->regs);
538 hose->last_busno = hose->first_busno;
542 out_be32(&pci->pme_msg_det, 0xffffffff);
543 out_be32(&pci->pme_msg_int_en, 0xffffffff);
545 /* Print the negotiated PCIe link width */
546 pci_hose_read_config_word(hose, dev, pci_lsr, &temp16);
547 printf("x%d gen%d, regs @ 0x%lx\n", (temp16 & 0x3f0) >> 4,
548 (temp16 & 0xf), pci_info->regs);
550 hose->current_busno++; /* Start scan with secondary */
551 pciauto_prescan_setup_bridge(hose, dev, hose->current_busno);
554 #ifdef CONFIG_SYS_FSL_ERRATUM_A007815
555 /* The Read-Only Write Enable bit defaults to 1 instead of 0.
556 * Set to 0 to protect the read-only registers.
558 clrbits_be32(&pci->dbi_ro_wr_en, 0x01);
561 /* Use generic setup_device to initialize standard pci regs,
562 * but do not allocate any windows since any BAR found (such
563 * as PCSRBAR) is not in this cpu's memory space.
565 pciauto_setup_device(hose, dev, 0, hose->pci_mem,
566 hose->pci_prefetch, hose->pci_io);
569 pci_hose_read_config_word(hose, dev, PCI_COMMAND, &temp16);
570 pci_hose_write_config_word(hose, dev, PCI_COMMAND,
571 temp16 | PCI_COMMAND_MEMORY);
574 #ifndef CONFIG_PCI_NOSCAN
575 if (!fsl_is_pci_agent(hose)) {
576 debug(" Scanning PCI bus %02x\n",
577 hose->current_busno);
578 hose->last_busno = pci_hose_scan_bus(hose, hose->current_busno);
580 debug(" Not scanning PCI bus %02x. PI=%x\n",
581 hose->current_busno, temp8);
582 hose->last_busno = hose->current_busno;
585 /* if we are PCIe - update limit regs and subordinate busno
586 * for the virtual P2P bridge
588 if (pcie_cap == PCI_CAP_ID_EXP) {
589 pciauto_postscan_setup_bridge(hose, dev, hose->last_busno);
592 hose->last_busno = hose->current_busno;
595 /* Clear all error indications */
596 if (pcie_cap == PCI_CAP_ID_EXP)
597 out_be32(&pci->pme_msg_det, 0xffffffff);
598 out_be32(&pci->pedr, 0xffffffff);
600 pci_hose_read_config_word(hose, dev, pci_dsr, &temp16);
602 pci_hose_write_config_word(hose, dev, pci_dsr, 0xffff);
605 pci_hose_read_config_word (hose, dev, PCI_SEC_STATUS, &temp16);
607 pci_hose_write_config_word(hose, dev, PCI_SEC_STATUS, 0xffff);
611 int fsl_is_pci_agent(struct pci_controller *hose)
615 pci_dev_t dev = PCI_BDF(hose->first_busno, 0, 0);
617 pcie_cap_pos = pci_hose_find_capability(hose, dev, PCI_CAP_ID_EXP);
618 pci_hose_read_config_byte(hose, dev, pcie_cap_pos, &pcie_cap);
619 if (pcie_cap == PCI_CAP_ID_EXP) {
622 pci_hose_read_config_byte(hose, dev, PCI_HEADER_TYPE,
624 return (header_type & 0x7f) == PCI_HEADER_TYPE_NORMAL;
628 pci_hose_read_config_byte(hose, dev, PCI_CLASS_PROG, &prog_if);
629 /* Programming Interface (PCI_CLASS_PROG)
630 * 0 == pci host or pcie root-complex,
631 * 1 == pci agent or pcie end-point
633 return (prog_if == FSL_PROG_IF_AGENT);
637 int fsl_pci_init_port(struct fsl_pci_info *pci_info,
638 struct pci_controller *hose, int busno)
640 volatile ccsr_fsl_pci_t *pci;
641 struct pci_region *r;
642 pci_dev_t dev = PCI_BDF(busno,0,0);
646 pci = (ccsr_fsl_pci_t *) pci_info->regs;
648 /* on non-PCIe controllers we don't have pme_msg_det so this code
649 * should do nothing since the read will return 0
651 if (in_be32(&pci->pme_msg_det)) {
652 out_be32(&pci->pme_msg_det, 0xffffffff);
653 debug (" with errors. Clearing. Now 0x%08x",
657 r = hose->regions + hose->region_count;
659 /* outbound memory */
673 hose->region_count = r - hose->regions;
674 hose->first_busno = busno;
676 fsl_pci_init(hose, pci_info);
678 if (fsl_is_pci_agent(hose)) {
679 fsl_pci_config_unlock(hose);
680 hose->last_busno = hose->first_busno;
681 #ifdef CONFIG_SRIO_PCIE_BOOT_MASTER
683 /* boot from PCIE --master releases slave's core 0 */
684 char *s = env_get("bootmaster");
686 sprintf(pcie, "PCIE%d", pci_info->pci_num);
688 if (s && (strcmp(s, pcie) == 0))
689 fsl_pcie_boot_master_release_slave(pci_info->pci_num);
693 pcie_cap_pos = pci_hose_find_capability(hose, dev, PCI_CAP_ID_EXP);
694 pci_hose_read_config_byte(hose, dev, pcie_cap_pos, &pcie_cap);
695 printf("PCI%s%x: Bus %02x - %02x\n", pcie_cap == PCI_CAP_ID_EXP ?
696 "e" : "", pci_info->pci_num,
697 hose->first_busno, hose->last_busno);
698 return(hose->last_busno + 1);
701 /* Enable inbound PCI config cycles for agent/endpoint interface */
702 void fsl_pci_config_unlock(struct pci_controller *hose)
704 pci_dev_t dev = PCI_BDF(hose->first_busno,0,0);
709 if (!fsl_is_pci_agent(hose))
712 pcie_cap_pos = pci_hose_find_capability(hose, dev, PCI_CAP_ID_EXP);
713 pci_hose_read_config_byte(hose, dev, pcie_cap_pos, &pcie_cap);
714 if (pcie_cap != 0x0) {
715 ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *)hose->cfg_addr;
716 u32 block_rev = in_be32(&pci->block_rev1);
717 /* PCIe - set CFG_READY bit of Configuration Ready Register */
718 if (block_rev >= PEX_IP_BLK_REV_3_0)
719 setbits_be32(&pci->config, FSL_PCIE_V3_CFG_RDY);
721 pci_hose_write_config_byte(hose, dev,
722 FSL_PCIE_CFG_RDY, 0x1);
724 /* PCI - clear ACL bit of PBFR */
725 pci_hose_read_config_word(hose, dev, FSL_PCI_PBFR, &pbfr);
727 pci_hose_write_config_word(hose, dev, FSL_PCI_PBFR, pbfr);
731 #if defined(CONFIG_PCIE1) || defined(CONFIG_PCIE2) || \
732 defined(CONFIG_PCIE3) || defined(CONFIG_PCIE4)
733 int fsl_configure_pcie(struct fsl_pci_info *info,
734 struct pci_controller *hose,
735 const char *connected, int busno)
739 set_next_law(info->mem_phys, law_size_bits(info->mem_size), info->law);
740 set_next_law(info->io_phys, law_size_bits(info->io_size), info->law);
742 is_endpoint = fsl_setup_hose(hose, info->regs);
743 printf("PCIe%u: %s", info->pci_num,
744 is_endpoint ? "Endpoint" : "Root Complex");
746 printf(" of %s", connected);
749 return fsl_pci_init_port(info, hose, busno);
752 #if defined(CONFIG_FSL_CORENET)
753 #ifdef CONFIG_SYS_FSL_QORIQ_CHASSIS2
754 #define _DEVDISR_PCIE1 FSL_CORENET_DEVDISR3_PCIE1
755 #define _DEVDISR_PCIE2 FSL_CORENET_DEVDISR3_PCIE2
756 #define _DEVDISR_PCIE3 FSL_CORENET_DEVDISR3_PCIE3
757 #define _DEVDISR_PCIE4 FSL_CORENET_DEVDISR3_PCIE4
759 #define _DEVDISR_PCIE1 FSL_CORENET_DEVDISR_PCIE1
760 #define _DEVDISR_PCIE2 FSL_CORENET_DEVDISR_PCIE2
761 #define _DEVDISR_PCIE3 FSL_CORENET_DEVDISR_PCIE3
762 #define _DEVDISR_PCIE4 FSL_CORENET_DEVDISR_PCIE4
764 #define CONFIG_SYS_MPC8xxx_GUTS_ADDR CONFIG_SYS_MPC85xx_GUTS_ADDR
765 #elif defined(CONFIG_MPC85xx)
766 #define _DEVDISR_PCIE1 MPC85xx_DEVDISR_PCIE
767 #define _DEVDISR_PCIE2 MPC85xx_DEVDISR_PCIE2
768 #define _DEVDISR_PCIE3 MPC85xx_DEVDISR_PCIE3
769 #define _DEVDISR_PCIE4 0
770 #define CONFIG_SYS_MPC8xxx_GUTS_ADDR CONFIG_SYS_MPC85xx_GUTS_ADDR
771 #elif defined(CONFIG_MPC86xx)
772 #define _DEVDISR_PCIE1 MPC86xx_DEVDISR_PCIE1
773 #define _DEVDISR_PCIE2 MPC86xx_DEVDISR_PCIE2
774 #define _DEVDISR_PCIE3 0
775 #define _DEVDISR_PCIE4 0
776 #define CONFIG_SYS_MPC8xxx_GUTS_ADDR \
777 (&((immap_t *)CONFIG_SYS_IMMR)->im_gur)
779 #error "No defines for DEVDISR_PCIE"
782 /* Implement a dummy function for those platforms w/o SERDES */
783 static const char *__board_serdes_name(enum srds_prtcl device)
786 #ifdef CONFIG_SYS_PCIE1_NAME
788 return CONFIG_SYS_PCIE1_NAME;
790 #ifdef CONFIG_SYS_PCIE2_NAME
792 return CONFIG_SYS_PCIE2_NAME;
794 #ifdef CONFIG_SYS_PCIE3_NAME
796 return CONFIG_SYS_PCIE3_NAME;
798 #ifdef CONFIG_SYS_PCIE4_NAME
800 return CONFIG_SYS_PCIE4_NAME;
809 __attribute__((weak, alias("__board_serdes_name"))) const char *
810 board_serdes_name(enum srds_prtcl device);
812 static u32 devdisr_mask[] = {
819 int fsl_pcie_init_ctrl(int busno, u32 devdisr, enum srds_prtcl dev,
820 struct fsl_pci_info *pci_info)
822 struct pci_controller *hose;
823 int num = dev - PCIE1;
825 hose = calloc(1, sizeof(struct pci_controller));
829 if (is_serdes_configured(dev) && !(devdisr & devdisr_mask[num])) {
830 busno = fsl_configure_pcie(pci_info, hose,
831 board_serdes_name(dev), busno);
833 printf("PCIe%d: disabled\n", num + 1);
839 int fsl_pcie_init_board(int busno)
841 struct fsl_pci_info pci_info;
842 ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC8xxx_GUTS_ADDR;
846 #ifdef CONFIG_SYS_FSL_QORIQ_CHASSIS2
847 addr = &gur->devdisr3;
849 addr = &gur->devdisr;
851 devdisr = in_be32(addr);
854 SET_STD_PCIE_INFO(pci_info, 1);
855 busno = fsl_pcie_init_ctrl(busno, devdisr, PCIE1, &pci_info);
857 setbits_be32(addr, _DEVDISR_PCIE1); /* disable */
861 SET_STD_PCIE_INFO(pci_info, 2);
862 busno = fsl_pcie_init_ctrl(busno, devdisr, PCIE2, &pci_info);
864 setbits_be32(addr, _DEVDISR_PCIE2); /* disable */
868 SET_STD_PCIE_INFO(pci_info, 3);
869 busno = fsl_pcie_init_ctrl(busno, devdisr, PCIE3, &pci_info);
871 setbits_be32(addr, _DEVDISR_PCIE3); /* disable */
875 SET_STD_PCIE_INFO(pci_info, 4);
876 busno = fsl_pcie_init_ctrl(busno, devdisr, PCIE4, &pci_info);
878 setbits_be32(addr, _DEVDISR_PCIE4); /* disable */
884 int fsl_pcie_init_ctrl(int busno, u32 devdisr, enum srds_prtcl dev,
885 struct fsl_pci_info *pci_info)
890 int fsl_pcie_init_board(int busno)
896 #ifdef CONFIG_OF_BOARD_SETUP
897 #include <linux/libfdt.h>
898 #include <fdt_support.h>
900 void ft_fsl_pci_setup(void *blob, const char *pci_compat,
901 unsigned long ctrl_addr)
905 phys_addr_t p_ctrl_addr = (phys_addr_t)ctrl_addr;
906 struct pci_controller *hose;
908 hose = find_hose_by_cfg_addr((void *)(ctrl_addr));
910 /* convert ctrl_addr to true physical address */
911 p_ctrl_addr = (phys_addr_t)ctrl_addr - CONFIG_SYS_CCSRBAR;
912 p_ctrl_addr += CONFIG_SYS_CCSRBAR_PHYS;
914 off = fdt_node_offset_by_compat_reg(blob, pci_compat, p_ctrl_addr);
919 /* We assume a cfg_addr not being set means we didn't setup the controller */
920 if ((hose == NULL) || (hose->cfg_addr == NULL)) {
921 fdt_del_node(blob, off);
924 bus_range[1] = hose->last_busno - hose->first_busno;
925 fdt_setprop(blob, off, "bus-range", &bus_range[0], 2*4);
926 fdt_pci_dma_ranges(blob, off, hose);