PM / sleep: Use valid_state() for platform-dependent sleep states only
Use the observation that, for platform-dependent sleep states (PM_SUSPEND_STANDBY, PM_SUSPEND_MEM), a given state is either always supported or always unsupported and store that information in pm_states[] instead of calling valid_state() every time we need to check it. Also do not use valid_state() for PM_SUSPEND_FREEZE, which is always valid, and move the pm_test_level validity check for PM_SUSPEND_FREEZE directly into enter_state(). Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
This commit is contained in:
parent
27ddcc6596
commit
43e8317b0b
|
@ -296,7 +296,7 @@ static ssize_t state_show(struct kobject *kobj, struct kobj_attribute *attr,
|
||||||
suspend_state_t i;
|
suspend_state_t i;
|
||||||
|
|
||||||
for (i = PM_SUSPEND_MIN; i < PM_SUSPEND_MAX; i++)
|
for (i = PM_SUSPEND_MIN; i < PM_SUSPEND_MAX; i++)
|
||||||
if (valid_state(i))
|
if (pm_states[i].state)
|
||||||
s += sprintf(s,"%s ", pm_states[i].label);
|
s += sprintf(s,"%s ", pm_states[i].label);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -328,8 +328,9 @@ static suspend_state_t decode_state(const char *buf, size_t n)
|
||||||
|
|
||||||
#ifdef CONFIG_SUSPEND
|
#ifdef CONFIG_SUSPEND
|
||||||
for (s = &pm_states[state]; state < PM_SUSPEND_MAX; s++, state++)
|
for (s = &pm_states[state]; state < PM_SUSPEND_MAX; s++, state++)
|
||||||
if (len == strlen(s->label) && !strncmp(buf, s->label, len))
|
if (s->state && len == strlen(s->label)
|
||||||
return state;
|
&& !strncmp(buf, s->label, len))
|
||||||
|
return s->state;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return PM_SUSPEND_ON;
|
return PM_SUSPEND_ON;
|
||||||
|
@ -447,7 +448,7 @@ static ssize_t autosleep_show(struct kobject *kobj,
|
||||||
|
|
||||||
#ifdef CONFIG_SUSPEND
|
#ifdef CONFIG_SUSPEND
|
||||||
if (state < PM_SUSPEND_MAX)
|
if (state < PM_SUSPEND_MAX)
|
||||||
return sprintf(buf, "%s\n", valid_state(state) ?
|
return sprintf(buf, "%s\n", pm_states[state].state ?
|
||||||
pm_states[state].label : "error");
|
pm_states[state].label : "error");
|
||||||
#endif
|
#endif
|
||||||
#ifdef CONFIG_HIBERNATION
|
#ifdef CONFIG_HIBERNATION
|
||||||
|
|
|
@ -186,14 +186,12 @@ struct pm_sleep_state {
|
||||||
/* kernel/power/suspend.c */
|
/* kernel/power/suspend.c */
|
||||||
extern struct pm_sleep_state pm_states[];
|
extern struct pm_sleep_state pm_states[];
|
||||||
|
|
||||||
extern bool valid_state(suspend_state_t state);
|
|
||||||
extern int suspend_devices_and_enter(suspend_state_t state);
|
extern int suspend_devices_and_enter(suspend_state_t state);
|
||||||
#else /* !CONFIG_SUSPEND */
|
#else /* !CONFIG_SUSPEND */
|
||||||
static inline int suspend_devices_and_enter(suspend_state_t state)
|
static inline int suspend_devices_and_enter(suspend_state_t state)
|
||||||
{
|
{
|
||||||
return -ENOSYS;
|
return -ENOSYS;
|
||||||
}
|
}
|
||||||
static inline bool valid_state(suspend_state_t state) { return false; }
|
|
||||||
#endif /* !CONFIG_SUSPEND */
|
#endif /* !CONFIG_SUSPEND */
|
||||||
|
|
||||||
#ifdef CONFIG_PM_TEST_SUSPEND
|
#ifdef CONFIG_PM_TEST_SUSPEND
|
||||||
|
|
|
@ -32,9 +32,9 @@
|
||||||
#include "power.h"
|
#include "power.h"
|
||||||
|
|
||||||
struct pm_sleep_state pm_states[PM_SUSPEND_MAX] = {
|
struct pm_sleep_state pm_states[PM_SUSPEND_MAX] = {
|
||||||
[PM_SUSPEND_FREEZE] = { "freeze", PM_SUSPEND_FREEZE },
|
[PM_SUSPEND_FREEZE] = { .label = "freeze", .state = PM_SUSPEND_FREEZE },
|
||||||
[PM_SUSPEND_STANDBY] = { "standby", PM_SUSPEND_STANDBY },
|
[PM_SUSPEND_STANDBY] = { .label = "standby", },
|
||||||
[PM_SUSPEND_MEM] = { "mem", PM_SUSPEND_MEM },
|
[PM_SUSPEND_MEM] = { .label = "mem", },
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct platform_suspend_ops *suspend_ops;
|
static const struct platform_suspend_ops *suspend_ops;
|
||||||
|
@ -68,42 +68,34 @@ void freeze_wake(void)
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(freeze_wake);
|
EXPORT_SYMBOL_GPL(freeze_wake);
|
||||||
|
|
||||||
|
static bool valid_state(suspend_state_t state)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* PM_SUSPEND_STANDBY and PM_SUSPEND_MEM states need low level
|
||||||
|
* support and need to be valid to the low level
|
||||||
|
* implementation, no valid callback implies that none are valid.
|
||||||
|
*/
|
||||||
|
return suspend_ops && suspend_ops->valid && suspend_ops->valid(state);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* suspend_set_ops - Set the global suspend method table.
|
* suspend_set_ops - Set the global suspend method table.
|
||||||
* @ops: Suspend operations to use.
|
* @ops: Suspend operations to use.
|
||||||
*/
|
*/
|
||||||
void suspend_set_ops(const struct platform_suspend_ops *ops)
|
void suspend_set_ops(const struct platform_suspend_ops *ops)
|
||||||
{
|
{
|
||||||
|
suspend_state_t i;
|
||||||
|
|
||||||
lock_system_sleep();
|
lock_system_sleep();
|
||||||
|
|
||||||
suspend_ops = ops;
|
suspend_ops = ops;
|
||||||
|
for (i = PM_SUSPEND_STANDBY; i <= PM_SUSPEND_MEM; i++)
|
||||||
|
pm_states[i].state = valid_state(i) ? i : 0;
|
||||||
|
|
||||||
unlock_system_sleep();
|
unlock_system_sleep();
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(suspend_set_ops);
|
EXPORT_SYMBOL_GPL(suspend_set_ops);
|
||||||
|
|
||||||
bool valid_state(suspend_state_t state)
|
|
||||||
{
|
|
||||||
if (state == PM_SUSPEND_FREEZE) {
|
|
||||||
#ifdef CONFIG_PM_DEBUG
|
|
||||||
if (pm_test_level != TEST_NONE &&
|
|
||||||
pm_test_level != TEST_FREEZER &&
|
|
||||||
pm_test_level != TEST_DEVICES &&
|
|
||||||
pm_test_level != TEST_PLATFORM) {
|
|
||||||
printk(KERN_WARNING "Unsupported pm_test mode for "
|
|
||||||
"freeze state, please choose "
|
|
||||||
"none/freezer/devices/platform.\n");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* PM_SUSPEND_STANDBY and PM_SUSPEND_MEMORY states need lowlevel
|
|
||||||
* support and need to be valid to the lowlevel
|
|
||||||
* implementation, no valid callback implies that none are valid.
|
|
||||||
*/
|
|
||||||
return suspend_ops && suspend_ops->valid && suspend_ops->valid(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* suspend_valid_only_mem - Generic memory-only valid callback.
|
* suspend_valid_only_mem - Generic memory-only valid callback.
|
||||||
*
|
*
|
||||||
|
@ -330,9 +322,17 @@ static int enter_state(suspend_state_t state)
|
||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
if (!valid_state(state))
|
if (state == PM_SUSPEND_FREEZE) {
|
||||||
return -ENODEV;
|
#ifdef CONFIG_PM_DEBUG
|
||||||
|
if (pm_test_level != TEST_NONE && pm_test_level <= TEST_CPUS) {
|
||||||
|
pr_warning("PM: Unsupported test mode for freeze state,"
|
||||||
|
"please choose none/freezer/devices/platform.\n");
|
||||||
|
return -EAGAIN;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
} else if (!valid_state(state)) {
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
if (!mutex_trylock(&pm_mutex))
|
if (!mutex_trylock(&pm_mutex))
|
||||||
return -EBUSY;
|
return -EBUSY;
|
||||||
|
|
||||||
|
|
|
@ -162,7 +162,7 @@ static int __init test_suspend(void)
|
||||||
/* PM is initialized by now; is that state testable? */
|
/* PM is initialized by now; is that state testable? */
|
||||||
if (test_state == PM_SUSPEND_ON)
|
if (test_state == PM_SUSPEND_ON)
|
||||||
goto done;
|
goto done;
|
||||||
if (!valid_state(test_state)) {
|
if (!pm_states[test_state].state) {
|
||||||
printk(warn_bad_state, pm_states[test_state].label);
|
printk(warn_bad_state, pm_states[test_state].label);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue