sh: hibernation support V2
Subsystems (2)
PATCH 1/1 sh: hibernation support V2
From: Magnus Damm <[email protected]>
Add Suspend-to-disk / swsusp / CONFIG_HIBERNATION support to the SuperH architecture V2.
To suspend, use "swapon /dev/sda2; echo disk > /sys/power/state" To resume, pass "resume=/dev/sda2" on the kernel command line.
The patch "pm: rework includes, remove arch ifdefs V2" is needed to allow the generic swsusp code to build properly.
Hibernation is not enabled with this patch though, a patch setting ARCH_HIBERNATION_POSSIBLE will be submitted later.
---
V2 contains changes according to feedback from Paul.
arch/sh/include/asm/sections.h | 1 arch/sh/include/asm/suspend.h | 13 +++ arch/sh/kernel/Makefile_32 | 1 arch/sh/kernel/asm-offsets.c | 8 ++ arch/sh/kernel/cpu/sh3/Makefile | 2 arch/sh/kernel/cpu/sh3/entry.S | 22 ++++- arch/sh/kernel/cpu/sh3/swsusp.S | 147 +++++++++++++++++++++++++++++++++++++++ arch/sh/kernel/cpu/sh4/Makefile | 1 arch/sh/kernel/swsusp.c | 38 ++++++++++ 9 files changed, 228 insertions(+), 5 deletions(-)
arch/sh/include/asm/sections.h +1 -0
@@ -3,6 +3,7 @@#include <asm-generic/sections.h> +extern void __nosave_begin, __nosave_end;extern long __machvec_start, __machvec_end;extern char __uncached_start, __uncached_end;extern char _ebss[];
arch/sh/include/asm/suspend.h new file +13 -0
@@ -0,0 +1,13 @@ +#ifndef _ASM_SH_SUSPEND_H +#define _ASM_SH_SUSPEND_H + +static inline int arch_prepare_suspend (void ) {return 0 ; } + +#include <asm/ptrace.h> + +struct swsusp_arch_regs { +struct pt_regs user_regs; +unsigned long bank1_regs[8 ]; +}; + +#endif /* _ASM_SH_SUSPEND_H */
arch/sh/kernel/Makefile_32 +1 -0
@@ -30,5 +30,6 @@ obj-$(CONFIG_KPROBES) += kprobes.o obj-$(CONFIG_GENERIC_GPIO) += gpio.o obj-$(CONFIG_DYNAMIC_FTRACE) += ftrace.o obj-$(CONFIG_DUMP_CODE) += disassemble.o +obj-$(CONFIG_HIBERNATION) += swsusp.o EXTRA_CFLAGS += -Werror
arch/sh/kernel/asm-offsets.c +8 -0
@@ -12,8 +12,10 @@#include <linux/types.h> #include <linux/mm.h> #include <linux/kbuild.h> +#include <linux/suspend.h> #include <asm/thread_info.h> +#include <asm/suspend.h> int main (void ) {
@@ -25,5 +27,11 @@ int main(void)DEFINE (TI_PRE_COUNT , offsetof(struct thread_info , preempt_count));DEFINE (TI_RESTART_BLOCK ,offsetof(struct thread_info , restart_block)); +#ifdef CONFIG_HIBERNATION +DEFINE (PBE_ADDRESS , offsetof(struct pbe , address)); +DEFINE (PBE_ORIG_ADDRESS , offsetof(struct pbe , orig_address)); +DEFINE (PBE_NEXT , offsetof(struct pbe , next)); +DEFINE (SWSUSP_ARCH_REGS_SIZE ,sizeof (struct swsusp_arch_regs )); +#endif return 0 ; }
arch/sh/kernel/cpu/sh3/Makefile +2 -0
@@ -4,6 +4,8 @@ obj-y := ex.o probe.o entry.o setup-sh3.o +obj-$(CONFIG_HIBERNATION) += swsusp.o + # CPU subtype setup obj-$(CONFIG_CPU_SUBTYPE_SH7705) += setup-sh7705.o obj-$(CONFIG_CPU_SUBTYPE_SH7706) += setup-sh770x.o
arch/sh/kernel/cpu/sh3/entry.S +17 -5
@@ -216,7 +216,7 @@ ENTRY(sh_bios_handler) ! r9 trashed ! BL=0 on entry, on exit BL=1 (depending on r8). -restore_regs: +ENTRY(restore_regs) mov.l @r15+, r0 mov.l @r15+, r1 mov.l @r15+, r2
@@ -362,8 +362,10 @@ general_exception: nop ! Save registers / Switch to bank 0 + mov.l k4, k2 ! keep vector in k2 + mov.l 1f, k4 ! SR bits to clear in k4 bsr save_regs ! needs original pr value in k3 - mov k4, k2 ! keep vector in k2 + nop bra handle_exception_special nop
@@ -471,6 +473,7 @@ handle_exception: ! Save registers / Switch to bank 0 mov.l 5f, k2 ! vector register address + mov.l 1f, k4 ! SR bits to clear in k4 bsr save_regs ! needs original pr value in k3 mov.l @k2, k2 ! read out vector and keep in k2
@@ -495,10 +498,10 @@ handle_exception_special: ! k0 contains original stack pointer* ! k1 trashed ! k3 passes original pr* -! k4 trashed +! k4 passes SR bitmask ! BL=1 on entry, on exit BL=0. -save_regs: +ENTRY(save_regs) mov #-1, r1 mov.l k1, @-r15 ! set TRA (default: -1) sts.l macl, @-r15
@@ -518,8 +521,16 @@ save_regs: mov.l r8, @-r15 mov.l 0f, k3 ! SR bits to set in k3 - mov.l 1f, k4 ! SR bits to clear in k4 + ! fall-through + +! save_low_regs() +! - modify SR for bank switch +! - save r7, r6, r5, r4, r3, r2, r1, r0 on the stack +! k3 passes bits to set in SR +! k4 passes bits to clear in SR + +ENTRY(save_low_regs) stc sr, r8 or k3, r8 and k4, r8
@@ -565,6 +576,7 @@ ENTRY(handle_interrupt) PREF(k0) ! Save registers / Switch to bank 0 + mov.l 1f, k4 ! SR bits to clear in k4 bsr save_regs ! needs original pr value in k3 mov #-1, k2 ! default vector kept in k2
arch/sh/kernel/cpu/sh3/swsusp.S new file +147 -0
147 lines not on this page · raw message
arch/sh/kernel/cpu/sh4/Makefile +1 -0
@@ -5,6 +5,7 @@ obj-y := probe.o common.o common-y += $(addprefix ../sh3/, entry.o ex.o) +obj-$(CONFIG_HIBERNATION) += $(addprefix ../sh3/, swsusp.o) obj-$(CONFIG_SH_FPU) += fpu.o softfloat.o obj-$(CONFIG_SH_STORE_QUEUES) += sq.o
arch/sh/kernel/swsusp.c new file +38 -0
@@ -0,0 +1,38 @@ +/* +* swsusp.c - SuperH hibernation support +* +* Copyright (C) 2009 Magnus Damm +* +* This file is subject to the terms and conditions of the GNU General Public +* License. See the file "COPYING" in the main directory of this archive +* for more details. +*/ + +#include <linux/mm.h> +#include <linux/sched.h> +#include <linux/suspend.h> +#include <asm/suspend.h> +#include <asm/sections.h> +#include <asm/tlbflush.h> +#include <asm/page.h> +#include <asm/fpu.h> + +struct swsusp_arch_regs swsusp_arch_regs_cpu0; + +int pfn_is_nosave (unsigned long pfn) +{ +unsigned long begin_pfn =__pa (&__nosave_begin) >>PAGE_SHIFT ; +unsigned long end_pfn =PAGE_ALIGN (__pa (&__nosave_end)) >>PAGE_SHIFT ; + +return (pfn >= begin_pfn) && (pfn < end_pfn); +} + +void save_processor_state (void ) +{ +init_fpu (current); +} + +void restore_processor_state (void ) +{ +local_flush_tlb_all (); +}
Quoted 9 lines · Magnus Damm
Add Suspend-to-disk / swsusp /
CONFIG_HIBERNATIONsupport to the SuperH architecture V2.To suspend, use "swapon
/dev/sda2; echo disk >/sys/power/state" To resume, pass "resume=/dev/sda2" on the kernel command line.The patch "pm: rework includes, remove arch ifdefs V2" is needed to allow the generic swsusp code to build properly.
Quoted 8 lines
Hibernation is not enabled with this patch though, a patch setting
ARCH_HIBERNATION_POSSIBLEwill be submitted later.Signed-off-by Magnus Damm <[email protected]>---
V2 contains changes according to feedback from Paul.
This is a good start anyways, applied.