public inbox for opensbi@lists.infradead.org
 help / color / mirror / Atom feed
From: Nylon Chen <nylon.chen@sifive.com>
To: opensbi@lists.infradead.org
Cc: zong.li@sifive.com, nick.hu@sifive.com,
	samuel.holland@sifive.com, yongxuan.wang@sifive.com,
	anup@brainfault.org, rkrcmar@qti.qualcomm.com,
	atishp@rivosinc.com, Nylon Chen <nylon.chen@sifive.com>
Subject: [PATCH v4 0/3] Add support for RISC-V Smrnmi extension
Date: Fri, 13 Mar 2026 06:39:38 -0700	[thread overview]
Message-ID: <20260313133941.3012966-1-nylon.chen@sifive.com> (raw)

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@sifive.com>
Signed-off-by: Zong Li <zong.li@sifive.com>
Suggested-by: Nick Hu <nick.hu@sifive.com>
Suggested-by: Samuel Holland <samuel.holland@sifive.com>
Signed-off-by: Nylon Chen <nylon.chen@sifive.com>
Signed-off-by: Yong-Xuan Wang <yongxuan.wang@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


-- 
opensbi mailing list
opensbi@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

             reply	other threads:[~2026-03-13 13:39 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-13 13:39 Nylon Chen [this message]
2026-03-13 13:39 ` [PATCH v4 1/3] lib: sbi: Add Smrnmi extension detection Nylon Chen
2026-03-13 13:39 ` [PATCH v4 2/3] lib: sbi: Enable Smrnmi extension handler Nylon Chen
2026-03-13 13:39 ` [PATCH v4 3/3] firmware: fw_base.S: Add common NMI trap handler Nylon Chen
2026-03-13 16:03 ` [PATCH v4 0/3] Add support for RISC-V Smrnmi extension Nylon Chen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260313133941.3012966-1-nylon.chen@sifive.com \
    --to=nylon.chen@sifive.com \
    --cc=anup@brainfault.org \
    --cc=atishp@rivosinc.com \
    --cc=nick.hu@sifive.com \
    --cc=opensbi@lists.infradead.org \
    --cc=rkrcmar@qti.qualcomm.com \
    --cc=samuel.holland@sifive.com \
    --cc=yongxuan.wang@sifive.com \
    --cc=zong.li@sifive.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox