]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/pci/probe.c
PCI: make no_pci_devices() use the pci_bus_type list
[linux-2.6-omap-h63xx.git] / drivers / pci / probe.c
index 5fd585293e7954c777094b6331e5a5fae9c094ca..387fbbb97431eef05d3920db995690ce2f201240 100644 (file)
@@ -22,16 +22,27 @@ 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
@@ -53,7 +64,7 @@ static void pci_create_legacy_files(struct pci_bus *b)
                b->legacy_io->attr.mode = S_IRUSR | S_IWUSR;
                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;
@@ -61,15 +72,15 @@ static void pci_create_legacy_files(struct pci_bus *b)
                b->legacy_mem->size = 1024*1024;
                b->legacy_mem->attr.mode = S_IRUSR | S_IWUSR;
                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 */
        }
 }
@@ -81,26 +92,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);
@@ -109,7 +121,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)
@@ -285,7 +297,7 @@ static void pci_read_bases(struct pci_dev *dev, unsigned int howmany, int rom)
        }
 }
 
-void pci_read_bridge_bases(struct pci_bus *child)
+void __devinit pci_read_bridge_bases(struct pci_bus *child)
 {
        struct pci_dev *dev = child->self;
        u8 io_base_lo, io_limit_lo;
@@ -392,7 +404,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..
@@ -408,15 +419,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
@@ -434,15 +442,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 *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;
 
@@ -471,8 +473,6 @@ static void pci_fixup_parent_subordinate_busnr(struct pci_bus *child, int max)
        }
 }
 
-unsigned int 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
@@ -483,7 +483,7 @@ unsigned int 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 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);
@@ -641,13 +641,13 @@ int pci_scan_bridge(struct pci_bus *bus, struct pci_dev * dev, int max, int pass
                    (child->number > bus->subordinate) ||
                    (child->number < bus->number) ||
                    (child->subordinate < bus->number)) {
-                       pr_debug("PCI: Bus #%02x (-#%02x) is %s"
+                       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" : " ",
+                                       "wholly" : "partially",
+                               bus->self->transparent ? " transparent" : "",
                                bus->number, bus->subordinate);
                }
                bus = bus->parent;
@@ -944,8 +944,12 @@ void 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);
 
@@ -959,7 +963,7 @@ void pci_device_add(struct pci_dev *dev, struct pci_bus *bus)
        up_write(&pci_bus_sem);
 }
 
-struct pci_dev *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;
 
@@ -971,6 +975,7 @@ struct pci_dev *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.
@@ -1014,7 +1019,7 @@ int pci_scan_slot(struct pci_bus *bus, int devfn)
        return nr;
 }
 
-unsigned int pci_scan_child_bus(struct pci_bus *bus)
+unsigned int __devinit pci_scan_child_bus(struct pci_bus *bus)
 {
        unsigned int devfn, pass, max = bus->secondary;
        struct pci_dev *dev;
@@ -1050,20 +1055,6 @@ unsigned int 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 * pci_create_bus(struct device *parent,
                int bus, struct pci_ops *ops, void *sysdata)
 {
@@ -1103,32 +1094,27 @@ struct pci_bus * 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:
@@ -1140,9 +1126,8 @@ err_out:
        kfree(b);
        return NULL;
 }
-EXPORT_SYMBOL_GPL(pci_create_bus);
 
-struct pci_bus *pci_scan_bus_parented(struct device *parent,
+struct pci_bus * __devinit pci_scan_bus_parented(struct device *parent,
                int bus, struct pci_ops *ops, void *sysdata)
 {
        struct pci_bus *b;
@@ -1156,10 +1141,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