[PATCH 2/3] lib: sbi: Enable Smrnmi extension handler

Radim Krcmar rkrcmar at qti.qualcomm.com
Mon Feb 2 07:26:33 PST 2026


2026-01-29T00:13:42-08:00, Nylon Chen <nylon.chen at sifive.com>:
> Enable the Smrnmi extension by:
> 1. Adding sbi_rnmi_vector_init() to allocate per-HART RNMI context and enable RNMI via MNSTATUS.NMIE
> 2. Saving and restoring CSR_MNSCRATCH and CSR_MNSTATUS across non-retentive suspend/resume
> 3. Calling sbi_rnmi_vector_init() from the cold and warm init paths
>
> Co-developed-by: Zong Li <zong.li at sifive.com>
> Signed-off-by: Zong Li <zong.li at sifive.com>
> Suggested-by: Nick Hu <nick.hu at sifive.com>
> Suggested-by: Samuel Holland <samuel.holland at sifive.com>
> Signed-off-by: Nylon Chen <nylon.chen at sifive.com>
> Signed-off-by: Yong-Xuan Wang <yongxuan.wang at sifive.com>
> ---
> diff --git a/include/sbi/sbi_platform.h b/include/sbi/sbi_platform.h
> @@ -149,6 +149,15 @@ struct sbi_platform_operations {
>  			unsigned long log2len);
>  	/** platform specific pmp disable on current HART */
>  	void (*pmp_disable)(unsigned int n);
> +	/**
> +	 * Platform-specific helper to program the RNMI trap vector.
> +	 *
> +	 * The core will call this from sbi_rnmi_vector_init() with the
> +	 * firmware RNMI handler entry address (rnmi_handler) and the
> +	 * cold_boot flag. Platforms that support Smrnmi should implement
> +	 * this; others can leave it NULL.
> +	 */

If the hart supports Smrnmi, then it begins with nmstatus.NMIE=0, which
means that any exception is going to enter a critical state.
The platform must somehow support Smrnmi to be useful, and I think it
would be better not to do it behind opensbi's back.

If the platform wants to handle Smrnmi itself, it can hide Smrnmi from
opensbi, so I think the requirement here would be better as MUST.

> +	int (*set_rnmi_trap_vector)(uintptr_t handler_addr, bool cold_boot);
> diff --git a/lib/sbi/sbi_init.c b/lib/sbi/sbi_init.c
> @@ -273,6 +273,10 @@ static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid)
>  	if (rc)
>  		sbi_hart_hang();
>  
> +	rc = sbi_rnmi_vector_init(scratch, true);

Are we sure that earlier opensbi code won't try to trigger a trap before
this point?  OpenSBI would fail to boot if it did...

Thanks.


More information about the opensbi mailing list