Merge branch 'linus' into pci-for-jesse
[sfrench/cifs-2.6.git] / drivers / pci / probe.c
index 4b3011a23effa43f9053d2889430e43225bfb2ea..d2bd74ee3e0875c9f6211ed90ae7ab696b4a54a7 100644 (file)
@@ -9,6 +9,7 @@
 #include <linux/slab.h>
 #include <linux/module.h>
 #include <linux/cpumask.h>
+#include <linux/pci-aspm.h>
 #include "pci.h"
 
 #define CARDBUS_LATENCY_TIMER  176     /* secondary latency timer */
 LIST_HEAD(pci_root_buses);
 EXPORT_SYMBOL(pci_root_buses);
 
-LIST_HEAD(pci_devices);
+
+static int find_anything(struct device *dev, void *data)
+{
+       return 1;
+}
 
 /*
  * Some device drivers need know if pci is initiated.
  * Basically, we think pci is not initiated when there
- * is no device in list of pci_devices.
+ * is no device to be found on the pci_bus_type.
  */
 int no_pci_devices(void)
 {
-       return list_empty(&pci_devices);
-}
+       struct device *dev;
+       int no_devices;
 
+       dev = bus_find_device(&pci_bus_type, NULL, NULL, find_anything);
+       no_devices = (dev == NULL);
+       put_device(dev);
+       return no_devices;
+}
 EXPORT_SYMBOL(no_pci_devices);
 
 #ifdef HAVE_PCI_LEGACY
@@ -244,7 +254,7 @@ static void pci_read_bases(struct pci_dev *dev, unsigned int howmany, int rom)
                        res->flags |= l & ~PCI_BASE_ADDRESS_IO_MASK;
                }
                res->end = res->start + (unsigned long) sz;
-               res->flags |= pci_calc_resource_flags(l);
+               res->flags |= pci_calc_resource_flags(l) | IORESOURCE_SIZEALIGN;
                if (is_64bit_memory(l)) {
                        u32 szhi, lhi;
 
@@ -265,10 +275,11 @@ static void pci_read_bases(struct pci_dev *dev, unsigned int howmany, int rom)
                        }
                        res->start = l64 & PCI_BASE_ADDRESS_MEM_MASK;
                        res->end = res->start + sz64;
+                       printk(KERN_INFO "PCI: %s reg %x 64bit mmio: [%llx, %llx]\n", pci_name(dev), reg, res->start, res->end);
 #else
                        if (sz64 > 0x100000000ULL) {
-                               printk(KERN_ERR "PCI: Unable to handle 64-bit "
-                                       "BAR for device %s\n", pci_name(dev));
+                               dev_err(&dev->dev, "BAR %d: can't handle 64-bit"
+                                       " BAR\n", pos);
                                res->start = 0;
                                res->flags = 0;
                        } else if (lhi) {
@@ -280,6 +291,8 @@ static void pci_read_bases(struct pci_dev *dev, unsigned int howmany, int rom)
                                res->end = sz;
                        }
 #endif
+               } else {
+                       printk(KERN_INFO "PCI: %s reg %x %s: [%llx, %llx]\n", pci_name(dev), reg, (res->flags & IORESOURCE_IO)? "io port":"32bit mmio", res->start, res->end);
                }
        }
        if (rom) {
@@ -297,7 +310,8 @@ static void pci_read_bases(struct pci_dev *dev, unsigned int howmany, int rom)
                        if (sz) {
                                res->flags = (l & IORESOURCE_ROM_ENABLE) |
                                  IORESOURCE_MEM | IORESOURCE_PREFETCH |
-                                 IORESOURCE_READONLY | IORESOURCE_CACHEABLE;
+                                 IORESOURCE_READONLY | IORESOURCE_CACHEABLE |
+                                 IORESOURCE_SIZEALIGN;
                                res->start = l & PCI_ROM_ADDRESS_MASK;
                                res->end = res->start + (unsigned long) sz;
                        }
@@ -318,7 +332,7 @@ void __devinit pci_read_bridge_bases(struct pci_bus *child)
                return;
 
        if (dev->transparent) {
-               printk(KERN_INFO "PCI: Transparent bridge - %s\n", pci_name(dev));
+               dev_info(&dev->dev, "transparent bridge\n");
                for(i = 3; i < PCI_BUS_NUM_RESOURCES; i++)
                        child->resource[i] = child->parent->resource[i - 3];
        }
@@ -346,6 +360,7 @@ void __devinit pci_read_bridge_bases(struct pci_bus *child)
                        res->start = base;
                if (!res->end)
                        res->end = limit + 0xfff;
+               printk(KERN_INFO "PCI: bridge %s io port: [%llx, %llx]\n", pci_name(dev), res->start, res->end);
        }
 
        res = child->resource[1];
