summaryrefslogtreecommitdiff
path: root/arch/x86/cpu/efi/payload.c
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2018-08-30 10:06:11 -0400
committerTom Rini <trini@konsulko.com>2018-08-30 10:06:11 -0400
commit284d201b4d9c17bc92044f825ce44550d66841cd (patch)
treefaf0b2bf48357077da5c5cd3cde2b66d7ea508da /arch/x86/cpu/efi/payload.c
parent11ed312896c5f5814064c5d45dcb2f53dc121437 (diff)
parente69cc6bc42c37598e2fdda421360be6cbc0470fd (diff)
Merge git://git.denx.de/u-boot-x86
Diffstat (limited to 'arch/x86/cpu/efi/payload.c')
-rw-r--r--arch/x86/cpu/efi/payload.c119
1 files changed, 119 insertions, 0 deletions
diff --git a/arch/x86/cpu/efi/payload.c b/arch/x86/cpu/efi/payload.c
index 4649bfe86e..c323c7b19a 100644
--- a/arch/x86/cpu/efi/payload.c
+++ b/arch/x86/cpu/efi/payload.c
@@ -8,6 +8,8 @@
#include <efi.h>
#include <errno.h>
#include <usb.h>
+#include <asm/bootparam.h>
+#include <asm/e820.h>
#include <asm/post.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -168,3 +170,120 @@ int last_stage_init(void)
return 0;
}
+
+unsigned int install_e820_map(unsigned int max_entries,
+ struct e820_entry *entries)
+{
+ struct efi_mem_desc *desc, *end;
+ struct efi_entry_memmap *map;
+ int size, ret;
+ efi_physical_addr_t last_end_addr = 0;
+ struct e820_entry *last_entry = NULL;
+ __u32 e820_type;
+ unsigned int num_entries = 0;
+
+ ret = efi_info_get(EFIET_MEMORY_MAP, (void **)&map, &size);
+ if (ret) {
+ printf("Cannot find EFI memory map tables, ret=%d\n", ret);
+
+ return -ENODEV;
+ }
+
+ end = (struct efi_mem_desc *)((ulong)map + size);
+ for (desc = map->desc; desc < end;
+ desc = efi_get_next_mem_desc(map, desc)) {
+ if (desc->num_pages == 0)
+ continue;
+
+ switch (desc->type) {
+ case EFI_LOADER_CODE:
+ case EFI_LOADER_DATA:
+ case EFI_BOOT_SERVICES_CODE:
+ case EFI_BOOT_SERVICES_DATA:
+ case EFI_CONVENTIONAL_MEMORY:
+ e820_type = E820_RAM;
+ break;
+
+ case EFI_RESERVED_MEMORY_TYPE:
+ case EFI_RUNTIME_SERVICES_CODE:
+ case EFI_RUNTIME_SERVICES_DATA:
+ case EFI_MMAP_IO:
+ case EFI_MMAP_IO_PORT:
+ case EFI_PAL_CODE:
+ e820_type = E820_RESERVED;
+ break;
+
+ case EFI_ACPI_RECLAIM_MEMORY:
+ e820_type = E820_ACPI;
+ break;
+
+ case EFI_ACPI_MEMORY_NVS:
+ e820_type = E820_NVS;
+ break;
+
+ case EFI_UNUSABLE_MEMORY:
+ e820_type = E820_UNUSABLE;
+ break;
+
+ default:
+ printf("Invalid EFI memory descriptor type (0x%x)!\n",
+ desc->type);
+ continue;
+ }
+
+ if (last_entry != NULL && last_entry->type == e820_type &&
+ desc->physical_start == last_end_addr) {
+ last_entry->size += (desc->num_pages << EFI_PAGE_SHIFT);
+ last_end_addr += (desc->num_pages << EFI_PAGE_SHIFT);
+ } else {
+ if (num_entries >= E820MAX)
+ break;
+
+ entries[num_entries].addr = desc->physical_start;
+ entries[num_entries].size = desc->num_pages;
+ entries[num_entries].size <<= EFI_PAGE_SHIFT;
+ entries[num_entries].type = e820_type;
+ last_entry = &entries[num_entries];
+ last_end_addr = last_entry->addr + last_entry->size;
+ num_entries++;
+ }
+ }
+
+ return num_entries;
+}
+
+void setup_efi_info(struct efi_info *efi_info)
+{
+ struct efi_entry_systable *table;
+ struct efi_entry_memmap *map;
+ char *signature;
+ int size, ret;
+
+ memset(efi_info, 0, sizeof(struct efi_info));
+
+ ret = efi_info_get(EFIET_SYS_TABLE, (void **)&table, &size);
+ if (ret) {
+ printf("Cannot find EFI system table, ret=%d\n", ret);
+ return;
+ }
+ efi_info->efi_systab = (u32)(table->sys_table);
+
+ ret = efi_info_get(EFIET_MEMORY_MAP, (void **)&map, &size);
+ if (ret) {
+ printf("Cannot find EFI memory map tables, ret=%d\n", ret);
+ return;
+ }
+ efi_info->efi_memdesc_size = map->desc_size;
+ efi_info->efi_memdesc_version = map->version;
+ efi_info->efi_memmap = (u32)(map->desc);
+ efi_info->efi_memmap_size = size - sizeof(struct efi_entry_memmap);
+
+#ifdef CONFIG_EFI_STUB_64BIT
+ efi_info->efi_systab_hi = table->sys_table >> 32;
+ efi_info->efi_memmap_hi = (u64)(u32)(map->desc) >> 32;
+ signature = EFI64_LOADER_SIGNATURE;
+#else
+ signature = EFI32_LOADER_SIGNATURE;
+#endif
+ memcpy(&efi_info->efi_loader_signature, signature, 4);
+}