Fill out information on patch tags in SubmittingPatches
[safe/jmp/linux-2.6] / drivers / pci / probe.c
index a4a9682..2db2e4b 100644 (file)
@@ -22,6 +22,18 @@ EXPORT_SYMBOL(pci_root_buses);
 
 LIST_HEAD(pci_devices);
 
+/*
+ * 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.
+ */
+int no_pci_devices(void)
+{
+       return list_empty(&pci_devices);
+}
+
+EXPORT_SYMBOL(no_pci_devices);
+
 #ifdef HAVE_PCI_LEGACY
 /**
  * pci_create_legacy_files - create legacy I/O port and memory files
@@ -39,27 +51,25 @@ static void pci_create_legacy_files(struct pci_bus *b)
                b->legacy_io->attr.name = "legacy_io";
                b->legacy_io->size = 0xffff;
                b->legacy_io->attr.mode = S_IRUSR | S_IWUSR;
-               b->legacy_io->attr.owner = THIS_MODULE;
                b->legacy_io->read = pci_read_legacy_io;
                b->legacy_io->write = pci_write_legacy_io;
-               class_device_create_bin_file(&b->class_dev, b->legacy_io);
+               device_create_bin_file(&b->dev, b->legacy_io);
 
                /* Allocated above after the legacy_io struct */
                b->legacy_mem = b->legacy_io + 1;
                b->legacy_mem->attr.name = "legacy_mem";
                b->legacy_mem->size = 1024*1024;
                b->legacy_mem->attr.mode = S_IRUSR | S_IWUSR;
-               b->legacy_mem->attr.owner = THIS_MODULE;
                b->legacy_mem->mmap = pci_mmap_legacy_mem;
-               class_device_create_bin_file(&b->class_dev, b->legacy_mem);
+               device_create_bin_file(&b->dev, b->legacy_mem);
        }
 }
 
 void pci_remove_legacy_files(struct pci_bus *b)
 {
        if (b->legacy_io) {
-               class_device_remove_bin_file(&b->class_dev, b->legacy_io);
-               class_device_remove_bin_file(&b->class_dev, b->legacy_mem);
+               device_remove_bin_file(&b->dev, b->legacy_io);
+               device_remove_bin_file(&b->dev, b->legacy_mem);
                kfree(b->legacy_io); /* both are allocated here */
        }
 }
@@ -71,26 +81,27 @@ 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,
+static ssize_t pci_bus_show_cpuaffinity(struct device *dev,
+                                       struct device_attribute *attr,
                                        char *buf)
 {
        int ret;
        cpumask_t cpumask;
 
-       cpumask = pcibus_to_cpumask(to_pci_bus(class_dev));
+       cpumask = pcibus_to_cpumask(to_pci_bus(dev));
        ret = cpumask_scnprintf(buf, PAGE_SIZE, cpumask);
        if (ret < PAGE_SIZE)
                buf[ret++] = '\n';
        return ret;
 }
-CLASS_DEVICE_ATTR(cpuaffinity, S_IRUGO, pci_bus_show_cpuaffinity, NULL);
+DEVICE_ATTR(cpuaffinity, S_IRUGO, pci_bus_show_cpuaffinity, NULL);
 
 /*
  * PCI Bus Class
  */
-static void release_pcibus_dev(struct class_device *class_dev)
+static void release_pcibus_dev(struct device *dev)
 {
-       struct pci_bus *pci_bus = to_pci_bus(class_dev);
+       struct pci_bus *pci_bus = to_pci_bus(dev);
 
        if (pci_bus->bridge)
                put_device(pci_bus->bridge);
@@ -99,7 +110,7 @@ static void release_pcibus_dev(struct class_device *class_dev)
 
 static struct class pcibus_class = {
        .name           = "pci_bus",
-       .release        = &release_pcibus_dev,
+       .dev_release    = &release_pcibus_dev,
 };
 
 static int __init pcibus_class_init(void)
@@ -364,7 +375,7 @@ void __devinit pci_read_bridge_bases(struct pci_bus *child)
        }
 }
 
