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 fd20684a7b mpfs_entrypoints.c: Add simple ACK mechanism for CPU boot
fd20684a7b is described below

commit fd20684a7b65b45a8e1e4e52ea8a4bd4b47cb11a
Author: Ville Juven <ville.ju...@unikie.com>
AuthorDate: Mon Dec 9 11:59:54 2024 +0200

    mpfs_entrypoints.c: Add simple ACK mechanism for CPU boot
    
    CPUs will acknowledge that they have booted, the primary CPU handling the
    boot can then wait for others to complete their boot, before booting
    itself.
---
 arch/risc-v/src/mpfs/mpfs_entrypoints.c | 25 +++++++++++++++++++++++++
 arch/risc-v/src/mpfs/mpfs_entrypoints.h | 16 ++++++++++++++++
 2 files changed, 41 insertions(+)

diff --git a/arch/risc-v/src/mpfs/mpfs_entrypoints.c 
b/arch/risc-v/src/mpfs/mpfs_entrypoints.c
index a15051ed3a..45aa6f6d8e 100644
--- a/arch/risc-v/src/mpfs/mpfs_entrypoints.c
+++ b/arch/risc-v/src/mpfs/mpfs_entrypoints.c
@@ -31,6 +31,7 @@
 #include <stdint.h>
 #include <stdbool.h>
 
+#include <nuttx/atomic.h>
 #include <nuttx/compiler.h>
 
 #include <sys/types.h>
@@ -92,6 +93,8 @@ uint8_t g_mpfs_boot_stacks[ENTRY_STACK * ENTRYPT_CNT]
   aligned_data(STACK_ALIGNMENT);
 #endif
 
+static int g_cpus_booted;
+
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
@@ -130,6 +133,9 @@ void mpfs_jump_to_app(void)
       "la   t0, g_app_entrypoints\n"         /* Entrypoint table base */
       "add  t0, t0, t1\n"                    /* Index in table */
       "ld   t0, 0(t0)\n"                     /* Load the address from table */
+      "li   t1, 1\n"
+      "la   t2, g_cpus_booted\n"
+      "amoadd.w.aqrl zero, t1, 0(t2)\n"      /* g_cpus_booted + 1 */
       "jr   t0\n"                            /* Jump to entrypoint */
       :
 #ifdef CONFIG_MPFS_BOARD_PMP
@@ -248,4 +254,23 @@ bool mpfs_get_use_sbi(uint64_t hartid)
   return false;
 }
 
+/****************************************************************************
+ * Name: mpfs_cpus_booted
+ *
+ * Description:
+ *   Get amount of CPUs that have completed boot.
+ *
+ * Input Parameters:
+ *   None.
+ *
+ * Returned value:
+ *   Amount of CPUs that have booted.
+ *
+ ****************************************************************************/
+
+int mpfs_cpus_booted(void)
+{
+  return atomic_load(&g_cpus_booted);
+}
+
 #endif /* CONFIG_MPFS_BOOTLOADER */
diff --git a/arch/risc-v/src/mpfs/mpfs_entrypoints.h 
b/arch/risc-v/src/mpfs/mpfs_entrypoints.h
index 9a753b8168..75992b349c 100644
--- a/arch/risc-v/src/mpfs/mpfs_entrypoints.h
+++ b/arch/risc-v/src/mpfs/mpfs_entrypoints.h
@@ -104,6 +104,22 @@ int mpfs_set_use_sbi(uint64_t hartid, bool use_sbi);
 
 bool mpfs_get_use_sbi(uint64_t hartid);
 
+/****************************************************************************
+ * Name: mpfs_cpus_booted
+ *
+ * Description:
+ *   Get amount of CPUs that have completed boot.
+ *
+ * Input Parameters:
+ *   None.
+ *
+ * Returned value:
+ *   Amount of CPUs that have booted.
+ *
+ ****************************************************************************/
+
+int mpfs_cpus_booted(void);
+
 #if defined(__cplusplus)
 }
 #endif

Reply via email to