MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / drivers / pci / remove.c
blob889b2e3ac84022ba649389a527850ffd0571415e
1 #include <linux/pci.h>
2 #include <linux/module.h>
3 #include "pci.h"
5 #undef DEBUG
7 #ifdef DEBUG
8 #define DBG(x...) printk(x)
9 #else
10 #define DBG(x...)
11 #endif
13 static void pci_free_resources(struct pci_dev *dev)
15 int i;
17 msi_remove_pci_irq_vectors(dev);
19 for (i = 0; i < PCI_NUM_RESOURCES; i++) {
20 struct resource *res = dev->resource + i;
21 if (res->parent)
22 release_resource(res);
26 static void pci_destroy_dev(struct pci_dev *dev)
28 pci_proc_detach_device(dev);
29 device_unregister(&dev->dev);
31 /* Remove the device from the device lists, and prevent any further
32 * list accesses from this device */
33 spin_lock(&pci_bus_lock);
34 list_del(&dev->bus_list);
35 list_del(&dev->global_list);
36 dev->bus_list.next = dev->bus_list.prev = NULL;
37 dev->global_list.next = dev->global_list.prev = NULL;
38 spin_unlock(&pci_bus_lock);
40 pci_free_resources(dev);
41 pci_dev_put(dev);
44 /**
45 * pci_remove_device_safe - remove an unused hotplug device
46 * @dev: the device to remove
48 * Delete the device structure from the device lists and
49 * notify userspace (/sbin/hotplug), but only if the device
50 * in question is not being used by a driver.
51 * Returns 0 on success.
53 int pci_remove_device_safe(struct pci_dev *dev)
55 if (pci_dev_driver(dev))
56 return -EBUSY;
57 pci_destroy_dev(dev);
58 return 0;
60 EXPORT_SYMBOL(pci_remove_device_safe);
62 void pci_remove_bus(struct pci_bus *b)
64 pci_proc_detach_bus(b);
66 spin_lock(&pci_bus_lock);
67 list_del(&b->node);
68 spin_unlock(&pci_bus_lock);
70 class_device_unregister(&b->class_dev);
72 EXPORT_SYMBOL(pci_remove_bus);
74 /**
75 * pci_remove_bus_device - remove a PCI device and any children
76 * @dev: the device to remove
78 * Remove a PCI device from the device lists, informing the drivers
79 * that the device has been removed. We also remove any subordinate
80 * buses and children in a depth-first manner.
82 * For each device we remove, delete the device structure from the
83 * device lists, remove the /proc entry, and notify userspace
84 * (/sbin/hotplug).
86 void pci_remove_bus_device(struct pci_dev *dev)
88 if (dev->subordinate) {
89 struct pci_bus *b = dev->subordinate;
91 pci_remove_behind_bridge(dev);
92 pci_remove_bus(b);
93 dev->subordinate = NULL;
96 pci_destroy_dev(dev);
99 /**
100 * pci_remove_behind_bridge - remove all devices behind a PCI bridge
101 * @dev: PCI bridge device
103 * Remove all devices on the bus, except for the parent bridge.
104 * This also removes any child buses, and any devices they may
105 * contain in a depth-first manner.
107 void pci_remove_behind_bridge(struct pci_dev *dev)
109 struct list_head *l, *n;
111 if (dev->subordinate) {
112 list_for_each_safe(l, n, &dev->subordinate->devices) {
113 struct pci_dev *dev = pci_dev_b(l);
115 pci_remove_bus_device(dev);
120 EXPORT_SYMBOL(pci_remove_bus_device);
121 EXPORT_SYMBOL(pci_remove_behind_bridge);