OpenSBI Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Anup Patel <apatel@ventanamicro.com>
To: opensbi@lists.infradead.org
Subject: [PATCH 04/11] lib: sbi: Remove MCOUNTEREN and SCOUNTEREN hart features
Date: Fri, 29 Apr 2022 21:21:44 +0530	[thread overview]
Message-ID: <20220429155151.314788-5-apatel@ventanamicro.com> (raw)
In-Reply-To: <20220429155151.314788-1-apatel@ventanamicro.com>

If a hart implements privileged spec v1.10 (or higher) then we can
safely assume that [m|s]counteren CSR are present and we don't need
MCOUNTEREN and SCOUNTEREN as hart features.

Signed-off-by: Anup Patel <apatel@ventanamicro.com>
---
 include/sbi/sbi_hart.h    | 18 +++++++-----------
 lib/sbi/sbi_emulate_csr.c |  4 ++--
 lib/sbi/sbi_hart.c        | 29 +++++------------------------
 lib/sbi/sbi_pmu.c         |  3 ++-
 4 files changed, 16 insertions(+), 38 deletions(-)

diff --git a/include/sbi/sbi_hart.h b/include/sbi/sbi_hart.h
index 3c37933..4665a62 100644
--- a/include/sbi/sbi_hart.h
+++ b/include/sbi/sbi_hart.h
@@ -26,24 +26,20 @@ enum sbi_hart_priv_versions {
 
 /** Possible feature flags of a hart */
 enum sbi_hart_features {
-	/** Hart has S-mode counter enable */
-	SBI_HART_HAS_SCOUNTEREN = (1 << 0),
-	/** Hart has M-mode counter enable */
-	SBI_HART_HAS_MCOUNTEREN = (1 << 1),
 	/** Hart has counter inhibit CSR */
-	SBI_HART_HAS_MCOUNTINHIBIT = (1 << 2),
+	SBI_HART_HAS_MCOUNTINHIBIT = (1 << 0),
 	/** Hart has sscofpmf extension */
-	SBI_HART_HAS_SSCOFPMF = (1 << 3),
+	SBI_HART_HAS_SSCOFPMF = (1 << 1),
 	/** HART has timer csr implementation in hardware */
-	SBI_HART_HAS_TIME = (1 << 4),
+	SBI_HART_HAS_TIME = (1 << 2),
 	/** HART has AIA local interrupt CSRs */
-	SBI_HART_HAS_AIA = (1 << 5),
+	SBI_HART_HAS_AIA = (1 << 3),
 	/** HART has menvcfg CSR */
-	SBI_HART_HAS_MENVCFG = (1 << 6),
+	SBI_HART_HAS_MENVCFG = (1 << 4),
 	/** HART has mstateen CSR **/
-	SBI_HART_HAS_SMSTATEEN = (1 << 7),
+	SBI_HART_HAS_SMSTATEEN = (1 << 5),
 	/** HART has SSTC extension implemented in hardware */
-	SBI_HART_HAS_SSTC = (1 << 8),
+	SBI_HART_HAS_SSTC = (1 << 6),
 
 	/** Last index of Hart features*/
 	SBI_HART_HAS_LAST_FEATURE = SBI_HART_HAS_SSTC,
diff --git a/lib/sbi/sbi_emulate_csr.c b/lib/sbi/sbi_emulate_csr.c
index dbb1755..aec9d3c 100644
--- a/lib/sbi/sbi_emulate_csr.c
+++ b/lib/sbi/sbi_emulate_csr.c
@@ -24,7 +24,7 @@ static bool hpm_allowed(int hpm_num, ulong prev_mode, bool virt)
 	struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
 
 	if (prev_mode <= PRV_S) {
-		if (sbi_hart_has_feature(scratch, SBI_HART_HAS_MCOUNTEREN)) {
+		if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_10) {
 			cen &= csr_read(CSR_MCOUNTEREN);
 			if (virt)
 				cen &= csr_read(CSR_HCOUNTEREN);
@@ -33,7 +33,7 @@ static bool hpm_allowed(int hpm_num, ulong prev_mode, bool virt)
 		}
 	}
 	if (prev_mode == PRV_U) {
-		if (sbi_hart_has_feature(scratch, SBI_HART_HAS_SCOUNTEREN))
+		if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_10)
 			cen &= csr_read(CSR_SCOUNTEREN);
 		else
 			cen = 0;
diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c
index ed4e631..ed8a061 100644
--- a/lib/sbi/sbi_hart.c
+++ b/lib/sbi/sbi_hart.c
@@ -58,7 +58,7 @@ static void mstatus_init(struct sbi_scratch *scratch)
 
 	/* Disable user mode usage of all perf counters except default ones (CY, TM, IR) */
 	if (misa_extension('S') &&
-	    sbi_hart_has_feature(scratch, SBI_HART_HAS_SCOUNTEREN))
+	    sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_10)
 		csr_write(CSR_SCOUNTEREN, 7);
 
 	/**
@@ -66,7 +66,7 @@ static void mstatus_init(struct sbi_scratch *scratch)
 	 * Supervisor mode usage for all counters are enabled by default
 	 * But counters will not run until mcountinhibit is set.
 	 */
-	if (sbi_hart_has_feature(scratch, SBI_HART_HAS_MCOUNTEREN))
+	if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_10)
 		csr_write(CSR_MCOUNTEREN, -1);
 
 	/* All programmable counters will start running at runtime after S-mode request */
