HV: vuart: refine vuart read/write

The vuart_read()/vuart_write() are coupled with PIO vuart type. Move
the non-type related code into vuart_read_reg()/vuart_write_reg(), so
that we can re-use them to handle MMIO request of pci-vuart type.

Tracked-On: #5394
Signed-off-by: Tao Yuhong <yuhong.tao@intel.com>
Reviewed-by: Wang, Yu1 <yu1.wang@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
Tao Yuhong 2020-10-09 06:28:13 -04:00 committed by wenlingz
parent 8e545734d4
commit 6ed7b8767c
2 changed files with 123 additions and 102 deletions

View File

@ -362,21 +362,14 @@ static void write_reg(struct acrn_vuart *vu, uint16_t reg, uint8_t value_u8)
release_vuart_lock(vu, rflags);
}
/**
* @pre vcpu != NULL
* @pre vcpu->vm != NULL
/*
* @pre: vu != NULL
*/
static bool vuart_write(struct acrn_vcpu *vcpu, uint16_t offset_arg,
__unused size_t width, uint32_t value)
void vuart_write_reg(struct acrn_vuart *vu, uint16_t offset, uint8_t value_u8)
{
uint16_t offset = offset_arg;
struct acrn_vuart *vu = find_vuart_by_port(vcpu->vm, offset);
uint8_t value_u8 = (uint8_t)value;
struct acrn_vuart *target_vu = NULL;
uint64_t rflags;
if (vu != NULL) {
offset -= vu->port_base;
target_vu = vu->target_vu;
if (((vu->mcr & MCR_LOOPBACK) == 0U) && ((vu->lcr & LCR_DLAB) == 0U)
@ -391,6 +384,22 @@ static bool vuart_write(struct acrn_vcpu *vcpu, uint16_t offset_arg,
} else {
write_reg(vu, offset, value_u8);
}
}
/**
* @pre vcpu != NULL
* @pre vcpu->vm != NULL
*/
static bool vuart_write(struct acrn_vcpu *vcpu, uint16_t offset_arg,
__unused size_t width, uint32_t value)
{
uint16_t offset = offset_arg;
struct acrn_vuart *vu = find_vuart_by_port(vcpu->vm, offset);
uint8_t value_u8 = (uint8_t)value;
if (vu != NULL) {
offset -= vu->port_base;
vuart_write_reg(vu, offset, value_u8);
}
return true;
}
@ -412,21 +421,15 @@ static void notify_target(const struct acrn_vuart *vu)
}
/**
* @pre vcpu != NULL
* @pre vcpu->vm != NULL
* @pre vu != NULL
*/
static bool vuart_read(struct acrn_vcpu *vcpu, uint16_t offset_arg, __unused size_t width)
uint8_t vuart_read_reg(struct acrn_vuart *vu, uint16_t offset)
{
uint16_t offset = offset_arg;
uint8_t iir, reg, intr_reason;
struct acrn_vuart *vu = find_vuart_by_port(vcpu->vm, offset);
struct acrn_vuart *t_vu;
struct pio_request *pio_req = &vcpu->req.reqs.pio;
uint8_t iir, reg = 0U, intr_reason;
uint64_t rflags;
if (vu != NULL) {
t_vu = vu->target_vu;
offset -= vu->port_base;
obtain_vuart_lock(vu, rflags);
/*
* Take care of the special case DLAB accesses first
@ -500,17 +503,32 @@ static bool vuart_read(struct acrn_vcpu *vcpu, uint16_t offset_arg, __unused siz
}
}
vuart_toggle_intr(vu);
pio_req->value = (uint32_t)reg;
release_vuart_lock(vu, rflags);
}
/* For commnunication vuart, when the data in FIFO is read out, should
* notify the target vuart to send more data. */
if (offset == UART16550_RBR) {
notify_target(vu);
}
return reg;
}
/**
* @pre vcpu != NULL
* @pre vcpu->vm != NULL
*/
static bool vuart_read(struct acrn_vcpu *vcpu, uint16_t offset_arg, __unused size_t width)
{
uint16_t offset = offset_arg;
struct acrn_vuart *vu = find_vuart_by_port(vcpu->vm, offset);
struct pio_request *pio_req = &vcpu->req.reqs.pio;
if (vu != NULL) {
offset -= vu->port_base;
pio_req->value = (uint32_t)vuart_read_reg(vu, offset);
}
return true;
}

View File

@ -89,4 +89,7 @@ char vuart_getchar(struct acrn_vuart *vu);
void vuart_toggle_intr(const struct acrn_vuart *vu);
bool is_vuart_intx(const struct acrn_vm *vm, uint32_t intx_gsi);
uint8_t vuart_read_reg(struct acrn_vuart *vu, uint16_t offset);
void vuart_write_reg(struct acrn_vuart *vu, uint16_t offset, uint8_t value);
#endif /* VUART_H */