Skip to content

Commit ffef54a

Browse files
nick650823Alexandre Ghiti
authored andcommitted
riscv: Add stimecmp save and restore
If the HW support the SSTC extension, we should save and restore the stimecmp register while cpu non retention suspend. Signed-off-by: Nick Hu <[email protected]> Reviewed-by: Anup Patel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexandre Ghiti <[email protected]>
1 parent 6586788 commit ffef54a

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

arch/riscv/include/asm/suspend.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ struct suspend_context {
1818
unsigned long ie;
1919
#ifdef CONFIG_MMU
2020
unsigned long satp;
21+
unsigned long stimecmp;
22+
#if __riscv_xlen < 64
23+
unsigned long stimecmph;
24+
#endif
2125
#endif
2226
};
2327

arch/riscv/kernel/suspend.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ void suspend_save_csrs(struct suspend_context *context)
3030
*/
3131

3232
#ifdef CONFIG_MMU
33+
if (riscv_has_extension_unlikely(RISCV_ISA_EXT_SSTC)) {
34+
context->stimecmp = csr_read(CSR_STIMECMP);
35+
#if __riscv_xlen < 64
36+
context->stimecmph = csr_read(CSR_STIMECMPH);
37+
#endif
38+
}
39+
3340
context->satp = csr_read(CSR_SATP);
3441
#endif
3542
}
@@ -43,6 +50,13 @@ void suspend_restore_csrs(struct suspend_context *context)
4350
csr_write(CSR_IE, context->ie);
4451

4552
#ifdef CONFIG_MMU
53+
if (riscv_has_extension_unlikely(RISCV_ISA_EXT_SSTC)) {
54+
csr_write(CSR_STIMECMP, context->stimecmp);
55+
#if __riscv_xlen < 64
56+
csr_write(CSR_STIMECMPH, context->stimecmph);
57+
#endif
58+
}
59+
4660
csr_write(CSR_SATP, context->satp);
4761
#endif
4862
}

0 commit comments

Comments
 (0)