Skip to content

Commit

Permalink
lib: sbi: fix number of PMP entries detection
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
vlkondratiev committed Sep 2, 2024
1 parent c4940a9 commit 797dba3
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/sbi/sbi_hart.c
Original file line number Diff line number Diff line change
Expand Up @@ -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; \
Expand Down

0 comments on commit 797dba3

Please sign in to comment.