2 * PCI / PCI-X / PCI-Express support for 4xx parts
4 * Copyright 2007 Ben. Herrenschmidt <benh@kernel.crashing.org>, IBM Corp.
6 * Most PCI Express code is coming from Stefan Roese implementation for
7 * arch/ppc in the Denx tree, slightly reworked by me.
9 * Copyright 2007 DENX Software Engineering, Stefan Roese <sr@denx.de>
11 * Some of that comes itself from a previous implementation for 440SPE only
14 * Copyright (c) 2005 Cisco Systems. All rights reserved.
15 * Roland Dreier <rolandd@cisco.com>
21 #include <linux/kernel.h>
22 #include <linux/pci.h>
23 #include <linux/init.h>
25 #include <linux/of_address.h>
26 #include <linux/delay.h>
27 #include <linux/slab.h>
30 #include <asm/pci-bridge.h>
31 #include <asm/machdep.h>
33 #include <asm/dcr-regs.h>
34 #include <mm/mmu_decl.h>
38 static int dma_offset_set;
40 #define U64_TO_U32_LOW(val) ((u32)((val) & 0x00000000ffffffffULL))
41 #define U64_TO_U32_HIGH(val) ((u32)((val) >> 32))
43 #define RES_TO_U32_LOW(val) \
44 ((sizeof(resource_size_t) > sizeof(u32)) ? U64_TO_U32_LOW(val) : (val))
45 #define RES_TO_U32_HIGH(val) \
46 ((sizeof(resource_size_t) > sizeof(u32)) ? U64_TO_U32_HIGH(val) : (0))
48 static inline int ppc440spe_revA(void)
50 /* Catch both 440SPe variants, with and without RAID6 support */
51 if ((mfspr(SPRN_PVR) & 0xffefffff) == 0x53421890)
57 static void fixup_ppc4xx_pci_bridge(struct pci_dev *dev)
59 struct pci_controller *hose;
62 if (dev->devfn != 0 || dev->bus->self != NULL)
65 hose = pci_bus_to_host(dev->bus);
69 if (!of_device_is_compatible(hose->dn, "ibm,plb-pciex") &&
70 !of_device_is_compatible(hose->dn, "ibm,plb-pcix") &&
71 !of_device_is_compatible(hose->dn, "ibm,plb-pci"))
74 if (of_device_is_compatible(hose->dn, "ibm,plb440epx-pci") ||
75 of_device_is_compatible(hose->dn, "ibm,plb440grx-pci")) {
76 hose->indirect_type |= PPC_INDIRECT_TYPE_BROKEN_MRM;
79 /* Hide the PCI host BARs from the kernel as their content doesn't
80 * fit well in the resource management
82 pci_dev_for_each_resource(dev, r) {
83 r->start = r->end = 0;
87 printk(KERN_INFO "PCI: Hiding 4xx host bridge resources %s\n",
90 DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, fixup_ppc4xx_pci_bridge);
92 static int __init ppc4xx_parse_dma_ranges(struct pci_controller *hose,
99 int pna = of_n_addr_cells(hose->dn);
106 res->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH;
108 /* Get dma-ranges property */
109 ranges = of_get_property(hose->dn, "dma-ranges", &rlen);
114 while ((rlen -= np * 4) >= 0) {
115 u32 pci_space = ranges[0];
116 u64 pci_addr = of_read_number(ranges + 1, 2);
117 u64 cpu_addr = of_translate_dma_address(hose->dn, ranges + 3);
118 size = of_read_number(ranges + pna + 3, 2);
120 if (cpu_addr == OF_BAD_ADDR || size == 0)
123 /* We only care about memory */
124 if ((pci_space & 0x03000000) != 0x02000000)
127 /* We currently only support memory at 0, and pci_addr
128 * within 32 bits space
130 if (cpu_addr != 0 || pci_addr > 0xffffffff) {
131 printk(KERN_WARNING "%pOF: Ignored unsupported dma range"
132 " 0x%016llx...0x%016llx -> 0x%016llx\n",
134 pci_addr, pci_addr + size - 1, cpu_addr);
138 /* Check if not prefetchable */
139 if (!(pci_space & 0x40000000))
140 res->flags &= ~IORESOURCE_PREFETCH;
144 res->start = pci_addr;
145 /* Beware of 32 bits resources */
146 if (sizeof(resource_size_t) == sizeof(u32) &&
147 (pci_addr + size) > 0x100000000ull)
148 res->end = 0xffffffff;
150 res->end = res->start + size - 1;
154 /* We only support one global DMA offset */
155 if (dma_offset_set && pci_dram_offset != res->start) {
156 printk(KERN_ERR "%pOF: dma-ranges(s) mismatch\n", hose->dn);
160 /* Check that we can fit all of memory as we don't support
163 if (size < total_memory) {
164 printk(KERN_ERR "%pOF: dma-ranges too small "
165 "(size=%llx total_memory=%llx)\n",
166 hose->dn, size, (u64)total_memory);
170 /* Check we are a power of 2 size and that base is a multiple of size*/
171 if ((size & (size - 1)) != 0 ||
172 (res->start & (size - 1)) != 0) {
173 printk(KERN_ERR "%pOF: dma-ranges unaligned\n", hose->dn);
177 /* Check that we are fully contained within 32 bits space if we are not
178 * running on a 460sx or 476fpe which have 64 bit bus addresses.
180 if (res->end > 0xffffffff &&
181 !(of_device_is_compatible(hose->dn, "ibm,plb-pciex-460sx")
182 || of_device_is_compatible(hose->dn, "ibm,plb-pciex-476fpe"))) {
183 printk(KERN_ERR "%pOF: dma-ranges outside of 32 bits space\n",
189 pci_dram_offset = res->start;
190 hose->dma_window_base_cur = res->start;
191 hose->dma_window_size = resource_size(res);
193 printk(KERN_INFO "4xx PCI DMA offset set to 0x%08lx\n",
195 printk(KERN_INFO "4xx PCI DMA window base to 0x%016llx\n",
196 (unsigned long long)hose->dma_window_base_cur);
197 printk(KERN_INFO "DMA window size 0x%016llx\n",
198 (unsigned long long)hose->dma_window_size);
206 static int __init ppc4xx_setup_one_pci_PMM(struct pci_controller *hose,
214 u32 ma, pcila, pciha;
216 /* Hack warning ! The "old" PCI 2.x cell only let us configure the low
217 * 32-bit of incoming PLB addresses. The top 4 bits of the 36-bit
218 * address are actually hard wired to a value that appears to depend
219 * on the specific SoC. For example, it's 0 on 440EP and 1 on 440EPx.
221 * The trick here is we just crop those top bits and ignore them when
222 * programming the chip. That means the device-tree has to be right
223 * for the specific part used (we don't print a warning if it's wrong
224 * but on the other hand, you'll crash quickly enough), but at least
225 * this code should work whatever the hard coded value is
227 plb_addr &= 0xffffffffull;
229 /* Note: Due to the above hack, the test below doesn't actually test
230 * if you address is above 4G, but it tests that address and
231 * (address + size) are both contained in the same 4G
233 if ((plb_addr + size) > 0xffffffffull || !is_power_of_2(size) ||
234 size < 0x1000 || (plb_addr & (size - 1)) != 0) {
235 printk(KERN_WARNING "%pOF: Resource out of range\n", hose->dn);
238 ma = (0xffffffffu << ilog2(size)) | 1;
239 if (flags & IORESOURCE_PREFETCH)
242 pciha = RES_TO_U32_HIGH(pci_addr);
243 pcila = RES_TO_U32_LOW(pci_addr);
245 writel(plb_addr, reg + PCIL0_PMM0LA + (0x10 * index));
246 writel(pcila, reg + PCIL0_PMM0PCILA + (0x10 * index));
247 writel(pciha, reg + PCIL0_PMM0PCIHA + (0x10 * index));
248 writel(ma, reg + PCIL0_PMM0MA + (0x10 * index));
253 static void __init ppc4xx_configure_pci_PMMs(struct pci_controller *hose,
256 int i, j, found_isa_hole = 0;
258 /* Setup outbound memory windows */
259 for (i = j = 0; i < 3; i++) {
260 struct resource *res = &hose->mem_resources[i];
261 resource_size_t offset = hose->mem_offset[i];
263 /* we only care about memory windows */
264 if (!(res->flags & IORESOURCE_MEM))
267 printk(KERN_WARNING "%pOF: Too many ranges\n", hose->dn);
271 /* Configure the resource */
272 if (ppc4xx_setup_one_pci_PMM(hose, reg,
280 /* If the resource PCI address is 0 then we have our
283 if (res->start == offset)
288 /* Handle ISA memory hole if not already covered */
289 if (j <= 2 && !found_isa_hole && hose->isa_mem_size)
290 if (ppc4xx_setup_one_pci_PMM(hose, reg, hose->isa_mem_phys, 0,
291 hose->isa_mem_size, 0, j) == 0)
292 printk(KERN_INFO "%pOF: Legacy ISA memory support enabled\n",
296 static void __init ppc4xx_configure_pci_PTMs(struct pci_controller *hose,
298 const struct resource *res)
300 resource_size_t size = resource_size(res);
303 /* Calculate window size */
304 sa = (0xffffffffu << ilog2(size)) | 1;
307 /* RAM is always at 0 local for now */
308 writel(0, reg + PCIL0_PTM1LA);
309 writel(sa, reg + PCIL0_PTM1MS);
311 /* Map on PCI side */
312 early_write_config_dword(hose, hose->first_busno, 0,
313 PCI_BASE_ADDRESS_1, res->start);
314 early_write_config_dword(hose, hose->first_busno, 0,
315 PCI_BASE_ADDRESS_2, 0x00000000);
316 early_write_config_word(hose, hose->first_busno, 0,
317 PCI_COMMAND, 0x0006);
320 static void __init ppc4xx_probe_pci_bridge(struct device_node *np)
323 struct resource rsrc_cfg;
324 struct resource rsrc_reg;
325 struct resource dma_window;
326 struct pci_controller *hose = NULL;
327 void __iomem *reg = NULL;
328 const int *bus_range;
331 /* Check if device is enabled */
332 if (!of_device_is_available(np)) {
333 printk(KERN_INFO "%pOF: Port disabled via device-tree\n", np);
337 /* Fetch config space registers address */
338 if (of_address_to_resource(np, 0, &rsrc_cfg)) {
339 printk(KERN_ERR "%pOF: Can't get PCI config register base !",
343 /* Fetch host bridge internal registers address */
344 if (of_address_to_resource(np, 3, &rsrc_reg)) {
345 printk(KERN_ERR "%pOF: Can't get PCI internal register base !",
350 /* Check if primary bridge */
351 if (of_property_read_bool(np, "primary"))
354 /* Get bus range if any */
355 bus_range = of_get_property(np, "bus-range", NULL);
358 reg = ioremap(rsrc_reg.start, resource_size(&rsrc_reg));
360 printk(KERN_ERR "%pOF: Can't map registers !", np);
364 /* Allocate the host controller data structure */
365 hose = pcibios_alloc_controller(np);
369 hose->first_busno = bus_range ? bus_range[0] : 0x0;
370 hose->last_busno = bus_range ? bus_range[1] : 0xff;
372 /* Setup config space */
373 setup_indirect_pci(hose, rsrc_cfg.start, rsrc_cfg.start + 0x4, 0);
375 /* Disable all windows */
376 writel(0, reg + PCIL0_PMM0MA);
377 writel(0, reg + PCIL0_PMM1MA);
378 writel(0, reg + PCIL0_PMM2MA);
379 writel(0, reg + PCIL0_PTM1MS);
380 writel(0, reg + PCIL0_PTM2MS);
382 /* Parse outbound mapping resources */
383 pci_process_bridge_OF_ranges(hose, np, primary);
385 /* Parse inbound mapping resources */
386 if (ppc4xx_parse_dma_ranges(hose, reg, &dma_window) != 0)
389 /* Configure outbound ranges POMs */
390 ppc4xx_configure_pci_PMMs(hose, reg);
392 /* Configure inbound ranges PIMs */
393 ppc4xx_configure_pci_PTMs(hose, reg, &dma_window);
395 /* We don't need the registers anymore */
401 pcibios_free_controller(hose);
410 static int __init ppc4xx_setup_one_pcix_POM(struct pci_controller *hose,
418 u32 lah, lal, pciah, pcial, sa;
420 if (!is_power_of_2(size) || size < 0x1000 ||
421 (plb_addr & (size - 1)) != 0) {
422 printk(KERN_WARNING "%pOF: Resource out of range\n",
427 /* Calculate register values */
428 lah = RES_TO_U32_HIGH(plb_addr);
429 lal = RES_TO_U32_LOW(plb_addr);
430 pciah = RES_TO_U32_HIGH(pci_addr);
431 pcial = RES_TO_U32_LOW(pci_addr);
432 sa = (0xffffffffu << ilog2(size)) | 0x1;
434 /* Program register values */
436 writel(lah, reg + PCIX0_POM0LAH);
437 writel(lal, reg + PCIX0_POM0LAL);
438 writel(pciah, reg + PCIX0_POM0PCIAH);
439 writel(pcial, reg + PCIX0_POM0PCIAL);
440 writel(sa, reg + PCIX0_POM0SA);
442 writel(lah, reg + PCIX0_POM1LAH);
443 writel(lal, reg + PCIX0_POM1LAL);
444 writel(pciah, reg + PCIX0_POM1PCIAH);
445 writel(pcial, reg + PCIX0_POM1PCIAL);
446 writel(sa, reg + PCIX0_POM1SA);
452 static void __init ppc4xx_configure_pcix_POMs(struct pci_controller *hose,
455 int i, j, found_isa_hole = 0;
457 /* Setup outbound memory windows */
458 for (i = j = 0; i < 3; i++) {
459 struct resource *res = &hose->mem_resources[i];
460 resource_size_t offset = hose->mem_offset[i];
462 /* we only care about memory windows */
463 if (!(res->flags & IORESOURCE_MEM))
466 printk(KERN_WARNING "%pOF: Too many ranges\n", hose->dn);
470 /* Configure the resource */
471 if (ppc4xx_setup_one_pcix_POM(hose, reg,
479 /* If the resource PCI address is 0 then we have our
482 if (res->start == offset)
487 /* Handle ISA memory hole if not already covered */
488 if (j <= 1 && !found_isa_hole && hose->isa_mem_size)
489 if (ppc4xx_setup_one_pcix_POM(hose, reg, hose->isa_mem_phys, 0,
490 hose->isa_mem_size, 0, j) == 0)
491 printk(KERN_INFO "%pOF: Legacy ISA memory support enabled\n",
495 static void __init ppc4xx_configure_pcix_PIMs(struct pci_controller *hose,
497 const struct resource *res,
501 resource_size_t size = resource_size(res);
504 /* RAM is always at 0 */
505 writel(0x00000000, reg + PCIX0_PIM0LAH);
506 writel(0x00000000, reg + PCIX0_PIM0LAL);
508 /* Calculate window size */
509 sa = (0xffffffffu << ilog2(size)) | 1;
511 if (res->flags & IORESOURCE_PREFETCH)
515 writel(sa, reg + PCIX0_PIM0SA);
517 writel(0xffffffff, reg + PCIX0_PIM0SAH);
519 /* Map on PCI side */
520 writel(0x00000000, reg + PCIX0_BAR0H);
521 writel(res->start, reg + PCIX0_BAR0L);
522 writew(0x0006, reg + PCIX0_COMMAND);
525 static void __init ppc4xx_probe_pcix_bridge(struct device_node *np)
527 struct resource rsrc_cfg;
528 struct resource rsrc_reg;
529 struct resource dma_window;
530 struct pci_controller *hose = NULL;
531 void __iomem *reg = NULL;
532 const int *bus_range;
533 int big_pim, msi, primary;
535 /* Fetch config space registers address */
536 if (of_address_to_resource(np, 0, &rsrc_cfg)) {
537 printk(KERN_ERR "%pOF: Can't get PCI-X config register base !",
541 /* Fetch host bridge internal registers address */
542 if (of_address_to_resource(np, 3, &rsrc_reg)) {
543 printk(KERN_ERR "%pOF: Can't get PCI-X internal register base !",
548 /* Check if it supports large PIMs (440GX) */
549 big_pim = of_property_read_bool(np, "large-inbound-windows");
551 /* Check if we should enable MSIs inbound hole */
552 msi = of_property_read_bool(np, "enable-msi-hole");
554 /* Check if primary bridge */
555 primary = of_property_read_bool(np, "primary");
557 /* Get bus range if any */
558 bus_range = of_get_property(np, "bus-range", NULL);
561 reg = ioremap(rsrc_reg.start, resource_size(&rsrc_reg));
563 printk(KERN_ERR "%pOF: Can't map registers !", np);
567 /* Allocate the host controller data structure */
568 hose = pcibios_alloc_controller(np);
572 hose->first_busno = bus_range ? bus_range[0] : 0x0;
573 hose->last_busno = bus_range ? bus_range[1] : 0xff;
575 /* Setup config space */
576 setup_indirect_pci(hose, rsrc_cfg.start, rsrc_cfg.start + 0x4,
577 PPC_INDIRECT_TYPE_SET_CFG_TYPE);
579 /* Disable all windows */
580 writel(0, reg + PCIX0_POM0SA);
581 writel(0, reg + PCIX0_POM1SA);
582 writel(0, reg + PCIX0_POM2SA);
583 writel(0, reg + PCIX0_PIM0SA);
584 writel(0, reg + PCIX0_PIM1SA);
585 writel(0, reg + PCIX0_PIM2SA);
587 writel(0, reg + PCIX0_PIM0SAH);
588 writel(0, reg + PCIX0_PIM2SAH);
591 /* Parse outbound mapping resources */
592 pci_process_bridge_OF_ranges(hose, np, primary);
594 /* Parse inbound mapping resources */
595 if (ppc4xx_parse_dma_ranges(hose, reg, &dma_window) != 0)
598 /* Configure outbound ranges POMs */
599 ppc4xx_configure_pcix_POMs(hose, reg);
601 /* Configure inbound ranges PIMs */
602 ppc4xx_configure_pcix_PIMs(hose, reg, &dma_window, big_pim, msi);
604 /* We don't need the registers anymore */
610 pcibios_free_controller(hose);
615 #ifdef CONFIG_PPC4xx_PCI_EXPRESS
618 * 4xx PCI-Express part
620 * We support 3 parts currently based on the compatible property:
622 * ibm,plb-pciex-440spe
623 * ibm,plb-pciex-405ex
624 * ibm,plb-pciex-460ex
626 * Anything else will be rejected for now as they are all subtly
627 * different unfortunately.
631 #define MAX_PCIE_BUS_MAPPED 0x40
633 struct ppc4xx_pciex_port
635 struct pci_controller *hose;
636 struct device_node *node;
641 unsigned int sdr_base;
643 struct resource cfg_space;
644 struct resource utl_regs;
645 void __iomem *utl_base;
648 static struct ppc4xx_pciex_port *ppc4xx_pciex_ports;
649 static unsigned int ppc4xx_pciex_port_count;
651 struct ppc4xx_pciex_hwops
654 int (*core_init)(struct device_node *np);
655 int (*port_init_hw)(struct ppc4xx_pciex_port *port);
656 int (*setup_utl)(struct ppc4xx_pciex_port *port);
657 void (*check_link)(struct ppc4xx_pciex_port *port);
660 static struct ppc4xx_pciex_hwops *ppc4xx_pciex_hwops;
662 static int __init ppc4xx_pciex_wait_on_sdr(struct ppc4xx_pciex_port *port,
663 unsigned int sdr_offset,
670 while(timeout_ms--) {
671 val = mfdcri(SDR0, port->sdr_base + sdr_offset);
672 if ((val & mask) == value) {
673 pr_debug("PCIE%d: Wait on SDR %x success with tm %d (%08x)\n",
674 port->index, sdr_offset, timeout_ms, val);
682 static int __init ppc4xx_pciex_port_reset_sdr(struct ppc4xx_pciex_port *port)
684 /* Wait for reset to complete */
685 if (ppc4xx_pciex_wait_on_sdr(port, PESDRn_RCSSTS, 1 << 20, 0, 10)) {
686 printk(KERN_WARNING "PCIE%d: PGRST failed\n",
694 static void __init ppc4xx_pciex_check_link_sdr(struct ppc4xx_pciex_port *port)
696 printk(KERN_INFO "PCIE%d: Checking link...\n", port->index);
698 /* Check for card presence detect if supported, if not, just wait for
699 * link unconditionally.
701 * note that we don't fail if there is no link, we just filter out
702 * config space accesses. That way, it will be easier to implement
705 if (!port->has_ibpre ||
706 !ppc4xx_pciex_wait_on_sdr(port, PESDRn_LOOP,
707 1 << 28, 1 << 28, 100)) {
709 "PCIE%d: Device detected, waiting for link...\n",
711 if (ppc4xx_pciex_wait_on_sdr(port, PESDRn_LOOP,
712 0x1000, 0x1000, 2000))
714 "PCIE%d: Link up failed\n", port->index);
717 "PCIE%d: link is up !\n", port->index);
721 printk(KERN_INFO "PCIE%d: No device detected.\n", port->index);
726 /* Check various reset bits of the 440SPe PCIe core */
727 static int __init ppc440spe_pciex_check_reset(struct device_node *np)
729 u32 valPE0, valPE1, valPE2;
732 /* SDR0_PEGPLLLCT1 reset */
733 if (!(mfdcri(SDR0, PESDR0_PLLLCT1) & 0x01000000)) {
735 * the PCIe core was probably already initialised
736 * by firmware - let's re-reset RCSSET regs
738 * -- Shouldn't we also re-reset the whole thing ? -- BenH
740 pr_debug("PCIE: SDR0_PLLLCT1 already reset.\n");
741 mtdcri(SDR0, PESDR0_440SPE_RCSSET, 0x01010000);
742 mtdcri(SDR0, PESDR1_440SPE_RCSSET, 0x01010000);
743 mtdcri(SDR0, PESDR2_440SPE_RCSSET, 0x01010000);
746 valPE0 = mfdcri(SDR0, PESDR0_440SPE_RCSSET);
747 valPE1 = mfdcri(SDR0, PESDR1_440SPE_RCSSET);
748 valPE2 = mfdcri(SDR0, PESDR2_440SPE_RCSSET);
750 /* SDR0_PExRCSSET rstgu */
751 if (!(valPE0 & 0x01000000) ||
752 !(valPE1 & 0x01000000) ||
753 !(valPE2 & 0x01000000)) {
754 printk(KERN_INFO "PCIE: SDR0_PExRCSSET rstgu error\n");
758 /* SDR0_PExRCSSET rstdl */
759 if (!(valPE0 & 0x00010000) ||
760 !(valPE1 & 0x00010000) ||
761 !(valPE2 & 0x00010000)) {
762 printk(KERN_INFO "PCIE: SDR0_PExRCSSET rstdl error\n");
766 /* SDR0_PExRCSSET rstpyn */
767 if ((valPE0 & 0x00001000) ||
768 (valPE1 & 0x00001000) ||
769 (valPE2 & 0x00001000)) {
770 printk(KERN_INFO "PCIE: SDR0_PExRCSSET rstpyn error\n");
774 /* SDR0_PExRCSSET hldplb */
775 if ((valPE0 & 0x10000000) ||
776 (valPE1 & 0x10000000) ||
777 (valPE2 & 0x10000000)) {
778 printk(KERN_INFO "PCIE: SDR0_PExRCSSET hldplb error\n");
782 /* SDR0_PExRCSSET rdy */
783 if ((valPE0 & 0x00100000) ||
784 (valPE1 & 0x00100000) ||
785 (valPE2 & 0x00100000)) {
786 printk(KERN_INFO "PCIE: SDR0_PExRCSSET rdy error\n");
790 /* SDR0_PExRCSSET shutdown */
791 if ((valPE0 & 0x00000100) ||
792 (valPE1 & 0x00000100) ||
793 (valPE2 & 0x00000100)) {
794 printk(KERN_INFO "PCIE: SDR0_PExRCSSET shutdown error\n");
801 /* Global PCIe core initializations for 440SPe core */
802 static int __init ppc440spe_pciex_core_init(struct device_node *np)
806 /* Set PLL clock receiver to LVPECL */
807 dcri_clrset(SDR0, PESDR0_PLLLCT1, 0, 1 << 28);
809 /* Shouldn't we do all the calibration stuff etc... here ? */
810 if (ppc440spe_pciex_check_reset(np))
813 if (!(mfdcri(SDR0, PESDR0_PLLLCT2) & 0x10000)) {
814 printk(KERN_INFO "PCIE: PESDR_PLLCT2 resistance calibration "
816 mfdcri(SDR0, PESDR0_PLLLCT2));
820 /* De-assert reset of PCIe PLL, wait for lock */
821 dcri_clrset(SDR0, PESDR0_PLLLCT1, 1 << 24, 0);
825 if (!(mfdcri(SDR0, PESDR0_PLLLCT3) & 0x10000000)) {
832 printk(KERN_INFO "PCIE: VCO output not locked\n");
836 pr_debug("PCIE initialization OK\n");
841 static int __init ppc440spe_pciex_init_port_hw(struct ppc4xx_pciex_port *port)
846 val = PTYPE_LEGACY_ENDPOINT << 20;
848 val = PTYPE_ROOT_PORT << 20;
850 if (port->index == 0)
851 val |= LNKW_X8 << 12;
853 val |= LNKW_X4 << 12;
855 mtdcri(SDR0, port->sdr_base + PESDRn_DLPSET, val);
856 mtdcri(SDR0, port->sdr_base + PESDRn_UTLSET1, 0x20222222);
857 if (ppc440spe_revA())
858 mtdcri(SDR0, port->sdr_base + PESDRn_UTLSET2, 0x11000000);
859 mtdcri(SDR0, port->sdr_base + PESDRn_440SPE_HSSL0SET1, 0x35000000);
860 mtdcri(SDR0, port->sdr_base + PESDRn_440SPE_HSSL1SET1, 0x35000000);
861 mtdcri(SDR0, port->sdr_base + PESDRn_440SPE_HSSL2SET1, 0x35000000);
862 mtdcri(SDR0, port->sdr_base + PESDRn_440SPE_HSSL3SET1, 0x35000000);
863 if (port->index == 0) {
864 mtdcri(SDR0, port->sdr_base + PESDRn_440SPE_HSSL4SET1,
866 mtdcri(SDR0, port->sdr_base + PESDRn_440SPE_HSSL5SET1,
868 mtdcri(SDR0, port->sdr_base + PESDRn_440SPE_HSSL6SET1,
870 mtdcri(SDR0, port->sdr_base + PESDRn_440SPE_HSSL7SET1,
873 dcri_clrset(SDR0, port->sdr_base + PESDRn_RCSSET,
874 (1 << 24) | (1 << 16), 1 << 12);
876 return ppc4xx_pciex_port_reset_sdr(port);
879 static int __init ppc440speA_pciex_init_port_hw(struct ppc4xx_pciex_port *port)
881 return ppc440spe_pciex_init_port_hw(port);
884 static int __init ppc440speB_pciex_init_port_hw(struct ppc4xx_pciex_port *port)
886 int rc = ppc440spe_pciex_init_port_hw(port);
893 static int ppc440speA_pciex_init_utl(struct ppc4xx_pciex_port *port)
895 /* XXX Check what that value means... I hate magic */
896 dcr_write(port->dcrs, DCRO_PEGPL_SPECIAL, 0x68782800);
899 * Set buffer allocations and then assert VRB and TXE.
901 out_be32(port->utl_base + PEUTL_OUTTR, 0x08000000);
902 out_be32(port->utl_base + PEUTL_INTR, 0x02000000);
903 out_be32(port->utl_base + PEUTL_OPDBSZ, 0x10000000);
904 out_be32(port->utl_base + PEUTL_PBBSZ, 0x53000000);
905 out_be32(port->utl_base + PEUTL_IPHBSZ, 0x08000000);
906 out_be32(port->utl_base + PEUTL_IPDBSZ, 0x10000000);
907 out_be32(port->utl_base + PEUTL_RCIRQEN, 0x00f00000);
908 out_be32(port->utl_base + PEUTL_PCTL, 0x80800066);
913 static int ppc440speB_pciex_init_utl(struct ppc4xx_pciex_port *port)
915 /* Report CRS to the operating system */
916 out_be32(port->utl_base + PEUTL_PBCTL, 0x08000000);
921 static struct ppc4xx_pciex_hwops ppc440speA_pcie_hwops __initdata =
924 .core_init = ppc440spe_pciex_core_init,
925 .port_init_hw = ppc440speA_pciex_init_port_hw,
926 .setup_utl = ppc440speA_pciex_init_utl,
927 .check_link = ppc4xx_pciex_check_link_sdr,
930 static struct ppc4xx_pciex_hwops ppc440speB_pcie_hwops __initdata =
933 .core_init = ppc440spe_pciex_core_init,
934 .port_init_hw = ppc440speB_pciex_init_port_hw,
935 .setup_utl = ppc440speB_pciex_init_utl,
936 .check_link = ppc4xx_pciex_check_link_sdr,
939 static int __init ppc460ex_pciex_core_init(struct device_node *np)
941 /* Nothing to do, return 2 ports */
945 static int __init ppc460ex_pciex_init_port_hw(struct ppc4xx_pciex_port *port)
951 val = PTYPE_LEGACY_ENDPOINT << 20;
953 val = PTYPE_ROOT_PORT << 20;
955 if (port->index == 0) {
956 val |= LNKW_X1 << 12;
957 utlset1 = 0x20000000;
959 val |= LNKW_X4 << 12;
960 utlset1 = 0x20101101;
963 mtdcri(SDR0, port->sdr_base + PESDRn_DLPSET, val);
964 mtdcri(SDR0, port->sdr_base + PESDRn_UTLSET1, utlset1);
965 mtdcri(SDR0, port->sdr_base + PESDRn_UTLSET2, 0x01210000);
967 switch (port->index) {
969 mtdcri(SDR0, PESDR0_460EX_L0CDRCTL, 0x00003230);
970 mtdcri(SDR0, PESDR0_460EX_L0DRV, 0x00000130);
971 mtdcri(SDR0, PESDR0_460EX_L0CLK, 0x00000006);
973 mtdcri(SDR0, PESDR0_460EX_PHY_CTL_RST,0x10000000);
977 mtdcri(SDR0, PESDR1_460EX_L0CDRCTL, 0x00003230);
978 mtdcri(SDR0, PESDR1_460EX_L1CDRCTL, 0x00003230);
979 mtdcri(SDR0, PESDR1_460EX_L2CDRCTL, 0x00003230);
980 mtdcri(SDR0, PESDR1_460EX_L3CDRCTL, 0x00003230);
981 mtdcri(SDR0, PESDR1_460EX_L0DRV, 0x00000130);
982 mtdcri(SDR0, PESDR1_460EX_L1DRV, 0x00000130);
983 mtdcri(SDR0, PESDR1_460EX_L2DRV, 0x00000130);
984 mtdcri(SDR0, PESDR1_460EX_L3DRV, 0x00000130);
985 mtdcri(SDR0, PESDR1_460EX_L0CLK, 0x00000006);
986 mtdcri(SDR0, PESDR1_460EX_L1CLK, 0x00000006);
987 mtdcri(SDR0, PESDR1_460EX_L2CLK, 0x00000006);
988 mtdcri(SDR0, PESDR1_460EX_L3CLK, 0x00000006);
990 mtdcri(SDR0, PESDR1_460EX_PHY_CTL_RST,0x10000000);
994 mtdcri(SDR0, port->sdr_base + PESDRn_RCSSET,
995 mfdcri(SDR0, port->sdr_base + PESDRn_RCSSET) |
996 (PESDRx_RCSSET_RSTGU | PESDRx_RCSSET_RSTPYN));
998 /* Poll for PHY reset */
999 /* XXX FIXME add timeout */
1000 switch (port->index) {
1002 while (!(mfdcri(SDR0, PESDR0_460EX_RSTSTA) & 0x1))
1006 while (!(mfdcri(SDR0, PESDR1_460EX_RSTSTA) & 0x1))
1011 mtdcri(SDR0, port->sdr_base + PESDRn_RCSSET,
1012 (mfdcri(SDR0, port->sdr_base + PESDRn_RCSSET) &
1013 ~(PESDRx_RCSSET_RSTGU | PESDRx_RCSSET_RSTDL)) |
1014 PESDRx_RCSSET_RSTPYN);
1016 port->has_ibpre = 1;
1018 return ppc4xx_pciex_port_reset_sdr(port);
1021 static int ppc460ex_pciex_init_utl(struct ppc4xx_pciex_port *port)
1023 dcr_write(port->dcrs, DCRO_PEGPL_SPECIAL, 0x0);
1026 * Set buffer allocations and then assert VRB and TXE.
1028 out_be32(port->utl_base + PEUTL_PBCTL, 0x0800000c);
1029 out_be32(port->utl_base + PEUTL_OUTTR, 0x08000000);
1030 out_be32(port->utl_base + PEUTL_INTR, 0x02000000);
1031 out_be32(port->utl_base + PEUTL_OPDBSZ, 0x04000000);
1032 out_be32(port->utl_base + PEUTL_PBBSZ, 0x00000000);
1033 out_be32(port->utl_base + PEUTL_IPHBSZ, 0x02000000);
1034 out_be32(port->utl_base + PEUTL_IPDBSZ, 0x04000000);
1035 out_be32(port->utl_base + PEUTL_RCIRQEN,0x00f00000);
1036 out_be32(port->utl_base + PEUTL_PCTL, 0x80800066);
1041 static struct ppc4xx_pciex_hwops ppc460ex_pcie_hwops __initdata =
1044 .core_init = ppc460ex_pciex_core_init,
1045 .port_init_hw = ppc460ex_pciex_init_port_hw,
1046 .setup_utl = ppc460ex_pciex_init_utl,
1047 .check_link = ppc4xx_pciex_check_link_sdr,
1050 static int __init apm821xx_pciex_core_init(struct device_node *np)
1052 /* Return the number of pcie port */
1056 static int __init apm821xx_pciex_init_port_hw(struct ppc4xx_pciex_port *port)
1061 * Do a software reset on PCIe ports.
1062 * This code is to fix the issue that pci drivers doesn't re-assign
1063 * bus number for PCIE devices after Uboot
1064 * scanned and configured all the buses (eg. PCIE NIC IntelPro/1000
1065 * PT quad port, SAS LSI 1064E)
1068 mtdcri(SDR0, PESDR0_460EX_PHY_CTL_RST, 0x0);
1072 val = PTYPE_LEGACY_ENDPOINT << 20;
1074 val = PTYPE_ROOT_PORT << 20;
1076 val |= LNKW_X1 << 12;
1078 mtdcri(SDR0, port->sdr_base + PESDRn_DLPSET, val);
1079 mtdcri(SDR0, port->sdr_base + PESDRn_UTLSET1, 0x00000000);
1080 mtdcri(SDR0, port->sdr_base + PESDRn_UTLSET2, 0x01010000);
1082 mtdcri(SDR0, PESDR0_460EX_L0CDRCTL, 0x00003230);
1083 mtdcri(SDR0, PESDR0_460EX_L0DRV, 0x00000130);
1084 mtdcri(SDR0, PESDR0_460EX_L0CLK, 0x00000006);
1086 mtdcri(SDR0, PESDR0_460EX_PHY_CTL_RST, 0x10000000);
1088 mtdcri(SDR0, PESDR0_460EX_PHY_CTL_RST, 0x30000000);
1090 mtdcri(SDR0, port->sdr_base + PESDRn_RCSSET,
1091 mfdcri(SDR0, port->sdr_base + PESDRn_RCSSET) |
1092 (PESDRx_RCSSET_RSTGU | PESDRx_RCSSET_RSTPYN));
1094 /* Poll for PHY reset */
1095 val = PESDR0_460EX_RSTSTA - port->sdr_base;
1096 if (ppc4xx_pciex_wait_on_sdr(port, val, 0x1, 1, 100)) {
1097 printk(KERN_WARNING "%s: PCIE: Can't reset PHY\n", __func__);
1100 mtdcri(SDR0, port->sdr_base + PESDRn_RCSSET,
1101 (mfdcri(SDR0, port->sdr_base + PESDRn_RCSSET) &
1102 ~(PESDRx_RCSSET_RSTGU | PESDRx_RCSSET_RSTDL)) |
1103 PESDRx_RCSSET_RSTPYN);
1105 port->has_ibpre = 1;
1110 static struct ppc4xx_pciex_hwops apm821xx_pcie_hwops __initdata = {
1112 .core_init = apm821xx_pciex_core_init,
1113 .port_init_hw = apm821xx_pciex_init_port_hw,
1114 .setup_utl = ppc460ex_pciex_init_utl,
1115 .check_link = ppc4xx_pciex_check_link_sdr,
1118 static int __init ppc460sx_pciex_core_init(struct device_node *np)
1120 /* HSS drive amplitude */
1121 mtdcri(SDR0, PESDR0_460SX_HSSL0DAMP, 0xB9843211);
1122 mtdcri(SDR0, PESDR0_460SX_HSSL1DAMP, 0xB9843211);
1123 mtdcri(SDR0, PESDR0_460SX_HSSL2DAMP, 0xB9843211);
1124 mtdcri(SDR0, PESDR0_460SX_HSSL3DAMP, 0xB9843211);
1125 mtdcri(SDR0, PESDR0_460SX_HSSL4DAMP, 0xB9843211);
1126 mtdcri(SDR0, PESDR0_460SX_HSSL5DAMP, 0xB9843211);
1127 mtdcri(SDR0, PESDR0_460SX_HSSL6DAMP, 0xB9843211);
1128 mtdcri(SDR0, PESDR0_460SX_HSSL7DAMP, 0xB9843211);
1130 mtdcri(SDR0, PESDR1_460SX_HSSL0DAMP, 0xB9843211);
1131 mtdcri(SDR0, PESDR1_460SX_HSSL1DAMP, 0xB9843211);
1132 mtdcri(SDR0, PESDR1_460SX_HSSL2DAMP, 0xB9843211);
1133 mtdcri(SDR0, PESDR1_460SX_HSSL3DAMP, 0xB9843211);
1135 mtdcri(SDR0, PESDR2_460SX_HSSL0DAMP, 0xB9843211);
1136 mtdcri(SDR0, PESDR2_460SX_HSSL1DAMP, 0xB9843211);
1137 mtdcri(SDR0, PESDR2_460SX_HSSL2DAMP, 0xB9843211);
1138 mtdcri(SDR0, PESDR2_460SX_HSSL3DAMP, 0xB9843211);
1140 /* HSS TX pre-emphasis */
1141 mtdcri(SDR0, PESDR0_460SX_HSSL0COEFA, 0xDCB98987);
1142 mtdcri(SDR0, PESDR0_460SX_HSSL1COEFA, 0xDCB98987);
1143 mtdcri(SDR0, PESDR0_460SX_HSSL2COEFA, 0xDCB98987);
1144 mtdcri(SDR0, PESDR0_460SX_HSSL3COEFA, 0xDCB98987);
1145 mtdcri(SDR0, PESDR0_460SX_HSSL4COEFA, 0xDCB98987);
1146 mtdcri(SDR0, PESDR0_460SX_HSSL5COEFA, 0xDCB98987);
1147 mtdcri(SDR0, PESDR0_460SX_HSSL6COEFA, 0xDCB98987);
1148 mtdcri(SDR0, PESDR0_460SX_HSSL7COEFA, 0xDCB98987);
1150 mtdcri(SDR0, PESDR1_460SX_HSSL0COEFA, 0xDCB98987);
1151 mtdcri(SDR0, PESDR1_460SX_HSSL1COEFA, 0xDCB98987);
1152 mtdcri(SDR0, PESDR1_460SX_HSSL2COEFA, 0xDCB98987);
1153 mtdcri(SDR0, PESDR1_460SX_HSSL3COEFA, 0xDCB98987);
1155 mtdcri(SDR0, PESDR2_460SX_HSSL0COEFA, 0xDCB98987);
1156 mtdcri(SDR0, PESDR2_460SX_HSSL1COEFA, 0xDCB98987);
1157 mtdcri(SDR0, PESDR2_460SX_HSSL2COEFA, 0xDCB98987);
1158 mtdcri(SDR0, PESDR2_460SX_HSSL3COEFA, 0xDCB98987);
1160 /* HSS TX calibration control */
1161 mtdcri(SDR0, PESDR0_460SX_HSSL1CALDRV, 0x22222222);
1162 mtdcri(SDR0, PESDR1_460SX_HSSL1CALDRV, 0x22220000);
1163 mtdcri(SDR0, PESDR2_460SX_HSSL1CALDRV, 0x22220000);
1165 /* HSS TX slew control */
1166 mtdcri(SDR0, PESDR0_460SX_HSSSLEW, 0xFFFFFFFF);
1167 mtdcri(SDR0, PESDR1_460SX_HSSSLEW, 0xFFFF0000);
1168 mtdcri(SDR0, PESDR2_460SX_HSSSLEW, 0xFFFF0000);
1170 /* Set HSS PRBS enabled */
1171 mtdcri(SDR0, PESDR0_460SX_HSSCTLSET, 0x00001130);
1172 mtdcri(SDR0, PESDR2_460SX_HSSCTLSET, 0x00001130);
1176 /* De-assert PLLRESET */
1177 dcri_clrset(SDR0, PESDR0_PLLLCT2, 0x00000100, 0);
1179 /* Reset DL, UTL, GPL before configuration */
1180 mtdcri(SDR0, PESDR0_460SX_RCSSET,
1181 PESDRx_RCSSET_RSTDL | PESDRx_RCSSET_RSTGU);
1182 mtdcri(SDR0, PESDR1_460SX_RCSSET,
1183 PESDRx_RCSSET_RSTDL | PESDRx_RCSSET_RSTGU);
1184 mtdcri(SDR0, PESDR2_460SX_RCSSET,
1185 PESDRx_RCSSET_RSTDL | PESDRx_RCSSET_RSTGU);
1190 * If bifurcation is not enabled, u-boot would have disabled the
1193 if (((mfdcri(SDR0, PESDR1_460SX_HSSCTLSET) & 0x00000001) ==
1195 printk(KERN_INFO "PCI: PCIE bifurcation setup successfully.\n");
1196 printk(KERN_INFO "PCI: Total 3 PCIE ports are present\n");
1200 printk(KERN_INFO "PCI: Total 2 PCIE ports are present\n");
1204 static int __init ppc460sx_pciex_init_port_hw(struct ppc4xx_pciex_port *port)
1208 dcri_clrset(SDR0, port->sdr_base + PESDRn_UTLSET2,
1211 dcri_clrset(SDR0, port->sdr_base + PESDRn_UTLSET2,
1214 dcri_clrset(SDR0, port->sdr_base + PESDRn_RCSSET,
1215 (PESDRx_RCSSET_RSTGU | PESDRx_RCSSET_RSTDL),
1216 PESDRx_RCSSET_RSTPYN);
1218 port->has_ibpre = 1;
1220 return ppc4xx_pciex_port_reset_sdr(port);
1223 static int ppc460sx_pciex_init_utl(struct ppc4xx_pciex_port *port)
1226 out_be32 (port->utl_base + PEUTL_PBBSZ, 0x00000000);
1227 /* Assert VRB and TXE - per datasheet turn off addr validation */
1228 out_be32(port->utl_base + PEUTL_PCTL, 0x80800000);
1232 static void __init ppc460sx_pciex_check_link(struct ppc4xx_pciex_port *port)
1234 void __iomem *mbase;
1239 mbase = ioremap(port->cfg_space.start + 0x10000000, 0x1000);
1240 if (mbase == NULL) {
1241 printk(KERN_ERR "%pOF: Can't map internal config space !",
1246 while (attempt && (0 == (in_le32(mbase + PECFG_460SX_DLLSTA)
1247 & PECFG_460SX_DLLSTA_LINKUP))) {
1256 static struct ppc4xx_pciex_hwops ppc460sx_pcie_hwops __initdata = {
1258 .core_init = ppc460sx_pciex_core_init,
1259 .port_init_hw = ppc460sx_pciex_init_port_hw,
1260 .setup_utl = ppc460sx_pciex_init_utl,
1261 .check_link = ppc460sx_pciex_check_link,
1264 #endif /* CONFIG_44x */
1268 static int __init ppc405ex_pciex_core_init(struct device_node *np)
1270 /* Nothing to do, return 2 ports */
1274 static void __init ppc405ex_pcie_phy_reset(struct ppc4xx_pciex_port *port)
1276 /* Assert the PE0_PHY reset */
1277 mtdcri(SDR0, port->sdr_base + PESDRn_RCSSET, 0x01010000);
1280 /* deassert the PE0_hotreset */
1282 mtdcri(SDR0, port->sdr_base + PESDRn_RCSSET, 0x01111000);
1284 mtdcri(SDR0, port->sdr_base + PESDRn_RCSSET, 0x01101000);
1286 /* poll for phy !reset */
1287 /* XXX FIXME add timeout */
1288 while (!(mfdcri(SDR0, port->sdr_base + PESDRn_405EX_PHYSTA) & 0x00001000))
1291 /* deassert the PE0_gpl_utl_reset */
1292 mtdcri(SDR0, port->sdr_base + PESDRn_RCSSET, 0x00101000);
1295 static int __init ppc405ex_pciex_init_port_hw(struct ppc4xx_pciex_port *port)
1300 val = PTYPE_LEGACY_ENDPOINT;
1302 val = PTYPE_ROOT_PORT;
1304 mtdcri(SDR0, port->sdr_base + PESDRn_DLPSET,
1305 1 << 24 | val << 20 | LNKW_X1 << 12);
1307 mtdcri(SDR0, port->sdr_base + PESDRn_UTLSET1, 0x00000000);
1308 mtdcri(SDR0, port->sdr_base + PESDRn_UTLSET2, 0x01010000);
1309 mtdcri(SDR0, port->sdr_base + PESDRn_405EX_PHYSET1, 0x720F0000);
1310 mtdcri(SDR0, port->sdr_base + PESDRn_405EX_PHYSET2, 0x70600003);
1313 * Only reset the PHY when no link is currently established.
1314 * This is for the Atheros PCIe board which has problems to establish
1315 * the link (again) after this PHY reset. All other currently tested
1316 * PCIe boards don't show this problem.
1317 * This has to be re-tested and fixed in a later release!
1319 val = mfdcri(SDR0, port->sdr_base + PESDRn_LOOP);
1320 if (!(val & 0x00001000))
1321 ppc405ex_pcie_phy_reset(port);
1323 dcr_write(port->dcrs, DCRO_PEGPL_CFG, 0x10000000); /* guarded on */
1325 port->has_ibpre = 1;
1327 return ppc4xx_pciex_port_reset_sdr(port);
1330 static int ppc405ex_pciex_init_utl(struct ppc4xx_pciex_port *port)
1332 dcr_write(port->dcrs, DCRO_PEGPL_SPECIAL, 0x0);
1335 * Set buffer allocations and then assert VRB and TXE.
1337 out_be32(port->utl_base + PEUTL_OUTTR, 0x02000000);
1338 out_be32(port->utl_base + PEUTL_INTR, 0x02000000);
1339 out_be32(port->utl_base + PEUTL_OPDBSZ, 0x04000000);
1340 out_be32(port->utl_base + PEUTL_PBBSZ, 0x21000000);
1341 out_be32(port->utl_base + PEUTL_IPHBSZ, 0x02000000);
1342 out_be32(port->utl_base + PEUTL_IPDBSZ, 0x04000000);
1343 out_be32(port->utl_base + PEUTL_RCIRQEN, 0x00f00000);
1344 out_be32(port->utl_base + PEUTL_PCTL, 0x80800066);
1346 out_be32(port->utl_base + PEUTL_PBCTL, 0x08000000);
1351 static struct ppc4xx_pciex_hwops ppc405ex_pcie_hwops __initdata =
1354 .core_init = ppc405ex_pciex_core_init,
1355 .port_init_hw = ppc405ex_pciex_init_port_hw,
1356 .setup_utl = ppc405ex_pciex_init_utl,
1357 .check_link = ppc4xx_pciex_check_link_sdr,
1360 #endif /* CONFIG_40x */
1362 #ifdef CONFIG_476FPE
1363 static int __init ppc_476fpe_pciex_core_init(struct device_node *np)
1368 static void __init ppc_476fpe_pciex_check_link(struct ppc4xx_pciex_port *port)
1370 u32 timeout_ms = 20;
1371 u32 val = 0, mask = (PECFG_TLDLP_LNKUP|PECFG_TLDLP_PRESENT);
1372 void __iomem *mbase = ioremap(port->cfg_space.start + 0x10000000,
1375 printk(KERN_INFO "PCIE%d: Checking link...\n", port->index);
1377 if (mbase == NULL) {
1378 printk(KERN_WARNING "PCIE%d: failed to get cfg space\n",
1383 while (timeout_ms--) {
1384 val = in_le32(mbase + PECFG_TLDLP);
1386 if ((val & mask) == mask)
1391 if (val & PECFG_TLDLP_PRESENT) {
1392 printk(KERN_INFO "PCIE%d: link is up !\n", port->index);
1395 printk(KERN_WARNING "PCIE%d: Link up failed\n", port->index);
1400 static struct ppc4xx_pciex_hwops ppc_476fpe_pcie_hwops __initdata =
1402 .core_init = ppc_476fpe_pciex_core_init,
1403 .check_link = ppc_476fpe_pciex_check_link,
1405 #endif /* CONFIG_476FPE */
1407 /* Check that the core has been initied and if not, do it */
1408 static int __init ppc4xx_pciex_check_core_init(struct device_node *np)
1410 static int core_init;
1411 int count = -ENODEV;
1417 if (of_device_is_compatible(np, "ibm,plb-pciex-440spe")) {
1418 if (ppc440spe_revA())
1419 ppc4xx_pciex_hwops = &ppc440speA_pcie_hwops;
1421 ppc4xx_pciex_hwops = &ppc440speB_pcie_hwops;
1423 if (of_device_is_compatible(np, "ibm,plb-pciex-460ex"))
1424 ppc4xx_pciex_hwops = &ppc460ex_pcie_hwops;
1425 if (of_device_is_compatible(np, "ibm,plb-pciex-460sx"))
1426 ppc4xx_pciex_hwops = &ppc460sx_pcie_hwops;
1427 if (of_device_is_compatible(np, "ibm,plb-pciex-apm821xx"))
1428 ppc4xx_pciex_hwops = &apm821xx_pcie_hwops;
1429 #endif /* CONFIG_44x */
1431 if (of_device_is_compatible(np, "ibm,plb-pciex-405ex"))
1432 ppc4xx_pciex_hwops = &ppc405ex_pcie_hwops;
1434 #ifdef CONFIG_476FPE
1435 if (of_device_is_compatible(np, "ibm,plb-pciex-476fpe")
1436 || of_device_is_compatible(np, "ibm,plb-pciex-476gtr"))
1437 ppc4xx_pciex_hwops = &ppc_476fpe_pcie_hwops;
1439 if (ppc4xx_pciex_hwops == NULL) {
1440 printk(KERN_WARNING "PCIE: unknown host type %pOF\n", np);
1444 count = ppc4xx_pciex_hwops->core_init(np);
1446 ppc4xx_pciex_ports =
1447 kcalloc(count, sizeof(struct ppc4xx_pciex_port),
1449 if (ppc4xx_pciex_ports) {
1450 ppc4xx_pciex_port_count = count;
1453 printk(KERN_WARNING "PCIE: failed to allocate ports array\n");
1459 static void __init ppc4xx_pciex_port_init_mapping(struct ppc4xx_pciex_port *port)
1461 /* We map PCI Express configuration based on the reg property */
1462 dcr_write(port->dcrs, DCRO_PEGPL_CFGBAH,
1463 RES_TO_U32_HIGH(port->cfg_space.start));
1464 dcr_write(port->dcrs, DCRO_PEGPL_CFGBAL,
1465 RES_TO_U32_LOW(port->cfg_space.start));
1467 /* XXX FIXME: Use size from reg property. For now, map 512M */
1468 dcr_write(port->dcrs, DCRO_PEGPL_CFGMSK, 0xe0000001);
1470 /* We map UTL registers based on the reg property */
1471 dcr_write(port->dcrs, DCRO_PEGPL_REGBAH,
1472 RES_TO_U32_HIGH(port->utl_regs.start));
1473 dcr_write(port->dcrs, DCRO_PEGPL_REGBAL,
1474 RES_TO_U32_LOW(port->utl_regs.start));
1476 /* XXX FIXME: Use size from reg property */
1477 dcr_write(port->dcrs, DCRO_PEGPL_REGMSK, 0x00007001);
1479 /* Disable all other outbound windows */
1480 dcr_write(port->dcrs, DCRO_PEGPL_OMR1MSKL, 0);
1481 dcr_write(port->dcrs, DCRO_PEGPL_OMR2MSKL, 0);
1482 dcr_write(port->dcrs, DCRO_PEGPL_OMR3MSKL, 0);
1483 dcr_write(port->dcrs, DCRO_PEGPL_MSGMSK, 0);
1486 static int __init ppc4xx_pciex_port_init(struct ppc4xx_pciex_port *port)
1491 if (ppc4xx_pciex_hwops->port_init_hw)
1492 rc = ppc4xx_pciex_hwops->port_init_hw(port);
1497 * Initialize mapping: disable all regions and configure
1498 * CFG and REG regions based on resources in the device tree
1500 ppc4xx_pciex_port_init_mapping(port);
1502 if (ppc4xx_pciex_hwops->check_link)
1503 ppc4xx_pciex_hwops->check_link(port);
1508 port->utl_base = ioremap(port->utl_regs.start, 0x100);
1509 BUG_ON(port->utl_base == NULL);
1512 * Setup UTL registers --BenH.
1514 if (ppc4xx_pciex_hwops->setup_utl)
1515 ppc4xx_pciex_hwops->setup_utl(port);
1518 * Check for VC0 active or PLL Locked and assert RDY.
1520 if (port->sdr_base) {
1521 if (of_device_is_compatible(port->node,
1522 "ibm,plb-pciex-460sx")){
1523 if (port->link && ppc4xx_pciex_wait_on_sdr(port,
1525 1 << 12, 1 << 12, 5000)) {
1526 printk(KERN_INFO "PCIE%d: PLL not locked\n",
1530 } else if (port->link &&
1531 ppc4xx_pciex_wait_on_sdr(port, PESDRn_RCSSTS,
1532 1 << 16, 1 << 16, 5000)) {
1533 printk(KERN_INFO "PCIE%d: VC0 not active\n",
1538 dcri_clrset(SDR0, port->sdr_base + PESDRn_RCSSET, 0, 1 << 20);
1546 static int ppc4xx_pciex_validate_bdf(struct ppc4xx_pciex_port *port,
1547 struct pci_bus *bus,
1552 /* Endpoint can not generate upstream(remote) config cycles */
1553 if (port->endpoint && bus->number != port->hose->first_busno)
1554 return PCIBIOS_DEVICE_NOT_FOUND;
1556 /* Check we are within the mapped range */
1557 if (bus->number > port->hose->last_busno) {
1559 printk(KERN_WARNING "Warning! Probing bus %u"
1560 " out of range !\n", bus->number);
1563 return PCIBIOS_DEVICE_NOT_FOUND;
1566 /* The root complex has only one device / function */
1567 if (bus->number == port->hose->first_busno && devfn != 0)
1568 return PCIBIOS_DEVICE_NOT_FOUND;
1570 /* The other side of the RC has only one device as well */
1571 if (bus->number == (port->hose->first_busno + 1) &&
1572 PCI_SLOT(devfn) != 0)
1573 return PCIBIOS_DEVICE_NOT_FOUND;
1575 /* Check if we have a link */
1576 if ((bus->number != port->hose->first_busno) && !port->link)
1577 return PCIBIOS_DEVICE_NOT_FOUND;
1582 static void __iomem *ppc4xx_pciex_get_config_base(struct ppc4xx_pciex_port *port,
1583 struct pci_bus *bus,
1588 /* Remove the casts when we finally remove the stupid volatile
1589 * in struct pci_controller
1591 if (bus->number == port->hose->first_busno)
1592 return (void __iomem *)port->hose->cfg_addr;
1594 relbus = bus->number - (port->hose->first_busno + 1);
1595 return (void __iomem *)port->hose->cfg_data +
1596 ((relbus << 20) | (devfn << 12));
1599 static int ppc4xx_pciex_read_config(struct pci_bus *bus, unsigned int devfn,
1600 int offset, int len, u32 *val)
1602 struct pci_controller *hose = pci_bus_to_host(bus);
1603 struct ppc4xx_pciex_port *port =
1604 &ppc4xx_pciex_ports[hose->indirect_type];
1608 BUG_ON(hose != port->hose);
1610 if (ppc4xx_pciex_validate_bdf(port, bus, devfn) != 0)
1611 return PCIBIOS_DEVICE_NOT_FOUND;
1613 addr = ppc4xx_pciex_get_config_base(port, bus, devfn);
1616 * Reading from configuration space of non-existing device can
1617 * generate transaction errors. For the read duration we suppress
1618 * assertion of machine check exceptions to avoid those.
1620 gpl_cfg = dcr_read(port->dcrs, DCRO_PEGPL_CFG);
1621 dcr_write(port->dcrs, DCRO_PEGPL_CFG, gpl_cfg | GPL_DMER_MASK_DISA);
1623 /* Make sure no CRS is recorded */
1624 out_be32(port->utl_base + PEUTL_RCSTA, 0x00040000);
1628 *val = in_8((u8 *)(addr + offset));
1631 *val = in_le16((u16 *)(addr + offset));
1634 *val = in_le32((u32 *)(addr + offset));
1638 pr_debug("pcie-config-read: bus=%3d [%3d..%3d] devfn=0x%04x"
1639 " offset=0x%04x len=%d, addr=0x%p val=0x%08x\n",
1640 bus->number, hose->first_busno, hose->last_busno,
1641 devfn, offset, len, addr + offset, *val);
1643 /* Check for CRS (440SPe rev B does that for us but heh ..) */
1644 if (in_be32(port->utl_base + PEUTL_RCSTA) & 0x00040000) {
1645 pr_debug("Got CRS !\n");
1646 if (len != 4 || offset != 0)
1647 return PCIBIOS_DEVICE_NOT_FOUND;
1651 dcr_write(port->dcrs, DCRO_PEGPL_CFG, gpl_cfg);
1653 return PCIBIOS_SUCCESSFUL;
1656 static int ppc4xx_pciex_write_config(struct pci_bus *bus, unsigned int devfn,
1657 int offset, int len, u32 val)
1659 struct pci_controller *hose = pci_bus_to_host(bus);
1660 struct ppc4xx_pciex_port *port =
1661 &ppc4xx_pciex_ports[hose->indirect_type];
1665 if (ppc4xx_pciex_validate_bdf(port, bus, devfn) != 0)
1666 return PCIBIOS_DEVICE_NOT_FOUND;
1668 addr = ppc4xx_pciex_get_config_base(port, bus, devfn);
1671 * Reading from configuration space of non-existing device can
1672 * generate transaction errors. For the read duration we suppress
1673 * assertion of machine check exceptions to avoid those.
1675 gpl_cfg = dcr_read(port->dcrs, DCRO_PEGPL_CFG);
1676 dcr_write(port->dcrs, DCRO_PEGPL_CFG, gpl_cfg | GPL_DMER_MASK_DISA);
1678 pr_debug("pcie-config-write: bus=%3d [%3d..%3d] devfn=0x%04x"
1679 " offset=0x%04x len=%d, addr=0x%p val=0x%08x\n",
1680 bus->number, hose->first_busno, hose->last_busno,
1681 devfn, offset, len, addr + offset, val);
1685 out_8((u8 *)(addr + offset), val);
1688 out_le16((u16 *)(addr + offset), val);
1691 out_le32((u32 *)(addr + offset), val);
1695 dcr_write(port->dcrs, DCRO_PEGPL_CFG, gpl_cfg);
1697 return PCIBIOS_SUCCESSFUL;
1700 static struct pci_ops ppc4xx_pciex_pci_ops =
1702 .read = ppc4xx_pciex_read_config,
1703 .write = ppc4xx_pciex_write_config,
1706 static int __init ppc4xx_setup_one_pciex_POM(struct ppc4xx_pciex_port *port,
1707 struct pci_controller *hose,
1708 void __iomem *mbase,
1715 u32 lah, lal, pciah, pcial, sa;
1717 if (!is_power_of_2(size) ||
1718 (index < 2 && size < 0x100000) ||
1719 (index == 2 && size < 0x100) ||
1720 (plb_addr & (size - 1)) != 0) {
1721 printk(KERN_WARNING "%pOF: Resource out of range\n", hose->dn);
1725 /* Calculate register values */
1726 lah = RES_TO_U32_HIGH(plb_addr);
1727 lal = RES_TO_U32_LOW(plb_addr);
1728 pciah = RES_TO_U32_HIGH(pci_addr);
1729 pcial = RES_TO_U32_LOW(pci_addr);
1730 sa = (0xffffffffu << ilog2(size)) | 0x1;
1732 /* Program register values */
1735 out_le32(mbase + PECFG_POM0LAH, pciah);
1736 out_le32(mbase + PECFG_POM0LAL, pcial);
1737 dcr_write(port->dcrs, DCRO_PEGPL_OMR1BAH, lah);
1738 dcr_write(port->dcrs, DCRO_PEGPL_OMR1BAL, lal);
1739 dcr_write(port->dcrs, DCRO_PEGPL_OMR1MSKH, 0x7fffffff);
1740 /*Enabled and single region */
1741 if (of_device_is_compatible(port->node, "ibm,plb-pciex-460sx"))
1742 dcr_write(port->dcrs, DCRO_PEGPL_OMR1MSKL,
1743 sa | DCRO_PEGPL_460SX_OMR1MSKL_UOT
1744 | DCRO_PEGPL_OMRxMSKL_VAL);
1745 else if (of_device_is_compatible(
1746 port->node, "ibm,plb-pciex-476fpe") ||
1747 of_device_is_compatible(
1748 port->node, "ibm,plb-pciex-476gtr"))
1749 dcr_write(port->dcrs, DCRO_PEGPL_OMR1MSKL,
1750 sa | DCRO_PEGPL_476FPE_OMR1MSKL_UOT
1751 | DCRO_PEGPL_OMRxMSKL_VAL);
1753 dcr_write(port->dcrs, DCRO_PEGPL_OMR1MSKL,
1754 sa | DCRO_PEGPL_OMR1MSKL_UOT
1755 | DCRO_PEGPL_OMRxMSKL_VAL);
1758 out_le32(mbase + PECFG_POM1LAH, pciah);
1759 out_le32(mbase + PECFG_POM1LAL, pcial);
1760 dcr_write(port->dcrs, DCRO_PEGPL_OMR2BAH, lah);
1761 dcr_write(port->dcrs, DCRO_PEGPL_OMR2BAL, lal);
1762 dcr_write(port->dcrs, DCRO_PEGPL_OMR2MSKH, 0x7fffffff);
1763 dcr_write(port->dcrs, DCRO_PEGPL_OMR2MSKL,
1764 sa | DCRO_PEGPL_OMRxMSKL_VAL);
1767 out_le32(mbase + PECFG_POM2LAH, pciah);
1768 out_le32(mbase + PECFG_POM2LAL, pcial);
1769 dcr_write(port->dcrs, DCRO_PEGPL_OMR3BAH, lah);
1770 dcr_write(port->dcrs, DCRO_PEGPL_OMR3BAL, lal);
1771 dcr_write(port->dcrs, DCRO_PEGPL_OMR3MSKH, 0x7fffffff);
1772 /* Note that 3 here means enabled | IO space !!! */
1773 dcr_write(port->dcrs, DCRO_PEGPL_OMR3MSKL,
1774 sa | DCRO_PEGPL_OMR3MSKL_IO
1775 | DCRO_PEGPL_OMRxMSKL_VAL);
1782 static void __init ppc4xx_configure_pciex_POMs(struct ppc4xx_pciex_port *port,
1783 struct pci_controller *hose,
1784 void __iomem *mbase)
1786 int i, j, found_isa_hole = 0;
1788 /* Setup outbound memory windows */
1789 for (i = j = 0; i < 3; i++) {
1790 struct resource *res = &hose->mem_resources[i];
1791 resource_size_t offset = hose->mem_offset[i];
1793 /* we only care about memory windows */
1794 if (!(res->flags & IORESOURCE_MEM))
1797 printk(KERN_WARNING "%pOF: Too many ranges\n",
1802 /* Configure the resource */
1803 if (ppc4xx_setup_one_pciex_POM(port, hose, mbase,
1805 res->start - offset,
1811 /* If the resource PCI address is 0 then we have our
1814 if (res->start == offset)
1819 /* Handle ISA memory hole if not already covered */
1820 if (j <= 1 && !found_isa_hole && hose->isa_mem_size)
1821 if (ppc4xx_setup_one_pciex_POM(port, hose, mbase,
1822 hose->isa_mem_phys, 0,
1823 hose->isa_mem_size, 0, j) == 0)
1824 printk(KERN_INFO "%pOF: Legacy ISA memory support enabled\n",
1827 /* Configure IO, always 64K starting at 0. We hard wire it to 64K !
1828 * Note also that it -has- to be region index 2 on this HW
1830 if (hose->io_resource.flags & IORESOURCE_IO)
1831 ppc4xx_setup_one_pciex_POM(port, hose, mbase,
1832 hose->io_base_phys, 0,
1833 0x10000, IORESOURCE_IO, 2);
1836 static void __init ppc4xx_configure_pciex_PIMs(struct ppc4xx_pciex_port *port,
1837 struct pci_controller *hose,
1838 void __iomem *mbase,
1839 struct resource *res)
1841 resource_size_t size = resource_size(res);
1844 if (port->endpoint) {
1845 resource_size_t ep_addr = 0;
1846 resource_size_t ep_size = 32 << 20;
1848 /* Currently we map a fixed 64MByte window to PLB address
1849 * 0 (SDRAM). This should probably be configurable via a dts
1853 /* Calculate window size */
1854 sa = (0xffffffffffffffffull << ilog2(ep_size));
1857 out_le32(mbase + PECFG_BAR0HMPA, RES_TO_U32_HIGH(sa));
1858 out_le32(mbase + PECFG_BAR0LMPA, RES_TO_U32_LOW(sa) |
1859 PCI_BASE_ADDRESS_MEM_TYPE_64);
1861 /* Disable BAR1 & BAR2 */
1862 out_le32(mbase + PECFG_BAR1MPA, 0);
1863 out_le32(mbase + PECFG_BAR2HMPA, 0);
1864 out_le32(mbase + PECFG_BAR2LMPA, 0);
1866 out_le32(mbase + PECFG_PIM01SAH, RES_TO_U32_HIGH(sa));
1867 out_le32(mbase + PECFG_PIM01SAL, RES_TO_U32_LOW(sa));
1869 out_le32(mbase + PCI_BASE_ADDRESS_0, RES_TO_U32_LOW(ep_addr));
1870 out_le32(mbase + PCI_BASE_ADDRESS_1, RES_TO_U32_HIGH(ep_addr));
1872 /* Calculate window size */
1873 sa = (0xffffffffffffffffull << ilog2(size));
1874 if (res->flags & IORESOURCE_PREFETCH)
1875 sa |= PCI_BASE_ADDRESS_MEM_PREFETCH;
1877 if (of_device_is_compatible(port->node, "ibm,plb-pciex-460sx") ||
1878 of_device_is_compatible(
1879 port->node, "ibm,plb-pciex-476fpe") ||
1880 of_device_is_compatible(
1881 port->node, "ibm,plb-pciex-476gtr"))
1882 sa |= PCI_BASE_ADDRESS_MEM_TYPE_64;
1884 out_le32(mbase + PECFG_BAR0HMPA, RES_TO_U32_HIGH(sa));
1885 out_le32(mbase + PECFG_BAR0LMPA, RES_TO_U32_LOW(sa));
1887 /* The setup of the split looks weird to me ... let's see
1890 out_le32(mbase + PECFG_PIM0LAL, 0x00000000);
1891 out_le32(mbase + PECFG_PIM0LAH, 0x00000000);
1892 out_le32(mbase + PECFG_PIM1LAL, 0x00000000);
1893 out_le32(mbase + PECFG_PIM1LAH, 0x00000000);
1894 out_le32(mbase + PECFG_PIM01SAH, 0xffff0000);
1895 out_le32(mbase + PECFG_PIM01SAL, 0x00000000);
1897 out_le32(mbase + PCI_BASE_ADDRESS_0, RES_TO_U32_LOW(res->start));
1898 out_le32(mbase + PCI_BASE_ADDRESS_1, RES_TO_U32_HIGH(res->start));
1901 /* Enable inbound mapping */
1902 out_le32(mbase + PECFG_PIMEN, 0x1);
1904 /* Enable I/O, Mem, and Busmaster cycles */
1905 out_le16(mbase + PCI_COMMAND,
1906 in_le16(mbase + PCI_COMMAND) |
1907 PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
1910 static void __init ppc4xx_pciex_port_setup_hose(struct ppc4xx_pciex_port *port)
1912 struct resource dma_window;
1913 struct pci_controller *hose = NULL;
1914 const int *bus_range;
1915 int primary, busses;
1916 void __iomem *mbase = NULL, *cfg_data = NULL;
1920 /* Check if primary bridge */
1921 primary = of_property_read_bool(port->node, "primary");
1923 /* Get bus range if any */
1924 bus_range = of_get_property(port->node, "bus-range", NULL);
1926 /* Allocate the host controller data structure */
1927 hose = pcibios_alloc_controller(port->node);
1931 /* We stick the port number in "indirect_type" so the config space
1932 * ops can retrieve the port data structure easily
1934 hose->indirect_type = port->index;
1937 hose->first_busno = bus_range ? bus_range[0] : 0x0;
1938 hose->last_busno = bus_range ? bus_range[1] : 0xff;
1940 /* Because of how big mapping the config space is (1M per bus), we
1941 * limit how many busses we support. In the long run, we could replace
1942 * that with something akin to kmap_atomic instead. We set aside 1 bus
1943 * for the host itself too.
1945 busses = hose->last_busno - hose->first_busno; /* This is off by 1 */
1946 if (busses > MAX_PCIE_BUS_MAPPED) {
1947 busses = MAX_PCIE_BUS_MAPPED;
1948 hose->last_busno = hose->first_busno + busses;
1951 if (!port->endpoint) {
1952 /* Only map the external config space in cfg_data for
1953 * PCIe root-complexes. External space is 1M per bus
1955 cfg_data = ioremap(port->cfg_space.start +
1956 (hose->first_busno + 1) * 0x100000,
1958 if (cfg_data == NULL) {
1959 printk(KERN_ERR "%pOF: Can't map external config space !",
1963 hose->cfg_data = cfg_data;
1966 /* Always map the host config space in cfg_addr.
1967 * Internal space is 4K
1969 mbase = ioremap(port->cfg_space.start + 0x10000000, 0x1000);
1970 if (mbase == NULL) {
1971 printk(KERN_ERR "%pOF: Can't map internal config space !",
1975 hose->cfg_addr = mbase;
1977 pr_debug("PCIE %pOF, bus %d..%d\n", port->node,
1978 hose->first_busno, hose->last_busno);
1979 pr_debug(" config space mapped at: root @0x%p, other @0x%p\n",
1980 hose->cfg_addr, hose->cfg_data);
1982 /* Setup config space */
1983 hose->ops = &ppc4xx_pciex_pci_ops;
1985 mbase = (void __iomem *)hose->cfg_addr;
1987 if (!port->endpoint) {
1989 * Set bus numbers on our root port
1991 out_8(mbase + PCI_PRIMARY_BUS, hose->first_busno);
1992 out_8(mbase + PCI_SECONDARY_BUS, hose->first_busno + 1);
1993 out_8(mbase + PCI_SUBORDINATE_BUS, hose->last_busno);
1997 * OMRs are already reset, also disable PIMs
1999 out_le32(mbase + PECFG_PIMEN, 0);
2001 /* Parse outbound mapping resources */
2002 pci_process_bridge_OF_ranges(hose, port->node, primary);
2004 /* Parse inbound mapping resources */
2005 if (ppc4xx_parse_dma_ranges(hose, mbase, &dma_window) != 0)
2008 /* Configure outbound ranges POMs */
2009 ppc4xx_configure_pciex_POMs(port, hose, mbase);
2011 /* Configure inbound ranges PIMs */
2012 ppc4xx_configure_pciex_PIMs(port, hose, mbase, &dma_window);
2014 /* The root complex doesn't show up if we don't set some vendor
2015 * and device IDs into it. The defaults below are the same bogus
2016 * one that the initial code in arch/ppc had. This can be
2017 * overwritten by setting the "vendor-id/device-id" properties
2018 * in the pciex node.
2021 /* Get the (optional) vendor-/device-id from the device-tree */
2022 pval = of_get_property(port->node, "vendor-id", NULL);
2026 if (!port->endpoint)
2027 val = 0xaaa0 + port->index;
2029 val = 0xeee0 + port->index;
2031 out_le16(mbase + 0x200, val);
2033 pval = of_get_property(port->node, "device-id", NULL);
2037 if (!port->endpoint)
2038 val = 0xbed0 + port->index;
2040 val = 0xfed0 + port->index;
2042 out_le16(mbase + 0x202, val);
2044 /* Enable Bus master, memory, and io space */
2045 if (of_device_is_compatible(port->node, "ibm,plb-pciex-460sx"))
2046 out_le16(mbase + 0x204, 0x7);
2048 if (!port->endpoint) {
2049 /* Set Class Code to PCI-PCI bridge and Revision Id to 1 */
2050 out_le32(mbase + 0x208, 0x06040001);
2052 printk(KERN_INFO "PCIE%d: successfully set as root-complex\n",
2055 /* Set Class Code to Processor/PPC */
2056 out_le32(mbase + 0x208, 0x0b200001);
2058 printk(KERN_INFO "PCIE%d: successfully set as endpoint\n",
2065 pcibios_free_controller(hose);
2072 static void __init ppc4xx_probe_pciex_bridge(struct device_node *np)
2074 struct ppc4xx_pciex_port *port;
2079 /* First, proceed to core initialization as we assume there's
2080 * only one PCIe core in the system
2082 if (ppc4xx_pciex_check_core_init(np))
2085 /* Get the port number from the device-tree */
2086 pval = of_get_property(np, "port", NULL);
2088 printk(KERN_ERR "PCIE: Can't find port number for %pOF\n", np);
2092 if (portno >= ppc4xx_pciex_port_count) {
2093 printk(KERN_ERR "PCIE: port number out of range for %pOF\n",
2097 port = &ppc4xx_pciex_ports[portno];
2098 port->index = portno;
2101 * Check if device is enabled
2103 if (!of_device_is_available(np)) {
2104 printk(KERN_INFO "PCIE%d: Port disabled via device-tree\n", port->index);
2108 port->node = of_node_get(np);
2109 if (ppc4xx_pciex_hwops->want_sdr) {
2110 pval = of_get_property(np, "sdr-base", NULL);
2112 printk(KERN_ERR "PCIE: missing sdr-base for %pOF\n",
2116 port->sdr_base = *pval;
2119 /* Check if device_type property is set to "pci" or "pci-endpoint".
2120 * Resulting from this setup this PCIe port will be configured
2121 * as root-complex or as endpoint.
2123 if (of_node_is_type(port->node, "pci-endpoint")) {
2125 } else if (of_node_is_type(port->node, "pci")) {
2128 printk(KERN_ERR "PCIE: missing or incorrect device_type for %pOF\n",
2133 /* Fetch config space registers address */
2134 if (of_address_to_resource(np, 0, &port->cfg_space)) {
2135 printk(KERN_ERR "%pOF: Can't get PCI-E config space !", np);
2138 /* Fetch host bridge internal registers address */
2139 if (of_address_to_resource(np, 1, &port->utl_regs)) {
2140 printk(KERN_ERR "%pOF: Can't get UTL register base !", np);
2145 dcrs = dcr_resource_start(np, 0);
2147 printk(KERN_ERR "%pOF: Can't get DCR register base !", np);
2150 port->dcrs = dcr_map(np, dcrs, dcr_resource_len(np, 0));
2152 /* Initialize the port specific registers */
2153 if (ppc4xx_pciex_port_init(port)) {
2154 printk(KERN_WARNING "PCIE%d: Port init failed\n", port->index);
2158 /* Setup the linux hose data structure */
2159 ppc4xx_pciex_port_setup_hose(port);
2162 #endif /* CONFIG_PPC4xx_PCI_EXPRESS */
2164 static int __init ppc4xx_pci_find_bridges(void)
2166 struct device_node *np;
2168 pci_add_flags(PCI_ENABLE_PROC_DOMAINS | PCI_COMPAT_DOMAIN_0);
2170 #ifdef CONFIG_PPC4xx_PCI_EXPRESS
2171 for_each_compatible_node(np, NULL, "ibm,plb-pciex")
2172 ppc4xx_probe_pciex_bridge(np);
2174 for_each_compatible_node(np, NULL, "ibm,plb-pcix")
2175 ppc4xx_probe_pcix_bridge(np);
2176 for_each_compatible_node(np, NULL, "ibm,plb-pci")
2177 ppc4xx_probe_pci_bridge(np);
2181 arch_initcall(ppc4xx_pci_find_bridges);