Merge branch 'devel' of master.kernel.org:/home/rmk/linux-2.6-arm
[safe/jmp/linux-2.6] / drivers / pci / bus.c
index e75d219..628ea20 100644 (file)
 #include <linux/ioport.h>
 #include <linux/proc_fs.h>
 #include <linux/init.h>
+#include <linux/slab.h>
 
 #include "pci.h"
 
+void pci_bus_add_resource(struct pci_bus *bus, struct resource *res,
+                         unsigned int flags)
+{
+       struct pci_bus_resource *bus_res;
+
+       bus_res = kzalloc(sizeof(struct pci_bus_resource), GFP_KERNEL);
+       if (!bus_res) {
+               dev_err(&bus->dev, "can't add %pR resource\n", res);
+               return;
+       }
+
+       bus_res->res = res;
+       bus_res->flags = flags;
+       list_add_tail(&bus_res->list, &bus->resources);
+}
+
+struct resource *pci_bus_resource_n(const struct pci_bus *bus, int n)
+{
+       struct pci_bus_resource *bus_res;
+
+       if (n < PCI_BRIDGE_RESOURCE_NUM)
+               return bus->resource[n];
+
+       n -= PCI_BRIDGE_RESOURCE_NUM;
+       list_for_each_entry(bus_res, &bus->resources, list) {
+               if (n-- == 0)
+                       return bus_res->res;
+       }
+       return NULL;
+}
+EXPORT_SYMBOL_GPL(pci_bus_resource_n);
+
+void pci_bus_remove_resources(struct pci_bus *bus)
+{
+       struct pci_bus_resource *bus_res, *tmp;
+       int i;
+
+       for (i = 0; i < PCI_BRIDGE_RESOURCE_NUM; i++)
+               bus->resource[i] = 0;
+
+       list_for_each_entry_safe(bus_res, tmp, &bus->resources, list) {
+               list_del(&bus_res->list);
+               kfree(bus_res);
+       }
+}
+
 /**
  * pci_bus_alloc_resource - allocate a resource from a parent bus
  * @bus: PCI bus
@@ -242,9 +289,9 @@ void pci_walk_bus(struct pci_bus *top, int (*cb)(struct pci_dev *, void *),
                        next = dev->bus_list.next;
 
                /* Run device routines with the device locked */
-               down(&dev->dev.sem);
+               device_lock(&dev->dev);
                retval = cb(dev, userdata);
-               up(&dev->dev.sem);
+               device_unlock(&dev->dev);
                if (retval)
                        break;
        }