[RFC PATCH 02/23] lib: sbi: hart_pmp: export start-aware PMP operations
Yu-Chien Peter Lin
peter.lin at sifive.com
Mon Nov 30 02:11:26 PST 2026
Export sbi_hart_oldpmp_configure(), sbi_hart_smepmp_configure(),
sbi_hart_pmp_unconfigure(), sbi_hart_smepmp_temp_map_range(),
and sbi_hart_smepmp_temp_unmap_range() for platform protection
providers.
Signed-off-by: Yu-Chien Peter Lin <peter.lin at sifive.com>
---
include/sbi/sbi_hart_pmp.h | 19 +++++++++++++++++++
lib/sbi/sbi_hart_pmp.c | 27 +++++++++++++--------------
2 files changed, 32 insertions(+), 14 deletions(-)
diff --git a/include/sbi/sbi_hart_pmp.h b/include/sbi/sbi_hart_pmp.h
index 6a8b3e79..d9151531 100644
--- a/include/sbi/sbi_hart_pmp.h
+++ b/include/sbi/sbi_hart_pmp.h
@@ -21,6 +21,7 @@ int sbi_hart_pmp_set(unsigned int n, unsigned long prot,
int sbi_hart_pmp_get(unsigned int n, unsigned long *prot_out,
unsigned long *addr_out, unsigned long *log2len);
+struct sbi_domain;
struct sbi_scratch;
unsigned int sbi_hart_pmp_count(struct sbi_scratch *scratch);
@@ -30,4 +31,22 @@ bool sbi_hart_smepmp_is_fw_region(unsigned int pmp_idx);
void sbi_hart_pmp_fence(void);
int sbi_hart_pmp_init(struct sbi_scratch *scratch);
+/*
+ * Entries below start are caller-owned. Regular domain entries begin at
+ * start. Smepmp reserves entry start for temporary mappings and begins
+ * domain entries at start + 1. Firmware entry indices remain absolute.
+ */
+int sbi_hart_smepmp_configure(struct sbi_scratch *scratch,
+ struct sbi_domain *dom, unsigned int start);
+int sbi_hart_oldpmp_configure(struct sbi_scratch *scratch,
+ struct sbi_domain *dom, unsigned int start);
+void sbi_hart_pmp_unconfigure(struct sbi_scratch *scratch,
+ struct sbi_domain *dom, unsigned int start);
+int sbi_hart_smepmp_temp_map_range(struct sbi_scratch *scratch,
+ unsigned long addr, unsigned long size,
+ unsigned int start);
+int sbi_hart_smepmp_temp_unmap_range(struct sbi_scratch *scratch,
+ unsigned long addr, unsigned long size,
+ unsigned int start);
+
#endif
diff --git a/lib/sbi/sbi_hart_pmp.c b/lib/sbi/sbi_hart_pmp.c
index 4182459b..1a36621d 100644
--- a/lib/sbi/sbi_hart_pmp.c
+++ b/lib/sbi/sbi_hart_pmp.c
@@ -9,6 +9,7 @@
#include <sbi/sbi_domain.h>
#include <sbi/sbi_hart.h>
#include <sbi/sbi_hart_protection.h>
+#include <sbi/sbi_hart_pmp.h>
#include <sbi/sbi_hfence.h>
#include <sbi/sbi_math.h>
#include <sbi/sbi_platform.h>
@@ -227,8 +228,8 @@ static bool is_valid_pmp_idx(unsigned int pmp_count, unsigned int pmp_idx)
return false;
}
-static int sbi_hart_smepmp_configure(struct sbi_scratch *scratch,
- struct sbi_domain *dom, unsigned int start)
+int sbi_hart_smepmp_configure(struct sbi_scratch *scratch,
+ struct sbi_domain *dom, unsigned int start)
{
struct sbi_domain_memregion *reg;
unsigned int pmp_log2gran, pmp_bits;
@@ -323,10 +324,9 @@ static int sbi_hart_smepmp_configure(struct sbi_scratch *scratch,
return 0;
}
-static int sbi_hart_smepmp_temp_map_range(struct sbi_scratch *scratch,
- unsigned long addr,
- unsigned long size,
- unsigned int start)
+int sbi_hart_smepmp_temp_map_range(struct sbi_scratch *scratch,
+ unsigned long addr, unsigned long size,
+ unsigned int start)
{
/* shared R/W access for M and S/U mode */
unsigned int pmp_flags = (PMP_W | PMP_X);
@@ -359,10 +359,9 @@ static int sbi_hart_smepmp_temp_map_range(struct sbi_scratch *scratch,
return SBI_OK;
}
-static int sbi_hart_smepmp_temp_unmap_range(struct sbi_scratch *scratch,
- unsigned long addr,
- unsigned long size,
- unsigned int start)
+int sbi_hart_smepmp_temp_unmap_range(struct sbi_scratch *scratch,
+ unsigned long addr, unsigned long size,
+ unsigned int start)
{
if (!is_valid_pmp_idx(sbi_hart_pmp_count(scratch), start))
return SBI_EFAIL;
@@ -371,8 +370,8 @@ static int sbi_hart_smepmp_temp_unmap_range(struct sbi_scratch *scratch,
return sbi_hart_pmp_disable(start);
}
-static int sbi_hart_oldpmp_configure(struct sbi_scratch *scratch,
- struct sbi_domain *dom, unsigned int start)
+int sbi_hart_oldpmp_configure(struct sbi_scratch *scratch,
+ struct sbi_domain *dom, unsigned int start)
{
struct sbi_domain_memregion *reg;
unsigned long pmp_addr, pmp_addr_max;
@@ -412,8 +411,8 @@ static int sbi_hart_oldpmp_configure(struct sbi_scratch *scratch,
return 0;
}
-static void sbi_hart_pmp_unconfigure(struct sbi_scratch *scratch,
- struct sbi_domain *dom, unsigned int start)
+void sbi_hart_pmp_unconfigure(struct sbi_scratch *scratch,
+ struct sbi_domain *dom, unsigned int start)
{
unsigned int i, pmp_count = sbi_hart_pmp_count(scratch);
--
2.43.7
More information about the opensbi
mailing list