-static struct pci_bus * __devinit pci_alloc_bus(void)
+static struct pci_bus * pci_alloc_bus(void)
 {
        struct pci_bus *b;
 
@@ -382,7 +393,6 @@ 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..
@@ -398,15 +408,12 @@ pci_alloc_child_bus(struct pci_bus *parent, struct pci_dev *bridge, int busnr)
        child->bus_flags = parent->bus_flags;
        child->bridge = get_device(&bridge->dev);
 
-       child->class_dev.class = &pcibus_class;
-       sprintf(child->class_dev.class_id, "%04x:%02x", pci_domain_nr(child), busnr);
-       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;
+       /* initialize some portions of the bus device, but don't register it
+        * now as the parent is not properly set up yet.  This device will get
+        * registered later in pci_bus_add_devices()
+        */
+       child->dev.class = &pcibus_class;
+       sprintf(child->dev.bus_id, "%04x:%02x", pci_domain_nr(child), busnr);
 
        /*
         * Set up the primary, secondary and subordinate
@@ -424,15 +431,9 @@ 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)
+struct pci_bus *__ref pci_add_new_bus(struct pci_bus *parent, struct pci_dev *dev, int busnr)
 {
        struct pci_bus *child;
 
@@ -445,23 +446,7 @@ struct pci_bus * __devinit pci_add_new_bus(struct pci_bus *parent, struct pci_de
        return child;
 }
 
-static void pci_enable_crs(struct pci_dev *dev)
-{
-       u16 cap, rpctl;
-       int rpcap = pci_find_capability(dev, PCI_CAP_ID_EXP);
-       if (!rpcap)
-               return;
-
-       pci_read_config_word(dev, rpcap + PCI_CAP_FLAGS, &cap);
-       if (((cap & PCI_EXP_FLAGS_TYPE) >> 4) != PCI_EXP_TYPE_ROOT_PORT)
-               return;
-
-       pci_read_config_word(dev, rpcap + PCI_EXP_RTCTL, &rpctl);
-       rpctl |= PCI_EXP_RTCTL_CRSSVE;
-       pci_write_config_word(dev, rpcap + PCI_EXP_RTCTL, rpctl);
-}
-
-static void __devinit pci_fixup_parent_subordinate_busnr(struct pci_bus *child, int max)
+static void pci_fixup_parent_subordinate_busnr(struct pci_bus *child, int max)
 {
        struct pci_bus *parent = child->parent;
 
@@ -477,8 +462,6 @@ static void __devinit pci_fixup_parent_subordinate_busnr(struct pci_bus *child,
        }
 }
 
-unsigned int __devinit pci_scan_child_bus(struct pci_bus *bus);
-
 /*
  * If it's a bridge, configure it and scan the bus behind it.
  * For CardBus bridges, we don't scan behind as the devices will
@@ -489,7 +472,7 @@ unsigned int __devinit pci_scan_child_bus(struct pci_bus *bus);
  * them, we proceed to assigning numbers to the remaining buses in
  * order to avoid overlaps between old and new bus numbers.
  */
-int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev * dev, int max, int pass)
+int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max, int pass)
 {
        struct pci_bus *child;
        int is_cardbus = (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS);
@@ -507,8 +490,6 @@ int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev * dev, int max
        pci_write_config_word(dev, PCI_BRIDGE_CONTROL,
                              bctl & ~PCI_BRIDGE_CTL_MASTER_ABORT);
 
-       pci_enable_crs(dev);
-
        if ((buses & 0xffff00) && !pcibios_assign_all_busses() && !is_cardbus) {
                unsigned int cmax, busnr;
                /*
@@ -587,7 +568,7 @@ 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 = bctl | PCI_BRIDGE_CTL_NO_ISA;
+                       child->bridge_ctl = bctl;
                        /*
                         * Adjust subordinate busnr in parent buses.
                         * We do this before scanning for children because
@@ -643,20 +624,20 @@ int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev * dev, int max
 
        sprintf(child->name, (is_cardbus ? "PCI CardBus #%02x" : "PCI Bus #%02x"), child->number);
 
+       /* Has only triggered on CardBus, fixup is in yenta_socket */
        while (bus->parent) {
                if ((child->subordinate > bus->subordinate) ||
                    (child->number > bus->subordinate) ||
                    (child->number < bus->number) ||
                    (child->subordinate < bus->number)) {
-                       printk(KERN_WARNING "PCI: Bus #%02x (-#%02x) is "
-                              "hidden behind%s bridge #%02x (-#%02x)%s\n",
-                              child->number, child->subordinate,
-                              bus->self->transparent ? " transparent" : " ",
-                              bus->number, bus->subordinate,
-                              pcibios_assign_all_busses() ? " " :
-                              " (try 'pci=assign-busses')");
-                       printk(KERN_WARNING "Please report the result to "
-                              "linux-kernel to fix this permanently\n");
+                       pr_debug("PCI: Bus #%02x (-#%02x) is %s "
+                               "hidden behind%s bridge #%02x (-#%02x)\n",
+                               child->number, child->subordinate,
+                               (bus->number > child->subordinate &&
+                                bus->subordinate < child->number) ?
+                                       "wholly" : "partially",
+                               bus->self->transparent ? " transparent" : "",
+                               bus->number, bus->subordinate);
                }
                bus = bus->parent;
        }
@@ -682,34 +663,7 @@ static void pci_read_irq(struct pci_dev *dev)
        dev->irq = irq;
 }
 
-static void change_legacy_io_resource(struct pci_dev * dev, unsigned index,
-                                      unsigned start, unsigned end)
-{
-       unsigned base = start & PCI_BASE_ADDRESS_IO_MASK;
-       unsigned len = (end | ~PCI_BASE_ADDRESS_IO_MASK) - base + 1;
-
-       /*
-        * Some X versions get confused when the BARs reported through
-        * /sys or /proc differ from those seen in config space, thus
-        * try to update the config space values, too.
-        */
-       if (!(pci_resource_flags(dev, index) & IORESOURCE_IO))
-               printk(KERN_WARNING "%s: cannot adjust BAR%u (not I/O)\n",
-                      pci_name(dev), index);
-       else if (pci_resource_len(dev, index) != len)
-               printk(KERN_WARNING "%s: cannot adjust BAR%u (size %04X)\n",
-                      pci_name(dev), index, (unsigned)pci_resource_len(dev, index));
-       else {
-               printk(KERN_INFO "%s: trying to change BAR%u from %04X to %04X\n",
-                      pci_name(dev), index,
-                      (unsigned)pci_resource_start(dev, index), base);
-               pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + index * 4, base);
-       }
-       pci_resource_start(dev, index) = start;
-       pci_resource_end(dev, index)   = end;
-       pci_resource_flags(dev, index) =
-               IORESOURCE_IO | IORESOURCE_PCI_FIXED | PCI_BASE_ADDRESS_SPACE_IO;
-}
+#define LEGACY_IO_RESOURCE     (IORESOURCE_IO | IORESOURCE_PCI_FIXED)
 
 /**
  * pci_setup_device - fill in class and map information of a device
@@ -729,6 +683,7 @@ static int pci_setup_device(struct pci_dev * dev)
                dev->bus->number, PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn));
 
        pci_read_config_dword(dev, PCI_CLASS_REVISION, &class);
+       dev->revision = class & 0xff;
        class >>= 8;                                /* upper 3 bytes */
        dev->class = class;
        class >>= 8;
