PM / sleep: Add state field to pm_states[] entries

To allow sleep states corresponding to the "mem", "standby" and
"freeze" lables to be different from the pm_states[] indexes of
those strings, introduce struct pm_sleep_state, consisting of
a string label and a state number, and turn pm_states[] into an
array of objects of that type.

This modification should not lead to any functional changes.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
This commit is contained in:
Rafael J. Wysocki 2014-05-26 13:40:47 +02:00
parent f71495f3f0
commit 27ddcc6596
4 changed files with 30 additions and 27 deletions

View File

@ -293,12 +293,12 @@ static ssize_t state_show(struct kobject *kobj, struct kobj_attribute *attr,
{ {
char *s = buf; char *s = buf;
#ifdef CONFIG_SUSPEND #ifdef CONFIG_SUSPEND
int i; suspend_state_t i;
for (i = PM_SUSPEND_MIN; i < PM_SUSPEND_MAX; i++)
if (valid_state(i))
s += sprintf(s,"%s ", pm_states[i].label);
for (i = 0; i < PM_SUSPEND_MAX; i++) {
if (pm_states[i] && valid_state(i))
s += sprintf(s,"%s ", pm_states[i]);
}
#endif #endif
#ifdef CONFIG_HIBERNATION #ifdef CONFIG_HIBERNATION
s += sprintf(s, "%s\n", "disk"); s += sprintf(s, "%s\n", "disk");
@ -314,7 +314,7 @@ static suspend_state_t decode_state(const char *buf, size_t n)
{ {
#ifdef CONFIG_SUSPEND #ifdef CONFIG_SUSPEND
suspend_state_t state = PM_SUSPEND_MIN; suspend_state_t state = PM_SUSPEND_MIN;
const char * const *s; struct pm_sleep_state *s;
#endif #endif
char *p; char *p;
int len; int len;
@ -328,7 +328,7 @@ 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 (*s && len == strlen(*s) && !strncmp(buf, *s, len)) if (len == strlen(s->label) && !strncmp(buf, s->label, len))
return state; return state;
#endif #endif
@ -448,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", valid_state(state) ?
pm_states[state] : "error"); pm_states[state].label : "error");
#endif #endif
#ifdef CONFIG_HIBERNATION #ifdef CONFIG_HIBERNATION
return sprintf(buf, "disk\n"); return sprintf(buf, "disk\n");

View File

@ -178,8 +178,13 @@ extern void swsusp_show_speed(struct timeval *, struct timeval *,
unsigned int, char *); unsigned int, char *);
#ifdef CONFIG_SUSPEND #ifdef CONFIG_SUSPEND
struct pm_sleep_state {
const char *label;
suspend_state_t state;
};
/* kernel/power/suspend.c */ /* kernel/power/suspend.c */
extern const char *const pm_states[]; extern struct pm_sleep_state pm_states[];
extern bool valid_state(suspend_state_t state); 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);

View File

@ -31,10 +31,10 @@
#include "power.h" #include "power.h"
const char *const pm_states[PM_SUSPEND_MAX] = { struct pm_sleep_state pm_states[PM_SUSPEND_MAX] = {
[PM_SUSPEND_FREEZE] = "freeze", [PM_SUSPEND_FREEZE] = { "freeze", PM_SUSPEND_FREEZE },
[PM_SUSPEND_STANDBY] = "standby", [PM_SUSPEND_STANDBY] = { "standby", PM_SUSPEND_STANDBY },
[PM_SUSPEND_MEM] = "mem", [PM_SUSPEND_MEM] = { "mem", PM_SUSPEND_MEM },
}; };
static const struct platform_suspend_ops *suspend_ops; static const struct platform_suspend_ops *suspend_ops;
@ -343,7 +343,7 @@ static int enter_state(suspend_state_t state)
sys_sync(); sys_sync();
printk("done.\n"); printk("done.\n");
pr_debug("PM: Preparing system for %s sleep\n", pm_states[state]); pr_debug("PM: Preparing system for %s sleep\n", pm_states[state].label);
error = suspend_prepare(state); error = suspend_prepare(state);
if (error) if (error)
goto Unlock; goto Unlock;
@ -351,7 +351,7 @@ static int enter_state(suspend_state_t state)
if (suspend_test(TEST_FREEZER)) if (suspend_test(TEST_FREEZER))
goto Finish; goto Finish;
pr_debug("PM: Entering %s sleep\n", pm_states[state]); pr_debug("PM: Entering %s sleep\n", pm_states[state].label);
pm_restrict_gfp_mask(); pm_restrict_gfp_mask();
error = suspend_devices_and_enter(state); error = suspend_devices_and_enter(state);
pm_restore_gfp_mask(); pm_restore_gfp_mask();

View File

@ -92,13 +92,13 @@ static void __init test_wakealarm(struct rtc_device *rtc, suspend_state_t state)
} }
if (state == PM_SUSPEND_MEM) { if (state == PM_SUSPEND_MEM) {
printk(info_test, pm_states[state]); printk(info_test, pm_states[state].label);
status = pm_suspend(state); status = pm_suspend(state);
if (status == -ENODEV) if (status == -ENODEV)
state = PM_SUSPEND_STANDBY; state = PM_SUSPEND_STANDBY;
} }
if (state == PM_SUSPEND_STANDBY) { if (state == PM_SUSPEND_STANDBY) {
printk(info_test, pm_states[state]); printk(info_test, pm_states[state].label);
status = pm_suspend(state); status = pm_suspend(state);
} }
if (status < 0) if (status < 0)
@ -136,18 +136,16 @@ static char warn_bad_state[] __initdata =
static int __init setup_test_suspend(char *value) static int __init setup_test_suspend(char *value)
{ {
unsigned i; suspend_state_t i;
/* "=mem" ==> "mem" */ /* "=mem" ==> "mem" */
value++; value++;
for (i = 0; i < PM_SUSPEND_MAX; i++) { for (i = PM_SUSPEND_MIN; i < PM_SUSPEND_MAX; i++)
if (!pm_states[i]) if (!strcmp(pm_states[i].label, value)) {
continue; test_state = pm_states[i].state;
if (strcmp(pm_states[i], value) != 0) return 0;
continue; }
test_state = (__force suspend_state_t) i;
return 0;
}
printk(warn_bad_state, value); printk(warn_bad_state, value);
return 0; return 0;
} }
@ -165,7 +163,7 @@ static int __init test_suspend(void)
if (test_state == PM_SUSPEND_ON) if (test_state == PM_SUSPEND_ON)
goto done; goto done;
if (!valid_state(test_state)) { if (!valid_state(test_state)) {
printk(warn_bad_state, pm_states[test_state]); printk(warn_bad_state, pm_states[test_state].label);
goto done; goto done;
} }