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/bootmem.h>
26 #include <linux/delay.h>
29 #include <asm/pci-bridge.h>
30 #include <asm/machdep.h>
32 #include <asm/dcr-regs.h>
34 #include "ppc4xx_pci.h"
36 static int dma_offset_set;
38 /* Move that to a useable header */
39 extern unsigned long total_memory;
41 #define U64_TO_U32_LOW(val) ((u32)((val) & 0x00000000ffffffffULL))
42 #define U64_TO_U32_HIGH(val) ((u32)((val) >> 32))
44 #ifdef CONFIG_RESOURCES_64BIT
45 #define RES_TO_U32_LOW(val) U64_TO_U32_LOW(val)
46 #define RES_TO_U32_HIGH(val) U64_TO_U32_HIGH(val)
48 #define RES_TO_U32_LOW(val) (val)
49 #define RES_TO_U32_HIGH(val) (0)
52 static inline int ppc440spe_revA(void)
54 /* Catch both 440SPe variants, with and without RAID6 support */
55 if ((mfspr(SPRN_PVR) & 0xffefffff) == 0x53421890)
61 static void fixup_ppc4xx_pci_bridge(struct pci_dev *dev)
63 struct pci_controller *hose;
66 if (dev->devfn != 0 || dev->bus->self != NULL)
69 hose = pci_bus_to_host(dev->bus);
73 if (!of_device_is_compatible(hose->dn, "ibm,plb-pciex") &&
74 !of_device_is_compatible(hose->dn, "ibm,plb-pcix") &&
75 !of_device_is_compatible(hose->dn, "ibm,plb-pci"))
78 /* Hide the PCI host BARs from the kernel as their content doesn't
79 * fit well in the resource management
81 for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
82 dev->resource[i].start = dev->resource[i].end = 0;
83 dev->resource[i].flags = 0;
86 printk(KERN_INFO "PCI: Hiding 4xx host bridge resources %s\n",
89 DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, fixup_ppc4xx_pci_bridge);
91 static int __init ppc4xx_parse_dma_ranges(struct pci_controller *hose,
98 int pna = of_n_addr_cells(hose->dn);
103 res->end = size = 0x80000000;
104 res->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH;
106 /* Get dma-ranges property */
107 ranges = of_get_property(hose->dn, "dma-ranges", &rlen);
112 while ((rlen -= np * 4) >= 0) {
113 u32 pci_space = ranges[0];
114 u64 pci_addr = of_read_number(ranges + 1, 2);
115 u64 cpu_addr = of_translate_dma_address(hose->dn, ranges + 3);
116 size = of_read_number(ranges + pna + 3, 2);
118 if (cpu_addr == OF_BAD_ADDR || size == 0)
121 /* We only care about memory */
122 if ((pci_space & 0x03000000) != 0x02000000)
125 /* We currently only support memory at 0, and pci_addr
126 * within 32 bits space
128 if (cpu_addr != 0 || pci_addr > 0xffffffff) {
129 printk(KERN_WARNING "%s: Ignored unsupported dma range"
130 " 0x%016llx...0x%016llx -> 0x%016llx\n",
132 pci_addr, pci_addr + size - 1, cpu_addr);
136 /* Check if not prefetchable */
137 if (!(pci_space & 0x40000000))
138 res->flags &= ~IORESOURCE_PREFETCH;
142 res->start = pci_addr;
143 #ifndef CONFIG_RESOURCES_64BIT
144 /* Beware of 32 bits resources */
145 if ((pci_addr + size) > 0x100000000ull)
146 res->end = 0xffffffff;
149 res->end = res->start + size - 1;
153 /* We only support one global DMA offset */
154 if (dma_offset_set && pci_dram_offset != res->start) {
155 printk(KERN_ERR "%s: dma-ranges(s) mismatch\n",
156 hose->dn->full_name);
160 /* Check that we can fit all of memory as we don't support
163 if (size < total_memory) {
164 printk(KERN_ERR "%s: dma-ranges too small "
165 "(size=%llx total_memory=%lx)\n",
166 hose->dn->full_name, size, total_memory);
170 /* Check we are a power of 2 size and that base is a multiple of size*/
171 if (!is_power_of_2(size) ||
172 (res->start & (size - 1)) != 0) {
173 printk(KERN_ERR "%s: dma-ranges unaligned\n",
174 hose->dn->full_name);
178 /* Check that we are fully contained within 32 bits space */
179 if (res->end > 0xffffffff) {
180 printk(KERN_ERR "%s: dma-ranges outside of 32 bits space\n",
181 hose->dn->full_name);
186 pci_dram_offset = res->start;
188 printk(KERN_INFO "4xx PCI DMA offset set to 0x%08lx\n",
197 static void __init ppc4xx_configure_pci_PMMs(struct pci_controller *hose,
200 u32 la, ma, pcila, pciha;
203 /* Setup outbound memory windows */
204 for (i = j = 0; i < 3; i++) {
205 struct resource *res = &hose->mem_resources[i];
207 /* we only care about memory windows */
208 if (!(res->flags & IORESOURCE_MEM))
211 printk(KERN_WARNING "%s: Too many ranges\n",
212 hose->dn->full_name);
216 /* Calculate register values */
218 pciha = RES_TO_U32_HIGH(res->start - hose->pci_mem_offset);
219 pcila = RES_TO_U32_LOW(res->start - hose->pci_mem_offset);
221 ma = res->end + 1 - res->start;
222 if (!is_power_of_2(ma) || ma < 0x1000 || ma > 0xffffffffu) {
223 printk(KERN_WARNING "%s: Resource out of range\n",
224 hose->dn->full_name);
227 ma = (0xffffffffu << ilog2(ma)) | 0x1;
228 if (res->flags & IORESOURCE_PREFETCH)
231 /* Program register values */
232 writel(la, reg + PCIL0_PMM0LA + (0x10 * j));
233 writel(pcila, reg + PCIL0_PMM0PCILA + (0x10 * j));
234 writel(pciha, reg + PCIL0_PMM0PCIHA + (0x10 * j));
235 writel(ma, reg + PCIL0_PMM0MA + (0x10 * j));
240 static void __init ppc4xx_configure_pci_PTMs(struct pci_controller *hose,
242 const struct resource *res)
244 resource_size_t size = res->end - res->start + 1;
247 /* Calculate window size */
248 sa = (0xffffffffu << ilog2(size)) | 1;
251 /* RAM is always at 0 local for now */
252 writel(0, reg + PCIL0_PTM1LA);
253 writel(sa, reg + PCIL0_PTM1MS);
255 /* Map on PCI side */
256 early_write_config_dword(hose, hose->first_busno, 0,
257 PCI_BASE_ADDRESS_1, res->start);
258 early_write_config_dword(hose, hose->first_busno, 0,
259 PCI_BASE_ADDRESS_2, 0x00000000);
260 early_write_config_word(hose, hose->first_busno, 0,
261 PCI_COMMAND, 0x0006);
264 static void __init ppc4xx_probe_pci_bridge(struct device_node *np)
267 struct resource rsrc_cfg;
268 struct resource rsrc_reg;
269 struct resource dma_window;
270 struct pci_controller *hose = NULL;
271 void __iomem *reg = NULL;
272 const int *bus_range;
275 /* Fetch config space registers address */
276 if (of_address_to_resource(np, 0, &rsrc_cfg)) {
277 printk(KERN_ERR "%s:Can't get PCI config register base !",
281 /* Fetch host bridge internal registers address */
282 if (of_address_to_resource(np, 3, &rsrc_reg)) {
283 printk(KERN_ERR "%s: Can't get PCI internal register base !",
288 /* Check if primary bridge */
289 if (of_get_property(np, "primary", NULL))
292 /* Get bus range if any */
293 bus_range = of_get_property(np, "bus-range", NULL);
296 reg = ioremap(rsrc_reg.start, rsrc_reg.end + 1 - rsrc_reg.start);
298 printk(KERN_ERR "%s: Can't map registers !", np->full_name);
302 /* Allocate the host controller data structure */
303 hose = pcibios_alloc_controller(np);
307 hose->first_busno = bus_range ? bus_range[0] : 0x0;
308 hose->last_busno = bus_range ? bus_range[1] : 0xff;
310 /* Setup config space */
311 setup_indirect_pci(hose, rsrc_cfg.start, rsrc_cfg.start + 0x4, 0);
313 /* Disable all windows */
314 writel(0, reg + PCIL0_PMM0MA);
315 writel(0, reg + PCIL0_PMM1MA);
316 writel(0, reg + PCIL0_PMM2MA);
317 writel(0, reg + PCIL0_PTM1MS);
318 writel(0, reg + PCIL0_PTM2MS);
320 /* Parse outbound mapping resources */
321 pci_process_bridge_OF_ranges(hose, np, primary);
323 /* Parse inbound mapping resources */
324 if (ppc4xx_parse_dma_ranges(hose, reg, &dma_window) != 0)
327 /* Configure outbound ranges POMs */
328 ppc4xx_configure_pci_PMMs(hose, reg);
330 /* Configure inbound ranges PIMs */
331 ppc4xx_configure_pci_PTMs(hose, reg, &dma_window);
333 /* We don't need the registers anymore */
339 pcibios_free_controller(hose);
348 static void __init ppc4xx_configure_pcix_POMs(struct pci_controller *hose,
351 u32 lah, lal, pciah, pcial, sa;
354 /* Setup outbound memory windows */
355 for (i = j = 0; i < 3; i++) {
356 struct resource *res = &hose->mem_resources[i];
358 /* we only care about memory windows */
359 if (!(res->flags & IORESOURCE_MEM))
362 printk(KERN_WARNING "%s: Too many ranges\n",
363 hose->dn->full_name);
367 /* Calculate register values */
368 lah = RES_TO_U32_HIGH(res->start);
369 lal = RES_TO_U32_LOW(res->start);
370 pciah = RES_TO_U32_HIGH(res->start - hose->pci_mem_offset);
371 pcial = RES_TO_U32_LOW(res->start - hose->pci_mem_offset);
372 sa = res->end + 1 - res->start;
373 if (!is_power_of_2(sa) || sa < 0x100000 ||
375 printk(KERN_WARNING "%s: Resource out of range\n",
376 hose->dn->full_name);
379 sa = (0xffffffffu << ilog2(sa)) | 0x1;
381 /* Program register values */
383 writel(lah, reg + PCIX0_POM0LAH);
384 writel(lal, reg + PCIX0_POM0LAL);
385 writel(pciah, reg + PCIX0_POM0PCIAH);
386 writel(pcial, reg + PCIX0_POM0PCIAL);
387 writel(sa, reg + PCIX0_POM0SA);
389 writel(lah, reg + PCIX0_POM1LAH);
390 writel(lal, reg + PCIX0_POM1LAL);
391 writel(pciah, reg + PCIX0_POM1PCIAH);
392 writel(pcial, reg + PCIX0_POM1PCIAL);
393 writel(sa, reg + PCIX0_POM1SA);
399 static void __init ppc4xx_configure_pcix_PIMs(struct pci_controller *hose,
401 const struct resource *res,
405 resource_size_t size = res->end - res->start + 1;
408 /* RAM is always at 0 */
409 writel(0x00000000, reg + PCIX0_PIM0LAH);
410 writel(0x00000000, reg + PCIX0_PIM0LAL);
412 /* Calculate window size */
413 sa = (0xffffffffu << ilog2(size)) | 1;
415 if (res->flags & IORESOURCE_PREFETCH)
419 writel(sa, reg + PCIX0_PIM0SA);
421 writel(0xffffffff, reg + PCIX0_PIM0SAH);
423 /* Map on PCI side */
424 writel(0x00000000, reg + PCIX0_BAR0H);
425 writel(res->start, reg + PCIX0_BAR0L);
426 writew(0x0006, reg + PCIX0_COMMAND);
429 static void __init ppc4xx_probe_pcix_bridge(struct device_node *np)
431 struct resource rsrc_cfg;
432 struct resource rsrc_reg;
433 struct resource dma_window;
434 struct pci_controller *hose = NULL;
435 void __iomem *reg = NULL;
436 const int *bus_range;
437 int big_pim = 0, msi = 0, primary = 0;
439 /* Fetch config space registers address */
440 if (of_address_to_resource(np, 0, &rsrc_cfg)) {
441 printk(KERN_ERR "%s:Can't get PCI-X config register base !",
445 /* Fetch host bridge internal registers address */
446 if (of_address_to_resource(np, 3, &rsrc_reg)) {
447 printk(KERN_ERR "%s: Can't get PCI-X internal register base !",
452 /* Check if it supports large PIMs (440GX) */
453 if (of_get_property(np, "large-inbound-windows", NULL))
456 /* Check if we should enable MSIs inbound hole */
457 if (of_get_property(np, "enable-msi-hole", NULL))
460 /* Check if primary bridge */
461 if (of_get_property(np, "primary", NULL))
464 /* Get bus range if any */
465 bus_range = of_get_property(np, "bus-range", NULL);
468 reg = ioremap(rsrc_reg.start, rsrc_reg.end + 1 - rsrc_reg.start);
470 printk(KERN_ERR "%s: Can't map registers !", np->full_name);
474 /* Allocate the host controller data structure */
475 hose = pcibios_alloc_controller(np);
479 hose->first_busno = bus_range ? bus_range[0] : 0x0;
480 hose->last_busno = bus_range ? bus_range[1] : 0xff;
482 /* Setup config space */
483 setup_indirect_pci(hose, rsrc_cfg.start, rsrc_cfg.start + 0x4, 0);
485 /* Disable all windows */
486 writel(0, reg + PCIX0_POM0SA);
487 writel(0, reg + PCIX0_POM1SA);
488 writel(0, reg + PCIX0_POM2SA);
489 writel(0, reg + PCIX0_PIM0SA);
490 writel(0, reg + PCIX0_PIM1SA);
491 writel(0, reg + PCIX0_PIM2SA);
493 writel(0, reg + PCIX0_PIM0SAH);
494 writel(0, reg + PCIX0_PIM2SAH);
497 /* Parse outbound mapping resources */
498 pci_process_bridge_OF_ranges(hose, np, primary);
500 /* Parse inbound mapping resources */
501 if (ppc4xx_parse_dma_ranges(hose, reg, &dma_window) != 0)
504 /* Configure outbound ranges POMs */
505 ppc4xx_configure_pcix_POMs(hose, reg);
507 /* Configure inbound ranges PIMs */
508 ppc4xx_configure_pcix_PIMs(hose, reg, &dma_window, big_pim, msi);
510 /* We don't need the registers anymore */
516 pcibios_free_controller(hose);
521 #ifdef CONFIG_PPC4xx_PCI_EXPRESS
524 * 4xx PCI-Express part
526 * We support 3 parts currently based on the compatible property:
528 * ibm,plb-pciex-440spe
529 * ibm,plb-pciex-405ex
530 * ibm,plb-pciex-460ex
532 * Anything else will be rejected for now as they are all subtly
533 * different unfortunately.
537 #define MAX_PCIE_BUS_MAPPED 0x40
539 struct ppc4xx_pciex_port
541 struct pci_controller *hose;
542 struct device_node *node;
547 unsigned int sdr_base;
549 struct resource cfg_space;
550 struct resource utl_regs;
551 void __iomem *utl_base;
554 static struct ppc4xx_pciex_port *ppc4xx_pciex_ports;
555 static unsigned int ppc4xx_pciex_port_count;
557 struct ppc4xx_pciex_hwops
559 int (*core_init)(struct device_node *np);
560 int (*port_init_hw)(struct ppc4xx_pciex_port *port);
561 int (*setup_utl)(struct ppc4xx_pciex_port *port);
564 static struct ppc4xx_pciex_hwops *ppc4xx_pciex_hwops;
568 /* Check various reset bits of the 440SPe PCIe core */
569 static int __init ppc440spe_pciex_check_reset(struct device_node *np)
571 u32 valPE0, valPE1, valPE2;
574 /* SDR0_PEGPLLLCT1 reset */
575 if (!(mfdcri(SDR0, PESDR0_PLLLCT1) & 0x01000000)) {
577 * the PCIe core was probably already initialised
578 * by firmware - let's re-reset RCSSET regs
580 * -- Shouldn't we also re-reset the whole thing ? -- BenH
582 pr_debug("PCIE: SDR0_PLLLCT1 already reset.\n");
583 mtdcri(SDR0, PESDR0_440SPE_RCSSET, 0x01010000);
584 mtdcri(SDR0, PESDR1_440SPE_RCSSET, 0x01010000);
585 mtdcri(SDR0, PESDR2_440SPE_RCSSET, 0x01010000);
588 valPE0 = mfdcri(SDR0, PESDR0_440SPE_RCSSET);
589 valPE1 = mfdcri(SDR0, PESDR1_440SPE_RCSSET);
590 valPE2 = mfdcri(SDR0, PESDR2_440SPE_RCSSET);
592 /* SDR0_PExRCSSET rstgu */
593 if (!(valPE0 & 0x01000000) ||
594 !(valPE1 & 0x01000000) ||
595 !(valPE2 & 0x01000000)) {
596 printk(KERN_INFO "PCIE: SDR0_PExRCSSET rstgu error\n");
600 /* SDR0_PExRCSSET rstdl */
601 if (!(valPE0 & 0x00010000) ||
602 !(valPE1 & 0x00010000) ||
603 !(valPE2 & 0x00010000)) {
604 printk(KERN_INFO "PCIE: SDR0_PExRCSSET rstdl error\n");
608 /* SDR0_PExRCSSET rstpyn */
609 if ((valPE0 & 0x00001000) ||
610 (valPE1 & 0x00001000) ||
611 (valPE2 & 0x00001000)) {
612 printk(KERN_INFO "PCIE: SDR0_PExRCSSET rstpyn error\n");
616 /* SDR0_PExRCSSET hldplb */
617 if ((valPE0 & 0x10000000) ||
618 (valPE1 & 0x10000000) ||
619 (valPE2 & 0x10000000)) {
620 printk(KERN_INFO "PCIE: SDR0_PExRCSSET hldplb error\n");
624 /* SDR0_PExRCSSET rdy */
625 if ((valPE0 & 0x00100000) ||
626 (valPE1 & 0x00100000) ||
627 (valPE2 & 0x00100000)) {
628 printk(KERN_INFO "PCIE: SDR0_PExRCSSET rdy error\n");
632 /* SDR0_PExRCSSET shutdown */
633 if ((valPE0 & 0x00000100) ||
634 (valPE1 & 0x00000100) ||
635 (valPE2 & 0x00000100)) {
636 printk(KERN_INFO "PCIE: SDR0_PExRCSSET shutdown error\n");
643 /* Global PCIe core initializations for 440SPe core */
644 static int __init ppc440spe_pciex_core_init(struct device_node *np)
648 /* Set PLL clock receiver to LVPECL */
649 dcri_clrset(SDR0, PESDR0_PLLLCT1, 0, 1 << 28);
651 /* Shouldn't we do all the calibration stuff etc... here ? */
652 if (ppc440spe_pciex_check_reset(np))
655 if (!(mfdcri(SDR0, PESDR0_PLLLCT2) & 0x10000)) {
656 printk(KERN_INFO "PCIE: PESDR_PLLCT2 resistance calibration "
658 mfdcri(SDR0, PESDR0_PLLLCT2));
662 /* De-assert reset of PCIe PLL, wait for lock */
663 dcri_clrset(SDR0, PESDR0_PLLLCT1, 1 << 24, 0);
667 if (!(mfdcri(SDR0, PESDR0_PLLLCT3) & 0x10000000)) {
674 printk(KERN_INFO "PCIE: VCO output not locked\n");
678 pr_debug("PCIE initialization OK\n");
683 static int ppc440spe_pciex_init_port_hw(struct ppc4xx_pciex_port *port)
688 val = PTYPE_LEGACY_ENDPOINT << 20;
690 val = PTYPE_ROOT_PORT << 20;
692 if (port->index == 0)
693 val |= LNKW_X8 << 12;
695 val |= LNKW_X4 << 12;
697 mtdcri(SDR0, port->sdr_base + PESDRn_DLPSET, val);
698 mtdcri(SDR0, port->sdr_base + PESDRn_UTLSET1, 0x20222222);
699 if (ppc440spe_revA())
700 mtdcri(SDR0, port->sdr_base + PESDRn_UTLSET2, 0x11000000);
701 mtdcri(SDR0, port->sdr_base + PESDRn_440SPE_HSSL0SET1, 0x35000000);
702 mtdcri(SDR0, port->sdr_base + PESDRn_440SPE_HSSL1SET1, 0x35000000);
703 mtdcri(SDR0, port->sdr_base + PESDRn_440SPE_HSSL2SET1, 0x35000000);
704 mtdcri(SDR0, port->sdr_base + PESDRn_440SPE_HSSL3SET1, 0x35000000);
705 if (port->index == 0) {
706 mtdcri(SDR0, port->sdr_base + PESDRn_440SPE_HSSL4SET1,
708 mtdcri(SDR0, port->sdr_base + PESDRn_440SPE_HSSL5SET1,
710 mtdcri(SDR0, port->sdr_base + PESDRn_440SPE_HSSL6SET1,
712 mtdcri(SDR0, port->sdr_base + PESDRn_440SPE_HSSL7SET1,
715 dcri_clrset(SDR0, port->sdr_base + PESDRn_RCSSET,
716 (1 << 24) | (1 << 16), 1 << 12);
721 static int ppc440speA_pciex_init_port_hw(struct ppc4xx_pciex_port *port)
723 return ppc440spe_pciex_init_port_hw(port);
726 static int ppc440speB_pciex_init_port_hw(struct ppc4xx_pciex_port *port)
728 int rc = ppc440spe_pciex_init_port_hw(port);
735 static int ppc440speA_pciex_init_utl(struct ppc4xx_pciex_port *port)
737 /* XXX Check what that value means... I hate magic */
738 dcr_write(port->dcrs, DCRO_PEGPL_SPECIAL, 0x68782800);
741 * Set buffer allocations and then assert VRB and TXE.
743 out_be32(port->utl_base + PEUTL_OUTTR, 0x08000000);
744 out_be32(port->utl_base + PEUTL_INTR, 0x02000000);
745 out_be32(port->utl_base + PEUTL_OPDBSZ, 0x10000000);
746 out_be32(port->utl_base + PEUTL_PBBSZ, 0x53000000);
747 out_be32(port->utl_base + PEUTL_IPHBSZ, 0x08000000);
748 out_be32(port->utl_base + PEUTL_IPDBSZ, 0x10000000);
749 out_be32(port->utl_base + PEUTL_RCIRQEN, 0x00f00000);
750 out_be32(port->utl_base + PEUTL_PCTL, 0x80800066);
755 static int ppc440speB_pciex_init_utl(struct ppc4xx_pciex_port *port)
757 /* Report CRS to the operating system */
758 out_be32(port->utl_base + PEUTL_PBCTL, 0x08000000);
763 static struct ppc4xx_pciex_hwops ppc440speA_pcie_hwops __initdata =
765 .core_init = ppc440spe_pciex_core_init,
766 .port_init_hw = ppc440speA_pciex_init_port_hw,
767 .setup_utl = ppc440speA_pciex_init_utl,
770 static struct ppc4xx_pciex_hwops ppc440speB_pcie_hwops __initdata =
772 .core_init = ppc440spe_pciex_core_init,
773 .port_init_hw = ppc440speB_pciex_init_port_hw,
774 .setup_utl = ppc440speB_pciex_init_utl,
777 static int __init ppc460ex_pciex_core_init(struct device_node *np)
779 /* Nothing to do, return 2 ports */
783 static int ppc460ex_pciex_init_port_hw(struct ppc4xx_pciex_port *port)
788 if (port->endpoint) {
789 val = PTYPE_LEGACY_ENDPOINT << 20;
790 utlset1 = 0x20222222;
792 val = PTYPE_ROOT_PORT << 20;
793 utlset1 = 0x21222222;
796 if (port->index == 0) {
797 val |= LNKW_X1 << 12;
799 val |= LNKW_X4 << 12;
800 utlset1 |= 0x00101101;
803 mtdcri(SDR0, port->sdr_base + PESDRn_DLPSET, val);
804 mtdcri(SDR0, port->sdr_base + PESDRn_UTLSET1, utlset1);
805 mtdcri(SDR0, port->sdr_base + PESDRn_UTLSET2, 0x01210000);
807 switch (port->index) {
809 mtdcri(SDR0, PESDR0_460EX_L0CDRCTL, 0x00003230);
810 mtdcri(SDR0, PESDR0_460EX_L0DRV, 0x00000136);
811 mtdcri(SDR0, PESDR0_460EX_L0CLK, 0x00000006);
813 mtdcri(SDR0, PESDR0_460EX_PHY_CTL_RST,0x10000000);
817 mtdcri(SDR0, PESDR1_460EX_L0CDRCTL, 0x00003230);
818 mtdcri(SDR0, PESDR1_460EX_L1CDRCTL, 0x00003230);
819 mtdcri(SDR0, PESDR1_460EX_L2CDRCTL, 0x00003230);
820 mtdcri(SDR0, PESDR1_460EX_L3CDRCTL, 0x00003230);
821 mtdcri(SDR0, PESDR1_460EX_L0DRV, 0x00000136);
822 mtdcri(SDR0, PESDR1_460EX_L1DRV, 0x00000136);
823 mtdcri(SDR0, PESDR1_460EX_L2DRV, 0x00000136);
824 mtdcri(SDR0, PESDR1_460EX_L3DRV, 0x00000136);
825 mtdcri(SDR0, PESDR1_460EX_L0CLK, 0x00000006);
826 mtdcri(SDR0, PESDR1_460EX_L1CLK, 0x00000006);
827 mtdcri(SDR0, PESDR1_460EX_L2CLK, 0x00000006);
828 mtdcri(SDR0, PESDR1_460EX_L3CLK, 0x00000006);
830 mtdcri(SDR0, PESDR1_460EX_PHY_CTL_RST,0x10000000);
834 mtdcri(SDR0, port->sdr_base + PESDRn_RCSSET,
835 mfdcri(SDR0, port->sdr_base + PESDRn_RCSSET) |
836 (PESDRx_RCSSET_RSTGU | PESDRx_RCSSET_RSTPYN));
838 /* Poll for PHY reset */
839 /* XXX FIXME add timeout */
840 switch (port->index) {
842 while (!(mfdcri(SDR0, PESDR0_460EX_RSTSTA) & 0x1))
846 while (!(mfdcri(SDR0, PESDR1_460EX_RSTSTA) & 0x1))
851 mtdcri(SDR0, port->sdr_base + PESDRn_RCSSET,
852 (mfdcri(SDR0, port->sdr_base + PESDRn_RCSSET) &
853 ~(PESDRx_RCSSET_RSTGU | PESDRx_RCSSET_RSTDL)) |
854 PESDRx_RCSSET_RSTPYN);
861 static int ppc460ex_pciex_init_utl(struct ppc4xx_pciex_port *port)
863 dcr_write(port->dcrs, DCRO_PEGPL_SPECIAL, 0x0);
866 * Set buffer allocations and then assert VRB and TXE.
868 out_be32(port->utl_base + PEUTL_PBCTL, 0x0800000c);
869 out_be32(port->utl_base + PEUTL_OUTTR, 0x08000000);
870 out_be32(port->utl_base + PEUTL_INTR, 0x02000000);
871 out_be32(port->utl_base + PEUTL_OPDBSZ, 0x04000000);
872 out_be32(port->utl_base + PEUTL_PBBSZ, 0x00000000);
873 out_be32(port->utl_base + PEUTL_IPHBSZ, 0x02000000);
874 out_be32(port->utl_base + PEUTL_IPDBSZ, 0x04000000);
875 out_be32(port->utl_base + PEUTL_RCIRQEN,0x00f00000);
876 out_be32(port->utl_base + PEUTL_PCTL, 0x80800066);
881 static struct ppc4xx_pciex_hwops ppc460ex_pcie_hwops __initdata =
883 .core_init = ppc460ex_pciex_core_init,
884 .port_init_hw = ppc460ex_pciex_init_port_hw,
885 .setup_utl = ppc460ex_pciex_init_utl,
888 #endif /* CONFIG_44x */
892 static int __init ppc405ex_pciex_core_init(struct device_node *np)
894 /* Nothing to do, return 2 ports */
898 static void ppc405ex_pcie_phy_reset(struct ppc4xx_pciex_port *port)
900 /* Assert the PE0_PHY reset */
901 mtdcri(SDR0, port->sdr_base + PESDRn_RCSSET, 0x01010000);
904 /* deassert the PE0_hotreset */
906 mtdcri(SDR0, port->sdr_base + PESDRn_RCSSET, 0x01111000);
908 mtdcri(SDR0, port->sdr_base + PESDRn_RCSSET, 0x01101000);
910 /* poll for phy !reset */
911 /* XXX FIXME add timeout */
912 while (!(mfdcri(SDR0, port->sdr_base + PESDRn_405EX_PHYSTA) & 0x00001000))
915 /* deassert the PE0_gpl_utl_reset */
916 mtdcri(SDR0, port->sdr_base + PESDRn_RCSSET, 0x00101000);
919 static int ppc405ex_pciex_init_port_hw(struct ppc4xx_pciex_port *port)
924 val = PTYPE_LEGACY_ENDPOINT;
926 val = PTYPE_ROOT_PORT;
928 mtdcri(SDR0, port->sdr_base + PESDRn_DLPSET,
929 1 << 24 | val << 20 | LNKW_X1 << 12);
931 mtdcri(SDR0, port->sdr_base + PESDRn_UTLSET1, 0x00000000);
932 mtdcri(SDR0, port->sdr_base + PESDRn_UTLSET2, 0x01010000);
933 mtdcri(SDR0, port->sdr_base + PESDRn_405EX_PHYSET1, 0x720F0000);
934 mtdcri(SDR0, port->sdr_base + PESDRn_405EX_PHYSET2, 0x70600003);
937 * Only reset the PHY when no link is currently established.
938 * This is for the Atheros PCIe board which has problems to establish
939 * the link (again) after this PHY reset. All other currently tested
940 * PCIe boards don't show this problem.
941 * This has to be re-tested and fixed in a later release!
943 val = mfdcri(SDR0, port->sdr_base + PESDRn_LOOP);
944 if (!(val & 0x00001000))
945 ppc405ex_pcie_phy_reset(port);
947 dcr_write(port->dcrs, DCRO_PEGPL_CFG, 0x10000000); /* guarded on */
954 static int ppc405ex_pciex_init_utl(struct ppc4xx_pciex_port *port)
956 dcr_write(port->dcrs, DCRO_PEGPL_SPECIAL, 0x0);
959 * Set buffer allocations and then assert VRB and TXE.
961 out_be32(port->utl_base + PEUTL_OUTTR, 0x02000000);
962 out_be32(port->utl_base + PEUTL_INTR, 0x02000000);
963 out_be32(port->utl_base + PEUTL_OPDBSZ, 0x04000000);
964 out_be32(port->utl_base + PEUTL_PBBSZ, 0x21000000);
965 out_be32(port->utl_base + PEUTL_IPHBSZ, 0x02000000);
966 out_be32(port->utl_base + PEUTL_IPDBSZ, 0x04000000);
967 out_be32(port->utl_base + PEUTL_RCIRQEN, 0x00f00000);
968 out_be32(port->utl_base + PEUTL_PCTL, 0x80800066);
970 out_be32(port->utl_base + PEUTL_PBCTL, 0x08000000);
975 static struct ppc4xx_pciex_hwops ppc405ex_pcie_hwops __initdata =
977 .core_init = ppc405ex_pciex_core_init,
978 .port_init_hw = ppc405ex_pciex_init_port_hw,
979 .setup_utl = ppc405ex_pciex_init_utl,
982 #endif /* CONFIG_40x */
985 /* Check that the core has been initied and if not, do it */
986 static int __init ppc4xx_pciex_check_core_init(struct device_node *np)
988 static int core_init;
995 if (of_device_is_compatible(np, "ibm,plb-pciex-440spe")) {
996 if (ppc440spe_revA())
997 ppc4xx_pciex_hwops = &ppc440speA_pcie_hwops;
999 ppc4xx_pciex_hwops = &ppc440speB_pcie_hwops;
1001 if (of_device_is_compatible(np, "ibm,plb-pciex-460ex"))
1002 ppc4xx_pciex_hwops = &ppc460ex_pcie_hwops;
1003 #endif /* CONFIG_44x */
1005 if (of_device_is_compatible(np, "ibm,plb-pciex-405ex"))
1006 ppc4xx_pciex_hwops = &ppc405ex_pcie_hwops;
1008 if (ppc4xx_pciex_hwops == NULL) {
1009 printk(KERN_WARNING "PCIE: unknown host type %s\n",
1014 count = ppc4xx_pciex_hwops->core_init(np);
1016 ppc4xx_pciex_ports =
1017 kzalloc(count * sizeof(struct ppc4xx_pciex_port),
1019 if (ppc4xx_pciex_ports) {
1020 ppc4xx_pciex_port_count = count;
1023 printk(KERN_WARNING "PCIE: failed to allocate ports array\n");
1029 static void __init ppc4xx_pciex_port_init_mapping(struct ppc4xx_pciex_port *port)
1031 /* We map PCI Express configuration based on the reg property */
1032 dcr_write(port->dcrs, DCRO_PEGPL_CFGBAH,
1033 RES_TO_U32_HIGH(port->cfg_space.start));
1034 dcr_write(port->dcrs, DCRO_PEGPL_CFGBAL,
1035 RES_TO_U32_LOW(port->cfg_space.start));
1037 /* XXX FIXME: Use size from reg property. For now, map 512M */
1038 dcr_write(port->dcrs, DCRO_PEGPL_CFGMSK, 0xe0000001);
1040 /* We map UTL registers based on the reg property */
1041 dcr_write(port->dcrs, DCRO_PEGPL_REGBAH,
1042 RES_TO_U32_HIGH(port->utl_regs.start));
1043 dcr_write(port->dcrs, DCRO_PEGPL_REGBAL,
1044 RES_TO_U32_LOW(port->utl_regs.start));
1046 /* XXX FIXME: Use size from reg property */
1047 dcr_write(port->dcrs, DCRO_PEGPL_REGMSK, 0x00007001);
1049 /* Disable all other outbound windows */
1050 dcr_write(port->dcrs, DCRO_PEGPL_OMR1MSKL, 0);
1051 dcr_write(port->dcrs, DCRO_PEGPL_OMR2MSKL, 0);
1052 dcr_write(port->dcrs, DCRO_PEGPL_OMR3MSKL, 0);
1053 dcr_write(port->dcrs, DCRO_PEGPL_MSGMSK, 0);
1056 static int __init ppc4xx_pciex_wait_on_sdr(struct ppc4xx_pciex_port *port,
1057 unsigned int sdr_offset,
1064 while(timeout_ms--) {
1065 val = mfdcri(SDR0, port->sdr_base + sdr_offset);
1066 if ((val & mask) == value) {
1067 pr_debug("PCIE%d: Wait on SDR %x success with tm %d (%08x)\n",
1068 port->index, sdr_offset, timeout_ms, val);
1076 static int __init ppc4xx_pciex_port_init(struct ppc4xx_pciex_port *port)
1081 if (ppc4xx_pciex_hwops->port_init_hw)
1082 rc = ppc4xx_pciex_hwops->port_init_hw(port);
1086 printk(KERN_INFO "PCIE%d: Checking link...\n",
1089 /* Wait for reset to complete */
1090 if (ppc4xx_pciex_wait_on_sdr(port, PESDRn_RCSSTS, 1 << 20, 0, 10)) {
1091 printk(KERN_WARNING "PCIE%d: PGRST failed\n",
1096 /* Check for card presence detect if supported, if not, just wait for
1097 * link unconditionally.
1099 * note that we don't fail if there is no link, we just filter out
1100 * config space accesses. That way, it will be easier to implement
1103 if (!port->has_ibpre ||
1104 !ppc4xx_pciex_wait_on_sdr(port, PESDRn_LOOP,
1105 1 << 28, 1 << 28, 100)) {
1107 "PCIE%d: Device detected, waiting for link...\n",
1109 if (ppc4xx_pciex_wait_on_sdr(port, PESDRn_LOOP,
1110 0x1000, 0x1000, 2000))
1112 "PCIE%d: Link up failed\n", port->index);
1115 "PCIE%d: link is up !\n", port->index);
1119 printk(KERN_INFO "PCIE%d: No device detected.\n", port->index);
1122 * Initialize mapping: disable all regions and configure
1123 * CFG and REG regions based on resources in the device tree
1125 ppc4xx_pciex_port_init_mapping(port);
1130 port->utl_base = ioremap(port->utl_regs.start, 0x100);
1131 BUG_ON(port->utl_base == NULL);
1134 * Setup UTL registers --BenH.
1136 if (ppc4xx_pciex_hwops->setup_utl)
1137 ppc4xx_pciex_hwops->setup_utl(port);
1140 * Check for VC0 active and assert RDY.
1143 ppc4xx_pciex_wait_on_sdr(port, PESDRn_RCSSTS,
1144 1 << 16, 1 << 16, 5000)) {
1145 printk(KERN_INFO "PCIE%d: VC0 not active\n", port->index);
1149 dcri_clrset(SDR0, port->sdr_base + PESDRn_RCSSET, 0, 1 << 20);
1155 static int ppc4xx_pciex_validate_bdf(struct ppc4xx_pciex_port *port,
1156 struct pci_bus *bus,
1161 /* Endpoint can not generate upstream(remote) config cycles */
1162 if (port->endpoint && bus->number != port->hose->first_busno)
1163 return PCIBIOS_DEVICE_NOT_FOUND;
1165 /* Check we are within the mapped range */
1166 if (bus->number > port->hose->last_busno) {
1168 printk(KERN_WARNING "Warning! Probing bus %u"
1169 " out of range !\n", bus->number);
1172 return PCIBIOS_DEVICE_NOT_FOUND;
1175 /* The root complex has only one device / function */
1176 if (bus->number == port->hose->first_busno && devfn != 0)
1177 return PCIBIOS_DEVICE_NOT_FOUND;
1179 /* The other side of the RC has only one device as well */
1180 if (bus->number == (port->hose->first_busno + 1) &&
1181 PCI_SLOT(devfn) != 0)
1182 return PCIBIOS_DEVICE_NOT_FOUND;
1184 /* Check if we have a link */
1185 if ((bus->number != port->hose->first_busno) && !port->link)
1186 return PCIBIOS_DEVICE_NOT_FOUND;
1191 static void __iomem *ppc4xx_pciex_get_config_base(struct ppc4xx_pciex_port *port,
1192 struct pci_bus *bus,
1197 /* Remove the casts when we finally remove the stupid volatile
1198 * in struct pci_controller
1200 if (bus->number == port->hose->first_busno)
1201 return (void __iomem *)port->hose->cfg_addr;
1203 relbus = bus->number - (port->hose->first_busno + 1);
1204 return (void __iomem *)port->hose->cfg_data +
1205 ((relbus << 20) | (devfn << 12));
1208 static int ppc4xx_pciex_read_config(struct pci_bus *bus, unsigned int devfn,
1209 int offset, int len, u32 *val)
1211 struct pci_controller *hose = (struct pci_controller *) bus->sysdata;
1212 struct ppc4xx_pciex_port *port =
1213 &ppc4xx_pciex_ports[hose->indirect_type];
1217 BUG_ON(hose != port->hose);
1219 if (ppc4xx_pciex_validate_bdf(port, bus, devfn) != 0)
1220 return PCIBIOS_DEVICE_NOT_FOUND;
1222 addr = ppc4xx_pciex_get_config_base(port, bus, devfn);
1225 * Reading from configuration space of non-existing device can
1226 * generate transaction errors. For the read duration we suppress
1227 * assertion of machine check exceptions to avoid those.
1229 gpl_cfg = dcr_read(port->dcrs, DCRO_PEGPL_CFG);
1230 dcr_write(port->dcrs, DCRO_PEGPL_CFG, gpl_cfg | GPL_DMER_MASK_DISA);
1232 /* Make sure no CRS is recorded */
1233 out_be32(port->utl_base + PEUTL_RCSTA, 0x00040000);
1237 *val = in_8((u8 *)(addr + offset));
1240 *val = in_le16((u16 *)(addr + offset));
1243 *val = in_le32((u32 *)(addr + offset));
1247 pr_debug("pcie-config-read: bus=%3d [%3d..%3d] devfn=0x%04x"
1248 " offset=0x%04x len=%d, addr=0x%p val=0x%08x\n",
1249 bus->number, hose->first_busno, hose->last_busno,
1250 devfn, offset, len, addr + offset, *val);
1252 /* Check for CRS (440SPe rev B does that for us but heh ..) */
1253 if (in_be32(port->utl_base + PEUTL_RCSTA) & 0x00040000) {
1254 pr_debug("Got CRS !\n");
1255 if (len != 4 || offset != 0)
1256 return PCIBIOS_DEVICE_NOT_FOUND;
1260 dcr_write(port->dcrs, DCRO_PEGPL_CFG, gpl_cfg);
1262 return PCIBIOS_SUCCESSFUL;
1265 static int ppc4xx_pciex_write_config(struct pci_bus *bus, unsigned int devfn,
1266 int offset, int len, u32 val)
1268 struct pci_controller *hose = (struct pci_controller *) bus->sysdata;
1269 struct ppc4xx_pciex_port *port =
1270 &ppc4xx_pciex_ports[hose->indirect_type];
1274 if (ppc4xx_pciex_validate_bdf(port, bus, devfn) != 0)
1275 return PCIBIOS_DEVICE_NOT_FOUND;
1277 addr = ppc4xx_pciex_get_config_base(port, bus, devfn);
1280 * Reading from configuration space of non-existing device can
1281 * generate transaction errors. For the read duration we suppress
1282 * assertion of machine check exceptions to avoid those.
1284 gpl_cfg = dcr_read(port->dcrs, DCRO_PEGPL_CFG);
1285 dcr_write(port->dcrs, DCRO_PEGPL_CFG, gpl_cfg | GPL_DMER_MASK_DISA);
1287 pr_debug("pcie-config-write: bus=%3d [%3d..%3d] devfn=0x%04x"
1288 " offset=0x%04x len=%d, addr=0x%p val=0x%08x\n",
1289 bus->number, hose->first_busno, hose->last_busno,
1290 devfn, offset, len, addr + offset, val);
1294 out_8((u8 *)(addr + offset), val);
1297 out_le16((u16 *)(addr + offset), val);
1300 out_le32((u32 *)(addr + offset), val);
1304 dcr_write(port->dcrs, DCRO_PEGPL_CFG, gpl_cfg);
1306 return PCIBIOS_SUCCESSFUL;
1309 static struct pci_ops ppc4xx_pciex_pci_ops =
1311 .read = ppc4xx_pciex_read_config,
1312 .write = ppc4xx_pciex_write_config,
1315 static void __init ppc4xx_configure_pciex_POMs(struct ppc4xx_pciex_port *port,
1316 struct pci_controller *hose,
1317 void __iomem *mbase)
1319 u32 lah, lal, pciah, pcial, sa;
1322 /* Setup outbound memory windows */
1323 for (i = j = 0; i < 3; i++) {
1324 struct resource *res = &hose->mem_resources[i];
1326 /* we only care about memory windows */
1327 if (!(res->flags & IORESOURCE_MEM))
1330 printk(KERN_WARNING "%s: Too many ranges\n",
1331 port->node->full_name);
1335 /* Calculate register values */
1336 lah = RES_TO_U32_HIGH(res->start);
1337 lal = RES_TO_U32_LOW(res->start);
1338 pciah = RES_TO_U32_HIGH(res->start - hose->pci_mem_offset);
1339 pcial = RES_TO_U32_LOW(res->start - hose->pci_mem_offset);
1340 sa = res->end + 1 - res->start;
1341 if (!is_power_of_2(sa) || sa < 0x100000 ||
1343 printk(KERN_WARNING "%s: Resource out of range\n",
1344 port->node->full_name);
1347 sa = (0xffffffffu << ilog2(sa)) | 0x1;
1349 /* Program register values */
1352 out_le32(mbase + PECFG_POM0LAH, pciah);
1353 out_le32(mbase + PECFG_POM0LAL, pcial);
1354 dcr_write(port->dcrs, DCRO_PEGPL_OMR1BAH, lah);
1355 dcr_write(port->dcrs, DCRO_PEGPL_OMR1BAL, lal);
1356 dcr_write(port->dcrs, DCRO_PEGPL_OMR1MSKH, 0x7fffffff);
1357 dcr_write(port->dcrs, DCRO_PEGPL_OMR1MSKL, sa | 3);
1360 out_le32(mbase + PECFG_POM1LAH, pciah);
1361 out_le32(mbase + PECFG_POM1LAL, pcial);
1362 dcr_write(port->dcrs, DCRO_PEGPL_OMR2BAH, lah);
1363 dcr_write(port->dcrs, DCRO_PEGPL_OMR2BAL, lal);
1364 dcr_write(port->dcrs, DCRO_PEGPL_OMR2MSKH, 0x7fffffff);
1365 dcr_write(port->dcrs, DCRO_PEGPL_OMR2MSKL, sa | 3);
1371 /* Configure IO, always 64K starting at 0 */
1372 if (hose->io_resource.flags & IORESOURCE_IO) {
1373 lah = RES_TO_U32_HIGH(hose->io_base_phys);
1374 lal = RES_TO_U32_LOW(hose->io_base_phys);
1375 out_le32(mbase + PECFG_POM2LAH, 0);
1376 out_le32(mbase + PECFG_POM2LAL, 0);
1377 dcr_write(port->dcrs, DCRO_PEGPL_OMR3BAH, lah);
1378 dcr_write(port->dcrs, DCRO_PEGPL_OMR3BAL, lal);
1379 dcr_write(port->dcrs, DCRO_PEGPL_OMR3MSKH, 0x7fffffff);
1380 dcr_write(port->dcrs, DCRO_PEGPL_OMR3MSKL, 0xffff0000 | 3);
1384 static void __init ppc4xx_configure_pciex_PIMs(struct ppc4xx_pciex_port *port,
1385 struct pci_controller *hose,
1386 void __iomem *mbase,
1387 struct resource *res)
1389 resource_size_t size = res->end - res->start + 1;
1392 /* Calculate window size */
1393 sa = (0xffffffffffffffffull << ilog2(size));;
1394 if (res->flags & IORESOURCE_PREFETCH)
1397 out_le32(mbase + PECFG_BAR0HMPA, RES_TO_U32_HIGH(sa));
1398 out_le32(mbase + PECFG_BAR0LMPA, RES_TO_U32_LOW(sa));
1400 /* The setup of the split looks weird to me ... let's see if it works */
1401 out_le32(mbase + PECFG_PIM0LAL, 0x00000000);
1402 out_le32(mbase + PECFG_PIM0LAH, 0x00000000);
1403 out_le32(mbase + PECFG_PIM1LAL, 0x00000000);
1404 out_le32(mbase + PECFG_PIM1LAH, 0x00000000);
1405 out_le32(mbase + PECFG_PIM01SAH, 0xffff0000);
1406 out_le32(mbase + PECFG_PIM01SAL, 0x00000000);
1408 /* Enable inbound mapping */
1409 out_le32(mbase + PECFG_PIMEN, 0x1);
1411 out_le32(mbase + PCI_BASE_ADDRESS_0, RES_TO_U32_LOW(res->start));
1412 out_le32(mbase + PCI_BASE_ADDRESS_1, RES_TO_U32_HIGH(res->start));
1414 /* Enable I/O, Mem, and Busmaster cycles */
1415 out_le16(mbase + PCI_COMMAND,
1416 in_le16(mbase + PCI_COMMAND) |
1417 PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
1420 static void __init ppc4xx_pciex_port_setup_hose(struct ppc4xx_pciex_port *port)
1422 struct resource dma_window;
1423 struct pci_controller *hose = NULL;
1424 const int *bus_range;
1425 int primary = 0, busses;
1426 void __iomem *mbase = NULL, *cfg_data = NULL;
1428 /* XXX FIXME: Handle endpoint mode properly */
1429 if (port->endpoint) {
1430 printk(KERN_WARNING "PCIE%d: Port in endpoint mode !\n",
1435 /* Check if primary bridge */
1436 if (of_get_property(port->node, "primary", NULL))
1439 /* Get bus range if any */
1440 bus_range = of_get_property(port->node, "bus-range", NULL);
1442 /* Allocate the host controller data structure */
1443 hose = pcibios_alloc_controller(port->node);
1447 /* We stick the port number in "indirect_type" so the config space
1448 * ops can retrieve the port data structure easily
1450 hose->indirect_type = port->index;
1453 hose->first_busno = bus_range ? bus_range[0] : 0x0;
1454 hose->last_busno = bus_range ? bus_range[1] : 0xff;
1456 /* Because of how big mapping the config space is (1M per bus), we
1457 * limit how many busses we support. In the long run, we could replace
1458 * that with something akin to kmap_atomic instead. We set aside 1 bus
1459 * for the host itself too.
1461 busses = hose->last_busno - hose->first_busno; /* This is off by 1 */
1462 if (busses > MAX_PCIE_BUS_MAPPED) {
1463 busses = MAX_PCIE_BUS_MAPPED;
1464 hose->last_busno = hose->first_busno + busses;
1467 /* We map the external config space in cfg_data and the host config
1468 * space in cfg_addr. External space is 1M per bus, internal space
1471 cfg_data = ioremap(port->cfg_space.start +
1472 (hose->first_busno + 1) * 0x100000,
1474 mbase = ioremap(port->cfg_space.start + 0x10000000, 0x1000);
1475 if (cfg_data == NULL || mbase == NULL) {
1476 printk(KERN_ERR "%s: Can't map config space !",
1477 port->node->full_name);
1481 hose->cfg_data = cfg_data;
1482 hose->cfg_addr = mbase;
1484 pr_debug("PCIE %s, bus %d..%d\n", port->node->full_name,
1485 hose->first_busno, hose->last_busno);
1486 pr_debug(" config space mapped at: root @0x%p, other @0x%p\n",
1487 hose->cfg_addr, hose->cfg_data);
1489 /* Setup config space */
1490 hose->ops = &ppc4xx_pciex_pci_ops;
1492 mbase = (void __iomem *)hose->cfg_addr;
1495 * Set bus numbers on our root port
1497 out_8(mbase + PCI_PRIMARY_BUS, hose->first_busno);
1498 out_8(mbase + PCI_SECONDARY_BUS, hose->first_busno + 1);
1499 out_8(mbase + PCI_SUBORDINATE_BUS, hose->last_busno);
1502 * OMRs are already reset, also disable PIMs
1504 out_le32(mbase + PECFG_PIMEN, 0);
1506 /* Parse outbound mapping resources */
1507 pci_process_bridge_OF_ranges(hose, port->node, primary);
1509 /* Parse inbound mapping resources */
1510 if (ppc4xx_parse_dma_ranges(hose, mbase, &dma_window) != 0)
1513 /* Configure outbound ranges POMs */
1514 ppc4xx_configure_pciex_POMs(port, hose, mbase);
1516 /* Configure inbound ranges PIMs */
1517 ppc4xx_configure_pciex_PIMs(port, hose, mbase, &dma_window);
1519 /* The root complex doesn't show up if we don't set some vendor
1520 * and device IDs into it. Those are the same bogus one that the
1521 * initial code in arch/ppc add. We might want to change that.
1523 out_le16(mbase + 0x200, 0xaaa0 + port->index);
1524 out_le16(mbase + 0x202, 0xbed0 + port->index);
1526 /* Set Class Code to PCI-PCI bridge and Revision Id to 1 */
1527 out_le32(mbase + 0x208, 0x06040001);
1529 printk(KERN_INFO "PCIE%d: successfully set as root-complex\n",
1534 pcibios_free_controller(hose);
1541 static void __init ppc4xx_probe_pciex_bridge(struct device_node *np)
1543 struct ppc4xx_pciex_port *port;
1548 /* First, proceed to core initialization as we assume there's
1549 * only one PCIe core in the system
1551 if (ppc4xx_pciex_check_core_init(np))
1554 /* Get the port number from the device-tree */
1555 pval = of_get_property(np, "port", NULL);
1557 printk(KERN_ERR "PCIE: Can't find port number for %s\n",
1562 if (portno >= ppc4xx_pciex_port_count) {
1563 printk(KERN_ERR "PCIE: port number out of range for %s\n",
1567 port = &ppc4xx_pciex_ports[portno];
1568 port->index = portno;
1569 port->node = of_node_get(np);
1570 pval = of_get_property(np, "sdr-base", NULL);
1572 printk(KERN_ERR "PCIE: missing sdr-base for %s\n",
1576 port->sdr_base = *pval;
1578 /* XXX Currently, we only support root complex mode */
1581 /* Fetch config space registers address */
1582 if (of_address_to_resource(np, 0, &port->cfg_space)) {
1583 printk(KERN_ERR "%s: Can't get PCI-E config space !",
1587 /* Fetch host bridge internal registers address */
1588 if (of_address_to_resource(np, 1, &port->utl_regs)) {
1589 printk(KERN_ERR "%s: Can't get UTL register base !",
1595 dcrs = dcr_resource_start(np, 0);
1597 printk(KERN_ERR "%s: Can't get DCR register base !",
1601 port->dcrs = dcr_map(np, dcrs, dcr_resource_len(np, 0));
1603 /* Initialize the port specific registers */
1604 if (ppc4xx_pciex_port_init(port)) {
1605 printk(KERN_WARNING "PCIE%d: Port init failed\n", port->index);
1609 /* Setup the linux hose data structure */
1610 ppc4xx_pciex_port_setup_hose(port);
1613 #endif /* CONFIG_PPC4xx_PCI_EXPRESS */
1615 static int __init ppc4xx_pci_find_bridges(void)
1617 struct device_node *np;
1619 #ifdef CONFIG_PPC4xx_PCI_EXPRESS
1620 for_each_compatible_node(np, NULL, "ibm,plb-pciex")
1621 ppc4xx_probe_pciex_bridge(np);
1623 for_each_compatible_node(np, NULL, "ibm,plb-pcix")
1624 ppc4xx_probe_pcix_bridge(np);
1625 for_each_compatible_node(np, NULL, "ibm,plb-pci")
1626 ppc4xx_probe_pci_bridge(np);
1630 arch_initcall(ppc4xx_pci_find_bridges);