From: Clément Léger <cleger@rivosinc.com>
To: opensbi@lists.infradead.org
Subject: [PATCH v3 3/4] lib: sbi: fwft: add support for SBI_FWFT_PTE_AD_HW_UPDATING
Date: Wed, 19 Jun 2024 11:42:41 +0200 [thread overview]
Message-ID: <20240619094244.603628-4-cleger@rivosinc.com> (raw)
In-Reply-To: <20240619094244.603628-1-cleger@rivosinc.com>
Add support for SBI_FWFT_PTE_AD_HW_UPDATING based on SVADU presence.
Signed-off-by: Cl?ment L?ger <cleger@rivosinc.com>
---
lib/sbi/sbi_fwft.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++
lib/sbi/sbi_hsm.c | 12 ++++++++++++
2 files changed, 59 insertions(+)
diff --git a/lib/sbi/sbi_fwft.c b/lib/sbi/sbi_fwft.c
index 289a344..aff087f 100644
--- a/lib/sbi/sbi_fwft.c
+++ b/lib/sbi/sbi_fwft.c
@@ -100,6 +100,47 @@ static int fwft_get_misaligned_delegation(struct fwft_config *conf,
return SBI_OK;
}
+static int fwft_adue_supported(struct fwft_config *conf)
+{
+ if (!sbi_hart_has_extension(sbi_scratch_thishart_ptr(),
+ SBI_HART_EXT_SVADU))
+ return SBI_ENOTSUPP;
+
+ return SBI_OK;
+}
+
+static int fwft_set_adue(struct fwft_config *conf, unsigned long value)
+{
+ if (value)
+#if __riscv_xlen == 32
+ csr_set(CSR_MENVCFGH, ENVCFG_ADUE >> 32);
+#else
+ csr_set(CSR_MENVCFG, ENVCFG_ADUE);
+#endif
+ else
+#if __riscv_xlen == 32
+ csr_clear(CSR_MENVCFGH, ENVCFG_ADUE >> 32);
+#else
+ csr_clear(CSR_MENVCFG, ENVCFG_ADUE);
+#endif
+
+ return SBI_OK;
+}
+
+static int fwft_get_adue(struct fwft_config *conf, unsigned long *value)
+{
+ unsigned long cfg;
+
+#if __riscv_xlen == 32
+ cfg = csr_read(CSR_MENVCFGH) & (ENVCFG_ADUE >> 32);
+#else
+ cfg = csr_read(CSR_MENVCFG) & ENVCFG_ADUE;
+#endif
+ *value = cfg != 0;
+
+ return SBI_OK;
+}
+
static struct fwft_config* get_feature_config(enum sbi_fwft_feature_t feature)
{
int i;
@@ -185,6 +226,12 @@ static const struct fwft_feature features[] =
.set = fwft_set_misaligned_delegation,
.get = fwft_get_misaligned_delegation,
},
+ {
+ .id = SBI_FWFT_PTE_AD_HW_UPDATING,
+ .supported = fwft_adue_supported,
+ .set = fwft_set_adue,
+ .get = fwft_get_adue,
+ },
};
int sbi_fwft_init(struct sbi_scratch *scratch, bool cold_boot)
diff --git a/lib/sbi/sbi_hsm.c b/lib/sbi/sbi_hsm.c
index 2b23e13..7e32af3 100644
--- a/lib/sbi/sbi_hsm.c
+++ b/lib/sbi/sbi_hsm.c
@@ -45,6 +45,10 @@ struct sbi_hsm_data {
unsigned long saved_mie;
unsigned long saved_mip;
unsigned long saved_medeleg;
+ unsigned long saved_menvcfg;
+#if __riscv_xlen == 32
+ unsigned long saved_menvcfgh;
+#endif
atomic_t start_ticket;
};
@@ -419,6 +423,10 @@ void __sbi_hsm_suspend_non_ret_save(struct sbi_scratch *scratch)
hdata->saved_mie = csr_read(CSR_MIE);
hdata->saved_mip = csr_read(CSR_MIP) & (MIP_SSIP | MIP_STIP);
hdata->saved_medeleg = csr_read(CSR_MEDELEG);
+#if __riscv_xlen == 32
+ hdata->saved_menvcfgh = csr_read(CSR_MENVCFGH);
+#endif
+ hdata->saved_menvcfg = csr_read(CSR_MENVCFG);
}
static void __sbi_hsm_suspend_non_ret_restore(struct sbi_scratch *scratch)
@@ -426,6 +434,10 @@ static void __sbi_hsm_suspend_non_ret_restore(struct sbi_scratch *scratch)
struct sbi_hsm_data *hdata = sbi_scratch_offset_ptr(scratch,
hart_data_offset);
+ csr_write(CSR_MENVCFG, hdata->saved_menvcfg);
+#if __riscv_xlen == 32
+ csr_write(CSR_MENVCFGH, hdata->saved_menvcfgh);
+#endif
csr_write(CSR_MEDELEG, hdata->saved_medeleg);
csr_write(CSR_MIE, hdata->saved_mie);
csr_set(CSR_MIP, (hdata->saved_mip & (MIP_SSIP | MIP_STIP)));
--
2.45.2
next prev parent reply other threads:[~2024-06-19 9:42 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-19 9:42 [PATCH v3 0/4] Add SBI FWFT extension support Clément Léger
2024-06-19 9:42 ` [PATCH v3 1/4] lib: sbi: add support for firmware features extension Clément Léger
2024-06-19 12:47 ` Anup Patel
2024-06-19 9:42 ` [PATCH v3 2/4] lib: sbi: fwft: add support for SBI_FWFT_MISALIGNED_EXC_DELEG Clément Léger
2024-06-19 12:48 ` Anup Patel
2024-06-21 13:50 ` Andrew Jones
2024-06-24 8:28 ` Clément Léger
2024-06-19 9:42 ` Clément Léger [this message]
2024-06-19 12:48 ` [PATCH v3 3/4] lib: sbi: fwft: add support for SBI_FWFT_PTE_AD_HW_UPDATING Anup Patel
2024-06-19 9:42 ` [PATCH v3 4/4] lib: sbi: implement SBI FWFT extension Clément Léger
2024-06-19 12:49 ` Anup Patel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240619094244.603628-4-cleger@rivosinc.com \
--to=cleger@rivosinc.com \
--cc=opensbi@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.