mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-06-20 20:53:46 +00:00
HV: move create_sos_vm_e820 to ve820.c
ve820.c is a common file in arch/x86/guest/ now, so move function of create_sos_vm_e820() to this file to make code structure clear; Tracked-On: #4458 Signed-off-by: Victor Sun <victor.sun@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
parent
a7b61d2511
commit
e74553492a
@ -7,12 +7,117 @@
|
||||
#include <e820.h>
|
||||
#include <mmu.h>
|
||||
#include <vm.h>
|
||||
#include <reloc.h>
|
||||
#include <logmsg.h>
|
||||
|
||||
#define ENTRY_HPA1 2U
|
||||
#define ENTRY_HPA1_HI 4U
|
||||
|
||||
static struct e820_entry sos_vm_e820[E820_MAX_ENTRIES];
|
||||
static struct e820_entry pre_vm_e820[PRE_VM_NUM][E820_MAX_ENTRIES];
|
||||
|
||||
static void filter_mem_from_sos_e820(struct acrn_vm *vm, uint64_t start_pa, uint64_t end_pa)
|
||||
{
|
||||
uint32_t i;
|
||||
uint64_t entry_start;
|
||||
uint64_t entry_end;
|
||||
uint32_t entries_count = vm->e820_entry_num;
|
||||
struct e820_entry *entry, new_entry = {0};
|
||||
|
||||
for (i = 0U; i < entries_count; i++) {
|
||||
entry = &sos_vm_e820[i];
|
||||
entry_start = entry->baseaddr;
|
||||
entry_end = entry->baseaddr + entry->length;
|
||||
|
||||
/* No need handle in these cases*/
|
||||
if ((entry->type != E820_TYPE_RAM) || (entry_end <= start_pa) || (entry_start >= end_pa)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* filter out the specific memory and adjust length of this entry*/
|
||||
if ((entry_start < start_pa) && (entry_end <= end_pa)) {
|
||||
entry->length = start_pa - entry_start;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* filter out the specific memory and need to create a new entry*/
|
||||
if ((entry_start < start_pa) && (entry_end > end_pa)) {
|
||||
entry->length = start_pa - entry_start;
|
||||
new_entry.baseaddr = end_pa;
|
||||
new_entry.length = entry_end - end_pa;
|
||||
new_entry.type = E820_TYPE_RAM;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* This entry is within the range of specific memory
|
||||
* change to E820_TYPE_RESERVED
|
||||
*/
|
||||
if ((entry_start >= start_pa) && (entry_end <= end_pa)) {
|
||||
entry->type = E820_TYPE_RESERVED;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((entry_start >= start_pa) && (entry_start < end_pa) && (entry_end > end_pa)) {
|
||||
entry->baseaddr = end_pa;
|
||||
entry->length = entry_end - end_pa;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (new_entry.length > 0UL) {
|
||||
entries_count++;
|
||||
ASSERT(entries_count <= E820_MAX_ENTRIES, "e820 entry overflow");
|
||||
entry = &sos_vm_e820[entries_count - 1U];
|
||||
entry->baseaddr = new_entry.baseaddr;
|
||||
entry->length = new_entry.length;
|
||||
entry->type = new_entry.type;
|
||||
vm->e820_entry_num = entries_count;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* before boot sos_vm(service OS), call it to hide HV and prelaunched VM memory in e820 table from sos_vm
|
||||
*
|
||||
* @pre vm != NULL
|
||||
*/
|
||||
void create_sos_vm_e820(struct acrn_vm *vm)
|
||||
{
|
||||
uint16_t vm_id;
|
||||
uint64_t hv_start_pa = hva2hpa((void *)(get_hv_image_base()));
|
||||
uint64_t hv_end_pa = hv_start_pa + CONFIG_HV_RAM_SIZE;
|
||||
uint32_t entries_count = get_e820_entries_count();
|
||||
const struct mem_range *p_mem_range_info = get_mem_range_info();
|
||||
struct acrn_vm_config *sos_vm_config = get_vm_config(vm->vm_id);
|
||||
|
||||
(void)memcpy_s((void *)sos_vm_e820, entries_count * sizeof(struct e820_entry),
|
||||
(const void *)get_e820_entry(), entries_count * sizeof(struct e820_entry));
|
||||
|
||||
vm->e820_entry_num = entries_count;
|
||||
vm->e820_entries = sos_vm_e820;
|
||||
/* filter out hv memory from e820 table */
|
||||
filter_mem_from_sos_e820(vm, hv_start_pa, hv_end_pa);
|
||||
sos_vm_config->memory.size = p_mem_range_info->total_mem_size - CONFIG_HV_RAM_SIZE;
|
||||
|
||||
/* filter out prelaunched vm memory from e820 table */
|
||||
for (vm_id = 0U; vm_id < CONFIG_MAX_VM_NUM; vm_id++) {
|
||||
struct acrn_vm_config *vm_config = get_vm_config(vm_id);
|
||||
|
||||
if (vm_config->load_order == PRE_LAUNCHED_VM) {
|
||||
filter_mem_from_sos_e820(vm, vm_config->memory.start_hpa,
|
||||
vm_config->memory.start_hpa + vm_config->memory.size);
|
||||
sos_vm_config->memory.size -= vm_config->memory.size;
|
||||
|
||||
/* if HPA2 is available, filter it out as well*/
|
||||
if (vm_config->memory.size_hpa2 != 0UL) {
|
||||
filter_mem_from_sos_e820(vm, vm_config->memory.start_hpa2,
|
||||
vm_config->memory.start_hpa2 + vm_config->memory.size_hpa2);
|
||||
sos_vm_config->memory.size -= vm_config->memory.size_hpa2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static const struct e820_entry pre_ve820_template[E820_MAX_ENTRIES] = {
|
||||
{ /* usable RAM under 1MB */
|
||||
.baseaddr = 0x0UL,
|
||||
|
@ -40,8 +40,6 @@ static struct acrn_vm vm_array[CONFIG_MAX_VM_NUM] __aligned(PAGE_SIZE);
|
||||
|
||||
static struct acrn_vm *sos_vm_ptr = NULL;
|
||||
|
||||
static struct e820_entry sos_ve820[E820_MAX_ENTRIES];
|
||||
|
||||
uint16_t get_vmid_by_uuid(const uint8_t *uuid)
|
||||
{
|
||||
uint16_t vm_id = 0U;
|
||||
@ -251,108 +249,6 @@ static void prepare_prelaunched_vm_memmap(struct acrn_vm *vm, const struct acrn_
|
||||
}
|
||||
}
|
||||
|
||||
static void filter_mem_from_sos_e820(struct acrn_vm *vm, uint64_t start_pa, uint64_t end_pa)
|
||||
{
|
||||
uint32_t i;
|
||||
uint64_t entry_start;
|
||||
uint64_t entry_end;
|
||||
uint32_t entries_count = vm->e820_entry_num;
|
||||
struct e820_entry *entry, new_entry = {0};
|
||||
|
||||
for (i = 0U; i < entries_count; i++) {
|
||||
entry = &sos_ve820[i];
|
||||
entry_start = entry->baseaddr;
|
||||
entry_end = entry->baseaddr + entry->length;
|
||||
|
||||
/* No need handle in these cases*/
|
||||
if ((entry->type != E820_TYPE_RAM) || (entry_end <= start_pa) || (entry_start >= end_pa)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* filter out the specific memory and adjust length of this entry*/
|
||||
if ((entry_start < start_pa) && (entry_end <= end_pa)) {
|
||||
entry->length = start_pa - entry_start;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* filter out the specific memory and need to create a new entry*/
|
||||
if ((entry_start < start_pa) && (entry_end > end_pa)) {
|
||||
entry->length = start_pa - entry_start;
|
||||
new_entry.baseaddr = end_pa;
|
||||
new_entry.length = entry_end - end_pa;
|
||||
new_entry.type = E820_TYPE_RAM;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* This entry is within the range of specific memory
|
||||
* change to E820_TYPE_RESERVED
|
||||
*/
|
||||
if ((entry_start >= start_pa) && (entry_end <= end_pa)) {
|
||||
entry->type = E820_TYPE_RESERVED;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((entry_start >= start_pa) && (entry_start < end_pa) && (entry_end > end_pa)) {
|
||||
entry->baseaddr = end_pa;
|
||||
entry->length = entry_end - end_pa;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (new_entry.length > 0UL) {
|
||||
entries_count++;
|
||||
ASSERT(entries_count <= E820_MAX_ENTRIES, "e820 entry overflow");
|
||||
entry = &sos_ve820[entries_count - 1U];
|
||||
entry->baseaddr = new_entry.baseaddr;
|
||||
entry->length = new_entry.length;
|
||||
entry->type = new_entry.type;
|
||||
vm->e820_entry_num = entries_count;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* before boot sos_vm(service OS), call it to hide HV and prelaunched VM memory in e820 table from sos_vm
|
||||
*
|
||||
* @pre vm != NULL
|
||||
*/
|
||||
static void create_sos_vm_e820(struct acrn_vm *vm)
|
||||
{
|
||||
uint16_t vm_id;
|
||||
uint64_t hv_start_pa = hva2hpa((void *)(get_hv_image_base()));
|
||||
uint64_t hv_end_pa = hv_start_pa + CONFIG_HV_RAM_SIZE;
|
||||
uint32_t entries_count = get_e820_entries_count();
|
||||
const struct mem_range *p_mem_range_info = get_mem_range_info();
|
||||
struct acrn_vm_config *sos_vm_config = get_vm_config(vm->vm_id);
|
||||
|
||||
(void)memcpy_s((void *)sos_ve820, entries_count * sizeof(struct e820_entry),
|
||||
(const void *)get_e820_entry(), entries_count * sizeof(struct e820_entry));
|
||||
|
||||
vm->e820_entry_num = entries_count;
|
||||
vm->e820_entries = sos_ve820;
|
||||
/* filter out hv memory from e820 table */
|
||||
filter_mem_from_sos_e820(vm, hv_start_pa, hv_end_pa);
|
||||
sos_vm_config->memory.size = p_mem_range_info->total_mem_size - CONFIG_HV_RAM_SIZE;
|
||||
|
||||
/* filter out prelaunched vm memory from e820 table */
|
||||
for (vm_id = 0U; vm_id < CONFIG_MAX_VM_NUM; vm_id++) {
|
||||
struct acrn_vm_config *vm_config = get_vm_config(vm_id);
|
||||
|
||||
if (vm_config->load_order == PRE_LAUNCHED_VM) {
|
||||
filter_mem_from_sos_e820(vm, vm_config->memory.start_hpa,
|
||||
vm_config->memory.start_hpa + vm_config->memory.size);
|
||||
sos_vm_config->memory.size -= vm_config->memory.size;
|
||||
|
||||
/* if HPA2 is available, filter it out as well*/
|
||||
if (vm_config->memory.size_hpa2 != 0UL) {
|
||||
filter_mem_from_sos_e820(vm, vm_config->memory.start_hpa2,
|
||||
vm_config->memory.start_hpa2 + vm_config->memory.size_hpa2);
|
||||
sos_vm_config->memory.size -= vm_config->memory.size_hpa2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param[inout] vm pointer to a vm descriptor
|
||||
*
|
||||
|
@ -31,7 +31,4 @@ extern struct platform_clos_info platform_mba_clos_array[MAX_PLATFORM_CLOS_NUM];
|
||||
extern const struct cpu_state_table board_cpu_state_tbl;
|
||||
extern const union pci_bdf plat_hidden_pdevs[MAX_HIDDEN_PDEVS_NUM];
|
||||
|
||||
/* board specific functions */
|
||||
void create_prelaunched_vm_e820(struct acrn_vm *vm);
|
||||
|
||||
#endif /* BOARD_H */
|
||||
|
@ -250,6 +250,9 @@ uint16_t get_vmid_by_uuid(const uint8_t *uuid);
|
||||
struct acrn_vm *get_vm_from_vmid(uint16_t vm_id);
|
||||
struct acrn_vm *get_sos_vm(void);
|
||||
|
||||
void create_sos_vm_e820(struct acrn_vm *vm);
|
||||
void create_prelaunched_vm_e820(struct acrn_vm *vm);
|
||||
|
||||
int32_t direct_boot_sw_loader(struct acrn_vm *vm);
|
||||
|
||||
typedef int32_t (*vm_sw_loader_t)(struct acrn_vm *vm);
|
||||
|
Loading…
Reference in New Issue
Block a user