Skip to content

Commit dd4c4f1

Browse files
Matthew Garrettlenb
authored andcommitted
suspend: Move NVS save/restore code to generic suspend functionality
Saving platform non-volatile state may be required for suspend to RAM as well as hibernation. Move it to more generic code. Signed-off-by: Matthew Garrett <[email protected]> Acked-by: Rafael J. Wysocki <[email protected]> Tested-by: Maxim Levitsky <[email protected]> Signed-off-by: Len Brown <[email protected]>
1 parent 67a3e12 commit dd4c4f1

File tree

7 files changed

+44
-37
lines changed

7 files changed

+44
-37
lines changed

arch/x86/kernel/e820.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ static int __init e820_mark_nvs_memory(void)
729729
struct e820entry *ei = &e820.map[i];
730730

731731
if (ei->type == E820_NVS)
732-
hibernate_nvs_register(ei->addr, ei->size);
732+
suspend_nvs_register(ei->addr, ei->size);
733733
}
734734

735735
return 0;

drivers/acpi/sleep.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ static int acpi_hibernation_begin(void)
393393
{
394394
int error;
395395

396-
error = s4_no_nvs ? 0 : hibernate_nvs_alloc();
396+
error = s4_no_nvs ? 0 : suspend_nvs_alloc();
397397
if (!error) {
398398
acpi_target_sleep_state = ACPI_STATE_S4;
399399
acpi_sleep_tts_switch(acpi_target_sleep_state);
@@ -407,7 +407,7 @@ static int acpi_hibernation_pre_snapshot(void)
407407
int error = acpi_pm_prepare();
408408

409409
if (!error)
410-
hibernate_nvs_save();
410+
suspend_nvs_save();
411411

412412
return error;
413413
}
@@ -432,7 +432,7 @@ static int acpi_hibernation_enter(void)
432432

433433
static void acpi_hibernation_finish(void)
434434
{
435-
hibernate_nvs_free();
435+
suspend_nvs_free();
436436
acpi_pm_finish();
437437
}
438438

@@ -452,7 +452,7 @@ static void acpi_hibernation_leave(void)
452452
panic("ACPI S4 hardware signature mismatch");
453453
}
454454
/* Restore the NVS memory area */
455-
hibernate_nvs_restore();
455+
suspend_nvs_restore();
456456
}
457457

458458
static int acpi_pm_pre_restore(void)
@@ -501,7 +501,7 @@ static int acpi_hibernation_begin_old(void)
501501

502502
if (!error) {
503503
if (!s4_no_nvs)
504-
error = hibernate_nvs_alloc();
504+
error = suspend_nvs_alloc();
505505
if (!error)
506506
acpi_target_sleep_state = ACPI_STATE_S4;
507507
}
@@ -513,7 +513,7 @@ static int acpi_hibernation_pre_snapshot_old(void)
513513
int error = acpi_pm_disable_gpes();
514514

515515
if (!error)
516-
hibernate_nvs_save();
516+
suspend_nvs_save();
517517

518518
return error;
519519
}

include/linux/suspend.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -256,22 +256,22 @@ static inline int hibernate(void) { return -ENOSYS; }
256256
static inline bool system_entering_hibernation(void) { return false; }
257257
#endif /* CONFIG_HIBERNATION */
258258

259-
#ifdef CONFIG_HIBERNATION_NVS
260-
extern int hibernate_nvs_register(unsigned long start, unsigned long size);
261-
extern int hibernate_nvs_alloc(void);
262-
extern void hibernate_nvs_free(void);
263-
extern void hibernate_nvs_save(void);
264-
extern void hibernate_nvs_restore(void);
265-
#else /* CONFIG_HIBERNATION_NVS */
266-
static inline int hibernate_nvs_register(unsigned long a, unsigned long b)
259+
#ifdef CONFIG_SUSPEND_NVS
260+
extern int suspend_nvs_register(unsigned long start, unsigned long size);
261+
extern int suspend_nvs_alloc(void);
262+
extern void suspend_nvs_free(void);
263+
extern void suspend_nvs_save(void);
264+
extern void suspend_nvs_restore(void);
265+
#else /* CONFIG_SUSPEND_NVS */
266+
static inline int suspend_nvs_register(unsigned long a, unsigned long b)
267267
{
268268
return 0;
269269
}
270-
static inline int hibernate_nvs_alloc(void) { return 0; }
271-
static inline void hibernate_nvs_free(void) {}
272-
static inline void hibernate_nvs_save(void) {}
273-
static inline void hibernate_nvs_restore(void) {}
274-
#endif /* CONFIG_HIBERNATION_NVS */
270+
static inline int suspend_nvs_alloc(void) { return 0; }
271+
static inline void suspend_nvs_free(void) {}
272+
static inline void suspend_nvs_save(void) {}
273+
static inline void suspend_nvs_restore(void) {}
274+
#endif /* CONFIG_SUSPEND_NVS */
275275

276276
#ifdef CONFIG_PM_SLEEP
277277
void save_processor_state(void);

kernel/power/Kconfig

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,13 @@ config PM_SLEEP_ADVANCED_DEBUG
9999
depends on PM_ADVANCED_DEBUG
100100
default n
101101

