mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-09-21 08:50:27 +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:
@@ -341,6 +341,54 @@ int prepare_vm0_memmap_and_e820(struct vm *vm)
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint64_t e820_alloc_low_memory(uint32_t size)
|
||||
{
|
||||
uint32_t i;
|
||||
struct e820_entry *entry, *new_entry;
|
||||
|
||||
/* We want memory in page boundary and want integral multiple of pages */
|
||||
size = ROUND_PAGE_UP(size);
|
||||
|
||||
for (i = 0; i < e820_entries; i++) {
|
||||
entry = &e820[i];
|
||||
uint64_t start, end, length;
|
||||
|
||||
start = ROUND_PAGE_UP(entry->baseaddr);
|
||||
end = ROUND_PAGE_DOWN(entry->baseaddr + entry->length);
|
||||
length = end - start;
|
||||
length = (end > start) ? (end - start) : 0;
|
||||
|
||||
if ((entry->type != E820_TYPE_RAM)
|
||||
|| (length < size)
|
||||
|| (start >= MEM_1M)
|
||||
|| (start + size > MEM_1M)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Found available memory */
|
||||
e820_mem.total_mem_size -= size;
|
||||
|
||||
/* found exact size of e820 entry */
|
||||
if (length == size) {
|
||||
entry->type = E820_TYPE_RESERVED;
|
||||
return start;
|
||||
}
|
||||
|
||||
/* create a new entry for the allocated memory */
|
||||
new_entry = &e820[e820_entries];
|
||||
new_entry->type = E820_TYPE_RESERVED;
|
||||
new_entry->baseaddr = end - size;
|
||||
new_entry->length = entry->baseaddr + entry->length - new_entry->baseaddr;
|
||||
entry->length -= new_entry->length;
|
||||
e820_entries++;
|
||||
|
||||
return new_entry->baseaddr;
|
||||
}
|
||||
|
||||
pr_fatal("Can't allocate memory under 1M from E820\n");
|
||||
return ACRN_INVALID_HPA;
|
||||
}
|
||||
|
||||
/*******************************************************************
|
||||
* GUEST initial page table
|
||||
*
|
||||
|
Reference in New Issue
Block a user