[POWERPC] Disable broken PPC_PTRACE_GETFPREGS on 32 bits
[safe/jmp/linux-2.6] / arch / powerpc / kernel / pci_64.c
index 88b7848..6ae67eb 100644 (file)
@@ -11,7 +11,7 @@
  *      2 of the License, or (at your option) any later version.
  */
 
-#undef DEBUG
+#define DEBUG
 
 #include <linux/kernel.h>
 #include <linux/pci.h>
@@ -22,6 +22,7 @@
 #include <linux/list.h>
 #include <linux/syscalls.h>
 #include <linux/irq.h>
+#include <linux/vmalloc.h>
 
 #include <asm/processor.h>
 #include <asm/io.h>
@@ -44,31 +45,33 @@ int pci_assign_all_buses = 0;
 
 static void fixup_resource(struct resource *res, struct pci_dev *dev);
 static void do_bus_setup(struct pci_bus *bus);
-static void phbs_remap_io(void);
 
 /* pci_io_base -- the base address from which io bars are offsets.
  * This is the lowest I/O base address (so bar values are always positive),
  * and it *must* be the start of ISA space if an ISA bus exists because
- * ISA drivers use hard coded offsets.  If no ISA bus exists a dummy
- * page is mapped and isa_io_limit prevents access to it.
+ * ISA drivers use hard coded offsets.  If no ISA bus exists nothing
+ * is mapped on the first 64K of IO space
  */
-unsigned long isa_io_base;     /* NULL if no ISA bus */
-EXPORT_SYMBOL(isa_io_base);
-unsigned long pci_io_base;
+unsigned long pci_io_base = ISA_IO_BASE;
 EXPORT_SYMBOL(pci_io_base);
 
-void iSeries_pcibios_init(void);
-
 LIST_HEAD(hose_list);
 
-struct dma_mapping_ops *pci_dma_ops;
-EXPORT_SYMBOL(pci_dma_ops);
+static struct dma_mapping_ops *pci_dma_ops;
 
+/* XXX kill that some day ... */
 int global_phb_number;         /* Global phb counter */
 
