From 5edbb7cda1849b3d05e33256cafb7708c36f3020 Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Mon, 21 Sep 2020 15:58:14 +0530 Subject: lib: utils: Update fdt_reserved_memory_fixup() to use current domain Now that each HART is mapped to a domain having a set of memory regions, we update fdt_reserved_memory_fixup() to use domain memory regions for adding reserved memory nodes in device tree. We also change reserved memory node name prefix from "mmode_pmp" to "mmode_resv" because domain memory regions can impact other hardware configurations (such as IOPMP, etc) along with PMP. Signed-off-by: Anup Patel Reviewed-by: Atish Patra --- lib/utils/fdt/fdt_fixup.c | 47 ++++++++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/lib/utils/fdt/fdt_fixup.c b/lib/utils/fdt/fdt_fixup.c index 8f554e1..e9e1dff 100644 --- a/lib/utils/fdt/fdt_fixup.c +++ b/lib/utils/fdt/fdt_fixup.c @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -97,11 +98,11 @@ static int fdt_resv_memory_update_node(void *fdt, unsigned long addr, if (na > 1 && addr_high) sbi_snprintf(name, sizeof(name), - "mmode_pmp%d@%x,%x", index, + "mmode_resv%d@%x,%x", index, addr_high, addr_low); else sbi_snprintf(name, sizeof(name), - "mmode_pmp%d@%x", index, + "mmode_resv%d@%x", index, addr_low); subnode = fdt_add_subnode(fdt, parent, name); @@ -153,10 +154,11 @@ static int fdt_resv_memory_update_node(void *fdt, unsigned long addr, */ int fdt_reserved_memory_fixup(void *fdt) { + struct sbi_domain_memregion *reg; + struct sbi_domain *dom = sbi_domain_thishart_ptr(); struct sbi_scratch *scratch = sbi_scratch_thishart_ptr(); - unsigned long prot, addr, size; - int parent, i, j; - int err; + unsigned long addr, size; + int err, parent, i; int na = fdt_address_cells(fdt, 0); int ns = fdt_size_cells(fdt, 0); @@ -203,34 +205,29 @@ int fdt_reserved_memory_fixup(void *fdt) * 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. + * Some additional memory spaces may be protected by domain memory + * regions. * * With above assumption, we create child nodes directly. */ - if (!sbi_hart_pmp_count(scratch)) { - /* - * Update the DT with firmware start & size even if PMP is not - * supported. This makes sure that supervisor OS is always - * aware of OpenSBI resident memory area. - */ - addr = scratch->fw_start & ~(scratch->fw_size - 1UL); - size = (1UL << log2roundup(scratch->fw_size)); - return fdt_resv_memory_update_node(fdt, addr, size, - 0, parent, true); - } - - for (i = 0, j = 0; i < sbi_hart_pmp_count(scratch); i++) { - err = sbi_hart_pmp_get(scratch, i, &prot, &addr, &size); - if (err) + i = 0; + sbi_domain_for_each_memregion(dom, reg) { + /* Ignore MMIO or READABLE or WRITABLE or EXECUTABLE regions */ + if (reg->flags & SBI_DOMAIN_MEMREGION_MMIO) + continue; + if (reg->flags & SBI_DOMAIN_MEMREGION_READABLE) continue; - if (!(prot & PMP_A)) + if (reg->flags & SBI_DOMAIN_MEMREGION_WRITEABLE) continue; - if (prot & (PMP_R | PMP_W | PMP_X)) + if (reg->flags & SBI_DOMAIN_MEMREGION_EXECUTABLE) continue; - fdt_resv_memory_update_node(fdt, addr, size, j, parent, false); - j++; + addr = reg->base; + size = 1UL << reg->order; + fdt_resv_memory_update_node(fdt, addr, size, i, parent, + (sbi_hart_pmp_count(scratch)) ? false : true); + i++; } return 0; -- cgit v1.2.3