public inbox for opensbi@lists.infradead.org
 help / color / mirror / Atom feed
From: Yu-Chien Peter Lin <peter.lin@sifive.com>
To: opensbi@lists.infradead.org
Cc: zong.li@sifive.com, greentime.hu@sifive.com,
	Yu-Chien Peter Lin <peter.lin@sifive.com>
Subject: [PATCH] lib: utils: fdt_domain: add support for root domain region inheritance
Date: Fri, 27 Mar 2026 12:33:57 +0800	[thread overview]
Message-ID: <20260327043357.3452008-1-peter.lin@sifive.com> (raw)

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@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


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

                 reply	other threads:[~2026-03-27  4:34 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20260327043357.3452008-1-peter.lin@sifive.com \
    --to=peter.lin@sifive.com \
    --cc=greentime.hu@sifive.com \
    --cc=opensbi@lists.infradead.org \
    --cc=zong.li@sifive.com \
    /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