Skip to content

Commit 1d8b120

Browse files
committed
arch/riscv: Fix NMI delivery for SMRNMI hardware
Add SMRNMI extension support and enable NMI delivery on boot. Changes: - Add CONFIG_RISCV_ISA_EXT_SMRNMI Kconfig option - Define SMRNMI CSRs in arch/riscv/include/csr.h - Set NMIE bit during boot to enable NMI delivery SMRNMI hardware generates but doesn't deliver NMIs when NMIE=0 (default). This causes twister test failures and prevents handling of critical hardware events like watchdog NMIs and ECC errors. Setting NMIE=1 is mandatory for correct operation on SMRNMI SOCs. Signed-off-by: Afonso Oliveira <[email protected]>
1 parent 521d948 commit 1d8b120

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

arch/riscv/Kconfig.isa

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,17 @@ config RISCV_ISA_EXT_C
9999
which reduces static and dynamic code size by adding short 16-bit
100100
instruction encodings for common operations.
101101

102+
config RISCV_ISA_EXT_SMRNMI
103+
bool
104+
help
105+
(Smrnmi) - Standard Extension for Resumable Non-Maskable Interrupts
106+
107+
The Smrnmi extension adds support for resumable non-maskable
108+
interrupts (RNMIs) to RISC-V. This extension provides architectural
109+
support for hardware error conditions, watchdog timers, and other
110+
critical events that require immediate attention while preserving
111+
the ability to resume execution after handling.
112+
102113
config RISCV_ISA_EXT_ZICNTR
103114
bool
104115
depends on RISCV_ISA_EXT_ZICSR

arch/riscv/core/reset.S

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ aa_loop:
8282
li t0, __z_interrupt_stack_SIZEOF
8383
add sp, sp, t0
8484

85+
#ifdef CONFIG_RISCV_ISA_EXT_SMRNMI
86+
csrs CSR_MNSTATUS, MNSTATUS_NMIE
87+
#endif
88+
8589
#ifdef CONFIG_WDOG_INIT
8690
call _WdogInit
8791
#endif

include/zephyr/arch/riscv/csr.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,17 @@
156156
#define IRQ_COP 12
157157
#define IRQ_HOST 13
158158

159+
/* SMRNMI CSR addresses */
160+
#ifdef CONFIG_RISCV_ISA_EXT_SMRNMI
161+
#define CSR_MNSCRATCH 0x740
162+
#define CSR_MNEPC 0x741
163+
#define CSR_MNCAUSE 0x742
164+
#define CSR_MNSTATUS 0x744
165+
166+
/* MNSTATUS bit fields */
167+
#define MNSTATUS_NMIE 0x00000008 /* NMI Enable (bit 3) */
168+
#endif /* CONFIG_RISCV_ISA_EXT_SMRNMI */
169+
159170
#define DEFAULT_RSTVEC 0x00001000
160171
#define CLINT_BASE 0x02000000
161172
#define CLINT_SIZE 0x000c0000

0 commit comments

Comments
 (0)