Skip to content

Commit

Permalink
mpfs_entrypoints.c: Add simple ACK mechanism for CPU boot
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pussuw committed Dec 10, 2024
1 parent a4df9f9 commit 4d6735f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
25 changes: 25 additions & 0 deletions arch/risc-v/src/mpfs/mpfs_entrypoints.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <stdint.h>
#include <stdbool.h>

#include <nuttx/atomic.h>
#include <nuttx/compiler.h>

#include <sys/types.h>
Expand Down Expand Up @@ -90,6 +91,8 @@ uint8_t g_mpfs_boot_stacks[ENTRY_STACK * ENTRYPT_CNT]
aligned_data(STACK_ALIGNMENT);
#endif

static int g_cpus_booted;

/****************************************************************************
* Public Functions
****************************************************************************/
Expand Down Expand Up @@ -128,6 +131,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
Expand Down Expand Up @@ -246,4 +252,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 */
16 changes: 16 additions & 0 deletions arch/risc-v/src/mpfs/mpfs_entrypoints.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,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
Expand Down

0 comments on commit 4d6735f

Please sign in to comment.