[PATCH] pci and yenta: pcibios_bus_to_resource

In yenta_socket, we default to using the resource setting of the CardBus
bridge. However, this is a PCI-bus-centric view of resources and thus needs
to be converted to generic resources first. Therefore, add a call to
pcibios_bus_to_resource() call in between. This function is a mere wrapper on
x86 and friends, however on some others it already exists, is added in this
patch (alpha, arm, ppc, ppc64) or still needs to be provided (parisc -- where
is its pcibios_resource_to_bus() ?).

Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by Dominik Brodowski and committed by Linus Torvalds 43c34735 fec59a71

+101 -9
+16
arch/alpha/kernel/pci.c
··· 350 350 region->end = res->end - offset; 351 351 } 352 352 353 + void pcibios_bus_to_resource(struct pci_dev *dev, struct resource *res, 354 + struct pci_bus_region *region) 355 + { 356 + struct pci_controller *hose = (struct pci_controller *)dev->sysdata; 357 + unsigned long offset = 0; 358 + 359 + if (res->flags & IORESOURCE_IO) 360 + offset = hose->io_space->start; 361 + else if (res->flags & IORESOURCE_MEM) 362 + offset = hose->mem_space->start; 363 + 364 + res->start = region->start + offset; 365 + res->end = region->end + offset; 366 + } 367 + 353 368 #ifdef CONFIG_HOTPLUG 354 369 EXPORT_SYMBOL(pcibios_resource_to_bus); 370 + EXPORT_SYMBOL(pcibios_bus_to_resource); 355 371 #endif 356 372 357 373 int
+17
arch/arm/kernel/bios32.c
··· 447 447 region->end = res->end - offset; 448 448 } 449 449 450 + void __devinit 451 + pcibios_bus_to_resource(struct pci_dev *dev, struct resource *res, 452 + struct pci_bus_region *region) 453 + { 454 + struct pci_sys_data *root = dev->sysdata; 455 + unsigned long offset = 0; 456 + 457 + if (res->flags & IORESOURCE_IO) 458 + offset = root->io_offset; 459 + if (res->flags & IORESOURCE_MEM) 460 + offset = root->mem_offset; 461 + 462 + res->start = region->start + offset; 463 + res->end = region->end + offset; 464 + } 465 + 450 466 #ifdef CONFIG_HOTPLUG 451 467 EXPORT_SYMBOL(pcibios_fixup_bus); 452 468 EXPORT_SYMBOL(pcibios_resource_to_bus); 469 + EXPORT_SYMBOL(pcibios_bus_to_resource); 453 470 #endif 454 471 455 472 /*
+15
arch/ppc/kernel/pci.c
··· 160 160 } 161 161 EXPORT_SYMBOL(pcibios_resource_to_bus); 162 162 163 + void pcibios_bus_to_resource(struct pci_dev *dev, struct resource *res, 164 + struct pci_bus_region *region) 165 + { 166 + unsigned long offset = 0; 167 + struct pci_controller *hose = dev->sysdata; 168 + 169 + if (hose && res->flags & IORESOURCE_IO) 170 + offset = (unsigned long)hose->io_base_virt - isa_io_base; 171 + else if (hose && res->flags & IORESOURCE_MEM) 172 + offset = hose->pci_mem_offset; 173 + res->start = region->start + offset; 174 + res->end = region->end + offset; 175 + } 176 + EXPORT_SYMBOL(pcibios_bus_to_resource); 177 + 163 178 /* 164 179 * We need to avoid collisions with `mirrored' VGA ports 165 180 * and other strange ISA hardware, so we always want the
+20
arch/ppc64/kernel/pci.c
··· 108 108 region->end = res->end - offset; 109 109 } 110 110 111 + void pcibios_bus_to_resource(struct pci_dev *dev, struct resource *res, 112 + struct pci_bus_region *region) 113 + { 114 + unsigned long offset = 0; 115 + struct pci_controller *hose = pci_bus_to_host(dev->bus); 116 + 117 + if (!hose) 118 + return; 119 + 120 + if (res->flags & IORESOURCE_IO) 121 + offset = (unsigned long)hose->io_base_virt - pci_io_base; 122 + 123 + if (res->flags & IORESOURCE_MEM) 124 + offset = hose->pci_mem_offset; 125 + 126 + res->start = region->start + offset; 127 + res->end = region->end + offset; 128 + } 129 + 111 130 #ifdef CONFIG_HOTPLUG 112 131 EXPORT_SYMBOL(pcibios_resource_to_bus); 132 + EXPORT_SYMBOL(pcibios_bus_to_resource); 113 133 #endif 114 134 115 135 /*
+6 -9
drivers/pcmcia/yenta_socket.c
··· 605 605 606 606 static void yenta_allocate_res(struct yenta_socket *socket, int nr, unsigned type, int addr_start, int addr_end) 607 607 { 608 - struct pci_bus *bus; 609 608 struct resource *root, *res; 610 - u32 start, end; 609 + struct pci_bus_region region; 611 610 unsigned mask; 612 611 613 612 res = socket->dev->resource + PCI_BRIDGE_RESOURCES + nr; ··· 619 620 if (type & IORESOURCE_IO) 620 621 mask = ~3; 621 622 622 - bus = socket->dev->subordinate; 623 - res->name = bus->name; 623 + res->name = socket->dev->subordinate->name; 624 624 res->flags = type; 625 625 626 - start = config_readl(socket, addr_start) & mask; 627 - end = config_readl(socket, addr_end) | ~mask; 628 - if (start && end > start && !override_bios) { 629 - res->start = start; 630 - res->end = end; 626 + region.start = config_readl(socket, addr_start) & mask; 627 + region.end = config_readl(socket, addr_end) | ~mask; 628 + if (region.start && region.end > region.start && !override_bios) { 629 + pcibios_bus_to_resource(socket->dev, res, &region); 631 630 root = pci_find_parent_resource(socket->dev, res); 632 631 if (root && (request_resource(root, res) == 0)) 633 632 return;
+3
include/asm-alpha/pci.h
··· 251 251 extern void pcibios_resource_to_bus(struct pci_dev *, struct pci_bus_region *, 252 252 struct resource *); 253 253 254 + extern void pcibios_bus_to_resource(struct pci_dev *dev, struct resource *res, 255 + struct pci_bus_region *region); 256 + 254 257 #define pci_domain_nr(bus) ((struct pci_controller *)(bus)->sysdata)->index 255 258 256 259 static inline int pci_proc_domain(struct pci_bus *bus)
+4
include/asm-arm/pci.h
··· 60 60 pcibios_resource_to_bus(struct pci_dev *dev, struct pci_bus_region *region, 61 61 struct resource *res); 62 62 63 + extern void 64 + pcibios_bus_to_resource(struct pci_dev *dev, struct resource *res, 65 + struct pci_bus_region *region); 66 + 63 67 static inline void pcibios_add_platform_entries(struct pci_dev *dev) 64 68 { 65 69 }
+8
include/asm-generic/pci.h
··· 22 22 region->end = res->end; 23 23 } 24 24 25 + static inline void 26 + pcibios_bus_to_resource(struct pci_dev *dev, struct resource *res, 27 + struct pci_bus_region *region) 28 + { 29 + res->start = region->start; 30 + res->end = region->end; 31 + } 32 + 25 33 #define pcibios_scan_all_fns(a, b) 0 26 34 27 35 #ifndef HAVE_ARCH_PCI_GET_LEGACY_IDE_IRQ
+4
include/asm-parisc/pci.h
··· 253 253 pcibios_resource_to_bus(struct pci_dev *dev, struct pci_bus_region *region, 254 254 struct resource *res); 255 255 256 + extern void 257 + pcibios_bus_to_resource(struct pci_dev *dev, struct resource *res, 258 + struct pci_bus_region *region); 259 + 256 260 static inline void pcibios_add_platform_entries(struct pci_dev *dev) 257 261 { 258 262 }
+4
include/asm-ppc/pci.h
··· 105 105 pcibios_resource_to_bus(struct pci_dev *dev, struct pci_bus_region *region, 106 106 struct resource *res); 107 107 108 + extern void 109 + pcibios_bus_to_resource(struct pci_dev *dev, struct resource *res, 110 + struct pci_bus_region *region); 111 + 108 112 extern void pcibios_add_platform_entries(struct pci_dev *dev); 109 113 110 114 struct file;
+4
include/asm-ppc64/pci.h
··· 134 134 pcibios_resource_to_bus(struct pci_dev *dev, struct pci_bus_region *region, 135 135 struct resource *res); 136 136 137 + extern void 138 + pcibios_bus_to_resource(struct pci_dev *dev, struct resource *res, 139 + struct pci_bus_region *region); 140 + 137 141 extern int 138 142 unmap_bus_range(struct pci_bus *bus); 139 143