+// SPDX-License-Identifier: GPL-2.0+
/*
* EFI application memory management
*
* Copyright (c) 2016 Alexander Graf
- *
- * SPDX-License-Identifier: GPL-2.0+
*/
#include <common.h>
#include <efi_loader.h>
-#include <malloc.h>
-#include <asm/global_data.h>
-#include <linux/libfdt_env.h>
-#include <linux/list_sort.h>
#include <inttypes.h>
+#include <malloc.h>
#include <watchdog.h>
+#include <linux/list_sort.h>
DECLARE_GLOBAL_DATA_PTR;
list_sort(NULL, &efi_mem, efi_mem_cmp);
}
-/*
- * Unmaps all memory occupied by the carve_desc region from the
- * list entry pointed to by map.
+/** efi_mem_carve_out - unmap memory region
+ *
+ * @map: memory map
+ * @carve_desc: memory region to unmap
+ * @overlap_only_ram: the carved out region may only overlap RAM
+ * Return Value: the number of overlapping pages which have been
+ * removed from the map,
+ * EFI_CARVE_NO_OVERLAP, if the regions don't overlap,
+ * EFI_CARVE_OVERLAPS_NONRAM, if the carve and map overlap,
+ * and the map contains anything but free ram
+ * (only when overlap_only_ram is true),
+ * EFI_CARVE_LOOP_AGAIN, if the mapping list should be
+ * traversed again, as it has been altered.
*
- * Returns EFI_CARVE_NO_OVERLAP if the regions don't overlap.
- * Returns EFI_CARVE_OVERLAPS_NONRAM if the carve and map overlap,
- * and the map contains anything but free ram.
- * (only when overlap_only_ram is true)
- * Returns EFI_CARVE_LOOP_AGAIN if the mapping list should be traversed
- * again, as it has been altered
- * Returns the number of overlapping pages. The pages are removed from
- * the mapping list.
+ * Unmaps all memory occupied by the carve_desc region from the list entry
+ * pointed to by map.
*
* In case of EFI_CARVE_OVERLAPS_NONRAM it is the callers responsibility
- * to readd the already carved out pages to the mapping.
+ * to re-add the already carved out pages to the mapping.
*/
-static int efi_mem_carve_out(struct efi_mem_list *map,
+static s64 efi_mem_carve_out(struct efi_mem_list *map,
struct efi_mem_desc *carve_desc,
bool overlap_only_ram)
{
carve_again = false;
list_for_each(lhandle, &efi_mem) {
struct efi_mem_list *lmem;
- int r;
+ s64 r;
lmem = list_entry(lhandle, struct efi_mem_list, link);
r = efi_mem_carve_out(lmem, &newlist->desc,
uint64_t addr;
switch (type) {
- case 0:
+ case EFI_ALLOCATE_ANY_PAGES:
/* Any page */
addr = efi_find_free_memory(len, gd->start_addr_sp);
if (!addr) {
break;
}
break;
- case 1:
+ case EFI_ALLOCATE_MAX_ADDRESS:
/* Max address */
addr = efi_find_free_memory(len, *memory);
if (!addr) {
break;
}
break;
- case 2:
+ case EFI_ALLOCATE_ADDRESS:
/* Exact address, reserve it. The addr is already in *memory. */
addr = *memory;
break;
uint64_t pages = (len + EFI_PAGE_MASK) >> EFI_PAGE_SHIFT;
efi_status_t r;
- r = efi_allocate_pages(0, memory_type, pages, &ret);
+ r = efi_allocate_pages(EFI_ALLOCATE_ANY_PAGES, memory_type, pages,
+ &ret);
if (r == EFI_SUCCESS)
return (void*)(uintptr_t)ret;
return EFI_SUCCESS;
}
- r = efi_allocate_pages(0, pool_type, num_pages, &t);
+ r = efi_allocate_pages(EFI_ALLOCATE_ANY_PAGES, pool_type, num_pages,
+ &t);
if (r == EFI_SUCCESS) {
struct efi_pool_allocation *alloc = (void *)(uintptr_t)t;
/* Request a 32bit 64MB bounce buffer region */
uint64_t efi_bounce_buffer_addr = 0xffffffff;
- if (efi_allocate_pages(1, EFI_LOADER_DATA,
+ if (efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS, EFI_LOADER_DATA,
(64 * 1024 * 1024) >> EFI_PAGE_SHIFT,
&efi_bounce_buffer_addr) != EFI_SUCCESS)
return -1;