From f7738cc1e5cea8cae6919810407a8903248ad497 Mon Sep 17 00:00:00 2001 From: Nicholas Piggin Date: Thu, 30 Apr 2026 14:55:23 +1000 Subject: [PATCH] lib: sbi: Add sbi_pmp_is_enabled() helper Signed-off-by: Nicholas Piggin Reviewed-by: Anup Patel Link: https://lore.kernel.org/r/20260430045528.420437-7-npiggin@gmail.com Signed-off-by: Anup Patel --- 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 c38dda55..ce00ec0c 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 sbi_pmp_is_enabled(pmp_t *pmp); int sbi_pmp_encode(pmp_t *pmp, unsigned long prot, unsigned long addr, unsigned long log2len); int sbi_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 6c1f2344..69b6aea1 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 sbi_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 bb8151c0..fd1a0fd0 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 sbi_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 sbi_pmp_encode(pmp_t *pmp, unsigned long prot, unsigned long addr, unsigned long log2len) {