From 9cef24bc62152d557b2dcbfa50391a2d0cc0ee1a Mon Sep 17 00:00:00 2001 From: urvashi sharma Date: Tue, 10 Jun 2025 13:34:04 -0700 Subject: [PATCH] Arch: Arm: SMP: Boot & Voting Refactor Support booting from any usable core in systems with partially fused-off CPUs. Update get_cpu_logic_id to iterate over the actual number of enabled CPUs using DT_CHILD_NUM_STATUS_OKAY(DT_PATH(cpus)) instead of CONFIG_MP_MAX_NUM_CPUS. Resize the voting[] array based on DT_CHILD_NUM_STATUS_OKAY to ensure each CPU can vote correctly. Signed-off-by: urvashi sharma --- arch/arm64/core/macro_priv.inc | 4 ++-- arch/arm64/core/reset.S | 3 ++- arch/arm64/core/smp.c | 4 +++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/arch/arm64/core/macro_priv.inc b/arch/arm64/core/macro_priv.inc index 22cefe235fe..00adcdc8383 100644 --- a/arch/arm64/core/macro_priv.inc +++ b/arch/arm64/core/macro_priv.inc @@ -25,7 +25,7 @@ * Get CPU logic id by looking up cpu_node_list * returns * xreg0: MPID - * xreg1: logic id (0 ~ CONFIG_MP_MAX_NUM_CPUS - 1) + * xreg1: logic id (0 ~ DT_CHILD_NUM_STATUS_OKAY(DT_PATH(cpus)) - 1) * clobbers: xreg0, xreg1, xreg2, xreg3 */ .macro get_cpu_logic_id xreg0, xreg1, xreg2, xreg3 @@ -36,7 +36,7 @@ cmp \xreg2, \xreg0 beq 2f add \xreg1, \xreg1, 1 - cmp \xreg1, #CONFIG_MP_MAX_NUM_CPUS + cmp \xreg1, #DT_CHILD_NUM_STATUS_OKAY(DT_PATH(cpus)) bne 1b b . 2: diff --git a/arch/arm64/core/reset.S b/arch/arm64/core/reset.S index a01139ad700..929e986019e 100644 --- a/arch/arm64/core/reset.S +++ b/arch/arm64/core/reset.S @@ -8,6 +8,7 @@ #include #include #include +#include #include "boot.h" #include "macro_priv.inc" @@ -163,7 +164,7 @@ resetwait: /* wait */ bne 2b add x5, x5, #1 - cmp x5, #CONFIG_MP_MAX_NUM_CPUS + cmp x5, #DT_CHILD_NUM_STATUS_OKAY(DT_PATH(cpus)) bne 2b diff --git a/arch/arm64/core/smp.c b/arch/arm64/core/smp.c index fd9d457ea7d..ff00a85457c 100644 --- a/arch/arm64/core/smp.c +++ b/arch/arm64/core/smp.c @@ -37,7 +37,7 @@ struct boot_params { uint64_t mpid; char *sp; - uint8_t voting[CONFIG_MP_MAX_NUM_CPUS]; + uint8_t voting[DT_CHILD_NUM_STATUS_OKAY(DT_PATH(cpus))]; arch_cpustart_t fn; void *arg; int cpu_num; @@ -56,6 +56,8 @@ const uint64_t cpu_node_list[] = { DT_FOREACH_CHILD_STATUS_OKAY_SEP(DT_PATH(cpus), DT_REG_ADDR, (,)) }; +BUILD_ASSERT(ARRAY_SIZE(cpu_node_list) == DT_CHILD_NUM_STATUS_OKAY(DT_PATH(cpus))); + /* cpu_map saves the maping of core id and mpid */ static uint64_t cpu_map[CONFIG_MP_MAX_NUM_CPUS] = { [0 ... (CONFIG_MP_MAX_NUM_CPUS - 1)] = INV_MPID