All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/5] Extend hart protection abstraction for ID configuration
@ 2026-07-17  7:44 Anup Patel
  2026-07-17  7:44 ` [PATCH 1/5] lib: sbi: Fix typos related to hart protection Anup Patel
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Anup Patel @ 2026-07-17  7:44 UTC (permalink / raw)
  To: Atish Patra; +Cc: Andrew Jones, Samuel Holland, Anup Patel, opensbi, Anup Patel

Extend hart protection abstraction to support ID configuration related
ISA extensions such as RISC-V worlds, Supervisor domain ID, QoS ID, etc.

These patches can also be found in sbi_hart_protect_imp_v1 branch
at: https://github.com/avpatel/opensbi.git

Anup Patel (5):
  lib: sbi: Fix typos related to hart protection
  lib: sbi: Introduce sbi_hart_protection_reconfigure() function
  lib: sbi: Add domain parameter to hart protection (un)configure()
  lib: sbi: Extend hart protection abstraction to allow ID configuration
  lib: sbi: Print list of all hart protection mechanisms at boot time

 include/sbi/sbi_hart_protection.h |  49 ++++++++--
 lib/sbi/sbi_domain_context.c      |   3 +-
 lib/sbi/sbi_hart_pmp.c            |  13 ++-
 lib/sbi/sbi_hart_protection.c     | 151 +++++++++++++++++++++++++++---
 lib/sbi/sbi_init.c                |  18 ++--
 platform/generic/eswin/eic770x.c  |   8 +-
 6 files changed, 200 insertions(+), 42 deletions(-)

-- 
2.43.0


-- 
opensbi mailing list
opensbi@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/5] lib: sbi: Fix typos related to hart protection
  2026-07-17  7:44 [PATCH 0/5] Extend hart protection abstraction for ID configuration Anup Patel
@ 2026-07-17  7:44 ` Anup Patel
  2026-07-17  7:44 ` [PATCH 2/5] lib: sbi: Introduce sbi_hart_protection_reconfigure() function Anup Patel
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: Anup Patel @ 2026-07-17  7:44 UTC (permalink / raw)
  To: Atish Patra; +Cc: Andrew Jones, Samuel Holland, Anup Patel, opensbi, Anup Patel

The hart protection is incorrectly mentioned as hart isolation
at few places in sbi_init.c hence fix these typos.

Signed-off-by: Anup Patel <anup.patel@oss.qualcomm.com>
---
 lib/sbi/sbi_init.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/sbi/sbi_init.c b/lib/sbi/sbi_init.c
index 658fe37f..4208db0b 100644
--- a/lib/sbi/sbi_init.c
+++ b/lib/sbi/sbi_init.c
@@ -428,12 +428,12 @@ static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid)
 	}
 
 	/*
-	 * Configure hart isolation at last because if SMEPMP is,
+	 * Configure hart protection at last because if SMEPMP is,
 	 * detected, M-mode access to the S/U space will be rescinded.
 	 */
 	rc = sbi_hart_protection_configure(scratch);
 	if (rc) {
-		sbi_printf("%s: hart isolation configure failed (error %d)\n",
+		sbi_printf("%s: hart protection configure failed (error %d)\n",
 			   __func__, rc);
 		sbi_hart_hang();
 	}
@@ -507,7 +507,7 @@ static void __noreturn init_warm_startup(struct sbi_scratch *scratch,
 		sbi_hart_hang();
 
 	/*
-	 * Configure hart isolation at last because if SMEPMP is,
+	 * Configure hart protection at last because if SMEPMP is,
 	 * detected, M-mode access to the S/U space will be rescinded.
 	 */
 	rc = sbi_hart_protection_configure(scratch);
-- 
2.43.0


-- 
opensbi mailing list
opensbi@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/5] lib: sbi: Introduce sbi_hart_protection_reconfigure() function
  2026-07-17  7:44 [PATCH 0/5] Extend hart protection abstraction for ID configuration Anup Patel
  2026-07-17  7:44 ` [PATCH 1/5] lib: sbi: Fix typos related to hart protection Anup Patel
@ 2026-07-17  7:44 ` Anup Patel
  2026-07-17  7:44 ` [PATCH 3/5] lib: sbi: Add domain parameter to hart protection (un)configure() Anup Patel
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: Anup Patel @ 2026-07-17  7:44 UTC (permalink / raw)
  To: Atish Patra; +Cc: Andrew Jones, Samuel Holland, Anup Patel, opensbi, Anup Patel

Instead of assuming that hart protection reconfiguration is unconfigure
followed by configure, introduce a separate sbi_hart_protection_reconfigure()
function and use it in switch_to_next_domain_context().

Signed-off-by: Anup Patel <anup.patel@oss.qualcomm.com>
---
 include/sbi/sbi_hart_protection.h |  7 +++++++
 lib/sbi/sbi_domain_context.c      |  3 +--
 lib/sbi/sbi_hart_protection.c     | 33 +++++++++++++++++++++++++------
 3 files changed, 35 insertions(+), 8 deletions(-)

diff --git a/include/sbi/sbi_hart_protection.h b/include/sbi/sbi_hart_protection.h
index d65f32ca..6698ceb0 100644
--- a/include/sbi/sbi_hart_protection.h
+++ b/include/sbi/sbi_hart_protection.h
@@ -77,6 +77,13 @@ int sbi_hart_protection_configure(struct sbi_scratch *scratch);
  */
 void sbi_hart_protection_unconfigure(struct sbi_scratch *scratch);
 
+/**
+ * Re-configure protection for current HART
+ *
+ * @param scratch pointer to scratch space of current HART
+ */
+int sbi_hart_protection_reconfigure(struct sbi_scratch *scratch);
+
 /**
  * Create temporary mapping to access address range on current HART
  *
diff --git a/lib/sbi/sbi_domain_context.c b/lib/sbi/sbi_domain_context.c
index cc4cc04d..7d9817d6 100644
--- a/lib/sbi/sbi_domain_context.c
+++ b/lib/sbi/sbi_domain_context.c
@@ -171,8 +171,7 @@ static int switch_to_next_domain_context(struct hart_context *ctx,
 	 * is also required for some of the above CSR updates (such
 	 * as satp CSR).
 	 */
-	sbi_hart_protection_unconfigure(scratch);
-	sbi_hart_protection_configure(scratch);
+	sbi_hart_protection_reconfigure(scratch);
 
 	/* Mark current context structure initialized because context saved */
 	ctx->initialized = true;
diff --git a/lib/sbi/sbi_hart_protection.c b/lib/sbi/sbi_hart_protection.c
index fbebfd1a..ed407ab7 100644
--- a/lib/sbi/sbi_hart_protection.c
+++ b/lib/sbi/sbi_hart_protection.c
@@ -49,10 +49,9 @@ void sbi_hart_protection_unregister(struct sbi_hart_protection *hprot)
 	sbi_list_del(&hprot->head);
 }
 
-int sbi_hart_protection_configure(struct sbi_scratch *scratch)
+static int __hart_protection_configure(struct sbi_scratch *scratch,
+				       struct sbi_hart_protection *hprot)
 {
-	struct sbi_hart_protection *hprot = sbi_hart_protection_best();
-
 	if (!hprot)
 		return 0;
 	if (!hprot->configure)
@@ -61,16 +60,38 @@ int sbi_hart_protection_configure(struct sbi_scratch *scratch)
 	return hprot->configure(scratch);
 }
 
-void sbi_hart_protection_unconfigure(struct sbi_scratch *scratch)
+static void __hart_protection_unconfigure(struct sbi_scratch *scratch,
+					  struct sbi_hart_protection *hprot)
 {
-	struct sbi_hart_protection *hprot = sbi_hart_protection_best();
-
 	if (!hprot || !hprot->unconfigure)
 		return;
 
 	hprot->unconfigure(scratch);
 }
 
