[PATCH 1/3] lib: sbi_hsm: Save mideleg across non-retentive suspend

Anup Patel anup at brainfault.org
Mon Sep 15 21:40:46 PDT 2025


On Mon, Sep 8, 2025 at 11:26 AM Samuel Holland
<samuel.holland at sifive.com> wrote:
>
> 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 <samuel.holland at sifive.com>

LGTM.

Reviewed-by: Anup Patel <anup at brainfault.org>

Applied this patch to the riscv/opensbi repo.

Thanks,
Anup

> ---
>
>  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)));
> --
> 2.47.2
>
> base-commit: 153cdeea5350837c1206a2d2b6189fd0ba06d1f2
> branch: up/mideleg-fix
>
> --
> opensbi mailing list
> opensbi at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/opensbi



More information about the opensbi mailing list