[PATCH 5/7] lib: sbi: Add pmp_is_enabled() helper

Nicholas Piggin npiggin at gmail.com
Wed Apr 29 21:55:23 PDT 2026


Signed-off-by: Nicholas Piggin <npiggin at gmail.com>
---
 include/sbi/sbi_pmp.h | 1 +
 lib/sbi/riscv_asm.c   | 6 +-----
 lib/sbi/sbi_pmp.c     | 9 +++++++++
 3 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/include/sbi/sbi_pmp.h b/include/sbi/sbi_pmp.h
index 66a5cc75..bce62d22 100644
--- a/include/sbi/sbi_pmp.h
+++ b/include/sbi/sbi_pmp.h
@@ -14,6 +14,7 @@ struct pmp {
 };
 typedef struct pmp pmp_t;
 
+bool pmp_is_enabled(pmp_t *pmp);
 int pmp_encode(pmp_t *pmp, unsigned long prot, unsigned long addr,
 	       unsigned long log2len);
 int pmp_decode(pmp_t *pmp, unsigned long *prot, unsigned long *addr,
diff --git a/lib/sbi/riscv_asm.c b/lib/sbi/riscv_asm.c
index 2fb0f585..c0ad4dbe 100644
--- a/lib/sbi/riscv_asm.c
+++ b/lib/sbi/riscv_asm.c
@@ -353,11 +353,7 @@ int is_pmp_entry_mapped(unsigned long entry)
 	if (hart_pmp_read(&pmp, entry) != SBI_OK)
 		return false;
 
-	/* If address matching bits are non-zero, the entry is enable */
-	if (pmp.cfg & PMP_A)
-		return true;
-
-	return false;
+	return pmp_is_enabled(&pmp);
 }
 
 int pmp_set(unsigned int n, unsigned long prot, unsigned long addr,
diff --git a/lib/sbi/sbi_pmp.c b/lib/sbi/sbi_pmp.c
index 91eab87f..75b18764 100644
--- a/lib/sbi/sbi_pmp.c
+++ b/lib/sbi/sbi_pmp.c
@@ -28,6 +28,15 @@ static unsigned long ctz(unsigned long x)
 	return ret;
 }
 
+bool pmp_is_enabled(pmp_t *pmp)
+{
+	/* If address matching bits are non-zero, the entry is enable */
+	if (pmp->cfg & PMP_A)
+		return true;
+
+	return false;
+}
+
 int pmp_encode(pmp_t *pmp, unsigned long prot, unsigned long addr,
 	       unsigned long log2len)
 {
-- 
2.53.0




More information about the opensbi mailing list