@@ -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);
};
@@ -466,15 +466,16 @@ static int hart_mhpm_get_allowed_bits(void)
return num_bits;
}
-static void sbi_smrnmi_hart_init(struct sbi_scratch *scratch)
+static int sbi_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);
@@ -484,13 +485,17 @@ static void sbi_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)
@@ -514,7 +519,9 @@ static int hart_detect_features(struct sbi_scratch *scratch, bool cold_boot)
if (rc)
return rc;
- sbi_smrnmi_hart_init(scratch);
+ rc = sbi_smrnmi_hart_init(scratch);
+ if (rc)
+ return rc;
#define __check_hpm_csr(__csr, __mask) \
oldval = csr_read_allowed(__csr, &trap); \
@@ -699,7 +706,11 @@ __pmp_skip:
int sbi_hart_reinit(struct sbi_scratch *scratch)
{
- sbi_smrnmi_hart_init(scratch);
+ int rc;
+
+ rc = sbi_smrnmi_hart_init(scratch);
+ if (rc)
+ return rc;
mstatus_init(scratch);