lib: sbi: Detect menvcfg CSR at boot time

We add the menvcfg CSR as a HART feature and detect it at boot time
using traping mechanism.

Signed-off-by: Atish Patra <atishp@rivosinc.com>
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
Reviewed-by: Xiang W <wxjstz@126.com>
This commit is contained in:
Atish Patra
2022-03-29 19:25:36 +05:30
committed by Anup Patel
parent 722f80d8e9
commit 31fecad46d
2 changed files with 12 additions and 1 deletions

View File

@@ -26,9 +26,11 @@ enum sbi_hart_features {
SBI_HART_HAS_TIME = (1 << 4), SBI_HART_HAS_TIME = (1 << 4),
/** HART has AIA local interrupt CSRs */ /** HART has AIA local interrupt CSRs */
SBI_HART_HAS_AIA = (1 << 5), SBI_HART_HAS_AIA = (1 << 5),
/** HART has menvcfg CSR */
SBI_HART_HAS_MENVCFG = (1 << 6),
/** Last index of Hart features*/ /** Last index of Hart features*/
SBI_HART_HAS_LAST_FEATURE = SBI_HART_HAS_AIA, SBI_HART_HAS_LAST_FEATURE = SBI_HART_HAS_MENVCFG,
}; };
struct sbi_scratch; struct sbi_scratch;

View File

@@ -304,6 +304,9 @@ static inline char *sbi_hart_feature_id2string(unsigned long feature)
case SBI_HART_HAS_AIA: case SBI_HART_HAS_AIA:
fstr = "aia"; fstr = "aia";
break; break;
case SBI_HART_HAS_MENVCFG:
fstr = "menvcfg";
break;
default: default:
break; break;
} }
@@ -534,6 +537,12 @@ __mhpm_skip:
goto __aia_skip; goto __aia_skip;
hfeatures->features |= SBI_HART_HAS_AIA; hfeatures->features |= SBI_HART_HAS_AIA;
__aia_skip: __aia_skip:
/* Detect if hart has menvcfg CSR */
csr_read_allowed(CSR_MENVCFG, (unsigned long)&trap);
if (!trap.cause)
hfeatures->features |= SBI_HART_HAS_MENVCFG;
return; return;
} }