Skip to content

Commit 2a6b697

Browse files
Matthew Garrettlenb
authored andcommitted
ACPI: Store NVS state even when entering suspend to RAM
https://bugzilla.kernel.org/show_bug.cgi?id=13931 describes a bug where a system fails to successfully resume after the second suspend. Maxim Levitsky discovered that this could be rectified by forcibly saving and restoring the ACPI non-volatile state. The spec indicates that this is only required for S4, but testing the behaviour of Windows by adding an ACPI NVS region to qemu's e820 map and registering a custom memory read/write handler reveals that it's saved and restored even over suspend to RAM. We should mimic that behaviour to avoid other broken platforms. Signed-off-by: Matthew Garrett <[email protected]> Signed-off-by: Len Brown <[email protected]>
1 parent dd4c4f1 commit 2a6b697

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

drivers/acpi/sleep.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ static int __acpi_pm_prepare(void)
112112
{
113113
int error = acpi_sleep_prepare(acpi_target_sleep_state);
114114

115+
suspend_nvs_save();
116+
115117
if (error)
116118
acpi_target_sleep_state = ACPI_STATE_S0;
117119
return error;
@@ -140,6 +142,8 @@ static void acpi_pm_finish(void)
140142
{
141143
u32 acpi_state = acpi_target_sleep_state;
142144

145+
suspend_nvs_free();
146+
143147
if (acpi_state == ACPI_STATE_S0)
144148
return;
145149

@@ -189,6 +193,11 @@ static int acpi_suspend_begin(suspend_state_t pm_state)
189193
u32 acpi_state = acpi_suspend_states[pm_state];
190194
int error = 0;
191195

196+
error = suspend_nvs_alloc();
197+
198+
if (error)
199+
return error;
200+
192201
if (sleep_states[acpi_state]) {
193202
acpi_target_sleep_state = acpi_state;
194203
acpi_sleep_tts_switch(acpi_target_sleep_state);
@@ -264,6 +273,8 @@ static int acpi_suspend_enter(suspend_state_t pm_state)
264273
if (acpi_state == ACPI_STATE_S3)
265274
acpi_restore_state_mem();
266275

276+
suspend_nvs_restore();
277+
267278
return ACPI_SUCCESS(status) ? 0 : -EFAULT;
268279
}
269280

@@ -430,12 +441,6 @@ static int acpi_hibernation_enter(void)
430441
return ACPI_SUCCESS(status) ? 0 : -EFAULT;
431442
}
432443

433-
static void acpi_hibernation_finish(void)
434-
{
435-
suspend_nvs_free();
436-
acpi_pm_finish();
437-
}
438-
439444
static void acpi_hibernation_leave(void)
440445
{
441446
/*
@@ -473,7 +478,7 @@ static struct platform_hibernation_ops acpi_hibernation_ops = {
473478
.begin = acpi_hibernation_begin,
474479
.end = acpi_pm_end,
475480
.pre_snapshot = acpi_hibernation_pre_snapshot,
476-
.finish = acpi_hibernation_finish,
481+
.finish = acpi_pm_finish,
477482
.prepare = acpi_pm_prepare,
478483
.enter = acpi_hibernation_enter,
479484
.leave = acpi_hibernation_leave,
@@ -526,7 +531,7 @@ static struct platform_hibernation_ops acpi_hibernation_ops_old = {
526531
.begin = acpi_hibernation_begin_old,
527532
.end = acpi_pm_end,
528533
.pre_snapshot = acpi_hibernation_pre_snapshot_old,
529-
.finish = acpi_hibernation_finish,
534+
.finish = acpi_pm_finish,
530535
.prepare = acpi_pm_disable_gpes,
531536
.enter = acpi_hibernation_enter,
532537
.leave = acpi_hibernation_leave,

0 commit comments

Comments
 (0)