efi-stub: reserve unconfigure high memory

Now ACRN support more and more platforms. However, the default configuration only
support board which memory is less than 16 GB. If a board memory is large than
16 GB, the developer needs to configure the memory configuration according to his
board. Otherwise, the boot will fail. This's because UEFI BIOS will use the high
memory as possible.
This patch try to allocate the memory as eraly as possible. So that the BIOS will
not access this region.

Tracked-On: #4007
Signed-off-by: Li Fei1 <fei1.li@intel.com>
This commit is contained in:
Li Fei1 2019-11-05 18:51:32 +08:00 committed by wenlingz
parent 8189d1f01c
commit af886fee8c

View File

@ -347,6 +347,53 @@ static inline EFI_STATUS isspace(CHAR8 ch)
return ((uint8_t)ch <= ' ');
}
EFI_STATUS reserve_unconfigure_high_memory(void)
{
#define PLATFORM_LO_MMIO_SIZE 0x80000000UL
UINTN map_size, map_key, desc_size;
EFI_MEMORY_DESCRIPTOR *map_buf;
UINTN d, map_end;
UINTN i;
UINT32 desc_version;
EFI_STATUS err;
UINT64 reserved_hpa;
EFI_PHYSICAL_ADDRESS top_addr_space = CONFIG_PLATFORM_RAM_SIZE + PLATFORM_LO_MMIO_SIZE;
err = memory_map(&map_buf, &map_size, &map_key, &desc_size, &desc_version);
if (err != EFI_SUCCESS)
goto fail;
d = (UINTN)map_buf;
map_end = (UINTN)map_buf + map_size;
for (i = 0; d < map_end; d += desc_size, i++) {
EFI_MEMORY_DESCRIPTOR *desc;
EFI_PHYSICAL_ADDRESS start, end;
desc = (EFI_MEMORY_DESCRIPTOR *)d;
if (desc->Type != EfiConventionalMemory)
continue;
start = desc->PhysicalStart;
end = start + (desc->NumberOfPages << EFI_PAGE_SHIFT);
if (end > top_addr_space) {
if (start < top_addr_space)
start = top_addr_space;
err = emalloc_fixed_addr(&reserved_hpa, end - start, start);
Print(L"memory region (%lx, %lx) is truncated from region (%lx, %lx).",
start, end, desc->PhysicalStart, end);
if (err != EFI_SUCCESS)
break;
}
}
free_pool(map_buf);
fail:
return err;
}
#define DEFAULT_UEFI_OS_LOADER_NAME L"\\EFI\\org.clearlinux\\bootloaderx64.efi"
/**
* efi_main - The entry point for the OS loader image.
@ -423,6 +470,12 @@ efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *_table)
goto free_args;
}
err = reserve_unconfigure_high_memory();
if (err != EFI_SUCCESS) {
Print(L"Unable to reserve un-configure high memory %r ", err);
goto free_args;
}
/* without relocateion enabled, hypervisor binary need to reside in
* fixed memory address starting from CONFIG_HV_RAM_START, make a call
* to emalloc_fixed_addr for that case. With CONFIG_RELOC enabled,