Merge ../torvalds-2.6/
[pandora-kernel.git] / drivers / pci / probe.c
index 6a0a82f..26a55d0 100644 (file)
@@ -72,11 +72,13 @@ void pci_remove_legacy_files(struct pci_bus *bus) { return; }
 /*
  * PCI Bus Class Devices
  */
-static ssize_t pci_bus_show_cpuaffinity(struct class_device *class_dev, char *buf)
+static ssize_t pci_bus_show_cpuaffinity(struct class_device *class_dev,
+                                       char *buf)
 {
-       cpumask_t cpumask = pcibus_to_cpumask(to_pci_bus(class_dev));
        int ret;
+       cpumask_t cpumask;
 
+       cpumask = pcibus_to_cpumask(to_pci_bus(class_dev));
        ret = cpumask_scnprintf(buf, PAGE_SIZE, cpumask);
        if (ret < PAGE_SIZE)
                buf[ret++] = '\n';
@@ -239,9 +241,8 @@ void __devinit pci_read_bridge_bases(struct pci_bus *child)
 
        if (dev->transparent) {
                printk(KERN_INFO "PCI: Transparent bridge - %s\n", pci_name(dev));
-               for(i = 0; i < PCI_BUS_NUM_RESOURCES; i++)
-                       child->resource[i] = child->parent->resource[i];
-               return;
+               for(i = 3; i < PCI_BUS_NUM_RESOURCES; i++)
+                       child->resource[i] = child->parent->resource[i - 3];
        }
 
        for(i=0; i<3; i++)
@@ -398,6 +399,16 @@ static void pci_enable_crs(struct pci_dev *dev)
        pci_write_config_word(dev, rpcap + PCI_EXP_RTCTL, rpctl);
 }
 
+static void __devinit pci_fixup_parent_subordinate_busnr(struct pci_bus *child, int max)
+{
+       struct pci_bus *parent = child->parent;
+       while (parent->parent && parent->subordinate < max) {
+               parent->subordinate = max;
+               pci_write_config_byte(parent->self, PCI_SUBORDINATE_BUS, max);
+               parent = parent->parent;
+       }
+}
+
 unsigned int __devinit pci_scan_child_bus(struct pci_bus *bus);
 
 /*
@@ -498,8 +509,14 @@ int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev * dev, int max
                pci_write_config_dword(dev, PCI_PRIMARY_BUS, buses);
 
                if (!is_cardbus) {
-                       child->bridge_ctl = PCI_BRIDGE_CTL_NO_ISA;
-
+                       child->bridge_ctl = bctl | PCI_BRIDGE_CTL_NO_ISA;
+                       /*
+                        * Adjust subordinate busnr in parent buses.
+                        * We do this before scanning for children because
+                        * some devices may not be detected if the bios
+                        * was lazy.
+                        */
+                       pci_fixup_parent_subordinate_busnr(child, max);
                        /* Now we can scan all subordinate buses... */
                        max = pci_scan_child_bus(child);
                } else {
@@ -513,6 +530,7 @@ int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev * dev, int max
                                                        max+i+1))
                                        break;
                        max += i;
+                       pci_fixup_parent_subordinate_busnr(child, max);
                }
                /*
                 * Set the subordinate bus number to its real value.
@@ -568,7 +586,7 @@ static int pci_setup_device(struct pci_dev * dev)
                 dev->vendor, dev->device, class, dev->hdr_type);
 
        /* "Unknown power state" */
-       dev->current_state = 4;
+       dev->current_state = PCI_UNKNOWN;
 
        /* Early fixups, before probing the BARs */
        pci_fixup_device(pci_fixup_early, dev);
@@ -737,29 +755,19 @@ pci_scan_device(struct pci_bus *bus, int devfn)
                kfree(dev);
                return NULL;
        }
-       device_initialize(&dev->dev);
-       dev->dev.release = pci_release_dev;
-       pci_dev_get(dev);
-
-       pci_name_device(dev);
-
-       dev->dev.dma_mask = &dev->dma_mask;
-       dev->dev.coherent_dma_mask = 0xffffffffull;
 
        return dev;
 }
 
-struct pci_dev * __devinit
-pci_scan_single_device(struct pci_bus *bus, int devfn)
+void __devinit pci_device_add(struct pci_dev *dev, struct pci_bus *bus)
 {
-       struct pci_dev *dev;
+       device_initialize(&dev->dev);
+       dev->dev.release = pci_release_dev;
+       pci_dev_get(dev);
 
-       dev = pci_scan_device(bus, devfn);
-       pci_scan_msi_device(dev);
+       dev->dev.dma_mask = &dev->dma_mask;
+       dev->dev.coherent_dma_mask = 0xffffffffull;
 
-       if (!dev)
-               return NULL;
-       
        /* Fix up broken headers */
        pci_fixup_device(pci_fixup_header, dev);
 
@@ -771,6 +779,19 @@ pci_scan_single_device(struct pci_bus *bus, int devfn)
        spin_lock(&pci_bus_lock);
        list_add_tail(&dev->bus_list, &bus->devices);
        spin_unlock(&pci_bus_lock);
+}
+
+struct pci_dev * __devinit
+pci_scan_single_device(struct pci_bus *bus, int devfn)
+{
+       struct pci_dev *dev;
+
+       dev = pci_scan_device(bus, devfn);
+       if (!dev)
+               return NULL;
+
+       pci_device_add(dev, bus);
+       pci_scan_msi_device(dev);
 
        return dev;
 }
@@ -867,7 +888,8 @@ unsigned int __devinit pci_do_scan_bus(struct pci_bus *bus)
        return max;
 }
 
-struct pci_bus * __devinit pci_scan_bus_parented(struct device *parent, int bus, struct pci_ops *ops, void *sysdata)
+struct pci_bus * __devinit pci_create_bus(struct device *parent,
+               int bus, struct pci_ops *ops, void *sysdata)
 {
        int error;
        struct pci_bus *b;
@@ -924,8 +946,6 @@ struct pci_bus * __devinit pci_scan_bus_parented(struct device *parent, int bus,
        b->resource[0] = &ioport_resource;
        b->resource[1] = &iomem_resource;
 
-       b->subordinate = pci_scan_child_bus(b);
-
        return b;
 
 sys_create_link_err:
@@ -943,6 +963,18 @@ err_out:
        kfree(b);
        return NULL;
 }
+EXPORT_SYMBOL_GPL(pci_create_bus);
+
+struct pci_bus * __devinit pci_scan_bus_parented(struct device *parent,
+               int bus, struct pci_ops *ops, void *sysdata)
+{
+       struct pci_bus *b;
+
+       b = pci_create_bus(parent, bus, ops, sysdata);
+       if (b)
+               b->subordinate = pci_scan_child_bus(b);
+       return b;
+}
 EXPORT_SYMBOL(pci_scan_bus_parented);
 
 #ifdef CONFIG_HOTPLUG