aboutsummaryrefslogtreecommitdiff
path: root/lib/sbi/sbi_hart.c
diff options
context:
space:
mode:
authorAnup Patel <apatel@ventanamicro.com>2022-04-28 19:18:17 +0530
committerAnup Patel <anup@brainfault.org>2022-05-07 10:06:19 +0530
commit97a17c2e5c38b0813bb4ab171cef893addf89cfe (patch)
treeef693ac9927b8130c1b7bcc62e03ca8fb255dbc7 /lib/sbi/sbi_hart.c
parentdbc3d8f0ef19563a89aea266e032acbab549f7fe (diff)
downloadopensbi-97a17c2e5c38b0813bb4ab171cef893addf89cfe.zip
opensbi-97a17c2e5c38b0813bb4ab171cef893addf89cfe.tar.gz
opensbi-97a17c2e5c38b0813bb4ab171cef893addf89cfe.tar.bz2
lib: sbi: Remove MENVCFG hart feature
If a hart implements privileged spec v1.12 (or higher) then we can safely assume that menvcfg CSR is present and we don't need MENVCFG as a hart feature. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Atish Patra <atishp@rivosinc.com>
Diffstat (limited to 'lib/sbi/sbi_hart.c')
-rw-r--r--lib/sbi/sbi_hart.c32
1 files changed, 12 insertions, 20 deletions
diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c
index 0fe88cb..5ee5ddd 100644
--- a/lib/sbi/sbi_hart.c
+++ b/lib/sbi/sbi_hart.c
@@ -97,10 +97,8 @@ static void mstatus_init(struct sbi_scratch *scratch)
mstateen_val |= ((uint64_t)csr_read(CSR_MSTATEEN0H)) << 32;
#endif
mstateen_val |= SMSTATEEN_STATEN;
- if (sbi_hart_has_feature(scratch, SBI_HART_HAS_MENVCFG))
- mstateen_val |= SMSTATEEN0_HSENVCFG;
- else
- mstateen_val &= ~SMSTATEEN0_HSENVCFG;
+ mstateen_val |= SMSTATEEN0_HSENVCFG;
+
if (sbi_hart_has_feature(scratch, SBI_HART_HAS_AIA))
mstateen_val |= (SMSTATEEN0_AIA | SMSTATEEN0_SVSLCT |
SMSTATEEN0_IMSIC);
@@ -113,7 +111,7 @@ static void mstatus_init(struct sbi_scratch *scratch)
#endif
}
- if (sbi_hart_has_feature(scratch, SBI_HART_HAS_MENVCFG)) {
+ if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_12) {
menvcfg_val = csr_read(CSR_MENVCFG);
/*
@@ -413,9 +411,6 @@ static inline char *sbi_hart_feature_id2string(unsigned long feature)
case SBI_HART_HAS_SSTC:
fstr = "sstc";
break;
- case SBI_HART_HAS_MENVCFG:
- fstr = "menvcfg";
- break;
case SBI_HART_HAS_SMSTATEEN:
fstr = "smstateen";
break;
@@ -616,13 +611,11 @@ __mhpm_skip:
(hfeatures->priv_version >= SBI_HART_PRIV_VER_1_10))
hfeatures->priv_version = SBI_HART_PRIV_VER_1_11;
- /* Detect if hart has menvcfg CSR */
+ /* Detect if hart supports Priv v1.12 */
csr_read_allowed(CSR_MENVCFG, (unsigned long)&trap);
if (!trap.cause &&
- (hfeatures->priv_version >= SBI_HART_PRIV_VER_1_11)) {
+ (hfeatures->priv_version >= SBI_HART_PRIV_VER_1_11))
hfeatures->priv_version = SBI_HART_PRIV_VER_1_12;
- hfeatures->features |= SBI_HART_HAS_MENVCFG;
- }
/* Counter overflow/filtering is not useful without mcounter/inhibit */
if (hfeatures->priv_version >= SBI_HART_PRIV_VER_1_12) {
@@ -644,20 +637,19 @@ __mhpm_skip:
hfeatures->features |= SBI_HART_HAS_AIA;
__aia_skip:
- /**
- * Detect if hart supports stimecmp CSR(Sstc extension) and menvcfg is
- * implemented.
- */
- if (hfeatures->features & SBI_HART_HAS_MENVCFG) {
+ /* Detect if hart supports stimecmp CSR(Sstc extension) */
+ if (hfeatures->priv_version >= SBI_HART_PRIV_VER_1_12) {
csr_read_allowed(CSR_STIMECMP, (unsigned long)&trap);
if (!trap.cause)
hfeatures->features |= SBI_HART_HAS_SSTC;
}
/* Detect if hart supports mstateen CSRs */
- val = csr_read_allowed(CSR_MSTATEEN0, (unsigned long)&trap);
- if (!trap.cause)
- hfeatures->features |= SBI_HART_HAS_SMSTATEEN;
+ if (hfeatures->priv_version >= SBI_HART_PRIV_VER_1_12) {
+ val = csr_read_allowed(CSR_MSTATEEN0, (unsigned long)&trap);
+ if (!trap.cause)
+ hfeatures->features |= SBI_HART_HAS_SMSTATEEN;
+ }
return;
}