]> git.karo-electronics.de Git - mv-sheeva.git/blobdiff - drivers/pci/probe.c
Merge master.kernel.org:/pub/scm/linux/kernel/git/sfrench/cifs-2.6
[mv-sheeva.git] / drivers / pci / probe.c
index a10ed9dab2c2d5a04327760de02e140c20ef6f2c..e159d6604494acd62a617efcca0b6a3b26a8d4d4 100644 (file)
@@ -180,25 +180,31 @@ static void pci_read_bases(struct pci_dev *dev, unsigned int howmany, int rom)
                res->flags |= pci_calc_resource_flags(l);
                if ((l & (PCI_BASE_ADDRESS_SPACE | PCI_BASE_ADDRESS_MEM_TYPE_MASK))
                    == (PCI_BASE_ADDRESS_SPACE_MEMORY | PCI_BASE_ADDRESS_MEM_TYPE_64)) {
-                       pci_read_config_dword(dev, reg+4, &l);
+                       u32 szhi, lhi;
+                       pci_read_config_dword(dev, reg+4, &lhi);
+                       pci_write_config_dword(dev, reg+4, ~0);
+                       pci_read_config_dword(dev, reg+4, &szhi);
+                       pci_write_config_dword(dev, reg+4, lhi);
+                       szhi = pci_size(lhi, szhi, 0xffffffff);
                        next++;
 #if BITS_PER_LONG == 64
-                       res->start |= ((unsigned long) l) << 32;
+                       res->start |= ((unsigned long) lhi) << 32;
                        res->end = res->start + sz;
-                       pci_write_config_dword(dev, reg+4, ~0);
-                       pci_read_config_dword(dev, reg+4, &sz);
-                       pci_write_config_dword(dev, reg+4, l);
-                       sz = pci_size(l, sz, 0xffffffff);
-                       if (sz) {
+                       if (szhi) {
                                /* This BAR needs > 4GB?  Wow. */
-                               res->end |= (unsigned long)sz<<32;
+                               res->end |= (unsigned long)szhi<<32;
                        }
 #else
-                       if (l) {
-                               printk(KERN_ERR "PCI: Unable to handle 64-bit address for device %s\n", pci_name(dev));
+                       if (szhi) {
+                               printk(KERN_ERR "PCI: Unable to handle 64-bit BAR for device %s\n", pci_name(dev));
                                res->start = 0;
                                res->flags = 0;
-                               continue;
+                       } else if (lhi) {
+                               /* 64-bit wide address, treat as disabled */
+                               pci_write_config_dword(dev, reg, l & ~(u32)PCI_BASE_ADDRESS_MEM_MASK);
+                               pci_write_config_dword(dev, reg+4, 0);
+                               res->start = 0;
+                               res->end = sz;
                        }
 #endif
                }
@@ -333,6 +339,7 @@ pci_alloc_child_bus(struct pci_bus *parent, struct pci_dev *bridge, int busnr)
 {
        struct pci_bus *child;
        int i;
+       int retval;
 
        /*
         * Allocate a new bus, and inherit stuff from the parent..
@@ -350,8 +357,13 @@ pci_alloc_child_bus(struct pci_bus *parent, struct pci_dev *bridge, int busnr)
 
        child->class_dev.class = &pcibus_class;
        sprintf(child->class_dev.class_id, "%04x:%02x", pci_domain_nr(child), busnr);
-       class_device_register(&child->class_dev);
-       class_device_create_file(&child->class_dev, &class_device_attr_cpuaffinity);
+       retval = class_device_register(&child->class_dev);
+       if (retval)
+               goto error_register;
+       retval = class_device_create_file(&child->class_dev,
+                                         &class_device_attr_cpuaffinity);
+       if (retval)
+               goto error_file_create;
 
        /*
         * Set up the primary, secondary and subordinate
@@ -369,6 +381,12 @@ pci_alloc_child_bus(struct pci_bus *parent, struct pci_dev *bridge, int busnr)
        bridge->subordinate = child;
 
        return child;
+
+error_file_create:
+       class_device_unregister(&child->class_dev);
+error_register:
+       kfree(child);
+       return NULL;
 }
 
 struct pci_bus * __devinit pci_add_new_bus(struct pci_bus *parent, struct pci_dev *dev, int busnr)
@@ -377,9 +395,9 @@ struct pci_bus * __devinit pci_add_new_bus(struct pci_bus *parent, struct pci_de
 
        child = pci_alloc_child_bus(parent, dev, busnr);
        if (child) {
-               spin_lock(&pci_bus_lock);
+               down_write(&pci_bus_sem);
                list_add_tail(&child->node, &parent->children);
-               spin_unlock(&pci_bus_lock);
+               up_write(&pci_bus_sem);
        }
        return child;
 }
@@ -809,6 +827,7 @@ pci_scan_device(struct pci_bus *bus, int devfn)
        dev->vendor = l & 0xffff;
        dev->device = (l >> 16) & 0xffff;
        dev->cfg_size = pci_cfg_space_size(dev);
+       dev->error_state = pci_channel_io_normal;
 
        /* Assume 32-bit PCI; let 64-bit PCI cards (which are far rarer)
           set this higher, assuming the system even supports it.  */
@@ -838,9 +857,9 @@ void __devinit pci_device_add(struct pci_dev *dev, struct pci_bus *bus)
         * and the bus list for fixup functions, etc.
         */
        INIT_LIST_HEAD(&dev->global_list);
-       spin_lock(&pci_bus_lock);
+       down_write(&pci_bus_sem);
        list_add_tail(&dev->bus_list, &bus->devices);
-       spin_unlock(&pci_bus_lock);
+       up_write(&pci_bus_sem);
 }
 
 struct pci_dev * __devinit
@@ -975,9 +994,10 @@ struct pci_bus * __devinit pci_create_bus(struct device *parent,
                pr_debug("PCI: Bus %04x:%02x already known\n", pci_domain_nr(b), bus);
                goto err_out;
        }
-       spin_lock(&pci_bus_lock);
+
+       down_write(&pci_bus_sem);
        list_add_tail(&b->node, &pci_root_buses);
-       spin_unlock(&pci_bus_lock);
+       up_write(&pci_bus_sem);
 
        memset(dev, 0, sizeof(*dev));
        dev->parent = parent;
@@ -1017,9 +1037,9 @@ class_dev_create_file_err:
 class_dev_reg_err:
        device_unregister(dev);
 dev_reg_err:
-       spin_lock(&pci_bus_lock);
+       down_write(&pci_bus_sem);
        list_del(&b->node);
-       spin_unlock(&pci_bus_lock);
+       up_write(&pci_bus_sem);
 err_out:
        kfree(dev);
        kfree(b);
@@ -1047,3 +1067,95 @@ EXPORT_SYMBOL(pci_scan_bridge);
 EXPORT_SYMBOL(pci_scan_single_device);
 EXPORT_SYMBOL_GPL(pci_scan_child_bus);
 #endif
+
+static int __init pci_sort_bf_cmp(const struct pci_dev *a, const struct pci_dev *b)
+{
+       if      (pci_domain_nr(a->bus) < pci_domain_nr(b->bus)) return -1;
+       else if (pci_domain_nr(a->bus) > pci_domain_nr(b->bus)) return  1;
+
+       if      (a->bus->number < b->bus->number) return -1;
+       else if (a->bus->number > b->bus->number) return  1;
+
+       if      (a->devfn < b->devfn) return -1;
+       else if (a->devfn > b->devfn) return  1;
+
+       return 0;
+}
+
+/*
+ * Yes, this forcably breaks the klist abstraction temporarily.  It
+ * just wants to sort the klist, not change reference counts and
+ * take/drop locks rapidly in the process.  It does all this while
+ * holding the lock for the list, so objects can't otherwise be
+ * added/removed while we're swizzling.
+ */
+static void __init pci_insertion_sort_klist(struct pci_dev *a, struct list_head *list)
+{
+       struct list_head *pos;
+       struct klist_node *n;
+       struct device *dev;
+       struct pci_dev *b;
+
+       list_for_each(pos, list) {
+               n = container_of(pos, struct klist_node, n_node);
+               dev = container_of(n, struct device, knode_bus);
+               b = to_pci_dev(dev);
+               if (pci_sort_bf_cmp(a, b) <= 0) {
+                       list_move_tail(&a->dev.knode_bus.n_node, &b->dev.knode_bus.n_node);
+                       return;
+               }
+       }
+       list_move_tail(&a->dev.knode_bus.n_node, list);
+}
+
+static void __init pci_sort_breadthfirst_klist(void)
+{
+       LIST_HEAD(sorted_devices);
+       struct list_head *pos, *tmp;
+       struct klist_node *n;
+       struct device *dev;
+       struct pci_dev *pdev;
+
+       spin_lock(&pci_bus_type.klist_devices.k_lock);
+       list_for_each_safe(pos, tmp, &pci_bus_type.klist_devices.k_list) {
+               n = container_of(pos, struct klist_node, n_node);
+               dev = container_of(n, struct device, knode_bus);
+               pdev = to_pci_dev(dev);
+               pci_insertion_sort_klist(pdev, &sorted_devices);
+       }
+       list_splice(&sorted_devices, &pci_bus_type.klist_devices.k_list);
+       spin_unlock(&pci_bus_type.klist_devices.k_lock);
+}
+
+static void __init pci_insertion_sort_devices(struct pci_dev *a, struct list_head *list)
+{
+       struct pci_dev *b;
+
+       list_for_each_entry(b, list, global_list) {
+               if (pci_sort_bf_cmp(a, b) <= 0) {
+                       list_move_tail(&a->global_list, &b->global_list);
+                       return;
+               }
+       }
+       list_move_tail(&a->global_list, list);
+}
+
+static void __init pci_sort_breadthfirst_devices(void)
+{
+       LIST_HEAD(sorted_devices);
+       struct pci_dev *dev, *tmp;
+
+       down_write(&pci_bus_sem);
+       list_for_each_entry_safe(dev, tmp, &pci_devices, global_list) {
+               pci_insertion_sort_devices(dev, &sorted_devices);
+       }
+       list_splice(&sorted_devices, &pci_devices);
+       up_write(&pci_bus_sem);
+}
+
+void __init pci_sort_breadthfirst(void)
+{
+       pci_sort_breadthfirst_devices();
+       pci_sort_breadthfirst_klist();
+}
+