[PATCH] lib: utils: fdt_domain: add support for root domain region inheritance

Yu-Chien Peter Lin peter.lin at sifive.com
Thu Mar 26 21:33:57 PDT 2026


Add the "root-regions" property in domain device-tree nodes to
allow domains to inherit all regions from the root domain. This
simplifies configuration for domains that need access to most
root domain regions with only minor exclusions or additions.

Signed-off-by: Yu-Chien Peter Lin <peter.lin at sifive.com>
---
 docs/domain_support.md     |  4 ++++
 lib/utils/fdt/fdt_domain.c | 46 +++++++++++++++++++++++---------------
 2 files changed, 32 insertions(+), 18 deletions(-)

diff --git a/docs/domain_support.md b/docs/domain_support.md
index 93186c4a..a88f1cfb 100644
--- a/docs/domain_support.md
+++ b/docs/domain_support.md
@@ -159,6 +159,10 @@ The DT properties of a domain instance DT node are as follows:
 * **possible-harts** (Optional) - The list of CPU DT node phandles for the
   the domain instance. This list represents the possible HARTs of the
   domain instance.
+* **root-regions** (Optional) - A boolean flag indicating whether this domain
+  inherits ALL memory regions from the root domain. If this property is present,
+  the domain will include with all root domain regions and then overlay with
+  regions specified in the **regions** property for additional restrictions.
 * **regions** (Optional) - The list of domain memory region DT node phandle
   and access permissions for the domain instance. Each list entry is a pair
   of DT node phandle and access permissions. The access permissions are
diff --git a/lib/utils/fdt/fdt_domain.c b/lib/utils/fdt/fdt_domain.c
index b2fa8633..45407c22 100644
--- a/lib/utils/fdt/fdt_domain.c
+++ b/lib/utils/fdt/fdt_domain.c
@@ -373,25 +373,35 @@ static int __fdt_parse_domain(const void *fdt, int domain_offset, void *opaque)
 	if (err)
 		goto fail_free_all;
 
-	/*
-	 * Copy over root domain memregions which don't allow
-	 * read, write and execute from lower privilege modes.
-	 *
-	 * These root domain memregions without read, write,
-	 * and execute permissions include:
-	 * 1) firmware region protecting the firmware memory
-	 * 2) mmio regions protecting M-mode only mmio devices
-	 */
-	sbi_domain_for_each_memregion(&root, reg) {
-		if ((reg->flags & SBI_DOMAIN_MEMREGION_SU_READABLE) ||
-		    (reg->flags & SBI_DOMAIN_MEMREGION_SU_WRITABLE) ||
-		    (reg->flags & SBI_DOMAIN_MEMREGION_SU_EXECUTABLE))
-			continue;
-		if (preg.max_regions <= preg.region_count) {
-			err = SBI_EINVAL;
-			goto fail_free_all;
+	if (fdt_get_property(fdt, domain_offset, "root-regions", NULL)) {
+		sbi_domain_for_each_memregion(&root, reg) {
+			if (preg.max_regions <= preg.region_count) {
+				err = SBI_EINVAL;
+				goto fail_free_all;
+			}
+			memcpy(&dom->regions[preg.region_count++], reg, sizeof(*reg));
+		}
+	} else {
+		/*
+		 * Copy over root domain memregions which don't allow
+		 * read, write and execute from lower privilege modes.
+		 *
+		 * These root domain memregions without read, write,
+		 * and execute permissions include:
+		 * 1) firmware region protecting the firmware memory
+		 * 2) mmio regions protecting M-mode only mmio devices
+		 */
+		sbi_domain_for_each_memregion(&root, reg) {
+			if ((reg->flags & SBI_DOMAIN_MEMREGION_SU_READABLE) ||
+			    (reg->flags & SBI_DOMAIN_MEMREGION_SU_WRITABLE) ||
+			    (reg->flags & SBI_DOMAIN_MEMREGION_SU_EXECUTABLE))
+				continue;
+			if (preg.max_regions <= preg.region_count) {
+				err = SBI_EINVAL;
+				goto fail_free_all;
+			}
+			memcpy(&dom->regions[preg.region_count++], reg, sizeof(*reg));
 		}
-		memcpy(&dom->regions[preg.region_count++], reg, sizeof(*reg));
 	}
 	dom->fw_region_inited = root.fw_region_inited;
 
-- 
2.48.0




More information about the opensbi mailing list