[RFC PATCH v7 6/6] lib: sbi: Initialize Smsd during coldboot
Rahul Pathak
rahul.pathak at oss.qualcomm.com
Sun Nov 1 20:33:57 PST 2026
Call sbi_mpt_init() function from coldboot path of
sbi_hart_init() to initialize the Smsd core. It will
create and the MPT tables for each SBI domain and maps
its memregions with appropriate permissions in MPT tables.
Also each MPT table requires to memory to install tables
so reserve more space in heap for MPT tables
Signed-off-by: Rahul Pathak <rahul.pathak at oss.qualcomm.com>
---
lib/sbi/sbi_hart.c | 6 ++++++
platform/generic/platform.c | 23 +++++++++++++++++++----
2 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c
index 54191041a2a1..b15a2a93c8cd 100644
--- a/lib/sbi/sbi_hart.c
+++ b/lib/sbi/sbi_hart.c
@@ -16,6 +16,7 @@
#include <sbi/sbi_csr_detect.h>
#include <sbi/sbi_error.h>
#include <sbi/sbi_hart.h>
+#include <sbi/sbi_hart_mpt.h>
#include <sbi/sbi_hart_pmp.h>
#include <sbi/sbi_platform.h>
#include <sbi/sbi_pmu.h>
@@ -731,6 +732,11 @@ int sbi_hart_init(struct sbi_scratch *scratch, bool cold_boot)
rc = sbi_hart_pmp_init(scratch);
if (rc)
return rc;
+
+ /* Smsd is optional. Continue if Smsd is not present. */
+ rc = sbi_mpt_init();
+ if (rc && rc != SBI_ENODEV)
+ return rc;
}
return sbi_hart_reinit(scratch);
diff --git a/platform/generic/platform.c b/platform/generic/platform.c
index 1df0280da61f..469c169c443f 100644
--- a/platform/generic/platform.c
+++ b/platform/generic/platform.c
@@ -33,7 +33,7 @@
/* List of platform override modules generated at compile time */
extern const struct fdt_driver *const platform_override_modules[];
-static u32 fw_platform_calculate_heap_size(u32 hart_count)
+static u32 fw_platform_calculate_heap_size(u32 hart_count, bool has_smsd)
{
u32 heap_size;
@@ -42,10 +42,21 @@ 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, only when a hart implements Smsd.
+ * 1 MiB memory for MPT allocated currently.
+ *
+ * TODO: Need better way to get the memory budget based on active
+ * MPT mode.
+ */
+ if (has_smsd)
+ heap_size += 1024 * 1024;
+
return BIT_ALIGN(heap_size, HEAP_BASE_ALIGN);
}
-static u32 fw_platform_get_heap_size(const void *fdt, u32 hart_count)
+static u32 fw_platform_get_heap_size(const void *fdt, u32 hart_count,
+ bool has_smsd)
{
int chosen_offset, config_offset, len;
const fdt32_t *val;
@@ -64,7 +75,7 @@ static u32 fw_platform_get_heap_size(const void *fdt, u32 hart_count)
return BIT_ALIGN(fdt32_to_cpu(*val), HEAP_BASE_ALIGN);
default_config:
- return fw_platform_calculate_heap_size(hart_count);
+ return fw_platform_calculate_heap_size(hart_count, has_smsd);
}
extern struct sbi_platform platform;
@@ -149,6 +160,7 @@ unsigned long fw_platform_init(unsigned long arg0, unsigned long arg1,
int rc, root_offset, cpus_offset, cpu_offset, len;
unsigned long cbom_block_size = 0;
unsigned long tmp = 0;
+ bool has_smsd = false;
root_offset = fdt_path_offset(fdt, "/");
if (root_offset < 0)
@@ -177,6 +189,9 @@ unsigned long fw_platform_init(unsigned long arg0, unsigned long arg1,
generic_hart_index2id[hart_count++] = hartid;
+ if (fdt_cpu_has_extension(fdt, cpu_offset, SBI_HART_EXT_SMSD))
+ has_smsd = true;
+
rc = fdt_parse_cbom_block_size(fdt, cpu_offset, &tmp);
if (rc)
continue;
@@ -184,7 +199,7 @@ unsigned long fw_platform_init(unsigned long arg0, unsigned long arg1,
}
platform.hart_count = hart_count;
- platform.heap_size = fw_platform_get_heap_size(fdt, hart_count);
+ platform.heap_size = fw_platform_get_heap_size(fdt, hart_count, has_smsd);
platform_has_mlevel_imsic = fdt_check_imsic_mlevel(fdt);
platform.cbom_block_size = cbom_block_size;
--
2.53.0
More information about the opensbi
mailing list