@@ -762,12 +717,20 @@ static int pci_setup_device(struct pci_dev * dev)
                        u8 progif;
                        pci_read_config_byte(dev, PCI_CLASS_PROG, &progif);
                        if ((progif & 1) == 0) {
-                               change_legacy_io_resource(dev, 0, 0x1F0, 0x1F7);
-                               change_legacy_io_resource(dev, 1, 0x3F6, 0x3F6);
+                               dev->resource[0].start = 0x1F0;
+                               dev->resource[0].end = 0x1F7;
+                               dev->resource[0].flags = LEGACY_IO_RESOURCE;
+                               dev->resource[1].start = 0x3F6;
+                               dev->resource[1].end = 0x3F6;
+                               dev->resource[1].flags = LEGACY_IO_RESOURCE;
                        }
                        if ((progif & 4) == 0) {
-                               change_legacy_io_resource(dev, 2, 0x170, 0x177);
-                               change_legacy_io_resource(dev, 3, 0x376, 0x376);
+                               dev->resource[2].start = 0x170;
+                               dev->resource[2].end = 0x177;
+                               dev->resource[2].flags = LEGACY_IO_RESOURCE;
+                               dev->resource[3].start = 0x376;
+                               dev->resource[3].end = 0x376;
+                               dev->resource[3].flags = LEGACY_IO_RESOURCE;
                        }
                }
                break;
