[RFC PATCH 22/23] platform: generic: sifive: dump static PMP entries at boot
Yu-Chien Peter Lin
peter.lin at sifive.com
Mon Nov 30 02:11:46 PST 2026
Print the static PMP entries after they are enforced on the cold boot
hart, one line per entry: PMP[n]: <lower>-<upper> L:<l> A:<a> R:<r>
W:<w> X:<x>. The values are decoded from the PMP CSRs read back with
sbi_hart_pmp_read(), not from the parsed region table, so the log shows
what hardware actually holds. A is the raw pmpcfg A field (0=OFF,
1=TOR, 2=NA4, 3=NAPOT). An OFF entry is the lower bound of the
following TOR entry and a TOR entry is the upper bound, so the missing
bound is shown as dots.
PMP[0]: 0x000000007f002000-.................. L:1 A:0 R:0 W:0 X:0
PMP[1]: ..................-0x000000007fe00000 L:1 A:1 R:0 W:0 X:0
PMP[2]: 0x000000007ff00000-0x0000000080000000 L:1 A:3 R:0 W:0 X:0
PMP[3]: 0x0000000480000000-.................. L:1 A:0 R:0 W:0 X:0
PMP[4]: ..................-0x0000008000000000 L:1 A:1 R:0 W:0 X:0
Signed-off-by: Yu-Chien Peter Lin <peter.lin at sifive.com>
---
platform/generic/sifive/sifive_pmp.c | 49 ++++++++++++++++++++++++++++
1 file changed, 49 insertions(+)
diff --git a/platform/generic/sifive/sifive_pmp.c b/platform/generic/sifive/sifive_pmp.c
index 2a4b08d2..58fe7006 100644
--- a/platform/generic/sifive/sifive_pmp.c
+++ b/platform/generic/sifive/sifive_pmp.c
@@ -213,6 +213,54 @@ static bool sifive_pmp_entry_matches(struct sbi_scratch *scratch,
return true;
}
+/* Dump static PMP entries from their programmed CSRs. */
+static void sifive_pmp_dump(void)
+{
+ unsigned int i;
+ unsigned long prot, base, end, log2len;
+ const char *dots = (__riscv_xlen == 64) ?
+ ".................." : "..........";
+
+ for (i = 0; i < unsafe_region_entries; i++) {
+ unsigned int l, a, r, w, x;
+ pmp_t pmp;
+
+ if (sbi_hart_pmp_read(&pmp, i)) {
+ sbi_printf("PMP[%u]: read failed\n", i);
+ continue;
+ }
+
+ l = !!(pmp.cfg & PMP_L);
+ a = (pmp.cfg & PMP_A) >> 3;
+ r = !!(pmp.cfg & PMP_R);
+ w = !!(pmp.cfg & PMP_W);
+ x = !!(pmp.cfg & PMP_X);
+
+ switch (pmp.cfg & PMP_A) {
+ case PMP_A_TOR:
+ end = pmp.addr << PMP_SHIFT;
+ sbi_printf("PMP[%u]: %s-0x%" PRILX
+ " L:%u A:%u R:%u W:%u X:%u\n",
+ i, dots, end, l, a, r, w, x);
+ break;
+ case PMP_A_NA4:
+ case PMP_A_NAPOT:
+ sbi_pmp_decode(&pmp, &prot, &base, &log2len);
+ end = base + (1UL << log2len);
+ sbi_printf("PMP[%u]: 0x%" PRILX "-0x%" PRILX
+ " L:%u A:%u R:%u W:%u X:%u\n",
+ i, base, end, l, a, r, w, x);
+ break;
+ default:
+ end = pmp.addr << PMP_SHIFT;
+ sbi_printf("PMP[%u]: 0x%" PRILX "-%s"
+ " L:%u A:%u R:%u W:%u X:%u\n",
+ i, end, dots, l, a, r, w, x);
+ break;
+ }
+ }
+}
+
/*
* Check that every region can be encoded for this hart and that no
* locked PMP entry conflicts with it. Read-only: no CSR is written.
@@ -463,6 +511,7 @@ int sifive_pmp_init(bool cold_boot)
sbi_printf("SiFive static PMP : %u PMP entries locked at "
"PMP[0..%u]\n",
unsafe_region_entries, unsafe_region_entries - 1);
+ sifive_pmp_dump();
}
return 0;
--
2.43.7
More information about the opensbi
mailing list