@@ -402,12 +402,6 @@ static inline char *sbi_hart_feature_id2string(unsigned long feature)
 		return NULL;
 
 	switch (feature) {
-	case SBI_HART_HAS_SCOUNTEREN:
-		fstr = "scounteren";
-		break;
-	case SBI_HART_HAS_MCOUNTEREN:
-		fstr = "mcounteren";
-		break;
 	case SBI_HART_HAS_MCOUNTINHIBIT:
 		fstr = "mcountinhibit";
 		break;
@@ -614,23 +608,10 @@ __mhpm_skip:
 #undef __check_csr_2
 #undef __check_csr
 
-	/* Detect if hart supports SCOUNTEREN feature */
-	val = csr_read_allowed(CSR_SCOUNTEREN, (unsigned long)&trap);
-	if (!trap.cause) {
-		hfeatures->priv_version = SBI_HART_PRIV_VER_1_10;
-		csr_write_allowed(CSR_SCOUNTEREN, (unsigned long)&trap, val);
-		if (!trap.cause)
-			hfeatures->features |= SBI_HART_HAS_SCOUNTEREN;
-	}
-
-	/* Detect if hart supports MCOUNTEREN feature */
+	/* Detect if hart supports Priv v1.10 */
 	val = csr_read_allowed(CSR_MCOUNTEREN, (unsigned long)&trap);
-	if (!trap.cause) {
+	if (!trap.cause)
 		hfeatures->priv_version = SBI_HART_PRIV_VER_1_10;
-		csr_write_allowed(CSR_MCOUNTEREN, (unsigned long)&trap, val);
-		if (!trap.cause)
-			hfeatures->features |= SBI_HART_HAS_MCOUNTEREN;
-	}
 
 	/* Detect if hart supports MCOUNTINHIBIT feature */
 	val = csr_read_allowed(CSR_MCOUNTINHIBIT, (unsigned long)&trap);
@@ -651,7 +632,7 @@ __mhpm_skip:
 
 	/* Counter overflow/filtering is not useful without mcounter/inhibit */
 	if (hfeatures->features & SBI_HART_HAS_MCOUNTINHIBIT &&
-	    hfeatures->features & SBI_HART_HAS_MCOUNTEREN) {
+	    hfeatures->priv_version >= SBI_HART_PRIV_VER_1_12) {
 		/* Detect if hart supports sscofpmf */
 		csr_read_allowed(CSR_SCOUNTOVF, (unsigned long)&trap);
 		if (!trap.cause)
diff --git a/lib/sbi/sbi_pmu.c b/lib/sbi/sbi_pmu.c
index 7ea0ca5..853229e 100644
--- a/lib/sbi/sbi_pmu.c
+++ b/lib/sbi/sbi_pmu.c
@@ -729,7 +729,8 @@ void sbi_pmu_exit(struct sbi_scratch *scratch)
 	if (sbi_hart_has_feature(scratch, SBI_HART_HAS_MCOUNTINHIBIT))
 		csr_write(CSR_MCOUNTINHIBIT, 0xFFFFFFF8);
 
-	csr_write(CSR_MCOUNTEREN, -1);
+	if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_10)
+		csr_write(CSR_MCOUNTEREN, -1);
 	pmu_reset_event_map(hartid);
 }
 
-- 
2.34.1



  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 ` Anup Patel [this message]
2022-05-04  1:51   ` [PATCH 04/11] lib: sbi: Remove MCOUNTEREN and SCOUNTEREN hart features 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 ` [PATCH 10/11] lib: sbi: Add sbi_hart_update_extension() function Anup Patel
2022-05-04  2:02   ` 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-5-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox