* [PATCH v4 1/2] riscv: Add stimecmp save and restore
[not found] <20250219114135.27764-1-nick.hu@sifive.com>
@ 2025-02-19 11:41 ` Nick Hu
2025-02-19 11:41 ` [PATCH v4 2/2] clocksource/drivers/timer-riscv: Stop stimecmp when cpu hotplug Nick Hu
1 sibling, 0 replies; 3+ messages in thread
From: Nick Hu @ 2025-02-19 11:41 UTC (permalink / raw)
To: Rafael J. Wysocki, Pavel Machek, Paul Walmsley, Palmer Dabbelt,
Albert Ou
Cc: Nick Hu, linux-pm, linux-riscv, linux-kernel
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 <nick.hu@sifive.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
---
arch/riscv/include/asm/suspend.h | 4 ++++
arch/riscv/kernel/suspend.c | 14 ++++++++++++++
2 files changed, 18 insertions(+)
diff --git a/arch/riscv/include/asm/suspend.h b/arch/riscv/include/asm/suspend.h
index 4ffb022b097f..dc5782b5fbad 100644
--- a/arch/riscv/include/asm/suspend.h
+++ b/arch/riscv/include/asm/suspend.h
@@ -18,6 +18,10 @@ struct suspend_context {
unsigned long ie;
#ifdef CONFIG_MMU
unsigned long satp;
+ unsigned long stimecmp;
+#if __riscv_xlen < 64
+ unsigned long stimecmph;
+#endif
#endif
};
diff --git a/arch/riscv/kernel/suspend.c b/arch/riscv/kernel/suspend.c
index 9a8a0dc035b2..24b3f57d467f 100644
--- a/arch/riscv/kernel/suspend.c
+++ b/arch/riscv/kernel/suspend.c
@@ -30,6 +30,13 @@ void suspend_save_csrs(struct suspend_context *context)
*/
#ifdef CONFIG_MMU
+ if (riscv_has_extension_unlikely(RISCV_ISA_EXT_SSTC)) {
+ context->stimecmp = csr_read(CSR_STIMECMP);
+#if __riscv_xlen < 64
+ context->stimecmph = csr_read(CSR_STIMECMPH);
+#endif
+ }
+
context->satp = csr_read(CSR_SATP);
#endif
}
@@ -43,6 +50,13 @@ void suspend_restore_csrs(struct suspend_context *context)
csr_write(CSR_IE, context->ie);
#ifdef CONFIG_MMU
+ if (riscv_has_extension_unlikely(RISCV_ISA_EXT_SSTC)) {
+ csr_write(CSR_STIMECMP, context->stimecmp);
+#if __riscv_xlen < 64
+ csr_write(CSR_STIMECMPH, context->stimecmph);
+#endif
+ }
+
csr_write(CSR_SATP, context->satp);
#endif
}
--
2.17.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v4 2/2] clocksource/drivers/timer-riscv: Stop stimecmp when cpu hotplug
[not found] <20250219114135.27764-1-nick.hu@sifive.com>
2025-02-19 11:41 ` [PATCH v4 1/2] riscv: Add stimecmp save and restore Nick Hu
@ 2025-02-19 11:41 ` Nick Hu
2025-02-19 12:48 ` Daniel Lezcano
1 sibling, 1 reply; 3+ messages in thread
From: Nick Hu @ 2025-02-19 11:41 UTC (permalink / raw)
To: Daniel Lezcano, Thomas Gleixner, Paul Walmsley, Palmer Dabbelt,
Albert Ou
Cc: Nick Hu, linux-kernel, linux-riscv
Stop the timer when the cpu is going to be offline otherwise the
timer interrupt may be pending while performing power-down.
Suggested-by: Anup Patel <anup@brainfault.org>
Link: https://lore.kernel.org/lkml/20240829033904.477200-3-nick.hu@sifive.com/T/#u
Signed-off-by: Nick Hu <nick.hu@sifive.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
---
drivers/clocksource/timer-riscv.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/clocksource/timer-riscv.c b/drivers/clocksource/timer-riscv.c
index 48ce50c5f5e6..4d7cf338824a 100644
--- a/drivers/clocksource/timer-riscv.c
+++ b/drivers/clocksource/timer-riscv.c
@@ -126,7 +126,13 @@ static int riscv_timer_starting_cpu(unsigned int cpu)
static int riscv_timer_dying_cpu(unsigned int cpu)
{
+ /*
+ * Stop the timer when the cpu is going to be offline otherwise
+ * the timer interrupt may be pending while performing power-down.
+ */
+ riscv_clock_event_stop();
disable_percpu_irq(riscv_clock_event_irq);
+
return 0;
}
--
2.17.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v4 2/2] clocksource/drivers/timer-riscv: Stop stimecmp when cpu hotplug
2025-02-19 11:41 ` [PATCH v4 2/2] clocksource/drivers/timer-riscv: Stop stimecmp when cpu hotplug Nick Hu
@ 2025-02-19 12:48 ` Daniel Lezcano
0 siblings, 0 replies; 3+ messages in thread
From: Daniel Lezcano @ 2025-02-19 12:48 UTC (permalink / raw)
To: Nick Hu, Thomas Gleixner, Paul Walmsley, Palmer Dabbelt, Albert Ou
Cc: linux-kernel, linux-riscv
On 19/02/2025 12:41, Nick Hu wrote:
> Stop the timer when the cpu is going to be offline otherwise the
> timer interrupt may be pending while performing power-down.
>
> Suggested-by: Anup Patel <anup@brainfault.org>
> Link: https://lore.kernel.org/lkml/20240829033904.477200-3-nick.hu@sifive.com/T/#u
> Signed-off-by: Nick Hu <nick.hu@sifive.com>
> Reviewed-by: Anup Patel <anup@brainfault.org>
> ---
Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
--
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs
Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-02-19 12:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <20250219114135.27764-1-nick.hu@sifive.com>
2025-02-19 11:41 ` [PATCH v4 1/2] riscv: Add stimecmp save and restore Nick Hu
2025-02-19 11:41 ` [PATCH v4 2/2] clocksource/drivers/timer-riscv: Stop stimecmp when cpu hotplug Nick Hu
2025-02-19 12:48 ` Daniel Lezcano
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®