diff options
-rw-r--r-- | arch/x86/pci/mrst.c | 2 | ||||
-rw-r--r-- | drivers/acpi/sleep.c | 24 | ||||
-rw-r--r-- | drivers/misc/cb710/core.c | 2 | ||||
-rw-r--r-- | drivers/pci/pci-acpi.c | 22 | ||||
-rw-r--r-- | drivers/pci/pci-driver.c | 10 | ||||
-rw-r--r-- | drivers/pci/pci-sysfs.c | 29 | ||||
-rw-r--r-- | drivers/pci/pci.c | 124 | ||||
-rw-r--r-- | drivers/pci/pci.h | 1 | ||||
-rw-r--r-- | drivers/pci/pcie/portdrv_pci.c | 60 | ||||
-rw-r--r-- | drivers/pnp/pnpacpi/core.c | 4 | ||||
-rw-r--r-- | include/acpi/acpi_bus.h | 6 | ||||
-rw-r--r-- | include/linux/pci.h | 16 |
12 files changed, 271 insertions, 29 deletions
diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c index 140942f66b31..e14a2ff708b5 100644 --- a/arch/x86/pci/mrst.c +++ b/arch/x86/pci/mrst.c | |||
@@ -264,7 +264,7 @@ DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_ANY_ID, pci_d3delay_fixup); | |||
264 | 264 | ||
265 | static void __devinit mrst_power_off_unused_dev(struct pci_dev *dev) | 265 | static void __devinit mrst_power_off_unused_dev(struct pci_dev *dev) |
266 | { | 266 | { |
267 | pci_set_power_state(dev, PCI_D3cold); | 267 | pci_set_power_state(dev, PCI_D3hot); |
268 | } | 268 | } |
269 | DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x0801, mrst_power_off_unused_dev); | 269 | DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x0801, mrst_power_off_unused_dev); |
270 | DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x0809, mrst_power_off_unused_dev); | 270 | DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x0809, mrst_power_off_unused_dev); |
diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c index 88561029cca8..1cc02ca2af2a 100644 --- a/drivers/acpi/sleep.c +++ b/drivers/acpi/sleep.c | |||
@@ -716,8 +716,9 @@ int acpi_suspend(u32 acpi_state) | |||
716 | * @dev: device to examine; its driver model wakeup flags control | 716 | * @dev: device to examine; its driver model wakeup flags control |
717 | * whether it should be able to wake up the system | 717 | * whether it should be able to wake up the system |
718 | * @d_min_p: used to store the upper limit of allowed states range | 718 | * @d_min_p: used to store the upper limit of allowed states range |
719 | * Return value: preferred power state of the device on success, -ENODEV on | 719 | * @d_max_in: specify the lowest allowed states |
720 | * failure (ie. if there's no 'struct acpi_device' for @dev) | 720 | * Return value: preferred power state of the device on success, -ENODEV |
721 | * (ie. if there's no 'struct acpi_device' for @dev) or -EINVAL on failure | ||
721 | * | 722 | * |
722 | * Find the lowest power (highest number) ACPI device power state that | 723 | * Find the lowest power (highest number) ACPI device power state that |
723 | * device @dev can be in while the system is in the sleep state represented | 724 | * device @dev can be in while the system is in the sleep state represented |
@@ -732,13 +733,15 @@ int acpi_suspend(u32 acpi_state) | |||
732 | * via @wake. | 733 | * via @wake. |
733 | */ | 734 | */ |
734 | 735 | ||
735 | int acpi_pm_device_sleep_state(struct device *dev, int *d_min_p) | 736 | int acpi_pm_device_sleep_state(struct device *dev, int *d_min_p, int d_max_in) |
736 | { | 737 | { |
737 | acpi_handle handle = DEVICE_ACPI_HANDLE(dev); | 738 | acpi_handle handle = DEVICE_ACPI_HANDLE(dev); |
738 | struct acpi_device *adev; | 739 | struct acpi_device *adev; |
739 | char acpi_method[] = "_SxD"; | 740 | char acpi_method[] = "_SxD"; |
740 | unsigned long long d_min, d_max; | 741 | unsigned long long d_min, d_max; |
741 | 742 | ||
743 | if (d_max_in < ACPI_STATE_D0 || d_max_in > ACPI_STATE_D3) | ||
744 | return -EINVAL; | ||
742 | if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &adev))) { | 745 | if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &adev))) { |
743 | printk(KERN_DEBUG "ACPI handle has no context!\n"); | 746 | printk(KERN_DEBUG "ACPI handle has no context!\n"); |
744 | return -ENODEV; | 747 | return -ENODEV; |
@@ -746,8 +749,10 @@ int acpi_pm_device_sleep_state(struct device *dev, int *d_min_p) | |||
746 | 749 | ||
747 | acpi_method[2] = '0' + acpi_target_sleep_state; | 750 | acpi_method[2] = '0' + acpi_target_sleep_state; |
748 | /* | 751 | /* |
749 | * If the sleep state is S0, we will return D3, but if the device has | 752 | * If the sleep state is S0, the lowest limit from ACPI is D3, |
750 | * _S0W, we will use the value from _S0W | 753 | * but if the device has _S0W, we will use the value from _S0W |
754 | * as the lowest limit from ACPI. Finally, we will constrain | ||
755 | * the lowest limit with the specified one. | ||
751 | */ | 756 | */ |
752 | d_min = ACPI_STATE_D0; | 757 | d_min = ACPI_STATE_D0; |
753 | d_max = ACPI_STATE_D3; | 758 | d_max = ACPI_STATE_D3; |
@@ -791,8 +796,17 @@ int acpi_pm_device_sleep_state(struct device *dev, int *d_min_p) | |||
791 | } | 796 | } |
792 | } | 797 | } |
793 | 798 | ||
799 | if (d_max_in < d_min) | ||
800 | return -EINVAL; | ||
794 | if (d_min_p) | 801 | if (d_min_p) |
795 | *d_min_p = d_min; | 802 | *d_min_p = d_min; |
803 | /* constrain d_max with specified lowest limit (max number) */ | ||
804 | if (d_max > d_max_in) { | ||
805 | for (d_max = d_max_in; d_max > d_min; d_max--) { | ||
806 | if (adev->power.states[d_max].flags.valid) | ||
807 | break; | ||
808 | } | ||
809 | } | ||
796 | return d_max; | 810 | return d_max; |
797 | } | 811 | } |
798 | #endif /* CONFIG_PM */ | 812 | #endif /* CONFIG_PM */ |
diff --git a/drivers/misc/cb710/core.c b/drivers/misc/cb710/core.c index 85cc7710193c..9d5eed754666 100644 --- a/drivers/misc/cb710/core.c +++ b/drivers/misc/cb710/core.c | |||
@@ -180,7 +180,7 @@ static int cb710_suspend(struct pci_dev *pdev, pm_message_t state) | |||
180 | pci_save_state(pdev); | 180 | pci_save_state(pdev); |
181 | pci_disable_device(pdev); | 181 | pci_disable_device(pdev); |
182 | if (state.event & PM_EVENT_SLEEP) | 182 | if (state.event & PM_EVENT_SLEEP) |
183 | pci_set_power_state(pdev, PCI_D3cold); | 183 | pci_set_power_state(pdev, PCI_D3hot); |
184 | return 0; | 184 | return 0; |
185 | } | 185 | } |
186 | 186 | ||
diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c index 87f4c504eafb..fbf7b26c7c8a 100644 --- a/drivers/pci/pci-acpi.c +++ b/drivers/pci/pci-acpi.c | |||
@@ -48,6 +48,12 @@ static void pci_acpi_wake_dev(acpi_handle handle, u32 event, void *context) | |||
48 | if (event != ACPI_NOTIFY_DEVICE_WAKE || !pci_dev) | 48 | if (event != ACPI_NOTIFY_DEVICE_WAKE || !pci_dev) |
49 | return; | 49 | return; |
50 | 50 | ||
51 | if (pci_dev->current_state == PCI_D3cold) { | ||
52 | pci_wakeup_event(pci_dev); | ||
53 | pm_runtime_resume(&pci_dev->dev); | ||
54 | return; | ||
55 | } | ||
56 | |||
51 | if (!pci_dev->pm_cap || !pci_dev->pme_support | 57 | if (!pci_dev->pm_cap || !pci_dev->pme_support |
52 | || pci_check_pme_status(pci_dev)) { | 58 | || pci_check_pme_status(pci_dev)) { |
53 | if (pci_dev->pme_poll) | 59 | if (pci_dev->pme_poll) |
@@ -201,9 +207,13 @@ phys_addr_t acpi_pci_root_get_mcfg_addr(acpi_handle handle) | |||
201 | 207 | ||
202 | static pci_power_t acpi_pci_choose_state(struct pci_dev *pdev) | 208 | static pci_power_t acpi_pci_choose_state(struct pci_dev *pdev) |
203 | { | 209 | { |
204 | int acpi_state; | 210 | int acpi_state, d_max; |
205 | 211 | ||
206 | acpi_state = acpi_pm_device_sleep_state(&pdev->dev, NULL); | 212 | if (pdev->no_d3cold) |
213 | d_max = ACPI_STATE_D3_HOT; | ||
214 | else | ||
215 | d_max = ACPI_STATE_D3_COLD; | ||
216 | acpi_state = acpi_pm_device_sleep_state(&pdev->dev, NULL, d_max); | ||
207 | if (acpi_state < 0) | 217 | if (acpi_state < 0) |
208 | return PCI_POWER_ERROR; | 218 | return PCI_POWER_ERROR; |
209 | 219 | ||
@@ -310,7 +320,13 @@ static void acpi_pci_propagate_run_wake(struct pci_bus *bus, bool enable) | |||
310 | 320 | ||
311 | static int acpi_pci_run_wake(struct pci_dev *dev, bool enable) | 321 | static int acpi_pci_run_wake(struct pci_dev *dev, bool enable) |
312 | { | 322 | { |
313 | if (dev->pme_interrupt) | 323 | /* |
324 | * Per PCI Express Base Specification Revision 2.0 section | ||
325 | * 5.3.3.2 Link Wakeup, platform support is needed for D3cold | ||
326 | * waking up to power on the main link even if there is PME | ||
327 | * support for D3cold | ||
328 | */ | ||
329 | if (dev->pme_interrupt && !dev->runtime_d3cold) | ||
314 | return 0; | 330 | return 0; |
315 | 331 | ||
316 | if (!acpi_pm_device_run_wake(&dev->dev, enable)) | 332 | if (!acpi_pm_device_run_wake(&dev->dev, enable)) |
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c index bf0cee629b60..ca2e4c79a588 100644 --- a/drivers/pci/pci-driver.c +++ b/drivers/pci/pci-driver.c | |||
@@ -1019,10 +1019,13 @@ static int pci_pm_runtime_suspend(struct device *dev) | |||
1019 | if (!pm || !pm->runtime_suspend) | 1019 | if (!pm || !pm->runtime_suspend) |
1020 | return -ENOSYS; | 1020 | return -ENOSYS; |
1021 | 1021 | ||
1022 | pci_dev->no_d3cold = false; | ||
1022 | error = pm->runtime_suspend(dev); | 1023 | error = pm->runtime_suspend(dev); |
1023 | suspend_report_result(pm->runtime_suspend, error); | 1024 | suspend_report_result(pm->runtime_suspend, error); |
1024 | if (error) | 1025 | if (error) |
1025 | return error; | 1026 | return error; |
1027 | if (!pci_dev->d3cold_allowed) | ||
1028 | pci_dev->no_d3cold = true; | ||
1026 | 1029 | ||
1027 | pci_fixup_device(pci_fixup_suspend, pci_dev); | 1030 | pci_fixup_device(pci_fixup_suspend, pci_dev); |
1028 | 1031 | ||
@@ -1044,6 +1047,7 @@ static int pci_pm_runtime_suspend(struct device *dev) | |||
1044 | 1047 | ||
1045 | static int pci_pm_runtime_resume(struct device *dev) | 1048 | static int pci_pm_runtime_resume(struct device *dev) |
1046 | { | 1049 | { |
1050 | int rc; | ||
1047 | struct pci_dev *pci_dev = to_pci_dev(dev); | 1051 | struct pci_dev *pci_dev = to_pci_dev(dev); |
1048 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; | 1052 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; |
1049 | 1053 | ||
@@ -1054,7 +1058,11 @@ static int pci_pm_runtime_resume(struct device *dev) | |||
1054 | __pci_enable_wake(pci_dev, PCI_D0, true, false); | 1058 | __pci_enable_wake(pci_dev, PCI_D0, true, false); |
1055 | pci_fixup_device(pci_fixup_resume, pci_dev); | 1059 | pci_fixup_device(pci_fixup_resume, pci_dev); |
1056 | 1060 | ||
1057 | return pm->runtime_resume(dev); | 1061 | rc = pm->runtime_resume(dev); |
1062 | |||
1063 | pci_dev->runtime_d3cold = false; | ||
1064 | |||
1065 | return rc; | ||
1058 | } | 1066 | } |
1059 | 1067 | ||
1060 | static int pci_pm_runtime_idle(struct device *dev) | 1068 | static int pci_pm_runtime_idle(struct device *dev) |
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index a0b435f20bd6..6869009c7393 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c | |||
@@ -28,6 +28,7 @@ | |||
28 | #include <linux/pci-aspm.h> | 28 | #include <linux/pci-aspm.h> |
29 | #include <linux/slab.h> | 29 | #include <linux/slab.h> |
30 | #include <linux/vgaarb.h> | 30 | #include <linux/vgaarb.h> |
31 | #include <linux/pm_runtime.h> | ||
31 | #include "pci.h" | 32 | #include "pci.h" |
32 | 33 | ||
33 | static int sysfs_initialized; /* = 0 */ | 34 | static int sysfs_initialized; /* = 0 */ |
@@ -378,6 +379,31 @@ dev_bus_rescan_store(struct device *dev, struct device_attribute *attr, | |||
378 | 379 | ||
379 | #endif | 380 | #endif |
380 | 381 | ||
382 | #if defined(CONFIG_PM_RUNTIME) && defined(CONFIG_ACPI) | ||
383 | static ssize_t d3cold_allowed_store(struct device *dev, | ||
384 | struct device_attribute *attr, | ||
385 | const char *buf, size_t count) | ||
386 | { | ||
387 | struct pci_dev *pdev = to_pci_dev(dev); | ||
388 | unsigned long val; | ||
389 | |||
390 | if (strict_strtoul(buf, 0, &val) < 0) | ||
391 | return -EINVAL; | ||
392 | |||
393 | pdev->d3cold_allowed = !!val; | ||
394 | pm_runtime_resume(dev); | ||
395 | |||
396 | return count; | ||
397 | } | ||
398 | |||
399 | static ssize_t d3cold_allowed_show(struct device *dev, | ||
400 | struct device_attribute *attr, char *buf) | ||
401 | { | ||
402 | struct pci_dev *pdev = to_pci_dev(dev); | ||
403 | return sprintf (buf, "%u\n", pdev->d3cold_allowed); | ||
404 | } | ||
405 | #endif | ||
406 | |||
381 | struct device_attribute pci_dev_attrs[] = { | 407 | struct device_attribute pci_dev_attrs[] = { |
382 | __ATTR_RO(resource), | 408 | __ATTR_RO(resource), |
383 | __ATTR_RO(vendor), | 409 | __ATTR_RO(vendor), |
@@ -402,6 +428,9 @@ struct device_attribute pci_dev_attrs[] = { | |||
402 | __ATTR(remove, (S_IWUSR|S_IWGRP), NULL, remove_store), | 428 | __ATTR(remove, (S_IWUSR|S_IWGRP), NULL, remove_store), |
403 | __ATTR(rescan, (S_IWUSR|S_IWGRP), NULL, dev_rescan_store), | 429 | __ATTR(rescan, (S_IWUSR|S_IWGRP), NULL, dev_rescan_store), |
404 | #endif | 430 | #endif |
431 | #if defined(CONFIG_PM_RUNTIME) && defined(CONFIG_ACPI) | ||
432 | __ATTR(d3cold_allowed, 0644, d3cold_allowed_show, d3cold_allowed_store), | ||
433 | #endif | ||
405 | __ATTR_NULL, | 434 | __ATTR_NULL, |
406 | }; | 435 | }; |
407 | 436 | ||
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 87928fde77b0..3f8b74f07147 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c | |||
@@ -587,7 +587,8 @@ static int pci_raw_set_power_state(struct pci_dev *dev, pci_power_t state) | |||
587 | dev_info(&dev->dev, "Refused to change power state, " | 587 | dev_info(&dev->dev, "Refused to change power state, " |
588 | "currently in D%d\n", dev->current_state); | 588 | "currently in D%d\n", dev->current_state); |
589 | 589 | ||
590 | /* According to section 5.4.1 of the "PCI BUS POWER MANAGEMENT | 590 | /* |
591 | * According to section 5.4.1 of the "PCI BUS POWER MANAGEMENT | ||
591 | * INTERFACE SPECIFICATION, REV. 1.2", a device transitioning | 592 | * INTERFACE SPECIFICATION, REV. 1.2", a device transitioning |
592 | * from D3hot to D0 _may_ perform an internal reset, thereby | 593 | * from D3hot to D0 _may_ perform an internal reset, thereby |
593 | * going to "D0 Uninitialized" rather than "D0 Initialized". | 594 | * going to "D0 Uninitialized" rather than "D0 Initialized". |
@@ -619,6 +620,16 @@ void pci_update_current_state(struct pci_dev *dev, pci_power_t state) | |||
619 | if (dev->pm_cap) { | 620 | if (dev->pm_cap) { |
620 | u16 pmcsr; | 621 | u16 pmcsr; |
621 | 622 | ||
623 | /* | ||
624 | * Configuration space is not accessible for device in | ||
625 | * D3cold, so just keep or set D3cold for safety | ||
626 | */ | ||
627 | if (dev->current_state == PCI_D3cold) | ||
628 | return; | ||
629 | if (state == PCI_D3cold) { | ||
630 | dev->current_state = PCI_D3cold; | ||
631 | return; | ||
632 | } | ||
622 | pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr); | 633 | pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr); |
623 | dev->current_state = (pmcsr & PCI_PM_CTRL_STATE_MASK); | 634 | dev->current_state = (pmcsr & PCI_PM_CTRL_STATE_MASK); |
624 | } else { | 635 | } else { |
@@ -659,8 +670,50 @@ static int pci_platform_power_transition(struct pci_dev *dev, pci_power_t state) | |||
659 | */ | 670 | */ |
660 | static void __pci_start_power_transition(struct pci_dev *dev, pci_power_t state) | 671 | static void __pci_start_power_transition(struct pci_dev *dev, pci_power_t state) |
661 | { | 672 | { |
662 | if (state == PCI_D0) | 673 | if (state == PCI_D0) { |
663 | pci_platform_power_transition(dev, PCI_D0); | 674 | pci_platform_power_transition(dev, PCI_D0); |
675 | /* | ||
676 | * Mandatory power management transition delays, see | ||
677 | * PCI Express Base Specification Revision 2.0 Section | ||
678 | * 6.6.1: Conventional Reset. Do not delay for | ||
679 | * devices powered on/off by corresponding bridge, | ||
680 | * because have already delayed for the bridge. | ||
681 | */ | ||
682 | if (dev->runtime_d3cold) { | ||
683 | msleep(dev->d3cold_delay); | ||
684 | /* | ||
685 | * When powering on a bridge from D3cold, the | ||
686 | * whole hierarchy may be powered on into | ||
687 | * D0uninitialized state, resume them to give | ||
688 | * them a chance to suspend again | ||
689 | */ | ||
690 | pci_wakeup_bus(dev->subordinate); | ||
691 | } | ||
692 | } | ||
693 | } | ||
694 | |||
695 | /** | ||
696 | * __pci_dev_set_current_state - Set current state of a PCI device | ||
697 | * @dev: Device to handle | ||
698 | * @data: pointer to state to be set | ||
699 | */ | ||
700 | static int __pci_dev_set_current_state(struct pci_dev *dev, void *data) | ||
701 | { | ||
702 | pci_power_t state = *(pci_power_t *)data; | ||
703 | |||
704 | dev->current_state = state; | ||
705 | return 0; | ||
706 | } | ||
707 | |||
708 | /** | ||
709 | * __pci_bus_set_current_state - Walk given bus and set current state of devices | ||
710 | * @bus: Top bus of the subtree to walk. | ||
711 | * @state: state to be set | ||
712 | */ | ||
713 | static void __pci_bus_set_current_state(struct pci_bus *bus, pci_power_t state) | ||
714 | { | ||
715 | if (bus) | ||
716 | pci_walk_bus(bus, __pci_dev_set_current_state, &state); | ||
664 | } | 717 | } |
665 | 718 | ||
666 | /** | 719 | /** |
@@ -672,8 +725,15 @@ static void __pci_start_power_transition(struct pci_dev *dev, pci_power_t state) | |||
672 | */ | 725 | */ |
673 | int __pci_complete_power_transition(struct pci_dev *dev, pci_power_t state) | 726 | int __pci_complete_power_transition(struct pci_dev *dev, pci_power_t state) |
674 | { | 727 | { |
675 | return state >= PCI_D0 ? | 728 | int ret; |
676 | pci_platform_power_transition(dev, state) : -EINVAL; | 729 | |
730 | if (state < PCI_D0) | ||
731 | return -EINVAL; | ||
732 | ret = pci_platform_power_transition(dev, state); | ||
733 | /* Power off the bridge may power off the whole hierarchy */ | ||
734 | if (!ret && state == PCI_D3cold) | ||
735 | __pci_bus_set_current_state(dev->subordinate, PCI_D3cold); | ||
736 | return ret; | ||
677 | } | 737 | } |
678 | EXPORT_SYMBOL_GPL(__pci_complete_power_transition); | 738 | EXPORT_SYMBOL_GPL(__pci_complete_power_transition); |
679 | 739 | ||
@@ -697,8 +757,8 @@ int pci_set_power_state(struct pci_dev *dev, pci_power_t state) | |||
697 | int error; | 757 | int error; |
698 | 758 | ||
699 | /* bound the state we're entering */ | 759 | /* bound the state we're entering */ |
700 | if (state > PCI_D3hot) | 760 | if (state > PCI_D3cold) |
701 | state = PCI_D3hot; | 761 | state = PCI_D3cold; |
702 | else if (state < PCI_D0) | 762 | else if (state < PCI_D0) |
703 | state = PCI_D0; | 763 | state = PCI_D0; |
704 | else if ((state == PCI_D1 || state == PCI_D2) && pci_no_d1d2(dev)) | 764 | else if ((state == PCI_D1 || state == PCI_D2) && pci_no_d1d2(dev)) |
@@ -713,10 +773,15 @@ int pci_set_power_state(struct pci_dev *dev, pci_power_t state) | |||
713 | 773 | ||
714 | /* This device is quirked not to be put into D3, so | 774 | /* This device is quirked not to be put into D3, so |
715 | don't put it in D3 */ | 775 | don't put it in D3 */ |
716 | if (state == PCI_D3hot && (dev->dev_flags & PCI_DEV_FLAGS_NO_D3)) | 776 | if (state >= PCI_D3hot && (dev->dev_flags & PCI_DEV_FLAGS_NO_D3)) |
717 | return 0; | 777 | return 0; |
718 | 778 | ||
719 | error = pci_raw_set_power_state(dev, state); | 779 | /* |
780 | * To put device in D3cold, we put device into D3hot in native | ||
781 | * way, then put device into D3cold with platform ops | ||
782 | */ | ||
783 | error = pci_raw_set_power_state(dev, state > PCI_D3hot ? | ||
784 | PCI_D3hot : state); | ||
720 | 785 | ||
721 | if (!__pci_complete_power_transition(dev, state)) | 786 | if (!__pci_complete_power_transition(dev, state)) |
722 | error = 0; | 787 | error = 0; |
@@ -1460,6 +1525,28 @@ void pci_pme_wakeup_bus(struct pci_bus *bus) | |||
1460 | } | 1525 | } |
1461 | 1526 | ||
1462 | /** | 1527 | /** |
1528 | * pci_wakeup - Wake up a PCI device | ||
1529 | * @dev: Device to handle. | ||
1530 | * @ign: ignored parameter | ||
1531 | */ | ||
1532 | static int pci_wakeup(struct pci_dev *pci_dev, void *ign) | ||
1533 | { | ||
1534 | pci_wakeup_event(pci_dev); | ||
1535 | pm_request_resume(&pci_dev->dev); | ||
1536 | return 0; | ||
1537 | } | ||
1538 | |||
1539 | /** | ||
1540 | * pci_wakeup_bus - Walk given bus and wake up devices on it | ||
1541 | * @bus: Top bus of the subtree to walk. | ||
1542 | */ | ||
1543 | void pci_wakeup_bus(struct pci_bus *bus) | ||
1544 | { | ||
1545 | if (bus) | ||
1546 | pci_walk_bus(bus, pci_wakeup, NULL); | ||
1547 | } | ||
1548 | |||
1549 | /** | ||
1463 | * pci_pme_capable - check the capability of PCI device to generate PME# | 1550 | * pci_pme_capable - check the capability of PCI device to generate PME# |
1464 | * @dev: PCI device to handle. | 1551 | * @dev: PCI device to handle. |
1465 | * @state: PCI state from which device will issue PME#. | 1552 | * @state: PCI state from which device will issue PME#. |
@@ -1480,6 +1567,16 @@ static void pci_pme_list_scan(struct work_struct *work) | |||
1480 | if (!list_empty(&pci_pme_list)) { | 1567 | if (!list_empty(&pci_pme_list)) { |
1481 | list_for_each_entry_safe(pme_dev, n, &pci_pme_list, list) { | 1568 | list_for_each_entry_safe(pme_dev, n, &pci_pme_list, list) { |
1482 | if (pme_dev->dev->pme_poll) { | 1569 | if (pme_dev->dev->pme_poll) { |
1570 | struct pci_dev *bridge; | ||
1571 | |||
1572 | bridge = pme_dev->dev->bus->self; | ||
1573 | /* | ||
1574 | * If bridge is in low power state, the | ||
1575 | * configuration space of subordinate devices | ||
1576 | * may be not accessible | ||
1577 | */ | ||
1578 | if (bridge && bridge->current_state != PCI_D0) | ||
1579 | continue; | ||
1483 | pci_pme_wakeup(pme_dev->dev, NULL); | 1580 | pci_pme_wakeup(pme_dev->dev, NULL); |
1484 | } else { | 1581 | } else { |
1485 | list_del(&pme_dev->list); | 1582 | list_del(&pme_dev->list); |
@@ -1706,6 +1803,10 @@ int pci_prepare_to_sleep(struct pci_dev *dev) | |||
1706 | if (target_state == PCI_POWER_ERROR) | 1803 | if (target_state == PCI_POWER_ERROR) |
1707 | return -EIO; | 1804 | return -EIO; |
1708 | 1805 | ||
1806 | /* D3cold during system suspend/hibernate is not supported */ | ||
1807 | if (target_state > PCI_D3hot) | ||
1808 | target_state = PCI_D3hot; | ||
1809 | |||
1709 | pci_enable_wake(dev, target_state, device_may_wakeup(&dev->dev)); | 1810 | pci_enable_wake(dev, target_state, device_may_wakeup(&dev->dev)); |
1710 | 1811 | ||
1711 | error = pci_set_power_state(dev, target_state); | 1812 | error = pci_set_power_state(dev, target_state); |
@@ -1743,12 +1844,16 @@ int pci_finish_runtime_suspend(struct pci_dev *dev) | |||
1743 | if (target_state == PCI_POWER_ERROR) | 1844 | if (target_state == PCI_POWER_ERROR) |
1744 | return -EIO; | 1845 | return -EIO; |
1745 | 1846 | ||
1847 | dev->runtime_d3cold = target_state == PCI_D3cold; | ||
1848 | |||
1746 | __pci_enable_wake(dev, target_state, true, pci_dev_run_wake(dev)); | 1849 | __pci_enable_wake(dev, target_state, true, pci_dev_run_wake(dev)); |
1747 | 1850 | ||
1748 | error = pci_set_power_state(dev, target_state); | 1851 | error = pci_set_power_state(dev, target_state); |
1749 | 1852 | ||
1750 | if (error) | 1853 | if (error) { |
1751 | __pci_enable_wake(dev, target_state, true, false); | 1854 | __pci_enable_wake(dev, target_state, true, false); |
1855 | dev->runtime_d3cold = false; | ||
1856 | } | ||
1752 | 1857 | ||
1753 | return error; | 1858 | return error; |
1754 | } | 1859 | } |
@@ -1818,6 +1923,7 @@ void pci_pm_init(struct pci_dev *dev) | |||
1818 | 1923 | ||
1819 | dev->pm_cap = pm; | 1924 | dev->pm_cap = pm; |
1820 | dev->d3_delay = PCI_PM_D3_WAIT; | 1925 | dev->d3_delay = PCI_PM_D3_WAIT; |
1926 | dev->d3cold_delay = PCI_PM_D3COLD_WAIT; | ||
1821 | 1927 | ||
1822 | dev->d1_support = false; | 1928 | dev->d1_support = false; |
1823 | dev->d2_support = false; | 1929 | dev->d2_support = false; |
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 4884d77d33b6..ec1512de4297 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h | |||
@@ -70,6 +70,7 @@ extern void pci_update_current_state(struct pci_dev *dev, pci_power_t state); | |||
70 | extern void pci_disable_enabled_device(struct pci_dev *dev); | 70 | extern void pci_disable_enabled_device(struct pci_dev *dev); |
71 | extern int pci_finish_runtime_suspend(struct pci_dev *dev); | 71 | extern int pci_finish_runtime_suspend(struct pci_dev *dev); |
72 | extern int __pci_pme_wakeup(struct pci_dev *dev, void *ign); | 72 | extern int __pci_pme_wakeup(struct pci_dev *dev, void *ign); |
73 | extern void pci_wakeup_bus(struct pci_bus *bus); | ||
73 | extern void pci_pm_init(struct pci_dev *dev); | 74 | extern void pci_pm_init(struct pci_dev *dev); |
74 | extern void platform_pci_wakeup_init(struct pci_dev *dev); | 75 | extern void platform_pci_wakeup_init(struct pci_dev *dev); |
75 | extern void pci_allocate_cap_save_buffers(struct pci_dev *dev); | 76 | extern void pci_allocate_cap_save_buffers(struct pci_dev *dev); |
diff --git a/drivers/pci/pcie/portdrv_pci.c b/drivers/pci/pcie/portdrv_pci.c index e0610bda1dea..3a7eefcb270a 100644 --- a/drivers/pci/pcie/portdrv_pci.c +++ b/drivers/pci/pcie/portdrv_pci.c | |||
@@ -11,6 +11,7 @@ | |||
11 | #include <linux/kernel.h> | 11 | #include <linux/kernel.h> |
12 | #include <linux/errno.h> | 12 | #include <linux/errno.h> |
13 | #include <linux/pm.h> | 13 | #include <linux/pm.h> |
14 | #include <linux/pm_runtime.h> | ||
14 | #include <linux/init.h> | 15 | #include <linux/init.h> |
15 | #include <linux/pcieport_if.h> | 16 | #include <linux/pcieport_if.h> |
16 | #include <linux/aer.h> | 17 | #include <linux/aer.h> |
@@ -99,6 +100,51 @@ static int pcie_port_resume_noirq(struct device *dev) | |||
99 | return 0; | 100 | return 0; |
100 | } | 101 | } |
101 | 102 | ||
103 | #ifdef CONFIG_PM_RUNTIME | ||
104 | struct d3cold_info { | ||
105 | bool no_d3cold; | ||
106 | unsigned int d3cold_delay; | ||
107 | }; | ||
108 | |||
109 | static int pci_dev_d3cold_info(struct pci_dev *pdev, void *data) | ||
110 | { | ||
111 | struct d3cold_info *info = data; | ||
112 | |||
113 | info->d3cold_delay = max_t(unsigned int, pdev->d3cold_delay, | ||
114 | info->d3cold_delay); | ||
115 | if (pdev->no_d3cold) | ||
116 | info->no_d3cold = true; | ||
117 | return 0; | ||
118 | } | ||
119 | |||
120 | static int pcie_port_runtime_suspend(struct device *dev) | ||
121 | { | ||
122 | struct pci_dev *pdev = to_pci_dev(dev); | ||
123 | struct d3cold_info d3cold_info = { | ||
124 | .no_d3cold = false, | ||
125 | .d3cold_delay = PCI_PM_D3_WAIT, | ||
126 | }; | ||
127 | |||
128 | /* | ||
129 | * If any subordinate device disable D3cold, we should not put | ||
130 | * the port into D3cold. The D3cold delay of port should be | ||
131 | * the max of that of all subordinate devices. | ||
132 | */ | ||
133 | pci_walk_bus(pdev->subordinate, pci_dev_d3cold_info, &d3cold_info); | ||
134 | pdev->no_d3cold = d3cold_info.no_d3cold; | ||
135 | pdev->d3cold_delay = d3cold_info.d3cold_delay; | ||
136 | return 0; | ||
137 | } | ||
138 | |||
139 | static int pcie_port_runtime_resume(struct device *dev) | ||
140 | { | ||
141 | return 0; | ||
142 | } | ||
143 | #else | ||
144 | #define pcie_port_runtime_suspend NULL | ||
145 | #define pcie_port_runtime_resume NULL | ||
146 | #endif | ||
147 | |||
102 | static const struct dev_pm_ops pcie_portdrv_pm_ops = { | 148 | static const struct dev_pm_ops pcie_portdrv_pm_ops = { |
103 | .suspend = pcie_port_device_suspend, | 149 | .suspend = pcie_port_device_suspend, |
104 | .resume = pcie_port_device_resume, | 150 | .resume = pcie_port_device_resume, |
@@ -107,6 +153,8 @@ static const struct dev_pm_ops pcie_portdrv_pm_ops = { | |||
107 | .poweroff = pcie_port_device_suspend, | 153 | .poweroff = pcie_port_device_suspend, |
108 | .restore = pcie_port_device_resume, | 154 | .restore = pcie_port_device_resume, |
109 | .resume_noirq = pcie_port_resume_noirq, | 155 | .resume_noirq = pcie_port_resume_noirq, |
156 | .runtime_suspend = pcie_port_runtime_suspend, | ||
157 | .runtime_resume = pcie_port_runtime_resume, | ||
110 | }; | 158 | }; |
111 | 159 | ||
112 | #define PCIE_PORTDRV_PM_OPS (&pcie_portdrv_pm_ops) | 160 | #define PCIE_PORTDRV_PM_OPS (&pcie_portdrv_pm_ops) |
@@ -117,6 +165,14 @@ static const struct dev_pm_ops pcie_portdrv_pm_ops = { | |||
117 | #endif /* !PM */ | 165 | #endif /* !PM */ |
118 | 166 | ||
119 | /* | 167 | /* |
168 | * PCIe port runtime suspend is broken for some chipsets, so use a | ||
169 | * black list to disable runtime PM for these chipsets. | ||
170 | */ | ||
171 | static const struct pci_device_id port_runtime_pm_black_list[] = { | ||
172 | { /* end: all zeroes */ } | ||
173 | }; | ||
174 | |||
175 | /* | ||
120 | * pcie_portdrv_probe - Probe PCI-Express port devices | 176 | * pcie_portdrv_probe - Probe PCI-Express port devices |
121 | * @dev: PCI-Express port device being probed | 177 | * @dev: PCI-Express port device being probed |
122 | * | 178 | * |
@@ -144,12 +200,16 @@ static int __devinit pcie_portdrv_probe(struct pci_dev *dev, | |||
144 | return status; | 200 | return status; |
145 | 201 | ||
146 | pci_save_state(dev); | 202 | pci_save_state(dev); |
203 | if (!pci_match_id(port_runtime_pm_black_list, dev)) | ||
204 | pm_runtime_put_noidle(&dev->dev); | ||
147 | 205 | ||
148 | return 0; | 206 | return 0; |
149 | } | 207 | } |
150 | 208 | ||
151 | static void pcie_portdrv_remove(struct pci_dev *dev) | 209 | static void pcie_portdrv_remove(struct pci_dev *dev) |
152 | { | 210 | { |
211 | if (!pci_match_id(port_runtime_pm_black_list, dev)) | ||
212 | pm_runtime_get_noresume(&dev->dev); | ||
153 | pcie_port_device_remove(dev); | 213 | pcie_port_device_remove(dev); |
154 | pci_disable_device(dev); | 214 | pci_disable_device(dev); |
155 | } | 215 | } |
diff --git a/drivers/pnp/pnpacpi/core.c b/drivers/pnp/pnpacpi/core.c index d21e8f59c84e..507a8e2b9a4c 100644 --- a/drivers/pnp/pnpacpi/core.c +++ b/drivers/pnp/pnpacpi/core.c | |||
@@ -170,8 +170,8 @@ static int pnpacpi_suspend(struct pnp_dev *dev, pm_message_t state) | |||
170 | } | 170 | } |
171 | 171 | ||
172 | if (acpi_bus_power_manageable(handle)) { | 172 | if (acpi_bus_power_manageable(handle)) { |
173 | int power_state = acpi_pm_device_sleep_state(&dev->dev, NULL); | 173 | int power_state = acpi_pm_device_sleep_state(&dev->dev, NULL, |
174 | 174 | ACPI_STATE_D3); | |
175 | if (power_state < 0) | 175 | if (power_state < 0) |
176 | power_state = (state.event == PM_EVENT_ON) ? | 176 | power_state = (state.event == PM_EVENT_ON) ? |
177 | ACPI_STATE_D0 : ACPI_STATE_D3; | 177 | ACPI_STATE_D0 : ACPI_STATE_D3; |
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h index 457974073994..6a6c46e84ae3 100644 --- a/include/acpi/acpi_bus.h +++ b/include/acpi/acpi_bus.h | |||
@@ -415,13 +415,13 @@ int acpi_enable_wakeup_device_power(struct acpi_device *dev, int state); | |||
415 | int acpi_disable_wakeup_device_power(struct acpi_device *dev); | 415 | int acpi_disable_wakeup_device_power(struct acpi_device *dev); |
416 | 416 | ||
417 | #ifdef CONFIG_PM | 417 | #ifdef CONFIG_PM |
418 | int acpi_pm_device_sleep_state(struct device *, int *); | 418 | int acpi_pm_device_sleep_state(struct device *, int *, int); |
419 | #else | 419 | #else |
420 | static inline int acpi_pm_device_sleep_state(struct device *d, int *p) | 420 | static inline int acpi_pm_device_sleep_state(struct device *d, int *p, int m) |
421 | { | 421 | { |
422 | if (p) | 422 | if (p) |
423 | *p = ACPI_STATE_D0; | 423 | *p = ACPI_STATE_D0; |
424 | return ACPI_STATE_D3; | 424 | return (m >= ACPI_STATE_D0 && m <= ACPI_STATE_D3) ? m : ACPI_STATE_D0; |
425 | } | 425 | } |
426 | #endif | 426 | #endif |
427 | 427 | ||
diff --git a/include/linux/pci.h b/include/linux/pci.h index c739df91bac9..0769aa409085 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h | |||
@@ -132,9 +132,10 @@ static inline const char *pci_power_name(pci_power_t state) | |||
132 | return pci_power_names[1 + (int) state]; | 132 | return pci_power_names[1 + (int) state]; |
133 | } | 133 | } |
134 | 134 | ||
135 | #define PCI_PM_D2_DELAY 200 | 135 | #define PCI_PM_D2_DELAY 200 |
136 | #define PCI_PM_D3_WAIT 10 | 136 | #define PCI_PM_D3_WAIT 10 |
137 | #define PCI_PM_BUS_WAIT 50 | 137 | #define PCI_PM_D3COLD_WAIT 100 |
138 | #define PCI_PM_BUS_WAIT 50 | ||
138 | 139 | ||
139 | /** The pci_channel state describes connectivity between the CPU and | 140 | /** The pci_channel state describes connectivity between the CPU and |
140 | * the pci device. If some PCI bus between here and the pci device | 141 | * the pci device. If some PCI bus between here and the pci device |
@@ -278,11 +279,18 @@ struct pci_dev { | |||
278 | unsigned int pme_poll:1; /* Poll device's PME status bit */ | 279 | unsigned int pme_poll:1; /* Poll device's PME status bit */ |
279 | unsigned int d1_support:1; /* Low power state D1 is supported */ | 280 | unsigned int d1_support:1; /* Low power state D1 is supported */ |
280 | unsigned int d2_support:1; /* Low power state D2 is supported */ | 281 | unsigned int d2_support:1; /* Low power state D2 is supported */ |
281 | unsigned int no_d1d2:1; /* Only allow D0 and D3 */ | 282 | unsigned int no_d1d2:1; /* D1 and D2 are forbidden */ |
283 | unsigned int no_d3cold:1; /* D3cold is forbidden */ | ||
284 | unsigned int d3cold_allowed:1; /* D3cold is allowed by user */ | ||
282 | unsigned int mmio_always_on:1; /* disallow turning off io/mem | 285 | unsigned int mmio_always_on:1; /* disallow turning off io/mem |
283 | decoding during bar sizing */ | 286 | decoding during bar sizing */ |
284 | unsigned int wakeup_prepared:1; | 287 | unsigned int wakeup_prepared:1; |
288 | unsigned int runtime_d3cold:1; /* whether go through runtime | ||
289 | D3cold, not set for devices | ||
290 | powered on/off by the | ||
291 | corresponding bridge */ | ||
285 | unsigned int d3_delay; /* D3->D0 transition time in ms */ | 292 | unsigned int d3_delay; /* D3->D0 transition time in ms */ |
293 | unsigned int d3cold_delay; /* D3cold->D0 transition time in ms */ | ||
286 | 294 | ||
287 | #ifdef CONFIG_PCIEASPM | 295 | #ifdef CONFIG_PCIEASPM |
288 | struct pcie_link_state *link_state; /* ASPM link state. */ | 296 | struct pcie_link_state *link_state; /* ASPM link state. */ |