mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-11-24 15:20:58 +07:00
Merge branches 'pm-apm' and 'pm-sleep'
* pm-apm: x86, apm: Remove unused variable * pm-sleep: PM / sleep: Move platform suspend operations to separate functions PM / sleep: Simplify sleep states sysfs interface code
This commit is contained in:
commit
bb1c095f73
@ -296,8 +296,8 @@ 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 (pm_states[i].state)
|
if (pm_states[i])
|
||||||
s += sprintf(s,"%s ", pm_states[i].label);
|
s += sprintf(s,"%s ", pm_states[i]);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
if (hibernation_available())
|
if (hibernation_available())
|
||||||
@ -311,8 +311,7 @@ static ssize_t state_show(struct kobject *kobj, struct kobj_attribute *attr,
|
|||||||
static suspend_state_t decode_state(const char *buf, size_t n)
|
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;
|
||||||
struct pm_sleep_state *s;
|
|
||||||
#endif
|
#endif
|
||||||
char *p;
|
char *p;
|
||||||
int len;
|
int len;
|
||||||
@ -325,10 +324,12 @@ static suspend_state_t decode_state(const char *buf, size_t n)
|
|||||||
return PM_SUSPEND_MAX;
|
return PM_SUSPEND_MAX;
|
||||||
|
|
||||||
#ifdef CONFIG_SUSPEND
|
#ifdef CONFIG_SUSPEND
|
||||||
for (s = &pm_states[state]; state < PM_SUSPEND_MAX; s++, state++)
|
for (state = PM_SUSPEND_MIN; state < PM_SUSPEND_MAX; state++) {
|
||||||
if (s->state && len == strlen(s->label)
|
const char *label = pm_states[state];
|
||||||
&& !strncmp(buf, s->label, len))
|
|
||||||
return s->state;
|
if (label && len == strlen(label) && !strncmp(buf, label, len))
|
||||||
|
return state;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return PM_SUSPEND_ON;
|
return PM_SUSPEND_ON;
|
||||||
@ -446,8 +447,8 @@ 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", pm_states[state].state ?
|
return sprintf(buf, "%s\n", pm_states[state] ?
|
||||||
pm_states[state].label : "error");
|
pm_states[state] : "error");
|
||||||
#endif
|
#endif
|
||||||
#ifdef CONFIG_HIBERNATION
|
#ifdef CONFIG_HIBERNATION
|
||||||
return sprintf(buf, "disk\n");
|
return sprintf(buf, "disk\n");
|
||||||
|
@ -178,13 +178,8 @@ 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 struct pm_sleep_state pm_states[];
|
extern const char *pm_states[];
|
||||||
|
|
||||||
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 */
|
||||||
|
@ -31,20 +31,11 @@
|
|||||||
|
|
||||||
#include "power.h"
|
#include "power.h"
|
||||||
|
|
||||||
struct pm_sleep_state pm_states[PM_SUSPEND_MAX] = {
|
static const char *pm_labels[] = { "mem", "standby", "freeze", };
|
||||||
[PM_SUSPEND_FREEZE] = { .label = "freeze", .state = PM_SUSPEND_FREEZE },
|
const char *pm_states[PM_SUSPEND_MAX];
|
||||||
[PM_SUSPEND_STANDBY] = { .label = "standby", },
|
|
||||||
[PM_SUSPEND_MEM] = { .label = "mem", },
|
|
||||||
};
|
|
||||||
|
|
||||||
static const struct platform_suspend_ops *suspend_ops;
|
static const struct platform_suspend_ops *suspend_ops;
|
||||||
static const struct platform_freeze_ops *freeze_ops;
|
static const struct platform_freeze_ops *freeze_ops;
|
||||||
|
|
||||||
static bool need_suspend_ops(suspend_state_t state)
|
|
||||||
{
|
|
||||||
return state > PM_SUSPEND_FREEZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static DECLARE_WAIT_QUEUE_HEAD(suspend_freeze_wait_head);
|
static DECLARE_WAIT_QUEUE_HEAD(suspend_freeze_wait_head);
|
||||||
static bool suspend_freeze_wake;
|
static bool suspend_freeze_wake;
|
||||||
|
|
||||||
@ -97,10 +88,7 @@ static bool relative_states;
|
|||||||
static int __init sleep_states_setup(char *str)
|
static int __init sleep_states_setup(char *str)
|
||||||
{
|
{
|
||||||
relative_states = !strncmp(str, "1", 1);
|
relative_states = !strncmp(str, "1", 1);
|
||||||
if (relative_states) {
|
pm_states[PM_SUSPEND_FREEZE] = pm_labels[relative_states ? 0 : 2];
|
||||||
pm_states[PM_SUSPEND_MEM].state = PM_SUSPEND_FREEZE;
|
|
||||||
pm_states[PM_SUSPEND_FREEZE].state = 0;
|
|
||||||
}
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,20 +101,20 @@ __setup("relative_sleep_states=", sleep_states_setup);
|
|||||||
void suspend_set_ops(const struct platform_suspend_ops *ops)
|
void suspend_set_ops(const struct platform_suspend_ops *ops)
|
||||||
{
|
{
|
||||||
suspend_state_t i;
|
suspend_state_t i;
|
||||||
int j = PM_SUSPEND_MAX - 1;
|
int j = 0;
|
||||||
|
|
||||||
lock_system_sleep();
|
lock_system_sleep();
|
||||||
|
|
||||||
suspend_ops = ops;
|
suspend_ops = ops;
|
||||||
for (i = PM_SUSPEND_MEM; i >= PM_SUSPEND_STANDBY; i--)
|
for (i = PM_SUSPEND_MEM; i >= PM_SUSPEND_STANDBY; i--)
|
||||||
if (valid_state(i))
|
if (valid_state(i)) {
|
||||||
pm_states[j--].state = i;
|
pm_states[i] = pm_labels[j++];
|
||||||
else if (!relative_states)
|
} else if (!relative_states) {
|
||||||
pm_states[j--].state = 0;
|
pm_states[i] = NULL;
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
|
||||||
pm_states[j--].state = PM_SUSPEND_FREEZE;
|
pm_states[PM_SUSPEND_FREEZE] = pm_labels[j];
|
||||||
while (j >= PM_SUSPEND_MIN)
|
|
||||||
pm_states[j--].state = 0;
|
|
||||||
|
|
||||||
unlock_system_sleep();
|
unlock_system_sleep();
|
||||||
}
|
}
|
||||||
@ -145,6 +133,65 @@ int suspend_valid_only_mem(suspend_state_t state)
|
|||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(suspend_valid_only_mem);
|
EXPORT_SYMBOL_GPL(suspend_valid_only_mem);
|
||||||
|
|
||||||
|
static bool sleep_state_supported(suspend_state_t state)
|
||||||
|
{
|
||||||
|
return state == PM_SUSPEND_FREEZE || (suspend_ops && suspend_ops->enter);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int platform_suspend_prepare(suspend_state_t state)
|
||||||
|
{
|
||||||
|
return state != PM_SUSPEND_FREEZE && suspend_ops->prepare ?
|
||||||
|
suspend_ops->prepare() : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int platform_suspend_prepare_late(suspend_state_t state)
|
||||||
|
{
|
||||||
|
return state != PM_SUSPEND_FREEZE && suspend_ops->prepare_late ?
|
||||||
|
suspend_ops->prepare_late() : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void platform_suspend_wake(suspend_state_t state)
|
||||||
|
{
|
||||||
|
if (state != PM_SUSPEND_FREEZE && suspend_ops->wake)
|
||||||
|
suspend_ops->wake();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void platform_suspend_finish(suspend_state_t state)
|
||||||
|
{
|
||||||
|
if (state != PM_SUSPEND_FREEZE && suspend_ops->finish)
|
||||||
|
suspend_ops->finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
static int platform_suspend_begin(suspend_state_t state)
|
||||||
|
{
|
||||||
|
if (state == PM_SUSPEND_FREEZE && freeze_ops && freeze_ops->begin)
|
||||||
|
return freeze_ops->begin();
|
||||||
|
else if (suspend_ops->begin)
|
||||||
|
return suspend_ops->begin(state);
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void platform_suspend_end(suspend_state_t state)
|
||||||
|
{
|
||||||
|
if (state == PM_SUSPEND_FREEZE && freeze_ops && freeze_ops->end)
|
||||||
|
freeze_ops->end();
|
||||||
|
else if (suspend_ops->end)
|
||||||
|
suspend_ops->end();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void platform_suspend_recover(suspend_state_t state)
|
||||||
|
{
|
||||||
|
if (state != PM_SUSPEND_FREEZE && suspend_ops->recover)
|
||||||
|
suspend_ops->recover();
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool platform_suspend_again(suspend_state_t state)
|
||||||
|
{
|
||||||
|
return state != PM_SUSPEND_FREEZE && suspend_ops->suspend_again ?
|
||||||
|
suspend_ops->suspend_again() : false;
|
||||||
|
}
|
||||||
|
|
||||||
static int suspend_test(int level)
|
static int suspend_test(int level)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_PM_DEBUG
|
#ifdef CONFIG_PM_DEBUG
|
||||||
@ -168,7 +215,7 @@ static int suspend_prepare(suspend_state_t state)
|
|||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
if (need_suspend_ops(state) && (!suspend_ops || !suspend_ops->enter))
|
if (!sleep_state_supported(state))
|
||||||
return -EPERM;
|
return -EPERM;
|
||||||
|
|
||||||
pm_prepare_console();
|
pm_prepare_console();
|
||||||
@ -214,23 +261,18 @@ static int suspend_enter(suspend_state_t state, bool *wakeup)
|
|||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
if (need_suspend_ops(state) && suspend_ops->prepare) {
|
error = platform_suspend_prepare(state);
|
||||||
error = suspend_ops->prepare();
|
if (error)
|
||||||
if (error)
|
goto Platform_finish;
|
||||||
goto Platform_finish;
|
|
||||||
}
|
|
||||||
|
|
||||||
error = dpm_suspend_end(PMSG_SUSPEND);
|
error = dpm_suspend_end(PMSG_SUSPEND);
|
||||||
if (error) {
|
if (error) {
|
||||||
printk(KERN_ERR "PM: Some devices failed to power down\n");
|
printk(KERN_ERR "PM: Some devices failed to power down\n");
|
||||||
goto Platform_finish;
|
goto Platform_finish;
|
||||||
}
|
}
|
||||||
|
error = platform_suspend_prepare_late(state);
|
||||||
if (need_suspend_ops(state) && suspend_ops->prepare_late) {
|
if (error)
|
||||||
error = suspend_ops->prepare_late();
|
goto Platform_wake;
|
||||||
if (error)
|
|
||||||
goto Platform_wake;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (suspend_test(TEST_PLATFORM))
|
if (suspend_test(TEST_PLATFORM))
|
||||||
goto Platform_wake;
|
goto Platform_wake;
|
||||||
@ -278,15 +320,11 @@ static int suspend_enter(suspend_state_t state, bool *wakeup)
|
|||||||
ftrace_start();
|
ftrace_start();
|
||||||
|
|
||||||
Platform_wake:
|
Platform_wake:
|
||||||
if (need_suspend_ops(state) && suspend_ops->wake)
|
platform_suspend_wake(state);
|
||||||
suspend_ops->wake();
|
|
||||||
|
|
||||||
dpm_resume_start(PMSG_RESUME);
|
dpm_resume_start(PMSG_RESUME);
|
||||||
|
|
||||||
Platform_finish:
|
Platform_finish:
|
||||||
if (need_suspend_ops(state) && suspend_ops->finish)
|
platform_suspend_finish(state);
|
||||||
suspend_ops->finish();
|
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -299,18 +337,13 @@ int suspend_devices_and_enter(suspend_state_t state)
|
|||||||
int error;
|
int error;
|
||||||
bool wakeup = false;
|
bool wakeup = false;
|
||||||
|
|
||||||
if (need_suspend_ops(state) && !suspend_ops)
|
if (!sleep_state_supported(state))
|
||||||
return -ENOSYS;
|
return -ENOSYS;
|
||||||
|
|
||||||
if (need_suspend_ops(state) && suspend_ops->begin) {
|
error = platform_suspend_begin(state);
|
||||||
error = suspend_ops->begin(state);
|
if (error)
|
||||||
if (error)
|
goto Close;
|
||||||
goto Close;
|
|
||||||
} else if (state == PM_SUSPEND_FREEZE && freeze_ops && freeze_ops->begin) {
|
|
||||||
error = freeze_ops->begin();
|
|
||||||
if (error)
|
|
||||||
goto Close;
|
|
||||||
}
|
|
||||||
suspend_console();
|
suspend_console();
|
||||||
suspend_test_start();
|
suspend_test_start();
|
||||||
error = dpm_suspend_start(PMSG_SUSPEND);
|
error = dpm_suspend_start(PMSG_SUSPEND);
|
||||||
@ -324,25 +357,20 @@ int suspend_devices_and_enter(suspend_state_t state)
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
error = suspend_enter(state, &wakeup);
|
error = suspend_enter(state, &wakeup);
|
||||||
} while (!error && !wakeup && need_suspend_ops(state)
|
} while (!error && !wakeup && platform_suspend_again(state));
|
||||||
&& suspend_ops->suspend_again && suspend_ops->suspend_again());
|
|
||||||
|
|
||||||
Resume_devices:
|
Resume_devices:
|
||||||
suspend_test_start();
|
suspend_test_start();
|
||||||
dpm_resume_end(PMSG_RESUME);
|
dpm_resume_end(PMSG_RESUME);
|
||||||
suspend_test_finish("resume devices");
|
suspend_test_finish("resume devices");
|
||||||
resume_console();
|
resume_console();
|
||||||
Close:
|
|
||||||
if (need_suspend_ops(state) && suspend_ops->end)
|
|
||||||
suspend_ops->end();
|
|
||||||
else if (state == PM_SUSPEND_FREEZE && freeze_ops && freeze_ops->end)
|
|
||||||
freeze_ops->end();
|
|
||||||
|
|
||||||
|
Close:
|
||||||
|
platform_suspend_end(state);
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
Recover_platform:
|
Recover_platform:
|
||||||
if (need_suspend_ops(state) && suspend_ops->recover)
|
platform_suspend_recover(state);
|
||||||
suspend_ops->recover();
|
|
||||||
goto Resume_devices;
|
goto Resume_devices;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -395,7 +423,7 @@ static int enter_state(suspend_state_t state)
|
|||||||
printk("done.\n");
|
printk("done.\n");
|
||||||
trace_suspend_resume(TPS("sync_filesystems"), 0, false);
|
trace_suspend_resume(TPS("sync_filesystems"), 0, false);
|
||||||
|
|
||||||
pr_debug("PM: Preparing system for %s sleep\n", pm_states[state].label);
|
pr_debug("PM: Preparing system for %s sleep\n", pm_states[state]);
|
||||||
error = suspend_prepare(state);
|
error = suspend_prepare(state);
|
||||||
if (error)
|
if (error)
|
||||||
goto Unlock;
|
goto Unlock;
|
||||||
@ -404,7 +432,7 @@ static int enter_state(suspend_state_t state)
|
|||||||
goto Finish;
|
goto Finish;
|
||||||
|
|
||||||
trace_suspend_resume(TPS("suspend_enter"), state, false);
|
trace_suspend_resume(TPS("suspend_enter"), state, false);
|
||||||
pr_debug("PM: Entering %s sleep\n", pm_states[state].label);
|
pr_debug("PM: Entering %s sleep\n", pm_states[state]);
|
||||||
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();
|
||||||
|
@ -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].label);
|
printk(info_test, pm_states[state]);
|
||||||
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].label);
|
printk(info_test, pm_states[state]);
|
||||||
status = pm_suspend(state);
|
status = pm_suspend(state);
|
||||||
}
|
}
|
||||||
if (status < 0)
|
if (status < 0)
|
||||||
@ -141,8 +141,8 @@ static int __init setup_test_suspend(char *value)
|
|||||||
/* "=mem" ==> "mem" */
|
/* "=mem" ==> "mem" */
|
||||||
value++;
|
value++;
|
||||||
for (i = PM_SUSPEND_MIN; i < PM_SUSPEND_MAX; i++)
|
for (i = PM_SUSPEND_MIN; i < PM_SUSPEND_MAX; i++)
|
||||||
if (!strcmp(pm_states[i].label, value)) {
|
if (!strcmp(pm_states[i], value)) {
|
||||||
test_state = pm_states[i].state;
|
test_state = i;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,8 +162,8 @@ 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 (!pm_states[test_state].state) {
|
if (!pm_states[test_state]) {
|
||||||
printk(warn_bad_state, pm_states[test_state].label);
|
printk(warn_bad_state, pm_states[test_state]);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user