diff options
author | Benjamin Herrenschmidt <benh@kernel.crashing.org> | 2013-05-05 23:40:40 -0400 |
---|---|---|
committer | Benjamin Herrenschmidt <benh@kernel.crashing.org> | 2013-05-05 23:40:40 -0400 |
commit | 3fd47f063b17692e843128e2abda3e697df42198 (patch) | |
tree | d90a5bdd247b0cc5af7cf78cd18cf6e27a884f00 /arch/powerpc/kernel | |
parent | 342d6666f7276723e418b91c885b0c03f02eeaaf (diff) |
powerpc/pci: Support per-aperture memory offset
The PCI core supports an offset per aperture nowadays but our arch
code still has a single offset per host bridge representing the
difference betwen CPU memory addresses and PCI MMIO addresses.
This is a problem as new machines and hypervisor versions are
coming out where the 64-bit windows will have a different offset
(basically mapped 1:1) from the 32-bit windows.
This fixes it by using separate offsets. In the long run, we probably
want to get rid of that intermediary struct pci_controller and have
those directly stored into the pci_host_bridge as they are parsed
but this will be a more invasive change.
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Diffstat (limited to 'arch/powerpc/kernel')
-rw-r--r-- | arch/powerpc/kernel/pci-common.c | 97 | ||||
-rw-r--r-- | arch/powerpc/kernel/pci_32.c | 2 | ||||
-rw-r--r-- | arch/powerpc/kernel/pci_64.c | 2 |
3 files changed, 30 insertions, 71 deletions
diff --git a/arch/powerpc/kernel/pci-common.c b/arch/powerpc/kernel/pci-common.c index cf00588b0023..f5c5c90799a7 100644 --- a/arch/powerpc/kernel/pci-common.c +++ b/arch/powerpc/kernel/pci-common.c | |||
@@ -786,22 +786,8 @@ void pci_process_bridge_OF_ranges(struct pci_controller *hose, | |||
786 | hose->isa_mem_size = size; | 786 | hose->isa_mem_size = size; |
787 | } | 787 | } |
788 | 788 | ||
789 | /* We get the PCI/Mem offset from the first range or | ||
790 | * the, current one if the offset came from an ISA | ||
791 | * hole. If they don't match, bugger. | ||
792 | */ | ||
793 | if (memno == 0 || | ||
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) { | ||
799 | printk(KERN_INFO | ||
800 | " \\--> Skipped (offset mismatch) !\n"); | ||
801 | continue; | ||
802 | } | ||
803 | |||
804 | /* Build resource */ | 789 | /* Build resource */ |
790 | hose->mem_offset[memno] = cpu_addr - pci_addr; | ||
805 | res = &hose->mem_resources[memno++]; | 791 | res = &hose->mem_resources[memno++]; |
806 | res->flags = IORESOURCE_MEM; | 792 | res->flags = IORESOURCE_MEM; |
807 | if (pci_space & 0x40000000) | 793 | if (pci_space & 0x40000000) |
@@ -817,20 +803,6 @@ void pci_process_bridge_OF_ranges(struct pci_controller *hose, | |||
817 | res->child = NULL; | 803 | res->child = NULL; |
818 | } | 804 | } |
819 | } | 805 | } |
820 | |||
821 | /* If there's an ISA hole and the pci_mem_offset is -not- matching | ||
822 | * the ISA hole offset, then we need to remove the ISA hole from | ||
823 | * the resource list for that brige | ||
824 | */ | ||
825 | if (isa_hole >= 0 && hose->pci_mem_offset != isa_mb) { | ||
826 | unsigned int next = isa_hole + 1; | ||
827 | printk(KERN_INFO " Removing ISA hole at 0x%016llx\n", isa_mb); | ||
828 | if (next < memno) | ||
829 | memmove(&hose->mem_resources[isa_hole], | ||
830 | &hose->mem_resources[next], | ||
831 | sizeof(struct resource) * (memno - next)); | ||
832 | hose->mem_resources[--memno].flags = 0; | ||
833 | } | ||
834 | } | 806 | } |
835 | 807 | ||
836 | /* Decide whether to display the domain number in /proc */ | 808 | /* Decide whether to display the domain number in /proc */ |
@@ -916,6 +888,7 @@ static int pcibios_uninitialized_bridge_resource(struct pci_bus *bus, | |||
916 | struct pci_controller *hose = pci_bus_to_host(bus); | 888 | struct pci_controller *hose = pci_bus_to_host(bus); |
917 | struct pci_dev *dev = bus->self; | 889 | struct pci_dev *dev = bus->self; |
918 | resource_size_t offset; | 890 | resource_size_t offset; |
891 | struct pci_bus_region region; | ||
919 | u16 command; | 892 | u16 command; |
920 | int i; | 893 | int i; |
921 | 894 | ||
@@ -925,10 +898,10 @@ static int pcibios_uninitialized_bridge_resource(struct pci_bus *bus, | |||
925 | 898 | ||
926 | /* Job is a bit different between memory and IO */ | 899 | /* Job is a bit different between memory and IO */ |
927 | if (res->flags & IORESOURCE_MEM) { | 900 | if (res->flags & IORESOURCE_MEM) { |
928 | /* If the BAR is non-0 (res != pci_mem_offset) then it's probably been | 901 | pcibios_resource_to_bus(dev, ®ion, res); |
929 | * initialized by somebody | 902 | |
930 | */ | 903 | /* If the BAR is non-0 then it's probably been initialized */ |
931 | if (res->start != hose->pci_mem_offset) | 904 | if (region.start != 0) |
932 | return 0; | 905 | return 0; |
933 | 906 | ||
934 | /* The BAR is 0, let's check if memory decoding is enabled on | 907 | /* The BAR is 0, let's check if memory decoding is enabled on |
@@ -940,11 +913,11 @@ static int pcibios_uninitialized_bridge_resource(struct pci_bus *bus, | |||
940 | 913 | ||
941 | /* Memory decoding is enabled and the BAR is 0. If any of the bridge | 914 | /* Memory decoding is enabled and the BAR is 0. If any of the bridge |
942 | * resources covers that starting address (0 then it's good enough for | 915 | * resources covers that starting address (0 then it's good enough for |
943 | * us for memory | 916 | * us for memory space) |
944 | */ | 917 | */ |
945 | for (i = 0; i < 3; i++) { | 918 | for (i = 0; i < 3; i++) { |
946 | if ((hose->mem_resources[i].flags & IORESOURCE_MEM) && | 919 | if ((hose->mem_resources[i].flags & IORESOURCE_MEM) && |
947 | hose->mem_resources[i].start == hose->pci_mem_offset) | 920 | hose->mem_resources[i].start == hose->mem_offset[i]) |
948 | return 0; | 921 | return 0; |
949 | } | 922 | } |
950 | 923 | ||
@@ -1381,10 +1354,9 @@ static void __init pcibios_reserve_legacy_regions(struct pci_bus *bus) | |||
1381 | 1354 | ||
1382 | no_io: | 1355 | no_io: |
1383 | /* Check for memory */ | 1356 | /* Check for memory */ |
1384 | offset = hose->pci_mem_offset; | ||
1385 | pr_debug("hose mem offset: %016llx\n", (unsigned long long)offset); | ||
1386 | for (i = 0; i < 3; i++) { | 1357 | for (i = 0; i < 3; i++) { |
1387 | pres = &hose->mem_resources[i]; | 1358 | pres = &hose->mem_resources[i]; |
1359 | offset = hose->mem_offset[i]; | ||
1388 | if (!(pres->flags & IORESOURCE_MEM)) | 1360 | if (!(pres->flags & IORESOURCE_MEM)) |
1389 | continue; | 1361 | continue; |
1390 | pr_debug("hose mem res: %pR\n", pres); | 1362 | pr_debug("hose mem res: %pR\n", pres); |
@@ -1524,6 +1496,7 @@ static void pcibios_setup_phb_resources(struct pci_controller *hose, | |||
1524 | struct list_head *resources) | 1496 | struct list_head *resources) |
1525 | { | 1497 | { |
1526 | struct resource *res; | 1498 | struct resource *res; |
1499 | resource_size_t offset; | ||
1527 | int i; | 1500 | int i; |
1528 | 1501 | ||
1529 | /* Hookup PHB IO resource */ | 1502 | /* Hookup PHB IO resource */ |
@@ -1533,51 +1506,37 @@ static void pcibios_setup_phb_resources(struct pci_controller *hose, | |||
1533 | printk(KERN_WARNING "PCI: I/O resource not set for host" | 1506 | printk(KERN_WARNING "PCI: I/O resource not set for host" |
1534 | " bridge %s (domain %d)\n", | 1507 | " bridge %s (domain %d)\n", |
1535 | hose->dn->full_name, hose->global_number); | 1508 | hose->dn->full_name, hose->global_number); |
1536 | #ifdef CONFIG_PPC32 | 1509 | } else { |
1537 | /* Workaround for lack of IO resource only on 32-bit */ | 1510 | offset = pcibios_io_space_offset(hose); |
1538 | res->start = (unsigned long)hose->io_base_virt - isa_io_base; | 1511 | |
1539 | res->end = res->start + IO_SPACE_LIMIT; | 1512 | pr_debug("PCI: PHB IO resource = %08llx-%08llx [%lx] off 0x%08llx\n", |
1540 | res->flags = IORESOURCE_IO; | ||
1541 | #endif /* CONFIG_PPC32 */ | ||
1542 | } | ||
1543 | if (res->flags) { | ||
1544 | pr_debug("PCI: PHB IO resource = %016llx-%016llx [%lx]\n", | ||
1545 | (unsigned long long)res->start, | 1513 | (unsigned long long)res->start, |
1546 | (unsigned long long)res->end, | 1514 | (unsigned long long)res->end, |
1547 | (unsigned long)res->flags); | 1515 | (unsigned long)res->flags, |
1548 | pci_add_resource_offset(resources, res, pcibios_io_space_offset(hose)); | 1516 | (unsigned long long)offset); |
1549 | 1517 | pci_add_resource_offset(resources, res, offset); | |
1550 | pr_debug("PCI: PHB IO offset = %08lx\n", | ||
1551 | (unsigned long)hose->io_base_virt - _IO_BASE); | ||
1552 | } | 1518 | } |
1553 | 1519 | ||
1554 | /* Hookup PHB Memory resources */ | 1520 | /* Hookup PHB Memory resources */ |
1555 | for (i = 0; i < 3; ++i) { | 1521 | for (i = 0; i < 3; ++i) { |
1556 | res = &hose->mem_resources[i]; | 1522 | res = &hose->mem_resources[i]; |
1557 | if (!res->flags) { | 1523 | if (!res->flags) { |
1558 | if (i > 0) | ||
1559 | continue; | ||
1560 | printk(KERN_ERR "PCI: Memory resource 0 not set for " | 1524 | printk(KERN_ERR "PCI: Memory resource 0 not set for " |
1561 | "host bridge %s (domain %d)\n", | 1525 | "host bridge %s (domain %d)\n", |
1562 | hose->dn->full_name, hose->global_number); | 1526 | hose->dn->full_name, hose->global_number); |
1563 | #ifdef CONFIG_PPC32 | 1527 | continue; |
1564 | /* Workaround for lack of MEM resource only on 32-bit */ | ||
1565 | res->start = hose->pci_mem_offset; | ||
1566 | res->end = (resource_size_t)-1LL; | ||
1567 | res->flags = IORESOURCE_MEM; | ||
1568 | #endif /* CONFIG_PPC32 */ | ||
1569 | } | ||
1570 | if (res->flags) { | ||
1571 | pr_debug("PCI: PHB MEM resource %d = %016llx-%016llx [%lx]\n", i, | ||
1572 | (unsigned long long)res->start, | ||
1573 | (unsigned long long)res->end, | ||
1574 | (unsigned long)res->flags); | ||
1575 | pci_add_resource_offset(resources, res, hose->pci_mem_offset); | ||
1576 | } | 1528 | } |
1577 | } | 1529 | offset = hose->mem_offset[i]; |
1578 | 1530 | ||
1579 | pr_debug("PCI: PHB MEM offset = %016llx\n", | 1531 | |
1580 | (unsigned long long)hose->pci_mem_offset); | 1532 | pr_debug("PCI: PHB MEM resource %d = %08llx-%08llx [%lx] off 0x%08llx\n", i, |
1533 | (unsigned long long)res->start, | ||
1534 | (unsigned long long)res->end, | ||
1535 | (unsigned long)res->flags, | ||
1536 | (unsigned long long)offset); | ||
1537 | |||
1538 | pci_add_resource_offset(resources, res, offset); | ||
1539 | } | ||
1581 | } | 1540 | } |
1582 | 1541 | ||
1583 | /* | 1542 | /* |
diff --git a/arch/powerpc/kernel/pci_32.c b/arch/powerpc/kernel/pci_32.c index e37c2152acf4..432459c817fa 100644 --- a/arch/powerpc/kernel/pci_32.c +++ b/arch/powerpc/kernel/pci_32.c | |||
@@ -295,7 +295,7 @@ long sys_pciconfig_iobase(long which, unsigned long bus, unsigned long devfn) | |||
295 | case IOBASE_BRIDGE_NUMBER: | 295 | case IOBASE_BRIDGE_NUMBER: |
296 | return (long)hose->first_busno; | 296 | return (long)hose->first_busno; |
297 | case IOBASE_MEMORY: | 297 | case IOBASE_MEMORY: |
298 | return (long)hose->pci_mem_offset; | 298 | return (long)hose->mem_offset[0]; |
299 | case IOBASE_IO: | 299 | case IOBASE_IO: |
300 | return (long)hose->io_base_phys; | 300 | return (long)hose->io_base_phys; |
301 | case IOBASE_ISA_IO: | 301 | case IOBASE_ISA_IO: |
diff --git a/arch/powerpc/kernel/pci_64.c b/arch/powerpc/kernel/pci_64.c index 51a133a78a09..873050d26840 100644 --- a/arch/powerpc/kernel/pci_64.c +++ b/arch/powerpc/kernel/pci_64.c | |||
@@ -246,7 +246,7 @@ long sys_pciconfig_iobase(long which, unsigned long in_bus, | |||
246 | case IOBASE_BRIDGE_NUMBER: | 246 | case IOBASE_BRIDGE_NUMBER: |
247 | return (long)hose->first_busno; | 247 | return (long)hose->first_busno; |
248 | case IOBASE_MEMORY: | 248 | case IOBASE_MEMORY: |
249 | return (long)hose->pci_mem_offset; | 249 | return (long)hose->mem_offset[0]; |
250 | case IOBASE_IO: | 250 | case IOBASE_IO: |
251 | return (long)hose->io_base_phys; | 251 | return (long)hose->io_base_phys; |
252 | case IOBASE_ISA_IO: | 252 | case IOBASE_ISA_IO: |