[PATCH v4 0/3] Add support for RISC-V Smrnmi extension
Nylon Chen
nylon.chen at sifive.com
Fri Mar 13 09:03:29 PDT 2026
Sorry, please ignore this v4 series. It was sent before I had fully
reviewed the ongoing discussion, particularly Nick's comments and
Evgeny's Smrnmi series for Ascalon.
I will take time to review their work carefully and send a revised
version that better aligns with the direction of the discussion.
Apologies for the noise.
Thanks,
Nylon
Nylon Chen <nylon.chen at sifive.com> 於 2026年3月13日週五 下午9:39寫道:
>
> This patch series adds support for the RISC-V Smrnmi (Resumable
> Non-Maskable Interrupts) extension to OpenSBI.
>
> 1. PATCH 1/3: Add Smrnmi extension detection
> - Defines Smrnmi CSR registers (MNSCRATCH, MNEPC, MNCAUSE, MNSTATUS)
> - Defines MNSTATUS bit fields (NMIE, MNPV, MNPELP, MNPP)
> - Registers the Smrnmi extension in hart extension enumeration
>
> 2. PATCH 2/3: Enable Smrnmi extension handler
> - Implements rnmi_vector_init() as a static function in sbi_hart.c
> - Sets MNSCRATCH to the scratch pointer (same role as MSCRATCH)
> - Adds platform operation set_rnmi_trap_vector() for trap vector programming
> - Adds suspend/resume support for RNMI CSRs (MNSCRATCH, MNSTATUS)
> - Calls rnmi_vector_init() at the end of sbi_hart_init()
> - Note: Does not yet enable RNMI; trap vector setup deferred to Patch 3
>
> 3. PATCH 3/3: Add common NMI trap handler
> - Implements sbi_rnmi_vector assembly entry point in fw_base.S
> - Checks MNSTATUS.MNPP to distinguish S/U-mode vs M-mode interrupts
> - Uses scratch area for S/U-mode interrupts
> - Reuses existing M-mode stack for M-mode interrupts (nested RNMI)
> - Implements default sbi_rnmi_trap_handler() in C (marked __attribute__((weak)))
> - Completes rnmi_vector_init() with platform hook call and NMIE enablement
>
> Changes in v4:
> - Added MNSTATUS.MNPELP bit definition (for Zicfilp extension)
> - Made rnmi_vector_init() a static function and removed global declaration
> - Moved rnmi_vector_init() call from sbi_init.c to end of sbi_hart_init()
> - Changed set_rnmi_trap_vector() parameter type from uintptr_t to unsigned long
> - Changed platform hook requirement from "should" to "must" in documentation
> - Simplified MNSCRATCH setup: directly use scratch pointer instead of allocating
> separate RNMI context (addresses Radim's feedback on stack space)
> - Rewrote sbi_rnmi_vector to check MNSTATUS.MNPP and reuse M-mode stack for
> nested RNMI (addresses Radim's feedback on M-mode stack reuse)
> - Removed RNMI_SAVE_REGS/RNMI_RESTORE_REGS macros in favor of explicit
> register save/restore for better control
> - Added sbi_rnmi_trap_handler() declaration in sbi_trap.h
> - Changed printf format from %016lx to PRILX macro for 32/64-bit compatibility
> - Fixed patch structure: Patch 2 now only sets up MNSCRATCH; Patch 3 completes
> the initialization with trap vector setup and NMIE enablement (ensures each
> patch can be compiled independently)
> - Marked sbi_rnmi_trap_handler() as __attribute__((weak)) to allow platform override
>
> Changes in v3:
> - Split single patch into three-patch series per Anup's feedback:
> * PATCH 1: Add Smrnmi extension detection (without enabling NMI)
> * PATCH 2: Enable Smrnmi extension handler
> * PATCH 3: Add common NMI trap handler in fw_base.S
> - Added platform abstraction via set_rnmi_trap_vector() callback
> - Added per-HART RNMI context allocation
> - Added suspend/resume support for RNMI CSRs
>
> Changes in v2:
> - Remove hart_smrnmi_get_allowed() and use sbi_hart_has_extension() for
> Smrnmi detection
>
> 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>
>
> Nylon Chen (3):
> lib: sbi: Add Smrnmi extension detection
> lib: sbi: Enable Smrnmi extension handler
> firmware: fw_base.S: Add common NMI trap handler
>
> firmware/fw_base.S | 141 +++++++++++++++++++++++++++++++++++
> include/sbi/riscv_encoding.h | 12 +++
> include/sbi/sbi_hart.h | 2 +
> include/sbi/sbi_platform.h | 8 ++
> include/sbi/sbi_trap.h | 22 +++++-
> lib/sbi/sbi_hart.c | 54 +++++++++++++-
> lib/sbi/sbi_hsm.c | 14 ++++
> lib/sbi/sbi_trap.c | 17 +++++
> 8 files changed, 267 insertions(+), 3 deletions(-)
>
> --
> 2.43.7
>
More information about the opensbi
mailing list