From a38bea9341a2da29bec00d5253ac71da8ca06bab Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Mon, 18 May 2020 12:04:18 +0530 Subject: 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 --- lib/utils/fdt/fdt_fixup.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'lib/utils') diff --git a/lib/utils/fdt/fdt_fixup.c b/lib/utils/fdt/fdt_fixup.c index 6b11b415..49848b2d 100644 --- a/lib/utils/fdt/fdt_fixup.c +++ b/lib/utils/fdt/fdt_fixup.c @@ -8,7 +8,6 @@ */ #include -#include #include #include #include @@ -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; -- cgit v1.3.1