Remove emalloc_for_low_mem() routine in EFI boot code of HV

CPU boot binary need to reside in the memory below 1MB. UEFI firmware
does provide that functionality to limit the highest physical addr of
allocated memory. we just call the right UEFI API and no longer do it
in EFI stub code.

Tracked-On:#1260
Signed-off-by: Chaohong Guo <chaohong.guo@intel.com>
Reviewed-by: Jason Chen <jason.cj.chen@intel.com>
Acked-by: Gen Zheng <gen.zheng@intel.com>
Reviewed-by: Anthony Xu <Anthony.Xu@intel.com>
This commit is contained in:
Chaohong guo 2018-09-17 13:21:58 +08:00 committed by lijinxia
parent ccf562402e
commit fea102ea69
4 changed files with 21 additions and 61 deletions

View File

@ -224,9 +224,11 @@ switch_to_guest_mode(EFI_HANDLE image)
efi_ctx = (struct boot_ctx *)(UINTN)addr;
/* reserve secondary memory region for hv */
err = emalloc_for_low_mem(&addr, CONFIG_LOW_RAM_SIZE);
err = emalloc_reserved_mem(&addr, CONFIG_LOW_RAM_SIZE, MEM_ADDR_1MB);
if (err != EFI_SUCCESS)
goto out;
if (addr < 4096)
Print(L"Warning: CPU trampoline code buf occupied zero-page\n");
efi_ctx->ap_trampoline_buf = (void *)addr;

View File

@ -45,6 +45,8 @@
#define EFILINUX_VERSION_MAJOR 1
#define EFILINUX_VERSION_MINOR 0
#define MEM_ADDR_1MB (1 << 20)
extern EFI_SYSTEM_TABLE *sys_table;
extern EFI_BOOT_SERVICES *boot;
@ -184,6 +186,22 @@ handle_protocol(EFI_HANDLE handle, EFI_GUID *protocol, void **interface)
}
/*
* emalloc_reserved_mem - it is called to allocate memory hypervisor itself
* and trampoline code, and mark the allocate memory as EfiReserved memory
* type so that SOS won't touch it during boot.
* @addr: a pointer to the allocated address on success
* @size: size in bytes of the requested allocation
* @max_addr: the allocated memory must be no more than this threshold
*/
static inline EFI_STATUS emalloc_reserved_mem(EFI_PHYSICAL_ADDRESS *addr,
UINTN size, EFI_PHYSICAL_ADDRESS max_addr)
{
*addr = max_addr;
return allocate_pages(AllocateMaxAddress, EfiReservedMemoryType,
EFI_SIZE_TO_PAGES(size), addr);
}
/**
* exit - Terminate a loaded EFI image
* @image: firmware-allocated handle that identifies the image

View File

@ -164,65 +164,6 @@ fail:
return err;
}
EFI_STATUS emalloc_for_low_mem(EFI_PHYSICAL_ADDRESS *addr, UINTN size)
{
UINTN map_size, map_key, desc_size;
EFI_MEMORY_DESCRIPTOR *map_buf;
UINTN d, map_end;
UINT32 desc_version;
EFI_STATUS err;
UINTN nr_pages = EFI_SIZE_TO_PAGES(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 (; d < map_end; d += desc_size) {
EFI_MEMORY_DESCRIPTOR *desc;
EFI_PHYSICAL_ADDRESS start, end, aligned;
desc = (EFI_MEMORY_DESCRIPTOR *)d;
if (desc->Type != EfiConventionalMemory)
continue;
if (desc->NumberOfPages < nr_pages)
continue;
start = desc->PhysicalStart;
end = start + (desc->NumberOfPages << EFI_PAGE_SHIFT);
size = nr_pages << EFI_PAGE_SHIFT;
/* allocate in low memory only */
if (start >= 1 << 20)
continue;
if (end > 1 << 20)
end = (1 << 20);
if (end - start >= size) {
aligned = end - size;
err = allocate_pages(AllocateAddress, EfiReservedMemoryType,
nr_pages, &aligned);
if (err == EFI_SUCCESS) {
*addr = aligned;
break;
}
}
}
if (d == map_end)
err = EFI_OUT_OF_RESOURCES;
free_pool(map_buf);
fail:
return err;
}
EFI_STATUS __emalloc(UINTN size, UINTN min_addr, EFI_PHYSICAL_ADDRESS *addr,
EFI_MEMORY_TYPE mem_type)
{

View File

@ -50,7 +50,6 @@ extern void *calloc(UINTN nmemb, UINTN size);
extern EFI_STATUS emalloc(UINTN, UINTN, EFI_PHYSICAL_ADDRESS *);
extern EFI_STATUS __emalloc(UINTN, UINTN, EFI_PHYSICAL_ADDRESS *, EFI_MEMORY_TYPE);
extern EFI_STATUS emalloc_for_low_mem(EFI_PHYSICAL_ADDRESS *addr, UINTN size);
extern void efree(EFI_PHYSICAL_ADDRESS, UINTN);
static inline void memset(void *dstv, char ch, UINTN size)