aboutsummaryrefslogtreecommitdiff
path: root/lib/sbi/sbi_hart.c
diff options
context:
space:
mode:
authorAnup Patel <apatel@ventanamicro.com>2022-04-29 20:47:04 +0530
committerAnup Patel <anup@brainfault.org>2022-05-07 10:17:25 +0530
commit994ace30f7c83f0cf9bd1b27a8bf15e0c0d5f9b6 (patch)
tree53173225a5d5f800deea1ce938e64985c6ab9826 /lib/sbi/sbi_hart.c
parentbe4903ae0019947853ebf331d5b752ea178fd697 (diff)
downloadopensbi-994ace30f7c83f0cf9bd1b27a8bf15e0c0d5f9b6.zip
opensbi-994ace30f7c83f0cf9bd1b27a8bf15e0c0d5f9b6.tar.gz
opensbi-994ace30f7c83f0cf9bd1b27a8bf15e0c0d5f9b6.tar.bz2
lib: sbi: Add sbi_hart_update_extension() function
We add sbi_hart_update_extension() function which allow platforms to enable/disable hart extensions. Signed-off-by: Anup Patel <anup@brainfault.org> Reviewed-by: Atish Patra <atishp@rivosinc.com>
Diffstat (limited to 'lib/sbi/sbi_hart.c')
-rw-r--r--lib/sbi/sbi_hart.c43
1 files changed, 38 insertions, 5 deletions
diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c
index a5ba239..de08f9e 100644
--- a/lib/sbi/sbi_hart.c
+++ b/lib/sbi/sbi_hart.c
@@ -367,6 +367,34 @@ void sbi_hart_get_priv_version_str(struct sbi_scratch *scratch,
sbi_snprintf(version_str, nvstr, "%s", temp);
}
+static inline void __sbi_hart_update_extension(
+ struct hart_features *hfeatures,
+ enum sbi_hart_extensions ext,
+ bool enable)
+{
+ if (enable)
+ hfeatures->extensions |= BIT(ext);
+ else
+ hfeatures->extensions &= ~BIT(ext);
+}
+
+/**
+ * Enable/Disable a particular hart extension
+ *
+ * @param scratch pointer to the HART scratch space
+ * @param ext the extension number to check
+ * @param enable new state of hart extension
+ */
+void sbi_hart_update_extension(struct sbi_scratch *scratch,
+ enum sbi_hart_extensions ext,
+ bool enable)
+{
+ struct hart_features *hfeatures =
+ sbi_scratch_offset_ptr(scratch, hart_features_offset);
+
+ __sbi_hart_update_extension(hfeatures, ext, enable);
+}
+
/**
* Check whether a particular hart extension is available
*
@@ -620,31 +648,36 @@ __mhpm_skip:
/* Detect if hart supports sscofpmf */
csr_read_allowed(CSR_SCOUNTOVF, (unsigned long)&trap);
if (!trap.cause)
- hfeatures->extensions |= BIT(SBI_HART_EXT_SSCOFPMF);
+ __sbi_hart_update_extension(hfeatures,
+ SBI_HART_EXT_SSCOFPMF, true);
}
/* Detect if hart supports time CSR */
csr_read_allowed(CSR_TIME, (unsigned long)&trap);
if (!trap.cause)
- hfeatures->extensions |= BIT(SBI_HART_EXT_TIME);
+ __sbi_hart_update_extension(hfeatures,
+ SBI_HART_EXT_TIME, true);
/* Detect if hart has AIA local interrupt CSRs */
csr_read_allowed(CSR_MTOPI, (unsigned long)&trap);
if (!trap.cause)
- hfeatures->extensions |= BIT(SBI_HART_EXT_AIA);
+ __sbi_hart_update_extension(hfeatures,
+ SBI_HART_EXT_AIA, true);
/* 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->extensions |= BIT(SBI_HART_EXT_SSTC);
+ __sbi_hart_update_extension(hfeatures,
+ SBI_HART_EXT_SSTC, true);
}
/* Detect if hart supports mstateen CSRs */
if (hfeatures->priv_version >= SBI_HART_PRIV_VER_1_12) {
val = csr_read_allowed(CSR_MSTATEEN0, (unsigned long)&trap);
if (!trap.cause)
- hfeatures->extensions |= BIT(SBI_HART_EXT_SMSTATEEN);
+ __sbi_hart_update_extension(hfeatures,
+ SBI_HART_EXT_SMSTATEEN, true);
}
/* Mark hart feature detection done */