@@ -357,6 +372,7 @@ void __devinit pci_read_bridge_bases(struct pci_bus *child)
                res->flags = (mem_base_lo & PCI_MEMORY_RANGE_TYPE_MASK) | IORESOURCE_MEM;
                res->start = base;
                res->end = limit + 0xfffff;
+               printk(KERN_INFO "PCI: bridge %s 32bit mmio: [%llx, %llx]\n", pci_name(dev), res->start, res->end);
        }
 
        res = child->resource[2];
@@ -381,7 +397,8 @@ void __devinit pci_read_bridge_bases(struct pci_bus *child)
                        limit |= ((long) mem_limit_hi) << 32;
 #else
                        if (mem_base_hi || mem_limit_hi) {
-                               printk(KERN_ERR "PCI: Unable to handle 64-bit address space for bridge %s\n", pci_name(dev));
+                               dev_err(&dev->dev, "can't handle 64-bit "
+                                       "address space for bridge\n");
                                return;
                        }
 #endif
@@ -391,6 +408,7 @@ void __devinit pci_read_bridge_bases(struct pci_bus *child)
                res->flags = (mem_base_lo & PCI_MEMORY_RANGE_TYPE_MASK) | IORESOURCE_MEM | IORESOURCE_PREFETCH;
                res->start = base;
                res->end = limit + 0xfffff;
+               printk(KERN_INFO "PCI: bridge %s %sbit mmio pref: [%llx, %llx]\n", pci_name(dev), (res->flags & PCI_PREF_RANGE_TYPE_64)?"64":"32",res->start, res->end);
        }
 }
 
@@ -403,12 +421,13 @@ static struct pci_bus * pci_alloc_bus(void)
                INIT_LIST_HEAD(&b->node);
                INIT_LIST_HEAD(&b->children);
                INIT_LIST_HEAD(&b->devices);
+               INIT_LIST_HEAD(&b->slots);
        }
        return b;
 }
 
-static struct pci_bus * __devinit
-pci_alloc_child_bus(struct pci_bus *parent, struct pci_dev *bridge, int busnr)
+static struct pci_bus *pci_alloc_child_bus(struct pci_bus *parent,
+                                          struct pci_dev *bridge, int busnr)
 {
        struct pci_bus *child;
        int i;
@@ -500,8 +519,8 @@ int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max,
 
        pci_read_config_dword(dev, PCI_PRIMARY_BUS, &buses);
 
-       pr_debug("PCI: Scanning behind PCI bridge %s, config %06x, pass %d\n",
-                pci_name(dev), buses & 0xffffff, pass);
+       dev_dbg(&dev->dev, "scanning behind bridge, config %06x, pass %d\n",
+               buses & 0xffffff, pass);
 
        /* Disable MasterAbortMode during probing to avoid reporting
           of bus errors (in some architectures) */ 
@@ -524,8 +543,8 @@ int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max,
                 * ignore it.  This can happen with the i450NX chipset.
                 */
                if (pci_find_bus(pci_domain_nr(bus), busnr)) {
-                       printk(KERN_INFO "PCI: Bus %04x:%02x already known\n",
-                                       pci_domain_nr(bus), busnr);
+                       dev_info(&dev->dev, "bus %04x:%02x already known\n",
+                                pci_domain_nr(bus), busnr);
                        goto out;
                }
 
@@ -641,7 +660,9 @@ int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max,
                pci_write_config_byte(dev, PCI_SUBORDINATE_BUS, max);
        }
 
