lib: sbi: extract smrnmi_hart_init() and call on non-retentive resume

On non-retentive suspend resume, the hart never initializes the
Smrnmi CSRs the way hart_detect_features() does at boot, so a hart
waking from non-retentive suspend resumes with NMIs disabled and no
RNMI handler installed.

Extract the setup into smrnmi_hart_init() and call it from both
hart_detect_features() and sbi_hart_reinit().

Fixes: 2d211fe6f9 ("lib: sbi: hart: Detect and enable Smrnmi before trap-based feature detection")
Signed-off-by: Nylon Chen <nylon.chen@sifive.com>
Co-developed-by: Nia Su <nia.su@sifive.com>
Signed-off-by: Nia Su <nia.su@sifive.com>
Reviewed-by: Evgeny Voevodin <evvoevod@tenstorrent.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Link: https://lore.kernel.org/r/20260915-smrnmi-context-restore-v3-1-e9dd31152515@sifive.com
Signed-off-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
Nia Su authored and Anup Patel committed 2026-11-03 13:15:33 +05:30
1 parent c9a7d00992
commit 54fad5bdda
2 files changed
+34 -26

No files matched your search

+30 -25
View File
@@ -464,6 +464,33 @@ static int hart_mhpm_get_allowed_bits(void)
return num_bits;
}
static void smrnmi_hart_init(struct sbi_scratch *scratch)
{
const struct sbi_platform *plat;
const struct sbi_platform_operations *ops;
extern void _trap_rnmi_handler(void);
extern void _trap_handler(void);
if (!sbi_hart_has_extension(scratch, SBI_HART_EXT_SMRNMI))
return;
plat = sbi_platform_thishart_ptr();
ops = sbi_platform_ops(plat);
if (!ops || !ops->smrnmi_handlers_init)
sbi_panic("Smrnmi detected, but platform lacks smrnmi_handlers_init callback\n");
/* Reuse _trap_handler for the RNME slot since RNME is taken
* as a regular M-mode trap with NMIE=0. */
ops->smrnmi_handlers_init(_trap_rnmi_handler, _trap_handler);
/* Initialize MNSCRATCH for the RNMI handler */
csr_write(CSR_MNSCRATCH, scratch);
/* Enable NMIs */
csr_set(CSR_MNSTATUS, MNSTATUS_NMIE);
}
static int hart_detect_features(struct sbi_scratch *scratch, bool cold_boot)
{
struct sbi_trap_info trap = {0};
@@ -489,25 +516,7 @@ static int hart_detect_features(struct sbi_scratch *scratch, bool cold_boot)
if (rc)
return rc;
if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SMRNMI)) {
const struct sbi_platform *plat = sbi_platform_thishart_ptr();
const struct sbi_platform_operations *ops = sbi_platform_ops(plat);
extern void _trap_rnmi_handler(void);
extern void _trap_handler(void);
if (!ops || !ops->smrnmi_handlers_init)
sbi_panic("Smrnmi detected, but platform lacks smrnmi_handlers_init callback\n");
/* Reuse _trap_handler for the RNME slot since RNME is taken
* as a regular M-mode trap with NMIE=0. */
ops->smrnmi_handlers_init(_trap_rnmi_handler, _trap_handler);
/* Initialize MNSCRATCH for the RNMI handler */
csr_write(CSR_MNSCRATCH, scratch);
/* Enable NMIs */
csr_set(CSR_MNSTATUS, MNSTATUS_NMIE);
}
smrnmi_hart_init(scratch);
#define __check_hpm_csr(__csr, __mask) \
oldval = csr_read_allowed(__csr, &trap); \
@@ -692,15 +701,11 @@ __pmp_skip:
int sbi_hart_reinit(struct sbi_scratch *scratch)
{
int rc;
smrnmi_hart_init(scratch);
mstatus_init(scratch);
rc = fp_init(scratch);
if (rc)
return rc;
return 0;
return fp_init(scratch);
}
int sbi_hart_init(struct sbi_scratch *scratch, bool cold_boot)