aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>2012-11-01 20:40:18 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2012-11-14 18:15:16 -0500
commit86b3832c64b6d01092216d84dc6a6b300875d0bb (patch)
tree3d990b5bee64a33159a3cfef7712949176832f6f
parentec2cd81ccfc055155ef4ca673f207168f516d287 (diff)
ACPI / PM: Move device power state selection routine to device_pm.c
The ACPI function for choosing device power state is now located in drivers/acpi/sleep.c, but drivers/acpi/device_pm.c is a more logical place for it, so move it there. However, instead of moving the function entirely, move its core only under a different name and with a different list of arguments, so that it is more flexible, and leave a wrapper around it in the original location. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
-rw-r--r--drivers/acpi/device_pm.c107
-rw-r--r--drivers/acpi/sleep.c88
-rw-r--r--include/acpi/acpi_bus.h15
3 files changed, 124 insertions, 86 deletions
diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c
index 2d2e0bc8891b..c017b801171c 100644
--- a/drivers/acpi/device_pm.c
+++ b/drivers/acpi/device_pm.c
@@ -23,7 +23,9 @@
23 */ 23 */
24 24
25#include <linux/device.h> 25#include <linux/device.h>
26#include <linux/export.h>
26#include <linux/mutex.h> 27#include <linux/mutex.h>
28#include <linux/pm_qos.h>
27 29
28#include <acpi/acpi.h> 30#include <acpi/acpi.h>
29#include <acpi/acpi_bus.h> 31#include <acpi/acpi_bus.h>
@@ -89,3 +91,108 @@ acpi_status acpi_remove_pm_notifier(struct acpi_device *adev,
89 mutex_unlock(&acpi_pm_notifier_lock); 91 mutex_unlock(&acpi_pm_notifier_lock);
90 return status; 92 return status;
91} 93}
94
95/**
96 * acpi_device_power_state - Get preferred power state of ACPI device.
97 * @dev: Device whose preferred target power state to return.
98 * @adev: ACPI device node corresponding to @dev.
99 * @target_state: System state to match the resultant device state.
100 * @d_max_in: Deepest low-power state to take into consideration.
101 * @d_min_p: Location to store the upper limit of the allowed states range.
102 * Return value: Preferred power state of the device on success, -ENODEV
103 * (if there's no 'struct acpi_device' for @dev) or -EINVAL on failure
104 *
105 * Find the lowest power (highest number) ACPI device power state that the
106 * device can be in while the system is in the state represented by
107 * @target_state. If @d_min_p is set, the highest power (lowest number) device
108 * power state that @dev can be in for the given system sleep state is stored
109 * at the location pointed to by it.
110 *
111 * Callers must ensure that @dev and @adev are valid pointers and that @adev
112 * actually corresponds to @dev before using this function.
113 */
114int acpi_device_power_state(struct device *dev, struct acpi_device *adev,
115 u32 target_state, int d_max_in, int *d_min_p)
116{
117 char acpi_method[] = "_SxD";
118 unsigned long long d_min, d_max;
119 bool wakeup = false;
120
121 if (d_max_in < ACPI_STATE_D0 || d_max_in > ACPI_STATE_D3)
122 return -EINVAL;
123
124 if (d_max_in > ACPI_STATE_D3_HOT) {
125 enum pm_qos_flags_status stat;
126
127 stat = dev_pm_qos_flags(dev, PM_QOS_FLAG_NO_POWER_OFF);
128 if (stat == PM_QOS_FLAGS_ALL)
129 d_max_in = ACPI_STATE_D3_HOT;
130 }
131
132 acpi_method[2] = '0' + target_state;
133 /*
134 * If the sleep state is S0, the lowest limit from ACPI is D3,
135 * but if the device has _S0W, we will use the value from _S0W
136 * as the lowest limit from ACPI. Finally, we will constrain
137 * the lowest limit with the specified one.
138 */
139 d_min = ACPI_STATE_D0;
140 d_max = ACPI_STATE_D3;
141
142 /*
143 * If present, _SxD methods return the minimum D-state (highest power
144 * state) we can use for the corresponding S-states. Otherwise, the
145 * minimum D-state is D0 (ACPI 3.x).
146 *
147 * NOTE: We rely on acpi_evaluate_integer() not clobbering the integer
148 * provided -- that's our fault recovery, we ignore retval.
149 */
150 if (target_state > ACPI_STATE_S0) {
151 acpi_evaluate_integer(adev->handle, acpi_method, NULL, &d_min);
152 wakeup = device_may_wakeup(dev) && adev->wakeup.flags.valid
153 && adev->wakeup.sleep_state >= target_state;
154 } else if (dev_pm_qos_flags(dev, PM_QOS_FLAG_REMOTE_WAKEUP) !=
155 PM_QOS_FLAGS_NONE) {
156 wakeup = adev->wakeup.flags.valid;
157 }
158
159 /*
160 * If _PRW says we can wake up the system from the target sleep state,
161 * the D-state returned by _SxD is sufficient for that (we assume a
162 * wakeup-aware driver if wake is set). Still, if _SxW exists
163 * (ACPI 3.x), it should return the maximum (lowest power) D-state that
164 * can wake the system. _S0W may be valid, too.
165 */
166 if (wakeup) {
167 acpi_status status;
168
169 acpi_method[3] = 'W';
170 status = acpi_evaluate_integer(adev->handle, acpi_method, NULL,
171 &d_max);
172 if (ACPI_FAILURE(status)) {
173 if (target_state != ACPI_STATE_S0 ||
174 status != AE_NOT_FOUND)
175 d_max = d_min;
176 } else if (d_max < d_min) {
177 /* Warn the user of the broken DSDT */
178 printk(KERN_WARNING "ACPI: Wrong value from %s\n",
179 acpi_method);
180 /* Sanitize it */
181 d_min = d_max;
182 }
183 }
184
185 if (d_max_in < d_min)
186 return -EINVAL;
187 if (d_min_p)
188 *d_min_p = d_min;
189 /* constrain d_max with specified lowest limit (max number) */
190 if (d_max > d_max_in) {
191 for (d_max = d_max_in; d_max > d_min; d_max--) {
192 if (adev->power.states[d_max].flags.valid)
193 break;
194 }
195 }
196 return d_max;
197}
198EXPORT_SYMBOL_GPL(acpi_device_power_state);
diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
index 4defa0297ee4..fa20d0171887 100644
--- a/drivers/acpi/sleep.c
+++ b/drivers/acpi/sleep.c
@@ -19,7 +19,6 @@
19#include <linux/acpi.h> 19#include <linux/acpi.h>
20#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/pm_runtime.h> 21#include <linux/pm_runtime.h>
22#include <linux/pm_qos.h>
23 22
24#include <asm/io.h> 23#include <asm/io.h>
25 24
@@ -691,101 +690,20 @@ int acpi_suspend(u32 acpi_state)
691 * Return value: Preferred power state of the device on success, -ENODEV 690 * Return value: Preferred power state of the device on success, -ENODEV
692 * (if there's no 'struct acpi_device' for @dev) or -EINVAL on failure 691 * (if there's no 'struct acpi_device' for @dev) or -EINVAL on failure
693 * 692 *
694 * Find the lowest power (highest number) ACPI device power state that the
695 * device can be in while the system is in the sleep state represented
696 * by %acpi_target_sleep_state. If @d_min_p is set, the highest power (lowest
697 * number) device power state that @dev can be in for the given system sleep
698 * state is stored at the location pointed to by it.
699 *
700 * The caller must ensure that @dev is valid before using this function. 693 * The caller must ensure that @dev is valid before using this function.
701 */ 694 */
702int acpi_pm_device_sleep_state(struct device *dev, int *d_min_p, int d_max_in) 695int acpi_pm_device_sleep_state(struct device *dev, int *d_min_p, int d_max_in)
703{ 696{
704 acpi_handle handle = DEVICE_ACPI_HANDLE(dev); 697 acpi_handle handle = DEVICE_ACPI_HANDLE(dev);
705 struct acpi_device *adev; 698 struct acpi_device *adev;
706 char acpi_method[] = "_SxD";
707 unsigned long long d_min, d_max;
708 bool wakeup = false;
709 699
710 if (d_max_in < ACPI_STATE_D0 || d_max_in > ACPI_STATE_D3)
711 return -EINVAL;
712 if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &adev))) { 700 if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &adev))) {
713 printk(KERN_DEBUG "ACPI handle has no context!\n"); 701 dev_dbg(dev, "ACPI handle without context in %s!\n", __func__);
714 return -ENODEV; 702 return -ENODEV;
715 } 703 }
716 if (d_max_in > ACPI_STATE_D3_HOT) {
717 enum pm_qos_flags_status stat;
718
719 stat = dev_pm_qos_flags(dev, PM_QOS_FLAG_NO_POWER_OFF);
720 if (stat == PM_QOS_FLAGS_ALL)
721 d_max_in = ACPI_STATE_D3_HOT;
722 }
723
724 acpi_method[2] = '0' + acpi_target_sleep_state;
725 /*
726 * If the sleep state is S0, the lowest limit from ACPI is D3,
727 * but if the device has _S0W, we will use the value from _S0W
728 * as the lowest limit from ACPI. Finally, we will constrain
729 * the lowest limit with the specified one.
730 */
731 d_min = ACPI_STATE_D0;
732 d_max = ACPI_STATE_D3;
733
734 /*
735 * If present, _SxD methods return the minimum D-state (highest power
736 * state) we can use for the corresponding S-states. Otherwise, the
737 * minimum D-state is D0 (ACPI 3.x).
738 *
739 * NOTE: We rely on acpi_evaluate_integer() not clobbering the integer
740 * provided -- that's our fault recovery, we ignore retval.
741 */
742 if (acpi_target_sleep_state > ACPI_STATE_S0) {
743 acpi_evaluate_integer(handle, acpi_method, NULL, &d_min);
744 wakeup = device_may_wakeup(dev) && adev->wakeup.flags.valid
745 && adev->wakeup.sleep_state >= acpi_target_sleep_state;
746 } else if (dev_pm_qos_flags(dev, PM_QOS_FLAG_REMOTE_WAKEUP) !=
747 PM_QOS_FLAGS_NONE) {
748 wakeup = adev->wakeup.flags.valid;
749 }
750
751 /*
752 * If _PRW says we can wake up the system from the target sleep state,
753 * the D-state returned by _SxD is sufficient for that (we assume a
754 * wakeup-aware driver if wake is set). Still, if _SxW exists
755 * (ACPI 3.x), it should return the maximum (lowest power) D-state that
756 * can wake the system. _S0W may be valid, too.
757 */
758 if (wakeup) {
759 acpi_status status;
760
761 acpi_method[3] = 'W';
762 status = acpi_evaluate_integer(handle, acpi_method, NULL,
763 &d_max);
764 if (ACPI_FAILURE(status)) {
765 if (acpi_target_sleep_state != ACPI_STATE_S0 ||
766 status != AE_NOT_FOUND)
767 d_max = d_min;
768 } else if (d_max < d_min) {
769 /* Warn the user of the broken DSDT */
770 printk(KERN_WARNING "ACPI: Wrong value from %s\n",
771 acpi_method);
772 /* Sanitize it */
773 d_min = d_max;
774 }
775 }
776 704
777 if (d_max_in < d_min) 705 return acpi_device_power_state(dev, adev, acpi_target_sleep_state,
778 return -EINVAL; 706 d_max_in, d_min_p);
779 if (d_min_p)
780 *d_min_p = d_min;
781 /* constrain d_max with specified lowest limit (max number) */
782 if (d_max > d_max_in) {
783 for (d_max = d_max_in; d_max > d_min; d_max--) {
784 if (adev->power.states[d_max].flags.valid)
785 break;
786 }
787 }
788 return d_max;
789} 707}
790EXPORT_SYMBOL(acpi_pm_device_sleep_state); 708EXPORT_SYMBOL(acpi_pm_device_sleep_state);
791#endif /* CONFIG_PM */ 709#endif /* CONFIG_PM */
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index 6983272f9d02..a8080dfe7183 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -420,6 +420,8 @@ acpi_status acpi_add_pm_notifier(struct acpi_device *adev,
420 acpi_notify_handler handler, void *context); 420 acpi_notify_handler handler, void *context);
421acpi_status acpi_remove_pm_notifier(struct acpi_device *adev, 421acpi_status acpi_remove_pm_notifier(struct acpi_device *adev,
422 acpi_notify_handler handler); 422 acpi_notify_handler handler);
423int acpi_device_power_state(struct device *dev, struct acpi_device *adev,
424 u32 target_state, int d_max_in, int *d_min_p);
423int acpi_pm_device_sleep_state(struct device *, int *, int); 425int acpi_pm_device_sleep_state(struct device *, int *, int);
424#else 426#else
425static inline acpi_status acpi_add_pm_notifier(struct acpi_device *adev, 427static inline acpi_status acpi_add_pm_notifier(struct acpi_device *adev,
@@ -433,12 +435,23 @@ static inline acpi_status acpi_remove_pm_notifier(struct acpi_device *adev,
433{ 435{
434 return AE_SUPPORT; 436 return AE_SUPPORT;
435} 437}
436static inline int acpi_pm_device_sleep_state(struct device *d, int *p, int m) 438static inline int __acpi_device_power_state(int m, int *p)
437{ 439{
438 if (p) 440 if (p)
439 *p = ACPI_STATE_D0; 441 *p = ACPI_STATE_D0;
440 return (m >= ACPI_STATE_D0 && m <= ACPI_STATE_D3) ? m : ACPI_STATE_D0; 442 return (m >= ACPI_STATE_D0 && m <= ACPI_STATE_D3) ? m : ACPI_STATE_D0;
441} 443}
444static inline int acpi_device_power_state(struct device *dev,
445 struct acpi_device *adev,
446 u32 target_state, int d_max_in,
447 int *d_min_p)
448{
449 return __acpi_device_power_state(d_max_in, d_min_p);
450}
451static inline int acpi_pm_device_sleep_state(struct device *d, int *p, int m)
452{
453 return __acpi_device_power_state(m, p);
454}
442#endif 455#endif
443 456
444#ifdef CONFIG_PM_RUNTIME 457#ifdef CONFIG_PM_RUNTIME