dm: Use new MMIO device passthrough management ioctls

IC_ASSIGN_MMIODEV	->	ACRN_IOCTL_ASSIGN_MMIODEV
IC_DEASSIGN_MMIODEV	->	ACRN_IOCTL_DEASSIGN_MMIODEV

struct acrn_mmiodev has slight change. Move struct acrn_mmiodev into
acrn_common.h because it is used by both DM and HV.

Tracked-On: #6282
Signed-off-by: Shuo A Liu <shuo.a.liu@intel.com>
This commit is contained in:
Shuo A Liu
2021-07-07 16:54:26 +08:00
committed by wenlingz
parent 3625eb7a99
commit 9e7abbb38c
13 changed files with 61 additions and 80 deletions

View File

@@ -925,7 +925,7 @@ 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.base_hpa, mmiodev.size)) {
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);
@@ -960,7 +960,7 @@ 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.base_gpa, mmiodev.size)) {
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);

View File

@@ -15,11 +15,11 @@ int32_t assign_mmio_dev(struct acrn_vm *vm, const struct acrn_mmiodev *mmiodev)
{
int32_t ret = -EINVAL;
if (mem_aligned_check(mmiodev->base_gpa, PAGE_SIZE) &&
mem_aligned_check(mmiodev->base_hpa, PAGE_SIZE) &&
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->base_hpa,
is_sos_vm(vm) ? mmiodev->base_hpa : mmiodev->base_gpa,
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;
}
@@ -31,11 +31,11 @@ int32_t deassign_mmio_dev(struct acrn_vm *vm, const struct acrn_mmiodev *mmiodev
{
int32_t ret = -EINVAL;
if (mem_aligned_check(mmiodev->base_gpa, PAGE_SIZE) &&
mem_aligned_check(mmiodev->base_hpa, PAGE_SIZE) &&
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->base_hpa : mmiodev->base_gpa, mmiodev->size);
is_sos_vm(vm) ? mmiodev->service_vm_pa: mmiodev->user_vm_pa, mmiodev->size);
ret = 0;
}

View File

@@ -136,10 +136,10 @@ void register_vgpio_handler(struct acrn_vm *vm, const struct acrn_mmiodev *mmiod
uint64_t gpa_start, gpa_end, gpio_pcr_sz;
uint64_t base_hpa;
gpa_start = mmiodev->base_gpa + (P2SB_BASE_GPIO_PORT_ID << P2SB_PORTID_SHIFT);
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->base_hpa + (P2SB_BASE_GPIO_PORT_ID << P2SB_PORTID_SHIFT);
base_hpa = mmiodev->service_vm_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);

View File

@@ -735,6 +735,21 @@ struct acrn_pcidev {
uint32_t bar[ACRN_PCI_NUM_BARS];
} __attribute__((aligned(8)));
/**
* @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;
} __attribute__((aligned(8)));
/**
* @}
*/

View File

@@ -271,26 +271,6 @@ struct hc_ptdev_irq {
} __aligned(8);
/**
* @brief Info to assign or deassign a MMIO device for a VM
*
* the parameter for HC_ASSIGN_MMIODEV or HC_DEASSIGN_MMIODEV hypercall
*/
struct acrn_mmiodev {
/** the gpa of the MMIO region for the MMIO device */
uint64_t base_gpa;
/** the hpa of the MMIO region for the MMIO device */
uint64_t base_hpa;
/** the size of the MMIO region for the MMIO device */
uint64_t size;
/** reserved for extension */
uint64_t reserved[13];
} __attribute__((aligned(8)));
/**
* @brief Info to create or destroy a virtual PCI or legacy device for a VM
*