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;
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;
}
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.
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;
/**
* 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;
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;
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;
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);
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;
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;
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)