riscv: kernel: Expand functionlity of swsusp_arch_suspend for JH7110
authorSia Jee Heng <jeeheng.sia@starfivetech.com>
Mon, 17 Oct 2022 02:25:05 +0000 (10:25 +0800)
committermason.huo <mason.huo@starfivetech.com>
Thu, 5 Jan 2023 05:24:40 +0000 (13:24 +0800)
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 <jeeheng.sia@starfivetech.com>
arch/riscv/include/asm/suspend.h
arch/riscv/kernel/hibernate.c
arch/riscv/kernel/suspend.c

index 9a5880c..9a98e0d 100644 (file)
@@ -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
index 83471b7..603c435 100644 (file)
@@ -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)
index 9ba24fb..3c89b8e 100644 (file)
@@ -8,7 +8,7 @@
 #include <asm/csr.h>
 #include <asm/suspend.h>
 
-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);