1 /* 2 * Copyright (C) 2019-2022 Intel Corporation. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #ifndef IO_EMUL_H 8 #define IO_EMUL_H 9 10 #include <types.h> 11 12 /* Define emulated port IO index */ 13 #define PIC_PRIMARY_PIO_IDX 0U 14 #define PIC_SECONDARY_PIO_IDX (PIC_PRIMARY_PIO_IDX + 1U) 15 #define PIC_ELC_PIO_IDX (PIC_SECONDARY_PIO_IDX + 1U) 16 #define PCI_CFGADDR_PIO_IDX (PIC_ELC_PIO_IDX + 1U) 17 #define PCI_CFGDATA_PIO_IDX (PCI_CFGADDR_PIO_IDX + 1U) 18 /* MAX_VUART_NUM_PER_VM is 8, so allocate UART_PIO_IDX0~UART_PIO_IDX0 + 7 for 8 vuart */ 19 #define UART_PIO_IDX0 (PCI_CFGDATA_PIO_IDX + 1U) 20 #define PM1A_EVT_PIO_IDX (UART_PIO_IDX0 + MAX_VUART_NUM_PER_VM) 21 #define PM1A_CNT_PIO_IDX (PM1A_EVT_PIO_IDX + 1U) 22 #define PM1B_EVT_PIO_IDX (PM1A_CNT_PIO_IDX + 1U) 23 #define PM1B_CNT_PIO_IDX (PM1B_EVT_PIO_IDX + 1U) 24 #define RTC_PIO_IDX (PM1B_CNT_PIO_IDX + 1U) 25 #define VIRTUAL_PM1A_CNT_PIO_IDX (RTC_PIO_IDX + 1U) 26 #define KB_PIO_IDX (VIRTUAL_PM1A_CNT_PIO_IDX + 1U) 27 #define CF9_PIO_IDX (KB_PIO_IDX + 1U) 28 #define PIO_RESET_REG_IDX (CF9_PIO_IDX + 1U) 29 #define SLEEP_CTL_PIO_IDX (PIO_RESET_REG_IDX + 1U) 30 #define EMUL_PIO_IDX_MAX (SLEEP_CTL_PIO_IDX + 1U) 31 /** 32 * @brief The handler of VM exits on I/O instructions 33 * 34 * @param vcpu The virtual CPU which triggers the VM exit on I/O instruction 35 */ 36 int32_t pio_instr_vmexit_handler(struct acrn_vcpu *vcpu); 37 38 /** 39 * @brief EPT violation handling 40 * 41 * @param[in] vcpu the pointer that points to vcpu data structure 42 * 43 * @retval -EINVAL fail to handle the EPT violation 44 * @retval 0 Success to handle the EPT violation 45 */ 46 int32_t ept_violation_vmexit_handler(struct acrn_vcpu *vcpu); 47 48 /** 49 * @brief General complete-work for port I/O emulation 50 * 51 * @pre io_req->io_type == REQ_PORTIO 52 * 53 * @remark This function must be called when \p io_req is completed, after 54 * either a previous call to emulate_io() returning 0 or the corresponding HSM 55 * request having transferred to the COMPLETE state. 56 */ 57 void emulate_pio_complete(struct acrn_vcpu *vcpu, const struct io_request *io_req); 58 59 /** 60 * @brief Allow a VM to access a port I/O range 61 * 62 * This API enables direct access from the given \p vm to the port I/O space 63 * starting from \p port_address to \p port_address + \p nbytes - 1. 64 * 65 * @param vm The VM whose port I/O access permissions is to be changed 66 * @param port_address The start address of the port I/O range 67 * @param nbytes The size of the range, in bytes 68 */ 69 void allow_guest_pio_access(struct acrn_vm *vm, uint16_t port_address, uint32_t nbytes); 70 71 /** 72 * @brief Allow a VM to access a port I/O range 73 * 74 * This API enables direct access from the given \p vm to the port I/O space 75 * starting from \p port_address to \p port_address + \p nbytes - 1. 76 * 77 * @param vm The VM whose port I/O access permissions is to be changed 78 * @param port_address The start address of the port I/O range 79 * @param nbytes The size of the range, in bytes 80 */ 81 void deny_guest_pio_access(struct acrn_vm *vm, uint16_t port_address, uint32_t nbytes); 82 83 /** 84 * @brief Fire HSM interrupt to Service VM 85 */ 86 void arch_fire_hsm_interrupt(void); 87 88 #endif /* IO_EMUL_H */ 89