summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2023-01-07 12:32:42 -0500
committerTom Rini <trini@konsulko.com>2023-01-07 12:32:42 -0500
commitbe914b00df4aeb6c115b412313f31daedab75fb5 (patch)
treeb300b0210942482ba87e61b14e20ea8199fcaed6 /lib
parent9ddcdcc03cc6f0f46895604c589af17fdbdfe8b7 (diff)
parent4bba71ff83e2b2a1607c5b3b9995767691242b29 (diff)
Merge tag 'efi-2023-01-rc5-4' of https://source.denx.de/u-boot/custodians/u-boot-efi
Pull request efi-2023-01-rc5-4 UEFI: * correct the vexpress loaddr which collides with memory used by EFI * consider the EFI memory map for LMB memory reservation * avoid RWX section warnings for .data section of *_efi.so files
Diffstat (limited to 'lib')
-rw-r--r--lib/efi_loader/efi_memory.c34
-rw-r--r--lib/lmb.c36
2 files changed, 70 insertions, 0 deletions
diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c
index 8d347f101f3..32254d24337 100644
--- a/lib/efi_loader/efi_memory.c
+++ b/lib/efi_loader/efi_memory.c
@@ -737,6 +737,40 @@ efi_status_t efi_get_memory_map(efi_uintn_t *memory_map_size,
}
/**
+ * efi_get_memory_map_alloc() - allocate map describing memory usage
+ *
+ * The caller is responsible for calling FreePool() if the call succeeds.
+ *
+ * @memory_map buffer to which the memory map is written
+ * @map_size size of the memory map
+ * Return: status code
+ */
+efi_status_t efi_get_memory_map_alloc(efi_uintn_t *map_size,
+ struct efi_mem_desc **memory_map)
+{
+ efi_status_t ret;
+
+ *memory_map = NULL;
+ *map_size = 0;
+ ret = efi_get_memory_map(map_size, *memory_map, NULL, NULL, NULL);
+ if (ret == EFI_BUFFER_TOO_SMALL) {
+ *map_size += sizeof(struct efi_mem_desc); /* for the map */
+ ret = efi_allocate_pool(EFI_BOOT_SERVICES_DATA, *map_size,
+ (void **)memory_map);
+ if (ret != EFI_SUCCESS)
+ return ret;
+ ret = efi_get_memory_map(map_size, *memory_map,
+ NULL, NULL, NULL);
+ if (ret != EFI_SUCCESS) {
+ efi_free_pool(*memory_map);
+ *memory_map = NULL;
+ }
+ }
+
+ return ret;
+}
+
+/**
* efi_add_conventional_memory_map() - add a RAM memory area to the map
*
* @ram_start: start address of a RAM memory area
diff --git a/lib/lmb.c b/lib/lmb.c
index c599608fa38..ec790760db6 100644
--- a/lib/lmb.c
+++ b/lib/lmb.c
@@ -7,7 +7,9 @@
*/
#include <common.h>
+#include <efi_loader.h>
#include <image.h>
+#include <mapmem.h>
#include <lmb.h>
#include <log.h>
#include <malloc.h>
@@ -153,6 +155,37 @@ void arch_lmb_reserve_generic(struct lmb *lmb, ulong sp, ulong end, ulong align)
}
}
+/**
+ * efi_lmb_reserve() - add reservations for EFI memory
+ *
+ * Add reservations for all EFI memory areas that are not
+ * EFI_CONVENTIONAL_MEMORY.
+ *
+ * @lmb: lmb environment
+ * Return: 0 on success, 1 on failure
+ */
+static __maybe_unused int efi_lmb_reserve(struct lmb *lmb)
+{
+ struct efi_mem_desc *memmap = NULL, *map;
+ efi_uintn_t i, map_size = 0;
+ efi_status_t ret;
+
+ ret = efi_get_memory_map_alloc(&map_size, &memmap);
+ if (ret != EFI_SUCCESS)
+ return 1;
+
+ for (i = 0, map = memmap; i < map_size / sizeof(*map); ++map, ++i) {
+ if (map->type != EFI_CONVENTIONAL_MEMORY)
+ lmb_reserve(lmb,
+ map_to_sysmem((void *)(uintptr_t)
+ map->physical_start),
+ map->num_pages * EFI_PAGE_SIZE);
+ }
+ efi_free_pool(memmap);
+
+ return 0;
+}
+
static void lmb_reserve_common(struct lmb *lmb, void *fdt_blob)
{
arch_lmb_reserve(lmb);
@@ -160,6 +193,9 @@ static void lmb_reserve_common(struct lmb *lmb, void *fdt_blob)
if (CONFIG_IS_ENABLED(OF_LIBFDT) && fdt_blob)
boot_fdt_add_mem_rsv_regions(lmb, fdt_blob);
+
+ if (CONFIG_IS_ENABLED(EFI_LOADER))
+ efi_lmb_reserve(lmb);
}
/* Initialize the struct, add memory and call arch/board reserve functions */