All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anup Patel <apatel@ventanamicro.com>
To: opensbi@lists.infradead.org
Subject: [PATCH 2/4] lib: sbi: Detect menvcfg CSR at boot time
Date: Tue, 29 Mar 2022 21:22:16 +0530	[thread overview]
Message-ID: <20220329155218.118580-3-apatel@ventanamicro.com> (raw)
In-Reply-To: <20220329155218.118580-1-apatel@ventanamicro.com>

From: Atish Patra <atishp@rivosinc.com>

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>
---
 include/sbi/sbi_hart.h | 4 +++-
 lib/sbi/sbi_hart.c     | 9 +++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/include/sbi/sbi_hart.h b/include/sbi/sbi_hart.h
index a83b45b..57f80bc 100644
--- a/include/sbi/sbi_hart.h
+++ b/include/sbi/sbi_hart.h
@@ -26,9 +26,11 @@ enum sbi_hart_features {
 	SBI_HART_HAS_TIME = (1 << 4),
 	/** HART has AIA local interrupt CSRs */
 	SBI_HART_HAS_AIA = (1 << 5),
+	/** HART has menvcfg CSR */
+	SBI_HART_HAS_MENVCFG = (1 << 6),
 
 	/** 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;
diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c
index e028540..31c8f39 100644
--- a/lib/sbi/sbi_hart.c
+++ b/lib/sbi/sbi_hart.c
@@ -304,6 +304,9 @@ static inline char *sbi_hart_feature_id2string(unsigned long feature)
 	case SBI_HART_HAS_AIA:
 		fstr = "aia";
 		break;
+	case SBI_HART_HAS_MENVCFG:
+		fstr = "menvcfg";
+		break;
 	default:
 		break;
 	}
@@ -534,6 +537,12 @@ __mhpm_skip:
 		goto __aia_skip;
 	hfeatures->features |= SBI_HART_HAS_AIA;
 __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;
 }
 
-- 
2.25.1



  parent reply	other threads:[~2022-03-29 15:52 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-29 15:52 [PATCH 0/4] Configure Zicbo[m|z] and Svpbmt in menvcfg CSR Anup Patel
2022-03-29 15:52 ` [PATCH 1/4] include: Add defines for [m|h|s]envcfg CSRs Anup Patel
2022-03-29 23:48   ` Atish Patra
2022-03-30 14:47   ` Xiang W
2022-04-05  3:27   ` Anup Patel
2022-03-29 15:52 ` Anup Patel [this message]
2022-03-30 14:48   ` [PATCH 2/4] lib: sbi: Detect menvcfg CSR at boot time Xiang W
2022-04-05  3:27   ` Anup Patel
2022-03-29 15:52 ` [PATCH 3/4] lib: sbi: Enable Zicbo[m|z] extensions in the menvcfg CSR Anup Patel
2022-03-30  0:04   ` Atish Patra
2022-03-30 14:49   ` Xiang W
2022-04-05  3:27   ` Anup Patel
2022-03-29 15:52 ` [PATCH 4/4] lib: sbi: Enable Svpbmt extension " Anup Patel
2022-03-30  0:04   ` Atish Patra
2022-03-30 14:49   ` Xiang W
2022-04-05  3:28   ` 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=20220329155218.118580-3-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.