Maximilian Brune has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/83283?usp=email )
Change subject: arch/riscv: Add PMP print function ......................................................................
arch/riscv: Add PMP print function
For easier debugging it is useful to have a function that prints the PMP regions.
Signed-off-by: Maximilian Brune maximilian.brune@9elements.com Change-Id: I6ab1531c65b14690e37aecf57ff441bf22db1ce5 --- M src/arch/riscv/include/arch/pmp.h M src/arch/riscv/pmp.c 2 files changed, 49 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/83/83283/1
diff --git a/src/arch/riscv/include/arch/pmp.h b/src/arch/riscv/include/arch/pmp.h index f98adf7..273ccfe 100644 --- a/src/arch/riscv/include/arch/pmp.h +++ b/src/arch/riscv/include/arch/pmp.h @@ -11,6 +11,8 @@ */ int pmp_entries_num(void);
+void print_pmp_regions(void); + /* reset PMP setting */ void reset_pmp(void);
diff --git a/src/arch/riscv/pmp.c b/src/arch/riscv/pmp.c index b643441..18bb704 100644 --- a/src/arch/riscv/pmp.c +++ b/src/arch/riscv/pmp.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-only */
+#include "commonlib/bsd/helpers.h" #include <arch/encoding.h> #include <stdint.h> #include <arch/pmp.h> @@ -314,6 +315,52 @@ pmp_entry_used_mask |= 1 << idx; }
+/* prints the pmp regions by reading the PMP address and configuration registers */ +void print_pmp_regions(void) +{ + uintptr_t prev_pmpaddr = 0; + uintptr_t base = 0; + uintptr_t size = 0; + const char *mode; + for (int i = 0; i < pmp_entries_num(); i++) { + uintptr_t pmpcfg = read_pmpcfg(i); + uintptr_t pmpaddr = read_pmpaddr(i); + if ((pmpcfg & PMP_A) == 0) { + continue; // PMP entry is disabled + } else if (pmpcfg & PMP_NA4) { + base = pmpaddr << PMP_SHIFT; + size = 4; + mode = "NA4"; + } else if (pmpcfg & PMP_NAPOT) { + unsigned int count_trailing_ones = 0; + base = pmpaddr; + while (base) { + if ((base & 1) == 0) + break; // we got a zero + count_trailing_ones++; + base >>= 1; + } + size = 8 << count_trailing_ones; + base = (pmpaddr & ~((2 << count_trailing_ones) - 1)) >> PMP_SHIFT; + mode = "NAPOT"; + } else if (pmpcfg & PMP_TOR) { + base = pmpaddr; + size = pmpaddr - prev_pmpaddr; + mode = "TOR"; + } + + printk(BIOS_DEBUG, "base: 0x%lx, size: 0x%lx, perm: %c%c%c, mode: %s, locked: %d\n", + base, size, + (pmpcfg & PMP_R) ? 'r' : ' ', + (pmpcfg & PMP_W) ? 'w' : ' ', + (pmpcfg & PMP_X) ? 'x' : ' ', + mode, + (pmpcfg & PMP_L) ? 1 : 0); + + prev_pmpaddr = pmpaddr; + } +} + /* reset PMP setting */ void reset_pmp(void) {