-/* Cached ISA bridge dev. */
-struct pci_dev *ppc64_isabridge_dev = NULL;
-EXPORT_SYMBOL_GPL(ppc64_isabridge_dev);
+void set_pci_dma_ops(struct dma_mapping_ops *dma_ops)
+{
+       pci_dma_ops = dma_ops;
+}
+
+struct dma_mapping_ops *get_pci_dma_ops(void)
+{
+       return pci_dma_ops;
+}
+EXPORT_SYMBOL(get_pci_dma_ops);
 
 static void fixup_broken_pcnet32(struct pci_dev* dev)
 {
@@ -89,7 +92,7 @@ void  pcibios_resource_to_bus(struct pci_dev *dev, struct pci_bus_region *region
                return;
 
        if (res->flags & IORESOURCE_IO)
-               offset = (unsigned long)hose->io_base_virt - pci_io_base;
+               offset = (unsigned long)hose->io_base_virt - _IO_BASE;
 
        if (res->flags & IORESOURCE_MEM)
                offset = hose->pci_mem_offset;
@@ -108,7 +111,7 @@ void pcibios_bus_to_resource(struct pci_dev *dev, struct resource *res,
                return;
 
        if (res->flags & IORESOURCE_IO)
-               offset = (unsigned long)hose->io_base_virt - pci_io_base;
+               offset = (unsigned long)hose->io_base_virt - _IO_BASE;
 
        if (res->flags & IORESOURCE_MEM)
                offset = hose->pci_mem_offset;
@@ -145,7 +148,7 @@ void pcibios_align_resource(void *data, struct resource *res,
 
        if (res->flags & IORESOURCE_IO) {
                unsigned long offset = (unsigned long)hose->io_base_virt -
-                                       pci_io_base;
+                                       _IO_BASE;
                /* Make sure we start at our min on all hoses */
                if (start - offset < PCIBIOS_MIN_IO)
                        start = PCIBIOS_MIN_IO + offset;
@@ -210,6 +213,10 @@ struct pci_controller * pcibios_alloc_controller(struct device_node *dev)
 
 void pcibios_free_controller(struct pci_controller *phb)
 {
+       spin_lock(&hose_spinlock);
+       list_del(&phb->list_node);
+       spin_unlock(&hose_spinlock);
+
        if (phb->is_dynamic)
                kfree(phb);
 }
@@ -254,7 +261,7 @@ static u32 get_int_prop(struct device_node *np, const char *name, u32 def)
        const u32 *prop;
        int len;
 
-       prop = get_property(np, name, &len);
+       prop = of_get_property(np, name, &len);
        if (prop && len >= 4)
                return *prop;
        return def;
@@ -287,7 +294,7 @@ static void pci_parse_of_addrs(struct device_node *node, struct pci_dev *dev)
        u32 i;
        int proplen;
 
-       addrs = get_property(node, "assigned-addresses", &proplen);
+       addrs = of_get_property(node, "assigned-addresses", &proplen);
        if (!addrs)
                return;
        DBG("    parse addresses (%d bytes) @ %p\n", proplen, addrs);
@@ -326,16 +333,15 @@ struct pci_dev *of_create_pci_dev(struct device_node *node,
        struct pci_dev *dev;
        const char *type;
 
-       dev = kmalloc(sizeof(struct pci_dev), GFP_KERNEL);
+       dev = alloc_pci_dev();
        if (!dev)
                return NULL;
-       type = get_property(node, "device_type", NULL);
+       type = of_get_property(node, "device_type", NULL);
        if (type == NULL)
                type = "";
 
        DBG("    create device, devfn: %x, type: %s\n", devfn, type);
 
-       memset(dev, 0, sizeof(struct pci_dev));
        dev->bus = bus;
        dev->sysdata = node;
        dev->dev.parent = bus->bridge;
@@ -357,6 +363,7 @@ struct pci_dev *of_create_pci_dev(struct device_node *node,
        DBG("    class: 0x%x\n", dev->class);
 
        dev->current_state = 4;         /* unknown power state */
+       dev->error_state = pci_channel_io_normal;
 
        if (!strcmp(type, "pci") || !strcmp(type, "pciex")) {
                /* a PCI-PCI bridge */
@@ -377,8 +384,6 @@ struct pci_dev *of_create_pci_dev(struct device_node *node,
 
        pci_device_add(dev, bus);
 
-       /* XXX pci_scan_msi_device(dev); */
-
        return dev;
 }
 EXPORT_SYMBOL(of_create_pci_dev);
@@ -395,7 +400,7 @@ void __devinit of_scan_bus(struct device_node *node,
 
        while ((child = of_get_next_child(node, child)) != NULL) {
                DBG("  * %s\n", child->full_name);
-               reg = get_property(child, "reg", &reglen);
+               reg = of_get_property(child, "reg", &reglen);
                if (reg == NULL || reglen < 20)
                        continue;
                devfn = (reg[0] >> 8) & 0xff;
@@ -428,13 +433,13 @@ void __devinit of_scan_pci_bridge(struct device_node *node,
        DBG("of_scan_pci_bridge(%s)\n", node->full_name);
 
        /* parse bus-range property */
-       busrange = get_property(node, "bus-range", &len);
+       busrange = of_get_property(node, "bus-range", &len);
        if (busrange == NULL || len != 8) {
                printk(KERN_DEBUG "Can't get bus-range for PCI-PCI bridge %s\n",
                       node->full_name);
                return;
        }
-       ranges = get_property(node, "ranges", &len);
+       ranges = of_get_property(node, "ranges", &len);
        if (ranges == NULL) {
                printk(KERN_DEBUG "Can't get ranges for PCI-PCI bridge %s\n",
                       node->full_name);
@@ -513,7 +518,7 @@ void __devinit scan_phb(struct pci_controller *hose)
 
        DBG("Scanning PHB %s\n", node ? node->full_name : "<NO NAME>");
 
-       bus = pci_create_bus(NULL, hose->first_busno, hose->ops, node);
+       bus = pci_create_bus(hose->parent, hose->first_busno, hose->ops, node);
        if (bus == NULL) {
                printk(KERN_ERR "Failed to create bus for PCI domain %04x\n",
                       hose->global_number);
@@ -522,10 +527,16 @@ void __devinit scan_phb(struct pci_controller *hose)
        bus->secondary = hose->first_busno;
        hose->bus = bus;
 
+       if (!firmware_has_feature(FW_FEATURE_ISERIES))
+               pcibios_map_io_space(bus);
+
        bus->resource[0] = res = &hose->io_resource;
-       if (res->flags && request_resource(&ioport_resource, res))
+       if (res->flags && request_resource(&ioport_resource, res)) {
                printk(KERN_ERR "Failed to request PCI IO region "
                       "on PCI domain %04x\n", hose->global_number);
+               DBG("res->start = 0x%016lx, res->end = 0x%016lx\n",
+                   res->start, res->end);
+       }
 
        for (i = 0; i < 3; ++i) {
                res = &hose->mem_resources[i];
@@ -583,15 +594,6 @@ static int __init pcibios_init(void)
        if (ppc_md.pcibios_fixup)
                ppc_md.pcibios_fixup();
 
-       /* Cache the location of the ISA bridge (if we have one) */
-       ppc64_isabridge_dev = pci_get_class(PCI_CLASS_BRIDGE_ISA << 8, NULL);
-       if (ppc64_isabridge_dev != NULL)
-               printk(KERN_DEBUG "ISA bridge at %s\n", pci_name(ppc64_isabridge_dev));
-
-       if (!firmware_has_feature(FW_FEATURE_ISERIES))
-               /* map in PCI I/O space */
-               phbs_remap_io();
-
        printk(KERN_DEBUG "PCI: Probing PCI hardware done\n");
 
        return 0;
@@ -679,7 +681,7 @@ int pci_proc_domain(struct pci_bus *bus)
  * Returns negative error code on failure, zero on success.
  */
 static struct resource *__pci_mmap_make_offset(struct pci_dev *dev,
-                                              unsigned long *offset,
+                                              resource_size_t *offset,
                                               enum pci_mmap_state mmap_state)
 {
        struct pci_controller *hose = pci_bus_to_host(dev->bus);
@@ -691,10 +693,12 @@ static struct resource *__pci_mmap_make_offset(struct pci_dev *dev,
 
        /* If memory, add on the PCI bridge address offset */
        if (mmap_state == pci_mmap_mem) {
+#if 0 /* See comment in pci_resource_to_user() for why this is disabled */
                *offset += hose->pci_mem_offset;
+#endif
                res_bit = IORESOURCE_MEM;
        } else {
-               io_offset = (unsigned long)hose->io_base_virt - pci_io_base;
+               io_offset = (unsigned long)hose->io_base_virt - _IO_BASE;
                *offset += io_offset;
                res_bit = IORESOURCE_IO;
        }
@@ -759,9 +763,6 @@ static pgprot_t __pci_mmap_set_pgprot(struct pci_dev *dev, struct resource *rp,
        else
                prot |= _PAGE_GUARDED;
 
-       printk(KERN_DEBUG "PCI map for %s:%lx, prot: %lx\n", pci_name(dev), rp->start,
-              prot);
-
        return __pgprot(prot);
 }
 
@@ -829,7 +830,7 @@ pgprot_t pci_phys_mem_access_prot(struct file *file,
 int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
                        enum pci_mmap_state mmap_state, int write_combine)
 {
-       unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
+       resource_size_t offset = vma->vm_pgoff << PAGE_SHIFT;
        struct resource *rp;
        int ret;
 
@@ -867,76 +868,6 @@ void pcibios_add_platform_entries(struct pci_dev *pdev)
        device_create_file(&pdev->dev, &dev_attr_devspec);
 }
 
-#define ISA_SPACE_MASK 0x1
-#define ISA_SPACE_IO 0x1
-
-static void __devinit pci_process_ISA_OF_ranges(struct device_node *isa_node,
-                                     unsigned long phb_io_base_phys,
-                                     void __iomem * phb_io_base_virt)
-{
-       /* Remove these asap */
-
-       struct pci_address {
-               u32 a_hi;
-               u32 a_mid;
-               u32 a_lo;
-       };
-
-       struct isa_address {
-               u32 a_hi;
-               u32 a_lo;
-       };
-
-       struct isa_range {
-               struct isa_address isa_addr;
-               struct pci_address pci_addr;
-               unsigned int size;
-       };
-
-       const struct isa_range *range;
-       unsigned long pci_addr;
-       unsigned int isa_addr;
-       unsigned int size;
-       int rlen = 0;
-
-       range = get_property(isa_node, "ranges", &rlen);
-       if (range == NULL || (rlen < sizeof(struct isa_range))) {
-               printk(KERN_ERR "no ISA ranges or unexpected isa range size,"
-                      "mapping 64k\n");
-               __ioremap_explicit(phb_io_base_phys,
-                                  (unsigned long)phb_io_base_virt,
-                                  0x10000, _PAGE_NO_CACHE | _PAGE_GUARDED);
-               return; 
-       }
-       
-       /* From "ISA Binding to 1275"
-        * The ranges property is laid out as an array of elements,
-        * each of which comprises:
-        *   cells 0 - 1:       an ISA address
-        *   cells 2 - 4:       a PCI address 
-        *                      (size depending on dev->n_addr_cells)
-        *   cell 5:            the size of the range
-        */
-       if ((range->isa_addr.a_hi && ISA_SPACE_MASK) == ISA_SPACE_IO) {
-               isa_addr = range->isa_addr.a_lo;
-               pci_addr = (unsigned long) range->pci_addr.a_mid << 32 | 
-                       range->pci_addr.a_lo;
-
-               /* Assume these are both zero */
-               if ((pci_addr != 0) || (isa_addr != 0)) {
-                       printk(KERN_ERR "unexpected isa to pci mapping: %s\n",
-                                       __FUNCTION__);
-                       return;
-               }
-               
-               size = PAGE_ALIGN(range->size);
-
-               __ioremap_explicit(phb_io_base_phys, 
-                                  (unsigned long) phb_io_base_virt, 
-                                  size, _PAGE_NO_CACHE | _PAGE_GUARDED);
-       }
-}
-
 void __devinit pci_process_bridge_OF_ranges(struct pci_controller *hose,
                                            struct device_node *dev, int prim)
 {
@@ -946,7 +877,7 @@ void __devinit pci_process_bridge_OF_ranges(struct pci_controller *hose,
        int rlen = 0;
        int memno = 0;
        struct resource *res;
-       int np, na = prom_n_addr_cells(dev);
+       int np, na = of_n_addr_cells(dev);
        unsigned long pci_addr, cpu_phys_addr;
 
        np = na + 5;
@@ -959,7 +890,7 @@ void __devinit pci_process_bridge_OF_ranges(struct pci_controller *hose,
         *                      (size depending on dev->n_addr_cells)
         *   cells 4+5 or 5+6:  the size of the range
         */
-       ranges = get_property(dev, "ranges", &rlen);
+       ranges = of_get_property(dev, "ranges", &rlen);
        if (ranges == NULL)
                return;
        hose->io_base_phys = 0;
@@ -967,11 +898,7 @@ void __devinit pci_process_bridge_OF_ranges(struct pci_controller *hose,
                res = NULL;
                pci_space = ranges[0];
                pci_addr = ((unsigned long)ranges[1] << 32) | ranges[2];
-
-               cpu_phys_addr = ranges[3];
-               if (na >= 2)
-                       cpu_phys_addr = (cpu_phys_addr << 32) | ranges[4];
-
+               cpu_phys_addr = of_translate_address(dev, &ranges[3]);
                size = ((unsigned long)ranges[na+3] << 32) | ranges[na+4];
                ranges += np;
                if (size == 0)
@@ -999,8 +926,9 @@ void __devinit pci_process_bridge_OF_ranges(struct pci_controller *hose,
 
                switch ((pci_space >> 24) & 0x3) {
                case 1:         /* I/O space */
-                       hose->io_base_phys = cpu_phys_addr;
-                       hose->pci_io_size = size;
+                       hose->io_base_phys = cpu_phys_addr - pci_addr;
+                       /* handle from 0 to top of I/O window */
+                       hose->pci_io_size = pci_addr + size;
 
                        res = &hose->io_resource;
                        res->flags = IORESOURCE_IO;
@@ -1034,148 +962,122 @@ void __devinit pci_process_bridge_OF_ranges(struct pci_controller *hose,
        }
 }
 
-void __init pci_setup_phb_io(struct pci_controller *hose, int primary)
+#ifdef CONFIG_HOTPLUG
+
+int pcibios_unmap_io_space(struct pci_bus *bus)
 {
-       unsigned long size = hose->pci_io_size;
-       unsigned long io_virt_offset;
-       struct resource *res;
-       struct device_node *isa_dn;
-
-       hose->io_base_virt = reserve_phb_iospace(size);
-       DBG("phb%d io_base_phys 0x%lx io_base_virt 0x%lx\n",
-               hose->global_number, hose->io_base_phys,
-               (unsigned long) hose->io_base_virt);
-
-       if (primary) {
-               pci_io_base = (unsigned long)hose->io_base_virt;
-               isa_dn = of_find_node_by_type(NULL, "isa");
-               if (isa_dn) {
-                       isa_io_base = pci_io_base;
-                       pci_process_ISA_OF_ranges(isa_dn, hose->io_base_phys,
-                                               hose->io_base_virt);
-                       of_node_put(isa_dn);
-               }
-       }
+       struct pci_controller *hose;
 
-       io_virt_offset = (unsigned long)hose->io_base_virt - pci_io_base;
-       res = &hose->io_resource;
-       res->start += io_virt_offset;
-       res->end += io_virt_offset;
-}
+       WARN_ON(bus == NULL);
 
-void __devinit pci_setup_phb_io_dynamic(struct pci_controller *hose,
-                                       int primary)
-{
-       unsigned long size = hose->pci_io_size;
-       unsigned long io_virt_offset;
-       struct resource *res;
+       /* If this is not a PHB, we only flush the hash table over
+        * the area mapped by this bridge. We don't play with the PTE
+        * mappings since we might have to deal with sub-page alignemnts
+        * so flushing the hash table is the only sane way to make sure
+        * that no hash entries are covering that removed bridge area
+        * while still allowing other busses overlapping those pages
+        */
+       if (bus->self) {
+               struct resource *res = bus->resource[0];
 
-       hose->io_base_virt = __ioremap(hose->io_base_phys, size,
-                                       _PAGE_NO_CACHE | _PAGE_GUARDED);
-       DBG("phb%d io_base_phys 0x%lx io_base_virt 0x%lx\n",
-               hose->global_number, hose->io_base_phys,
-               (unsigned long) hose->io_base_virt);
+               DBG("IO unmapping for PCI-PCI bridge %s\n",
+                   pci_name(bus->self));
 
-       if (primary)
-               pci_io_base = (unsigned long)hose->io_base_virt;
+               __flush_hash_table_range(&init_mm, res->start + _IO_BASE,
+                                        res->end - res->start + 1);
+               return 0;
+       }
 
-       io_virt_offset = (unsigned long)hose->io_base_virt - pci_io_base;
-       res = &hose->io_resource;
-       res->start += io_virt_offset;
-       res->end += io_virt_offset;
-}
+       /* Get the host bridge */
+       hose = pci_bus_to_host(bus);
 
+       /* Check if we have IOs allocated */
+       if (hose->io_base_alloc == 0)
+               return 0;
 
-static int get_bus_io_range(struct pci_bus *bus, unsigned long *start_phys,
-                               unsigned long *start_virt, unsigned long *size)
-{
-       struct pci_controller *hose = pci_bus_to_host(bus);
-       struct pci_bus_region region;
-       struct resource *res;
+       DBG("IO unmapping for PHB %s\n",
+           ((struct device_node *)hose->arch_data)->full_name);
+       DBG("  alloc=0x%p\n", hose->io_base_alloc);
 
-       if (bus->self) {
-               res = bus->resource[0];
-               pcibios_resource_to_bus(bus->self, &region, res);
-               *start_phys = hose->io_base_phys + region.start;
-               *start_virt = (unsigned long) hose->io_base_virt + 
-                               region.start;
-               if (region.end > region.start) 
-                       *size = region.end - region.start + 1;
-               else {
-                       printk("%s(): unexpected region 0x%lx->0x%lx\n", 
-                                       __FUNCTION__, region.start, region.end);
-                       return 1;
-               }
-               
-       } else {
-               /* Root Bus */
-               res = &hose->io_resource;
-               *start_phys = hose->io_base_phys;
-               *start_virt = (unsigned long) hose->io_base_virt;
-               if (res->end > res->start)
-                       *size = res->end - res->start + 1;
-               else {
-                       printk("%s(): unexpected region 0x%lx->0x%lx\n", 
-                                       __FUNCTION__, res->start, res->end);
-                       return 1;
-               }
-       }
+       /* This is a PHB, we fully unmap the IO area */
+       vunmap(hose->io_base_alloc);
 
        return 0;
 }
+EXPORT_SYMBOL_GPL(pcibios_unmap_io_space);
 
-int unmap_bus_range(struct pci_bus *bus)
+#endif /* CONFIG_HOTPLUG */
+
+int __devinit pcibios_map_io_space(struct pci_bus *bus)
 {
-       unsigned long start_phys;
-       unsigned long start_virt;
-       unsigned long size;
+       struct vm_struct *area;
+       unsigned long phys_page;
+       unsigned long size_page;
+       unsigned long io_virt_offset;
+       struct pci_controller *hose;
 
-       if (!bus) {
-               printk(KERN_ERR "%s() expected bus\n", __FUNCTION__);
-               return 1;
-       }
-       
-       if (get_bus_io_range(bus, &start_phys, &start_virt, &size))
-               return 1;
-       if (iounmap_explicit((void __iomem *) start_virt, size))
-               return 1;
+       WARN_ON(bus == NULL);
 
-       return 0;
-}
-EXPORT_SYMBOL(unmap_bus_range);
+       /* If this not a PHB, nothing to do, page tables still exist and
+        * thus HPTEs will be faulted in when needed
+        */
+       if (bus->self) {
+               DBG("IO mapping for PCI-PCI bridge %s\n",
+                   pci_name(bus->self));
+               DBG("  virt=0x%016lx...0x%016lx\n",
+                   bus->resource[0]->start + _IO_BASE,
+                   bus->resource[0]->end + _IO_BASE);
+               return 0;
+       }
 
-int remap_bus_range(struct pci_bus *bus)
-{
-       unsigned long start_phys;
-       unsigned long start_virt;
-       unsigned long size;
+       /* Get the host bridge */
+       hose = pci_bus_to_host(bus);
+       phys_page = _ALIGN_DOWN(hose->io_base_phys, PAGE_SIZE);
+       size_page = _ALIGN_UP(hose->pci_io_size, PAGE_SIZE);
 
-       if (!bus) {
-               printk(KERN_ERR "%s() expected bus\n", __FUNCTION__);
-               return 1;
-       }
-       
-       
-       if (get_bus_io_range(bus, &start_phys, &start_virt, &size))
-               return 1;
-       if (start_phys == 0)
-               return 1;
-       printk(KERN_DEBUG "mapping IO %lx -> %lx, size: %lx\n", start_phys, start_virt, size);
-       if (__ioremap_explicit(start_phys, start_virt, size,
-                              _PAGE_NO_CACHE | _PAGE_GUARDED))
-               return 1;
+       /* Make sure IO area address is clear */
+       hose->io_base_alloc = NULL;
 
-       return 0;
-}
-EXPORT_SYMBOL(remap_bus_range);
+       /* If there's no IO to map on that bus, get away too */
+       if (hose->pci_io_size == 0 || hose->io_base_phys == 0)
+               return 0;
 
-static void phbs_remap_io(void)
-{
-       struct pci_controller *hose, *tmp;
+       /* Let's allocate some IO space for that guy. We don't pass
+        * VM_IOREMAP because we don't care about alignment tricks that
+        * the core does in that case. Maybe we should due to stupid card
+        * with incomplete address decoding but I'd rather not deal with
+        * those outside of the reserved 64K legacy region.
+        */
+       area = __get_vm_area(size_page, 0, PHB_IO_BASE, PHB_IO_END);
+       if (area == NULL)
+               return -ENOMEM;
+       hose->io_base_alloc = area->addr;
+       hose->io_base_virt = (void __iomem *)(area->addr +
+                                             hose->io_base_phys - phys_page);
+
+       DBG("IO mapping for PHB %s\n",
+           ((struct device_node *)hose->arch_data)->full_name);
+       DBG("  phys=0x%016lx, virt=0x%p (alloc=0x%p)\n",
+           hose->io_base_phys, hose->io_base_virt, hose->io_base_alloc);
+       DBG("  size=0x%016lx (alloc=0x%016lx)\n",
+           hose->pci_io_size, size_page);
+
+       /* Establish the mapping */
+       if (__ioremap_at(phys_page, area->addr, size_page,
+                        _PAGE_NO_CACHE | _PAGE_GUARDED) == NULL)
+               return -ENOMEM;
+
+       /* Fixup hose IO resource */
+       io_virt_offset = (unsigned long)hose->io_base_virt - _IO_BASE;
+       hose->io_resource.start += io_virt_offset;
+       hose->io_resource.end += io_virt_offset;
+
+       DBG("  hose->io_resource=0x%016lx...0x%016lx\n",
+           hose->io_resource.start, hose->io_resource.end);
 
-       list_for_each_entry_safe(hose, tmp, &hose_list, list_node)
-               remap_bus_range(hose->bus);
+       return 0;
 }
+EXPORT_SYMBOL_GPL(pcibios_map_io_space);
 
 static void __devinit fixup_resource(struct resource *res, struct pci_dev *dev)
 {
@@ -1183,8 +1085,7 @@ static void __devinit fixup_resource(struct resource *res, struct pci_dev *dev)
        unsigned long offset;
 
        if (res->flags & IORESOURCE_IO) {
-               offset = (unsigned long)hose->io_base_virt - pci_io_base;
-
+               offset = (unsigned long)hose->io_base_virt - _IO_BASE;
                res->start += offset;
                res->end += offset;
        } else if (res->flags & IORESOURCE_MEM) {
@@ -1199,9 +1100,20 @@ void __devinit pcibios_fixup_device_resources(struct pci_dev *dev,
        /* Update device resources.  */
        int i;
 
-       for (i = 0; i < PCI_NUM_RESOURCES; i++)
-               if (dev->resource[i].flags)
-                       fixup_resource(&dev->resource[i], dev);
+       DBG("%s: Fixup resources:\n", pci_name(dev));
+       for (i = 0; i < PCI_NUM_RESOURCES; i++) {
+               struct resource *res = &dev->resource[i];
+               if (!res->flags)
+                       continue;
+
+               DBG("  0x%02x < %08lx:0x%016lx...0x%016lx\n",
+                   i, res->flags, res->start, res->end);
+
+               fixup_resource(res, dev);
+
+               DBG("       > %08lx:0x%016lx...0x%016lx\n",
+                   res->flags, res->start, res->end);
+       }
 }
 EXPORT_SYMBOL(pcibios_fixup_device_resources);
 
@@ -1246,6 +1158,11 @@ static void __devinit do_bus_setup(struct pci_bus *bus)
 void __devinit pcibios_fixup_bus(struct pci_bus *bus)
 {
        struct pci_dev *dev = bus->self;
+       struct device_node *np;
+
+       np = pci_bus_to_OF_node(bus);
+
+       DBG("pcibios_fixup_bus(%s)\n", np ? np->full_name : "<???>");
 
        if (dev && pci_probe_only &&
            (dev->class >> 8) == PCI_CLASS_BRIDGE_PCI) {
@@ -1321,7 +1238,6 @@ int pci_read_irq_line(struct pci_dev *pci_dev)
        DBG(" -> mapped to linux irq %d\n", virq);
 
        pci_dev->irq = virq;
-       pci_write_config_byte(pci_dev, PCI_INTERRUPT_LINE, virq);
 
        return 0;
 }
@@ -1329,20 +1245,41 @@ EXPORT_SYMBOL(pci_read_irq_line);
 
 void pci_resource_to_user(const struct pci_dev *dev, int bar,
                          const struct resource *rsrc,
-                         u64 *start, u64 *end)
+                         resource_size_t *start, resource_size_t *end)
 {
        struct pci_controller *hose = pci_bus_to_host(dev->bus);
-       unsigned long offset = 0;
+       resource_size_t offset = 0;
 
        if (hose == NULL)
                return;
 
        if (rsrc->flags & IORESOURCE_IO)
-               offset = pci_io_base - (unsigned long)hose->io_base_virt +
-                       hose->io_base_phys;
+               offset = (unsigned long)hose->io_base_virt - _IO_BASE;
+
+       /* We pass a fully fixed up address to userland for MMIO instead of
+        * a BAR value because X is lame and expects to be able to use that
+        * to pass to /dev/mem !
+        *
+        * That means that we'll have potentially 64 bits values where some
+        * userland apps only expect 32 (like X itself since it thinks only
+        * Sparc has 64 bits MMIO) but if we don't do that, we break it on
+        * 32 bits CHRPs :-(
+        *
+        * Hopefully, the sysfs insterface is immune to that gunk. Once X
+        * has been fixed (and the fix spread enough), we can re-enable the
+        * 2 lines below and pass down a BAR value to userland. In that case
+        * we'll also have to re-enable the matching code in
+        * __pci_mmap_make_offset().
+        *
+        * BenH.
+        */
+#if 0
+       else if (rsrc->flags & IORESOURCE_MEM)
+               offset = hose->pci_mem_offset;
+#endif
 
-       *start = rsrc->start + offset;
-       *end = rsrc->end + offset;
+       *start = rsrc->start - offset;
+       *end = rsrc->end - offset;
 }
 
 struct pci_controller* pci_find_hose_for_OF_device(struct device_node* node)
@@ -1367,7 +1304,7 @@ unsigned long pci_address_to_pio(phys_addr_t address)
                if (address >= hose->io_base_phys &&
                    address < (hose->io_base_phys + hose->pci_io_size)) {
                        unsigned long base =
-                               (unsigned long)hose->io_base_virt - pci_io_base;
+                               (unsigned long)hose->io_base_virt - _IO_BASE;
                        return base + (address - hose->io_base_phys);
                }
        }
@@ -1405,7 +1342,7 @@ long sys_pciconfig_iobase(long which, unsigned long in_bus,
 
        for (ln = pci_root_buses.next; ln != &pci_root_buses; ln = ln->next) {
                bus = pci_bus_b(ln);
-               if (in_bus >= bus->number && in_bus < (bus->number + bus->subordinate))
+               if (in_bus >= bus->number && in_bus <= bus->subordinate)
                        break;
                bus = NULL;
        }