Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branches 'pci/hotplug', 'pci/pci_is_bridge' and 'pci/virtualization' into next

* pci/hotplug:
PCI: cpqphp: Fix possible null pointer dereference
NVMe: Implement PCIe reset notification callback
PCI: Notify driver before and after device reset

* pci/pci_is_bridge:
pcmcia: Use pci_is_bridge() to simplify code
PCI: pciehp: Use pci_is_bridge() to simplify code
PCI: acpiphp: Use pci_is_bridge() to simplify code
PCI: cpcihp: Use pci_is_bridge() to simplify code
PCI: shpchp: Use pci_is_bridge() to simplify code
PCI: rpaphp: Use pci_is_bridge() to simplify code
sparc/PCI: Use pci_is_bridge() to simplify code
powerpc/PCI: Use pci_is_bridge() to simplify code
ia64/PCI: Use pci_is_bridge() to simplify code
x86/PCI: Use pci_is_bridge() to simplify code
PCI: Use pci_is_bridge() to simplify code
PCI: Add new pci_is_bridge() interface
PCI: Rename pci_is_bridge() to pci_has_subordinate()

* pci/virtualization:
PCI: Introduce new device binding path using pci_dev.driver_override

Conflicts:
drivers/pci/pci-sysfs.c

+154 -45
+21
Documentation/ABI/testing/sysfs-bus-pci
··· 250 250 valid. For example, writing a 2 to this file when sriov_numvfs 251 251 is not 0 and not 2 already will return an error. Writing a 10 252 252 when the value of sriov_totalvfs is 8 will return an error. 253 + 254 + What: /sys/bus/pci/devices/.../driver_override 255 + Date: April 2014 256 + Contact: Alex Williamson <alex.williamson@redhat.com> 257 + Description: 258 + This file allows the driver for a device to be specified which 259 + will override standard static and dynamic ID matching. When 260 + specified, only a driver with a name matching the value written 261 + to driver_override will have an opportunity to bind to the 262 + device. The override is specified by writing a string to the 263 + driver_override file (echo pci-stub > driver_override) and 264 + may be cleared with an empty string (echo > driver_override). 265 + This returns the device to standard matching rules binding. 266 + Writing to driver_override does not automatically unbind the 267 + device from its current driver or make any attempt to 268 + automatically load the specified driver. If no driver with a 269 + matching name is currently loaded in the kernel, the device 270 + will not bind to any driver. This also allows devices to 271 + opt-out of driver binding using a driver_override name such as 272 + "none". Only a single driver may be specified in the override, 273 + there is no support for parsing delimiters.
+1 -3
arch/ia64/pci/fixup.c
··· 49 49 * type BRIDGE, or CARDBUS. Host to PCI controllers use 50 50 * PCI header type NORMAL. 51 51 */ 52 - if (bridge 53 - &&((bridge->hdr_type == PCI_HEADER_TYPE_BRIDGE) 54 - ||(bridge->hdr_type == PCI_HEADER_TYPE_CARDBUS))) { 52 + if (bridge && (pci_is_bridge(bridge))) { 55 53 pci_read_config_word(bridge, PCI_BRIDGE_CONTROL, 56 54 &config); 57 55 if (!(config & PCI_BRIDGE_CTL_VGA))
+1 -2
arch/powerpc/kernel/pci-hotplug.c
··· 98 98 max = bus->busn_res.start; 99 99 for (pass = 0; pass < 2; pass++) { 100 100 list_for_each_entry(dev, &bus->devices, bus_list) { 101 - if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE || 102 - dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) 101 + if (pci_is_bridge(dev)) 103 102 max = pci_scan_bridge(bus, dev, 104 103 max, pass); 105 104 }
+1 -2
arch/powerpc/kernel/pci_of_scan.c
··· 362 362 363 363 /* Now scan child busses */ 364 364 list_for_each_entry(dev, &bus->devices, bus_list) { 365 - if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE || 366 - dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) { 365 + if (pci_is_bridge(dev)) { 367 366 of_scan_pci_bridge(dev); 368 367 } 369 368 }
+1 -2
arch/sparc/kernel/pci.c
··· 543 543 printk("PCI: dev header type: %x\n", 544 544 dev->hdr_type); 545 545 546 - if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE || 547 - dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) 546 + if (pci_is_bridge(dev)) 548 547 of_scan_pci_bridge(pbm, child, dev); 549 548 } 550 549 }
+1 -3
arch/x86/pci/fixup.c
··· 338 338 * type BRIDGE, or CARDBUS. Host to PCI controllers use 339 339 * PCI header type NORMAL. 340 340 */ 341 - if (bridge 342 - && ((bridge->hdr_type == PCI_HEADER_TYPE_BRIDGE) 343 - || (bridge->hdr_type == PCI_HEADER_TYPE_CARDBUS))) { 341 + if (bridge && (pci_is_bridge(bridge))) { 344 342 pci_read_config_word(bridge, PCI_BRIDGE_CONTROL, 345 343 &config); 346 344 if (!(config & PCI_BRIDGE_CTL_VGA))
+11
drivers/block/nvme-core.c
··· 2775 2775 return result; 2776 2776 } 2777 2777 2778 + static void nvme_reset_notify(struct pci_dev *pdev, bool prepare) 2779 + { 2780 + struct nvme_dev *dev = pci_get_drvdata(pdev); 2781 + 2782 + if (prepare) 2783 + nvme_dev_shutdown(dev); 2784 + else 2785 + nvme_dev_resume(dev); 2786 + } 2787 + 2778 2788 static void nvme_shutdown(struct pci_dev *pdev) 2779 2789 { 2780 2790 struct nvme_dev *dev = pci_get_drvdata(pdev); ··· 2849 2839 .link_reset = nvme_link_reset, 2850 2840 .slot_reset = nvme_slot_reset, 2851 2841 .resume = nvme_error_resume, 2842 + .reset_notify = nvme_reset_notify, 2852 2843 }; 2853 2844 2854 2845 /* Move to pci_ids.h later */
+1 -2
drivers/pci/hotplug/acpiphp_glue.c
··· 515 515 if (PCI_SLOT(dev->devfn) != slot->device) 516 516 continue; 517 517 518 - if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE || 519 - dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) { 518 + if (pci_is_bridge(dev)) { 520 519 max = pci_scan_bridge(bus, dev, max, pass); 521 520 if (pass && dev->subordinate) { 522 521 check_hotplug_bridge(slot, dev);
+1 -2
drivers/pci/hotplug/cpci_hotplug_pci.c
··· 289 289 list_for_each_entry(dev, &parent->devices, bus_list) 290 290 if (PCI_SLOT(dev->devfn) != PCI_SLOT(slot->devfn)) 291 291 continue; 292 - if ((dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) || 293 - (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)) 292 + if (pci_is_bridge(dev)) 294 293 pci_hp_add_bridge(dev); 295 294 296 295
+2 -1
drivers/pci/hotplug/cpqphp_ctrl.c
··· 709 709 temp = temp->next; 710 710 } 711 711 712 - temp->next = max->next; 712 + if (temp) 713 + temp->next = max->next; 713 714 } 714 715 715 716 max->next = NULL;
+1 -2
drivers/pci/hotplug/pciehp_pci.c
··· 62 62 } 63 63 64 64 list_for_each_entry(dev, &parent->devices, bus_list) 65 - if ((dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) || 66 - (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)) 65 + if (pci_is_bridge(dev)) 67 66 pci_hp_add_bridge(dev); 68 67 69 68 pci_assign_unassigned_bridge_resources(bridge);
+1 -2
drivers/pci/hotplug/rpadlpar_core.c
··· 157 157 } 158 158 159 159 /* Scan below the new bridge */ 160 - if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE || 161 - dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) 160 + if (pci_is_bridge(dev)) 162 161 of_scan_pci_bridge(dev); 163 162 164 163 /* Map IO space for child bus, which may or may not succeed */
+1 -2
drivers/pci/hotplug/shpchp_pci.c
··· 64 64 list_for_each_entry(dev, &parent->devices, bus_list) { 65 65 if (PCI_SLOT(dev->devfn) != p_slot->device) 66 66 continue; 67 - if ((dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) || 68 - (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)) 67 + if (pci_is_bridge(dev)) 69 68 pci_hp_add_bridge(dev); 70 69 } 71 70
+1 -7
drivers/pci/pci-acpi.c
··· 309 309 bool check_children; 310 310 u64 addr; 311 311 312 - /* 313 - * pci_is_bridge() is not suitable here, because pci_dev->subordinate 314 - * is set only after acpi_pci_find_device() has been called for the 315 - * given device. 316 - */ 317 - check_children = pci_dev->hdr_type == PCI_HEADER_TYPE_BRIDGE 318 - || pci_dev->hdr_type == PCI_HEADER_TYPE_CARDBUS; 312 + check_children = pci_is_bridge(pci_dev); 319 313 /* Please ref to ACPI spec for the syntax of _ADR */ 320 314 addr = (PCI_SLOT(pci_dev->devfn) << 16) | PCI_FUNC(pci_dev->devfn); 321 315 return acpi_find_child_device(ACPI_COMPANION(dev->parent), addr,
+26 -7
drivers/pci/pci-driver.c
··· 236 236 return NULL; 237 237 } 238 238 239 + static const struct pci_device_id pci_device_id_any = { 240 + .vendor = PCI_ANY_ID, 241 + .device = PCI_ANY_ID, 242 + .subvendor = PCI_ANY_ID, 243 + .subdevice = PCI_ANY_ID, 244 + }; 245 + 239 246 /** 240 247 * pci_match_device - Tell if a PCI device structure has a matching PCI device id structure 241 248 * @drv: the PCI driver to match against ··· 256 249 struct pci_dev *dev) 257 250 { 258 251 struct pci_dynid *dynid; 252 + const struct pci_device_id *found_id = NULL; 253 + 254 + /* When driver_override is set, only bind to the matching driver */ 255 + if (dev->driver_override && strcmp(dev->driver_override, drv->name)) 256 + return NULL; 259 257 260 258 /* Look at the dynamic ids first, before the static ones */ 261 259 spin_lock(&drv->dynids.lock); 262 260 list_for_each_entry(dynid, &drv->dynids.list, node) { 263 261 if (pci_match_one_device(&dynid->id, dev)) { 264 - spin_unlock(&drv->dynids.lock); 265 - return &dynid->id; 262 + found_id = &dynid->id; 263 + break; 266 264 } 267 265 } 268 266 spin_unlock(&drv->dynids.lock); 269 267 270 - return pci_match_id(drv->id_table, dev); 268 + if (!found_id) 269 + found_id = pci_match_id(drv->id_table, dev); 270 + 271 + /* driver_override will always match, send a dummy id */ 272 + if (!found_id && dev->driver_override) 273 + found_id = &pci_device_id_any; 274 + 275 + return found_id; 271 276 } 272 277 273 278 struct drv_dev_and_id { ··· 619 600 { 620 601 pci_fixup_device(pci_fixup_resume, pci_dev); 621 602 622 - if (!pci_is_bridge(pci_dev)) 603 + if (!pci_has_subordinate(pci_dev)) 623 604 pci_enable_wake(pci_dev, PCI_D0, false); 624 605 } 625 606 626 607 static void pci_pm_default_suspend(struct pci_dev *pci_dev) 627 608 { 628 609 /* Disable non-bridge devices without PM support */ 629 - if (!pci_is_bridge(pci_dev)) 610 + if (!pci_has_subordinate(pci_dev)) 630 611 pci_disable_enabled_device(pci_dev); 631 612 } 632 613 ··· 756 737 757 738 if (!pci_dev->state_saved) { 758 739 pci_save_state(pci_dev); 759 - if (!pci_is_bridge(pci_dev)) 740 + if (!pci_has_subordinate(pci_dev)) 760 741 pci_prepare_to_sleep(pci_dev); 761 742 } 762 743 ··· 1010 991 return error; 1011 992 } 1012 993 1013 - if (!pci_dev->state_saved && !pci_is_bridge(pci_dev)) 994 + if (!pci_dev->state_saved && !pci_has_subordinate(pci_dev)) 1014 995 pci_prepare_to_sleep(pci_dev); 1015 996 1016 997 /*
+40
drivers/pci/pci-sysfs.c
··· 514 514 sriov_numvfs_show, sriov_numvfs_store); 515 515 #endif /* CONFIG_PCI_IOV */ 516 516 517 + static ssize_t driver_override_store(struct device *dev, 518 + struct device_attribute *attr, 519 + const char *buf, size_t count) 520 + { 521 + struct pci_dev *pdev = to_pci_dev(dev); 522 + char *driver_override, *old = pdev->driver_override, *cp; 523 + 524 + if (count > PATH_MAX) 525 + return -EINVAL; 526 + 527 + driver_override = kstrndup(buf, count, GFP_KERNEL); 528 + if (!driver_override) 529 + return -ENOMEM; 530 + 531 + cp = strchr(driver_override, '\n'); 532 + if (cp) 533 + *cp = '\0'; 534 + 535 + if (strlen(driver_override)) { 536 + pdev->driver_override = driver_override; 537 + } else { 538 + kfree(driver_override); 539 + pdev->driver_override = NULL; 540 + } 541 + 542 + kfree(old); 543 + 544 + return count; 545 + } 546 + 547 + static ssize_t driver_override_show(struct device *dev, 548 + struct device_attribute *attr, char *buf) 549 + { 550 + struct pci_dev *pdev = to_pci_dev(dev); 551 + 552 + return sprintf(buf, "%s\n", pdev->driver_override); 553 + } 554 + static DEVICE_ATTR_RW(driver_override); 555 + 517 556 static struct attribute *pci_dev_attrs[] = { 518 557 &dev_attr_resource.attr, 519 558 &dev_attr_vendor.attr, ··· 578 539 #ifdef CONFIG_OF 579 540 &dev_attr_devspec.attr, 580 541 #endif 542 + &dev_attr_driver_override.attr, 581 543 NULL, 582 544 }; 583 545
+21
drivers/pci/pci.c
··· 3305 3305 pci_cfg_access_unlock(dev); 3306 3306 } 3307 3307 3308 + /** 3309 + * pci_reset_notify - notify device driver of reset 3310 + * @dev: device to be notified of reset 3311 + * @prepare: 'true' if device is about to be reset; 'false' if reset attempt 3312 + * completed 3313 + * 3314 + * Must be called prior to device access being disabled and after device 3315 + * access is restored. 3316 + */ 3317 + static void pci_reset_notify(struct pci_dev *dev, bool prepare) 3318 + { 3319 + const struct pci_error_handlers *err_handler = 3320 + dev->driver ? dev->driver->err_handler : NULL; 3321 + if (err_handler && err_handler->reset_notify) 3322 + err_handler->reset_notify(dev, prepare); 3323 + } 3324 + 3308 3325 static void pci_dev_save_and_disable(struct pci_dev *dev) 3309 3326 { 3327 + pci_reset_notify(dev, true); 3328 + 3310 3329 /* 3311 3330 * Wake-up device prior to save. PM registers default to D0 after 3312 3331 * reset and a simple register restore doesn't reliably return ··· 3347 3328 static void pci_dev_restore(struct pci_dev *dev) 3348 3329 { 3349 3330 pci_restore_state(dev); 3331 + pci_reset_notify(dev, false); 3350 3332 } 3351 3333 3352 3334 static int pci_dev_reset(struct pci_dev *dev, int probe) ··· 3364 3344 3365 3345 return rc; 3366 3346 } 3347 + 3367 3348 /** 3368 3349 * __pci_reset_function - reset a PCI device function 3369 3350 * @dev: PCI device to reset
+1 -1
drivers/pci/pci.h
··· 77 77 pm_wakeup_event(&dev->dev, 100); 78 78 } 79 79 80 - static inline bool pci_is_bridge(struct pci_dev *pci_dev) 80 + static inline bool pci_has_subordinate(struct pci_dev *pci_dev) 81 81 { 82 82 return !!(pci_dev->subordinate); 83 83 }
+2 -2
drivers/pci/probe.c
··· 1225 1225 pci_release_of_node(pci_dev); 1226 1226 pcibios_release_device(pci_dev); 1227 1227 pci_bus_put(pci_dev->bus); 1228 + kfree(pci_dev->driver_override); 1228 1229 kfree(pci_dev); 1229 1230 } 1230 1231 ··· 1681 1680 1682 1681 for (pass=0; pass < 2; pass++) 1683 1682 list_for_each_entry(dev, &bus->devices, bus_list) { 1684 - if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE || 1685 - dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) 1683 + if (pci_is_bridge(dev)) 1686 1684 max = pci_scan_bridge(bus, dev, max, pass); 1687 1685 } 1688 1686
+1 -3
drivers/pci/setup-bus.c
··· 1716 1716 1717 1717 down_read(&pci_bus_sem); 1718 1718 list_for_each_entry(dev, &bus->devices, bus_list) 1719 - if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE || 1720 - dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) 1721 - if (dev->subordinate) 1719 + if (pci_is_bridge(dev) && pci_has_subordinate(dev)) 1722 1720 __pci_bus_size_bridges(dev->subordinate, 1723 1721 &add_list); 1724 1722 up_read(&pci_bus_sem);
+1 -2
drivers/pcmcia/cardbus.c
··· 78 78 max = bus->busn_res.start; 79 79 for (pass = 0; pass < 2; pass++) 80 80 list_for_each_entry(dev, &bus->devices, bus_list) 81 - if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE || 82 - dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) 81 + if (pci_is_bridge(dev)) 83 82 max = pci_scan_bridge(bus, dev, max, pass); 84 83 85 84 /*
+17
include/linux/pci.h
··· 365 365 #endif 366 366 phys_addr_t rom; /* Physical address of ROM if it's not from the BAR */ 367 367 size_t romlen; /* Length of ROM if it's not from the BAR */ 368 + char *driver_override; /* Driver name to force a match */ 368 369 }; 369 370 370 371 static inline struct pci_dev *pci_physfn(struct pci_dev *dev) ··· 476 475 static inline bool pci_is_root_bus(struct pci_bus *pbus) 477 476 { 478 477 return !(pbus->parent); 478 + } 479 + 480 + /** 481 + * pci_is_bridge - check if the PCI device is a bridge 482 + * @dev: PCI device 483 + * 484 + * Return true if the PCI device is bridge whether it has subordinate 485 + * or not. 486 + */ 487 + static inline bool pci_is_bridge(struct pci_dev *dev) 488 + { 489 + return dev->hdr_type == PCI_HEADER_TYPE_BRIDGE || 490 + dev->hdr_type == PCI_HEADER_TYPE_CARDBUS; 479 491 } 480 492 481 493 static inline struct pci_dev *pci_upstream_bridge(struct pci_dev *dev) ··· 616 602 617 603 /* PCI slot has been reset */ 618 604 pci_ers_result_t (*slot_reset)(struct pci_dev *dev); 605 + 606 + /* PCI function reset prepare or completed */ 607 + void (*reset_notify)(struct pci_dev *dev, bool prepare); 619 608 620 609 /* Device driver may resume normal operations */ 621 610 void (*resume)(struct pci_dev *dev);