riscv: Do not save the scratch CSR during suspend
authorSamuel Holland <samuel.holland@sifive.com>
Tue, 12 Mar 2024 19:56:38 +0000 (12:56 -0700)
committerPalmer Dabbelt <palmer@rivosinc.com>
Sun, 28 Apr 2024 21:50:36 +0000 (14:50 -0700)
While the processor is executing kernel code, the value of the scratch
CSR is always zero, so there is no need to save the value. Continue to
write the CSR during the resume flow, so we do not rely on firmware to
initialize it.

Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
Link: https://lore.kernel.org/r/20240312195641.1830521-1-samuel.holland@sifive.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
arch/riscv/include/asm/suspend.h
arch/riscv/kernel/suspend.c

index 4718096fa5e3fc19306239de2ecfa353fc755991..4ffb022b097f42b084b3328de8f10a8d87d28355 100644 (file)
@@ -13,7 +13,6 @@ struct suspend_context {
        /* Saved and restored by low-level functions */
        struct pt_regs regs;
        /* Saved and restored by high-level functions */
-       unsigned long scratch;
        unsigned long envcfg;
        unsigned long tvec;
        unsigned long ie;
index 8a327b485b90e7c690d33c92b144b114b998a3a8..c8cec0cc5833c464eb6e29df8b3106676c83e208 100644 (file)
@@ -14,7 +14,6 @@
 
 void suspend_save_csrs(struct suspend_context *context)
 {
-       context->scratch = csr_read(CSR_SCRATCH);
        if (riscv_cpu_has_extension_unlikely(smp_processor_id(), RISCV_ISA_EXT_XLINUXENVCFG))
                context->envcfg = csr_read(CSR_ENVCFG);
        context->tvec = csr_read(CSR_TVEC);
@@ -37,7 +36,7 @@ void suspend_save_csrs(struct suspend_context *context)
 
 void suspend_restore_csrs(struct suspend_context *context)
 {
-       csr_write(CSR_SCRATCH, context->scratch);
+       csr_write(CSR_SCRATCH, 0);
        if (riscv_cpu_has_extension_unlikely(smp_processor_id(), RISCV_ISA_EXT_XLINUXENVCFG))
                csr_write(CSR_ENVCFG, context->envcfg);
        csr_write(CSR_TVEC, context->tvec);