opensbi
opensbi copied to clipboard
pmp-granularity detection assumes pmpcfg is reset to 0
The current method for checking pmp granularity is to write all ones to the pmpaddr0 and then checking the number of trailing zeros on a read of the same csr. However, this only works if the pmpcfg0.A as been configured to TOR or OFF. But reset values of pmpcfg.A is implementation defined. For example, Spike resets all the pmpcfg.A to NAPOT. Which means the lower order bits will all be read as ones instead of zeros.
Thus opensbi needs to first set pmpcfg0.A to 0 and then check for trailing zeros in pmpaddr0.
Yes, we have been assuming that all PMPCFGx will be set to zero upon reset.
This is a good catch.
Can any of your folks send patch to mailing list for fixing this in hart_pmp_get_allowed_addr() ?
Regards, Anup
The following is the PATCH for this fix and has been sent to the mailing list as well.
diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c index 6254452..0659486 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -346,6 +346,7 @@ static unsigned long hart_pmp_get_allowed_addr(void) unsigned long val = 0; struct sbi_trap_info trap = {0};
- csr_write(CSR_PMPCFG0, 0); csr_write_allowed(CSR_PMPADDR0, (ulong)&trap, PMP_ADDR_MASK); if (!trap.cause) { val = csr_read_allowed(CSR_PMPADDR0, (ulong)&trap);