Skip to content

Commit a5edc51

Browse files
author
Alexandre Ghiti
committed
Merge patch series "Support SSTC while PM operations"
Nick Hu <[email protected]> says: When the cpu is going to be hotplug, stop the stimecmp to prevent pending interrupt. When the cpu is going to be suspended, save the stimecmp before entering the suspend state and restore it in the resume path. * patches from https://lore.kernel.org/r/[email protected]: clocksource/drivers/timer-riscv: Stop stimecmp when cpu hotplug riscv: Add stimecmp save and restore Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexandre Ghiti <[email protected]>
2 parents 7f238b1 + 70c93b0 commit a5edc51

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-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
}

drivers/clocksource/timer-riscv.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,13 @@ static int riscv_timer_starting_cpu(unsigned int cpu)
126126

127127
static int riscv_timer_dying_cpu(unsigned int cpu)
128128
{
129+
/*
130+
* Stop the timer when the cpu is going to be offline otherwise
131+
* the timer interrupt may be pending while performing power-down.
132+
*/
133+
riscv_clock_event_stop();
129134
disable_percpu_irq(riscv_clock_event_irq);
135+
130136
return 0;
131137
}
132138

0 commit comments

Comments
 (0)