-       sprintf(child->name, (is_cardbus ? "PCI CardBus #%02x" : "PCI Bus #%02x"), child->number);
+       sprintf(child->name,
+               (is_cardbus ? "PCI CardBus %04x:%02x" : "PCI Bus %04x:%02x"),
+               pci_domain_nr(bus), child->number);
 
        /* Has only triggered on CardBus, fixup is in yenta_socket */
        while (bus->parent) {
@@ -698,8 +719,9 @@ static int pci_setup_device(struct pci_dev * dev)
 {
        u32 class;
 
-       sprintf(pci_name(dev), "%04x:%02x:%02x.%d", pci_domain_nr(dev->bus),
-               dev->bus->number, PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn));
+       dev_set_name(&dev->dev, "%04x:%02x:%02x.%d", pci_domain_nr(dev->bus),
+                    dev->bus->number, PCI_SLOT(dev->devfn),
+                    PCI_FUNC(dev->devfn));
 
        pci_read_config_dword(dev, PCI_CLASS_REVISION, &class);
        dev->revision = class & 0xff;
@@ -707,7 +729,7 @@ static int pci_setup_device(struct pci_dev * dev)
        dev->class = class;
        class >>= 8;
 
-       pr_debug("PCI: Found %s [%04x/%04x] %06x %02x\n", pci_name(dev),
+       dev_dbg(&dev->dev, "found [%04x/%04x] class %06x header type %02x\n",
                 dev->vendor, dev->device, class, dev->hdr_type);
 
        /* "Unknown power state" */
@@ -775,13 +797,13 @@ static int pci_setup_device(struct pci_dev * dev)
                break;
 
        default:                                    /* unknown header */
-               printk(KERN_ERR "PCI: device %s has unknown header type %02x, ignoring.\n",
-                       pci_name(dev), dev->hdr_type);
+               dev_err(&dev->dev, "unknown header type %02x, "
+                       "ignoring device\n", dev->hdr_type);
                return -1;
 
        bad:
-               printk(KERN_ERR "PCI: %s: class %x doesn't match header type %02x. Ignoring class.\n",
-                      pci_name(dev), class, dev->hdr_type);
+               dev_err(&dev->dev, "ignoring class %02x (doesn't match header "
+                       "type %02x)\n", class, dev->hdr_type);
                dev->class = PCI_CLASS_NOT_DEFINED;
        }
 
@@ -801,6 +823,7 @@ static void pci_release_dev(struct device *dev)
        struct pci_dev *pci_dev;
 
        pci_dev = to_pci_dev(dev);
+       pci_vpd_release(pci_dev);
        kfree(pci_dev);
 }
 
@@ -828,6 +851,21 @@ static void set_pcie_port_type(struct pci_dev *pdev)
  * reading the dword at 0x100 which must either be 0 or a valid extended
  * capability header.
  */
+int pci_cfg_space_size_ext(struct pci_dev *dev)
+{
+       u32 status;
+
+       if (pci_read_config_dword(dev, 256, &status) != PCIBIOS_SUCCESSFUL)
+               goto fail;
+       if (status == 0xffffffff)
+               goto fail;
+
+       return PCI_CFG_SPACE_EXP_SIZE;
+
+ fail:
+       return PCI_CFG_SPACE_SIZE;
+}
+
 int pci_cfg_space_size(struct pci_dev *dev)
 {
        int pos;
@@ -844,12 +882,7 @@ int pci_cfg_space_size(struct pci_dev *dev)
                        goto fail;
        }
 
-       if (pci_read_config_dword(dev, 256, &status) != PCIBIOS_SUCCESSFUL)
-               goto fail;
-       if (status == 0xffffffff)
-               goto fail;
-
-       return PCI_CFG_SPACE_EXP_SIZE;
+       return pci_cfg_space_size_ext(dev);
 
  fail:
        return PCI_CFG_SPACE_SIZE;
@@ -868,7 +901,6 @@ struct pci_dev *alloc_pci_dev(void)
        if (!dev)
                return NULL;
 
-       INIT_LIST_HEAD(&dev->global_list);
        INIT_LIST_HEAD(&dev->bus_list);
 
        pci_msi_init_pci_dev(dev);
@@ -881,8 +913,7 @@ EXPORT_SYMBOL(alloc_pci_dev);
  * Read the config data for a PCI device, sanity-check it
  * and fill in the dev structure...
  */
