From 797dba3179c2dbee99778442c1ec40ca1dfc7ca9 Mon Sep 17 00:00:00 2001 From: Vladimir Kondratiev Date: Mon, 2 Sep 2024 11:56:35 +0300 Subject: [PATCH] lib: sbi: fix number of PMP entries detection CSR_PMPADDRn lower bits may read all-0 or all-1, depending on the configuration. For TOR it is all-0, for NAPOT - all-1. Thus if PMP entry was pre-configured as NAPOT, original code would stop scanning because value read back not equal to the written one. Mask lower bits before comparison to fix this Signed-off-by: Vladimir Kondratiev --- 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 cc364fac2c..61cddc2b1d 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -817,7 +817,7 @@ static int hart_detect_features(struct sbi_scratch *scratch) } else { \ csr_write_allowed(__csr, &trap, __wrval); \ if (!trap.cause) { \ - if (csr_swap(__csr, oldval) == __wrval) \ + if ((csr_swap(__csr, oldval) & __wrval) == __wrval) \ (hfeatures->__field)++; \ else \ goto __skip; \