+int sbi_hart_protection_configure(struct sbi_scratch *scratch)
+{
+	return __hart_protection_configure(scratch, sbi_hart_protection_best());
+}
+
+void sbi_hart_protection_unconfigure(struct sbi_scratch *scratch)
+{
+	__hart_protection_unconfigure(scratch, sbi_hart_protection_best());
+}
+
+int sbi_hart_protection_reconfigure(struct sbi_scratch *scratch)
+{
+	struct sbi_hart_protection *hprot = sbi_hart_protection_best();
+	int ret;
+
+	__hart_protection_unconfigure(scratch, hprot);
+	ret = __hart_protection_configure(scratch, hprot);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
 int sbi_hart_protection_map_range(unsigned long base, unsigned long size)
 {
 	struct sbi_hart_protection *hprot = sbi_hart_protection_best();
-- 
2.43.0


-- 
opensbi mailing list
opensbi@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 3/5] lib: sbi: Add domain parameter to hart protection (un)configure()
  2026-07-17  7:44 [PATCH 0/5] Extend hart protection abstraction for ID configuration Anup Patel
  2026-07-17  7:44 ` [PATCH 1/5] lib: sbi: Fix typos related to hart protection Anup Patel
  2026-07-17  7:44 ` [PATCH 2/5] lib: sbi: Introduce sbi_hart_protection_reconfigure() function Anup Patel
@ 2026-07-17  7:44 ` Anup Patel
  2026-07-17  7:44 ` [PATCH 4/5] lib: sbi: Extend hart protection abstraction to allow ID configuration Anup Patel
  2026-07-17  7:44 ` [PATCH 5/5] lib: sbi: Print list of all hart protection mechanisms at boot time Anup Patel
  4 siblings, 0 replies; 10+ messages in thread
From: Anup Patel @ 2026-07-17  7:44 UTC (permalink / raw)
  To: Atish Patra; +Cc: Andrew Jones, Samuel Holland, Anup Patel, opensbi, Anup Patel

The switch_to_next_domain_context() already has the pointers to current
and next domains so pass them as parameters to hart protection configure()
and unconfigure() callbacks.

Signed-off-by: Anup Patel <anup.patel@oss.qualcomm.com>
---
 include/sbi/sbi_hart_protection.h | 25 +++++++++++++++++++------
 lib/sbi/sbi_domain_context.c      |  2 +-
 lib/sbi/sbi_hart_pmp.c            | 11 ++++++-----
 lib/sbi/sbi_hart_protection.c     | 28 +++++++++++++++++-----------
 lib/sbi/sbi_init.c                |  6 +++---
 platform/generic/eswin/eic770x.c  |  7 ++++---
 6 files changed, 50 insertions(+), 29 deletions(-)

diff --git a/include/sbi/sbi_hart_protection.h b/include/sbi/sbi_hart_protection.h
index 6698ceb0..5e170f05 100644
--- a/include/sbi/sbi_hart_protection.h
+++ b/include/sbi/sbi_hart_protection.h
@@ -11,6 +11,7 @@
 #include <sbi/sbi_list.h>
 
 struct sbi_scratch;
+struct sbi_domain;
 
 /** Representation of hart protection mechanism */
 struct sbi_hart_protection {
@@ -24,10 +25,10 @@ struct sbi_hart_protection {
 	unsigned long rating;
 
 	/** Configure protection for current HART (Mandatory) */
-	int (*configure)(struct sbi_scratch *scratch);
+	int (*configure)(struct sbi_scratch *scratch, struct sbi_domain *dom);
 
-	/** Unconfigure protection for current HART (Mandatory) */
-	void (*unconfigure)(struct sbi_scratch *scratch);
+	/** Unconfigure protection for current HART (Optional) */
+	void (*unconfigure)(struct sbi_scratch *scratch, struct sbi_domain *dom);
 
 	/** Create temporary mapping to access address range on current HART (Optional) */
 	int (*map_range)(struct sbi_scratch *scratch,
@@ -65,24 +66,36 @@ void sbi_hart_protection_unregister(struct sbi_hart_protection *hprot);
  * Configure protection for current HART
  *
  * @param scratch pointer to scratch space of current HART
+ * @param dom pointer to the domain for which HART protection
+ *        is being configured
  *
  * @return 0 on success and negative error code on failure
  */
-int sbi_hart_protection_configure(struct sbi_scratch *scratch);
+int sbi_hart_protection_configure(struct sbi_scratch *scratch,
+				  struct sbi_domain *dom);
 
 /**
  * Unconfigure protection for current HART
  *
  * @param scratch pointer to scratch space of current HART
+ * @param dom pointer to the domain for which HART protection
+ *        is being unconfigured
  */
-void sbi_hart_protection_unconfigure(struct sbi_scratch *scratch);
+void sbi_hart_protection_unconfigure(struct sbi_scratch *scratch,
+				     struct sbi_domain *dom);
 
 /**
  * Re-configure protection for current HART
  *
  * @param scratch pointer to scratch space of current HART
+ * @param current_dom pointer to the current domain for which
+ *        HART protection is being unconfigured
+ * @param next_dom pointer to the next domain for which HART
+ *        protection is being configured
  */
-int sbi_hart_protection_reconfigure(struct sbi_scratch *scratch);
+int sbi_hart_protection_reconfigure(struct sbi_scratch *scratch,
+				    struct sbi_domain *current_dom,
+				    struct sbi_domain *next_dom);
 
 /**
  * Create temporary mapping to access address range on current HART
diff --git a/lib/sbi/sbi_domain_context.c b/lib/sbi/sbi_domain_context.c
index 7d9817d6..0861d541 100644
--- a/lib/sbi/sbi_domain_context.c
+++ b/lib/sbi/sbi_domain_context.c
@@ -171,7 +171,7 @@ static int switch_to_next_domain_context(struct hart_context *ctx,
 	 * is also required for some of the above CSR updates (such
 	 * as satp CSR).
 	 */
-	sbi_hart_protection_reconfigure(scratch);
+	sbi_hart_protection_reconfigure(scratch, current_dom, target_dom);
 
 	/* Mark current context structure initialized because context saved */
 	ctx->initialized = true;
diff --git a/lib/sbi/sbi_hart_pmp.c b/lib/sbi/sbi_hart_pmp.c
index 4528258d..5ede3cc1 100644
--- a/lib/sbi/sbi_hart_pmp.c
+++ b/lib/sbi/sbi_hart_pmp.c
@@ -228,10 +228,10 @@ static bool is_valid_pmp_idx(unsigned int pmp_count, unsigned int pmp_idx)
 	return false;
 }
 
-static int sbi_hart_smepmp_configure(struct sbi_scratch *scratch)
+static int sbi_hart_smepmp_configure(struct sbi_scratch *scratch,
+				     struct sbi_domain *dom)
 {
 	struct sbi_domain_memregion *reg;
-	struct sbi_domain *dom = sbi_domain_thishart_ptr();
 	unsigned int pmp_log2gran, pmp_bits;
 	unsigned int pmp_idx, pmp_count;
 	unsigned long pmp_addr_max;
@@ -366,10 +366,10 @@ static int sbi_hart_smepmp_unmap_range(struct sbi_scratch *scratch,
 	return sbi_hart_pmp_disable(SBI_SMEPMP_RESV_ENTRY);
 }
 
-static int sbi_hart_oldpmp_configure(struct sbi_scratch *scratch)
+static int sbi_hart_oldpmp_configure(struct sbi_scratch *scratch,
+				     struct sbi_domain *dom)
 {
 	struct sbi_domain_memregion *reg;
-	struct sbi_domain *dom = sbi_domain_thishart_ptr();
 	unsigned long pmp_addr, pmp_addr_max;
 	unsigned int pmp_log2gran, pmp_bits;
 	unsigned int pmp_idx, pmp_count;
@@ -407,7 +407,8 @@ static int sbi_hart_oldpmp_configure(struct sbi_scratch *scratch)
 	return 0;
 }
 
-static void sbi_hart_pmp_unconfigure(struct sbi_scratch *scratch)
+static void sbi_hart_pmp_unconfigure(struct sbi_scratch *scratch,
+				     struct sbi_domain *dom)
 {
 	int i, pmp_count = sbi_hart_pmp_count(scratch);
 
diff --git a/lib/sbi/sbi_hart_protection.c b/lib/sbi/sbi_hart_protection.c
index ed407ab7..fecefde8 100644
--- a/lib/sbi/sbi_hart_protection.c
+++ b/lib/sbi/sbi_hart_protection.c
@@ -50,42 +50,48 @@ void sbi_hart_protection_unregister(struct sbi_hart_protection *hprot)
 }
 
 static int __hart_protection_configure(struct sbi_scratch *scratch,
-				       struct sbi_hart_protection *hprot)
+				       struct sbi_hart_protection *hprot,
+				       struct sbi_domain *dom)
 {
 	if (!hprot)
 		return 0;
 	if (!hprot->configure)
 		return SBI_ENOSYS;
 
-	return hprot->configure(scratch);
+	return hprot->configure(scratch, dom);
 }
 
 static void __hart_protection_unconfigure(struct sbi_scratch *scratch,
-					  struct sbi_hart_protection *hprot)
+					  struct sbi_hart_protection *hprot,
+					  struct sbi_domain *dom)
 {
 	if (!hprot || !hprot->unconfigure)
 		return;
 
-	hprot->unconfigure(scratch);
+	hprot->unconfigure(scratch, dom);
 }
 
-int sbi_hart_protection_configure(struct sbi_scratch *scratch)
+int sbi_hart_protection_configure(struct sbi_scratch *scratch,
+				  struct sbi_domain *dom)
 {
-	return __hart_protection_configure(scratch, sbi_hart_protection_best());
+	return __hart_protection_configure(scratch, sbi_hart_protection_best(), dom);
 }
 
-void sbi_hart_protection_unconfigure(struct sbi_scratch *scratch)
+void sbi_hart_protection_unconfigure(struct sbi_scratch *scratch,
+				     struct sbi_domain *dom)
 {
-	__hart_protection_unconfigure(scratch, sbi_hart_protection_best());
+	__hart_protection_unconfigure(scratch, sbi_hart_protection_best(), dom);
 }
 
-int sbi_hart_protection_reconfigure(struct sbi_scratch *scratch)
+int sbi_hart_protection_reconfigure(struct sbi_scratch *scratch,
+				    struct sbi_domain *current_dom,
+				    struct sbi_domain *next_dom)
 {
 	struct sbi_hart_protection *hprot = sbi_hart_protection_best();
 	int ret;
 
-	__hart_protection_unconfigure(scratch, hprot);
-	ret = __hart_protection_configure(scratch, hprot);
+	__hart_protection_unconfigure(scratch, hprot, current_dom);
+	ret = __hart_protection_configure(scratch, hprot, next_dom);
 	if (ret)
 		return ret;
 
diff --git a/lib/sbi/sbi_init.c b/lib/sbi/sbi_init.c
index 4208db0b..d74dc67c 100644
--- a/lib/sbi/sbi_init.c
+++ b/lib/sbi/sbi_init.c
@@ -431,7 +431,7 @@ static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid)
 	 * Configure hart protection at last because if SMEPMP is,
 	 * detected, M-mode access to the S/U space will be rescinded.
 	 */
-	rc = sbi_hart_protection_configure(scratch);
+	rc = sbi_hart_protection_configure(scratch, sbi_domain_thishart_ptr());
 	if (rc) {
 		sbi_printf("%s: hart protection configure failed (error %d)\n",
 			   __func__, rc);
@@ -510,7 +510,7 @@ static void __noreturn init_warm_startup(struct sbi_scratch *scratch,
 	 * Configure hart protection at last because if SMEPMP is,
 	 * detected, M-mode access to the S/U space will be rescinded.
 	 */
-	rc = sbi_hart_protection_configure(scratch);
+	rc = sbi_hart_protection_configure(scratch, sbi_domain_thishart_ptr());
 	if (rc)
 		sbi_hart_hang();
 
@@ -531,7 +531,7 @@ static void __noreturn init_warm_resume(struct sbi_scratch *scratch,
 	if (rc)
 		sbi_hart_hang();
 
-	rc = sbi_hart_protection_configure(scratch);
+	rc = sbi_hart_protection_configure(scratch, sbi_domain_thishart_ptr());
 	if (rc)
 		sbi_hart_hang();
 
diff --git a/platform/generic/eswin/eic770x.c b/platform/generic/eswin/eic770x.c
index 3fe3d090..da4d0e34 100644
--- a/platform/generic/eswin/eic770x.c
+++ b/platform/generic/eswin/eic770x.c
@@ -380,9 +380,9 @@ static int eswin_eic7700_final_init(bool cold_boot)
 	return 0;
 }
 
-static int eswin_eic7700_pmp_configure(struct sbi_scratch *scratch)
+static int eswin_eic7700_pmp_configure(struct sbi_scratch *scratch,
+				       struct sbi_domain *dom)
 {
-	struct sbi_domain *dom = sbi_domain_thishart_ptr();
 	struct sbi_domain_memregion *reg, *prev = NULL;
 	unsigned int pmp_idx, pmp_max;
 	unsigned int i, j;
@@ -453,7 +453,8 @@ no_more_pmp:
 	return SBI_EFAIL;
 }
 
-static void eswin_eic7700_pmp_unconfigure(struct sbi_scratch *scratch)
+static void eswin_eic7700_pmp_unconfigure(struct sbi_scratch *scratch,
+					  struct sbi_domain *dom)
 {
 	/* Enable P550 internal + System Port */
 	sbi_hart_pmp_set(PMP_FREE_A_START + PMP_FREE_A_COUNT - 1, 0, 0,
-- 
2.43.0


-- 
opensbi mailing list
opensbi@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 4/5] lib: sbi: Extend hart protection abstraction to allow ID configuration
  2026-07-17  7:44 [PATCH 0/5] Extend hart protection abstraction for ID configuration Anup Patel
                   ` (2 preceding siblings ...)
  2026-07-17  7:44 ` [PATCH 3/5] lib: sbi: Add domain parameter to hart protection (un)configure() Anup Patel
@ 2026-07-17  7:44 ` Anup Patel
  2026-07-20 10:10   ` Yu-Chien Peter Lin
  2026-07-17  7:44 ` [PATCH 5/5] lib: sbi: Print list of all hart protection mechanisms at boot time Anup Patel
  4 siblings, 1 reply; 10+ messages in thread
From: Anup Patel @ 2026-07-17  7:44 UTC (permalink / raw)
  To: Atish Patra; +Cc: Andrew Jones, Samuel Holland, Anup Patel, opensbi, Anup Patel

There are various ID configuration ISA extensions such as RISC-V Worlds,
Supervisor domain ID, QoS ID, etc which need to be re-configured upon
domain context switch on a hart. Extend hart protection abstraction to
support both memory protection and ID configuration ISA extensions.

Signed-off-by: Anup Patel <anup.patel@oss.qualcomm.com>
---
 include/sbi/sbi_hart_protection.h | 16 +++++-
 lib/sbi/sbi_hart_pmp.c            |  2 +
 lib/sbi/sbi_hart_protection.c     | 94 ++++++++++++++++++++++++++-----
 lib/sbi/sbi_init.c                |  2 +-
 platform/generic/eswin/eic770x.c  |  1 +
 5 files changed, 98 insertions(+), 17 deletions(-)

diff --git a/include/sbi/sbi_hart_protection.h b/include/sbi/sbi_hart_protection.h
index 5e170f05..1358b5be 100644
--- a/include/sbi/sbi_hart_protection.h
+++ b/include/sbi/sbi_hart_protection.h
@@ -13,6 +13,13 @@
 struct sbi_scratch;
 struct sbi_domain;
 
+/** Different types of hart protection mechanisms */
+enum sbi_hart_protection_type {
+	SBI_HART_PROTECTION_TYPE_MEMORY = 0,
+	SBI_HART_PROTECTION_TYPE_ID,
+	SBI_HART_PROTECTIOn_TYPE_MAX
+};
+
 /** Representation of hart protection mechanism */
 struct sbi_hart_protection {
 	/** List head */
@@ -21,6 +28,9 @@ struct sbi_hart_protection {
 	/** Name of the hart protection mechanism */
 	char name[32];
 
+	/** Type of the hart protection mechanism */
+	enum sbi_hart_protection_type type;
+
 	/** Ratings of the hart protection mechanism (higher is better) */
 	unsigned long rating;
 
@@ -40,11 +50,11 @@ struct sbi_hart_protection {
 };
 
 /**
- * Get the best hart protection mechanism
+ * Get the best hart memory protection mechanism
  *
- * @return pointer to best hart protection mechanism
+ * @return pointer to best hart memory protection mechanism
  */
-struct sbi_hart_protection *sbi_hart_protection_best(void);
+struct sbi_hart_protection *sbi_hart_memory_protection_best(void);
 
 /**
  * Register a hart protection mechanism
diff --git a/lib/sbi/sbi_hart_pmp.c b/lib/sbi/sbi_hart_pmp.c
index 5ede3cc1..c0a4ce1b 100644
--- a/lib/sbi/sbi_hart_pmp.c
+++ b/lib/sbi/sbi_hart_pmp.c
@@ -425,6 +425,7 @@ static void sbi_hart_pmp_unconfigure(struct sbi_scratch *scratch,
 static struct sbi_hart_protection pmp_protection = {
 	.name = "pmp",
 	.rating = 100,
+	.type = SBI_HART_PROTECTION_TYPE_MEMORY,
 	.configure = sbi_hart_oldpmp_configure,
 	.unconfigure = sbi_hart_pmp_unconfigure,
 };
@@ -432,6 +433,7 @@ static struct sbi_hart_protection pmp_protection = {
 static struct sbi_hart_protection epmp_protection = {
 	.name = "epmp",
 	.rating = 200,
+	.type = SBI_HART_PROTECTION_TYPE_MEMORY,
 	.configure = sbi_hart_smepmp_configure,
 	.unconfigure = sbi_hart_pmp_unconfigure,
 	.map_range = sbi_hart_smepmp_map_range,
diff --git a/lib/sbi/sbi_hart_protection.c b/lib/sbi/sbi_hart_protection.c
index fecefde8..d31e9938 100644
--- a/lib/sbi/sbi_hart_protection.c
+++ b/lib/sbi/sbi_hart_protection.c
@@ -10,12 +10,16 @@
 
 static SBI_LIST_HEAD(hart_protection_list);
 
-struct sbi_hart_protection *sbi_hart_protection_best(void)
+struct sbi_hart_protection *sbi_hart_memory_protection_best(void)
 {
-	if (sbi_list_empty(&hart_protection_list))
-		return NULL;
+	struct sbi_hart_protection *pos;
 
-	return sbi_list_first_entry(&hart_protection_list, struct sbi_hart_protection, head);
+	sbi_list_for_each_entry(pos, &hart_protection_list, head) {
+		if (pos->type == SBI_HART_PROTECTION_TYPE_MEMORY)
+			return pos;
+	}
+
+	return NULL;
 }
 
 int sbi_hart_protection_register(struct sbi_hart_protection *hprot)
@@ -74,33 +78,97 @@ static void __hart_protection_unconfigure(struct sbi_scratch *scratch,
 int sbi_hart_protection_configure(struct sbi_scratch *scratch,
 				  struct sbi_domain *dom)
 {
-	return __hart_protection_configure(scratch, sbi_hart_protection_best(), dom);
+	bool do_configure, memory_protect_done = false;
+	struct sbi_hart_protection *hprot;
+	int ret;
+
+	sbi_list_for_each_entry(hprot, &hart_protection_list, head) {
+		do_configure = false;
+		switch (hprot->type) {
+		case SBI_HART_PROTECTION_TYPE_MEMORY:
+			do_configure = !memory_protect_done;
+			memory_protect_done = true;
+			break;
+		case SBI_HART_PROTECTION_TYPE_ID:
+			do_configure = true;
+			break;
+		default:
+			break;
+		}
+		if (!do_configure)
+			continue;
+
+		ret = __hart_protection_configure(scratch, hprot, dom);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
 }
 
 void sbi_hart_protection_unconfigure(struct sbi_scratch *scratch,
 				     struct sbi_domain *dom)
 {
-	__hart_protection_unconfigure(scratch, sbi_hart_protection_best(), dom);
+
+	bool do_unconfigure, memory_protect_done = false;
+	struct sbi_hart_protection *hprot;
+
+	sbi_list_for_each_entry(hprot, &hart_protection_list, head) {
+		do_unconfigure = false;
+		switch (hprot->type) {
+		case SBI_HART_PROTECTION_TYPE_MEMORY:
+			do_unconfigure = !memory_protect_done;
+			memory_protect_done = true;
+			break;
+		case SBI_HART_PROTECTION_TYPE_ID:
+			do_unconfigure = true;
+			break;
+		default:
+			break;
+		}
+		if (!do_unconfigure)
+			continue;
+
+		__hart_protection_unconfigure(scratch, hprot, dom);
+	}
 }
 
 int sbi_hart_protection_reconfigure(struct sbi_scratch *scratch,
 				    struct sbi_domain *current_dom,
 				    struct sbi_domain *next_dom)
 {
-	struct sbi_hart_protection *hprot = sbi_hart_protection_best();
+	bool do_reconfigure, memory_protect_done = false;
+	struct sbi_hart_protection *hprot;
 	int ret;
 
-	__hart_protection_unconfigure(scratch, hprot, current_dom);
-	ret = __hart_protection_configure(scratch, hprot, next_dom);
-	if (ret)
-		return ret;
+	sbi_list_for_each_entry(hprot, &hart_protection_list, head) {
+		do_reconfigure = false;
+		switch (hprot->type) {
+		case SBI_HART_PROTECTION_TYPE_MEMORY:
+			do_reconfigure = !memory_protect_done;
+			memory_protect_done = true;
+			break;
+		case SBI_HART_PROTECTION_TYPE_ID:
+			do_reconfigure = true;
+			break;
+		default:
+			break;
+		}
+		if (!do_reconfigure)
+			continue;
+
+		__hart_protection_unconfigure(scratch, hprot, current_dom);
+		ret = __hart_protection_configure(scratch, hprot, next_dom);
+		if (ret)
+			return ret;
+	}
 
 	return 0;
 }
 
 int sbi_hart_protection_map_range(unsigned long base, unsigned long size)
 {
-	struct sbi_hart_protection *hprot = sbi_hart_protection_best();
+	struct sbi_hart_protection *hprot = sbi_hart_memory_protection_best();
 
 	if (!hprot || !hprot->map_range)
 		return 0;
@@ -110,7 +178,7 @@ int sbi_hart_protection_map_range(unsigned long base, unsigned long size)
 
 int sbi_hart_protection_unmap_range(unsigned long base, unsigned long size)
 {
-	struct sbi_hart_protection *hprot = sbi_hart_protection_best();
+	struct sbi_hart_protection *hprot = sbi_hart_memory_protection_best();
 
 	if (!hprot || !hprot->unmap_range)
 		return 0;
diff --git a/lib/sbi/sbi_init.c b/lib/sbi/sbi_init.c
index d74dc67c..3f1f136a 100644
--- a/lib/sbi/sbi_init.c
+++ b/lib/sbi/sbi_init.c
@@ -93,7 +93,7 @@ static void sbi_boot_print_general(struct sbi_scratch *scratch)
 	sbi_printf("Platform Features           : %s\n", str);
 	sbi_printf("Platform HART Count         : %u\n",
 		   sbi_platform_hart_count(plat));
-	hprot = sbi_hart_protection_best();
+	hprot = sbi_hart_memory_protection_best();
 	sbi_printf("Platform HART Protection    : %s\n",
 		   (hprot) ? hprot->name : "---");
 	idev = sbi_ipi_get_device();
diff --git a/platform/generic/eswin/eic770x.c b/platform/generic/eswin/eic770x.c
index da4d0e34..c71198a8 100644
--- a/platform/generic/eswin/eic770x.c
+++ b/platform/generic/eswin/eic770x.c
@@ -470,6 +470,7 @@ static void eswin_eic7700_pmp_unconfigure(struct sbi_scratch *scratch,
 static struct sbi_hart_protection eswin_eic7700_pmp_protection = {
 	.name = "eic7700_pmp",
 	.rating = -1UL,
+	.type = SBI_HART_PROTECTION_TYPE_MEMORY,
 	.configure = eswin_eic7700_pmp_configure,
 	.unconfigure = eswin_eic7700_pmp_unconfigure,
 };
-- 
2.43.0


-- 
opensbi mailing list
opensbi@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 5/5] lib: sbi: Print list of all hart protection mechanisms at boot time
  2026-07-17  7:44 [PATCH 0/5] Extend hart protection abstraction for ID configuration Anup Patel
                   ` (3 preceding siblings ...)
  2026-07-17  7:44 ` [PATCH 4/5] lib: sbi: Extend hart protection abstraction to allow ID configuration Anup Patel
@ 2026-07-17  7:44 ` Anup Patel
  4 siblings, 0 replies; 10+ messages in thread
From: Anup Patel @ 2026-07-17  7:44 UTC (permalink / raw)
  To: Atish Patra; +Cc: Andrew Jones, Samuel Holland, Anup Patel, opensbi, Anup Patel

Instead of printing only the best hart memory protection name at
boot time let's print a list of all hart projection mechanisms.

Signed-off-by: Anup Patel <anup.patel@oss.qualcomm.com>
---
 include/sbi/sbi_hart_protection.h |  7 +++++--
 lib/sbi/sbi_hart_protection.c     | 34 ++++++++++++++++++++++++++++---
 lib/sbi/sbi_init.c                |  6 ++----
 3 files changed, 38 insertions(+), 9 deletions(-)

diff --git a/include/sbi/sbi_hart_protection.h b/include/sbi/sbi_hart_protection.h
index 1358b5be..dbe8eae1 100644
--- a/include/sbi/sbi_hart_protection.h
+++ b/include/sbi/sbi_hart_protection.h
@@ -50,11 +50,14 @@ struct sbi_hart_protection {
 };
 
 /**
- * Get the best hart memory protection mechanism
+ * Get a string containing names of protection mechanisms
+ *
+ * @param out_str pointer to output string
+ * @param out_str_size maximum size of output string
  *
  * @return pointer to best hart memory protection mechanism
  */
-struct sbi_hart_protection *sbi_hart_memory_protection_best(void);
+void sbi_hart_protection_get_str(char *out_str, int out_str_size);
 
 /**
  * Register a hart protection mechanism
diff --git a/lib/sbi/sbi_hart_protection.c b/lib/sbi/sbi_hart_protection.c
index d31e9938..a5f19639 100644
--- a/lib/sbi/sbi_hart_protection.c
+++ b/lib/sbi/sbi_hart_protection.c
@@ -4,13 +4,15 @@
  * Copyright (c) 2025 Ventana Micro Systems Inc.
  */
 
+#include <sbi/sbi_console.h>
 #include <sbi/sbi_error.h>
 #include <sbi/sbi_hart_protection.h>
 #include <sbi/sbi_scratch.h>
+#include <sbi/sbi_string.h>
 
 static SBI_LIST_HEAD(hart_protection_list);
 
-struct sbi_hart_protection *sbi_hart_memory_protection_best(void)
+static struct sbi_hart_protection *__hart_memory_protection_best(void)
 {
 	struct sbi_hart_protection *pos;
 
@@ -22,6 +24,32 @@ struct sbi_hart_protection *sbi_hart_memory_protection_best(void)
 	return NULL;
 }
 
+void sbi_hart_protection_get_str(char *out_str, int out_str_size)
+{
+	bool memory_protect_done = false;
+	struct sbi_hart_protection *pos;
+	int offset = 0;
+
+	if (!out_str || out_str_size <= 0)
+		return;
+	sbi_memset(out_str, 0, out_str_size);
+
+	sbi_list_for_each_entry(pos, &hart_protection_list, head) {
+		if (pos->type == SBI_HART_PROTECTION_TYPE_MEMORY) {
+			if (memory_protect_done)
+				continue;
+			memory_protect_done = true;
+		}
+		sbi_snprintf(out_str + offset, out_str_size - offset, "%s,", pos->name);
+		offset = offset + sbi_strlen(pos->name) + 1;
+	}
+
+	if (offset)
+		out_str[offset - 1] = '\0';
+	else
+		sbi_strncpy(out_str, "none", out_str_size);
+}
+
 int sbi_hart_protection_register(struct sbi_hart_protection *hprot)
 {
 	struct sbi_hart_protection *pos = NULL;
@@ -168,7 +196,7 @@ int sbi_hart_protection_reconfigure(struct sbi_scratch *scratch,
 
 int sbi_hart_protection_map_range(unsigned long base, unsigned long size)
 {
-	struct sbi_hart_protection *hprot = sbi_hart_memory_protection_best();
+	struct sbi_hart_protection *hprot = __hart_memory_protection_best();
 
 	if (!hprot || !hprot->map_range)
 		return 0;
@@ -178,7 +206,7 @@ int sbi_hart_protection_map_range(unsigned long base, unsigned long size)
 
 int sbi_hart_protection_unmap_range(unsigned long base, unsigned long size)
 {
-	struct sbi_hart_protection *hprot = sbi_hart_memory_protection_best();
+	struct sbi_hart_protection *hprot = __hart_memory_protection_best();
 
 	if (!hprot || !hprot->unmap_range)
 		return 0;
diff --git a/lib/sbi/sbi_init.c b/lib/sbi/sbi_init.c
index 3f1f136a..c3f09c52 100644
--- a/lib/sbi/sbi_init.c
+++ b/lib/sbi/sbi_init.c
@@ -76,7 +76,6 @@ static void sbi_boot_print_general(struct sbi_scratch *scratch)
 	const struct sbi_hsm_device *hdev;
 	const struct sbi_ipi_device *idev;
 	const struct sbi_timer_device *tdev;
-	const struct sbi_hart_protection *hprot;
 	const struct sbi_console_device *cdev;
 	const struct sbi_system_reset_device *srdev;
 	const struct sbi_system_suspend_device *susp_dev;
@@ -93,9 +92,8 @@ static void sbi_boot_print_general(struct sbi_scratch *scratch)
 	sbi_printf("Platform Features           : %s\n", str);
 	sbi_printf("Platform HART Count         : %u\n",
 		   sbi_platform_hart_count(plat));
-	hprot = sbi_hart_memory_protection_best();
-	sbi_printf("Platform HART Protection    : %s\n",
-		   (hprot) ? hprot->name : "---");
+	sbi_hart_protection_get_str(str, sizeof(str));
+	sbi_printf("Platform HART Protection    : %s\n", str);
 	idev = sbi_ipi_get_device();
 	sbi_printf("Platform IPI Device         : %s\n",
 		   (idev) ? idev->name : "---");
-- 
2.43.0


-- 
opensbi mailing list
opensbi@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 4/5] lib: sbi: Extend hart protection abstraction to allow ID configuration
  2026-07-17  7:44 ` [PATCH 4/5] lib: sbi: Extend hart protection abstraction to allow ID configuration Anup Patel
@ 2026-07-20 10:10   ` Yu-Chien Peter Lin
  2026-07-20 10:49     ` Anup Patel
  0 siblings, 1 reply; 10+ messages in thread
From: Yu-Chien Peter Lin @ 2026-07-20 10:10 UTC (permalink / raw)
  To: Anup Patel
  Cc: Atish Patra, Andrew Jones, Samuel Holland, Anup Patel, opensbi,
	raymondmaoca, zong.li, jim.shu, pawandeep.oza

Hi Anup and Raymond,

On Fri, Jul 17, 2026 at 01:14:12PM +0530, Anup Patel wrote:
> There are various ID configuration ISA extensions such as RISC-V Worlds,
> Supervisor domain ID, QoS ID, etc which need to be re-configured upon
> domain context switch on a hart. Extend hart protection abstraction to
> support both memory protection and ID configuration ISA extensions.

I will rework my "[RFC,00/12] Add RISC-V Worlds ISA support to OpenSBI"
series based on this series.

Thanks,
Peter Lin

> 
> Signed-off-by: Anup Patel <anup.patel@oss.qualcomm.com>
> ---
>  include/sbi/sbi_hart_protection.h | 16 +++++-
>  lib/sbi/sbi_hart_pmp.c            |  2 +
>  lib/sbi/sbi_hart_protection.c     | 94 ++++++++++++++++++++++++++-----
>  lib/sbi/sbi_init.c                |  2 +-
>  platform/generic/eswin/eic770x.c  |  1 +
>  5 files changed, 98 insertions(+), 17 deletions(-)
> 
> diff --git a/include/sbi/sbi_hart_protection.h b/include/sbi/sbi_hart_protection.h
> index 5e170f05..1358b5be 100644
> --- a/include/sbi/sbi_hart_protection.h
> +++ b/include/sbi/sbi_hart_protection.h
> @@ -13,6 +13,13 @@
>  struct sbi_scratch;
>  struct sbi_domain;
>  
> +/** Different types of hart protection mechanisms */
> +enum sbi_hart_protection_type {
> +	SBI_HART_PROTECTION_TYPE_MEMORY = 0,
> +	SBI_HART_PROTECTION_TYPE_ID,
> +	SBI_HART_PROTECTIOn_TYPE_MAX
> +};
> +
>  /** Representation of hart protection mechanism */
>  struct sbi_hart_protection {
>  	/** List head */
> @@ -21,6 +28,9 @@ struct sbi_hart_protection {
>  	/** Name of the hart protection mechanism */
>  	char name[32];
>  
> +	/** Type of the hart protection mechanism */
> +	enum sbi_hart_protection_type type;
> +
>  	/** Ratings of the hart protection mechanism (higher is better) */
>  	unsigned long rating;
>  
> @@ -40,11 +50,11 @@ struct sbi_hart_protection {
>  };
>  
>  /**
> - * Get the best hart protection mechanism
> + * Get the best hart memory protection mechanism
>   *
> - * @return pointer to best hart protection mechanism
> + * @return pointer to best hart memory protection mechanism
>   */
> -struct sbi_hart_protection *sbi_hart_protection_best(void);
> +struct sbi_hart_protection *sbi_hart_memory_protection_best(void);
>  
>  /**
>   * Register a hart protection mechanism
> diff --git a/lib/sbi/sbi_hart_pmp.c b/lib/sbi/sbi_hart_pmp.c
> index 5ede3cc1..c0a4ce1b 100644
> --- a/lib/sbi/sbi_hart_pmp.c
> +++ b/lib/sbi/sbi_hart_pmp.c
> @@ -425,6 +425,7 @@ static void sbi_hart_pmp_unconfigure(struct sbi_scratch *scratch,
>  static struct sbi_hart_protection pmp_protection = {
>  	.name = "pmp",
>  	.rating = 100,
> +	.type = SBI_HART_PROTECTION_TYPE_MEMORY,
>  	.configure = sbi_hart_oldpmp_configure,
>  	.unconfigure = sbi_hart_pmp_unconfigure,
>  };
> @@ -432,6 +433,7 @@ static struct sbi_hart_protection pmp_protection = {
>  static struct sbi_hart_protection epmp_protection = {
>  	.name = "epmp",
>  	.rating = 200,
> +	.type = SBI_HART_PROTECTION_TYPE_MEMORY,
>  	.configure = sbi_hart_smepmp_configure,
>  	.unconfigure = sbi_hart_pmp_unconfigure,
>  	.map_range = sbi_hart_smepmp_map_range,
> diff --git a/lib/sbi/sbi_hart_protection.c b/lib/sbi/sbi_hart_protection.c
> index fecefde8..d31e9938 100644
> --- a/lib/sbi/sbi_hart_protection.c
> +++ b/lib/sbi/sbi_hart_protection.c
> @@ -10,12 +10,16 @@
>  
>  static SBI_LIST_HEAD(hart_protection_list);
>  
> -struct sbi_hart_protection *sbi_hart_protection_best(void)
> +struct sbi_hart_protection *sbi_hart_memory_protection_best(void)
>  {
> -	if (sbi_list_empty(&hart_protection_list))
> -		return NULL;
> +	struct sbi_hart_protection *pos;
>  
> -	return sbi_list_first_entry(&hart_protection_list, struct sbi_hart_protection, head);
> +	sbi_list_for_each_entry(pos, &hart_protection_list, head) {
> +		if (pos->type == SBI_HART_PROTECTION_TYPE_MEMORY)
> +			return pos;
> +	}
> +
> +	return NULL;
>  }
>  
>  int sbi_hart_protection_register(struct sbi_hart_protection *hprot)
> @@ -74,33 +78,97 @@ static void __hart_protection_unconfigure(struct sbi_scratch *scratch,
>  int sbi_hart_protection_configure(struct sbi_scratch *scratch,
>  				  struct sbi_domain *dom)
>  {
> -	return __hart_protection_configure(scratch, sbi_hart_protection_best(), dom);
> +	bool do_configure, memory_protect_done = false;
> +	struct sbi_hart_protection *hprot;
> +	int ret;
> +
> +	sbi_list_for_each_entry(hprot, &hart_protection_list, head) {
> +		do_configure = false;
> +		switch (hprot->type) {
> +		case SBI_HART_PROTECTION_TYPE_MEMORY:
> +			do_configure = !memory_protect_done;
> +			memory_protect_done = true;
> +			break;
> +		case SBI_HART_PROTECTION_TYPE_ID:
> +			do_configure = true;
> +			break;
> +		default:
> +			break;
> +		}
> +		if (!do_configure)
> +			continue;
> +
> +		ret = __hart_protection_configure(scratch, hprot, dom);
> +		if (ret)
> +			return ret;
> +	}
> +
> +	return 0;
>  }
>  
>  void sbi_hart_protection_unconfigure(struct sbi_scratch *scratch,
>  				     struct sbi_domain *dom)
>  {
> -	__hart_protection_unconfigure(scratch, sbi_hart_protection_best(), dom);
> +
> +	bool do_unconfigure, memory_protect_done = false;
> +	struct sbi_hart_protection *hprot;
> +
> +	sbi_list_for_each_entry(hprot, &hart_protection_list, head) {
> +		do_unconfigure = false;
> +		switch (hprot->type) {
> +		case SBI_HART_PROTECTION_TYPE_MEMORY:
> +			do_unconfigure = !memory_protect_done;
> +			memory_protect_done = true;
> +			break;
> +		case SBI_HART_PROTECTION_TYPE_ID:
> +			do_unconfigure = true;
> +			break;
> +		default:
> +			break;
> +		}
> +		if (!do_unconfigure)
> +			continue;
> +
> +		__hart_protection_unconfigure(scratch, hprot, dom);
> +	}
>  }
>  
>  int sbi_hart_protection_reconfigure(struct sbi_scratch *scratch,
>  				    struct sbi_domain *current_dom,
>  				    struct sbi_domain *next_dom)
>  {
> -	struct sbi_hart_protection *hprot = sbi_hart_protection_best();
> +	bool do_reconfigure, memory_protect_done = false;
> +	struct sbi_hart_protection *hprot;
>  	int ret;
>  
> -	__hart_protection_unconfigure(scratch, hprot, current_dom);
> -	ret = __hart_protection_configure(scratch, hprot, next_dom);
> -	if (ret)
> -		return ret;
> +	sbi_list_for_each_entry(hprot, &hart_protection_list, head) {
> +		do_reconfigure = false;
> +		switch (hprot->type) {
> +		case SBI_HART_PROTECTION_TYPE_MEMORY:
> +			do_reconfigure = !memory_protect_done;
> +			memory_protect_done = true;
> +			break;
> +		case SBI_HART_PROTECTION_TYPE_ID:
> +			do_reconfigure = true;
> +			break;
> +		default:
> +			break;
> +		}
> +		if (!do_reconfigure)
> +			continue;
> +
> +		__hart_protection_unconfigure(scratch, hprot, current_dom);
> +		ret = __hart_protection_configure(scratch, hprot, next_dom);
> +		if (ret)
> +			return ret;
> +	}
>  
>  	return 0;
>  }
>  
>  int sbi_hart_protection_map_range(unsigned long base, unsigned long size)
>  {
> -	struct sbi_hart_protection *hprot = sbi_hart_protection_best();
> +	struct sbi_hart_protection *hprot = sbi_hart_memory_protection_best();
>  
>  	if (!hprot || !hprot->map_range)
>  		return 0;
> @@ -110,7 +178,7 @@ int sbi_hart_protection_map_range(unsigned long base, unsigned long size)
>  
>  int sbi_hart_protection_unmap_range(unsigned long base, unsigned long size)
>  {
> -	struct sbi_hart_protection *hprot = sbi_hart_protection_best();
> +	struct sbi_hart_protection *hprot = sbi_hart_memory_protection_best();
>  
>  	if (!hprot || !hprot->unmap_range)
>  		return 0;
> diff --git a/lib/sbi/sbi_init.c b/lib/sbi/sbi_init.c
> index d74dc67c..3f1f136a 100644
> --- a/lib/sbi/sbi_init.c
> +++ b/lib/sbi/sbi_init.c
> @@ -93,7 +93,7 @@ static void sbi_boot_print_general(struct sbi_scratch *scratch)
>  	sbi_printf("Platform Features           : %s\n", str);
>  	sbi_printf("Platform HART Count         : %u\n",
>  		   sbi_platform_hart_count(plat));
> -	hprot = sbi_hart_protection_best();
> +	hprot = sbi_hart_memory_protection_best();
>  	sbi_printf("Platform HART Protection    : %s\n",
>  		   (hprot) ? hprot->name : "---");
>  	idev = sbi_ipi_get_device();
> diff --git a/platform/generic/eswin/eic770x.c b/platform/generic/eswin/eic770x.c
> index da4d0e34..c71198a8 100644
> --- a/platform/generic/eswin/eic770x.c
> +++ b/platform/generic/eswin/eic770x.c
> @@ -470,6 +470,7 @@ static void eswin_eic7700_pmp_unconfigure(struct sbi_scratch *scratch,
>  static struct sbi_hart_protection eswin_eic7700_pmp_protection = {
>  	.name = "eic7700_pmp",
>  	.rating = -1UL,
> +	.type = SBI_HART_PROTECTION_TYPE_MEMORY,
>  	.configure = eswin_eic7700_pmp_configure,
>  	.unconfigure = eswin_eic7700_pmp_unconfigure,
>  };

-- 
opensbi mailing list
opensbi@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 4/5] lib: sbi: Extend hart protection abstraction to allow ID configuration
  2026-07-20 10:10   ` Yu-Chien Peter Lin
@ 2026-07-20 10:49     ` Anup Patel
  2026-07-20 10:54       ` Anup Patel
  2026-07-21  7:47       ` Yu-Chien Peter Lin
  0 siblings, 2 replies; 10+ messages in thread
From: Anup Patel @ 2026-07-20 10:49 UTC (permalink / raw)
  To: Yu-Chien Peter Lin
  Cc: Anup Patel, Atish Patra, Andrew Jones, Samuel Holland, opensbi,
	raymondmaoca, zong.li, jim.shu, pawandeep.oza

On Mon, Jul 20, 2026 at 3:40 PM Yu-Chien Peter Lin <peter.lin@sifive.com> wrote:
>
> Hi Anup and Raymond,
>
> On Fri, Jul 17, 2026 at 01:14:12PM +0530, Anup Patel wrote:
> > There are various ID configuration ISA extensions such as RISC-V Worlds,
> > Supervisor domain ID, QoS ID, etc which need to be re-configured upon
> > domain context switch on a hart. Extend hart protection abstraction to
> > support both memory protection and ID configuration ISA extensions.
>
> I will rework my "[RFC,00/12] Add RISC-V Worlds ISA support to OpenSBI"
> series based on this series.

Thanks Peter!

The RISC-V world DT property parsing can be done at the
time of parsing domains from FDT (like already done in this
series). The hart platform abstraction will be only for configuring
the RISC-V world CSRs.

May be you can add sbi_hart_worlds.c (just like sbi_hart_pmp.c) ?

For RISC-V world checkers, we can have separate FDT based driver
under lib/utils which will register sbi_domain_data instance upon probe
of each RISC-V world checker instance. The domain_setup() and
domain_cleanup() callbacks of the RISC-V worlds checker driver will
program the RISC-V world checker MMIO registers.

Regards,
Anup

>
> Thanks,
> Peter Lin
>
> >
> > Signed-off-by: Anup Patel <anup.patel@oss.qualcomm.com>
> > ---
> >  include/sbi/sbi_hart_protection.h | 16 +++++-
> >  lib/sbi/sbi_hart_pmp.c            |  2 +
> >  lib/sbi/sbi_hart_protection.c     | 94 ++++++++++++++++++++++++++-----
> >  lib/sbi/sbi_init.c                |  2 +-
> >  platform/generic/eswin/eic770x.c  |  1 +
> >  5 files changed, 98 insertions(+), 17 deletions(-)
> >
> > diff --git a/include/sbi/sbi_hart_protection.h b/include/sbi/sbi_hart_protection.h
> > index 5e170f05..1358b5be 100644
> > --- a/include/sbi/sbi_hart_protection.h
> > +++ b/include/sbi/sbi_hart_protection.h
> > @@ -13,6 +13,13 @@
> >  struct sbi_scratch;
> >  struct sbi_domain;
> >
> > +/** Different types of hart protection mechanisms */
> > +enum sbi_hart_protection_type {
> > +     SBI_HART_PROTECTION_TYPE_MEMORY = 0,
> > +     SBI_HART_PROTECTION_TYPE_ID,
> > +     SBI_HART_PROTECTIOn_TYPE_MAX
> > +};
> > +
> >  /** Representation of hart protection mechanism */
> >  struct sbi_hart_protection {
> >       /** List head */
> > @@ -21,6 +28,9 @@ struct sbi_hart_protection {
> >       /** Name of the hart protection mechanism */
> >       char name[32];
> >
> > +     /** Type of the hart protection mechanism */
> > +     enum sbi_hart_protection_type type;
> > +
> >       /** Ratings of the hart protection mechanism (higher is better) */
> >       unsigned long rating;
> >
> > @@ -40,11 +50,11 @@ struct sbi_hart_protection {
> >  };
> >
> >  /**
> > - * Get the best hart protection mechanism
> > + * Get the best hart memory protection mechanism
> >   *
> > - * @return pointer to best hart protection mechanism
> > + * @return pointer to best hart memory protection mechanism
> >   */
> > -struct sbi_hart_protection *sbi_hart_protection_best(void);
> > +struct sbi_hart_protection *sbi_hart_memory_protection_best(void);
> >
> >  /**
> >   * Register a hart protection mechanism
> > diff --git a/lib/sbi/sbi_hart_pmp.c b/lib/sbi/sbi_hart_pmp.c
> > index 5ede3cc1..c0a4ce1b 100644
> > --- a/lib/sbi/sbi_hart_pmp.c
> > +++ b/lib/sbi/sbi_hart_pmp.c
> > @@ -425,6 +425,7 @@ static void sbi_hart_pmp_unconfigure(struct sbi_scratch *scratch,
> >  static struct sbi_hart_protection pmp_protection = {
> >       .name = "pmp",
> >       .rating = 100,
> > +     .type = SBI_HART_PROTECTION_TYPE_MEMORY,
> >       .configure = sbi_hart_oldpmp_configure,
> >       .unconfigure = sbi_hart_pmp_unconfigure,
> >  };
> > @@ -432,6 +433,7 @@ static struct sbi_hart_protection pmp_protection = {
> >  static struct sbi_hart_protection epmp_protection = {
> >       .name = "epmp",
> >       .rating = 200,
> > +     .type = SBI_HART_PROTECTION_TYPE_MEMORY,
> >       .configure = sbi_hart_smepmp_configure,
> >       .unconfigure = sbi_hart_pmp_unconfigure,
> >       .map_range = sbi_hart_smepmp_map_range,
> > diff --git a/lib/sbi/sbi_hart_protection.c b/lib/sbi/sbi_hart_protection.c
> > index fecefde8..d31e9938 100644
> > --- a/lib/sbi/sbi_hart_protection.c
> > +++ b/lib/sbi/sbi_hart_protection.c
> > @@ -10,12 +10,16 @@
> >
> >  static SBI_LIST_HEAD(hart_protection_list);
> >
> > -struct sbi_hart_protection *sbi_hart_protection_best(void)
> > +struct sbi_hart_protection *sbi_hart_memory_protection_best(void)
> >  {
> > -     if (sbi_list_empty(&hart_protection_list))
> > -             return NULL;
> > +     struct sbi_hart_protection *pos;
> >
> > -     return sbi_list_first_entry(&hart_protection_list, struct sbi_hart_protection, head);
> > +     sbi_list_for_each_entry(pos, &hart_protection_list, head) {
> > +             if (pos->type == SBI_HART_PROTECTION_TYPE_MEMORY)
> > +                     return pos;
> > +     }
> > +
> > +     return NULL;
> >  }
> >
> >  int sbi_hart_protection_register(struct sbi_hart_protection *hprot)
> > @@ -74,33 +78,97 @@ static void __hart_protection_unconfigure(struct sbi_scratch *scratch,
> >  int sbi_hart_protection_configure(struct sbi_scratch *scratch,
> >                                 struct sbi_domain *dom)
> >  {
> > -     return __hart_protection_configure(scratch, sbi_hart_protection_best(), dom);
> > +     bool do_configure, memory_protect_done = false;
> > +     struct sbi_hart_protection *hprot;
> > +     int ret;
> > +
> > +     sbi_list_for_each_entry(hprot, &hart_protection_list, head) {
> > +             do_configure = false;
> > +             switch (hprot->type) {
> > +             case SBI_HART_PROTECTION_TYPE_MEMORY:
> > +                     do_configure = !memory_protect_done;
> > +                     memory_protect_done = true;
> > +                     break;
> > +             case SBI_HART_PROTECTION_TYPE_ID:
> > +                     do_configure = true;
> > +                     break;
> > +             default:
> > +                     break;
> > +             }
> > +             if (!do_configure)
> > +                     continue;
> > +
> > +             ret = __hart_protection_configure(scratch, hprot, dom);
> > +             if (ret)
> > +                     return ret;
> > +     }
> > +
> > +     return 0;
> >  }
> >
> >  void sbi_hart_protection_unconfigure(struct sbi_scratch *scratch,
> >                                    struct sbi_domain *dom)
> >  {
> > -     __hart_protection_unconfigure(scratch, sbi_hart_protection_best(), dom);
> > +
> > +     bool do_unconfigure, memory_protect_done = false;
> > +     struct sbi_hart_protection *hprot;
> > +
> > +     sbi_list_for_each_entry(hprot, &hart_protection_list, head) {
> > +             do_unconfigure = false;
> > +             switch (hprot->type) {
> > +             case SBI_HART_PROTECTION_TYPE_MEMORY:
> > +                     do_unconfigure = !memory_protect_done;
> > +                     memory_protect_done = true;
> > +                     break;
> > +             case SBI_HART_PROTECTION_TYPE_ID:
> > +                     do_unconfigure = true;
> > +                     break;
> > +             default:
> > +                     break;
> > +             }
> > +             if (!do_unconfigure)
> > +                     continue;
> > +
> > +             __hart_protection_unconfigure(scratch, hprot, dom);
> > +     }
> >  }
> >
> >  int sbi_hart_protection_reconfigure(struct sbi_scratch *scratch,
> >                                   struct sbi_domain *current_dom,
> >                                   struct sbi_domain *next_dom)
> >  {
> > -     struct sbi_hart_protection *hprot = sbi_hart_protection_best();
> > +     bool do_reconfigure, memory_protect_done = false;
> > +     struct sbi_hart_protection *hprot;
> >       int ret;
> >
> > -     __hart_protection_unconfigure(scratch, hprot, current_dom);
> > -     ret = __hart_protection_configure(scratch, hprot, next_dom);
> > -     if (ret)
> > -             return ret;
> > +     sbi_list_for_each_entry(hprot, &hart_protection_list, head) {
> > +             do_reconfigure = false;
> > +             switch (hprot->type) {
> > +             case SBI_HART_PROTECTION_TYPE_MEMORY:
> > +                     do_reconfigure = !memory_protect_done;
> > +                     memory_protect_done = true;
> > +                     break;
> > +             case SBI_HART_PROTECTION_TYPE_ID:
> > +                     do_reconfigure = true;
> > +                     break;
> > +             default:
> > +                     break;
> > +             }
> > +             if (!do_reconfigure)
> > +                     continue;
> > +
> > +             __hart_protection_unconfigure(scratch, hprot, current_dom);
> > +             ret = __hart_protection_configure(scratch, hprot, next_dom);
> > +             if (ret)
> > +                     return ret;
> > +     }
> >
> >       return 0;
> >  }
> >
> >  int sbi_hart_protection_map_range(unsigned long base, unsigned long size)
> >  {
> > -     struct sbi_hart_protection *hprot = sbi_hart_protection_best();
> > +     struct sbi_hart_protection *hprot = sbi_hart_memory_protection_best();
> >
> >       if (!hprot || !hprot->map_range)
> >               return 0;
> > @@ -110,7 +178,7 @@ int sbi_hart_protection_map_range(unsigned long base, unsigned long size)
> >
> >  int sbi_hart_protection_unmap_range(unsigned long base, unsigned long size)
> >  {
> > -     struct sbi_hart_protection *hprot = sbi_hart_protection_best();
> > +     struct sbi_hart_protection *hprot = sbi_hart_memory_protection_best();
> >
> >       if (!hprot || !hprot->unmap_range)
> >               return 0;
> > diff --git a/lib/sbi/sbi_init.c b/lib/sbi/sbi_init.c
> > index d74dc67c..3f1f136a 100644
> > --- a/lib/sbi/sbi_init.c
> > +++ b/lib/sbi/sbi_init.c
> > @@ -93,7 +93,7 @@ static void sbi_boot_print_general(struct sbi_scratch *scratch)
> >       sbi_printf("Platform Features           : %s\n", str);
> >       sbi_printf("Platform HART Count         : %u\n",
> >                  sbi_platform_hart_count(plat));
> > -     hprot = sbi_hart_protection_best();
> > +     hprot = sbi_hart_memory_protection_best();
> >       sbi_printf("Platform HART Protection    : %s\n",
> >                  (hprot) ? hprot->name : "---");
> >       idev = sbi_ipi_get_device();
> > diff --git a/platform/generic/eswin/eic770x.c b/platform/generic/eswin/eic770x.c
> > index da4d0e34..c71198a8 100644
> > --- a/platform/generic/eswin/eic770x.c
> > +++ b/platform/generic/eswin/eic770x.c
> > @@ -470,6 +470,7 @@ static void eswin_eic7700_pmp_unconfigure(struct sbi_scratch *scratch,
> >  static struct sbi_hart_protection eswin_eic7700_pmp_protection = {
> >       .name = "eic7700_pmp",
> >       .rating = -1UL,
> > +     .type = SBI_HART_PROTECTION_TYPE_MEMORY,
> >       .configure = eswin_eic7700_pmp_configure,
> >       .unconfigure = eswin_eic7700_pmp_unconfigure,
> >  };

-- 
opensbi mailing list
opensbi@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 4/5] lib: sbi: Extend hart protection abstraction to allow ID configuration
  2026-07-20 10:49     ` Anup Patel
@ 2026-07-20 10:54       ` Anup Patel
  2026-07-21  7:47       ` Yu-Chien Peter Lin
  1 sibling, 0 replies; 10+ messages in thread
From: Anup Patel @ 2026-07-20 10:54 UTC (permalink / raw)
  To: Yu-Chien Peter Lin
  Cc: Anup Patel, Atish Patra, Andrew Jones, Samuel Holland, opensbi,
	raymondmaoca, zong.li, jim.shu, pawandeep.oza

On Mon, Jul 20, 2026 at 4:19 PM Anup Patel <anup@brainfault.org> wrote:
>
> On Mon, Jul 20, 2026 at 3:40 PM Yu-Chien Peter Lin <peter.lin@sifive.com> wrote:
> >
> > Hi Anup and Raymond,
> >
> > On Fri, Jul 17, 2026 at 01:14:12PM +0530, Anup Patel wrote:
> > > There are various ID configuration ISA extensions such as RISC-V Worlds,
> > > Supervisor domain ID, QoS ID, etc which need to be re-configured upon
> > > domain context switch on a hart. Extend hart protection abstraction to
> > > support both memory protection and ID configuration ISA extensions.
> >
> > I will rework my "[RFC,00/12] Add RISC-V Worlds ISA support to OpenSBI"
> > series based on this series.
>
> Thanks Peter!
>
> The RISC-V world DT property parsing can be done at the
> time of parsing domains from FDT (like already done in this
> series). The hart platform abstraction will be only for configuring
> the RISC-V world CSRs.
>
> May be you can add sbi_hart_worlds.c (just like sbi_hart_pmp.c) ?
>
> For RISC-V world checkers, we can have separate FDT based driver
> under lib/utils which will register sbi_domain_data instance upon probe
> of each RISC-V world checker instance. The domain_setup() and
> domain_cleanup() callbacks of the RISC-V worlds checker driver will
> program the RISC-V world checker MMIO registers.

Thinking about this more, we should rename sbi_domain_data to
sbi_domain_state so that we use it for both software and hardware
state setup or cleanup. The term "data" looks like software state
only.

Regards,
Anup

>
> Regards,
> Anup
>
> >
> > Thanks,
> > Peter Lin
> >
> > >
> > > Signed-off-by: Anup Patel <anup.patel@oss.qualcomm.com>
> > > ---
> > >  include/sbi/sbi_hart_protection.h | 16 +++++-
> > >  lib/sbi/sbi_hart_pmp.c            |  2 +
> > >  lib/sbi/sbi_hart_protection.c     | 94 ++++++++++++++++++++++++++-----
> > >  lib/sbi/sbi_init.c                |  2 +-
> > >  platform/generic/eswin/eic770x.c  |  1 +
> > >  5 files changed, 98 insertions(+), 17 deletions(-)
> > >
> > > diff --git a/include/sbi/sbi_hart_protection.h b/include/sbi/sbi_hart_protection.h
> > > index 5e170f05..1358b5be 100644
> > > --- a/include/sbi/sbi_hart_protection.h
> > > +++ b/include/sbi/sbi_hart_protection.h
> > > @@ -13,6 +13,13 @@
> > >  struct sbi_scratch;
> > >  struct sbi_domain;
> > >
> > > +/** Different types of hart protection mechanisms */
> > > +enum sbi_hart_protection_type {
> > > +     SBI_HART_PROTECTION_TYPE_MEMORY = 0,
> > > +     SBI_HART_PROTECTION_TYPE_ID,
> > > +     SBI_HART_PROTECTIOn_TYPE_MAX
> > > +};
> > > +
> > >  /** Representation of hart protection mechanism */
> > >  struct sbi_hart_protection {
> > >       /** List head */
> > > @@ -21,6 +28,9 @@ struct sbi_hart_protection {
> > >       /** Name of the hart protection mechanism */
> > >       char name[32];
> > >
> > > +     /** Type of the hart protection mechanism */
> > > +     enum sbi_hart_protection_type type;
> > > +
> > >       /** Ratings of the hart protection mechanism (higher is better) */
> > >       unsigned long rating;
> > >
> > > @@ -40,11 +50,11 @@ struct sbi_hart_protection {
> > >  };
> > >
> > >  /**
> > > - * Get the best hart protection mechanism
> > > + * Get the best hart memory protection mechanism
> > >   *
> > > - * @return pointer to best hart protection mechanism
> > > + * @return pointer to best hart memory protection mechanism
> > >   */
> > > -struct sbi_hart_protection *sbi_hart_protection_best(void);
> > > +struct sbi_hart_protection *sbi_hart_memory_protection_best(void);
> > >
> > >  /**
> > >   * Register a hart protection mechanism
> > > diff --git a/lib/sbi/sbi_hart_pmp.c b/lib/sbi/sbi_hart_pmp.c
> > > index 5ede3cc1..c0a4ce1b 100644
> > > --- a/lib/sbi/sbi_hart_pmp.c
> > > +++ b/lib/sbi/sbi_hart_pmp.c
> > > @@ -425,6 +425,7 @@ static void sbi_hart_pmp_unconfigure(struct sbi_scratch *scratch,
> > >  static struct sbi_hart_protection pmp_protection = {
> > >       .name = "pmp",
> > >       .rating = 100,
> > > +     .type = SBI_HART_PROTECTION_TYPE_MEMORY,
> > >       .configure = sbi_hart_oldpmp_configure,
> > >       .unconfigure = sbi_hart_pmp_unconfigure,
> > >  };
> > > @@ -432,6 +433,7 @@ static struct sbi_hart_protection pmp_protection = {
> > >  static struct sbi_hart_protection epmp_protection = {
> > >       .name = "epmp",
> > >       .rating = 200,
> > > +     .type = SBI_HART_PROTECTION_TYPE_MEMORY,
> > >       .configure = sbi_hart_smepmp_configure,
> > >       .unconfigure = sbi_hart_pmp_unconfigure,
> > >       .map_range = sbi_hart_smepmp_map_range,
> > > diff --git a/lib/sbi/sbi_hart_protection.c b/lib/sbi/sbi_hart_protection.c
> > > index fecefde8..d31e9938 100644
> > > --- a/lib/sbi/sbi_hart_protection.c
> > > +++ b/lib/sbi/sbi_hart_protection.c
> > > @@ -10,12 +10,16 @@
> > >
> > >  static SBI_LIST_HEAD(hart_protection_list);
> > >
> > > -struct sbi_hart_protection *sbi_hart_protection_best(void)
> > > +struct sbi_hart_protection *sbi_hart_memory_protection_best(void)
> > >  {
> > > -     if (sbi_list_empty(&hart_protection_list))
> > > -             return NULL;
> > > +     struct sbi_hart_protection *pos;
> > >
> > > -     return sbi_list_first_entry(&hart_protection_list, struct sbi_hart_protection, head);
> > > +     sbi_list_for_each_entry(pos, &hart_protection_list, head) {
> > > +             if (pos->type == SBI_HART_PROTECTION_TYPE_MEMORY)
> > > +                     return pos;
> > > +     }
> > > +
> > > +     return NULL;
> > >  }
> > >
> > >  int sbi_hart_protection_register(struct sbi_hart_protection *hprot)
> > > @@ -74,33 +78,97 @@ static void __hart_protection_unconfigure(struct sbi_scratch *scratch,
> > >  int sbi_hart_protection_configure(struct sbi_scratch *scratch,
> > >                                 struct sbi_domain *dom)
> > >  {
> > > -     return __hart_protection_configure(scratch, sbi_hart_protection_best(), dom);
> > > +     bool do_configure, memory_protect_done = false;
> > > +     struct sbi_hart_protection *hprot;
> > > +     int ret;
> > > +
> > > +     sbi_list_for_each_entry(hprot, &hart_protection_list, head) {
> > > +             do_configure = false;
> > > +             switch (hprot->type) {
> > > +             case SBI_HART_PROTECTION_TYPE_MEMORY:
> > > +                     do_configure = !memory_protect_done;
> > > +                     memory_protect_done = true;
> > > +                     break;
> > > +             case SBI_HART_PROTECTION_TYPE_ID:
> > > +                     do_configure = true;
> > > +                     break;
> > > +             default:
> > > +                     break;
> > > +             }
> > > +             if (!do_configure)
> > > +                     continue;
> > > +
> > > +             ret = __hart_protection_configure(scratch, hprot, dom);
> > > +             if (ret)
> > > +                     return ret;
> > > +     }
> > > +
> > > +     return 0;
> > >  }
> > >
> > >  void sbi_hart_protection_unconfigure(struct sbi_scratch *scratch,
> > >                                    struct sbi_domain *dom)
> > >  {
> > > -     __hart_protection_unconfigure(scratch, sbi_hart_protection_best(), dom);
> > > +
> > > +     bool do_unconfigure, memory_protect_done = false;
> > > +     struct sbi_hart_protection *hprot;
> > > +
> > > +     sbi_list_for_each_entry(hprot, &hart_protection_list, head) {
> > > +             do_unconfigure = false;
> > > +             switch (hprot->type) {
> > > +             case SBI_HART_PROTECTION_TYPE_MEMORY:
> > > +                     do_unconfigure = !memory_protect_done;
> > > +                     memory_protect_done = true;
> > > +                     break;
> > > +             case SBI_HART_PROTECTION_TYPE_ID:
> > > +                     do_unconfigure = true;
> > > +                     break;
> > > +             default:
> > > +                     break;
> > > +             }
> > > +             if (!do_unconfigure)
> > > +                     continue;
> > > +
> > > +             __hart_protection_unconfigure(scratch, hprot, dom);
> > > +     }
> > >  }
> > >
> > >  int sbi_hart_protection_reconfigure(struct sbi_scratch *scratch,
> > >                                   struct sbi_domain *current_dom,
> > >                                   struct sbi_domain *next_dom)
> > >  {
> > > -     struct sbi_hart_protection *hprot = sbi_hart_protection_best();
> > > +     bool do_reconfigure, memory_protect_done = false;
> > > +     struct sbi_hart_protection *hprot;
> > >       int ret;
> > >
> > > -     __hart_protection_unconfigure(scratch, hprot, current_dom);
> > > -     ret = __hart_protection_configure(scratch, hprot, next_dom);
> > > -     if (ret)
> > > -             return ret;
> > > +     sbi_list_for_each_entry(hprot, &hart_protection_list, head) {
> > > +             do_reconfigure = false;
> > > +             switch (hprot->type) {
> > > +             case SBI_HART_PROTECTION_TYPE_MEMORY:
> > > +                     do_reconfigure = !memory_protect_done;
> > > +                     memory_protect_done = true;
> > > +                     break;
> > > +             case SBI_HART_PROTECTION_TYPE_ID:
> > > +                     do_reconfigure = true;
> > > +                     break;
> > > +             default:
> > > +                     break;
> > > +             }
> > > +             if (!do_reconfigure)
> > > +                     continue;
> > > +
> > > +             __hart_protection_unconfigure(scratch, hprot, current_dom);
> > > +             ret = __hart_protection_configure(scratch, hprot, next_dom);
> > > +             if (ret)
> > > +                     return ret;
> > > +     }
> > >
> > >       return 0;
> > >  }
> > >
> > >  int sbi_hart_protection_map_range(unsigned long base, unsigned long size)
> > >  {
> > > -     struct sbi_hart_protection *hprot = sbi_hart_protection_best();
> > > +     struct sbi_hart_protection *hprot = sbi_hart_memory_protection_best();
> > >
> > >       if (!hprot || !hprot->map_range)
> > >               return 0;
> > > @@ -110,7 +178,7 @@ int sbi_hart_protection_map_range(unsigned long base, unsigned long size)
> > >
> > >  int sbi_hart_protection_unmap_range(unsigned long base, unsigned long size)
> > >  {
> > > -     struct sbi_hart_protection *hprot = sbi_hart_protection_best();
> > > +     struct sbi_hart_protection *hprot = sbi_hart_memory_protection_best();
> > >
> > >       if (!hprot || !hprot->unmap_range)
> > >               return 0;
> > > diff --git a/lib/sbi/sbi_init.c b/lib/sbi/sbi_init.c
> > > index d74dc67c..3f1f136a 100644
> > > --- a/lib/sbi/sbi_init.c
> > > +++ b/lib/sbi/sbi_init.c
> > > @@ -93,7 +93,7 @@ static void sbi_boot_print_general(struct sbi_scratch *scratch)
> > >       sbi_printf("Platform Features           : %s\n", str);
> > >       sbi_printf("Platform HART Count         : %u\n",
> > >                  sbi_platform_hart_count(plat));
> > > -     hprot = sbi_hart_protection_best();
> > > +     hprot = sbi_hart_memory_protection_best();
> > >       sbi_printf("Platform HART Protection    : %s\n",
> > >                  (hprot) ? hprot->name : "---");
> > >       idev = sbi_ipi_get_device();
> > > diff --git a/platform/generic/eswin/eic770x.c b/platform/generic/eswin/eic770x.c
> > > index da4d0e34..c71198a8 100644
> > > --- a/platform/generic/eswin/eic770x.c
> > > +++ b/platform/generic/eswin/eic770x.c
> > > @@ -470,6 +470,7 @@ static void eswin_eic7700_pmp_unconfigure(struct sbi_scratch *scratch,
> > >  static struct sbi_hart_protection eswin_eic7700_pmp_protection = {
> > >       .name = "eic7700_pmp",
> > >       .rating = -1UL,
> > > +     .type = SBI_HART_PROTECTION_TYPE_MEMORY,
> > >       .configure = eswin_eic7700_pmp_configure,
> > >       .unconfigure = eswin_eic7700_pmp_unconfigure,
> > >  };

-- 
opensbi mailing list
opensbi@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 4/5] lib: sbi: Extend hart protection abstraction to allow ID configuration
  2026-07-20 10:49     ` Anup Patel
  2026-07-20 10:54       ` Anup Patel
@ 2026-07-21  7:47       ` Yu-Chien Peter Lin
  1 sibling, 0 replies; 10+ messages in thread
From: Yu-Chien Peter Lin @ 2026-07-21  7:47 UTC (permalink / raw)
  To: Anup Patel
  Cc: Anup Patel, Atish Patra, Andrew Jones, Samuel Holland, opensbi,
	raymondmaoca, zong.li, jim.shu, pawandeep.oza

On Mon, Jul 20, 2026 at 04:19:10PM +0530, Anup Patel wrote:
> On Mon, Jul 20, 2026 at 3:40 PM Yu-Chien Peter Lin <peter.lin@sifive.com> wrote:
> >
> > Hi Anup and Raymond,
> >
> > On Fri, Jul 17, 2026 at 01:14:12PM +0530, Anup Patel wrote:
> > > There are various ID configuration ISA extensions such as RISC-V Worlds,
> > > Supervisor domain ID, QoS ID, etc which need to be re-configured upon
> > > domain context switch on a hart. Extend hart protection abstraction to
> > > support both memory protection and ID configuration ISA extensions.
> >
> > I will rework my "[RFC,00/12] Add RISC-V Worlds ISA support to OpenSBI"
> > series based on this series.
> 
> Thanks Peter!
> 
> The RISC-V world DT property parsing can be done at the
> time of parsing domains from FDT (like already done in this
> series). The hart platform abstraction will be only for configuring
> the RISC-V world CSRs.
> 
> May be you can add sbi_hart_worlds.c (just like sbi_hart_pmp.c) ?
> 
> For RISC-V world checkers, we can have separate FDT based driver
> under lib/utils which will register sbi_domain_data instance upon probe
> of each RISC-V world checker instance. The domain_setup() and
> domain_cleanup() callbacks of the RISC-V worlds checker driver will
> program the RISC-V world checker MMIO registers.

Sounds great, thanks for the direction. Will follow this approach and
update in v2.

Thanks,
Peter Lin

> 
> Regards,
> Anup
> 
> >
> > Thanks,
> > Peter Lin
> >
> > >
> > > Signed-off-by: Anup Patel <anup.patel@oss.qualcomm.com>
> > > ---
> > >  include/sbi/sbi_hart_protection.h | 16 +++++-
> > >  lib/sbi/sbi_hart_pmp.c            |  2 +
> > >  lib/sbi/sbi_hart_protection.c     | 94 ++++++++++++++++++++++++++-----
> > >  lib/sbi/sbi_init.c                |  2 +-
> > >  platform/generic/eswin/eic770x.c  |  1 +
> > >  5 files changed, 98 insertions(+), 17 deletions(-)
> > >
> > > diff --git a/include/sbi/sbi_hart_protection.h b/include/sbi/sbi_hart_protection.h
> > > index 5e170f05..1358b5be 100644
> > > --- a/include/sbi/sbi_hart_protection.h
> > > +++ b/include/sbi/sbi_hart_protection.h
> > > @@ -13,6 +13,13 @@
> > >  struct sbi_scratch;
> > >  struct sbi_domain;
> > >
> > > +/** Different types of hart protection mechanisms */
> > > +enum sbi_hart_protection_type {
> > > +     SBI_HART_PROTECTION_TYPE_MEMORY = 0,
> > > +     SBI_HART_PROTECTION_TYPE_ID,
> > > +     SBI_HART_PROTECTIOn_TYPE_MAX
> > > +};
> > > +
> > >  /** Representation of hart protection mechanism */
> > >  struct sbi_hart_protection {
> > >       /** List head */
> > > @@ -21,6 +28,9 @@ struct sbi_hart_protection {
> > >       /** Name of the hart protection mechanism */
> > >       char name[32];
> > >
> > > +     /** Type of the hart protection mechanism */
> > > +     enum sbi_hart_protection_type type;
> > > +
> > >       /** Ratings of the hart protection mechanism (higher is better) */
> > >       unsigned long rating;
> > >
> > > @@ -40,11 +50,11 @@ struct sbi_hart_protection {
> > >  };
> > >
> > >  /**
> > > - * Get the best hart protection mechanism
> > > + * Get the best hart memory protection mechanism
> > >   *
> > > - * @return pointer to best hart protection mechanism
> > > + * @return pointer to best hart memory protection mechanism
> > >   */
> > > -struct sbi_hart_protection *sbi_hart_protection_best(void);
> > > +struct sbi_hart_protection *sbi_hart_memory_protection_best(void);
> > >
> > >  /**
> > >   * Register a hart protection mechanism
> > > diff --git a/lib/sbi/sbi_hart_pmp.c b/lib/sbi/sbi_hart_pmp.c
> > > index 5ede3cc1..c0a4ce1b 100644
> > > --- a/lib/sbi/sbi_hart_pmp.c
> > > +++ b/lib/sbi/sbi_hart_pmp.c
> > > @@ -425,6 +425,7 @@ static void sbi_hart_pmp_unconfigure(struct sbi_scratch *scratch,
> > >  static struct sbi_hart_protection pmp_protection = {
> > >       .name = "pmp",
> > >       .rating = 100,
> > > +     .type = SBI_HART_PROTECTION_TYPE_MEMORY,
> > >       .configure = sbi_hart_oldpmp_configure,
> > >       .unconfigure = sbi_hart_pmp_unconfigure,
> > >  };
> > > @@ -432,6 +433,7 @@ static struct sbi_hart_protection pmp_protection = {
> > >  static struct sbi_hart_protection epmp_protection = {
> > >       .name = "epmp",
> > >       .rating = 200,
> > > +     .type = SBI_HART_PROTECTION_TYPE_MEMORY,
> > >       .configure = sbi_hart_smepmp_configure,
> > >       .unconfigure = sbi_hart_pmp_unconfigure,
> > >       .map_range = sbi_hart_smepmp_map_range,
> > > diff --git a/lib/sbi/sbi_hart_protection.c b/lib/sbi/sbi_hart_protection.c
> > > index fecefde8..d31e9938 100644
> > > --- a/lib/sbi/sbi_hart_protection.c
> > > +++ b/lib/sbi/sbi_hart_protection.c
> > > @@ -10,12 +10,16 @@
> > >
> > >  static SBI_LIST_HEAD(hart_protection_list);
> > >
> > > -struct sbi_hart_protection *sbi_hart_protection_best(void)
> > > +struct sbi_hart_protection *sbi_hart_memory_protection_best(void)
> > >  {
> > > -     if (sbi_list_empty(&hart_protection_list))
> > > -             return NULL;
> > > +     struct sbi_hart_protection *pos;
> > >
> > > -     return sbi_list_first_entry(&hart_protection_list, struct sbi_hart_protection, head);
> > > +     sbi_list_for_each_entry(pos, &hart_protection_list, head) {
> > > +             if (pos->type == SBI_HART_PROTECTION_TYPE_MEMORY)
> > > +                     return pos;
> > > +     }
> > > +
> > > +     return NULL;
> > >  }
> > >
> > >  int sbi_hart_protection_register(struct sbi_hart_protection *hprot)
> > > @@ -74,33 +78,97 @@ static void __hart_protection_unconfigure(struct sbi_scratch *scratch,
> > >  int sbi_hart_protection_configure(struct sbi_scratch *scratch,
> > >                                 struct sbi_domain *dom)
> > >  {
> > > -     return __hart_protection_configure(scratch, sbi_hart_protection_best(), dom);
> > > +     bool do_configure, memory_protect_done = false;
> > > +     struct sbi_hart_protection *hprot;
> > > +     int ret;
> > > +
> > > +     sbi_list_for_each_entry(hprot, &hart_protection_list, head) {
> > > +             do_configure = false;
> > > +             switch (hprot->type) {
> > > +             case SBI_HART_PROTECTION_TYPE_MEMORY:
> > > +                     do_configure = !memory_protect_done;
> > > +                     memory_protect_done = true;
> > > +                     break;
> > > +             case SBI_HART_PROTECTION_TYPE_ID:
> > > +                     do_configure = true;
> > > +                     break;
> > > +             default:
> > > +                     break;
> > > +             }
> > > +             if (!do_configure)
> > > +                     continue;
> > > +
> > > +             ret = __hart_protection_configure(scratch, hprot, dom);
> > > +             if (ret)
> > > +                     return ret;
> > > +     }
> > > +
> > > +     return 0;
> > >  }
> > >
> > >  void sbi_hart_protection_unconfigure(struct sbi_scratch *scratch,
> > >                                    struct sbi_domain *dom)
> > >  {
> > > -     __hart_protection_unconfigure(scratch, sbi_hart_protection_best(), dom);
> > > +
> > > +     bool do_unconfigure, memory_protect_done = false;
> > > +     struct sbi_hart_protection *hprot;
> > > +
> > > +     sbi_list_for_each_entry(hprot, &hart_protection_list, head) {
> > > +             do_unconfigure = false;
> > > +             switch (hprot->type) {
> > > +             case SBI_HART_PROTECTION_TYPE_MEMORY:
> > > +                     do_unconfigure = !memory_protect_done;
> > > +                     memory_protect_done = true;
> > > +                     break;
> > > +             case SBI_HART_PROTECTION_TYPE_ID:
> > > +                     do_unconfigure = true;
> > > +                     break;
> > > +             default:
> > > +                     break;
> > > +             }
> > > +             if (!do_unconfigure)
> > > +                     continue;
> > > +
> > > +             __hart_protection_unconfigure(scratch, hprot, dom);
> > > +     }
> > >  }
> > >
> > >  int sbi_hart_protection_reconfigure(struct sbi_scratch *scratch,
> > >                                   struct sbi_domain *current_dom,
> > >                                   struct sbi_domain *next_dom)
> > >  {
> > > -     struct sbi_hart_protection *hprot = sbi_hart_protection_best();
> > > +     bool do_reconfigure, memory_protect_done = false;
> > > +     struct sbi_hart_protection *hprot;
> > >       int ret;
> > >
> > > -     __hart_protection_unconfigure(scratch, hprot, current_dom);
> > > -     ret = __hart_protection_configure(scratch, hprot, next_dom);
> > > -     if (ret)
> > > -             return ret;
> > > +     sbi_list_for_each_entry(hprot, &hart_protection_list, head) {
> > > +             do_reconfigure = false;
> > > +             switch (hprot->type) {
> > > +             case SBI_HART_PROTECTION_TYPE_MEMORY:
> > > +                     do_reconfigure = !memory_protect_done;
> > > +                     memory_protect_done = true;
> > > +                     break;
> > > +             case SBI_HART_PROTECTION_TYPE_ID:
> > > +                     do_reconfigure = true;
> > > +                     break;
> > > +             default:
> > > +                     break;
> > > +             }
> > > +             if (!do_reconfigure)
> > > +                     continue;
> > > +
> > > +             __hart_protection_unconfigure(scratch, hprot, current_dom);
> > > +             ret = __hart_protection_configure(scratch, hprot, next_dom);
> > > +             if (ret)
> > > +                     return ret;
> > > +     }
> > >
> > >       return 0;
> > >  }
> > >
> > >  int sbi_hart_protection_map_range(unsigned long base, unsigned long size)
> > >  {
> > > -     struct sbi_hart_protection *hprot = sbi_hart_protection_best();
> > > +     struct sbi_hart_protection *hprot = sbi_hart_memory_protection_best();
> > >
> > >       if (!hprot || !hprot->map_range)
> > >               return 0;
> > > @@ -110,7 +178,7 @@ int sbi_hart_protection_map_range(unsigned long base, unsigned long size)
> > >
> > >  int sbi_hart_protection_unmap_range(unsigned long base, unsigned long size)
> > >  {
> > > -     struct sbi_hart_protection *hprot = sbi_hart_protection_best();
> > > +     struct sbi_hart_protection *hprot = sbi_hart_memory_protection_best();
> > >
> > >       if (!hprot || !hprot->unmap_range)
> > >               return 0;
> > > diff --git a/lib/sbi/sbi_init.c b/lib/sbi/sbi_init.c
> > > index d74dc67c..3f1f136a 100644
> > > --- a/lib/sbi/sbi_init.c
> > > +++ b/lib/sbi/sbi_init.c
> > > @@ -93,7 +93,7 @@ static void sbi_boot_print_general(struct sbi_scratch *scratch)
> > >       sbi_printf("Platform Features           : %s\n", str);
> > >       sbi_printf("Platform HART Count         : %u\n",
> > >                  sbi_platform_hart_count(plat));
> > > -     hprot = sbi_hart_protection_best();
> > > +     hprot = sbi_hart_memory_protection_best();
> > >       sbi_printf("Platform HART Protection    : %s\n",
> > >                  (hprot) ? hprot->name : "---");
> > >       idev = sbi_ipi_get_device();
> > > diff --git a/platform/generic/eswin/eic770x.c b/platform/generic/eswin/eic770x.c
> > > index da4d0e34..c71198a8 100644
> > > --- a/platform/generic/eswin/eic770x.c
> > > +++ b/platform/generic/eswin/eic770x.c
> > > @@ -470,6 +470,7 @@ static void eswin_eic7700_pmp_unconfigure(struct sbi_scratch *scratch,
> > >  static struct sbi_hart_protection eswin_eic7700_pmp_protection = {
> > >       .name = "eic7700_pmp",
> > >       .rating = -1UL,
> > > +     .type = SBI_HART_PROTECTION_TYPE_MEMORY,
> > >       .configure = eswin_eic7700_pmp_configure,
> > >       .unconfigure = eswin_eic7700_pmp_unconfigure,
> > >  };

-- 
opensbi mailing list
opensbi@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-07-21  7:47 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-17  7:44 [PATCH 0/5] Extend hart protection abstraction for ID configuration Anup Patel
2026-07-17  7:44 ` [PATCH 1/5] lib: sbi: Fix typos related to hart protection Anup Patel
2026-07-17  7:44 ` [PATCH 2/5] lib: sbi: Introduce sbi_hart_protection_reconfigure() function Anup Patel
2026-07-17  7:44 ` [PATCH 3/5] lib: sbi: Add domain parameter to hart protection (un)configure() Anup Patel
2026-07-17  7:44 ` [PATCH 4/5] lib: sbi: Extend hart protection abstraction to allow ID configuration Anup Patel
2026-07-20 10:10   ` Yu-Chien Peter Lin
2026-07-20 10:49     ` Anup Patel
2026-07-20 10:54       ` Anup Patel
2026-07-21  7:47       ` Yu-Chien Peter Lin
2026-07-17  7:44 ` [PATCH 5/5] lib: sbi: Print list of all hart protection mechanisms at boot time Anup Patel

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.