lib: sbi/hart: preserve csr validation value

The OpenSBI hart init function hart_detect_features() try to read
important CSRs but reasign the last read value to the variable that
initially contains write probe value. So for series of CSRs (like
PMPADDRx) the second CSR probe value will became the initial value of
first probing CSR. To avoid of this issue the CSR read value should be
saved in different variable. In this configuration the count of PMP
will detect rightly if any PMPADDR is hardwired to zero.

Signed-off-by: Dmitry Dunaev <dunaich@mail.ru>
Signed-off-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
Dmitry Dunaev 2022-04-17 14:43:08 +05:30 committed by Anup Patel
parent c1e47d0c3f
commit 9cd95e13bb
1 changed files with 3 additions and 3 deletions

View File

@ -478,7 +478,7 @@ static void hart_detect_features(struct sbi_scratch *scratch)
{ {
struct sbi_trap_info trap = {0}; struct sbi_trap_info trap = {0};
struct hart_features *hfeatures; struct hart_features *hfeatures;
unsigned long val; unsigned long val, oldval;
/* Reset hart features */ /* Reset hart features */
hfeatures = sbi_scratch_offset_ptr(scratch, hart_features_offset); hfeatures = sbi_scratch_offset_ptr(scratch, hart_features_offset);
@ -487,14 +487,14 @@ static void hart_detect_features(struct sbi_scratch *scratch)
hfeatures->mhpm_count = 0; hfeatures->mhpm_count = 0;
#define __check_csr(__csr, __rdonly, __wrval, __field, __skip) \ #define __check_csr(__csr, __rdonly, __wrval, __field, __skip) \
val = csr_read_allowed(__csr, (ulong)&trap); \ oldval = csr_read_allowed(__csr, (ulong)&trap); \
if (!trap.cause) { \ if (!trap.cause) { \
if (__rdonly) { \ if (__rdonly) { \
(hfeatures->__field)++; \ (hfeatures->__field)++; \
} else { \ } else { \
csr_write_allowed(__csr, (ulong)&trap, __wrval);\ csr_write_allowed(__csr, (ulong)&trap, __wrval);\
if (!trap.cause) { \ if (!trap.cause) { \
if (csr_swap(__csr, val) == __wrval) \ if (csr_swap(__csr, oldval) == __wrval) \
(hfeatures->__field)++; \ (hfeatures->__field)++; \
else \ else \
goto __skip; \ goto __skip; \