mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-09-22 17:27:53 +00:00
HV: refine acrn_mmiodev data structure
1. add a name field to indicate what the MMIO Device is. 2. add two more MMIO resource to the acrn_mmiodev data structure. Tracked-On: #6366 Signed-off-by: Tao Yuhong <yuhong.tao@intel.com> Signed-off-by: Fei Li <fei1.li@intel.com>
This commit is contained in:
@@ -291,6 +291,11 @@ static void prepare_prelaunched_vm_memmap(struct acrn_vm *vm, const struct acrn_
|
||||
}
|
||||
|
||||
for (i = 0U; i < MAX_MMIO_DEV_NUM; i++) {
|
||||
/* Now we include the TPM2 event log region in ACPI NVS, so we need to
|
||||
* delete this potential mapping first.
|
||||
*/
|
||||
(void)deassign_mmio_dev(vm, &vm_config->mmiodevs[i]);
|
||||
|
||||
(void)assign_mmio_dev(vm, &vm_config->mmiodevs[i]);
|
||||
|
||||
#ifdef P2SB_VGPIO_DM_ENABLED
|
||||
|
@@ -925,11 +925,9 @@ int32_t hcall_assign_mmiodev(struct acrn_vcpu *vcpu, struct acrn_vm *target_vm,
|
||||
/* We should only assign a device to a post-launched VM at creating time for safety, not runtime or other cases*/
|
||||
if (is_created_vm(target_vm)) {
|
||||
if (copy_from_gpa(vm, &mmiodev, param2, sizeof(mmiodev)) == 0) {
|
||||
if (ept_is_valid_mr(vm, mmiodev.service_vm_pa, mmiodev.size)) {
|
||||
ret = deassign_mmio_dev(vm, &mmiodev);
|
||||
if (ret == 0) {
|
||||
ret = assign_mmio_dev(target_vm, &mmiodev);
|
||||
}
|
||||
ret = deassign_mmio_dev(vm, &mmiodev);
|
||||
if (ret == 0) {
|
||||
ret = assign_mmio_dev(target_vm, &mmiodev);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -960,11 +958,9 @@ int32_t hcall_deassign_mmiodev(struct acrn_vcpu *vcpu, struct acrn_vm *target_vm
|
||||
/* We should only de-assign a device from a post-launched VM at creating/shutdown/reset time */
|
||||
if ((is_paused_vm(target_vm) || is_created_vm(target_vm))) {
|
||||
if (copy_from_gpa(vm, &mmiodev, param2, sizeof(mmiodev)) == 0) {
|
||||
if (ept_is_valid_mr(target_vm, mmiodev.user_vm_pa, mmiodev.size)) {
|
||||
ret = deassign_mmio_dev(target_vm, &mmiodev);
|
||||
if (ret == 0) {
|
||||
ret = assign_mmio_dev(vm, &mmiodev);
|
||||
}
|
||||
ret = deassign_mmio_dev(target_vm, &mmiodev);
|
||||
if (ret == 0) {
|
||||
ret = assign_mmio_dev(vm, &mmiodev);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@@ -10,18 +10,28 @@
|
||||
#include <asm/pgtable.h>
|
||||
#include <asm/guest/vm.h>
|
||||
#include <asm/guest/ept.h>
|
||||
#include <debug/logmsg.h>
|
||||
|
||||
|
||||
int32_t assign_mmio_dev(struct acrn_vm *vm, const struct acrn_mmiodev *mmiodev)
|
||||
{
|
||||
int32_t ret = -EINVAL;
|
||||
int32_t i, ret = 0;
|
||||
const struct acrn_mmiores *res;
|
||||
|
||||
if (mem_aligned_check(mmiodev->user_vm_pa, PAGE_SIZE) &&
|
||||
mem_aligned_check(mmiodev->service_vm_pa, PAGE_SIZE) &&
|
||||
mem_aligned_check(mmiodev->size, PAGE_SIZE)) {
|
||||
ept_add_mr(vm, (uint64_t *)vm->arch_vm.nworld_eptp, mmiodev->service_vm_pa,
|
||||
is_sos_vm(vm) ? mmiodev->service_vm_pa: mmiodev->user_vm_pa,
|
||||
mmiodev->size, EPT_RWX | EPT_UNCACHED);
|
||||
ret = 0;
|
||||
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->arch_vm.nworld_eptp, res->host_pa,
|
||||
is_sos_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;
|
||||
@@ -29,14 +39,24 @@ int32_t assign_mmio_dev(struct acrn_vm *vm, const struct acrn_mmiodev *mmiodev)
|
||||
|
||||
int32_t deassign_mmio_dev(struct acrn_vm *vm, const struct acrn_mmiodev *mmiodev)
|
||||
{
|
||||
int32_t ret = -EINVAL;
|
||||
int32_t i, ret = 0;
|
||||
uint64_t gpa;
|
||||
const struct acrn_mmiores *res;
|
||||
|
||||
if (mem_aligned_check(mmiodev->user_vm_pa, PAGE_SIZE) &&
|
||||
mem_aligned_check(mmiodev->service_vm_pa, PAGE_SIZE) &&
|
||||
mem_aligned_check(mmiodev->size, PAGE_SIZE)) {
|
||||
ept_del_mr(vm, (uint64_t *)vm->arch_vm.nworld_eptp,
|
||||
is_sos_vm(vm) ? mmiodev->service_vm_pa: mmiodev->user_vm_pa, mmiodev->size);
|
||||
ret = 0;
|
||||
for (i = 0; i < MMIODEV_RES_NUM; i++) {
|
||||
res = &mmiodev->res[i];
|
||||
gpa = is_sos_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->arch_vm.nworld_eptp, 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;
|
||||
|
@@ -139,7 +139,7 @@ void register_vgpio_handler(struct acrn_vm *vm, const struct acrn_mmiodev *mmiod
|
||||
gpa_start = mmiodev->user_vm_pa + (P2SB_BASE_GPIO_PORT_ID << P2SB_PORTID_SHIFT);
|
||||
gpio_pcr_sz = P2SB_PCR_SPACE_SIZE_PER_AGENT * P2SB_MAX_GPIO_COMMUNITIES;
|
||||
gpa_end = gpa_start + gpio_pcr_sz;
|
||||
base_hpa = mmiodev->service_vm_pa + (P2SB_BASE_GPIO_PORT_ID << P2SB_PORTID_SHIFT);
|
||||
base_hpa = mmiodev->host_pa + (P2SB_BASE_GPIO_PORT_ID << P2SB_PORTID_SHIFT);
|
||||
|
||||
/* emulate MMIO access to the GPIO private configuration space registers */
|
||||
set_paging_supervisor((uint64_t)hpa2hva(base_hpa), gpio_pcr_sz);
|
||||
|
@@ -654,19 +654,25 @@ struct acrn_pcidev {
|
||||
uint32_t bar[ACRN_PCI_NUM_BARS];
|
||||
};
|
||||
|
||||
#define MMIODEV_RES_NUM 3
|
||||
|
||||
/**
|
||||
* @brief Info to assign or deassign a MMIO device for a VM
|
||||
*/
|
||||
struct acrn_mmiodev {
|
||||
/** the gpa of the MMIO region for the MMIO device */
|
||||
uint64_t user_vm_pa;
|
||||
|
||||
/** the hpa of the MMIO region for the MMIO device */
|
||||
uint64_t service_vm_pa;
|
||||
|
||||
/** the size of the MMIO region for the MMIO device */
|
||||
uint64_t size;
|
||||
char name[8];
|
||||
struct acrn_mmiores {
|
||||
/** the gpa of the MMIO region for the MMIO device */
|
||||
uint64_t user_vm_pa;
|
||||
/** the hpa of the MMIO region for the MMIO device: for post-launched VM
|
||||
* it's pa in service vm; for pre-launched VM it's pa in HV.
|
||||
*/
|
||||
uint64_t host_pa;
|
||||
/** the size of the MMIO region for the MMIO resource */
|
||||
uint64_t size;
|
||||
/** the memory type of the MMIO region for the MMIO resource */
|
||||
uint64_t mem_type;
|
||||
} res[MMIODEV_RES_NUM];
|
||||
};
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user