mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-09-22 17:27:53 +00:00
HV: added memory allocation functions for AP trampoline code relocation
V2->V3: Fixed the booting issue on MRB board and removed the restriction of allocate memory from address 0 1) Fix the booting from MRB issue -#define CONFIG_LOW_RAM_SIZE 0x000CF000 +#define CONFIG_LOW_RAM_SIZE 0x00010000 2) changed e820_alloc_low_memory() to handle corner case of unaligned e820 entries and enable it to allocate memory at address 0 + a length = end > start ? (end - start) : 0; - /* We don't want the first page */ - if ((length == size) && (start == 0)) - continue; 3) changed emalloc_for_low_mem() to enable to allocate memory at address 0 - /* We don't want the first page */ - if (start == 0) - start = EFI_PAGE_SIZE; V1->V2: moved e820_alloc_low_memory() to guest.c and added the logic to handle unaligned E820 entries emalloc_for_low_mem() is used if CONFIG_EFI_STUB is defined. e820_alloc_low_memory() is used for other cases In either case, the allocated memory will be marked with E820_TYPE_RESERVED Signed-off-by: Zheng, Gen <gen.zheng@intel.com> Signed-off-by: Jason Chen CJ <jason.cj.chen@intel.com> Signed-off-by: Zide Chen <zide.chen@intel.com> Acked-by: Eddie Dong <eddie.dong> Acked-by: Xu, Anthony <anthony.xu@intel.com>
This commit is contained in:
@@ -41,7 +41,7 @@
|
||||
#define HEAP_SIZE 0x100000
|
||||
#define CONSOLE_LOGLEVEL_DEFAULT 2
|
||||
#define MEM_LOGLEVEL_DEFAULT 4
|
||||
#define CONFIG_LOW_RAM_SIZE 0x000CF000
|
||||
#define CONFIG_LOW_RAM_SIZE 0x00010000
|
||||
#define CONFIG_RAM_START 0x6E000000
|
||||
#define CONFIG_RAM_SIZE 0x02000000 /* 32M */
|
||||
#define CONFIG_CMA
|
||||
|
@@ -164,6 +164,67 @@ 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 = (size + EFI_PAGE_SIZE - 1) & ~(EFI_PAGE_SIZE - 1);
|
||||
|
||||
/* allocate in low memory only */
|
||||
if (start >= 1 << 20)
|
||||
continue;
|
||||
|
||||
if (end > 1 << 20) {
|
||||
size -= 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;
|
||||
}
|
||||
|
||||
/* FIXME: This function cannot guarantee to return address under 4G,
|
||||
* and the hypervisor cannot handle params, which address is above 4G,
|
||||
* delivered from efi stub.
|
||||
|
@@ -50,6 +50,7 @@ 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)
|
||||
|
Reference in New Issue
Block a user