summaryrefslogtreecommitdiff
path: root/lib/utils/fdt
diff options
context:
space:
mode:
authorAnup Patel <anup.patel@wdc.com>2020-05-18 09:34:18 +0300
committerAnup Patel <anup@brainfault.org>2020-05-19 06:49:48 +0300
commita38bea9341a2da29bec00d5253ac71da8ca06bab (patch)
tree167a46716be4bd24d36b64c50412d11c63a15ce1 /lib/utils/fdt
parent2966510eedf03e47e13f3e1a88039bd4199c1085 (diff)
downloadopensbi-a38bea9341a2da29bec00d5253ac71da8ca06bab.tar.xz
lib: sbi_hart: Detect number of supported PMP regions
It is not mandatory for a RISC-V systems to implement all PMP regions so we have to check all PMPADDRx CSRs to determine excat number of supported PMP regions. Signed-off-by: Anup Patel <anup.patel@wdc.com>
Diffstat (limited to 'lib/utils/fdt')
-rw-r--r--lib/utils/fdt/fdt_fixup.c34
1 files changed, 18 insertions, 16 deletions
diff --git a/lib/utils/fdt/fdt_fixup.c b/lib/utils/fdt/fdt_fixup.c
index 6b11b41..49848b2 100644
--- a/lib/utils/fdt/fdt_fixup.c
+++ b/lib/utils/fdt/fdt_fixup.c
@@ -8,7 +8,6 @@
*/
#include <libfdt.h>
-#include <sbi/riscv_asm.h>
#include <sbi/sbi_console.h>
#include <sbi/sbi_math.h>
#include <sbi/sbi_hart.h>
@@ -183,6 +182,15 @@ int fdt_reserved_memory_fixup(void *fdt)
return err;
}
+ /*
+ * We assume the given device tree does not contain any memory region
+ * child node protected by PMP. Normally PMP programming happens at
+ * M-mode firmware. The memory space used by OpenSBI is protected.
+ * Some additional memory spaces may be protected by platform codes.
+ *
+ * With above assumption, we create child nodes directly.
+ */
+
if (!sbi_hart_has_feature(scratch, SBI_HART_HAS_PMP)) {
/*
* Update the DT with firmware start & size even if PMP is not
@@ -193,24 +201,18 @@ int fdt_reserved_memory_fixup(void *fdt)
size = (1UL << log2roundup(scratch->fw_size));
return fdt_resv_memory_update_node(fdt, addr, size, 0, parent);
}
- /*
- * We assume the given device tree does not contain any memory region
- * child node protected by PMP. Normally PMP programming happens at
- * M-mode firmware. The memory space used by OpenSBI is protected.
- * Some additional memory spaces may be protected by platform codes.
- *
- * With above assumption, we create child nodes directly.
- */
- for (i = 0, j = 0; i < PMP_COUNT; i++) {
- pmp_get(i, &prot, &addr, &size);
+ for (i = 0, j = 0; i < sbi_hart_pmp_count(scratch); i++) {
+ err = sbi_hart_pmp_get(scratch, i, &prot, &addr, &size);
+ if (err)
+ continue;
if (!(prot & PMP_A))
continue;
- if (!(prot & (PMP_R | PMP_W | PMP_X))) {
- return fdt_resv_memory_update_node(fdt, addr, size,
- j, parent);
- j++;
- }
+ if (prot & (PMP_R | PMP_W | PMP_X))
+ continue;
+
+ fdt_resv_memory_update_node(fdt, addr, size, j, parent);
+ j++;
}
return 0;