arch/riscv: add cluster local hartid

Some multicore RV chips (mpfs, jh7110 etc) have hart clusters
and globally numbered mhartids. Clusters with single hart or
SMP support can be managed by one NuttX instance. Currently
NuttX expects to use cluster-local ids.

This allows us to get local ids by offsetting mhartids with a
base value.

Note that there are chips (e.g. k230) that use cluster-local
ids directly, so this is not needed for them.

Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
This commit is contained in:
Yanfeng Liu 2024-07-29 16:01:54 +08:00 committed by Xiang Xiao
parent 029411f00c
commit 47b0414eab
2 changed files with 17 additions and 0 deletions

View File

@ -451,6 +451,20 @@ config ARCH_RV_MMIO_BITS
default 32 if ARCH_RV32 default 32 if ARCH_RV32
default 64 if ARCH_RV64 default 64 if ARCH_RV64
config ARCH_RV_HARTID_BASE
int "Base hartid of this cluster"
default 0
---help---
Some RV chips have multiple cluster of harts with
globally numbered mhartids, like qemu-rv, mpfs and
jh7110 etc. Clusters with SMP ability can be managed
by NuttX. As NuttX expects cluster-local hart ids,
we can shift mhartid by this value to derive such
local ids. The SMP_NCPUS still defines number of
harts in the cluster. Note that we assume that global
ids for each cluster are continuous. Note that there
are chips like k230 which don't have global mhartid.
config ARCH_FAMILY config ARCH_FAMILY
string string
default "rv32" if ARCH_RV32 default "rv32" if ARCH_RV32

View File

@ -362,6 +362,9 @@
REGLOAD \out, RISCV_PERCPU_HARTID(\out) REGLOAD \out, RISCV_PERCPU_HARTID(\out)
#else #else
csrr \out, CSR_MHARTID csrr \out, CSR_MHARTID
# if CONFIG_ARCH_RV_HARTID_BASE > 0
add \out, \out, - CONFIG_ARCH_RV_HARTID_BASE
# endif
#endif #endif
.endm .endm