[PATCH] CPCI hotplug: fix resource assignment

Here is a patch against the CPCI hotplug core to fix up PCI resource
assignment such that things will actually work when a hot inserted
device is enabled. I mentioned this patch to you way back in April at
ELC, but am only now out from under things enough to clean it up and
submit it. I've basically cribbed the corresponding code from
shpchp_pci.c, so there are no big surprises. If it's still possible, I
wouldn't mind this going into 2.6.18, but it wouldn't be the end of the
world if it went into 2.6.19.

Signed-off-by: Scott Murray <scottm@somanetworks.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by Scott Murray and committed by Greg Kroah-Hartman cc702c2c 65ae4ddd

+41 -11
+41 -11
drivers/pci/hotplug/cpci_hotplug_pci.c
··· 254 255 int cpci_configure_slot(struct slot* slot) 256 { 257 - unsigned char busnr; 258 - struct pci_bus *child; 259 260 dbg("%s - enter", __FUNCTION__); 261 ··· 276 */ 277 n = pci_scan_slot(slot->bus, slot->devfn); 278 dbg("%s: pci_scan_slot returned %d", __FUNCTION__, n); 279 - if (n > 0) 280 - pci_bus_add_devices(slot->bus); 281 slot->dev = pci_get_slot(slot->bus, slot->devfn); 282 if (slot->dev == NULL) { 283 err("Could not find PCI device for slot %02x", slot->number); 284 - return 1; 285 } 286 } 287 288 - if (slot->dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) { 289 - pci_read_config_byte(slot->dev, PCI_SECONDARY_BUS, &busnr); 290 - child = pci_add_new_bus(slot->dev->bus, slot->dev, busnr); 291 - pci_do_scan_bus(child); 292 - pci_bus_size_bridges(child); 293 } 294 295 - pci_bus_assign_resources(slot->dev->bus); 296 297 dbg("%s - exit", __FUNCTION__); 298 return 0;
··· 254 255 int cpci_configure_slot(struct slot* slot) 256 { 257 + struct pci_bus *parent; 258 + int fn; 259 260 dbg("%s - enter", __FUNCTION__); 261 ··· 276 */ 277 n = pci_scan_slot(slot->bus, slot->devfn); 278 dbg("%s: pci_scan_slot returned %d", __FUNCTION__, n); 279 slot->dev = pci_get_slot(slot->bus, slot->devfn); 280 if (slot->dev == NULL) { 281 err("Could not find PCI device for slot %02x", slot->number); 282 + return -ENODEV; 283 } 284 } 285 + parent = slot->dev->bus; 286 287 + for (fn = 0; fn < 8; fn++) { 288 + struct pci_dev *dev; 289 + 290 + dev = pci_get_slot(parent, PCI_DEVFN(PCI_SLOT(slot->devfn), fn)); 291 + if (!dev) 292 + continue; 293 + if ((dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) || 294 + (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)) { 295 + /* Find an unused bus number for the new bridge */ 296 + struct pci_bus *child; 297 + unsigned char busnr, start = parent->secondary; 298 + unsigned char end = parent->subordinate; 299 + 300 + for (busnr = start; busnr <= end; busnr++) { 301 + if (!pci_find_bus(pci_domain_nr(parent), 302 + busnr)) 303 + break; 304 + } 305 + if (busnr >= end) { 306 + err("No free bus for hot-added bridge\n"); 307 + pci_dev_put(dev); 308 + continue; 309 + } 310 + child = pci_add_new_bus(parent, dev, busnr); 311 + if (!child) { 312 + err("Cannot add new bus for %s\n", 313 + pci_name(dev)); 314 + pci_dev_put(dev); 315 + continue; 316 + } 317 + child->subordinate = pci_do_scan_bus(child); 318 + pci_bus_size_bridges(child); 319 + } 320 + pci_dev_put(dev); 321 } 322 323 + pci_bus_assign_resources(parent); 324 + pci_bus_add_devices(parent); 325 + pci_enable_bridges(parent); 326 327 dbg("%s - exit", __FUNCTION__); 328 return 0;