@@ -13,6 +13,7 @@ struct suspend_context {
/* Saved and restored by low-level functions */
struct pt_regs regs;
/* Saved and restored by high-level functions */
+ unsigned long scontext;
unsigned long scratch;
unsigned long envcfg;
unsigned long tvec;
@@ -8,6 +8,7 @@
#include <linux/jump_label.h>
#include <linux/sched/task_stack.h>
+#include <linux/pid.h>
#include <asm/vector.h>
#include <asm/cpufeature.h>
#include <asm/processor.h>
@@ -75,6 +76,12 @@ static __always_inline bool has_scontext(void)
return static_branch_likely(&use_scontext);
}
+static __always_inline void __switch_to_scontext(struct task_struct *__prev,
+ struct task_struct *__next)
+{
+ csr_write(CSR_SCONTEXT, task_pid_nr(__next));
+}
+
extern struct task_struct *__switch_to(struct task_struct *,
struct task_struct *);
@@ -86,6 +93,8 @@ do { \
__switch_to_fpu(__prev, __next); \
if (has_vector()) \
__switch_to_vector(__prev, __next); \
+ if (has_scontext()) \
+ __switch_to_scontext(__prev, __next); \
((last) = __switch_to(__prev, __next)); \
} while (0)
@@ -11,9 +11,13 @@
#include <asm/csr.h>
#include <asm/sbi.h>
#include <asm/suspend.h>
+#include <asm/switch_to.h>
void suspend_save_csrs(struct suspend_context *context)
{
+ if (has_scontext())
+ context->scontext = csr_read(CSR_SCONTEXT);
+
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);
@@ -46,6 +50,9 @@ void suspend_save_csrs(struct suspend_context *context)
void suspend_restore_csrs(struct suspend_context *context)
{
+ if (has_scontext())
+ csr_write(CSR_SCONTEXT, context->scontext);
+
csr_write(CSR_SCRATCH, context->scratch);
if (riscv_cpu_has_extension_unlikely(smp_processor_id(), RISCV_ISA_EXT_XLINUXENVCFG))
csr_write(CSR_ENVCFG, context->envcfg);