diff --git a/devicemodel/core/main.c b/devicemodel/core/main.c index 085619aaf..66577ce4b 100644 --- a/devicemodel/core/main.c +++ b/devicemodel/core/main.c @@ -652,28 +652,6 @@ num_vcpus_allowed(struct vmctx *ctx) return VM_MAXCPU; } -static struct vmctx * -do_open(const char *vmname) -{ - struct vmctx *ctx; - int error; - - error = vm_create(vmname); - if (error) { - perror("vm_create"); - exit(1); - - } - - ctx = vm_open(vmname); - if (ctx == NULL) { - perror("vm_open"); - exit(1); - } - - return ctx; -} - static void sig_handler_term(int signo) { @@ -901,12 +879,11 @@ main(int argc, char *argv[]) vmname = argv[0]; for (;;) { - ctx = do_open(vmname); - - /* set IOReq buffer page */ - error = vm_set_shared_io_page(ctx, (unsigned long)vhm_req_buf); - if (error) - goto fail; + ctx = vm_create(vmname, (unsigned long)vhm_req_buf); + if (!ctx) { + perror("vm_open"); + exit(1); + } if (guest_ncpus < 1) { fprintf(stderr, "Invalid guest vCPUs (%d)\n", @@ -997,7 +974,6 @@ main(int argc, char *argv[]) mevent_deinit(); vm_unsetup_memory(ctx); vm_destroy(ctx); - vm_close(ctx); _ctx = 0; vm_set_suspend_mode(VM_SUSPEND_NONE); @@ -1011,6 +987,5 @@ mevent_fail: vm_unsetup_memory(ctx); fail: vm_destroy(ctx); - vm_close(ctx); exit(0); } diff --git a/devicemodel/core/vmmapi.c b/devicemodel/core/vmmapi.c index 63a426914..e732c7151 100644 --- a/devicemodel/core/vmmapi.c +++ b/devicemodel/core/vmmapi.c @@ -58,13 +58,6 @@ #define SUPPORT_VHM_API_VERSION_MAJOR 1 #define SUPPORT_VHM_API_VERSION_MINOR 0 -int -vm_create(const char *name) -{ - /* TODO: specific part for vm create */ - return 0; -} - static int check_api(int fd) { @@ -92,7 +85,7 @@ check_api(int fd) static int devfd = -1; struct vmctx * -vm_open(const char *name) +vm_create(const char *name, uint64_t req_buf) { struct vmctx *ctx; struct acrn_create_vm create_vm; @@ -138,6 +131,7 @@ vm_open(const char *name) else create_vm.vm_flag &= (~SECURE_WORLD_ENABLED); + create_vm.req_buf = req_buf; while (retry > 0) { error = ioctl(ctx->fd, IC_CREATE_VM, &create_vm); if (error == 0) @@ -160,33 +154,6 @@ err: return NULL; } -void -vm_close(struct vmctx *ctx) -{ - if (!ctx) - return; - - close(ctx->fd); - free(ctx); - devfd = -1; -} - -int -vm_set_shared_io_page(struct vmctx *ctx, uint64_t page_vma) -{ - int error; - - error = ioctl(ctx->fd, IC_SET_IOREQ_BUFFER, page_vma); - - if (error) { - fprintf(stderr, "failed to setup shared io page create VM %s\n", - ctx->name); - return -1; - } - - return 0; -} - int vm_create_ioreq_client(struct vmctx *ctx) { @@ -239,8 +206,13 @@ vm_notify_request_done(struct vmctx *ctx, int vcpu) void vm_destroy(struct vmctx *ctx) { - if (ctx) - ioctl(ctx->fd, IC_DESTROY_VM, NULL); + if (!ctx) + return; + + ioctl(ctx->fd, IC_DESTROY_VM, NULL); + close(ctx->fd); + free(ctx); + devfd = -1; } int diff --git a/devicemodel/include/public/acrn_common.h b/devicemodel/include/public/acrn_common.h index dbe3fe93e..03ead291a 100644 --- a/devicemodel/include/public/acrn_common.h +++ b/devicemodel/include/public/acrn_common.h @@ -250,8 +250,10 @@ struct acrn_create_vm { */ uint64_t vm_flag; + uint64_t req_buf; + /** Reserved for future use*/ - uint8_t reserved2[24]; + uint8_t reserved2[16]; } __aligned(8); /** diff --git a/devicemodel/include/vmmapi.h b/devicemodel/include/vmmapi.h index 299c5a8ad..f6bf8ee16 100644 --- a/devicemodel/include/vmmapi.h +++ b/devicemodel/include/vmmapi.h @@ -96,13 +96,10 @@ struct vm_isa_irq { */ void *vm_create_devmem(struct vmctx *ctx, int segid, const char *name, size_t len); -int vm_create(const char *name); int vm_get_device_fd(struct vmctx *ctx); -struct vmctx *vm_open(const char *name); -void vm_close(struct vmctx *ctx); +struct vmctx *vm_create(const char *name, uint64_t req_buf); void vm_pause(struct vmctx *ctx); void vm_reset(struct vmctx *ctx); -int vm_set_shared_io_page(struct vmctx *ctx, uint64_t page_vma); int vm_create_ioreq_client(struct vmctx *ctx); int vm_destroy_ioreq_client(struct vmctx *ctx); int vm_attach_ioreq_client(struct vmctx *ctx);