2 #include <linux/module.h>
3 #include <linux/aspm.h>
6 static void pci_free_resources(struct pci_dev
*dev
)
10 msi_remove_pci_irq_vectors(dev
);
13 for (i
= 0; i
< PCI_NUM_RESOURCES
; i
++) {
14 struct resource
*res
= dev
->resource
+ i
;
16 release_resource(res
);
20 static void pci_stop_dev(struct pci_dev
*dev
)
22 if (!dev
->global_list
.next
)
25 if (!list_empty(&dev
->global_list
)) {
26 pci_proc_detach_device(dev
);
27 pci_remove_sysfs_dev_files(dev
);
28 device_unregister(&dev
->dev
);
29 down_write(&pci_bus_sem
);
30 list_del(&dev
->global_list
);
31 dev
->global_list
.next
= dev
->global_list
.prev
= NULL
;
32 up_write(&pci_bus_sem
);
36 pcie_aspm_exit_link_state(dev
);
39 static void pci_destroy_dev(struct pci_dev
*dev
)
43 /* Remove the device from the device lists, and prevent any further
44 * list accesses from this device */
45 down_write(&pci_bus_sem
);
46 list_del(&dev
->bus_list
);
47 dev
->bus_list
.next
= dev
->bus_list
.prev
= NULL
;
48 up_write(&pci_bus_sem
);
50 pci_free_resources(dev
);
55 * pci_remove_device_safe - remove an unused hotplug device
56 * @dev: the device to remove
58 * Delete the device structure from the device lists and
59 * notify userspace (/sbin/hotplug), but only if the device
60 * in question is not being used by a driver.
61 * Returns 0 on success.
64 int pci_remove_device_safe(struct pci_dev
*dev
)
66 if (pci_dev_driver(dev
))
73 void pci_remove_bus(struct pci_bus
*pci_bus
)
75 pci_proc_detach_bus(pci_bus
);
77 down_write(&pci_bus_sem
);
78 list_del(&pci_bus
->node
);
79 up_write(&pci_bus_sem
);
80 pci_remove_legacy_files(pci_bus
);
81 device_remove_file(&pci_bus
->dev
, &dev_attr_cpuaffinity
);
82 device_unregister(&pci_bus
->dev
);
84 EXPORT_SYMBOL(pci_remove_bus
);
87 * pci_remove_bus_device - remove a PCI device and any children
88 * @dev: the device to remove
90 * Remove a PCI device from the device lists, informing the drivers
91 * that the device has been removed. We also remove any subordinate
92 * buses and children in a depth-first manner.
94 * For each device we remove, delete the device structure from the
95 * device lists, remove the /proc entry, and notify userspace
98 void pci_remove_bus_device(struct pci_dev
*dev
)
100 if (dev
->subordinate
) {
101 struct pci_bus
*b
= dev
->subordinate
;
103 pci_remove_behind_bridge(dev
);
105 dev
->subordinate
= NULL
;
108 pci_destroy_dev(dev
);
112 * pci_remove_behind_bridge - remove all devices behind a PCI bridge
113 * @dev: PCI bridge device
115 * Remove all devices on the bus, except for the parent bridge.
116 * This also removes any child buses, and any devices they may
117 * contain in a depth-first manner.
119 void pci_remove_behind_bridge(struct pci_dev
*dev
)
121 struct list_head
*l
, *n
;
123 if (dev
->subordinate
) {
124 list_for_each_safe(l
, n
, &dev
->subordinate
->devices
) {
125 struct pci_dev
*dev
= pci_dev_b(l
);
127 pci_remove_bus_device(dev
);
132 static void pci_stop_bus_devices(struct pci_bus
*bus
)
134 struct list_head
*l
, *n
;
136 list_for_each_safe(l
, n
, &bus
->devices
) {
137 struct pci_dev
*dev
= pci_dev_b(l
);
138 pci_stop_bus_device(dev
);
143 * pci_stop_bus_device - stop a PCI device and any children
144 * @dev: the device to stop
146 * Stop a PCI device (detach the driver, remove from the global list
147 * and so on). This also stop any subordinate buses and children in a
148 * depth-first manner.
150 void pci_stop_bus_device(struct pci_dev
*dev
)
152 if (dev
->subordinate
)
153 pci_stop_bus_devices(dev
->subordinate
);
158 EXPORT_SYMBOL(pci_remove_bus_device
);
159 EXPORT_SYMBOL(pci_remove_behind_bridge
);
160 EXPORT_SYMBOL_GPL(pci_stop_bus_device
);