efi_loader: consider no-map property of reserved memory

The device tree may contain a /reserved-memory node. The no-map property
of the sub-nodes signals if the memory may be accessed by the UEFI payload
or not.

In the EBBR specification (https://github.com/arm-software/ebbr) the
modeling of the reserved memory has been clarified.

If a reserved memory node in the device tree has the no-map property map,
create a EfiReservedMemoryType memory map entry else use
EfiBootServicesData.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
This commit is contained in:
Heinrich Schuchardt 2020-08-27 12:52:20 +02:00
parent 4b71f6dc4e
commit 4cbb2930bd
1 changed files with 28 additions and 6 deletions

View File

@ -135,12 +135,29 @@ done:
return ret;
}
static void efi_reserve_memory(u64 addr, u64 size)
/**
* efi_reserve_memory() - add reserved memory to memory map
*
* @addr: start address of the reserved memory range
* @size: size of the reserved memory range
* @nomap: indicates that the memory range shall not be accessed by the
* UEFI payload
*/
static void efi_reserve_memory(u64 addr, u64 size, bool nomap)
{
int type;
efi_uintn_t ret;
/* Convert from sandbox address space. */
addr = (uintptr_t)map_sysmem(addr, 0);
if (efi_add_memory_map(addr, size,
EFI_RESERVED_MEMORY_TYPE) != EFI_SUCCESS)
if (nomap)
type = EFI_RESERVED_MEMORY_TYPE;
else
type = EFI_BOOT_SERVICES_DATA;
ret = efi_add_memory_map(addr, size, type);
if (ret != EFI_SUCCESS)
log_err("Reserved memory mapping failed addr %llx size %llx\n",
addr, size);
}
@ -166,7 +183,7 @@ static void efi_carve_out_dt_rsv(void *fdt)
for (i = 0; i < nr_rsv; i++) {
if (fdt_get_mem_rsv(fdt, i, &addr, &size) != 0)
continue;
efi_reserve_memory(addr, size);
efi_reserve_memory(addr, size, false);
}
/* process reserved-memory */
@ -186,8 +203,13 @@ static void efi_carve_out_dt_rsv(void *fdt)
* a size instead of a reg property.
*/
if (fdt_addr != FDT_ADDR_T_NONE &&
fdtdec_get_is_enabled(fdt, subnode))
efi_reserve_memory(fdt_addr, fdt_size);
fdtdec_get_is_enabled(fdt, subnode)) {
bool nomap;
nomap = !!fdt_getprop(fdt, subnode, "no-map",
NULL);
efi_reserve_memory(fdt_addr, fdt_size, nomap);
}
subnode = fdt_next_subnode(fdt, subnode);
}
}