diff --git a/hypervisor/dm/io_req.c b/hypervisor/dm/io_req.c index 56ece8d67..9720c3a26 100644 --- a/hypervisor/dm/io_req.c +++ b/hypervisor/dm/io_req.c @@ -596,7 +596,8 @@ void register_pio_emulation_handler(struct acrn_vm *vm, uint32_t pio_idx, /** * @brief Register a MMIO handler * - * This API registers a MMIO handler to \p vm before it is launched. + * This API registers a MMIO handler to \p vm before it is Started + * For Pre-launched VMs, this API can be called after it is Started * * @param vm The VM to which the MMIO handler is registered * @param read_write The handler for emulating accesses to the given range @@ -604,50 +605,40 @@ void register_pio_emulation_handler(struct acrn_vm *vm, uint32_t pio_idx, * @param end The end of the range (exclusive) \p read_write can emulate * @param handler_private_data Handler-specific data which will be passed to \p read_write when called * - * @retval 0 Registration succeeds - * @retval -EINVAL \p read_write is NULL, \p end is not larger than \p start or \p vm has been launched + * @return None */ -int32_t register_mmio_emulation_handler(struct acrn_vm *vm, +void register_mmio_emulation_handler(struct acrn_vm *vm, hv_mem_io_handler_t read_write, uint64_t start, uint64_t end, void *handler_private_data) { - int32_t status = -EINVAL; struct mem_io_node *mmio_node; - if ((vm->hw.created_vcpus > 0U) && (vm->hw.vcpu_array[0].launched)) { - pr_err("register mmio handler after vm launched"); - } else { - /* Ensure both a read/write handler and range check function exist */ - if ((read_write != NULL) && (end > start)) { - if (vm->emul_mmio_regions >= CONFIG_MAX_EMULATED_MMIO_REGIONS) { - pr_err("the emulated mmio region is out of range"); - } else { - mmio_node = &(vm->emul_mmio[vm->emul_mmio_regions]); - /* Fill in information for this node */ - mmio_node->read_write = read_write; - mmio_node->handler_private_data = handler_private_data; - mmio_node->range_start = start; - mmio_node->range_end = end; + /* Ensure both a read/write handler and range check function exist */ + if ((read_write != NULL) && (end > start)) { + if (vm->emul_mmio_regions >= CONFIG_MAX_EMULATED_MMIO_REGIONS) { + pr_err("the emulated mmio region is out of range"); + } else { + mmio_node = &(vm->emul_mmio[vm->emul_mmio_regions]); + /* Fill in information for this node */ + mmio_node->read_write = read_write; + mmio_node->handler_private_data = handler_private_data; + mmio_node->range_start = start; + mmio_node->range_end = end; - (vm->emul_mmio_regions)++; + (vm->emul_mmio_regions)++; - /* - * SOS would map all its memory at beginning, so we - * should unmap it. But UOS will not, so we shouldn't - * need to unmap it. - */ - if (is_sos_vm(vm)) { - ept_mr_del(vm, (uint64_t *)vm->arch_vm.nworld_eptp, start, end - start); - } - - /* Return success */ - status = 0; + /* + * SOS would map all its memory at beginning, so we + * should unmap it. But UOS will not, so we shouldn't + * need to unmap it. + */ + if (is_sos_vm(vm)) { + ept_mr_del(vm, (uint64_t *)vm->arch_vm.nworld_eptp, start, end - start); } + } } - /* Return status to caller */ - return status; } /** diff --git a/hypervisor/dm/vioapic.c b/hypervisor/dm/vioapic.c index 6cbfedd3b..59b6db511 100644 --- a/hypervisor/dm/vioapic.c +++ b/hypervisor/dm/vioapic.c @@ -457,7 +457,7 @@ vioapic_init(struct acrn_vm *vm) vioapic_reset(vm); - (void)register_mmio_emulation_handler(vm, + register_mmio_emulation_handler(vm, vioapic_mmio_access_handler, (uint64_t)VIOAPIC_BASE, (uint64_t)VIOAPIC_BASE + VIOAPIC_SIZE, diff --git a/hypervisor/dm/vpci/pci_pt.c b/hypervisor/dm/vpci/pci_pt.c index 44882f846..4c9108de3 100644 --- a/hypervisor/dm/vpci/pci_pt.c +++ b/hypervisor/dm/vpci/pci_pt.c @@ -163,7 +163,7 @@ void vdev_pt_remap_msix_table_bar(struct pci_vdev *vdev) addr_lo = round_page_down(msix->mmio_gpa + msix->table_offset); } - (void)register_mmio_emulation_handler(vdev->vpci->vm, vmsix_table_mmio_access_handler, + register_mmio_emulation_handler(vdev->vpci->vm, vmsix_table_mmio_access_handler, addr_lo, addr_hi, vdev); } } diff --git a/hypervisor/include/dm/io_req.h b/hypervisor/include/dm/io_req.h index fffa8c64f..b9d8a640c 100644 --- a/hypervisor/include/dm/io_req.h +++ b/hypervisor/include/dm/io_req.h @@ -265,10 +265,9 @@ void register_pio_emulation_handler(struct acrn_vm *vm, uint32_t pio_idx, * @param end The end of the range (exclusive) \p read_write can emulate * @param handler_private_data Handler-specific data which will be passed to \p read_write when called * - * @retval 0 Registration succeeds - * @retval -EINVAL \p read_write is NULL, \p end is not larger than \p start or \p vm has been launched + * @return None */ -int32_t register_mmio_emulation_handler(struct acrn_vm *vm, +void register_mmio_emulation_handler(struct acrn_vm *vm, hv_mem_io_handler_t read_write, uint64_t start, uint64_t end, void *handler_private_data);