]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/pci/remove.c
PCI: fix codingstyle issues in include/linux/pci.h
[mirror_ubuntu-bionic-kernel.git] / drivers / pci / remove.c
CommitLineData
1da177e4
LT
1#include <linux/pci.h>
2#include <linux/module.h>
6c723d5b 3#include <linux/aspm.h>
1da177e4
LT
4#include "pci.h"
5
6static void pci_free_resources(struct pci_dev *dev)
7{
8 int i;
9
10 msi_remove_pci_irq_vectors(dev);
11
12 pci_cleanup_rom(dev);
13 for (i = 0; i < PCI_NUM_RESOURCES; i++) {
14 struct resource *res = dev->resource + i;
15 if (res->parent)
16 release_resource(res);
17 }
18}
19
24f8aa9b 20static void pci_stop_dev(struct pci_dev *dev)
1da177e4 21{
24f8aa9b
ST
22 if (!dev->global_list.next)
23 return;
24
091ca9f0
RS
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);
d71374da 29 down_write(&pci_bus_sem);
091ca9f0
RS
30 list_del(&dev->global_list);
31 dev->global_list.next = dev->global_list.prev = NULL;
d71374da 32 up_write(&pci_bus_sem);
091ca9f0 33 }
6c723d5b
SL
34
35 if (dev->bus->self)
36 pcie_aspm_exit_link_state(dev);
24f8aa9b
ST
37}
38
39static void pci_destroy_dev(struct pci_dev *dev)
40{
41 pci_stop_dev(dev);
1da177e4
LT
42
43 /* Remove the device from the device lists, and prevent any further
44 * list accesses from this device */
d71374da 45 down_write(&pci_bus_sem);
1da177e4 46 list_del(&dev->bus_list);
1da177e4 47 dev->bus_list.next = dev->bus_list.prev = NULL;
d71374da 48 up_write(&pci_bus_sem);
1da177e4
LT
49
50 pci_free_resources(dev);
51 pci_dev_put(dev);
52}
53
54/**
55 * pci_remove_device_safe - remove an unused hotplug device
56 * @dev: the device to remove
57 *
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.
62 */
54c762fe 63#if 0
1da177e4
LT
64int pci_remove_device_safe(struct pci_dev *dev)
65{
66 if (pci_dev_driver(dev))
67 return -EBUSY;
68 pci_destroy_dev(dev);
69 return 0;
70}
54c762fe 71#endif /* 0 */
1da177e4
LT
72
73void pci_remove_bus(struct pci_bus *pci_bus)
74{
75 pci_proc_detach_bus(pci_bus);
76
d71374da 77 down_write(&pci_bus_sem);
1da177e4 78 list_del(&pci_bus->node);
d71374da 79 up_write(&pci_bus_sem);
1da177e4
LT
80 pci_remove_legacy_files(pci_bus);
81 class_device_remove_file(&pci_bus->class_dev,
82 &class_device_attr_cpuaffinity);
83 sysfs_remove_link(&pci_bus->class_dev.kobj, "bridge");
84 class_device_unregister(&pci_bus->class_dev);
85}
86EXPORT_SYMBOL(pci_remove_bus);
87
88/**
89 * pci_remove_bus_device - remove a PCI device and any children
90 * @dev: the device to remove
91 *
92 * Remove a PCI device from the device lists, informing the drivers
93 * that the device has been removed. We also remove any subordinate
94 * buses and children in a depth-first manner.
95 *
96 * For each device we remove, delete the device structure from the
97 * device lists, remove the /proc entry, and notify userspace
98 * (/sbin/hotplug).
99 */
100void pci_remove_bus_device(struct pci_dev *dev)
101{
102 if (dev->subordinate) {
103 struct pci_bus *b = dev->subordinate;
104
105 pci_remove_behind_bridge(dev);
106 pci_remove_bus(b);
107 dev->subordinate = NULL;
108 }
109
110 pci_destroy_dev(dev);
111}
112
113/**
114 * pci_remove_behind_bridge - remove all devices behind a PCI bridge
115 * @dev: PCI bridge device
116 *
117 * Remove all devices on the bus, except for the parent bridge.
118 * This also removes any child buses, and any devices they may
119 * contain in a depth-first manner.
120 */
121void pci_remove_behind_bridge(struct pci_dev *dev)
122{
123 struct list_head *l, *n;
124
125 if (dev->subordinate) {
126 list_for_each_safe(l, n, &dev->subordinate->devices) {
127 struct pci_dev *dev = pci_dev_b(l);
128
129 pci_remove_bus_device(dev);
130 }
131 }
132}
133
24f8aa9b
ST
134static void pci_stop_bus_devices(struct pci_bus *bus)
135{
136 struct list_head *l, *n;
137
138 list_for_each_safe(l, n, &bus->devices) {
139 struct pci_dev *dev = pci_dev_b(l);
140 pci_stop_bus_device(dev);
141 }
142}
143
144/**
145 * pci_stop_bus_device - stop a PCI device and any children
146 * @dev: the device to stop
147 *
148 * Stop a PCI device (detach the driver, remove from the global list
149 * and so on). This also stop any subordinate buses and children in a
150 * depth-first manner.
151 */
152void pci_stop_bus_device(struct pci_dev *dev)
153{
154 if (dev->subordinate)
155 pci_stop_bus_devices(dev->subordinate);
156
157 pci_stop_dev(dev);
158}
159
1da177e4
LT
160EXPORT_SYMBOL(pci_remove_bus_device);
161EXPORT_SYMBOL(pci_remove_behind_bridge);
24f8aa9b 162EXPORT_SYMBOL_GPL(pci_stop_bus_device);