-static struct pci_dev * __devinit
-pci_scan_device(struct pci_bus *bus, int devfn)
+static struct pci_dev *pci_scan_device(struct pci_bus *bus, int devfn)
 {
        struct pci_dev *dev;
        u32 l;
@@ -905,7 +936,7 @@ pci_scan_device(struct pci_bus *bus, int devfn)
                        return NULL;
                /* Card hasn't responded in 60 seconds?  Must be stuck. */
                if (delay > 60 * 1000) {
-                       printk(KERN_WARNING "Device %04x:%02x:%02x.%d not "
+                       printk(KERN_WARNING "pci %04x:%02x:%02x.%d: not "
                                        "responding\n", pci_domain_nr(bus),
                                        bus->number, PCI_SLOT(devfn),
                                        PCI_FUNC(devfn));
@@ -941,6 +972,8 @@ pci_scan_device(struct pci_bus *bus, int devfn)
                return NULL;
        }
 
+       pci_vpd_pci22_init(dev);
+
        return dev;
 }
 
@@ -950,7 +983,6 @@ void pci_device_add(struct pci_dev *dev, struct pci_bus *bus)
        dev->dev.release = pci_release_dev;
        pci_dev_get(dev);
 
-       set_dev_node(&dev->dev, pcibus_to_node(bus));
        dev->dev.dma_mask = &dev->dma_mask;
        dev->dev.dma_parms = &dev->dma_parms;
        dev->dev.coherent_dma_mask = 0xffffffffull;
@@ -961,11 +993,13 @@ void pci_device_add(struct pci_dev *dev, struct pci_bus *bus)
        /* Fix up broken headers */
        pci_fixup_device(pci_fixup_header, dev);
 
+       /* Initialize power management of the device */
+       pci_pm_init(dev);
+
        /*
         * Add the device to our list of discovered devices
         * and the bus list for fixup functions, etc.
         */
-       INIT_LIST_HEAD(&dev->global_list);
        down_write(&pci_bus_sem);
        list_add_tail(&dev->bus_list, &bus->devices);
        up_write(&pci_bus_sem);
@@ -992,7 +1026,7 @@ EXPORT_SYMBOL(pci_scan_single_device);
  *
  * Scan a PCI slot on the specified PCI bus for devices, adding
  * discovered devices to the @bus->devices list.  New devices
- * will have an empty dev->global_list head.
+ * will not have is_added set.
  */
 int pci_scan_slot(struct pci_bus *bus, int devfn)
 {
@@ -1024,6 +1058,10 @@ int pci_scan_slot(struct pci_bus *bus, int devfn)
                                break;
                }
        }
+
+       if (bus->self)
+               pcie_aspm_init_link_state(bus->self);
+
        return nr;
 }
 
@@ -1063,6 +1101,10 @@ unsigned int __devinit pci_scan_child_bus(struct pci_bus *bus)
        return max;
 }
 
+void __attribute__((weak)) set_pci_bus_resources_arch_default(struct pci_bus *b)
+{
+}
+
 struct pci_bus * pci_create_bus(struct device *parent,
                int bus, struct pci_ops *ops, void *sysdata)
 {
@@ -1102,6 +1144,9 @@ struct pci_bus * pci_create_bus(struct device *parent,
                goto dev_reg_err;
        b->bridge = get_device(dev);
 
+       if (!parent)
+               set_dev_node(b->bridge, pcibus_to_node(b));
+
        b->dev.class = &pcibus_class;
        b->dev.parent = b->bridge;
        sprintf(b->dev.bus_id, "%04x:%02x", pci_domain_nr(b), bus);
@@ -1119,6 +1164,8 @@ struct pci_bus * pci_create_bus(struct device *parent,
        b->resource[0] = &ioport_resource;
        b->resource[1] = &iomem_resource;
 
+       set_pci_bus_resources_arch_default(b);
+
        return b;
 
 dev_create_file_err:
@@ -1194,7 +1241,7 @@ static void __init pci_insertion_sort_klist(struct pci_dev *a, struct list_head
        list_move_tail(&a->dev.knode_bus.n_node, list);
 }
 
-static void __init pci_sort_breadthfirst_klist(void)
+void __init pci_sort_breadthfirst(void)
 {
        LIST_HEAD(sorted_devices);
        struct list_head *pos, *tmp;
@@ -1215,36 +1262,3 @@ static void __init pci_sort_breadthfirst_klist(void)
        list_splice(&sorted_devices, &device_klist->k_list);
        spin_unlock(&device_klist->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();
-}
-