@@ -822,6 +785,19 @@ static void pci_release_dev(struct device *dev)
        kfree(pci_dev);
 }
 
+static void set_pcie_port_type(struct pci_dev *pdev)
+{
+       int pos;
+       u16 reg16;
+
+       pos = pci_find_capability(pdev, PCI_CAP_ID_EXP);
+       if (!pos)
+               return;
+       pdev->is_pcie = 1;
+       pci_read_config_word(pdev, pos + PCI_EXP_FLAGS, &reg16);
+       pdev->pcie_type = (reg16 & PCI_EXP_FLAGS_TYPE) >> 4;
+}
+
 /**
  * pci_cfg_space_size - get the configuration space size of the PCI device.
  * @dev: PCI device
@@ -865,6 +841,23 @@ static void pci_release_bus_bridge_dev(struct device *dev)
        kfree(dev);
 }
 
+struct pci_dev *alloc_pci_dev(void)
+{
+       struct pci_dev *dev;
+
+       dev = kzalloc(sizeof(struct pci_dev), GFP_KERNEL);
+       if (!dev)
+               return NULL;
+
+       INIT_LIST_HEAD(&dev->global_list);
+       INIT_LIST_HEAD(&dev->bus_list);
+
+       pci_msi_init_pci_dev(dev);
+
+       return dev;
+}
+EXPORT_SYMBOL(alloc_pci_dev);
+
 /*
  * Read the config data for a PCI device, sanity-check it
  * and fill in the dev structure...
@@ -904,7 +897,7 @@ pci_scan_device(struct pci_bus *bus, int devfn)
        if (pci_bus_read_config_byte(bus, devfn, PCI_HEADER_TYPE, &hdr_type))
                return NULL;
 
-       dev = kzalloc(sizeof(struct pci_dev), GFP_KERNEL);
+       dev = alloc_pci_dev();
        if (!dev)
                return NULL;
 
@@ -919,6 +912,7 @@ pci_scan_device(struct pci_bus *bus, int devfn)
        dev->device = (l >> 16) & 0xffff;
        dev->cfg_size = pci_cfg_space_size(dev);
        dev->error_state = pci_channel_io_normal;
+       set_pcie_port_type(dev);
 
        /* Assume 32-bit PCI; let 64-bit PCI cards (which are far rarer)
           set this higher, assuming the system even supports it.  */
@@ -931,7 +925,7 @@ pci_scan_device(struct pci_bus *bus, int devfn)
        return dev;
 }
 
-void __devinit pci_device_add(struct pci_dev *dev, struct pci_bus *bus)
+void pci_device_add(struct pci_dev *dev, struct pci_bus *bus)
 {
        device_initialize(&dev->dev);
        dev->dev.release = pci_release_dev;
@@ -939,8 +933,12 @@ void __devinit pci_device_add(struct pci_dev *dev, struct pci_bus *bus)
 
        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;
 
+       pci_set_dma_max_seg_size(dev, 65536);
+       pci_set_dma_seg_boundary(dev, 0xffffffff);
+
        /* Fix up broken headers */
        pci_fixup_device(pci_fixup_header, dev);
 
@@ -954,8 +952,7 @@ void __devinit pci_device_add(struct pci_dev *dev, struct pci_bus *bus)
        up_write(&pci_bus_sem);
 }
 
-struct pci_dev * __devinit
-pci_scan_single_device(struct pci_bus *bus, int devfn)
+struct pci_dev *__ref pci_scan_single_device(struct pci_bus *bus, int devfn)
 {
        struct pci_dev *dev;
 
@@ -967,6 +964,7 @@ pci_scan_single_device(struct pci_bus *bus, int devfn)
 
        return dev;
 }
