mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2025-08-24 15:31:22 +01:00
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 <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include <libfdt.h>
|
#include <libfdt.h>
|
||||||
#include <sbi/sbi_console.h>
|
#include <sbi/sbi_console.h>
|
||||||
|
#include <sbi/sbi_domain.h>
|
||||||
#include <sbi/sbi_math.h>
|
#include <sbi/sbi_math.h>
|
||||||
#include <sbi/sbi_hart.h>
|
#include <sbi/sbi_hart.h>
|
||||||
#include <sbi/sbi_platform.h>
|
#include <sbi/sbi_platform.h>
|
||||||
@@ -97,11 +98,11 @@ static int fdt_resv_memory_update_node(void *fdt, unsigned long addr,
|
|||||||
|
|
||||||
if (na > 1 && addr_high)
|
if (na > 1 && addr_high)
|
||||||
sbi_snprintf(name, sizeof(name),
|
sbi_snprintf(name, sizeof(name),
|
||||||
"mmode_pmp%d@%x,%x", index,
|
"mmode_resv%d@%x,%x", index,
|
||||||
addr_high, addr_low);
|
addr_high, addr_low);
|
||||||
else
|
else
|
||||||
sbi_snprintf(name, sizeof(name),
|
sbi_snprintf(name, sizeof(name),
|
||||||
"mmode_pmp%d@%x", index,
|
"mmode_resv%d@%x", index,
|
||||||
addr_low);
|
addr_low);
|
||||||
|
|
||||||
subnode = fdt_add_subnode(fdt, parent, name);
|
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)
|
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();
|
struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
|
||||||
unsigned long prot, addr, size;
|
unsigned long addr, size;
|
||||||
int parent, i, j;
|
int err, parent, i;
|
||||||
int err;
|
|
||||||
int na = fdt_address_cells(fdt, 0);
|
int na = fdt_address_cells(fdt, 0);
|
||||||
int ns = fdt_size_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
|
* We assume the given device tree does not contain any memory region
|
||||||
* child node protected by PMP. Normally PMP programming happens at
|
* child node protected by PMP. Normally PMP programming happens at
|
||||||
* M-mode firmware. The memory space used by OpenSBI is protected.
|
* 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.
|
* With above assumption, we create child nodes directly.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!sbi_hart_pmp_count(scratch)) {
|
i = 0;
|
||||||
/*
|
sbi_domain_for_each_memregion(dom, reg) {
|
||||||
* Update the DT with firmware start & size even if PMP is not
|
/* Ignore MMIO or READABLE or WRITABLE or EXECUTABLE regions */
|
||||||
* supported. This makes sure that supervisor OS is always
|
if (reg->flags & SBI_DOMAIN_MEMREGION_MMIO)
|
||||||
* 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)
|
|
||||||
continue;
|
continue;
|
||||||
if (!(prot & PMP_A))
|
if (reg->flags & SBI_DOMAIN_MEMREGION_READABLE)
|
||||||
continue;
|
continue;
|
||||||
if (prot & (PMP_R | PMP_W | PMP_X))
|
if (reg->flags & SBI_DOMAIN_MEMREGION_WRITEABLE)
|
||||||
|
continue;
|
||||||
|
if (reg->flags & SBI_DOMAIN_MEMREGION_EXECUTABLE)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
fdt_resv_memory_update_node(fdt, addr, size, j, parent, false);
|
addr = reg->base;
|
||||||
j++;
|
size = 1UL << reg->order;
|
||||||
|
fdt_resv_memory_update_node(fdt, addr, size, i, parent,
|
||||||
|
(sbi_hart_pmp_count(scratch)) ? false : true);
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Reference in New Issue
Block a user