19 #include <linux/kernel.h>
20 #include <linux/pci.h>
21 #include <linux/string.h>
24 #include <linux/export.h>
28 #include <linux/list.h>
32 #include <linux/slab.h>
34 #include <asm/processor.h>
37 #include <asm/pci-bridge.h>
38 #include <asm/byteorder.h>
39 #include <asm/machdep.h>
47 static int global_phb_number;
73 spin_lock(&hose_spinlock);
74 phb->global_number = global_phb_number++;
76 spin_unlock(&hose_spinlock);
86 PHB_SET_NODE(phb, nid);
94 spin_lock(&hose_spinlock);
96 spin_unlock(&hose_spinlock);
111 if (
ppc_md.pcibios_window_alignment)
112 return ppc_md.pcibios_window_alignment(bus, type);
125 return hose->pci_io_size;
127 return resource_size(&hose->io_resource);
137 spin_lock(&hose_spinlock);
139 size = pcibios_io_size(hose);
140 if (address >= hose->io_base_virt &&
141 address < (hose->io_base_virt + size)) {
146 spin_unlock(&hose_spinlock);
154 unsigned long ret = ~0;
156 spin_lock(&hose_spinlock);
158 size = pcibios_io_size(hose);
159 if (address >= hose->io_base_phys &&
160 address < (hose->io_base_phys + size)) {
163 ret = base + (address - hose->io_base_phys);
167 spin_unlock(&hose_spinlock);
180 return hose->global_number;
196 if (hose->dn == node)
210 np = pci_device_to_OF_node(pdev);
233 pr_debug(
"PCI: Try to map irq for %s...\n", pci_name(pci_dev));
236 memset(&oirq, 0xff,
sizeof(oirq));
254 line == 0xff || line == 0) {
257 pr_debug(
" No map ! Using line %d (pin %d) from PCI config\n",
264 pr_debug(
" Got one, spec %d cells (0x%08x 0x%08x...) on %s\n",
265 oirq.size, oirq.specifier[0], oirq.specifier[1],
266 of_node_full_name(oirq.controller));
276 pr_debug(
" Mapped to linux irq %d\n", virq);
300 static struct resource *__pci_mmap_make_offset(
struct pci_dev *dev,
305 unsigned long io_offset = 0;
314 *offset += hose->pci_mem_offset;
318 io_offset = (
unsigned long)hose->io_base_virt -
_IO_BASE;
319 *offset += io_offset;
336 if ((flags & res_bit) == 0)
345 *offset += hose->io_base_phys - io_offset;
356 static pgprot_t __pci_mmap_set_pgprot(
struct pci_dev *dev,
struct resource *rp,
371 else if (write_combine == 0) {
393 struct pci_dev *pdev =
NULL;
405 int flags = rp->
flags;
426 pr_debug(
"PCI: Non-PCI map for %llx, prot: %lx\n",
427 (
unsigned long long)offset,
pgprot_val(prot));
451 rp = __pci_mmap_make_offset(dev, &offset, mmap_state);
458 mmap_state, write_combine);
471 struct resource *rp = &hose->io_resource;
486 addr = hose->io_base_virt +
port;
490 *((
u8 *)val) =
in_8(addr);
511 struct resource *rp = &hose->io_resource;
526 addr = hose->io_base_virt +
port;
535 out_8(addr, val >> 24);
562 pr_debug(
"pci_mmap_legacy_page_range(%04x:%02x, %s @%llx..%llx)\n",
565 (
unsigned long long)offset,
566 (
unsigned long long)(offset + size - 1));
576 if ((offset + size) > hose->isa_mem_size) {
578 "Process %s (pid:%d) mapped non-existing PCI legacy memory for 0%04x:%02x\n",
584 offset += hose->isa_mem_phys;
586 unsigned long io_offset = (
unsigned long)hose->io_base_virt -
_IO_BASE;
587 unsigned long roffset = offset + io_offset;
588 rp = &hose->io_resource;
591 if (roffset < rp->
start || (roffset + size) > rp->
end)
593 offset += hose->io_base_phys;
595 pr_debug(
" -> mapping phys %llx\n", (
unsigned long long)offset);
636 offset = hose->pci_mem_offset;
684 int memno = 0, isa_hole = -1;
687 unsigned long long isa_mb = 0;
691 dev->
full_name, primary ?
"(primary)" :
"");
699 while ((rlen -= np * 4) >= 0) {
701 pci_space = ranges[0];
702 pci_addr = of_read_number(ranges + 1, 2);
704 size = of_read_number(ranges + pna + 3, 2);
712 if (cpu_addr == OF_BAD_ADDR || size == 0)
716 for (; rlen >= np *
sizeof(
u32);
717 ranges += np, rlen -= np * 4) {
718 if (ranges[0] != pci_space)
720 pci_next = of_read_number(ranges + 1, 2);
722 if (pci_next != pci_addr + size ||
723 cpu_next != cpu_addr + size)
725 size += of_read_number(ranges + pna + 3, 2);
730 switch ((pci_space >> 24) & 0x3) {
733 " IO 0x%016llx..0x%016llx -> 0x%016llx\n",
734 cpu_addr, cpu_addr + size - 1, pci_addr);
737 if (hose->pci_io_size) {
739 " \\--> Skipped (too many) !\n");
744 if (size > 0x01000000)
748 hose->io_base_virt =
ioremap(cpu_addr, size);
753 (
unsigned long)hose->io_base_virt;
758 hose->pci_io_size = pci_addr + size;
759 hose->io_base_phys = cpu_addr - pci_addr;
762 res = &hose->io_resource;
764 res->
start = pci_addr;
769 " MEM 0x%016llx..0x%016llx -> 0x%016llx %s\n",
770 cpu_addr, cpu_addr + size - 1, pci_addr,
771 (pci_space & 0x40000000) ?
"Prefetch" :
"");
776 " \\--> Skipped (too many) !\n");
786 hose->isa_mem_size =
size;
794 (isa_hole >= 0 && pci_addr != 0 &&
795 hose->pci_mem_offset == isa_mb))
796 hose->pci_mem_offset = cpu_addr -
pci_addr;
797 else if (pci_addr != 0 &&
798 hose->pci_mem_offset != cpu_addr - pci_addr) {
800 " \\--> Skipped (offset mismatch) !\n");
807 if (pci_space & 0x40000000)
825 if (isa_hole >= 0 && hose->pci_mem_offset != isa_mb) {
826 unsigned int next = isa_hole + 1;
831 sizeof(
struct resource) * (memno - next));
841 if (!pci_has_flag(PCI_ENABLE_PROC_DOMAINS))
843 if (pci_has_flag(PCI_COMPAT_DOMAIN_0))
844 return hose->global_number != 0;
871 if (pci_has_flag(PCI_REASSIGN_ALL_RSRC) ||
872 (res->
start == 0 && !pci_has_flag(PCI_PROBE_ONLY))) {
874 if (!pci_has_flag(PCI_REASSIGN_ALL_RSRC))
875 pr_debug(
"PCI:%s Resource %d %016llx-%016llx [%x] "
878 (
unsigned long long)res->
start,
879 (
unsigned long long)res->
end,
880 (
unsigned int)res->
flags);
887 pr_debug(
"PCI:%s Resource %d %016llx-%016llx [%x]\n",
889 (
unsigned long long)res->
start,\
890 (
unsigned long long)res->
end,
891 (
unsigned int)res->
flags);
895 if (
ppc_md.pcibios_fixup_resources)
896 ppc_md.pcibios_fixup_resources(dev);
909 struct pci_dev *dev = bus->
self;
915 if (pci_has_flag(PCI_PROBE_ONLY))
923 if (res->
start != hose->pci_mem_offset)
937 for (i = 0; i < 3; i++) {
950 if (((res->
start - offset) & 0xfffffffful) != 0)
975 struct pci_dev *dev = bus->
self;
977 pci_bus_for_each_resource(bus, res, i) {
978 if (!res || !res->
flags)
980 if (i >= 3 && bus->
self->transparent)
987 if (pci_has_flag(PCI_REASSIGN_ALL_RSRC)) {
994 pr_debug(
"PCI:%s Bus rsrc %d %016llx-%016llx [%x]\n",
996 (
unsigned long long)res->
start,\
997 (
unsigned long long)res->
end,
998 (
unsigned int)res->
flags);
1003 if (pcibios_uninitialized_bridge_resource(bus, res)) {
1005 pr_debug(
"PCI:%s (unassigned)\n", pci_name(dev));
1014 pcibios_fixup_bridge(bus);
1019 if (
ppc_md.pcibios_fixup_bus)
1020 ppc_md.pcibios_fixup_bus(bus);
1023 if (
ppc_md.pci_dma_bus_setup)
1024 ppc_md.pci_dma_bus_setup(bus);
1029 struct pci_dev *
dev;
1031 pr_debug(
"PCI: Fixup bus devices %d (%s)\n",
1047 set_dma_ops(&dev->
dev, pci_dma_ops);
1051 if (
ppc_md.pci_dma_dev_setup)
1052 ppc_md.pci_dma_dev_setup(dev);
1056 if (
ppc_md.pci_irq_fixup)
1057 ppc_md.pci_irq_fixup(dev);
1090 static int skip_isa_ioresource_align(
struct pci_dev *dev)
1114 struct pci_dev *dev =
data;
1118 if (skip_isa_ioresource_align(dev))
1121 start = (start + 0x3ff) & ~0x3ff;
1132 static int reparent_resources(
struct resource *parent,
1145 if (firstpp ==
NULL)
1148 if (firstpp ==
NULL)
1151 res->
child = *firstpp;
1157 pr_debug(
"PCI: Reparented %s [%llx..%llx] under %s\n",
1159 (
unsigned long long)p->
start,
1160 (
unsigned long long)p->
end, res->
name);
1204 pr_debug(
"PCI: Allocating bus resources for %04x:%02x...\n",
1207 pci_bus_for_each_resource(bus, res, i) {
1213 goto clear_resource;
1229 pr_debug(
"PCI: %s (bus %d) bridge rsrc %d: %016llx-%016llx "
1230 "[0x%x], parent %p (%s)\n",
1231 bus->
self ? pci_name(bus->
self) :
"PHB",
1233 (
unsigned long long)res->
start,
1234 (
unsigned long long)res->
end,
1235 (
unsigned int)res->
flags,
1236 pr, (pr && pr->
name) ? pr->
name :
"nil");
1246 if (reparent_resources(pr, res) == 0)
1249 pr_warning(
"PCI: Cannot allocate resource region "
1250 "%d of PCI bridge %d, will remap\n", i, bus->
number);
1271 pr_debug(
"PCI: Allocating %s: Resource %d: %016llx..%016llx [%x]\n",
1273 (
unsigned long long)r->
start,
1274 (
unsigned long long)r->
end,
1275 (
unsigned int)r->
flags);
1281 " of device %s, will remap\n", idx, pci_name(dev));
1283 pr_debug(
"PCI: parent is %p: %016llx-%016llx [%x]\n",
1285 (
unsigned long long)pr->
start,
1286 (
unsigned long long)pr->
end,
1287 (
unsigned int)pr->
flags);
1295 static void __init pcibios_allocate_resources(
int pass)
1297 struct pci_dev *dev =
NULL;
1319 if (pass == disabled)
1332 pr_debug(
"PCI: Switching off ROM of %s\n",
1336 reg & ~PCI_ROM_ADDRESS_ENABLE);
1342 static void __init pcibios_reserve_legacy_regions(
struct pci_bus *bus)
1357 res->
name =
"Legacy IO";
1360 res->
end = (offset + 0xfff) & 0xfffffffful;
1361 pr_debug(
"Candidate legacy IO: %pR\n", res);
1364 "PCI %04x:%02x Cannot reserve Legacy IO %pR\n",
1371 offset = hose->pci_mem_offset;
1372 pr_debug(
"hose mem offset: %016llx\n", (
unsigned long long)offset);
1373 for (i = 0; i < 3; i++) {
1377 pr_debug(
"hose mem res: %pR\n", pres);
1378 if ((pres->
start - offset) <= 0xa0000 &&
1379 (pres->
end - offset) >= 0xbffff)
1386 res->
name =
"Legacy VGA memory";
1390 pr_debug(
"Candidate VGA memory: %pR\n", res);
1393 "PCI %04x:%02x Cannot reserve VGA memory %pR\n",
1406 pcibios_allocate_resources(0);
1407 pcibios_allocate_resources(1);
1413 if (!pci_has_flag(PCI_PROBE_ONLY)) {
1415 pcibios_reserve_legacy_regions(b);
1421 if (!pci_has_flag(PCI_PROBE_ONLY)) {
1422 pr_debug(
"PCI: Assigning unassigned resources...\n");
1427 if (
ppc_md.pcibios_fixup)
1431 #ifdef CONFIG_HOTPLUG
1440 struct pci_dev *
dev;
1453 "Resource %d: %016llx..%016llx [%x]\n",
1455 (
unsigned long long)r->
start,
1456 (
unsigned long long)r->
end,
1457 (
unsigned int)r->
flags);
1476 pr_debug(
"PCI: Finishing adding to hotplug bus %04x:%02x\n",
1495 if (
ppc_md.pcibios_enable_device_hook)
1496 if (
ppc_md.pcibios_enable_device_hook(dev))
1504 return (
unsigned long) hose->io_base_virt -
_IO_BASE;
1513 res = &hose->io_resource;
1517 " bridge %s (domain %d)\n",
1518 hose->dn->full_name, hose->global_number);
1527 pr_debug(
"PCI: PHB IO resource = %016llx-%016llx [%lx]\n",
1528 (
unsigned long long)res->
start,
1529 (
unsigned long long)res->
end,
1530 (
unsigned long)res->
flags);
1534 for (i = 0; i < 3; ++
i) {
1540 "host bridge %s (domain %d)\n",
1541 hose->dn->full_name, hose->global_number);
1544 res->
start = hose->pci_mem_offset;
1550 pr_debug(
"PCI: PHB MEM resource %d = %016llx-%016llx [%lx]\n", i,
1551 (
unsigned long long)res->
start,
1552 (
unsigned long long)res->
end,
1553 (
unsigned long)res->
flags);
1557 pr_debug(
"PCI: PHB MEM offset = %016llx\n",
1558 (
unsigned long long)hose->pci_mem_offset);
1559 pr_debug(
"PCI: PHB IO offset = %08lx\n",
1560 (
unsigned long)hose->io_base_virt -
_IO_BASE);
1568 #define NULL_PCI_OP(rw, size, type) \
1570 null_##rw##_config_##size(struct pci_dev *dev, int offset, type val) \
1572 return PCIBIOS_DEVICE_NOT_FOUND; \
1576 null_read_config(
struct pci_bus *bus,
unsigned int devfn,
int offset,
1583 null_write_config(
struct pci_bus *bus,
unsigned int devfn,
int offset,
1589 static struct pci_ops null_pci_ops =
1591 .read = null_read_config,
1592 .write = null_write_config,
1609 bus.
ops = hose? hose->
ops: &null_pci_ops;
1613 #define EARLY_PCI_OP(rw, size, type) \
1614 int early_##rw##_config_##size(struct pci_controller *hose, int bus, \
1615 int devfn, int offset, type value) \
1617 return pci_bus_##rw##_config_##size(fake_pci_bus(hose, bus), \
1618 devfn, offset, value); \
1639 return of_node_get(hose->dn);
1653 pr_debug(
"PCI: Scanning PHB %s\n", of_node_full_name(node));
1659 pcibios_setup_phb_resources(hose, &resources);
1668 hose->
ops, hose, &resources);
1670 pr_err(
"Failed to create bus for PCI domain %04x\n",
1671 hose->global_number);
1678 mode = PCI_PROBE_NORMAL;
1679 if (node &&
ppc_md.pci_probe_mode)
1680 mode =
ppc_md.pci_probe_mode(bus);
1681 pr_debug(
" probe mode: %d\n", mode);
1682 if (mode == PCI_PROBE_DEVTREE)
1685 if (mode == PCI_PROBE_NORMAL) {
1694 if (
ppc_md.pcibios_fixup_phb)
1695 ppc_md.pcibios_fixup_phb(hose);
1698 if (bus && !pci_has_flag(PCI_PROBE_ONLY)) {
1701 struct pci_dev *
self = child->
self;
1709 static void fixup_hide_host_resource_fsl(
struct pci_dev *dev)
1711 int i,
class = dev->
class >> 8;
1713 int prog_if = dev->
class & 0xf;