+EXPORT_SYMBOL(pci_scan_single_device);
 
 /**
  * pci_scan_slot - scan a PCI slot on a bus for devices.
@@ -977,7 +975,7 @@ pci_scan_single_device(struct pci_bus *bus, int devfn)
  * discovered devices to the @bus->devices list.  New devices
  * will have an empty dev->global_list head.
  */
-int __devinit pci_scan_slot(struct pci_bus *bus, int devfn)
+int pci_scan_slot(struct pci_bus *bus, int devfn)
 {
        int func, nr = 0;
        int scan_all_fns;
@@ -1046,21 +1044,7 @@ unsigned int __devinit pci_scan_child_bus(struct pci_bus *bus)
        return max;
 }
 
-unsigned int __devinit pci_do_scan_bus(struct pci_bus *bus)
-{
-       unsigned int max;
-
-       max = pci_scan_child_bus(bus);
-
-       /*
-        * Make the discovered devices available.
-        */
-       pci_bus_add_devices(bus);
-
-       return max;
-}
-
-struct pci_bus * __devinit pci_create_bus(struct device *parent,
+struct pci_bus * pci_create_bus(struct device *parent,
                int bus, struct pci_ops *ops, void *sysdata)
 {
        int error;
@@ -1099,32 +1083,27 @@ struct pci_bus * __devinit pci_create_bus(struct device *parent,
                goto dev_reg_err;
        b->bridge = get_device(dev);
 
-       b->class_dev.class = &pcibus_class;
-       sprintf(b->class_dev.class_id, "%04x:%02x", pci_domain_nr(b), bus);
-       error = class_device_register(&b->class_dev);
+       b->dev.class = &pcibus_class;
+       b->dev.parent = b->bridge;
+       sprintf(b->dev.bus_id, "%04x:%02x", pci_domain_nr(b), bus);
+       error = device_register(&b->dev);
        if (error)
                goto class_dev_reg_err;
-       error = class_device_create_file(&b->class_dev, &class_device_attr_cpuaffinity);
+       error = device_create_file(&b->dev, &dev_attr_cpuaffinity);
        if (error)
-               goto class_dev_create_file_err;
+               goto dev_create_file_err;
 
        /* Create legacy_io and legacy_mem files for this bus */
        pci_create_legacy_files(b);
 
-       error = sysfs_create_link(&b->class_dev.kobj, &b->bridge->kobj, "bridge");
-       if (error)
-               goto sys_create_link_err;
-
        b->number = b->secondary = bus;
        b->resource[0] = &ioport_resource;
        b->resource[1] = &iomem_resource;
 
        return b;
 
-sys_create_link_err:
-       class_device_remove_file(&b->class_dev, &class_device_attr_cpuaffinity);
-class_dev_create_file_err:
-       class_device_unregister(&b->class_dev);
+dev_create_file_err:
+       device_unregister(&b->dev);
 class_dev_reg_err:
        device_unregister(dev);
 dev_reg_err:
@@ -1136,7 +1115,6 @@ 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)
@@ -1152,10 +1130,8 @@ EXPORT_SYMBOL(pci_scan_bus_parented);
 
 #ifdef CONFIG_HOTPLUG
 EXPORT_SYMBOL(pci_add_new_bus);
-EXPORT_SYMBOL(pci_do_scan_bus);
 EXPORT_SYMBOL(pci_scan_slot);
 EXPORT_SYMBOL(pci_scan_bridge);
-EXPORT_SYMBOL(pci_scan_single_device);
 EXPORT_SYMBOL_GPL(pci_scan_child_bus);
 #endif
 
@@ -1206,16 +1182,19 @@ static void __init pci_sort_breadthfirst_klist(void)
        struct klist_node *n;
        struct device *dev;
        struct pci_dev *pdev;
+       struct klist *device_klist;
+
+       device_klist = bus_get_device_klist(&pci_bus_type);
 
-       spin_lock(&pci_bus_type.klist_devices.k_lock);
-       list_for_each_safe(pos, tmp, &pci_bus_type.klist_devices.k_list) {
+       spin_lock(&device_klist->k_lock);
+       list_for_each_safe(pos, tmp, &device_klist->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);
+       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)