2 #include <linux/module.h>
8 #define DBG(x...) printk(x)
13 static void pci_free_resources(struct pci_dev *dev)
17 msi_remove_pci_irq_vectors(dev);
19 for (i = 0; i < PCI_NUM_RESOURCES; i++) {
20 struct resource *res = dev->resource + i;
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);
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))
60 EXPORT_SYMBOL(pci_remove_device_safe);
63 * pci_remove_bus_device - remove a PCI device and any children
64 * @dev: the device to remove
66 * Remove a PCI device from the device lists, informing the drivers
67 * that the device has been removed. We also remove any subordinate
68 * buses and children in a depth-first manner.
70 * For each device we remove, delete the device structure from the
71 * device lists, remove the /proc entry, and notify userspace
74 void pci_remove_bus_device(struct pci_dev *dev)
76 if (dev->subordinate) {
77 struct pci_bus *b = dev->subordinate;
79 pci_remove_behind_bridge(dev);
80 pci_proc_detach_bus(b);
82 spin_lock(&pci_bus_lock);
84 spin_unlock(&pci_bus_lock);
86 class_device_unregister(&b->class_dev);
87 dev->subordinate = NULL;
94 * pci_remove_behind_bridge - remove all devices behind a PCI bridge
95 * @dev: PCI bridge device
97 * Remove all devices on the bus, except for the parent bridge.
98 * This also removes any child buses, and any devices they may
99 * contain in a depth-first manner.
101 void pci_remove_behind_bridge(struct pci_dev *dev)
103 struct list_head *l, *n;
105 if (dev->subordinate) {
106 list_for_each_safe(l, n, &dev->subordinate->devices) {
107 struct pci_dev *dev = pci_dev_b(l);
109 pci_remove_bus_device(dev);
114 EXPORT_SYMBOL(pci_remove_bus_device);
115 EXPORT_SYMBOL(pci_remove_behind_bridge);