aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorYao Zi <ziyao@disroot.org>2025-05-16 13:33:52 +0000
committerAnup Patel <anup@brainfault.org>2025-05-20 13:25:53 +0530
commit7e31dc80525f752d97c2c5a97eb4b9583054e8bc (patch)
treea04b28f15cf9b349459c50509549ca2da6fad906 /include
parent2bb76326496440996b44bf20f3ceab127c7f72ae (diff)
downloadopensbi-7e31dc80525f752d97c2c5a97eb4b9583054e8bc.zip
opensbi-7e31dc80525f752d97c2c5a97eb4b9583054e8bc.tar.gz
opensbi-7e31dc80525f752d97c2c5a97eb4b9583054e8bc.tar.bz2
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>
Diffstat (limited to 'include')
-rw-r--r--include/sbi/sbi_hart.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/include/sbi/sbi_hart.h b/include/sbi/sbi_hart.h
index bce88c5..dfbe8e4 100644
--- a/include/sbi/sbi_hart.h
+++ b/include/sbi/sbi_hart.h
@@ -93,6 +93,14 @@ struct sbi_hart_ext_data {
extern const struct sbi_hart_ext_data sbi_hart_ext[];
+/** CSRs should be detected by access and trapping */
+enum sbi_hart_csrs {
+ SBI_HART_CSR_CYCLE = 0,
+ SBI_HART_CSR_TIME,
+ SBI_HART_CSR_INSTRET,
+ SBI_HART_CSR_MAX,
+};
+
/*
* Smepmp enforces access boundaries between M-mode and
* S/U-mode. When it is enabled, the PMPs are programmed
@@ -112,6 +120,7 @@ struct sbi_hart_features {
bool detected;
int priv_version;
unsigned long extensions[BITS_TO_LONGS(SBI_HART_EXT_MAX)];
+ unsigned long csrs[BITS_TO_LONGS(SBI_HART_CSR_MAX)];
unsigned int pmp_count;
unsigned int pmp_addr_bits;
unsigned int pmp_log2gran;
@@ -150,6 +159,7 @@ bool sbi_hart_has_extension(struct sbi_scratch *scratch,
enum sbi_hart_extensions ext);
void sbi_hart_get_extensions_str(struct sbi_scratch *scratch,
char *extension_str, int nestr);
+bool sbi_hart_has_csr(struct sbi_scratch *scratch, enum sbi_hart_csrs csr);
void __attribute__((noreturn)) sbi_hart_hang(void);