From: Anup Patel <apatel@ventanamicro.com>
To: opensbi@lists.infradead.org
Subject: [PATCH 10/11] lib: sbi: Add sbi_hart_update_extension() function
Date: Fri, 29 Apr 2022 21:21:50 +0530 [thread overview]
Message-ID: <20220429155151.314788-11-apatel@ventanamicro.com> (raw)
In-Reply-To: <20220429155151.314788-1-apatel@ventanamicro.com>
We add sbi_hart_update_extension() function which allow platforms
to enable/disable hart extensions.
Signed-off-by: Anup Patel <anup@brainfault.org>
---
include/sbi/sbi_hart.h | 3 +++
lib/sbi/sbi_hart.c | 43 +++++++++++++++++++++++++++++++++++++-----
2 files changed, 41 insertions(+), 5 deletions(-)
diff --git a/include/sbi/sbi_hart.h b/include/sbi/sbi_hart.h
index 8b21fd4..4661506 100644
--- a/include/sbi/sbi_hart.h
+++ b/include/sbi/sbi_hart.h
@@ -63,6 +63,9 @@ int sbi_hart_pmp_configure(struct sbi_scratch *scratch);
int sbi_hart_priv_version(struct sbi_scratch *scratch);
void sbi_hart_get_priv_version_str(struct sbi_scratch *scratch,
char *version_str, int nvstr);
+void sbi_hart_update_extension(struct sbi_scratch *scratch,
+ enum sbi_hart_extensions ext,
+ bool enable);
bool sbi_hart_has_extension(struct sbi_scratch *scratch,
enum sbi_hart_extensions ext);
void sbi_hart_get_extensions_str(struct sbi_scratch *scratch,
diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c
index 28a7e75..3fc8899 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 */
--
2.34.1
next prev parent reply other threads:[~2022-04-29 15:51 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-29 15:51 [PATCH 00/11] HART Feature Improvements Anup Patel
2022-04-29 15:51 ` [PATCH 01/11] lib: sbi: Detect and print privileged spec version Anup Patel
2022-05-04 1:42 ` Atish Patra
2022-05-07 4:57 ` Anup Patel
2022-04-29 15:51 ` [PATCH 02/11] lib: sbi: Remove 's' and 'u' from misa_string() output Anup Patel
2022-05-04 1:42 ` Atish Patra
2022-05-07 4:58 ` Anup Patel
2022-04-29 15:51 ` [PATCH 03/11] lib: sbi: Update the name of ISA string printed at boot time Anup Patel
2022-05-04 1:55 ` Atish Patra
2022-05-07 4:59 ` Anup Patel
2022-04-29 15:51 ` [PATCH 04/11] lib: sbi: Remove MCOUNTEREN and SCOUNTEREN hart features Anup Patel
2022-05-04 1:51 ` Atish Patra
2022-05-04 1:55 ` Atish Patra
2022-05-07 5:00 ` Anup Patel
2022-04-29 15:51 ` [PATCH 05/11] lib: sbi: Remove MCOUNTINHIBT hart feature Anup Patel
2022-05-04 1:56 ` Atish Patra
2022-05-07 5:00 ` Anup Patel
2022-04-29 15:51 ` [PATCH 06/11] lib: sbi: Remove MENVCFG " Anup Patel
2022-05-04 1:57 ` Atish Patra
2022-05-07 5:03 ` Anup Patel
2022-04-29 15:51 ` [PATCH 07/11] lib: sbi: Fix AIA feature detection Anup Patel
2022-05-04 1:57 ` Atish Patra
2022-05-07 5:03 ` Anup Patel
2022-04-29 15:51 ` [PATCH 08/11] lib: sbi: Convert hart features into hart extensions Anup Patel
2022-05-04 2:00 ` Atish Patra
2022-05-07 5:04 ` Anup Patel
2022-04-29 15:51 ` [PATCH 09/11] lib: sbi: Detect hart features only once for each hart Anup Patel
2022-05-04 2:01 ` Atish Patra
2022-05-07 5:04 ` Anup Patel
2022-04-29 15:51 ` Anup Patel [this message]
2022-05-04 2:02 ` [PATCH 10/11] lib: sbi: Add sbi_hart_update_extension() function Atish Patra
2022-05-07 5:04 ` Anup Patel
2022-04-29 15:51 ` [PATCH 11/11] lib: sbi_platform: Add callback to populate HART extensions Anup Patel
2022-05-04 2:05 ` Atish Patra
2022-05-07 5:05 ` Anup Patel
2022-05-05 16:30 ` [PATCH 00/11] HART Feature Improvements Xiang W
2022-05-06 3:21 ` 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=20220429155151.314788-11-apatel@ventanamicro.com \
--to=apatel@ventanamicro.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.