From 55135abcd555b72ca4edf481461fb37acd27e9cc Mon Sep 17 00:00:00 2001 From: Samuel Holland Date: Sun, 7 Sep 2025 22:56:38 -0700 Subject: [PATCH] lib: sbi_hsm: Save mideleg across non-retentive suspend OpenSBI updates mideleg when registering or unregistering the PMU SSE event. The updated CSR value must be saved across non-retentive suspend, or PMU SSE events will not be delivered after the hart is resumed. Fixes: b31a0a24279d ("lib: sbi: pmu: Add SSE register/unregister() callbacks") Signed-off-by: Samuel Holland Reviewed-by: Anup Patel Link: https://lore.kernel.org/r/20250908055646.2391370-1-samuel.holland@sifive.com Signed-off-by: Anup Patel --- lib/sbi/sbi_hsm.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/sbi/sbi_hsm.c b/lib/sbi/sbi_hsm.c index 557ab131..8ec94d2b 100644 --- a/lib/sbi/sbi_hsm.c +++ b/lib/sbi/sbi_hsm.c @@ -47,6 +47,7 @@ struct sbi_hsm_data { unsigned long saved_mie; unsigned long saved_mip; unsigned long saved_medeleg; + unsigned long saved_mideleg; unsigned long saved_menvcfg; #if __riscv_xlen == 32 unsigned long saved_menvcfgh; @@ -429,6 +430,7 @@ void __sbi_hsm_suspend_non_ret_save(struct sbi_scratch *scratch) hdata->saved_mie = csr_read(CSR_MIE); hdata->saved_mip = csr_read(CSR_MIP) & (MIP_SSIP | MIP_STIP); hdata->saved_medeleg = csr_read(CSR_MEDELEG); + hdata->saved_mideleg = csr_read(CSR_MIDELEG); if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_12) { #if __riscv_xlen == 32 hdata->saved_menvcfgh = csr_read(CSR_MENVCFGH); @@ -448,6 +450,7 @@ static void __sbi_hsm_suspend_non_ret_restore(struct sbi_scratch *scratch) csr_write(CSR_MENVCFGH, hdata->saved_menvcfgh); #endif } + csr_write(CSR_MIDELEG, hdata->saved_mideleg); csr_write(CSR_MEDELEG, hdata->saved_medeleg); csr_write(CSR_MIE, hdata->saved_mie); csr_set(CSR_MIP, (hdata->saved_mip & (MIP_SSIP | MIP_STIP)));