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.
This commit is contained in:
Ville Juven 2024-10-18 12:08:07 +03:00 committed by Xiang Xiao
parent 53d90c8205
commit 5de9d957e6
2 changed files with 11 additions and 3 deletions

View file

@ -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) int weak_function riscv_cpuid_to_hartid(int cpu)
{ {
#ifdef CONFIG_SMP
return cpu + CONFIG_ARCH_RV_HARTID_BASE; return cpu + CONFIG_ARCH_RV_HARTID_BASE;
#else
return (int)riscv_mhartid();
#endif
} }

View file

@ -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 * Name: riscv_cpuid_to_hartid