From 26ab2c9146ef997463a6e60ab1ca09d94c042098 Mon Sep 17 00:00:00 2001 From: Junjie Mao Date: Wed, 25 Jul 2018 18:33:52 +0800 Subject: [PATCH] HV: io: move MMIO handler registration to io.c This patch solely moves MMIO handler registration APIs from ept.c to io.c as it is related more to I/O request handling. Signed-off-by: Junjie Mao Acked-by: Eddie Dong --- hypervisor/arch/x86/ept.c | 69 --------------------------------------- hypervisor/arch/x86/io.c | 69 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 69 deletions(-) diff --git a/hypervisor/arch/x86/ept.c b/hypervisor/arch/x86/ept.c index 8d8be090e..20b28a875 100644 --- a/hypervisor/arch/x86/ept.c +++ b/hypervisor/arch/x86/ept.c @@ -189,75 +189,6 @@ bool is_ept_supported(void) return status; } -int register_mmio_emulation_handler(struct vm *vm, - hv_mem_io_handler_t read_write, uint64_t start, - uint64_t end, void *handler_private_data) -{ - int status = -EINVAL; - struct mem_io_node *mmio_node; - - if (vm->hw.created_vcpus > 0 && vm->hw.vcpu_array[0]->launched) { - ASSERT(false, "register mmio handler after vm launched"); - return status; - } - - /* Ensure both a read/write handler and range check function exist */ - if ((read_write != NULL) && (end > start)) { - /* Allocate memory for node */ - mmio_node = - (struct mem_io_node *)calloc(1U, sizeof(struct mem_io_node)); - - /* Ensure memory successfully allocated */ - if (mmio_node != NULL) { - /* Fill in information for this node */ - mmio_node->read_write = read_write; - mmio_node->handler_private_data = handler_private_data; - - INIT_LIST_HEAD(&mmio_node->list); - list_add(&mmio_node->list, &vm->mmio_list); - - mmio_node->range_start = start; - mmio_node->range_end = end; - - /* - * 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_vm0(vm)) { - ept_mr_del(vm, - (uint64_t *)vm->arch_vm.nworld_eptp, - start, end - start); - } - - /* Return success */ - status = 0; - } - } - - /* Return status to caller */ - return status; -} - -void unregister_mmio_emulation_handler(struct vm *vm, uint64_t start, - uint64_t end) -{ - struct list_head *pos, *tmp; - struct mem_io_node *mmio_node; - - list_for_each_safe(pos, tmp, &vm->mmio_list) { - mmio_node = list_entry(pos, struct mem_io_node, list); - - if ((mmio_node->range_start == start) && - (mmio_node->range_end == end)) { - /* assume only one entry found in mmio_list */ - list_del_init(&mmio_node->list); - free(mmio_node); - break; - } - } -} - int ept_violation_vmexit_handler(struct vcpu *vcpu) { int status = -EINVAL, ret; diff --git a/hypervisor/arch/x86/io.c b/hypervisor/arch/x86/io.c index 0be09db01..57b91a1ef 100644 --- a/hypervisor/arch/x86/io.c +++ b/hypervisor/arch/x86/io.c @@ -435,3 +435,72 @@ void register_io_emulation_handler(struct vm *vm, struct vm_io_range *range, register_io_handler(vm, handler); } + +int register_mmio_emulation_handler(struct vm *vm, + hv_mem_io_handler_t read_write, uint64_t start, + uint64_t end, void *handler_private_data) +{ + int status = -EINVAL; + struct mem_io_node *mmio_node; + + if (vm->hw.created_vcpus > 0 && vm->hw.vcpu_array[0]->launched) { + ASSERT(false, "register mmio handler after vm launched"); + return status; + } + + /* Ensure both a read/write handler and range check function exist */ + if ((read_write != NULL) && (end > start)) { + /* Allocate memory for node */ + mmio_node = + (struct mem_io_node *)calloc(1U, sizeof(struct mem_io_node)); + + /* Ensure memory successfully allocated */ + if (mmio_node != NULL) { + /* Fill in information for this node */ + mmio_node->read_write = read_write; + mmio_node->handler_private_data = handler_private_data; + + INIT_LIST_HEAD(&mmio_node->list); + list_add(&mmio_node->list, &vm->mmio_list); + + mmio_node->range_start = start; + mmio_node->range_end = end; + + /* + * 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_vm0(vm)) { + ept_mr_del(vm, + (uint64_t *)vm->arch_vm.nworld_eptp, + start, end - start); + } + + /* Return success */ + status = 0; + } + } + + /* Return status to caller */ + return status; +} + +void unregister_mmio_emulation_handler(struct vm *vm, uint64_t start, + uint64_t end) +{ + struct list_head *pos, *tmp; + struct mem_io_node *mmio_node; + + list_for_each_safe(pos, tmp, &vm->mmio_list) { + mmio_node = list_entry(pos, struct mem_io_node, list); + + if ((mmio_node->range_start == start) && + (mmio_node->range_end == end)) { + /* assume only one entry found in mmio_list */ + list_del_init(&mmio_node->list); + free(mmio_node); + break; + } + } +}