[PATCH 1/7] lib: sbi: Probe pmp_count in read-only

Yangyu Chen cyy at cyyself.name
Thu Dec 7 14:04:05 PST 2023


Some CPU implementations such as T-Head C908 will raise illegal
instruction exception when writing a different value to some pmpaddr
which is locked.

To avoid this, a solution is to probe pmp_count in read-only. This will
not affect the existing CPU implementation as RISC-V Privileged
Architecture specified that access to a non-existent CSR raises an
illegal instruction exception.

Signed-off-by: Yangyu Chen <cyy at cyyself.name>
---
 lib/sbi/sbi_hart.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c
index c948373..49d1454 100644
--- a/lib/sbi/sbi_hart.c
+++ b/lib/sbi/sbi_hart.c
@@ -877,7 +877,7 @@ static int hart_detect_features(struct sbi_scratch *scratch)
 		hfeatures->pmp_gran =  1 << (sbi_ffs(val) + 2);
 		hfeatures->pmp_addr_bits = sbi_fls(val) + 1;
 		/* Detect number of PMP regions. At least PMPADDR0 should be implemented*/
-		__check_csr_64(CSR_PMPADDR0, 0, val, pmp_count, __pmp_skip);
+		__check_csr_64(CSR_PMPADDR0, true, 0, pmp_count, __pmp_skip);
 	}
 __pmp_skip:
 	/* Detect number of MHPM counters */
-- 
2.43.0




More information about the opensbi mailing list