From: Sia Jee Heng Date: Mon, 17 Oct 2022 02:25:05 +0000 (+0800) Subject: riscv: kernel: Expand functionlity of swsusp_arch_suspend for JH7110 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=90957965b19514a7f82b1e97a516db2724c40f0a;p=platform%2Fkernel%2Flinux-starfive.git riscv: kernel: Expand functionlity of swsusp_arch_suspend for JH7110 Futher expand the functionality of the swsusp_arch_suspend so that the hibernated image can be written to the disk and resume from the hibernated image. Signed-off-by: Sia Jee Heng --- diff --git a/arch/riscv/include/asm/suspend.h b/arch/riscv/include/asm/suspend.h index 9a5880c452b8..9a98e0db6648 100644 --- a/arch/riscv/include/asm/suspend.h +++ b/arch/riscv/include/asm/suspend.h @@ -21,6 +21,11 @@ struct suspend_context { #endif }; +/* This value will be assigned to 0 during resume and will be used by + * hibernation core for the subsequent resume sequence + */ +extern int in_suspend; + /* Low-level CPU suspend entry function */ int __cpu_suspend_enter(struct suspend_context *context); @@ -42,4 +47,7 @@ int arch_hibernation_header_restore(void *addr); /* Used to resume on the CPU we hibernated on */ int hibernate_resume_nonboot_cpu_disable(void); +/* Used to save and restore the csr */ +void suspend_save_csrs(struct suspend_context *context); +void suspend_restore_csrs(struct suspend_context *context); #endif diff --git a/arch/riscv/kernel/hibernate.c b/arch/riscv/kernel/hibernate.c index 83471b76ab79..603c43543e99 100644 --- a/arch/riscv/kernel/hibernate.c +++ b/arch/riscv/kernel/hibernate.c @@ -30,6 +30,9 @@ */ static int sleep_cpu = -EINVAL; +/* CPU context to be saved */ +struct suspend_context context = { 0 }; + /* * Values that may not change over hibernate/resume. We put the build number * and date in here so that we guarantee not to resume with a different @@ -123,7 +126,25 @@ EXPORT_SYMBOL(arch_hibernation_header_restore); int swsusp_arch_suspend(void) { - return 0; + int ret = 0; + + if (__cpu_suspend_enter(&context)) { + sleep_cpu = smp_processor_id(); + suspend_save_csrs(&context); + ret = swsusp_save(); + } else { + local_flush_icache_all(); + + /* + * Tell the hibernation core that we've just restored + * the memory + */ + in_suspend = 0; + + sleep_cpu = -EINVAL; + } + + return ret; } int swsusp_arch_resume(void) diff --git a/arch/riscv/kernel/suspend.c b/arch/riscv/kernel/suspend.c index 9ba24fb8cc93..3c89b8ec69c4 100644 --- a/arch/riscv/kernel/suspend.c +++ b/arch/riscv/kernel/suspend.c @@ -8,7 +8,7 @@ #include #include -static void suspend_save_csrs(struct suspend_context *context) +void suspend_save_csrs(struct suspend_context *context) { context->scratch = csr_read(CSR_SCRATCH); context->tvec = csr_read(CSR_TVEC); @@ -29,7 +29,7 @@ static void suspend_save_csrs(struct suspend_context *context) #endif } -static void suspend_restore_csrs(struct suspend_context *context) +void suspend_restore_csrs(struct suspend_context *context) { csr_write(CSR_SCRATCH, context->scratch); csr_write(CSR_TVEC, context->tvec);