mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2026-11-19 02:21:38 +00:00
lib: sbi: report smrnmi_handlers_init failures instead of ignoring them
smrnmi_handlers_init returned void, so a failed callback went unreported and NMIE was enabled anyway. Change it to return int and skip enabling NMIE on failure. Also update the doc comment on rnmi_handler to use SBI_OK instead of SBI_SUCCESS, so both callbacks consistently reference the correct firmware-internal success constant rather than the ecall-facing one. 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-2-e9dd31152515@sifive.com Signed-off-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
1 parent
54fad5bdda
commit
894435d28f
2 files changed
+20
-8
No files matched your search
@@ -157,12 +157,13 @@ struct sbi_platform_operations {
|
||||
/** platform specific Smrnmi handlers init on current HART.
|
||||
* May be called more than once on the same HART (e.g. once
|
||||
* during boot feature detection and again during hart
|
||||
* re-init), so it must be safe to call repeatedly. */
|
||||
void (*smrnmi_handlers_init)(void (*rnmi_handler)(void),
|
||||
* re-init), so it must be safe to call repeatedly.
|
||||
* Returns SBI_OK on success, error code otherwise. */
|
||||
int (*smrnmi_handlers_init)(void (*rnmi_handler)(void),
|
||||
void (*rnme_handler)(void));
|
||||
|
||||
/** platform specific Smrnmi NMI handler.
|
||||
* Returns SBI_SUCCESS on success, error code if NMI cannot be handled. */
|
||||
* Returns SBI_OK on success, error code if NMI cannot be handled. */
|
||||
int (*rnmi_handler)(struct sbi_trap_context *tcntx);
|
||||
};
|
||||
|
||||
|
||||
+16
-5
@@ -464,15 +464,16 @@ static int hart_mhpm_get_allowed_bits(void)
|
||||
return num_bits;
|
||||
}
|
||||
|
||||
static void smrnmi_hart_init(struct sbi_scratch *scratch)
|
||||
static int 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);
|
||||
int ret;
|
||||
|
||||
if (!sbi_hart_has_extension(scratch, SBI_HART_EXT_SMRNMI))
|
||||
return;
|
||||
return 0;
|
||||
|
||||
plat = sbi_platform_thishart_ptr();
|
||||
ops = sbi_platform_ops(plat);
|
||||
@@ -482,13 +483,17 @@ static void smrnmi_hart_init(struct sbi_scratch *scratch)
|
||||
|
||||
/* 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);
|
||||
ret = ops->smrnmi_handlers_init(_trap_rnmi_handler, _trap_handler);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
/* Initialize MNSCRATCH for the RNMI handler */
|
||||
csr_write(CSR_MNSCRATCH, scratch);
|
||||
|
||||
/* Enable NMIs */
|
||||
csr_set(CSR_MNSTATUS, MNSTATUS_NMIE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int hart_detect_features(struct sbi_scratch *scratch, bool cold_boot)
|
||||
@@ -516,7 +521,9 @@ static int hart_detect_features(struct sbi_scratch *scratch, bool cold_boot)
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
smrnmi_hart_init(scratch);
|
||||
rc = smrnmi_hart_init(scratch);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
#define __check_hpm_csr(__csr, __mask) \
|
||||
oldval = csr_read_allowed(__csr, &trap); \
|
||||
@@ -701,7 +708,11 @@ __pmp_skip:
|
||||
|
||||
int sbi_hart_reinit(struct sbi_scratch *scratch)
|
||||
{
|
||||
smrnmi_hart_init(scratch);
|
||||
int rc;
|
||||
|
||||
rc = smrnmi_hart_init(scratch);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
mstatus_init(scratch);
|
||||
|
||||
|
||||
Reference in new issue
Block a user