aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Capella <sebastian.capella@linaro.org>2014-03-24 20:20:29 -0400
committerRussell King <rmk+kernel@arm.linux.org.uk>2014-04-22 20:24:14 -0400
commit603fb42a66499ab353466c7afa3d38beea20a8a9 (patch)
tree14fd0f62deb8efe86340c528ddf5abc8289630fa
parent44ae903b96b1e5f9ff3103cd86918619c188003f (diff)
ARM: 8011/1: ARM hibernation / suspend-to-disk
Enable hibernation for ARM architectures and provide ARM architecture specific calls used during hibernation. The swsusp hibernation framework depends on the platform first having functional suspend/resume. Then, in order to enable hibernation on a given platform, a platform_hibernation_ops structure may need to be registered with the system in order to save/restore any SoC-specific / cpu specific state needing (re)init over a suspend-to-disk/resume-from-disk cycle. For example: - "secure" SoCs that have different sets of control registers and/or different CR reg access patterns. - SoCs with L2 caches as the activation sequence there is SoC-dependent; a full off-on cycle for L2 is not done by the hibernation support code. - SoCs requiring steps on wakeup _before_ the "generic" parts done by cpu_suspend / cpu_resume can work correctly. - SoCs having persistent state which is maintained during suspend and resume, but will be lost during the power off cycle after suspend-to-disk. This is a rebase/rework of Frank Hofmann's v5 hibernation patchset. Acked-by: Russ Dill <Russ.Dill@ti.com> Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net> Signed-off-by: Sebastian Capella <sebastian.capella@linaro.org> Acked-by: Pavel Machek <pavel@ucw.cz> Reviewed-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> [fixed duplicate virt_to_pfn() definition --rmk] Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
-rw-r--r--arch/arm/Kconfig5
-rw-r--r--arch/arm/kernel/Makefile1
-rw-r--r--arch/arm/kernel/hibernate.c107
-rw-r--r--include/linux/suspend.h2
4 files changed, 115 insertions, 0 deletions
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index ab438cb5af55..58506175a3ea 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -2294,6 +2294,11 @@ config ARCH_SUSPEND_POSSIBLE
2294config ARM_CPU_SUSPEND 2294config ARM_CPU_SUSPEND
2295 def_bool PM_SLEEP 2295 def_bool PM_SLEEP
2296 2296
2297config ARCH_HIBERNATION_POSSIBLE
2298 bool
2299 depends on MMU
2300 default y if ARCH_SUSPEND_POSSIBLE
2301
2297endmenu 2302endmenu
2298 2303
2299source "net/Kconfig" 2304source "net/Kconfig"
diff --git a/arch/arm/kernel/Makefile b/arch/arm/kernel/Makefile
index a766bcbaf8ad..10f0464206a2 100644
--- a/arch/arm/kernel/Makefile
+++ b/arch/arm/kernel/Makefile
@@ -39,6 +39,7 @@ obj-$(CONFIG_ARTHUR) += arthur.o
39obj-$(CONFIG_ISA_DMA) += dma-isa.o 39obj-$(CONFIG_ISA_DMA) += dma-isa.o
40obj-$(CONFIG_PCI) += bios32.o isa.o 40obj-$(CONFIG_PCI) += bios32.o isa.o
41obj-$(CONFIG_ARM_CPU_SUSPEND) += sleep.o suspend.o 41obj-$(CONFIG_ARM_CPU_SUSPEND) += sleep.o suspend.o
42obj-$(CONFIG_HIBERNATION) += hibernate.o
42obj-$(CONFIG_SMP) += smp.o 43obj-$(CONFIG_SMP) += smp.o
43ifdef CONFIG_MMU 44ifdef CONFIG_MMU
44obj-$(CONFIG_SMP) += smp_tlb.o 45obj-$(CONFIG_SMP) += smp_tlb.o
diff --git a/arch/arm/kernel/hibernate.c b/arch/arm/kernel/hibernate.c
new file mode 100644
index 000000000000..bb8b79648643
--- /dev/null
+++ b/arch/arm/kernel/hibernate.c
@@ -0,0 +1,107 @@
1/*
2 * Hibernation support specific for ARM
3 *
4 * Derived from work on ARM hibernation support by:
5 *
6 * Ubuntu project, hibernation support for mach-dove
7 * Copyright (C) 2010 Nokia Corporation (Hiroshi Doyu)
8 * Copyright (C) 2010 Texas Instruments, Inc. (Teerth Reddy et al.)
9 * https://lkml.org/lkml/2010/6/18/4
10 * https://lists.linux-foundation.org/pipermail/linux-pm/2010-June/027422.html
11 * https://patchwork.kernel.org/patch/96442/
12 *
13 * Copyright (C) 2006 Rafael J. Wysocki <rjw@sisk.pl>
14 *
15 * License terms: GNU General Public License (GPL) version 2
16 */
17
18#include <linux/mm.h>
19#include <linux/suspend.h>
20#include <asm/system_misc.h>
21#include <asm/idmap.h>
22#include <asm/suspend.h>
23#include <asm/memory.h>
24
25extern const void __nosave_begin, __nosave_end;
26
27int pfn_is_nosave(unsigned long pfn)
28{
29 unsigned long nosave_begin_pfn = virt_to_pfn(&__nosave_begin);
30 unsigned long nosave_end_pfn = virt_to_pfn(&__nosave_end - 1);
31
32 return (pfn >= nosave_begin_pfn) && (pfn <= nosave_end_pfn);
33}
34
35void notrace save_processor_state(void)
36{
37 WARN_ON(num_online_cpus() != 1);
38 local_fiq_disable();
39}
40
41void notrace restore_processor_state(void)
42{
43 local_fiq_enable();
44}
45
46/*
47 * Snapshot kernel memory and reset the system.
48 *
49 * swsusp_save() is executed in the suspend finisher so that the CPU
50 * context pointer and memory are part of the saved image, which is
51 * required by the resume kernel image to restart execution from
52 * swsusp_arch_suspend().
53 *
54 * soft_restart is not technically needed, but is used to get success
55 * returned from cpu_suspend.
56 *
57 * When soft reboot completes, the hibernation snapshot is written out.
58 */
59static int notrace arch_save_image(unsigned long unused)
60{
61 int ret;
62
63 ret = swsusp_save();
64 if (ret == 0)
65 soft_restart(virt_to_phys(cpu_resume));
66 return ret;
67}
68
69/*
70 * Save the current CPU state before suspend / poweroff.
71 */
72int notrace swsusp_arch_suspend(void)
73{
74 return cpu_suspend(0, arch_save_image);
75}
76
77/*
78 * Restore page contents for physical pages that were in use during loading
79 * hibernation image. Switch to idmap_pgd so the physical page tables
80 * are overwritten with the same contents.
81 */
82static void notrace arch_restore_image(void *unused)
83{
84 struct pbe *pbe;
85
86 cpu_switch_mm(idmap_pgd, &init_mm);
87 for (pbe = restore_pblist; pbe; pbe = pbe->next)
88 copy_page(pbe->orig_address, pbe->address);
89
90 soft_restart(virt_to_phys(cpu_resume));
91}
92
93static u64 resume_stack[PAGE_SIZE/2/sizeof(u64)] __nosavedata;
94
95/*
96 * Resume from the hibernation image.
97 * Due to the kernel heap / data restore, stack contents change underneath
98 * and that would make function calls impossible; switch to a temporary
99 * stack within the nosave region to avoid that problem.
100 */
101int swsusp_arch_resume(void)
102{
103 extern void call_with_stack(void (*fn)(void *), void *arg, void *sp);
104 call_with_stack(arch_restore_image, 0,
105 resume_stack + ARRAY_SIZE(resume_stack));
106 return 0;
107}
diff --git a/include/linux/suspend.h b/include/linux/suspend.h
index f73cabf59012..38bbf95109da 100644
--- a/include/linux/suspend.h
+++ b/include/linux/suspend.h
@@ -320,6 +320,8 @@ extern unsigned long get_safe_page(gfp_t gfp_mask);
320extern void hibernation_set_ops(const struct platform_hibernation_ops *ops); 320extern void hibernation_set_ops(const struct platform_hibernation_ops *ops);
321extern int hibernate(void); 321extern int hibernate(void);
322extern bool system_entering_hibernation(void); 322extern bool system_entering_hibernation(void);
323asmlinkage int swsusp_save(void);
324extern struct pbe *restore_pblist;
323#else /* CONFIG_HIBERNATION */ 325#else /* CONFIG_HIBERNATION */
324static inline void register_nosave_region(unsigned long b, unsigned long e) {} 326static inline void register_nosave_region(unsigned long b, unsigned long e) {}
325static inline void register_nosave_region_late(unsigned long b, unsigned long e) {} 327static inline void register_nosave_region_late(unsigned long b, unsigned long e) {}