aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci/bus.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/pci/bus.c')
-rw-r--r--drivers/pci/bus.c81
1 files changed, 17 insertions, 64 deletions
diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c
index ad6a8b635692..8647dc6f52d0 100644
--- a/drivers/pci/bus.c
+++ b/drivers/pci/bus.c
@@ -158,69 +158,38 @@ pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res,
158 return ret; 158 return ret;
159} 159}
160 160
161void __weak pcibios_resource_survey_bus(struct pci_bus *bus) { }
162
161/** 163/**
162 * pci_bus_add_device - add a single device 164 * pci_bus_add_device - start driver for a single device
163 * @dev: device to add 165 * @dev: device to add
164 * 166 *
165 * This adds a single pci device to the global 167 * This adds add sysfs entries and start device drivers
166 * device list and adds sysfs and procfs entries
167 */ 168 */
168int pci_bus_add_device(struct pci_dev *dev) 169int pci_bus_add_device(struct pci_dev *dev)
169{ 170{
170 int retval; 171 int retval;
171 172
172 pci_fixup_device(pci_fixup_final, dev); 173 /*
173 174 * Can not put in pci_device_add yet because resources
174 retval = pcibios_add_device(dev); 175 * are not assigned yet for some devices.
175 if (retval) 176 */
176 return retval;
177
178 retval = device_add(&dev->dev);
179 if (retval)
180 return retval;
181
182 dev->is_added = 1;
183 pci_proc_attach_device(dev);
184 pci_create_sysfs_dev_files(dev); 177 pci_create_sysfs_dev_files(dev);
185 return 0;
186}
187
188/**
189 * pci_bus_add_child - add a child bus
190 * @bus: bus to add
191 *
192 * This adds sysfs entries for a single bus
193 */
194int pci_bus_add_child(struct pci_bus *bus)
195{
196 int retval;
197
198 if (bus->bridge)
199 bus->dev.parent = bus->bridge;
200 178
201 retval = device_register(&bus->dev); 179 dev->match_driver = true;
202 if (retval) 180 retval = device_attach(&dev->dev);
203 return retval; 181 WARN_ON(retval < 0);
204 182
205 bus->is_added = 1; 183 dev->is_added = 1;
206
207 /* Create legacy_io and legacy_mem files for this bus */
208 pci_create_legacy_files(bus);
209 184
210 return retval; 185 return 0;
211} 186}
212 187
213/** 188/**
214 * pci_bus_add_devices - insert newly discovered PCI devices 189 * pci_bus_add_devices - start driver for PCI devices
215 * @bus: bus to check for new devices 190 * @bus: bus to check for new devices
216 * 191 *
217 * Add newly discovered PCI devices (which are on the bus->devices 192 * Start driver for PCI devices and add some sysfs entries.
218 * list) to the global PCI device list, add the sysfs and procfs
219 * entries. Where a bridge is found, add the discovered bus to
220 * the parents list of child buses, and recurse (breadth-first
221 * to be compatible with 2.4)
222 *
223 * Call hotplug for each new devices.
224 */ 193 */
225void pci_bus_add_devices(const struct pci_bus *bus) 194void pci_bus_add_devices(const struct pci_bus *bus)
226{ 195{
@@ -233,36 +202,20 @@ void pci_bus_add_devices(const struct pci_bus *bus)
233 if (dev->is_added) 202 if (dev->is_added)
234 continue; 203 continue;
235 retval = pci_bus_add_device(dev); 204 retval = pci_bus_add_device(dev);
236 if (retval)
237 dev_err(&dev->dev, "Error adding device, continuing\n");
238 } 205 }
239 206
240 list_for_each_entry(dev, &bus->devices, bus_list) { 207 list_for_each_entry(dev, &bus->devices, bus_list) {
241 BUG_ON(!dev->is_added); 208 BUG_ON(!dev->is_added);
242 209
243 child = dev->subordinate; 210 child = dev->subordinate;
244 /* 211
245 * If there is an unattached subordinate bus, attach
246 * it and then scan for unattached PCI devices.
247 */
248 if (!child) 212 if (!child)
249 continue; 213 continue;
250 if (list_empty(&child->node)) {
251 down_write(&pci_bus_sem);
252 list_add_tail(&child->node, &dev->bus->children);
253 up_write(&pci_bus_sem);
254 }
255 pci_bus_add_devices(child); 214 pci_bus_add_devices(child);
256 215
257 /*
258 * register the bus with sysfs as the parent is now
259 * properly registered.
260 */
261 if (child->is_added) 216 if (child->is_added)
262 continue; 217 continue;
263 retval = pci_bus_add_child(child); 218 child->is_added = 1;
264 if (retval)
265 dev_err(&dev->dev, "Error adding bus, continuing\n");
266 } 219 }
267} 220}
268 221