Merge master.kernel.org:/pub/scm/linux/kernel/git/steve/gfs2-2.6-nmw
[pandora-kernel.git] / arch / powerpc / kernel / pci_32.c
index 09b1e1b..2f54cd8 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/errno.h>
 #include <linux/bootmem.h>
 #include <linux/irq.h>
+#include <linux/list.h>
 
 #include <asm/processor.h>
 #include <asm/io.h>
@@ -99,7 +100,7 @@ pcibios_fixup_resources(struct pci_dev *dev)
                        continue;
                if (res->end == 0xffffffff) {
                        DBG("PCI:%s Resource %d [%016llx-%016llx] is unassigned\n",
-                           pci_name(dev), i, res->start, res->end);
+                           pci_name(dev), i, (u64)res->start, (u64)res->end);
                        res->end -= res->start;
                        res->start = 0;
                        res->flags |= IORESOURCE_UNSET;
@@ -115,11 +116,9 @@ pcibios_fixup_resources(struct pci_dev *dev)
                if (offset != 0) {
                        res->start += offset;
                        res->end += offset;
-#ifdef DEBUG
-                       printk("Fixup res %d (%lx) of dev %s: %llx -> %llx\n",
-                              i, res->flags, pci_name(dev),
-                              res->start - offset, res->start);
-#endif
+                       DBG("Fixup res %d (%lx) of dev %s: %llx -> %llx\n",
+                           i, res->flags, pci_name(dev),
+                           (u64)res->start - offset, (u64)res->start);
                }
        }
 
@@ -255,7 +254,7 @@ pcibios_allocate_bus_resources(struct list_head *bus_list)
                        }
 
                        DBG("PCI: bridge rsrc %llx..%llx (%lx), parent %p\n",
-                               res->start, res->end, res->flags, pr);
+                           (u64)res->start, (u64)res->end, res->flags, pr);
                        if (pr) {
                                if (request_resource(pr, res) == 0)
                                        continue;
@@ -306,7 +305,7 @@ reparent_resources(struct resource *parent, struct resource *res)
        for (p = res->child; p != NULL; p = p->sibling) {
                p->parent = res;
                DBG(KERN_INFO "PCI: reparented %s [%llx..%llx] under %s\n",
-                   p->name, p->start, p->end, res->name);
+                   p->name, (u64)p->start, (u64)p->end, res->name);
        }
        return 0;
 }
@@ -362,7 +361,7 @@ pci_relocate_bridge_resource(struct pci_bus *bus, int i)
        }
        if (request_resource(pr, res)) {
                DBG(KERN_ERR "PCI: huh? couldn't move to %llx..%llx\n",
-                   res->start, res->end);
+                   (u64)res->start, (u64)res->end);
                return -1;              /* "can't happen" */
        }
        update_bridge_base(bus, i);
@@ -441,14 +440,14 @@ update_bridge_base(struct pci_bus *bus, int i)
                end = res->end - off;
                io_base_lo = (start >> 8) & PCI_IO_RANGE_MASK;
                io_limit_lo = (end >> 8) & PCI_IO_RANGE_MASK;
-               if (end > 0xffff) {
-                       pci_write_config_word(dev, PCI_IO_BASE_UPPER16,
-                                             start >> 16);
-                       pci_write_config_word(dev, PCI_IO_LIMIT_UPPER16,
-                                             end >> 16);
+               if (end > 0xffff)
                        io_base_lo |= PCI_IO_RANGE_TYPE_32;
-               else
+               else
                        io_base_lo |= PCI_IO_RANGE_TYPE_16;
+               pci_write_config_word(dev, PCI_IO_BASE_UPPER16,
+                               start >> 16);
+               pci_write_config_word(dev, PCI_IO_LIMIT_UPPER16,
+                               end >> 16);
                pci_write_config_byte(dev, PCI_IO_BASE, io_base_lo);
                pci_write_config_byte(dev, PCI_IO_LIMIT, io_limit_lo);
 
@@ -480,14 +479,14 @@ static inline void alloc_resource(struct pci_dev *dev, int idx)
        struct resource *pr, *r = &dev->resource[idx];
 
        DBG("PCI:%s: Resource %d: %016llx-%016llx (f=%lx)\n",
-           pci_name(dev), idx, r->start, r->end, r->flags);
+           pci_name(dev), idx, (u64)r->start, (u64)r->end, r->flags);
        pr = pci_find_parent_resource(dev, r);
        if (!pr || request_resource(pr, r) < 0) {
                printk(KERN_ERR "PCI: Cannot allocate resource region %d"
                       " of device %s\n", idx, pci_name(dev));
                if (pr)
                        DBG("PCI:  parent is %p: %016llx-%016llx (f=%lx)\n",
-                           pr, pr->start, pr->end, pr->flags);
+                           pr, (u64)pr->start, (u64)pr->end, pr->flags);
                /* We'll assign a new address later */
                r->flags |= IORESOURCE_UNSET;
                r->end -= r->start;
