diff options
author | Heinrich Schuchardt <heinrich.schuchardt@canonical.com> | 2023-01-05 18:26:01 +0100 |
---|---|---|
committer | Heinrich Schuchardt <heinrich.schuchardt@canonical.com> | 2023-01-06 22:27:30 +0100 |
commit | eff444019545642a844431692dd51829aa52528c (patch) | |
tree | e52a108d870a0313f4f24a7f2f6a9e4acdfcfcdf /lib | |
parent | f4af97cdb4b9d702bf7d76d896e3b6d13a162bb3 (diff) | |
download | u-boot-eff444019545642a844431692dd51829aa52528c.zip u-boot-eff444019545642a844431692dd51829aa52528c.tar.gz u-boot-eff444019545642a844431692dd51829aa52528c.tar.bz2 |
efi_loader: carve out efi_get_memory_map_alloc()
Carve out code from efidebug command used to read the memory map.
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/efi_loader/efi_memory.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c index 8d347f1..32254d2 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 |