From: Rahul Pathak <rahul.pathak@oss.qualcomm.com>
To: opensbi@lists.infradead.org
Cc: rahul.pathak@oss.qualcomm.com, rahul@summations.net
Subject: [RFC PATCH v2 3/5] platform/generic: Initialise MPT at boot
Date: Mon, 27 Jul 2026 19:26:01 +0530 [thread overview]
Message-ID: <20260727135605.465309-4-rahul.pathak@oss.qualcomm.com> (raw)
In-Reply-To: <20260727135605.465309-1-rahul.pathak@oss.qualcomm.com>
Integrates MPT initialisation into the generic platform boot flow.
mpt_early_init() probes for SMMPT during cold-boot early init and
initialises the structures required to build MPT tables.
mpt_final_init() creates the root supervisor domain which is mapping all
physical memory with the firmware region explcitly denied to S-mode and
adds support for an MPT domain for each additional registered SBI domain.
The heap budget is extended to reserve space for MPT tables.
With this patch MPT tables are built at boot.
Signed-off-by: Rahul Pathak <rahul.pathak@oss.qualcomm.com>
---
platform/generic/platform.c | 101 ++++++++++++++++++++++++++++++++++++
1 file changed, 101 insertions(+)
diff --git a/platform/generic/platform.c b/platform/generic/platform.c
index 1df0280d..b9a715b6 100644
--- a/platform/generic/platform.c
+++ b/platform/generic/platform.c
@@ -17,6 +17,9 @@
#include <sbi/sbi_string.h>
#include <sbi/sbi_system.h>
#include <sbi/sbi_tlb.h>
+#include <sbi/sbi_mpt.h>
+#include <sbi/sbi_domain.h>
+#include <sbi/sbi_console.h>
#include <sbi_utils/cache/fdt_cmo_helper.h>
#include <sbi_utils/fdt/fdt_domain.h>
#include <sbi_utils/fdt/fdt_driver.h>
@@ -33,6 +36,86 @@
/* List of platform override modules generated at compile time */
extern const struct fdt_driver *const platform_override_modules[];
+/*
+ * mpt_early_init(): Detects the SMMPT mode and initializes the
+ * structures (not MPT tables) requried to prepare MPT tables and
+ * domain programming.
+ */
+int mpt_early_init(bool cold_boot)
+{
+ int rc;
+
+ if (!cold_boot)
+ return 0;
+
+ rc = sbi_mpt_init();
+ if (rc == SBI_ENODEV)
+ return 0;
+
+ return rc;
+}
+
+/*
+ * mpt_final_init(): Performs the final initialzation including
+ * creation of Root supervisor domain.
+ */
+int mpt_final_init(bool cold_boot)
+{
+ int rc;
+ u32 sdid;
+ struct sbi_domain *dom, *root_dom;
+ struct sbi_mpt_domain_config cfg;
+
+ if (!cold_boot)
+ return 0;
+
+ /* SMMPT may be unavailable */
+ if (!sbi_mpt_ctrl_get()->ready)
+ return 0;
+
+ /*
+ * Create MPT domain for Root domain.
+ *
+ * Root domain maps all physical memory so the
+ * firmware region must be explicitly denied to S-mode.
+ *
+ * regions pointer is NULL and nregions is 0 since there
+ * are no other regions other than respective SBI domain for mapping.
+ */
+ root_dom = sbi_domain_thishart_ptr();
+ cfg.sbi_dom = root_dom;
+ cfg.xwr = SBI_MPT_PERM_RWX;
+ cfg.fw_protect = true;
+ cfg.regions = NULL;
+ cfg.nregions = 0;
+
+ rc = sbi_mpt_domain_create(&cfg, &sdid);
+ if (rc) {
+ sbi_printf("mpt: Root domain create failed rc=%d\n", rc);
+ return rc;
+ }
+
+ sbi_memset(&cfg, 0, sizeof(cfg));
+
+ /* Create MPT domain for all other registered SBI domains. */
+ sbi_domain_for_each(dom) {
+ if (dom == root_dom)
+ continue;
+
+ cfg.sbi_dom = dom;
+ cfg.xwr = SBI_MPT_PERM_RWX;
+ cfg.fw_protect = false;
+ cfg.regions = NULL;
+ cfg.nregions = 0;
+
+ rc = sbi_mpt_domain_create(&cfg, &sdid);
+ if (rc)
+ sbi_printf("mpt: domain '%s' failed rc=%d\n", dom->name, rc);
+ }
+
+ return 0;
+}
+
static u32 fw_platform_calculate_heap_size(u32 hart_count)
{
u32 heap_size;
@@ -42,6 +125,15 @@ static u32 fw_platform_calculate_heap_size(u32 hart_count)
/* For TLB fifo */
heap_size += SBI_TLB_INFO_SIZE * (hart_count) * (hart_count);
+ /*
+ * MPT table budget
+ * 1 MiB memory for MPT allocated currently.
+ *
+ * TODO: Need better way to get the memory budget based on active
+ * SMMPT mode.
+ */
+ heap_size += 1024 * 1024;
+
return BIT_ALIGN(heap_size, HEAP_BASE_ALIGN);
}
@@ -229,6 +321,10 @@ int generic_early_init(bool cold_boot)
return rc;
fdt_driver_init_all(fdt, fdt_early_drivers);
+
+ rc = mpt_early_init(cold_boot);
+ if (rc)
+ return rc;
}
return fdt_cmo_init(cold_boot);
@@ -236,11 +332,16 @@ int generic_early_init(bool cold_boot)
int generic_final_init(bool cold_boot)
{
+ int rc;
void *fdt = fdt_get_address_rw();
if (!cold_boot)
return 0;
+ rc = mpt_final_init(cold_boot);
+ if (rc)
+ return rc;
+
fdt_cpu_fixup(fdt);
fdt_fixups(fdt);
fdt_domain_fixup(fdt);
--
2.51.0
--
opensbi mailing list
opensbi@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
next prev parent reply other threads:[~2026-07-27 13:56 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-27 13:55 [RFC PATCH v2 0/5] Add Smsdid and Smmpt supervisor domain protection Rahul Pathak
2026-07-27 13:55 ` [RFC PATCH v2 1/5] riscv: Add Smsdid and Smmpt hart extensions Rahul Pathak
2026-07-27 13:56 ` [RFC PATCH v2 2/5] mpt: Add Smsdid and Smmpt supervisor domain core Rahul Pathak
2026-08-14 18:28 ` Pawandeep Oza
2026-08-22 12:18 ` Rahul Pathak
2026-07-27 13:56 ` Rahul Pathak [this message]
2026-07-28 17:53 ` [RFC PATCH v2 3/5] platform/generic: Initialise MPT at boot Pawandeep Oza
2026-07-29 2:37 ` Rahul Pathak
2026-07-27 13:56 ` [RFC PATCH v2 4/5] sbi: hsm: Activate MPT for domain on hart start/resume Rahul Pathak
2026-07-28 18:18 ` Pawandeep Oza
2026-07-27 13:56 ` [RFC PATCH v2 5/5] sbi: init: Print supervisor domains at boot Rahul Pathak
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=20260727135605.465309-4-rahul.pathak@oss.qualcomm.com \
--to=rahul.pathak@oss.qualcomm.com \
--cc=opensbi@lists.infradead.org \
--cc=rahul@summations.net \
/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