This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 78e8c0dea5 risc-v/nuttsbi: add device specific initialization hook
78e8c0dea5 is described below

commit 78e8c0dea5165f809864c1fbceba1c05d232cf11
Author: Yanfeng Liu <[email protected]>
AuthorDate: Sun Jan 14 12:20:01 2024 +0800

    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 <[email protected]>
---
 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);

Reply via email to