@@ -633,12 +632,12 @@ pcibios_alloc_controller(void)
 static void
 make_one_node_map(struct device_node* node, u8 pci_bus)
 {
-       int *bus_range;
+       const int *bus_range;
        int len;
 
        if (pci_bus >= pci_bus_count)
                return;
-       bus_range = (int *) get_property(node, "bus-range", &len);
+       bus_range = get_property(node, "bus-range", &len);
        if (bus_range == NULL || len < 2 * sizeof(int)) {
                printk(KERN_WARNING "Can't get bus-range for %s, "
                       "assuming it starts at 0\n", node->full_name);
@@ -648,13 +647,13 @@ make_one_node_map(struct device_node* node, u8 pci_bus)
 
        for (node=node->child; node != 0;node = node->sibling) {
                struct pci_dev* dev;
-               unsigned int *class_code, *reg;
+               const unsigned int *class_code, *reg;
        
-               class_code = (unsigned int *) get_property(node, "class-code", NULL);
+               class_code = get_property(node, "class-code", NULL);
                if (!class_code || ((*class_code >> 8) != PCI_CLASS_BRIDGE_PCI &&
                        (*class_code >> 8) != PCI_CLASS_BRIDGE_CARDBUS))
                        continue;
-               reg = (unsigned int *)get_property(node, "reg", NULL);
+               reg = get_property(node, "reg", NULL);
                if (!reg)
                        continue;
                dev = pci_find_slot(pci_bus, ((reg[0] >> 8) & 0xff));
@@ -669,7 +668,7 @@ pcibios_make_OF_bus_map(void)
 {
        int i;
        struct pci_controller* hose;
-       u8* of_prop_map;
+       struct property *map_prop;
 
        pci_to_OF_bus_map = (u8*)kmalloc(pci_bus_count, GFP_KERNEL);
        if (!pci_to_OF_bus_map) {
@@ -691,9 +690,12 @@ pcibios_make_OF_bus_map(void)
                        continue;
                make_one_node_map(node, hose->first_busno);
        }
-       of_prop_map = get_property(find_path_device("/"), "pci-OF-bus-map", NULL);
-       if (of_prop_map)
-               memcpy(of_prop_map, pci_to_OF_bus_map, pci_bus_count);
+       map_prop = of_find_property(find_path_device("/"),
+                       "pci-OF-bus-map", NULL);
+       if (map_prop) {
+               BUG_ON(pci_bus_count > map_prop->length);
+               memcpy(map_prop->value, pci_to_OF_bus_map, pci_bus_count);
+       }
 #ifdef DEBUG
        printk("PCI->OF bus map:\n");
        for (i=0; i<pci_bus_count; i++) {
@@ -712,7 +714,7 @@ scan_OF_pci_childs(struct device_node* node, pci_OF_scan_iterator filter, void*
        struct device_node* sub_node;
 
        for (; node != 0;node = node->sibling) {
-               unsigned int *class_code;
+               const unsigned int *class_code;
        
                if (filter(node, data))
                        return node;
@@ -722,7 +724,7 @@ scan_OF_pci_childs(struct device_node* node, pci_OF_scan_iterator filter, void*
                 * a fake root for all functions of a multi-function device,
                 * we go down them as well.
                 */
-               class_code = (unsigned int *) get_property(node, "class-code", NULL);
+               class_code = get_property(node, "class-code", NULL);
                if ((!class_code || ((*class_code >> 8) != PCI_CLASS_BRIDGE_PCI &&
                        (*class_code >> 8) != PCI_CLASS_BRIDGE_CARDBUS)) &&
                        strcmp(node->name, "multifunc-device"))
@@ -737,10 +739,10 @@ scan_OF_pci_childs(struct device_node* node, pci_OF_scan_iterator filter, void*
 static int
 scan_OF_pci_childs_iterator(struct device_node* node, void* data)
 {
-       unsigned int *reg;
+       const unsigned int *reg;
        u8* fdata = (u8*)data;
        
-       reg = (unsigned int *) get_property(node, "reg", NULL);
+       reg = get_property(node, "reg", NULL);
        if (reg && ((reg[0] >> 8) & 0xff) == fdata[1]
                && ((reg[0] >> 16) & 0xff) == fdata[0])
                return 1;
@@ -841,7 +843,7 @@ find_OF_pci_device_filter(struct device_node* node, void* data)
 int
 pci_device_from_OF_node(struct device_node* node, u8* bus, u8* devfn)
 {
-       unsigned int *reg;
+       const unsigned int *reg;
        struct pci_controller* hose;
        struct pci_dev* dev = NULL;
        
@@ -854,7 +856,7 @@ pci_device_from_OF_node(struct device_node* node, u8* bus, u8* devfn)
        if (!scan_OF_pci_childs(((struct device_node*)hose->arch_data)->child,
                        find_OF_pci_device_filter, (void *)node))
                return -ENODEV;
-       reg = (unsigned int *) get_property(node, "reg", NULL);
+       reg = get_property(node, "reg", NULL);
        if (!reg)
                return -ENODEV;
        *bus = (reg[0] >> 16) & 0xff;
@@ -885,8 +887,8 @@ pci_process_bridge_OF_ranges(struct pci_controller *hose,
                           struct device_node *dev, int primary)
 {
        static unsigned int static_lc_ranges[256] __initdata;
-       unsigned int *dt_ranges, *lc_ranges, *ranges, *prev;
-       unsigned int size;
+       const unsigned int *dt_ranges;
+       unsigned int *lc_ranges, *ranges, *prev, size;
        int rlen = 0, orig_rlen;
        int memno = 0;
        struct resource *res;
@@ -897,7 +899,7 @@ pci_process_bridge_OF_ranges(struct pci_controller *hose,
         * that can have more than 3 ranges, fortunately using contiguous
         * addresses -- BenH
         */
-       dt_ranges = (unsigned int *) get_property(dev, "ranges", &rlen);
+       dt_ranges = get_property(dev, "ranges", &rlen);
        if (!dt_ranges)
                return;
        /* Sanity check, though hopefully that never happens */
@@ -957,7 +959,7 @@ pci_process_bridge_OF_ranges(struct pci_controller *hose,
                        res->flags = IORESOURCE_IO;
                        res->start = ranges[2];
                        DBG("PCI: IO 0x%llx -> 0x%llx\n",
-                                   res->start, res->start + size - 1);
+                           (u64)res->start, (u64)res->start + size - 1);
                        break;
                case 2:         /* memory space */
                        memno = 0;
@@ -979,7 +981,7 @@ pci_process_bridge_OF_ranges(struct pci_controller *hose,
                                        res->flags |= IORESOURCE_PREFETCH;
                                res->start = ranges[na+2];
                                DBG("PCI: MEM[%d] 0x%llx -> 0x%llx\n", memno,
-                                           res->start, res->start + size - 1);
+                                   (u64)res->start, (u64)res->start + size - 1);
                        }
                        break;
                }
@@ -1265,7 +1267,10 @@ pcibios_init(void)
                if (pci_assign_all_buses)
                        hose->first_busno = next_busno;
                hose->last_busno = 0xff;
-               bus = pci_scan_bus(hose->first_busno, hose->ops, hose);
+               bus = pci_scan_bus_parented(hose->parent, hose->first_busno,
+                                           hose->ops, hose);
+               if (bus)
+                       pci_bus_add_devices(bus);
                hose->last_busno = bus->subordinate;
                if (pci_assign_all_buses || next_busno <= hose->last_busno)
                        next_busno = hose->last_busno + pcibios_assign_bus_offset;
@@ -1279,10 +1284,6 @@ pcibios_init(void)
        if (pci_assign_all_buses && have_of)
                pcibios_make_OF_bus_map();
 
-       /* Do machine dependent PCI interrupt routing */
-       if (ppc_md.pci_swizzle && ppc_md.pci_map_irq)
-               pci_fixup_irqs(ppc_md.pci_swizzle, ppc_md.pci_map_irq);
-
        /* Call machine dependent fixup */
        if (ppc_md.pcibios_fixup)
                ppc_md.pcibios_fixup();
@@ -1305,25 +1306,6 @@ pcibios_init(void)
 
 subsys_initcall(pcibios_init);
 
-unsigned char __init
-common_swizzle(struct pci_dev *dev, unsigned char *pinp)
-{
-       struct pci_controller *hose = dev->sysdata;
-
-       if (dev->bus->number != hose->first_busno) {
-               u8 pin = *pinp;
-               do {
-                       pin = bridge_swizzle(pin, PCI_SLOT(dev->devfn));
-                       /* Move up the chain of bridges. */
-                       dev = dev->bus->self;
-               } while (dev->bus->self);
-               *pinp = pin;
-
-               /* The slot is the idsel of the last bridge. */
-       }
-       return PCI_SLOT(dev->devfn);
-}
-
 unsigned long resource_fixup(struct pci_dev * dev, struct resource * res,
                             unsigned long start, unsigned long size)
 {
@@ -1335,6 +1317,7 @@ void __init pcibios_fixup_bus(struct pci_bus *bus)
        struct pci_controller *hose = (struct pci_controller *) bus->sysdata;
        unsigned long io_offset;
        struct resource *res;
+       struct pci_dev *dev;
        int i;
 
        io_offset = (unsigned long)hose->io_base_virt - isa_io_base;
@@ -1387,8 +1370,16 @@ void __init pcibios_fixup_bus(struct pci_bus *bus)
                }
        }
 
+       /* Platform specific bus fixups */
        if (ppc_md.pcibios_fixup_bus)
                ppc_md.pcibios_fixup_bus(bus);
+
+       /* Read default IRQs and fixup if necessary */
+       list_for_each_entry(dev, &bus->devices, bus_list) {
+               pci_read_irq_line(dev);
+               if (ppc_md.pci_irq_fixup)
+                       ppc_md.pci_irq_fixup(dev);
+       }
 }
 
 char __init *pcibios_setup(char *str)
@@ -1568,7 +1559,7 @@ static struct resource *__pci_mmap_make_offset(struct pci_dev *dev,
                *offset += hose->pci_mem_offset;
                res_bit = IORESOURCE_MEM;
        } else {
-               io_offset = hose->io_base_virt - ___IO_BASE;
+               io_offset = hose->io_base_virt - (void __iomem *)_IO_BASE;
                *offset += io_offset;
                res_bit = IORESOURCE_IO;
        }
@@ -1823,7 +1814,8 @@ void pci_resource_to_user(const struct pci_dev *dev, int bar,
                return;
 
        if (rsrc->flags & IORESOURCE_IO)
-               offset = ___IO_BASE - hose->io_base_virt + hose->io_base_phys;
+               offset = (void __iomem *)_IO_BASE - hose->io_base_virt
+                       + hose->io_base_phys;
 
        *start = rsrc->start + offset;
        *end = rsrc->end + offset;
@@ -1842,35 +1834,6 @@ pci_init_resource(struct resource *res, unsigned long start, unsigned long end,
        res->child = NULL;
 }
 
-void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max)
-{
-       unsigned long start = pci_resource_start(dev, bar);
-       unsigned long len = pci_resource_len(dev, bar);
-       unsigned long flags = pci_resource_flags(dev, bar);
-
-       if (!len)
-               return NULL;
-       if (max && len > max)
-               len = max;
-       if (flags & IORESOURCE_IO)
-               return ioport_map(start, len);
-       if (flags & IORESOURCE_MEM)
-               /* Not checking IORESOURCE_CACHEABLE because PPC does
-                * not currently distinguish between ioremap and
-                * ioremap_nocache.
-                */
-               return ioremap(start, len);
-       /* What? */
-       return NULL;
-}
-
-void pci_iounmap(struct pci_dev *dev, void __iomem *addr)
-{
-       /* Nothing to do */
-}
-EXPORT_SYMBOL(pci_iomap);
-EXPORT_SYMBOL(pci_iounmap);
-
 unsigned long pci_address_to_pio(phys_addr_t address)
 {
        struct pci_controller* hose = hose_head;