diff options
| -rw-r--r-- | drivers/pci/Makefile | 3 | ||||
| -rw-r--r-- | drivers/pci/hotplug-pci.c | 29 | ||||
| -rw-r--r-- | drivers/pci/hotplug/acpiphp_glue.c | 15 | ||||
| -rw-r--r-- | drivers/pci/hotplug/cpci_hotplug_pci.c | 7 | ||||
| -rw-r--r-- | drivers/pci/hotplug/cpqphp.h | 2 | ||||
| -rw-r--r-- | drivers/pci/hotplug/cpqphp_core.c | 3 | ||||
| -rw-r--r-- | drivers/pci/hotplug/cpqphp_ctrl.c | 19 | ||||
| -rw-r--r-- | drivers/pci/hotplug/ibmphp_pci.c | 19 | ||||
| -rw-r--r-- | drivers/pci/hotplug/pciehp_ctrl.c | 7 | ||||
| -rw-r--r-- | drivers/pci/hotplug/pciehp_hpc.c | 25 | ||||
| -rw-r--r-- | drivers/pci/hotplug/pciehp_pci.c | 11 | ||||
| -rw-r--r-- | drivers/pci/hotplug/shpchp_hpc.c | 9 | ||||
| -rw-r--r-- | drivers/pci/hotplug/shpchp_pci.c | 6 | ||||
| -rw-r--r-- | drivers/pci/probe.c | 187 | ||||
| -rw-r--r-- | drivers/pci/setup-bus.c | 184 | ||||
| -rw-r--r-- | drivers/pcmcia/cardbus.c | 5 | ||||
| -rw-r--r-- | include/linux/pci.h | 4 |
17 files changed, 419 insertions, 116 deletions
diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile index 66a21acad952..fa56267fa2c0 100644 --- a/drivers/pci/Makefile +++ b/drivers/pci/Makefile | |||
| @@ -16,9 +16,6 @@ obj-$(CONFIG_PCIEPORTBUS) += pcie/ | |||
| 16 | 16 | ||
| 17 | # Build the PCI Hotplug drivers if we were asked to | 17 | # Build the PCI Hotplug drivers if we were asked to |
| 18 | obj-$(CONFIG_HOTPLUG_PCI) += hotplug/ | 18 | obj-$(CONFIG_HOTPLUG_PCI) += hotplug/ |
| 19 | ifdef CONFIG_HOTPLUG_PCI | ||
| 20 | obj-y += hotplug-pci.o | ||
| 21 | endif | ||
| 22 | 19 | ||
| 23 | # Build the PCI MSI interrupt support | 20 | # Build the PCI MSI interrupt support |
| 24 | obj-$(CONFIG_PCI_MSI) += msi.o | 21 | obj-$(CONFIG_PCI_MSI) += msi.o |
diff --git a/drivers/pci/hotplug-pci.c b/drivers/pci/hotplug-pci.c deleted file mode 100644 index c68366cee6b7..000000000000 --- a/drivers/pci/hotplug-pci.c +++ /dev/null | |||
| @@ -1,29 +0,0 @@ | |||
| 1 | /* Core PCI functionality used only by PCI hotplug */ | ||
| 2 | |||
| 3 | #include <linux/pci.h> | ||
| 4 | #include <linux/export.h> | ||
| 5 | #include "pci.h" | ||
| 6 | |||
| 7 | int pci_hp_add_bridge(struct pci_dev *dev) | ||
| 8 | { | ||
| 9 | struct pci_bus *parent = dev->bus; | ||
| 10 | int pass, busnr, start = parent->busn_res.start; | ||
| 11 | int end = parent->busn_res.end; | ||
| 12 | |||
| 13 | for (busnr = start; busnr <= end; busnr++) { | ||
| 14 | if (!pci_find_bus(pci_domain_nr(parent), busnr)) | ||
| 15 | break; | ||
| 16 | } | ||
| 17 | if (busnr-- > end) { | ||
| 18 | printk(KERN_ERR "No bus number available for hot-added bridge %s\n", | ||
| 19 | pci_name(dev)); | ||
| 20 | return -1; | ||
| 21 | } | ||
| 22 | for (pass = 0; pass < 2; pass++) | ||
| 23 | busnr = pci_scan_bridge(parent, dev, busnr, pass); | ||
| 24 | if (!dev->subordinate) | ||
| 25 | return -1; | ||
| 26 | |||
| 27 | return 0; | ||
| 28 | } | ||
| 29 | EXPORT_SYMBOL_GPL(pci_hp_add_bridge); | ||
diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c index 5ed2dcaa8e27..5db6f1839dad 100644 --- a/drivers/pci/hotplug/acpiphp_glue.c +++ b/drivers/pci/hotplug/acpiphp_glue.c | |||
| @@ -462,18 +462,15 @@ static void enable_slot(struct acpiphp_slot *slot) | |||
| 462 | acpiphp_rescan_slot(slot); | 462 | acpiphp_rescan_slot(slot); |
| 463 | max = acpiphp_max_busnr(bus); | 463 | max = acpiphp_max_busnr(bus); |
| 464 | for (pass = 0; pass < 2; pass++) { | 464 | for (pass = 0; pass < 2; pass++) { |
| 465 | list_for_each_entry(dev, &bus->devices, bus_list) { | 465 | for_each_pci_bridge(dev, bus) { |
| 466 | if (PCI_SLOT(dev->devfn) != slot->device) | 466 | if (PCI_SLOT(dev->devfn) != slot->device) |
| 467 | continue; | 467 | continue; |
| 468 | 468 | ||
| 469 | if (pci_is_bridge(dev)) { | 469 | max = pci_scan_bridge(bus, dev, max, pass); |
| 470 | max = pci_scan_bridge(bus, dev, max, pass); | 470 | if (pass && dev->subordinate) { |
| 471 | if (pass && dev->subordinate) { | 471 | check_hotplug_bridge(slot, dev); |
| 472 | check_hotplug_bridge(slot, dev); | 472 | pcibios_resource_survey_bus(dev->subordinate); |
| 473 | pcibios_resource_survey_bus(dev->subordinate); | 473 | __pci_bus_size_bridges(dev->subordinate, &add_list); |
| 474 | __pci_bus_size_bridges(dev->subordinate, | ||
| 475 | &add_list); | ||
| 476 | } | ||
| 477 | } | 474 | } |
| 478 | } | 475 | } |
| 479 | } | 476 | } |
diff --git a/drivers/pci/hotplug/cpci_hotplug_pci.c b/drivers/pci/hotplug/cpci_hotplug_pci.c index 80c80017197d..f616358fa938 100644 --- a/drivers/pci/hotplug/cpci_hotplug_pci.c +++ b/drivers/pci/hotplug/cpci_hotplug_pci.c | |||
| @@ -286,14 +286,11 @@ int cpci_configure_slot(struct slot *slot) | |||
| 286 | } | 286 | } |
| 287 | parent = slot->dev->bus; | 287 | parent = slot->dev->bus; |
| 288 | 288 | ||
| 289 | list_for_each_entry(dev, &parent->devices, bus_list) { | 289 | for_each_pci_bridge(dev, parent) { |
| 290 | if (PCI_SLOT(dev->devfn) != PCI_SLOT(slot->devfn)) | 290 | if (PCI_SLOT(dev->devfn) == PCI_SLOT(slot->devfn)) |
| 291 | continue; | ||
| 292 | if (pci_is_bridge(dev)) | ||
| 293 | pci_hp_add_bridge(dev); | 291 | pci_hp_add_bridge(dev); |
| 294 | } | 292 | } |
| 295 | 293 | ||
| 296 | |||
| 297 | pci_assign_unassigned_bridge_resources(parent->self); | 294 | pci_assign_unassigned_bridge_resources(parent->self); |
| 298 | 295 | ||
| 299 | pci_bus_add_devices(parent); | 296 | pci_bus_add_devices(parent); |
diff --git a/drivers/pci/hotplug/cpqphp.h b/drivers/pci/hotplug/cpqphp.h index 48c8a066a6b7..c2bbe6b65d06 100644 --- a/drivers/pci/hotplug/cpqphp.h +++ b/drivers/pci/hotplug/cpqphp.h | |||
| @@ -410,7 +410,7 @@ void cpqhp_create_debugfs_files(struct controller *ctrl); | |||
| 410 | void cpqhp_remove_debugfs_files(struct controller *ctrl); | 410 | void cpqhp_remove_debugfs_files(struct controller *ctrl); |
| 411 | 411 | ||
| 412 | /* controller functions */ | 412 | /* controller functions */ |
| 413 | void cpqhp_pushbutton_thread(unsigned long event_pointer); | 413 | void cpqhp_pushbutton_thread(struct timer_list *t); |
| 414 | irqreturn_t cpqhp_ctrl_intr(int IRQ, void *data); | 414 | irqreturn_t cpqhp_ctrl_intr(int IRQ, void *data); |
| 415 | int cpqhp_find_available_resources(struct controller *ctrl, | 415 | int cpqhp_find_available_resources(struct controller *ctrl, |
| 416 | void __iomem *rom_start); | 416 | void __iomem *rom_start); |
diff --git a/drivers/pci/hotplug/cpqphp_core.c b/drivers/pci/hotplug/cpqphp_core.c index 4d06b8461255..70967ac75265 100644 --- a/drivers/pci/hotplug/cpqphp_core.c +++ b/drivers/pci/hotplug/cpqphp_core.c | |||
| @@ -661,9 +661,8 @@ static int ctrl_slot_setup(struct controller *ctrl, | |||
| 661 | 661 | ||
| 662 | slot->p_sm_slot = slot_entry; | 662 | slot->p_sm_slot = slot_entry; |
| 663 | 663 | ||
| 664 | init_timer(&slot->task_event); | 664 | timer_setup(&slot->task_event, cpqhp_pushbutton_thread, 0); |
| 665 | slot->task_event.expires = jiffies + 5 * HZ; | 665 | slot->task_event.expires = jiffies + 5 * HZ; |
| 666 | slot->task_event.function = cpqhp_pushbutton_thread; | ||
| 667 | 666 | ||
| 668 | /*FIXME: these capabilities aren't used but if they are | 667 | /*FIXME: these capabilities aren't used but if they are |
| 669 | * they need to be correctly implemented | 668 | * they need to be correctly implemented |
diff --git a/drivers/pci/hotplug/cpqphp_ctrl.c b/drivers/pci/hotplug/cpqphp_ctrl.c index a55653b54eed..a93069e739cb 100644 --- a/drivers/pci/hotplug/cpqphp_ctrl.c +++ b/drivers/pci/hotplug/cpqphp_ctrl.c | |||
| @@ -47,7 +47,7 @@ static void interrupt_event_handler(struct controller *ctrl); | |||
| 47 | 47 | ||
| 48 | 48 | ||
| 49 | static struct task_struct *cpqhp_event_thread; | 49 | static struct task_struct *cpqhp_event_thread; |
| 50 | static unsigned long pushbutton_pending; /* = 0 */ | 50 | static struct timer_list *pushbutton_pending; /* = NULL */ |
| 51 | 51 | ||
| 52 | /* delay is in jiffies to wait for */ | 52 | /* delay is in jiffies to wait for */ |
| 53 | static void long_delay(int delay) | 53 | static void long_delay(int delay) |
| @@ -1732,9 +1732,10 @@ static u32 remove_board(struct pci_func *func, u32 replace_flag, struct controll | |||
| 1732 | return 0; | 1732 | return 0; |
| 1733 | } | 1733 | } |
| 1734 | 1734 | ||
| 1735 | static void pushbutton_helper_thread(unsigned long data) | 1735 | static void pushbutton_helper_thread(struct timer_list *t) |
| 1736 | { | 1736 | { |
| 1737 | pushbutton_pending = data; | 1737 | pushbutton_pending = t; |
| 1738 | |||
| 1738 | wake_up_process(cpqhp_event_thread); | 1739 | wake_up_process(cpqhp_event_thread); |
| 1739 | } | 1740 | } |
| 1740 | 1741 | ||
| @@ -1883,13 +1884,13 @@ static void interrupt_event_handler(struct controller *ctrl) | |||
| 1883 | wait_for_ctrl_irq(ctrl); | 1884 | wait_for_ctrl_irq(ctrl); |
| 1884 | 1885 | ||
| 1885 | mutex_unlock(&ctrl->crit_sect); | 1886 | mutex_unlock(&ctrl->crit_sect); |
| 1886 | init_timer(&p_slot->task_event); | 1887 | timer_setup(&p_slot->task_event, |
| 1888 | pushbutton_helper_thread, | ||
| 1889 | 0); | ||
| 1887 | p_slot->hp_slot = hp_slot; | 1890 | p_slot->hp_slot = hp_slot; |
| 1888 | p_slot->ctrl = ctrl; | 1891 | p_slot->ctrl = ctrl; |
| 1889 | /* p_slot->physical_slot = physical_slot; */ | 1892 | /* p_slot->physical_slot = physical_slot; */ |
| 1890 | p_slot->task_event.expires = jiffies + 5 * HZ; /* 5 second delay */ | 1893 | p_slot->task_event.expires = jiffies + 5 * HZ; /* 5 second delay */ |
| 1891 | p_slot->task_event.function = pushbutton_helper_thread; | ||
| 1892 | p_slot->task_event.data = (u32) p_slot; | ||
| 1893 | 1894 | ||
| 1894 | dbg("add_timer p_slot = %p\n", p_slot); | 1895 | dbg("add_timer p_slot = %p\n", p_slot); |
| 1895 | add_timer(&p_slot->task_event); | 1896 | add_timer(&p_slot->task_event); |
| @@ -1920,15 +1921,15 @@ static void interrupt_event_handler(struct controller *ctrl) | |||
| 1920 | * Scheduled procedure to handle blocking stuff for the pushbuttons. | 1921 | * Scheduled procedure to handle blocking stuff for the pushbuttons. |
| 1921 | * Handles all pending events and exits. | 1922 | * Handles all pending events and exits. |
| 1922 | */ | 1923 | */ |
| 1923 | void cpqhp_pushbutton_thread(unsigned long slot) | 1924 | void cpqhp_pushbutton_thread(struct timer_list *t) |
| 1924 | { | 1925 | { |
| 1925 | u8 hp_slot; | 1926 | u8 hp_slot; |
| 1926 | u8 device; | 1927 | u8 device; |
| 1927 | struct pci_func *func; | 1928 | struct pci_func *func; |
| 1928 | struct slot *p_slot = (struct slot *) slot; | 1929 | struct slot *p_slot = from_timer(p_slot, t, task_event); |
| 1929 | struct controller *ctrl = (struct controller *) p_slot->ctrl; | 1930 | struct controller *ctrl = (struct controller *) p_slot->ctrl; |
| 1930 | 1931 | ||
| 1931 | pushbutton_pending = 0; | 1932 | pushbutton_pending = NULL; |
| 1932 | hp_slot = p_slot->hp_slot; | 1933 | hp_slot = p_slot->hp_slot; |
| 1933 | 1934 | ||
| 1934 | device = p_slot->device; | 1935 | device = p_slot->device; |
diff --git a/drivers/pci/hotplug/ibmphp_pci.c b/drivers/pci/hotplug/ibmphp_pci.c index dc1876feb06f..25edd0b18b75 100644 --- a/drivers/pci/hotplug/ibmphp_pci.c +++ b/drivers/pci/hotplug/ibmphp_pci.c | |||
| @@ -1267,20 +1267,19 @@ static int unconfigure_boot_device(u8 busno, u8 device, u8 function) | |||
| 1267 | size = size & 0xFFFFFFFC; | 1267 | size = size & 0xFFFFFFFC; |
| 1268 | size = ~size + 1; | 1268 | size = ~size + 1; |
| 1269 | end_address = start_address + size - 1; | 1269 | end_address = start_address + size - 1; |
| 1270 | if (ibmphp_find_resource(bus, start_address, &io, IO) < 0) { | 1270 | if (ibmphp_find_resource(bus, start_address, &io, IO)) |
| 1271 | err("cannot find corresponding IO resource to remove\n"); | 1271 | goto report_search_failure; |
| 1272 | return -EIO; | 1272 | |
| 1273 | } | ||
| 1274 | debug("io->start = %x\n", io->start); | 1273 | debug("io->start = %x\n", io->start); |
| 1275 | temp_end = io->end; | 1274 | temp_end = io->end; |
| 1276 | start_address = io->end + 1; | 1275 | start_address = io->end + 1; |
| 1277 | ibmphp_remove_resource(io); | 1276 | ibmphp_remove_resource(io); |
| 1278 | /* This is needed b/c of the old I/O restrictions in the BIOS */ | 1277 | /* This is needed b/c of the old I/O restrictions in the BIOS */ |
| 1279 | while (temp_end < end_address) { | 1278 | while (temp_end < end_address) { |
| 1280 | if (ibmphp_find_resource(bus, start_address, &io, IO) < 0) { | 1279 | if (ibmphp_find_resource(bus, start_address, |
| 1281 | err("cannot find corresponding IO resource to remove\n"); | 1280 | &io, IO)) |
| 1282 | return -EIO; | 1281 | goto report_search_failure; |
| 1283 | } | 1282 | |
| 1284 | debug("io->start = %x\n", io->start); | 1283 | debug("io->start = %x\n", io->start); |
| 1285 | temp_end = io->end; | 1284 | temp_end = io->end; |
| 1286 | start_address = io->end + 1; | 1285 | start_address = io->end + 1; |
| @@ -1327,6 +1326,10 @@ static int unconfigure_boot_device(u8 busno, u8 device, u8 function) | |||
| 1327 | } /* end of for */ | 1326 | } /* end of for */ |
| 1328 | 1327 | ||
| 1329 | return 0; | 1328 | return 0; |
| 1329 | |||
| 1330 | report_search_failure: | ||
| 1331 | err("cannot find corresponding IO resource to remove\n"); | ||
| 1332 | return -EIO; | ||
| 1330 | } | 1333 | } |
| 1331 | 1334 | ||
| 1332 | static int unconfigure_boot_bridge(u8 busno, u8 device, u8 function) | 1335 | static int unconfigure_boot_bridge(u8 busno, u8 device, u8 function) |
diff --git a/drivers/pci/hotplug/pciehp_ctrl.c b/drivers/pci/hotplug/pciehp_ctrl.c index ec0b4c11ccd9..83f3d4af3677 100644 --- a/drivers/pci/hotplug/pciehp_ctrl.c +++ b/drivers/pci/hotplug/pciehp_ctrl.c | |||
| @@ -113,10 +113,11 @@ static int board_added(struct slot *p_slot) | |||
| 113 | 113 | ||
| 114 | retval = pciehp_configure_device(p_slot); | 114 | retval = pciehp_configure_device(p_slot); |
| 115 | if (retval) { | 115 | if (retval) { |
| 116 | ctrl_err(ctrl, "Cannot add device at %04x:%02x:00\n", | 116 | if (retval != -EEXIST) { |
| 117 | pci_domain_nr(parent), parent->number); | 117 | ctrl_err(ctrl, "Cannot add device at %04x:%02x:00\n", |
| 118 | if (retval != -EEXIST) | 118 | pci_domain_nr(parent), parent->number); |
| 119 | goto err_exit; | 119 | goto err_exit; |
| 120 | } | ||
| 120 | } | 121 | } |
| 121 | 122 | ||
| 122 | pciehp_green_led_on(p_slot); | 123 | pciehp_green_led_on(p_slot); |
diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c index e5d5ce9e3010..7bab0606f1a9 100644 --- a/drivers/pci/hotplug/pciehp_hpc.c +++ b/drivers/pci/hotplug/pciehp_hpc.c | |||
| @@ -50,14 +50,13 @@ static irqreturn_t pcie_isr(int irq, void *dev_id); | |||
| 50 | static void start_int_poll_timer(struct controller *ctrl, int sec); | 50 | static void start_int_poll_timer(struct controller *ctrl, int sec); |
| 51 | 51 | ||
| 52 | /* This is the interrupt polling timeout function. */ | 52 | /* This is the interrupt polling timeout function. */ |
| 53 | static void int_poll_timeout(unsigned long data) | 53 | static void int_poll_timeout(struct timer_list *t) |
| 54 | { | 54 | { |
| 55 | struct controller *ctrl = (struct controller *)data; | 55 | struct controller *ctrl = from_timer(ctrl, t, poll_timer); |
| 56 | 56 | ||
| 57 | /* Poll for interrupt events. regs == NULL => polling */ | 57 | /* Poll for interrupt events. regs == NULL => polling */ |
| 58 | pcie_isr(0, ctrl); | 58 | pcie_isr(0, ctrl); |
| 59 | 59 | ||
| 60 | init_timer(&ctrl->poll_timer); | ||
| 61 | if (!pciehp_poll_time) | 60 | if (!pciehp_poll_time) |
| 62 | pciehp_poll_time = 2; /* default polling interval is 2 sec */ | 61 | pciehp_poll_time = 2; /* default polling interval is 2 sec */ |
| 63 | 62 | ||
| @@ -71,8 +70,6 @@ static void start_int_poll_timer(struct controller *ctrl, int sec) | |||
| 71 | if ((sec <= 0) || (sec > 60)) | 70 | if ((sec <= 0) || (sec > 60)) |
| 72 | sec = 2; | 71 | sec = 2; |
| 73 | 72 | ||
| 74 | ctrl->poll_timer.function = &int_poll_timeout; | ||
| 75 | ctrl->poll_timer.data = (unsigned long)ctrl; | ||
| 76 | ctrl->poll_timer.expires = jiffies + sec * HZ; | 73 | ctrl->poll_timer.expires = jiffies + sec * HZ; |
| 77 | add_timer(&ctrl->poll_timer); | 74 | add_timer(&ctrl->poll_timer); |
| 78 | } | 75 | } |
| @@ -83,7 +80,7 @@ static inline int pciehp_request_irq(struct controller *ctrl) | |||
| 83 | 80 | ||
| 84 | /* Install interrupt polling timer. Start with 10 sec delay */ | 81 | /* Install interrupt polling timer. Start with 10 sec delay */ |
| 85 | if (pciehp_poll_mode) { | 82 | if (pciehp_poll_mode) { |
| 86 | init_timer(&ctrl->poll_timer); | 83 | timer_setup(&ctrl->poll_timer, int_poll_timeout, 0); |
| 87 | start_int_poll_timer(ctrl, 10); | 84 | start_int_poll_timer(ctrl, 10); |
| 88 | return 0; | 85 | return 0; |
| 89 | } | 86 | } |
| @@ -764,8 +761,7 @@ int pciehp_reset_slot(struct slot *slot, int probe) | |||
| 764 | ctrl_dbg(ctrl, "%s: SLOTCTRL %x write cmd %x\n", __func__, | 761 | ctrl_dbg(ctrl, "%s: SLOTCTRL %x write cmd %x\n", __func__, |
| 765 | pci_pcie_cap(ctrl->pcie->port) + PCI_EXP_SLTCTL, ctrl_mask); | 762 | pci_pcie_cap(ctrl->pcie->port) + PCI_EXP_SLTCTL, ctrl_mask); |
| 766 | if (pciehp_poll_mode) | 763 | if (pciehp_poll_mode) |
| 767 | int_poll_timeout(ctrl->poll_timer.data); | 764 | int_poll_timeout(&ctrl->poll_timer); |
| 768 | |||
| 769 | return 0; | 765 | return 0; |
| 770 | } | 766 | } |
| 771 | 767 | ||
| @@ -795,7 +791,7 @@ static int pcie_init_slot(struct controller *ctrl) | |||
| 795 | if (!slot) | 791 | if (!slot) |
| 796 | return -ENOMEM; | 792 | return -ENOMEM; |
| 797 | 793 | ||
| 798 | slot->wq = alloc_workqueue("pciehp-%u", 0, 0, PSN(ctrl)); | 794 | slot->wq = alloc_ordered_workqueue("pciehp-%u", 0, PSN(ctrl)); |
| 799 | if (!slot->wq) | 795 | if (!slot->wq) |
| 800 | goto abort; | 796 | goto abort; |
| 801 | 797 | ||
| @@ -862,11 +858,16 @@ struct controller *pcie_init(struct pcie_device *dev) | |||
| 862 | if (link_cap & PCI_EXP_LNKCAP_DLLLARC) | 858 | if (link_cap & PCI_EXP_LNKCAP_DLLLARC) |
| 863 | ctrl->link_active_reporting = 1; | 859 | ctrl->link_active_reporting = 1; |
| 864 | 860 | ||
| 865 | /* Clear all remaining event bits in Slot Status register */ | 861 | /* |
| 862 | * Clear all remaining event bits in Slot Status register except | ||
| 863 | * Presence Detect Changed. We want to make sure possible | ||
| 864 | * hotplug event is triggered when the interrupt is unmasked so | ||
| 865 | * that we don't lose that event. | ||
| 866 | */ | ||
| 866 | pcie_capability_write_word(pdev, PCI_EXP_SLTSTA, | 867 | pcie_capability_write_word(pdev, PCI_EXP_SLTSTA, |
| 867 | PCI_EXP_SLTSTA_ABP | PCI_EXP_SLTSTA_PFD | | 868 | PCI_EXP_SLTSTA_ABP | PCI_EXP_SLTSTA_PFD | |
| 868 | PCI_EXP_SLTSTA_MRLSC | PCI_EXP_SLTSTA_PDC | | 869 | PCI_EXP_SLTSTA_MRLSC | PCI_EXP_SLTSTA_CC | |
| 869 | PCI_EXP_SLTSTA_CC | PCI_EXP_SLTSTA_DLLSC); | 870 | PCI_EXP_SLTSTA_DLLSC); |
| 870 | 871 | ||
| 871 | ctrl_info(ctrl, "Slot #%d AttnBtn%c PwrCtrl%c MRL%c AttnInd%c PwrInd%c HotPlug%c Surprise%c Interlock%c NoCompl%c LLActRep%c\n", | 872 | ctrl_info(ctrl, "Slot #%d AttnBtn%c PwrCtrl%c MRL%c AttnInd%c PwrInd%c HotPlug%c Surprise%c Interlock%c NoCompl%c LLActRep%c\n", |
| 872 | (slot_cap & PCI_EXP_SLTCAP_PSN) >> 19, | 873 | (slot_cap & PCI_EXP_SLTCAP_PSN) >> 19, |
diff --git a/drivers/pci/hotplug/pciehp_pci.c b/drivers/pci/hotplug/pciehp_pci.c index 19f30a9f461d..2a1ca020cf5a 100644 --- a/drivers/pci/hotplug/pciehp_pci.c +++ b/drivers/pci/hotplug/pciehp_pci.c | |||
| @@ -46,7 +46,11 @@ int pciehp_configure_device(struct slot *p_slot) | |||
| 46 | 46 | ||
| 47 | dev = pci_get_slot(parent, PCI_DEVFN(0, 0)); | 47 | dev = pci_get_slot(parent, PCI_DEVFN(0, 0)); |
| 48 | if (dev) { | 48 | if (dev) { |
| 49 | ctrl_err(ctrl, "Device %s already exists at %04x:%02x:00, cannot hot-add\n", | 49 | /* |
| 50 | * The device is already there. Either configured by the | ||
| 51 | * boot firmware or a previous hotplug event. | ||
| 52 | */ | ||
| 53 | ctrl_dbg(ctrl, "Device %s already exists at %04x:%02x:00, skipping hot-add\n", | ||
| 50 | pci_name(dev), pci_domain_nr(parent), parent->number); | 54 | pci_name(dev), pci_domain_nr(parent), parent->number); |
| 51 | pci_dev_put(dev); | 55 | pci_dev_put(dev); |
| 52 | ret = -EEXIST; | 56 | ret = -EEXIST; |
| @@ -60,9 +64,8 @@ int pciehp_configure_device(struct slot *p_slot) | |||
| 60 | goto out; | 64 | goto out; |
| 61 | } | 65 | } |
| 62 | 66 | ||
| 63 | list_for_each_entry(dev, &parent->devices, bus_list) | 67 | for_each_pci_bridge(dev, parent) |
| 64 | if (pci_is_bridge(dev)) | 68 | pci_hp_add_bridge(dev); |
| 65 | pci_hp_add_bridge(dev); | ||
| 66 | 69 | ||
| 67 | pci_assign_unassigned_bridge_resources(bridge); | 70 | pci_assign_unassigned_bridge_resources(bridge); |
| 68 | pcie_bus_configure_settings(parent); | 71 | pcie_bus_configure_settings(parent); |
diff --git a/drivers/pci/hotplug/shpchp_hpc.c b/drivers/pci/hotplug/shpchp_hpc.c index e5824c7b7b6b..4810e9626d9f 100644 --- a/drivers/pci/hotplug/shpchp_hpc.c +++ b/drivers/pci/hotplug/shpchp_hpc.c | |||
| @@ -229,14 +229,13 @@ static inline int shpc_indirect_read(struct controller *ctrl, int index, | |||
| 229 | /* | 229 | /* |
| 230 | * This is the interrupt polling timeout function. | 230 | * This is the interrupt polling timeout function. |
| 231 | */ | 231 | */ |
| 232 | static void int_poll_timeout(unsigned long data) | 232 | static void int_poll_timeout(struct timer_list *t) |
| 233 | { | 233 | { |
| 234 | struct controller *ctrl = (struct controller *)data; | 234 | struct controller *ctrl = from_timer(ctrl, t, poll_timer); |
| 235 | 235 | ||
| 236 | /* Poll for interrupt events. regs == NULL => polling */ | 236 | /* Poll for interrupt events. regs == NULL => polling */ |
| 237 | shpc_isr(0, ctrl); | 237 | shpc_isr(0, ctrl); |
| 238 | 238 | ||
| 239 | init_timer(&ctrl->poll_timer); | ||
| 240 | if (!shpchp_poll_time) | 239 | if (!shpchp_poll_time) |
| 241 | shpchp_poll_time = 2; /* default polling interval is 2 sec */ | 240 | shpchp_poll_time = 2; /* default polling interval is 2 sec */ |
| 242 | 241 | ||
| @@ -252,8 +251,6 @@ static void start_int_poll_timer(struct controller *ctrl, int sec) | |||
| 252 | if ((sec <= 0) || (sec > 60)) | 251 | if ((sec <= 0) || (sec > 60)) |
| 253 | sec = 2; | 252 | sec = 2; |
| 254 | 253 | ||
| 255 | ctrl->poll_timer.function = &int_poll_timeout; | ||
| 256 | ctrl->poll_timer.data = (unsigned long)ctrl; | ||
| 257 | ctrl->poll_timer.expires = jiffies + sec * HZ; | 254 | ctrl->poll_timer.expires = jiffies + sec * HZ; |
| 258 | add_timer(&ctrl->poll_timer); | 255 | add_timer(&ctrl->poll_timer); |
| 259 | } | 256 | } |
| @@ -1054,7 +1051,7 @@ int shpc_init(struct controller *ctrl, struct pci_dev *pdev) | |||
| 1054 | 1051 | ||
| 1055 | if (shpchp_poll_mode) { | 1052 | if (shpchp_poll_mode) { |
| 1056 | /* Install interrupt polling timer. Start with 10 sec delay */ | 1053 | /* Install interrupt polling timer. Start with 10 sec delay */ |
| 1057 | init_timer(&ctrl->poll_timer); | 1054 | timer_setup(&ctrl->poll_timer, int_poll_timeout, 0); |
| 1058 | start_int_poll_timer(ctrl, 10); | 1055 | start_int_poll_timer(ctrl, 10); |
| 1059 | } else { | 1056 | } else { |
| 1060 | /* Installs the interrupt handler */ | 1057 | /* Installs the interrupt handler */ |
diff --git a/drivers/pci/hotplug/shpchp_pci.c b/drivers/pci/hotplug/shpchp_pci.c index f8cd3a27e351..ea63db58b4b1 100644 --- a/drivers/pci/hotplug/shpchp_pci.c +++ b/drivers/pci/hotplug/shpchp_pci.c | |||
| @@ -61,10 +61,8 @@ int shpchp_configure_device(struct slot *p_slot) | |||
| 61 | goto out; | 61 | goto out; |
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | list_for_each_entry(dev, &parent->devices, bus_list) { | 64 | for_each_pci_bridge(dev, parent) { |
| 65 | if (PCI_SLOT(dev->devfn) != p_slot->device) | 65 | if (PCI_SLOT(dev->devfn) == p_slot->device) |
| 66 | continue; | ||
| 67 | if (pci_is_bridge(dev)) | ||
| 68 | pci_hp_add_bridge(dev); | 66 | pci_hp_add_bridge(dev); |
| 69 | } | 67 | } |
| 70 | 68 | ||
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index ff94b69738a8..14e0ea1ff38b 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c | |||
| @@ -959,7 +959,21 @@ static void pci_enable_crs(struct pci_dev *pdev) | |||
| 959 | PCI_EXP_RTCTL_CRSSVE); | 959 | PCI_EXP_RTCTL_CRSSVE); |
| 960 | } | 960 | } |
| 961 | 961 | ||
| 962 | static unsigned int pci_scan_child_bus_extend(struct pci_bus *bus, | ||
| 963 | unsigned int available_buses); | ||
| 964 | |||
| 962 | /* | 965 | /* |
| 966 | * pci_scan_bridge_extend() - Scan buses behind a bridge | ||
| 967 | * @bus: Parent bus the bridge is on | ||
| 968 | * @dev: Bridge itself | ||
| 969 | * @max: Starting subordinate number of buses behind this bridge | ||
| 970 | * @available_buses: Total number of buses available for this bridge and | ||
| 971 | * the devices below. After the minimal bus space has | ||
| 972 | * been allocated the remaining buses will be | ||
| 973 | * distributed equally between hotplug-capable bridges. | ||
| 974 | * @pass: Either %0 (scan already configured bridges) or %1 (scan bridges | ||
| 975 | * that need to be reconfigured. | ||
| 976 | * | ||
| 963 | * If it's a bridge, configure it and scan the bus behind it. | 977 | * If it's a bridge, configure it and scan the bus behind it. |
| 964 | * For CardBus bridges, we don't scan behind as the devices will | 978 | * For CardBus bridges, we don't scan behind as the devices will |
| 965 | * be handled by the bridge driver itself. | 979 | * be handled by the bridge driver itself. |
| @@ -969,7 +983,9 @@ static void pci_enable_crs(struct pci_dev *pdev) | |||
| 969 | * them, we proceed to assigning numbers to the remaining buses in | 983 | * them, we proceed to assigning numbers to the remaining buses in |
| 970 | * order to avoid overlaps between old and new bus numbers. | 984 | * order to avoid overlaps between old and new bus numbers. |
| 971 | */ | 985 | */ |
| 972 | int pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max, int pass) | 986 | static int pci_scan_bridge_extend(struct pci_bus *bus, struct pci_dev *dev, |
| 987 | int max, unsigned int available_buses, | ||
| 988 | int pass) | ||
| 973 | { | 989 | { |
| 974 | struct pci_bus *child; | 990 | struct pci_bus *child; |
| 975 | int is_cardbus = (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS); | 991 | int is_cardbus = (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS); |
| @@ -1076,9 +1092,13 @@ int pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max, int pass) | |||
| 1076 | child = pci_add_new_bus(bus, dev, max+1); | 1092 | child = pci_add_new_bus(bus, dev, max+1); |
| 1077 | if (!child) | 1093 | if (!child) |
| 1078 | goto out; | 1094 | goto out; |
| 1079 | pci_bus_insert_busn_res(child, max+1, 0xff); | 1095 | pci_bus_insert_busn_res(child, max+1, |
| 1096 | bus->busn_res.end); | ||
| 1080 | } | 1097 | } |
| 1081 | max++; | 1098 | max++; |
| 1099 | if (available_buses) | ||
| 1100 | available_buses--; | ||
| 1101 | |||
| 1082 | buses = (buses & 0xff000000) | 1102 | buses = (buses & 0xff000000) |
| 1083 | | ((unsigned int)(child->primary) << 0) | 1103 | | ((unsigned int)(child->primary) << 0) |
| 1084 | | ((unsigned int)(child->busn_res.start) << 8) | 1104 | | ((unsigned int)(child->busn_res.start) << 8) |
| @@ -1100,7 +1120,7 @@ int pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max, int pass) | |||
| 1100 | 1120 | ||
| 1101 | if (!is_cardbus) { | 1121 | if (!is_cardbus) { |
| 1102 | child->bridge_ctl = bctl; | 1122 | child->bridge_ctl = bctl; |
| 1103 | max = pci_scan_child_bus(child); | 1123 | max = pci_scan_child_bus_extend(child, available_buses); |
| 1104 | } else { | 1124 | } else { |
| 1105 | /* | 1125 | /* |
| 1106 | * For CardBus bridges, we leave 4 bus numbers | 1126 | * For CardBus bridges, we leave 4 bus numbers |
| @@ -1168,6 +1188,28 @@ out: | |||
| 1168 | 1188 | ||
| 1169 | return max; | 1189 | return max; |
| 1170 | } | 1190 | } |
| 1191 | |||
| 1192 | /* | ||
| 1193 | * pci_scan_bridge() - Scan buses behind a bridge | ||
| 1194 | * @bus: Parent bus the bridge is on | ||
| 1195 | * @dev: Bridge itself | ||
| 1196 | * @max: Starting subordinate number of buses behind this bridge | ||
| 1197 | * @pass: Either %0 (scan already configured bridges) or %1 (scan bridges | ||
| 1198 | * that need to be reconfigured. | ||
| 1199 | * | ||
| 1200 | * If it's a bridge, configure it and scan the bus behind it. | ||
| 1201 | * For CardBus bridges, we don't scan behind as the devices will | ||
| 1202 | * be handled by the bridge driver itself. | ||
| 1203 | * | ||
| 1204 | * We need to process bridges in two passes -- first we scan those | ||
| 1205 | * already configured by the BIOS and after we are done with all of | ||
| 1206 | * them, we proceed to assigning numbers to the remaining buses in | ||
| 1207 | * order to avoid overlaps between old and new bus numbers. | ||
| 1208 | */ | ||
| 1209 | int pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max, int pass) | ||
| 1210 | { | ||
| 1211 | return pci_scan_bridge_extend(bus, dev, max, 0, pass); | ||
| 1212 | } | ||
| 1171 | EXPORT_SYMBOL(pci_scan_bridge); | 1213 | EXPORT_SYMBOL(pci_scan_bridge); |
| 1172 | 1214 | ||
| 1173 | /* | 1215 | /* |
| @@ -2396,9 +2438,24 @@ void __weak pcibios_fixup_bus(struct pci_bus *bus) | |||
| 2396 | /* nothing to do, expected to be removed in the future */ | 2438 | /* nothing to do, expected to be removed in the future */ |
| 2397 | } | 2439 | } |
| 2398 | 2440 | ||
| 2399 | unsigned int pci_scan_child_bus(struct pci_bus *bus) | 2441 | /** |
| 2442 | * pci_scan_child_bus_extend() - Scan devices below a bus | ||
| 2443 | * @bus: Bus to scan for devices | ||
| 2444 | * @available_buses: Total number of buses available (%0 does not try to | ||
| 2445 | * extend beyond the minimal) | ||
| 2446 | * | ||
| 2447 | * Scans devices below @bus including subordinate buses. Returns new | ||
| 2448 | * subordinate number including all the found devices. Passing | ||
| 2449 | * @available_buses causes the remaining bus space to be distributed | ||
| 2450 | * equally between hotplug-capable bridges to allow future extension of the | ||
| 2451 | * hierarchy. | ||
| 2452 | */ | ||
| 2453 | static unsigned int pci_scan_child_bus_extend(struct pci_bus *bus, | ||
| 2454 | unsigned int available_buses) | ||
| 2400 | { | 2455 | { |
| 2401 | unsigned int devfn, pass, max = bus->busn_res.start; | 2456 | unsigned int used_buses, normal_bridges = 0, hotplug_bridges = 0; |
| 2457 | unsigned int start = bus->busn_res.start; | ||
| 2458 | unsigned int devfn, cmax, max = start; | ||
| 2402 | struct pci_dev *dev; | 2459 | struct pci_dev *dev; |
| 2403 | 2460 | ||
| 2404 | dev_dbg(&bus->dev, "scanning bus\n"); | 2461 | dev_dbg(&bus->dev, "scanning bus\n"); |
| @@ -2408,7 +2465,8 @@ unsigned int pci_scan_child_bus(struct pci_bus *bus) | |||
| 2408 | pci_scan_slot(bus, devfn); | 2465 | pci_scan_slot(bus, devfn); |
| 2409 | 2466 | ||
| 2410 | /* Reserve buses for SR-IOV capability. */ | 2467 | /* Reserve buses for SR-IOV capability. */ |
| 2411 | max += pci_iov_bus_range(bus); | 2468 | used_buses = pci_iov_bus_range(bus); |
| 2469 | max += used_buses; | ||
| 2412 | 2470 | ||
| 2413 | /* | 2471 | /* |
| 2414 | * After performing arch-dependent fixup of the bus, look behind | 2472 | * After performing arch-dependent fixup of the bus, look behind |
| @@ -2420,19 +2478,73 @@ unsigned int pci_scan_child_bus(struct pci_bus *bus) | |||
| 2420 | bus->is_added = 1; | 2478 | bus->is_added = 1; |
| 2421 | } | 2479 | } |
| 2422 | 2480 | ||
| 2423 | for (pass = 0; pass < 2; pass++) | 2481 | /* |
| 2424 | list_for_each_entry(dev, &bus->devices, bus_list) { | 2482 | * Calculate how many hotplug bridges and normal bridges there |
| 2425 | if (pci_is_bridge(dev)) | 2483 | * are on this bus. We will distribute the additional available |
| 2426 | max = pci_scan_bridge(bus, dev, max, pass); | 2484 | * buses between hotplug bridges. |
| 2485 | */ | ||
| 2486 | for_each_pci_bridge(dev, bus) { | ||
| 2487 | if (dev->is_hotplug_bridge) | ||
| 2488 | hotplug_bridges++; | ||
| 2489 | else | ||
| 2490 | normal_bridges++; | ||
| 2491 | } | ||
| 2492 | |||
| 2493 | /* | ||
| 2494 | * Scan bridges that are already configured. We don't touch them | ||
| 2495 | * unless they are misconfigured (which will be done in the second | ||
| 2496 | * scan below). | ||
| 2497 | */ | ||
| 2498 | for_each_pci_bridge(dev, bus) { | ||
| 2499 | cmax = max; | ||
| 2500 | max = pci_scan_bridge_extend(bus, dev, max, 0, 0); | ||
| 2501 | used_buses += cmax - max; | ||
| 2502 | } | ||
| 2503 | |||
| 2504 | /* Scan bridges that need to be reconfigured */ | ||
| 2505 | for_each_pci_bridge(dev, bus) { | ||
| 2506 | unsigned int buses = 0; | ||
| 2507 | |||
| 2508 | if (!hotplug_bridges && normal_bridges == 1) { | ||
| 2509 | /* | ||
| 2510 | * There is only one bridge on the bus (upstream | ||
| 2511 | * port) so it gets all available buses which it | ||
| 2512 | * can then distribute to the possible hotplug | ||
| 2513 | * bridges below. | ||
| 2514 | */ | ||
| 2515 | buses = available_buses; | ||
| 2516 | } else if (dev->is_hotplug_bridge) { | ||
| 2517 | /* | ||
| 2518 | * Distribute the extra buses between hotplug | ||
| 2519 | * bridges if any. | ||
| 2520 | */ | ||
| 2521 | buses = available_buses / hotplug_bridges; | ||
| 2522 | buses = min(buses, available_buses - used_buses); | ||
| 2427 | } | 2523 | } |
| 2428 | 2524 | ||
| 2525 | cmax = max; | ||
| 2526 | max = pci_scan_bridge_extend(bus, dev, cmax, buses, 1); | ||
| 2527 | used_buses += max - cmax; | ||
| 2528 | } | ||
| 2529 | |||
| 2429 | /* | 2530 | /* |
| 2430 | * Make sure a hotplug bridge has at least the minimum requested | 2531 | * Make sure a hotplug bridge has at least the minimum requested |
| 2431 | * number of buses. | 2532 | * number of buses but allow it to grow up to the maximum available |
| 2533 | * bus number of there is room. | ||
| 2432 | */ | 2534 | */ |
| 2433 | if (bus->self && bus->self->is_hotplug_bridge && pci_hotplug_bus_size) { | 2535 | if (bus->self && bus->self->is_hotplug_bridge) { |
| 2434 | if (max - bus->busn_res.start < pci_hotplug_bus_size - 1) | 2536 | used_buses = max_t(unsigned int, available_buses, |
| 2435 | max = bus->busn_res.start + pci_hotplug_bus_size - 1; | 2537 | pci_hotplug_bus_size - 1); |
| 2538 | if (max - start < used_buses) { | ||
| 2539 | max = start + used_buses; | ||
| 2540 | |||
| 2541 | /* Do not allocate more buses than we have room left */ | ||
| 2542 | if (max > bus->busn_res.end) | ||
| 2543 | max = bus->busn_res.end; | ||
| 2544 | |||
| 2545 | dev_dbg(&bus->dev, "%pR extended by %#02x\n", | ||
| 2546 | &bus->busn_res, max - start); | ||
| 2547 | } | ||
| 2436 | } | 2548 | } |
| 2437 | 2549 | ||
| 2438 | /* | 2550 | /* |
| @@ -2445,6 +2557,18 @@ unsigned int pci_scan_child_bus(struct pci_bus *bus) | |||
| 2445 | dev_dbg(&bus->dev, "bus scan returning with max=%02x\n", max); | 2557 | dev_dbg(&bus->dev, "bus scan returning with max=%02x\n", max); |
| 2446 | return max; | 2558 | return max; |
| 2447 | } | 2559 | } |
| 2560 | |||
| 2561 | /** | ||
| 2562 | * pci_scan_child_bus() - Scan devices below a bus | ||
| 2563 | * @bus: Bus to scan for devices | ||
| 2564 | * | ||
| 2565 | * Scans devices below @bus including subordinate buses. Returns new | ||
| 2566 | * subordinate number including all the found devices. | ||
| 2567 | */ | ||
| 2568 | unsigned int pci_scan_child_bus(struct pci_bus *bus) | ||
| 2569 | { | ||
| 2570 | return pci_scan_child_bus_extend(bus, 0); | ||
| 2571 | } | ||
| 2448 | EXPORT_SYMBOL_GPL(pci_scan_child_bus); | 2572 | EXPORT_SYMBOL_GPL(pci_scan_child_bus); |
| 2449 | 2573 | ||
| 2450 | /** | 2574 | /** |
| @@ -2737,3 +2861,38 @@ void __init pci_sort_breadthfirst(void) | |||
| 2737 | { | 2861 | { |
| 2738 | bus_sort_breadthfirst(&pci_bus_type, &pci_sort_bf_cmp); | 2862 | bus_sort_breadthfirst(&pci_bus_type, &pci_sort_bf_cmp); |
| 2739 | } | 2863 | } |
| 2864 | |||
| 2865 | int pci_hp_add_bridge(struct pci_dev *dev) | ||
| 2866 | { | ||
| 2867 | struct pci_bus *parent = dev->bus; | ||
| 2868 | int busnr, start = parent->busn_res.start; | ||
| 2869 | unsigned int available_buses = 0; | ||
| 2870 | int end = parent->busn_res.end; | ||
| 2871 | |||
| 2872 | for (busnr = start; busnr <= end; busnr++) { | ||
| 2873 | if (!pci_find_bus(pci_domain_nr(parent), busnr)) | ||
| 2874 | break; | ||
| 2875 | } | ||
| 2876 | if (busnr-- > end) { | ||
| 2877 | dev_err(&dev->dev, "No bus number available for hot-added bridge\n"); | ||
| 2878 | return -1; | ||
| 2879 | } | ||
| 2880 | |||
| 2881 | /* Scan bridges that are already configured */ | ||
| 2882 | busnr = pci_scan_bridge(parent, dev, busnr, 0); | ||
| 2883 | |||
| 2884 | /* | ||
| 2885 | * Distribute the available bus numbers between hotplug-capable | ||
| 2886 | * bridges to make extending the chain later possible. | ||
| 2887 | */ | ||
| 2888 | available_buses = end - busnr; | ||
| 2889 | |||
| 2890 | /* Scan bridges that need to be reconfigured */ | ||
| 2891 | pci_scan_bridge_extend(parent, dev, busnr, available_buses, 1); | ||
| 2892 | |||
| 2893 | if (!dev->subordinate) | ||
| 2894 | return -1; | ||
| 2895 | |||
| 2896 | return 0; | ||
| 2897 | } | ||
| 2898 | EXPORT_SYMBOL_GPL(pci_hp_add_bridge); | ||
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 958da7db9033..5e547e0dc47b 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c | |||
| @@ -1853,6 +1853,175 @@ void __init pci_assign_unassigned_resources(void) | |||
| 1853 | } | 1853 | } |
| 1854 | } | 1854 | } |
| 1855 | 1855 | ||
| 1856 | static void extend_bridge_window(struct pci_dev *bridge, struct resource *res, | ||
| 1857 | struct list_head *add_list, resource_size_t available) | ||
| 1858 | { | ||
| 1859 | struct pci_dev_resource *dev_res; | ||
| 1860 | |||
| 1861 | if (res->parent) | ||
| 1862 | return; | ||
| 1863 | |||
| 1864 | if (resource_size(res) >= available) | ||
| 1865 | return; | ||
| 1866 | |||
| 1867 | dev_res = res_to_dev_res(add_list, res); | ||
| 1868 | if (!dev_res) | ||
| 1869 | return; | ||
| 1870 | |||
| 1871 | /* Is there room to extend the window? */ | ||
| 1872 | if (available - resource_size(res) <= dev_res->add_size) | ||
| 1873 | return; | ||
| 1874 | |||
| 1875 | dev_res->add_size = available - resource_size(res); | ||
| 1876 | dev_dbg(&bridge->dev, "bridge window %pR extended by %pa\n", res, | ||
| 1877 | &dev_res->add_size); | ||
| 1878 | } | ||
| 1879 | |||
| 1880 | static void pci_bus_distribute_available_resources(struct pci_bus *bus, | ||
| 1881 | struct list_head *add_list, resource_size_t available_io, | ||
| 1882 | resource_size_t available_mmio, resource_size_t available_mmio_pref) | ||
| 1883 | { | ||
| 1884 | resource_size_t remaining_io, remaining_mmio, remaining_mmio_pref; | ||
| 1885 | unsigned int normal_bridges = 0, hotplug_bridges = 0; | ||
| 1886 | struct resource *io_res, *mmio_res, *mmio_pref_res; | ||
| 1887 | struct pci_dev *dev, *bridge = bus->self; | ||
| 1888 | |||
| 1889 | io_res = &bridge->resource[PCI_BRIDGE_RESOURCES + 0]; | ||
| 1890 | mmio_res = &bridge->resource[PCI_BRIDGE_RESOURCES + 1]; | ||
| 1891 | mmio_pref_res = &bridge->resource[PCI_BRIDGE_RESOURCES + 2]; | ||
| 1892 | |||
| 1893 | /* | ||
| 1894 | * Update additional resource list (add_list) to fill all the | ||
| 1895 | * extra resource space available for this port except the space | ||
| 1896 | * calculated in __pci_bus_size_bridges() which covers all the | ||
| 1897 | * devices currently connected to the port and below. | ||
| 1898 | */ | ||
| 1899 | extend_bridge_window(bridge, io_res, add_list, available_io); | ||
| 1900 | extend_bridge_window(bridge, mmio_res, add_list, available_mmio); | ||
| 1901 | extend_bridge_window(bridge, mmio_pref_res, add_list, | ||
| 1902 | available_mmio_pref); | ||
| 1903 | |||
| 1904 | /* | ||
| 1905 | * Calculate the total amount of extra resource space we can | ||
| 1906 | * pass to bridges below this one. This is basically the | ||
| 1907 | * extra space reduced by the minimal required space for the | ||
| 1908 | * non-hotplug bridges. | ||
| 1909 | */ | ||
| 1910 | remaining_io = available_io; | ||
| 1911 | remaining_mmio = available_mmio; | ||
| 1912 | remaining_mmio_pref = available_mmio_pref; | ||
| 1913 | |||
| 1914 | /* | ||
| 1915 | * Calculate how many hotplug bridges and normal bridges there | ||
| 1916 | * are on this bus. We will distribute the additional available | ||
| 1917 | * resources between hotplug bridges. | ||
| 1918 | */ | ||
| 1919 | for_each_pci_bridge(dev, bus) { | ||
| 1920 | if (dev->is_hotplug_bridge) | ||
| 1921 | hotplug_bridges++; | ||
| 1922 | else | ||
| 1923 | normal_bridges++; | ||
| 1924 | } | ||
| 1925 | |||
| 1926 | for_each_pci_bridge(dev, bus) { | ||
| 1927 | const struct resource *res; | ||
| 1928 | |||
| 1929 | if (dev->is_hotplug_bridge) | ||
| 1930 | continue; | ||
| 1931 | |||
| 1932 | /* | ||
| 1933 | * Reduce the available resource space by what the | ||
| 1934 | * bridge and devices below it occupy. | ||
| 1935 | */ | ||
| 1936 | res = &dev->resource[PCI_BRIDGE_RESOURCES + 0]; | ||
| 1937 | if (!res->parent && available_io > resource_size(res)) | ||
| 1938 | remaining_io -= resource_size(res); | ||
| 1939 | |||
| 1940 | res = &dev->resource[PCI_BRIDGE_RESOURCES + 1]; | ||
| 1941 | if (!res->parent && available_mmio > resource_size(res)) | ||
| 1942 | remaining_mmio -= resource_size(res); | ||
| 1943 | |||
| 1944 | res = &dev->resource[PCI_BRIDGE_RESOURCES + 2]; | ||
| 1945 | if (!res->parent && available_mmio_pref > resource_size(res)) | ||
| 1946 | remaining_mmio_pref -= resource_size(res); | ||
| 1947 | } | ||
| 1948 | |||
| 1949 | /* | ||
| 1950 | * Go over devices on this bus and distribute the remaining | ||
| 1951 | * resource space between hotplug bridges. | ||
| 1952 | */ | ||
| 1953 | for_each_pci_bridge(dev, bus) { | ||
| 1954 | struct pci_bus *b; | ||
| 1955 | |||
| 1956 | b = dev->subordinate; | ||
| 1957 | if (!b) | ||
| 1958 | continue; | ||
| 1959 | |||
| 1960 | if (!hotplug_bridges && normal_bridges == 1) { | ||
| 1961 | /* | ||
| 1962 | * There is only one bridge on the bus (upstream | ||
| 1963 | * port) so it gets all available resources | ||
| 1964 | * which it can then distribute to the possible | ||
| 1965 | * hotplug bridges below. | ||
| 1966 | */ | ||
| 1967 | pci_bus_distribute_available_resources(b, add_list, | ||
| 1968 | available_io, available_mmio, | ||
| 1969 | available_mmio_pref); | ||
| 1970 | } else if (dev->is_hotplug_bridge) { | ||
| 1971 | resource_size_t align, io, mmio, mmio_pref; | ||
| 1972 | |||
| 1973 | /* | ||
| 1974 | * Distribute available extra resources equally | ||
| 1975 | * between hotplug-capable downstream ports | ||
| 1976 | * taking alignment into account. | ||
| 1977 | * | ||
| 1978 | * Here hotplug_bridges is always != 0. | ||
| 1979 | */ | ||
| 1980 | align = pci_resource_alignment(bridge, io_res); | ||
| 1981 | io = div64_ul(available_io, hotplug_bridges); | ||
| 1982 | io = min(ALIGN(io, align), remaining_io); | ||
| 1983 | remaining_io -= io; | ||
| 1984 | |||
| 1985 | align = pci_resource_alignment(bridge, mmio_res); | ||
| 1986 | mmio = div64_ul(available_mmio, hotplug_bridges); | ||
| 1987 | mmio = min(ALIGN(mmio, align), remaining_mmio); | ||
| 1988 | remaining_mmio -= mmio; | ||
| 1989 | |||
| 1990 | align = pci_resource_alignment(bridge, mmio_pref_res); | ||
| 1991 | mmio_pref = div64_ul(available_mmio_pref, | ||
| 1992 | hotplug_bridges); | ||
| 1993 | mmio_pref = min(ALIGN(mmio_pref, align), | ||
| 1994 | remaining_mmio_pref); | ||
| 1995 | remaining_mmio_pref -= mmio_pref; | ||
| 1996 | |||
| 1997 | pci_bus_distribute_available_resources(b, add_list, io, | ||
| 1998 | mmio, mmio_pref); | ||
| 1999 | } | ||
| 2000 | } | ||
| 2001 | } | ||
| 2002 | |||
| 2003 | static void | ||
| 2004 | pci_bridge_distribute_available_resources(struct pci_dev *bridge, | ||
| 2005 | struct list_head *add_list) | ||
| 2006 | { | ||
| 2007 | resource_size_t available_io, available_mmio, available_mmio_pref; | ||
| 2008 | const struct resource *res; | ||
| 2009 | |||
| 2010 | if (!bridge->is_hotplug_bridge) | ||
| 2011 | return; | ||
| 2012 | |||
| 2013 | /* Take the initial extra resources from the hotplug port */ | ||
| 2014 | res = &bridge->resource[PCI_BRIDGE_RESOURCES + 0]; | ||
| 2015 | available_io = resource_size(res); | ||
| 2016 | res = &bridge->resource[PCI_BRIDGE_RESOURCES + 1]; | ||
| 2017 | available_mmio = resource_size(res); | ||
| 2018 | res = &bridge->resource[PCI_BRIDGE_RESOURCES + 2]; | ||
| 2019 | available_mmio_pref = resource_size(res); | ||
| 2020 | |||
| 2021 | pci_bus_distribute_available_resources(bridge->subordinate, | ||
| 2022 | add_list, available_io, available_mmio, available_mmio_pref); | ||
| 2023 | } | ||
| 2024 | |||
| 1856 | void pci_assign_unassigned_bridge_resources(struct pci_dev *bridge) | 2025 | void pci_assign_unassigned_bridge_resources(struct pci_dev *bridge) |
| 1857 | { | 2026 | { |
| 1858 | struct pci_bus *parent = bridge->subordinate; | 2027 | struct pci_bus *parent = bridge->subordinate; |
| @@ -1867,6 +2036,14 @@ void pci_assign_unassigned_bridge_resources(struct pci_dev *bridge) | |||
| 1867 | 2036 | ||
| 1868 | again: | 2037 | again: |
| 1869 | __pci_bus_size_bridges(parent, &add_list); | 2038 | __pci_bus_size_bridges(parent, &add_list); |
| 2039 | |||
| 2040 | /* | ||
| 2041 | * Distribute remaining resources (if any) equally between | ||
| 2042 | * hotplug bridges below. This makes it possible to extend the | ||
| 2043 | * hierarchy later without running out of resources. | ||
| 2044 | */ | ||
| 2045 | pci_bridge_distribute_available_resources(bridge, &add_list); | ||
| 2046 | |||
| 1870 | __pci_bridge_assign_resources(bridge, &add_list, &fail_head); | 2047 | __pci_bridge_assign_resources(bridge, &add_list, &fail_head); |
| 1871 | BUG_ON(!list_empty(&add_list)); | 2048 | BUG_ON(!list_empty(&add_list)); |
| 1872 | tried_times++; | 2049 | tried_times++; |
| @@ -1921,10 +2098,9 @@ void pci_assign_unassigned_bus_resources(struct pci_bus *bus) | |||
| 1921 | want additional resources */ | 2098 | want additional resources */ |
| 1922 | 2099 | ||
| 1923 | down_read(&pci_bus_sem); | 2100 | down_read(&pci_bus_sem); |
| 1924 | list_for_each_entry(dev, &bus->devices, bus_list) | 2101 | for_each_pci_bridge(dev, bus) |
| 1925 | if (pci_is_bridge(dev) && pci_has_subordinate(dev)) | 2102 | if (pci_has_subordinate(dev)) |
| 1926 | __pci_bus_size_bridges(dev->subordinate, | 2103 | __pci_bus_size_bridges(dev->subordinate, &add_list); |
| 1927 | &add_list); | ||
| 1928 | up_read(&pci_bus_sem); | 2104 | up_read(&pci_bus_sem); |
| 1929 | __pci_bus_assign_resources(bus, &add_list, NULL); | 2105 | __pci_bus_assign_resources(bus, &add_list, NULL); |
| 1930 | BUG_ON(!list_empty(&add_list)); | 2106 | BUG_ON(!list_empty(&add_list)); |
diff --git a/drivers/pcmcia/cardbus.c b/drivers/pcmcia/cardbus.c index 4fe4cc4ae19a..5c0170597037 100644 --- a/drivers/pcmcia/cardbus.c +++ b/drivers/pcmcia/cardbus.c | |||
| @@ -77,9 +77,8 @@ int __ref cb_alloc(struct pcmcia_socket *s) | |||
| 77 | 77 | ||
| 78 | max = bus->busn_res.start; | 78 | max = bus->busn_res.start; |
| 79 | for (pass = 0; pass < 2; pass++) | 79 | for (pass = 0; pass < 2; pass++) |
| 80 | list_for_each_entry(dev, &bus->devices, bus_list) | 80 | for_each_pci_bridge(dev, bus) |
| 81 | if (pci_is_bridge(dev)) | 81 | max = pci_scan_bridge(bus, dev, max, pass); |
| 82 | max = pci_scan_bridge(bus, dev, max, pass); | ||
| 83 | 82 | ||
| 84 | /* | 83 | /* |
| 85 | * Size all resources below the CardBus controller. | 84 | * Size all resources below the CardBus controller. |
diff --git a/include/linux/pci.h b/include/linux/pci.h index f4f8ee5a7362..3dbe947b4152 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h | |||
| @@ -596,6 +596,10 @@ static inline bool pci_is_bridge(struct pci_dev *dev) | |||
| 596 | dev->hdr_type == PCI_HEADER_TYPE_CARDBUS; | 596 | dev->hdr_type == PCI_HEADER_TYPE_CARDBUS; |
| 597 | } | 597 | } |
| 598 | 598 | ||
| 599 | #define for_each_pci_bridge(dev, bus) \ | ||
| 600 | list_for_each_entry(dev, &bus->devices, bus_list) \ | ||
| 601 | if (!pci_is_bridge(dev)) {} else | ||
| 602 | |||
| 599 | static inline struct pci_dev *pci_upstream_bridge(struct pci_dev *dev) | 603 | static inline struct pci_dev *pci_upstream_bridge(struct pci_dev *dev) |
| 600 | { | 604 | { |
| 601 | dev = pci_physfn(dev); | 605 | dev = pci_physfn(dev); |
