lib: sbi: hart: Detect existence of cycle and instret CSRs for Zicntr

Zicntr extension specifies three read-only CSRs, time, cycle and
instret. It isn't sufficient to report Zicntr is fully supported with
only time CSR detected.

This patch introduces a bitmap to sbi_hart_features to record
availability of these CSRs, which are detected using traps. Zicntr is
reported as present if and only if three CSRs are all available on the
HARTs.

Sites originally depending on SBI_HART_EXT_ZICNTR for detecting
existence of time CSR are switched to detect SBI_HART_CSR_TIME instead.

Suggested-by: Anup Patel <anup@brainfault.org>
Signed-off-by: Yao Zi <ziyao@disroot.org>
Reviewed-by: Anup Patel <anup@brainfault.org>
Link: https://lore.kernel.org/r/20250516133352.36617-3-ziyao@disroot.org
Signed-off-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
Yao Zi
2025-05-16 13:33:52 +00:00
committed by Anup Patel
parent 2bb7632649
commit 7e31dc8052
3 changed files with 39 additions and 8 deletions

View File

@@ -185,7 +185,7 @@ int sbi_timer_init(struct sbi_scratch *scratch, bool cold_boot)
if (!time_delta_off)
return SBI_ENOMEM;
if (sbi_hart_has_extension(scratch, SBI_HART_EXT_ZICNTR))
if (sbi_hart_has_csr(scratch, SBI_HART_CSR_TIME))
get_time_val = get_ticks;
ret = sbi_platform_timer_init(plat);