x86: efi: Update efi_get_next_mem_desc() to avoid needing a map
At present this function requires a pointer to struct efi_entry_memmap
but the only field used in there is the desc_size. We want to be able
to use it from the app, so update it to use desc_size directly.
Signed-off-by: Simon Glass <sjg@chromium.org>
diff --git a/arch/x86/cpu/efi/payload.c b/arch/x86/cpu/efi/payload.c
index 04ce188..b777856 100644
--- a/arch/x86/cpu/efi/payload.c
+++ b/arch/x86/cpu/efi/payload.c
@@ -51,7 +51,7 @@
end = (struct efi_mem_desc *)((ulong)map + size);
desc = map->desc;
- for (; desc < end; desc = efi_get_next_mem_desc(map, desc)) {
+ for (; desc < end; desc = efi_get_next_mem_desc(desc, map->desc_size)) {
if (desc->type != EFI_CONVENTIONAL_MEMORY ||
desc->physical_start >= 1ULL << 32)
continue;
@@ -89,7 +89,7 @@
end = (struct efi_mem_desc *)((ulong)map + size);
gd->ram_size = 0;
desc = map->desc;
- for (; desc < end; desc = efi_get_next_mem_desc(map, desc)) {
+ for (; desc < end; desc = efi_get_next_mem_desc(desc, map->desc_size)) {
if (desc->type < EFI_MMAP_IO)
gd->ram_size += desc->num_pages << EFI_PAGE_SHIFT;
}
@@ -114,7 +114,7 @@
desc = map->desc;
for (num_banks = 0;
desc < end && num_banks < CONFIG_NR_DRAM_BANKS;
- desc = efi_get_next_mem_desc(map, desc)) {
+ desc = efi_get_next_mem_desc(desc, map->desc_size)) {
/*
* We only use conventional memory and ignore
* anything less than 1MB.
@@ -197,7 +197,7 @@
end = (struct efi_mem_desc *)((ulong)map + size);
for (desc = map->desc; desc < end;
- desc = efi_get_next_mem_desc(map, desc)) {
+ desc = efi_get_next_mem_desc(desc, map->desc_size)) {
if (desc->num_pages == 0)
continue;
diff --git a/cmd/efi.c b/cmd/efi.c
index f2ed26b..d2400ac 100644
--- a/cmd/efi.c
+++ b/cmd/efi.c
@@ -75,16 +75,17 @@
/**
* efi_build_mem_table() - make a sorted copy of the memory table
*
- * @map: Pointer to EFI memory map table
+ * @desc_base: Pointer to EFI memory map table
* @size: Size of table in bytes
+ * @desc_size: Size of each @desc_base record
* @skip_bs: True to skip boot-time memory and merge it with conventional
* memory. This will significantly reduce the number of table
* entries.
* Return: pointer to the new table. It should be freed with free() by the
* caller.
*/
-static void *efi_build_mem_table(struct efi_entry_memmap *map, int size,
- bool skip_bs)
+static void *efi_build_mem_table(struct efi_mem_desc *desc_base, int size,
+ int desc_size, bool skip_bs)
{
struct efi_mem_desc *desc, *end, *base, *dest, *prev;
int count;
@@ -95,15 +96,16 @@
debug("%s: Cannot allocate %#x bytes\n", __func__, size);
return NULL;
}
- end = (struct efi_mem_desc *)((ulong)map + size);
- count = ((ulong)end - (ulong)map->desc) / map->desc_size;
- memcpy(base, map->desc, (ulong)end - (ulong)map->desc);
- qsort(base, count, map->desc_size, h_cmp_entry);
+ end = (void *)desc_base + size;
+ count = ((ulong)end - (ulong)desc_base) / desc_size;
+ memcpy(base, desc_base, (ulong)end - (ulong)desc_base);
+ qsort(base, count, desc_size, h_cmp_entry);
prev = NULL;
addr = 0;
dest = base;
- end = (struct efi_mem_desc *)((ulong)base + count * map->desc_size);
- for (desc = base; desc < end; desc = efi_get_next_mem_desc(map, desc)) {
+ end = (struct efi_mem_desc *)((ulong)base + count * desc_size);
+ for (desc = base; desc < end;
+ desc = efi_get_next_mem_desc(desc, desc_size)) {
bool merge = true;
u32 type = desc->type;
@@ -116,7 +118,7 @@
if (skip_bs && is_boot_services(desc->type))
type = EFI_CONVENTIONAL_MEMORY;
- memcpy(dest, desc, map->desc_size);
+ memcpy(dest, desc, desc_size);
dest->type = type;
if (!skip_bs || !prev)
merge = false;
@@ -131,7 +133,7 @@
prev->num_pages += desc->num_pages;
} else {
prev = dest;
- dest = efi_get_next_mem_desc(map, dest);
+ dest = efi_get_next_mem_desc(dest, desc_size);
}
addr = desc->physical_start + (desc->num_pages <<
EFI_PAGE_SHIFT);
@@ -143,8 +145,8 @@
return base;
}
-static void efi_print_mem_table(struct efi_entry_memmap *map,
- struct efi_mem_desc *desc, bool skip_bs)
+static void efi_print_mem_table(struct efi_mem_desc *desc, int desc_size,
+ bool skip_bs)
{
u64 attr_seen[ATTR_SEEN_MAX];
int attr_seen_count;
@@ -158,7 +160,7 @@
attr_seen_count = 0;
addr = 0;
for (upto = 0; desc->type != EFI_MAX_MEMORY_TYPE;
- upto++, desc = efi_get_next_mem_desc(map, desc)) {
+ upto++, desc = efi_get_next_mem_desc(desc, desc_size)) {
const char *name;
u64 size;
@@ -238,13 +240,13 @@
goto done;
}
- desc = efi_build_mem_table(map, size, skip_bs);
+ desc = efi_build_mem_table(map->desc, size, map->desc_size, skip_bs);
if (!desc) {
ret = -ENOMEM;
goto done;
}
- efi_print_mem_table(map, desc, skip_bs);
+ efi_print_mem_table(desc, map->desc_size, skip_bs);
free(desc);
done:
if (ret)
diff --git a/include/efi.h b/include/efi.h
index dc9907f..3508ff8 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -395,9 +395,9 @@
};
static inline struct efi_mem_desc *efi_get_next_mem_desc(
- struct efi_entry_memmap *map, struct efi_mem_desc *desc)
+ struct efi_mem_desc *desc, int desc_size)
{
- return (struct efi_mem_desc *)((ulong)desc + map->desc_size);
+ return (struct efi_mem_desc *)((ulong)desc + desc_size);
}
/**