From 78e8c0dea5165f809864c1fbceba1c05d232cf11 Mon Sep 17 00:00:00 2001 From: Yanfeng Liu Date: Sun, 14 Jan 2024 12:20:01 +0800 Subject: [PATCH] risc-v/nuttsbi: add device specific initialization hook Some devices have special preparations before entering S-mode, thus a hook is needed from NUTTSBI to give them the chance. Signed-off-by: Yanfeng Liu --- arch/risc-v/src/nuttsbi/sbi_internal.h | 12 ++++++++++++ arch/risc-v/src/nuttsbi/sbi_start.c | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/arch/risc-v/src/nuttsbi/sbi_internal.h b/arch/risc-v/src/nuttsbi/sbi_internal.h index 79e4690135..2e04c758de 100644 --- a/arch/risc-v/src/nuttsbi/sbi_internal.h +++ b/arch/risc-v/src/nuttsbi/sbi_internal.h @@ -140,5 +140,17 @@ uint64_t sbi_get_mtime(void); void sbi_set_mtimecmp(uint64_t value); +/**************************************************************************** + * Name: sbi_late_initialize + * + * Description: + * Conduct any device specific initialization before entering S-mode from + * NUTTSBI as some chips need such preparations. This function still runs + * in M-mode. + * + ****************************************************************************/ + +weak_function void sbi_late_initialize(void); + #endif /* __ASSEMBLY__ */ #endif /* __ARCH_RISC_V_SRC_NUTTSBI_SBI_INTERNAL_H */ diff --git a/arch/risc-v/src/nuttsbi/sbi_start.c b/arch/risc-v/src/nuttsbi/sbi_start.c index b968302d03..12dcab6a07 100644 --- a/arch/risc-v/src/nuttsbi/sbi_start.c +++ b/arch/risc-v/src/nuttsbi/sbi_start.c @@ -107,6 +107,10 @@ void sbi_start(void) WRITE_CSR(mcounteren, UINT32_C(~0)); WRITE_CSR(scounteren, UINT32_C(~0)); + /* Do device specific initialization as needed */ + + sbi_late_initialize(); + /* Set program counter to __start_s */ WRITE_CSR(mepc, __start_s);