102+
config SUSPEND_NVS
103+
bool
104+
102105
config SUSPEND
103106
bool "Suspend to RAM and standby"
104107
depends on PM && ARCH_SUSPEND_POSSIBLE
108+
select SUSPEND_NVS if HAS_IOMEM
105109
default y
106110
---help---
107111
Allow the system to enter sleep states in which main memory is
@@ -130,13 +134,10 @@ config SUSPEND_FREEZER
130134

131135
Turning OFF this setting is NOT recommended! If in doubt, say Y.
132136

133-
config HIBERNATION_NVS
134-
bool
135-
136137
config HIBERNATION
137138
bool "Hibernation (aka 'suspend to disk')"
138139
depends on PM && SWAP && ARCH_HIBERNATION_POSSIBLE
139-
select HIBERNATION_NVS if HAS_IOMEM
140+
select SUSPEND_NVS if HAS_IOMEM
140141
---help---
141142
Enable the suspend to disk (STD) functionality, which is usually
142143
called "hibernation" in user interfaces. STD checkpoints the

kernel/power/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ obj-$(CONFIG_SUSPEND) += suspend.o
1010
obj-$(CONFIG_PM_TEST_SUSPEND) += suspend_test.o
1111
obj-$(CONFIG_HIBERNATION) += hibernate.o snapshot.o swap.o user.o \
1212
block_io.o
13-
obj-$(CONFIG_HIBERNATION_NVS) += hibernate_nvs.o
13+
obj-$(CONFIG_SUSPEND_NVS) += nvs.o
1414

1515
obj-$(CONFIG_MAGIC_SYSRQ) += poweroff.o

kernel/power/hibernate_nvs.c renamed to kernel/power/nvs.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
/*
1717
* Platforms, like ACPI, may want us to save some memory used by them during
18-
* hibernation and to restore the contents of this memory during the subsequent
18+
* suspend and to restore the contents of this memory during the subsequent
1919
* resume. The code below implements a mechanism allowing us to do that.
2020
*/
2121

@@ -30,15 +30,15 @@ struct nvs_page {
3030
static LIST_HEAD(nvs_list);
3131

3232
/**
33-
* hibernate_nvs_register - register platform NVS memory region to save
33+
* suspend_nvs_register - register platform NVS memory region to save
3434
* @start - physical address of the region
3535
* @size - size of the region
3636
*
3737
* The NVS region need not be page-aligned (both ends) and we arrange
3838
* things so that the data from page-aligned addresses in this region will
3939
* be copied into separate RAM pages.
4040
*/
41-
int hibernate_nvs_register(unsigned long start, unsigned long size)
41+
int suspend_nvs_register(unsigned long start, unsigned long size)
4242
{
4343
struct nvs_page *entry, *next;
4444

@@ -68,9 +68,9 @@ int hibernate_nvs_register(unsigned long start, unsigned long size)
6868
}
6969

7070
/**
71-
* hibernate_nvs_free - free data pages allocated for saving NVS regions
71+
* suspend_nvs_free - free data pages allocated for saving NVS regions
7272
*/
73-
void hibernate_nvs_free(void)
73+
void suspend_nvs_free(void)
7474
{
7575
struct nvs_page *entry;
7676

@@ -86,26 +86,26 @@ void hibernate_nvs_free(void)
8686
}
8787

8888
/**
89-
* hibernate_nvs_alloc - allocate memory necessary for saving NVS regions
89+
* suspend_nvs_alloc - allocate memory necessary for saving NVS regions
9090
*/
91-
int hibernate_nvs_alloc(void)
91+
int suspend_nvs_alloc(void)
9292
{
9393
struct nvs_page *entry;
9494

9595
list_for_each_entry(entry, &nvs_list, node) {
9696
entry->data = (void *)__get_free_page(GFP_KERNEL);
9797
if (!entry->data) {
98-
hibernate_nvs_free();
98+
suspend_nvs_free();
9999
return -ENOMEM;
100100
}
101101
}
102102
return 0;
103103
}
104104

105105
/**
106-
* hibernate_nvs_save - save NVS memory regions
106+
* suspend_nvs_save - save NVS memory regions
107107
*/
108-
void hibernate_nvs_save(void)
108+
void suspend_nvs_save(void)
109109
{
110110
struct nvs_page *entry;
111111

@@ -119,12 +119,12 @@ void hibernate_nvs_save(void)
119119
}
120120

121121
/**
122-
* hibernate_nvs_restore - restore NVS memory regions
122+
* suspend_nvs_restore - restore NVS memory regions
123123
*
124124
* This function is going to be called with interrupts disabled, so it
125125
* cannot iounmap the virtual addresses used to access the NVS region.
126126
*/
127-
void hibernate_nvs_restore(void)
127+
void suspend_nvs_restore(void)
128128
{
129129
struct nvs_page *entry;
130130

kernel/power/suspend.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
#include <linux/cpu.h>
1717
#include <linux/syscalls.h>
1818
#include <linux/gfp.h>
19+
#include <linux/io.h>
20+
#include <linux/kernel.h>
21+
#include <linux/list.h>
22+
#include <linux/mm.h>
23+
#include <linux/slab.h>
24+
#include <linux/suspend.h>
1925

2026
#include "power.h"
2127

0 commit comments

Comments
 (0)