mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-09-21 08:50:27 +00:00
hv:move some common APIs to io_req.c
Now the io_emul.c is relates with arch,io_req.c is common, move some APIs from io_emul.c to io_req.c as common like these APIs: register_pio/mmio_emulation_handler dm_emulate_pio/mmio_complete pio_default_read/write mmio_default_access_handler hv_emulate_pio/mmio etc Tracked-On: #1842 Signed-off-by: Mingqiang Chi <mingqiang.chi@intel.com> Reviewed-by: Jason Chen CJ <jason.cj.chen@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
@@ -41,6 +41,17 @@ int32_t pio_instr_vmexit_handler(struct acrn_vcpu *vcpu);
|
||||
*/
|
||||
int32_t ept_violation_vmexit_handler(struct acrn_vcpu *vcpu);
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*/
|
||||
void emulate_pio_complete(struct acrn_vcpu *vcpu, const struct io_request *io_req);
|
||||
|
||||
/**
|
||||
* @brief Allow a VM to access a port I/O range
|
||||
*
|
||||
@@ -54,49 +65,16 @@ int32_t ept_violation_vmexit_handler(struct acrn_vcpu *vcpu);
|
||||
void allow_guest_pio_access(struct acrn_vm *vm, uint16_t port_address, uint32_t nbytes);
|
||||
|
||||
/**
|
||||
* @brief Register a port I/O handler
|
||||
* @brief Allow a VM to access a port I/O range
|
||||
*
|
||||
* @param vm The VM to which the port I/O handlers are registered
|
||||
* @param pio_idx The emulated port io index
|
||||
* @param range The emulated port io range
|
||||
* @param io_read_fn_ptr The handler for emulating reads from the given range
|
||||
* @param io_write_fn_ptr The handler for emulating writes to the given range
|
||||
* @pre pio_idx < EMUL_PIO_IDX_MAX
|
||||
* This API enables direct access from the given \p vm to the port I/O space
|
||||
* starting from \p port_address to \p port_address + \p nbytes - 1.
|
||||
*
|
||||
* @param vm The VM whose port I/O access permissions is to be changed
|
||||
* @param port_address The start address of the port I/O range
|
||||
* @param nbytes The size of the range, in bytes
|
||||
*/
|
||||
void register_pio_emulation_handler(struct acrn_vm *vm, uint32_t pio_idx,
|
||||
const struct vm_io_range *range, io_read_fn_t io_read_fn_ptr, io_write_fn_t io_write_fn_ptr);
|
||||
|
||||
/**
|
||||
* @brief Register a MMIO handler
|
||||
*
|
||||
* This API registers a MMIO handler to \p vm before it is launched.
|
||||
*
|
||||
* @param vm The VM to which the MMIO handler is registered
|
||||
* @param read_write The handler for emulating accesses to the given range
|
||||
* @param start The base address of the range \p read_write can emulate
|
||||
* @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
|
||||
*/
|
||||
int32_t 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);
|
||||
|
||||
/**
|
||||
* @brief Register port I/O default handler
|
||||
*
|
||||
* @param vm The VM to which the port I/O handlers are registered
|
||||
*/
|
||||
void register_pio_default_emulation_handler(struct acrn_vm *vm);
|
||||
|
||||
/**
|
||||
* @brief Register MMIO default handler
|
||||
*
|
||||
* @param vm The VM to which the MMIO handler is registered
|
||||
*/
|
||||
void register_mmio_default_emulation_handler(struct acrn_vm *vm);
|
||||
void deny_guest_pio_access(struct acrn_vm *vm, uint16_t port_address, uint32_t nbytes);
|
||||
|
||||
/**
|
||||
* @brief Fire VHM interrupt to SOS
|
||||
|
@@ -219,6 +219,73 @@ void set_vhm_notification_vector(uint32_t vector);
|
||||
* @return vector for HV callbakc VH
|
||||
*/
|
||||
uint32_t get_vhm_notification_vector(void);
|
||||
|
||||
/**
|
||||
* @brief Emulate \p io_req for \p vcpu
|
||||
*
|
||||
* Handle an I/O request by either invoking a hypervisor-internal handler or
|
||||
* deliver to VHM.
|
||||
*
|
||||
* @pre vcpu != NULL
|
||||
* @pre vcpu->vm != NULL
|
||||
* @pre vcpu->vm->vm_id < CONFIG_MAX_VM_NUM
|
||||
*
|
||||
* @param vcpu The virtual CPU that triggers the MMIO access
|
||||
* @param io_req The I/O request holding the details of the MMIO access
|
||||
*
|
||||
* @retval 0 Successfully emulated by registered handlers.
|
||||
* @retval IOREQ_PENDING The I/O request is delivered to VHM.
|
||||
* @retval -EIO The request spans multiple devices and cannot be emulated.
|
||||
* @retval -EINVAL \p io_req has an invalid type.
|
||||
* @retval <0 on other errors during emulation.
|
||||
*/
|
||||
int32_t emulate_io(struct acrn_vcpu *vcpu, struct io_request *io_req);
|
||||
|
||||
/**
|
||||
* @brief Register a port I/O handler
|
||||
*
|
||||
* @param vm The VM to which the port I/O handlers are registered
|
||||
* @param pio_idx The emulated port io index
|
||||
* @param range The emulated port io range
|
||||
* @param io_read_fn_ptr The handler for emulating reads from the given range
|
||||
* @param io_write_fn_ptr The handler for emulating writes to the given range
|
||||
* @pre pio_idx < EMUL_PIO_IDX_MAX
|
||||
*/
|
||||
void register_pio_emulation_handler(struct acrn_vm *vm, uint32_t pio_idx,
|
||||
const struct vm_io_range *range, io_read_fn_t io_read_fn_ptr, io_write_fn_t io_write_fn_ptr);
|
||||
|
||||
/**
|
||||
* @brief Register a MMIO handler
|
||||
*
|
||||
* This API registers a MMIO handler to \p vm before it is launched.
|
||||
*
|
||||
* @param vm The VM to which the MMIO handler is registered
|
||||
* @param read_write The handler for emulating accesses to the given range
|
||||
* @param start The base address of the range \p read_write can emulate
|
||||
* @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
|
||||
*/
|
||||
int32_t 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);
|
||||
|
||||
/**
|
||||
* @brief Register port I/O default handler
|
||||
*
|
||||
* @param vm The VM to which the port I/O handlers are registered
|
||||
*/
|
||||
void register_pio_default_emulation_handler(struct acrn_vm *vm);
|
||||
|
||||
/**
|
||||
* @brief Register MMIO default handler
|
||||
*
|
||||
* @param vm The VM to which the MMIO handler is registered
|
||||
*/
|
||||
void register_mmio_default_emulation_handler(struct acrn_vm *vm);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
Reference in New Issue
Block a user