2 #include <linux/module.h>
3 #include <linux/pci-aspm.h>
6 static void pci_free_resources(struct pci_dev *dev)
11 for (i = 0; i < PCI_NUM_RESOURCES; i++) {
12 struct resource *res = dev->resource + i;
14 release_resource(res);
18 static void pci_stop_dev(struct pci_dev *dev)
20 pci_pme_active(dev, false);
23 pci_proc_detach_device(dev);
24 pci_remove_sysfs_dev_files(dev);
25 device_release_driver(&dev->dev);
31 pcie_aspm_exit_link_state(dev);
34 static void pci_destroy_dev(struct pci_dev *dev)
36 if (!dev->dev.kobj.parent)
39 device_del(&dev->dev);
41 down_write(&pci_bus_sem);
42 list_del(&dev->bus_list);
43 up_write(&pci_bus_sem);
45 pci_free_resources(dev);
46 put_device(&dev->dev);
49 void pci_remove_bus(struct pci_bus *bus)
51 pci_proc_detach_bus(bus);
53 down_write(&pci_bus_sem);
55 pci_bus_release_busn_res(bus);
56 up_write(&pci_bus_sem);
57 pci_remove_legacy_files(bus);
58 pcibios_remove_bus(bus);
59 device_unregister(&bus->dev);
61 EXPORT_SYMBOL(pci_remove_bus);
63 static void pci_stop_bus_device(struct pci_dev *dev)
65 struct pci_bus *bus = dev->subordinate;
66 struct pci_dev *child, *tmp;
69 * Stopping an SR-IOV PF device removes all the associated VFs,
70 * which will update the bus->devices list and confuse the
71 * iterator. Therefore, iterate in reverse so we remove the VFs
75 list_for_each_entry_safe_reverse(child, tmp,
76 &bus->devices, bus_list)
77 pci_stop_bus_device(child);
83 static void pci_remove_bus_device(struct pci_dev *dev)
85 struct pci_bus *bus = dev->subordinate;
86 struct pci_dev *child, *tmp;
89 list_for_each_entry_safe(child, tmp,
90 &bus->devices, bus_list)
91 pci_remove_bus_device(child);
94 dev->subordinate = NULL;
101 * pci_stop_and_remove_bus_device - remove a PCI device and any children
102 * @dev: the device to remove
104 * Remove a PCI device from the device lists, informing the drivers
105 * that the device has been removed. We also remove any subordinate
106 * buses and children in a depth-first manner.
108 * For each device we remove, delete the device structure from the
109 * device lists, remove the /proc entry, and notify userspace
112 void pci_stop_and_remove_bus_device(struct pci_dev *dev)
114 pci_stop_bus_device(dev);
115 pci_remove_bus_device(dev);
117 EXPORT_SYMBOL(pci_stop_and_remove_bus_device);
119 void pci_stop_and_remove_bus_device_locked(struct pci_dev *dev)
121 pci_lock_rescan_remove();
122 pci_stop_and_remove_bus_device(dev);
123 pci_unlock_rescan_remove();
125 EXPORT_SYMBOL_GPL(pci_stop_and_remove_bus_device_locked);
127 void pci_stop_root_bus(struct pci_bus *bus)
129 struct pci_dev *child, *tmp;
130 struct pci_host_bridge *host_bridge;
132 if (!pci_is_root_bus(bus))
135 host_bridge = to_pci_host_bridge(bus->bridge);
136 list_for_each_entry_safe_reverse(child, tmp,
137 &bus->devices, bus_list)
138 pci_stop_bus_device(child);
140 /* stop the host bridge */
141 device_release_driver(&host_bridge->dev);
143 EXPORT_SYMBOL_GPL(pci_stop_root_bus);
145 void pci_remove_root_bus(struct pci_bus *bus)
147 struct pci_dev *child, *tmp;
148 struct pci_host_bridge *host_bridge;
150 if (!pci_is_root_bus(bus))
153 host_bridge = to_pci_host_bridge(bus->bridge);
154 list_for_each_entry_safe(child, tmp,
155 &bus->devices, bus_list)
156 pci_remove_bus_device(child);
158 host_bridge->bus = NULL;
160 /* remove the host bridge */
161 device_unregister(&host_bridge->dev);
163 EXPORT_SYMBOL_GPL(pci_remove_root_bus);