diff options
author | Huang Ying <ying.huang@intel.com> | 2012-08-14 21:43:03 -0400 |
---|---|---|
committer | Bjorn Helgaas <bhelgaas@google.com> | 2012-08-21 19:34:24 -0400 |
commit | 3d8387efe1ad9eb5bfe8a2e58cdbd1b88b247eef (patch) | |
tree | a589e0ab38c2ecda5aff3792b677bd2b0c06b718 /drivers/pci/pci-sysfs.c | |
parent | ea8c88f13d9fb1d6b39a05bfa07ae076ca1c6803 (diff) |
PCI/PM: Fix config reg access for D3cold and bridge suspending
This patch fixes the following bug:
http://marc.info/?l=linux-pci&m=134338059022620&w=2
Where lspci does not work properly if a device and the corresponding
parent bridge (such as PCIe port) is suspended. This is because the
device configuration space registers will be not accessible if the
corresponding parent bridge is suspended or the device is put into
D3cold state.
To solve the issue, the bridge/PCIe port connected to the device is
put into active state before read/write configuration space registers.
If the device is in D3cold state, it will be put into active state
too.
To avoid resume/suspend PCIe port for each configuration register
read/write, a small delay is added before the PCIe port to go
suspended.
Reported-by: Bjorn Mork <bjorn@mork.no>
Signed-off-by: Huang Ying <ying.huang@intel.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Rafael J. Wysocki <rjw@sisk.pl>
Diffstat (limited to 'drivers/pci/pci-sysfs.c')
-rw-r--r-- | drivers/pci/pci-sysfs.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 6869009c7393..02d107b15281 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c | |||
@@ -458,6 +458,40 @@ boot_vga_show(struct device *dev, struct device_attribute *attr, char *buf) | |||
458 | } | 458 | } |
459 | struct device_attribute vga_attr = __ATTR_RO(boot_vga); | 459 | struct device_attribute vga_attr = __ATTR_RO(boot_vga); |
460 | 460 | ||
461 | static void | ||
462 | pci_config_pm_runtime_get(struct pci_dev *pdev) | ||
463 | { | ||
464 | struct device *dev = &pdev->dev; | ||
465 | struct device *parent = dev->parent; | ||
466 | |||
467 | if (parent) | ||
468 | pm_runtime_get_sync(parent); | ||
469 | pm_runtime_get_noresume(dev); | ||
470 | /* | ||
471 | * pdev->current_state is set to PCI_D3cold during suspending, | ||
472 | * so wait until suspending completes | ||
473 | */ | ||
474 | pm_runtime_barrier(dev); | ||
475 | /* | ||
476 | * Only need to resume devices in D3cold, because config | ||
477 | * registers are still accessible for devices suspended but | ||
478 | * not in D3cold. | ||
479 | */ | ||
480 | if (pdev->current_state == PCI_D3cold) | ||
481 | pm_runtime_resume(dev); | ||
482 | } | ||
483 | |||
484 | static void | ||
485 | pci_config_pm_runtime_put(struct pci_dev *pdev) | ||
486 | { | ||
487 | struct device *dev = &pdev->dev; | ||
488 | struct device *parent = dev->parent; | ||
489 | |||
490 | pm_runtime_put(dev); | ||
491 | if (parent) | ||
492 | pm_runtime_put_sync(parent); | ||
493 | } | ||
494 | |||
461 | static ssize_t | 495 | static ssize_t |
462 | pci_read_config(struct file *filp, struct kobject *kobj, | 496 | pci_read_config(struct file *filp, struct kobject *kobj, |
463 | struct bin_attribute *bin_attr, | 497 | struct bin_attribute *bin_attr, |
@@ -484,6 +518,8 @@ pci_read_config(struct file *filp, struct kobject *kobj, | |||
484 | size = count; | 518 | size = count; |
485 | } | 519 | } |
486 | 520 | ||
521 | pci_config_pm_runtime_get(dev); | ||
522 | |||
487 | if ((off & 1) && size) { | 523 | if ((off & 1) && size) { |
488 | u8 val; | 524 | u8 val; |
489 | pci_user_read_config_byte(dev, off, &val); | 525 | pci_user_read_config_byte(dev, off, &val); |
@@ -529,6 +565,8 @@ pci_read_config(struct file *filp, struct kobject *kobj, | |||
529 | --size; | 565 | --size; |
530 | } | 566 | } |
531 | 567 | ||
568 | pci_config_pm_runtime_put(dev); | ||
569 | |||
532 | return count; | 570 | return count; |
533 | } | 571 | } |
534 | 572 | ||
@@ -549,6 +587,8 @@ pci_write_config(struct file* filp, struct kobject *kobj, | |||
549 | count = size; | 587 | count = size; |
550 | } | 588 | } |
551 | 589 | ||
590 | pci_config_pm_runtime_get(dev); | ||
591 | |||
552 | if ((off & 1) && size) { | 592 | if ((off & 1) && size) { |
553 | pci_user_write_config_byte(dev, off, data[off - init_off]); | 593 | pci_user_write_config_byte(dev, off, data[off - init_off]); |
554 | off++; | 594 | off++; |
@@ -587,6 +627,8 @@ pci_write_config(struct file* filp, struct kobject *kobj, | |||
587 | --size; | 627 | --size; |
588 | } | 628 | } |
589 | 629 | ||
630 | pci_config_pm_runtime_put(dev); | ||
631 | |||
590 | return count; | 632 | return count; |
591 | } | 633 | } |
592 | 634 | ||