From 3c60512738c261654b11e7017e6690712f0be67e Mon Sep 17 00:00:00 2001 From: Jason Chen CJ Date: Wed, 23 Jan 2019 11:17:42 +0800 Subject: [PATCH] io_emul: reorg function definition to pass partition mode build reorg function definition to pass partition mode build Tracked-On: #2394 Signed-off-by: Jason Chen CJ --- hypervisor/arch/x86/io_emul.c | 116 +++++++++++++++++----------------- 1 file changed, 59 insertions(+), 57 deletions(-) diff --git a/hypervisor/arch/x86/io_emul.c b/hypervisor/arch/x86/io_emul.c index a1745ed5b..34da2a594 100644 --- a/hypervisor/arch/x86/io_emul.c +++ b/hypervisor/arch/x86/io_emul.c @@ -8,6 +8,64 @@ #include +/** + * @brief General complete-work for port I/O emulation + * + * @pre io_req->type == REQ_PORTIO + * + * @remark This function must be called when \p io_req is completed, after + * either a previous call to emulate_io() returning 0 or the corresponding VHM + * request having transferred to the COMPLETE state. + */ +static void +emulate_pio_complete(struct acrn_vcpu *vcpu, const struct io_request *io_req) +{ + const struct pio_request *pio_req = &io_req->reqs.pio; + uint64_t mask = 0xFFFFFFFFUL >> (32UL - 8UL * pio_req->size); + + if (pio_req->direction == REQUEST_READ) { + uint64_t value = (uint64_t)pio_req->value; + uint64_t rax = vcpu_get_gpreg(vcpu, CPU_REG_RAX); + + rax = ((rax) & ~mask) | (value & mask); + vcpu_set_gpreg(vcpu, CPU_REG_RAX, rax); + } +} + +/** + * @brief General complete-work for MMIO emulation + * + * @param vcpu The virtual CPU that triggers the MMIO access + * @param io_req The I/O request holding the details of the MMIO access + * + * @pre io_req->type == REQ_MMIO + * + * @remark This function must be called when \p io_req is completed, after + * either a previous call to emulate_io() returning 0 or the corresponding VHM + * request transferring to the COMPLETE state. + */ +static void emulate_mmio_complete(const struct acrn_vcpu *vcpu, const struct io_request *io_req) +{ + const struct mmio_request *mmio_req = &io_req->reqs.mmio; + + if (mmio_req->direction == REQUEST_READ) { + /* Emulate instruction and update vcpu register set */ + (void)emulate_instruction(vcpu); + } +} + +#ifdef CONFIG_PARTITION_MODE +static void io_instr_dest_handler(struct io_request *io_req) +{ + struct pio_request *pio_req = &io_req->reqs.pio; + + if (pio_req->direction == REQUEST_READ) { + pio_req->value = 0xFFFFFFFFU; + } +} + +#else + static void complete_ioreq(struct acrn_vcpu *vcpu, struct io_request *io_req) { union vhm_request_buffer *req_buf = NULL; @@ -36,30 +94,6 @@ static void complete_ioreq(struct acrn_vcpu *vcpu, struct io_request *io_req) clac(); } -/** - * @brief General complete-work for port I/O emulation - * - * @pre io_req->type == REQ_PORTIO - * - * @remark This function must be called when \p io_req is completed, after - * either a previous call to emulate_io() returning 0 or the corresponding VHM - * request having transferred to the COMPLETE state. - */ -static void -emulate_pio_complete(struct acrn_vcpu *vcpu, const struct io_request *io_req) -{ - const struct pio_request *pio_req = &io_req->reqs.pio; - uint64_t mask = 0xFFFFFFFFUL >> (32UL - 8UL * pio_req->size); - - if (pio_req->direction == REQUEST_READ) { - uint64_t value = (uint64_t)pio_req->value; - uint64_t rax = vcpu_get_gpreg(vcpu, CPU_REG_RAX); - - rax = ((rax) & ~mask) | (value & mask); - vcpu_set_gpreg(vcpu, CPU_REG_RAX, rax); - } -} - /** * @brief Complete-work of VHM requests for port I/O emulation * @@ -77,28 +111,6 @@ static void dm_emulate_pio_complete(struct acrn_vcpu *vcpu) emulate_pio_complete(vcpu, io_req); } -/** - * @brief General complete-work for MMIO emulation - * - * @param vcpu The virtual CPU that triggers the MMIO access - * @param io_req The I/O request holding the details of the MMIO access - * - * @pre io_req->type == REQ_MMIO - * - * @remark This function must be called when \p io_req is completed, after - * either a previous call to emulate_io() returning 0 or the corresponding VHM - * request transferring to the COMPLETE state. - */ -static void emulate_mmio_complete(const struct acrn_vcpu *vcpu, const struct io_request *io_req) -{ - const struct mmio_request *mmio_req = &io_req->reqs.mmio; - - if (mmio_req->direction == REQUEST_READ) { - /* Emulate instruction and update vcpu register set */ - (void)emulate_instruction(vcpu); - } -} - /** * @brief Complete-work of VHM requests for MMIO emulation * @@ -118,17 +130,6 @@ static void dm_emulate_mmio_complete(struct acrn_vcpu *vcpu) emulate_mmio_complete(vcpu, io_req); } -#ifdef CONFIG_PARTITION_MODE -static void io_instr_dest_handler(struct io_request *io_req) -{ - struct pio_request *pio_req = &io_req->reqs.pio; - - if (pio_req->direction == REQUEST_READ) { - pio_req->value = 0xFFFFFFFFU; - } -} -#endif - /** * @brief General complete-work for all kinds of VHM requests for I/O emulation * @@ -173,6 +174,7 @@ static void dm_emulate_io_complete(struct acrn_vcpu *vcpu) } } } +#endif /** * Try handling the given request by any port I/O handler registered in the