All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anup Patel <apatel@ventanamicro.com>
To: opensbi@lists.infradead.org
Subject: [PATCH 11/11] lib: sbi_platform: Add callback to populate HART extensions
Date: Fri, 29 Apr 2022 21:21:51 +0530	[thread overview]
Message-ID: <20220429155151.314788-12-apatel@ventanamicro.com> (raw)
In-Reply-To: <20220429155151.314788-1-apatel@ventanamicro.com>

We add platform specific extensions_init() callback which allows
platforms to populate HART extensions for each HART. For example,
the generic platform can populate HART extensions from HART ISA
string described in DeviceTree.

Signed-off-by: Anup Patel <apatel@ventanamicro.com>
---
 include/sbi/sbi_platform.h | 18 ++++++++++++++++++
 lib/sbi/sbi_hart.c         | 18 ++++++++++++++----
 2 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/include/sbi/sbi_platform.h b/include/sbi/sbi_platform.h
index 2c777ac..87024db 100644
--- a/include/sbi/sbi_platform.h
+++ b/include/sbi/sbi_platform.h
@@ -89,6 +89,9 @@ struct sbi_platform_operations {
 	 */
 	int (*misa_get_xlen)(void);
 
+	/** Initialize (or populate) HART extensions for the platform */
+	int (*extensions_init)(void);
+
 	/** Initialize (or populate) domains for the platform */
 	int (*domains_init)(void);
 
@@ -453,6 +456,21 @@ static inline int sbi_platform_misa_xlen(const struct sbi_platform *plat)
 	return -1;
 }
 
+/**
+ * Initialize (or populate) HART extensions for the platform
+ *
+ * @param plat pointer to struct sbi_platform
+ *
+ * @return 0 on success and negative error code on failure
+ */
+static inline int sbi_platform_extensions_init(
+					const struct sbi_platform *plat)
+{
+	if (plat && sbi_platform_ops(plat)->extensions_init)
+		return sbi_platform_ops(plat)->extensions_init();
+	return 0;
+}
+
 /**
  * Initialize (or populate) domains for the platform
  *
diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c
index 3fc8899..8284792 100644
--- a/lib/sbi/sbi_hart.c
+++ b/lib/sbi/sbi_hart.c
@@ -536,16 +536,17 @@ static int hart_pmu_get_allowed_bits(void)
 	return num_bits;
 }
 
-static void hart_detect_features(struct sbi_scratch *scratch)
+static int hart_detect_features(struct sbi_scratch *scratch)
 {
 	struct sbi_trap_info trap = {0};
 	struct hart_features *hfeatures =
 		sbi_scratch_offset_ptr(scratch, hart_features_offset);
 	unsigned long val, oldval;
+	int rc;
 
 	/* If hart features already detected then do nothing */
 	if (hfeatures->detected)
-		return;
+		return 0;
 
 	/* Clear hart features */
 	hfeatures->extensions = 0;
@@ -680,10 +681,15 @@ __mhpm_skip:
 					SBI_HART_EXT_SMSTATEEN, true);
 	}
 
+	/* Let platform populate extensions */
+	rc = sbi_platform_extensions_init(sbi_platform_thishart_ptr());
+	if (rc)
+		return rc;
+
 	/* Mark hart feature detection done */
 	hfeatures->detected = true;
 
-	return;
+	return 0;
 }
 
 int sbi_hart_reinit(struct sbi_scratch *scratch)
@@ -705,6 +711,8 @@ int sbi_hart_reinit(struct sbi_scratch *scratch)
 
 int sbi_hart_init(struct sbi_scratch *scratch, bool cold_boot)
 {
+	int rc;
+
 	if (cold_boot) {
 		if (misa_extension('H'))
 			sbi_hart_expected_trap = &__sbi_expected_trap_hext;
@@ -715,7 +723,9 @@ int sbi_hart_init(struct sbi_scratch *scratch, bool cold_boot)
 			return SBI_ENOMEM;
 	}
 
-	hart_detect_features(scratch);
+	rc = hart_detect_features(scratch);
+	if (rc)
+		return rc;
 
 	return sbi_hart_reinit(scratch);
 }
-- 
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 ` [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 ` [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 ` Anup Patel [this message]
2022-05-04  2:05   ` [PATCH 11/11] lib: sbi_platform: Add callback to populate HART extensions 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-12-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.