mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-11-16 13:55:04 +00:00
This commit moves struct acrn_vm under common header vm.h, and move some x86-specific members of struct acrn_vm into arch_vm. This commit focuses on struct cleanup only. API cleanup will be in future patch series. The affected members are: e820_entry_num e820_entries wire_mode wbinvd_lock vlapic_mode_lock vcpuid_entry_nr vcpuid_level vcpuid_xlevel vcpuid_entries reset_control pm sworld_control sworld_snapshot intr_inject_delay_delta Moved to common vm.h: ept_lock -> rename to stg2pt_lock ept_pgtable -> rename to stg2_pgtable nworld_eptp -> rename to root_stg2ptp emul_mmio_lock nr_emul_mmio_regions emul_mmio emul_pio To avoid circular dependency, some in-header helpers are also moved into common vm.h. Tracked-On: #8830 Signed-off-by: Yifan Liu <yifan1.liu@intel.com> Reviewed-by: Fei Li <fei1.li@intel.com> Acked-by: Wang Yu1 <yu1.wang@intel.com>
64 lines
1.6 KiB
C
64 lines
1.6 KiB
C
/*
|
|
* Copyright (C) 2020-2022 Intel Corporation.
|
|
*
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
*/
|
|
|
|
#include <errno.h>
|
|
#include <util.h>
|
|
#include <acrn_hv_defs.h>
|
|
#include <asm/pgtable.h>
|
|
#include <vm.h>
|
|
#include <asm/guest/ept.h>
|
|
#include <logmsg.h>
|
|
|
|
|
|
int32_t assign_mmio_dev(struct acrn_vm *vm, const struct acrn_mmiodev *mmiodev)
|
|
{
|
|
int32_t i, ret = 0;
|
|
const struct acrn_mmiores *res;
|
|
|
|
for (i = 0; i < MMIODEV_RES_NUM; i++) {
|
|
res = &mmiodev->res[i];
|
|
if (mem_aligned_check(res->user_vm_pa, PAGE_SIZE) &&
|
|
mem_aligned_check(res->host_pa, PAGE_SIZE) &&
|
|
mem_aligned_check(res->size, PAGE_SIZE)) {
|
|
ept_add_mr(vm, (uint64_t *)vm->root_stg2ptp, res->host_pa,
|
|
is_service_vm(vm) ? res->host_pa : res->user_vm_pa,
|
|
res->size, EPT_RWX | (res->mem_type & EPT_MT_MASK));
|
|
} else {
|
|
pr_err("%s invalid mmio res[%d] gpa:0x%lx hpa:0x%lx size:0x%lx",
|
|
__FUNCTION__, i, res->user_vm_pa, res->host_pa, res->size);
|
|
ret = -EINVAL;
|
|
break;
|
|
}
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
int32_t deassign_mmio_dev(struct acrn_vm *vm, const struct acrn_mmiodev *mmiodev)
|
|
{
|
|
int32_t i, ret = 0;
|
|
uint64_t gpa;
|
|
const struct acrn_mmiores *res;
|
|
|
|
for (i = 0; i < MMIODEV_RES_NUM; i++) {
|
|
res = &mmiodev->res[i];
|
|
gpa = is_service_vm(vm) ? res->host_pa : res->user_vm_pa;
|
|
if (ept_is_valid_mr(vm, gpa, res->size)) {
|
|
if (mem_aligned_check(gpa, PAGE_SIZE) &&
|
|
mem_aligned_check(res->size, PAGE_SIZE)) {
|
|
ept_del_mr(vm, (uint64_t *)vm->root_stg2ptp, gpa, res->size);
|
|
} else {
|
|
pr_err("%s invalid mmio res[%d] gpa:0x%lx hpa:0x%lx size:0x%lx",
|
|
__FUNCTION__, i, res->user_vm_pa, res->host_pa, res->size);
|
|
ret = -EINVAL;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
return ret;
|
|
}
|