[PATCH] lib: sbi: Fix PMP entry detetcion mechanism
Vincent Chen
vincent.chen at sifive.com
Tue Oct 27 03:54:23 EDT 2020
The granularity of PMP access control settings is platform-specific. If
the granularity is greater than 4 bytes, the current mechanism will not
work because the return value will be forced to be granularity alignment
so that the returned value is not equal to the written value. This patch
writes PMP_ADDR_MASK to each PMP addr registers and checks the return
value that is unequaled to zero to identify whether this PMP entry is
support or not.
Signed-off-by: Vincent Chen <vincent.chen at sifive.com>
---
lib/sbi/sbi_hart.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c
index 6413194..42c4f51 100644
--- a/lib/sbi/sbi_hart.c
+++ b/lib/sbi/sbi_hart.c
@@ -372,7 +372,7 @@ static void hart_detect_features(struct sbi_scratch *scratch)
} else { \
csr_write_allowed(__csr, (ulong)&trap, __wrval);\
if (!trap.cause) { \
- if (csr_swap(__csr, val) == __wrval) \
+ if (csr_swap(__csr, val)) \
(hfeatures->__field)++; \
else \
goto __skip; \
@@ -403,7 +403,7 @@ static void hart_detect_features(struct sbi_scratch *scratch)
__check_csr_32(__csr + 32, __rdonly, __wrval, __field, __skip)
/* Detect number of PMP regions */
- __check_csr_64(CSR_PMPADDR0, 0, 1UL, pmp_count, __pmp_skip);
+ __check_csr_64(CSR_PMPADDR0, 0, PMP_ADDR_MASK, pmp_count, __pmp_skip);
__pmp_skip:
/* Detect number of MHPM counters */
--
2.7.4
More information about the opensbi
mailing list