[RFC PATCH 05/23] lib: sbi: hart_pmp: use sbi_hart_pmp_addr_mask()

Yu-Chien Peter Lin peter.lin at sifive.com
Mon Nov 30 02:11:29 PST 2026


Use sbi_hart_pmp_addr_mask() for address-limit checks in regular and
Smepmp configuration rather than duplicating the mask calculation.

The shared helper avoids invalid shifts for a reported address width
of zero or at least BITS_PER_LONG.

Signed-off-by: Yu-Chien Peter Lin <peter.lin at sifive.com>
---
 lib/sbi/sbi_hart_pmp.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/lib/sbi/sbi_hart_pmp.c b/lib/sbi/sbi_hart_pmp.c
index bda641c5..26864fd8 100644
--- a/lib/sbi/sbi_hart_pmp.c
+++ b/lib/sbi/sbi_hart_pmp.c
@@ -243,15 +243,14 @@ 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;
+	unsigned int pmp_log2gran;
 	unsigned int pmp_idx, pmp_count;
 	unsigned long pmp_addr_max;
 	unsigned int pmp_flags;
 
 	pmp_count = sbi_hart_pmp_count(scratch);
 	pmp_log2gran = sbi_hart_pmp_log2gran(scratch);
-	pmp_bits = sbi_hart_pmp_addrbits(scratch) - 1;
-	pmp_addr_max = (1UL << pmp_bits) | ((1UL << pmp_bits) - 1);
+	pmp_addr_max = sbi_hart_pmp_addr_mask(scratch);
 
 	/*
 	 * Set the RLB so that, we can write to PMP entries without
@@ -386,14 +385,13 @@ int sbi_hart_oldpmp_configure(struct sbi_scratch *scratch,
 {
 	struct sbi_domain_memregion *reg;
 	unsigned long pmp_addr, pmp_addr_max;
-	unsigned int pmp_log2gran, pmp_bits;
+	unsigned int pmp_log2gran;
 	unsigned int pmp_idx, pmp_count;
 	unsigned int pmp_flags;
 
 	pmp_count = sbi_hart_pmp_count(scratch);
 	pmp_log2gran = sbi_hart_pmp_log2gran(scratch);
-	pmp_bits = sbi_hart_pmp_addrbits(scratch) - 1;
-	pmp_addr_max = (1UL << pmp_bits) | ((1UL << pmp_bits) - 1);
+	pmp_addr_max = sbi_hart_pmp_addr_mask(scratch);
 
 	pmp_idx = start;
 	sbi_domain_for_each_memregion(dom, reg) {
-- 
2.43.7




More information about the opensbi mailing list