From 5de9d957e61150a9f067815981b64b89b0945a1e Mon Sep 17 00:00:00 2001 From: Ville Juven Date: Fri, 18 Oct 2024 12:08:07 +0300 Subject: [PATCH] ricv/riscv_cpuid: Return meaningful values for CPU/Hart ID when SMP=no Return 0 for CPU ID for any hart ID, and return the current Hart ID for any CPU ID. At least these values are somewhat usable / meaningful in non-SMP configurations. --- arch/risc-v/src/common/riscv_cpuindex.c | 12 ++++++++++-- arch/risc-v/src/common/riscv_internal.h | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/arch/risc-v/src/common/riscv_cpuindex.c b/arch/risc-v/src/common/riscv_cpuindex.c index 8586d1cf55..c8c5c45703 100644 --- a/arch/risc-v/src/common/riscv_cpuindex.c +++ b/arch/risc-v/src/common/riscv_cpuindex.c @@ -71,9 +71,13 @@ int up_this_cpu(void) * ****************************************************************************/ -int weak_function riscv_hartid_to_cpuid(int cpu) +int weak_function riscv_hartid_to_cpuid(int hart) { - return cpu - CONFIG_ARCH_RV_HARTID_BASE; +#ifdef CONFIG_SMP + return hart - CONFIG_ARCH_RV_HARTID_BASE; +#else + return 0; +#endif } /**************************************************************************** @@ -87,5 +91,9 @@ int weak_function riscv_hartid_to_cpuid(int cpu) int weak_function riscv_cpuid_to_hartid(int cpu) { +#ifdef CONFIG_SMP return cpu + CONFIG_ARCH_RV_HARTID_BASE; +#else + return (int)riscv_mhartid(); +#endif } diff --git a/arch/risc-v/src/common/riscv_internal.h b/arch/risc-v/src/common/riscv_internal.h index bb6737f4a4..ffa85d5450 100644 --- a/arch/risc-v/src/common/riscv_internal.h +++ b/arch/risc-v/src/common/riscv_internal.h @@ -436,7 +436,7 @@ uintptr_t riscv_mhartid(void); * ****************************************************************************/ -int riscv_hartid_to_cpuid(int cpu); +int riscv_hartid_to_cpuid(int hart); /**************************************************************************** * Name: riscv_cpuid_to_hartid