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
Reviewed-on: https://review.coreboot.org/c/coreboot/+/83283
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Elyes Haouas <ehaouas@noos.fr>
Reviewed-by: ron minnich <rminnich@gmail.com>
This commit is contained in:
Maximilian Brune
2024-06-08 20:22:45 +02:00
committed by Felix Held
parent 96719adda3
commit eb28f3da7d
2 changed files with 48 additions and 0 deletions

View File

@@ -11,6 +11,8 @@
*/
int pmp_entries_num(void);
void print_pmp_regions(void);
/* reset PMP setting */
void reset_pmp(void);

View File

@@ -314,6 +314,52 @@ static void mask_pmp_entry_used(int idx)
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)
{