[RFC PATCH v2 3/7] platform: generic: introduce fw_platform_get_reserved_pmp_count()
Yu-Chien Peter Lin
peter.lin at sifive.com
Sat Oct 25 02:18:07 PDT 2025
Introduce fw_platform_get_reserved_pmp_count() to parse the
`reserved-pmp-count` property from the opensbi-config node.
Since mseccfg.{RLB,MMWP,MML} are sticky bits, we can't poll them
to detect the presence of Smempp. Therefore, the only way is to
parse it from FDT `riscv,isa-extensions` or `riscv,isa`.
Signed-off-by: Yu-Chien Peter Lin <peter.lin at sifive.com>
---
platform/generic/platform.c | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/platform/generic/platform.c b/platform/generic/platform.c
index 91140958..936e5356 100644
--- a/platform/generic/platform.c
+++ b/platform/generic/platform.c
@@ -66,6 +66,35 @@ default_config:
return fw_platform_calculate_heap_size(hart_count);
}
+static u32 fw_platform_get_reserved_pmp_count(const void *fdt)
+{
+ int chosen_offset, config_offset, len;
+ u32 reserved_pmp_count = 0;
+ const fdt32_t *val;
+
+ /*
+ * If smepmp is enabled, minimal 1 entry is required
+ * by sbi_hart_map_saddr().
+ */
+ if (fdt_has_isa_extension(fdt, "smepmp"))
+ reserved_pmp_count = 1;
+
+ chosen_offset = fdt_path_offset(fdt, "/chosen");
+ if (chosen_offset < 0)
+ goto out;
+
+ config_offset = fdt_node_offset_by_compatible(fdt, chosen_offset, "opensbi,config");
+ if (config_offset < 0)
+ goto out;
+
+ val = (fdt32_t *)fdt_getprop(fdt, config_offset, "reserved-pmp-count", &len);
+ if (len > 0 && val)
+ return fdt32_to_cpu(*val) + reserved_pmp_count;
+
+out:
+ return reserved_pmp_count;
+}
+
extern struct sbi_platform platform;
static bool platform_has_mlevel_imsic = false;
static u32 generic_hart_index2id[SBI_HARTMASK_MAX_BITS] = { 0 };
@@ -184,6 +213,8 @@ 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.reserved_pmp_count = fw_platform_get_reserved_pmp_count(fdt);
+
platform_has_mlevel_imsic = fdt_check_imsic_mlevel(fdt);
platform.cbom_block_size = cbom_block_size;
--
2.39.3
More information about the opensbi
mailing list