summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVasan VS <vasan.vs@gmail.com>2021-11-08 07:54:56 +0300
committerAnup Patel <anup@brainfault.org>2021-11-11 15:57:53 +0300
commit31fe5a7a3d80f0ceb25005740313cee1ef3fd4f6 (patch)
tree1879794074da80210363b7df3ff55806ecb4eca8
parentb8845e420453531f92414b91828c58d6d4f90fff (diff)
downloadopensbi-31fe5a7a3d80f0ceb25005740313cee1ef3fd4f6.tar.xz
lib: sbi: Fix PMP address bits detection
We should ensure that pmpcfg0.pmp0cfg is set to zero before using pmpaddr0 CSR for detecting implemented PMP address bits. Fixes: bf21632860b4 ("lib: sbi: Detect PMP granularity and number of address bits") Signed-off-by: Vasan VS <vasan.vs@gmail.com> Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Dong Du <Dd_nirvana@sjtu.edu.cn>
-rw-r--r--lib/sbi/sbi_hart.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c
index a4e9bf5..76ed678 100644
--- a/lib/sbi/sbi_hart.c
+++ b/lib/sbi/sbi_hart.c
@@ -338,6 +338,10 @@ static unsigned long hart_pmp_get_allowed_addr(void)
unsigned long val = 0;
struct sbi_trap_info trap = {0};
+ csr_write_allowed(CSR_PMPCFG0, (ulong)&trap, 0);
+ if (trap.cause)
+ return 0;
+
csr_write_allowed(CSR_PMPADDR0, (ulong)&trap, PMP_ADDR_MASK);
if (!trap.cause) {
val = csr_read_allowed(CSR_PMPADDR0, (ulong)&trap);