diff --git a/include/sbi/sbi_platform.h b/include/sbi/sbi_platform.h index 0a1e7eee..2cfb0976 100644 --- a/include/sbi/sbi_platform.h +++ b/include/sbi/sbi_platform.h @@ -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); }; diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c index c3b5785d..50d1a345 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -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);