Extract pl011_xmit() from pl011_write_txdata(). Use the FIFO to pass the single character to be transmitted. Update flags appropriately.
Reviewed-by: Peter Maydell <peter.mayd...@linaro.org> Signed-off-by: Philippe Mathieu-Daudé <phi...@linaro.org> --- hw/char/pl011.c | 43 ++++++++++++++++++++++++++++++++++++------- hw/char/trace-events | 3 +++ 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/hw/char/pl011.c b/hw/char/pl011.c index 0e9ad5d5d90..113b29cd9e6 100644 --- a/hw/char/pl011.c +++ b/hw/char/pl011.c @@ -226,6 +226,36 @@ static void pl011_loopback_tx(PL011State *s, uint32_t value) pl011_fifo_rx_put(s, value); } +static void pl011_xmit(PL011State *s) +{ + int bytes_consumed; + uint8_t buf[PL011_FIFO_DEPTH]; + uint32_t count; + bool emptied_fifo; + + count = fifo8_num_used(&s->xmit_fifo); + trace_pl011_fifo_tx_xmit_used(count); + + buf[0] = fifo8_pop(&s->xmit_fifo); + bytes_consumed = 1; + + /* + * XXX this blocks entire thread. Rewrite to use + * qemu_chr_fe_write and background I/O callbacks + */ + qemu_chr_fe_write_all(&s->chr, buf, bytes_consumed); + trace_pl011_fifo_tx_xmit_consumed(bytes_consumed); + s->int_level |= INT_TX; + s->flags &= ~PL011_FLAG_TXFF; + + emptied_fifo = fifo8_is_empty(&s->xmit_fifo); + if (emptied_fifo) { + s->flags |= PL011_FLAG_TXFE; + } + + pl011_update(s); +} + static void pl011_write_txdata(PL011State *s, uint8_t data) { if (!(s->cr & CR_UARTEN)) { @@ -237,14 +267,13 @@ static void pl011_write_txdata(PL011State *s, uint8_t data) "PL011 data written to disabled TX UART\n"); } - /* - * XXX this blocks entire thread. Rewrite to use - * qemu_chr_fe_write and background I/O callbacks - */ - qemu_chr_fe_write_all(&s->chr, &data, 1); + trace_pl011_fifo_tx_put(data); pl011_loopback_tx(s, data); - s->int_level |= INT_TX; - pl011_update(s); + fifo8_push(&s->xmit_fifo, data); + s->flags |= PL011_FLAG_TXFF; + s->flags &= ~PL011_FLAG_TXFE; + + pl011_xmit(s); } static uint32_t pl011_read_rxdata(PL011State *s) diff --git a/hw/char/trace-events b/hw/char/trace-events index 05a33036c12..1bab98fb5f3 100644 --- a/hw/char/trace-events +++ b/hw/char/trace-events @@ -65,6 +65,9 @@ pl011_write(uint32_t addr, uint32_t value, const char *regname) "addr 0x%03x val pl011_can_receive(uint32_t lcr, unsigned rx_fifo_used, size_t rx_fifo_depth, unsigned rx_fifo_available) "LCR 0x%02x, RX FIFO used %u/%zu, can_receive %u chars" pl011_fifo_rx_put(uint32_t c, unsigned read_count, size_t rx_fifo_depth) "RX FIFO push char [0x%02x] %d/%zu depth used" pl011_fifo_rx_full(void) "RX FIFO now full, RXFF set" +pl011_fifo_tx_put(uint8_t byte) "TX FIFO push char [0x%02x]" +pl011_fifo_tx_xmit_used(unsigned sent) "TX FIFO used %u chars" +pl011_fifo_tx_xmit_consumed(unsigned sent) "TX FIFO consumed %u chars" pl011_baudrate_change(unsigned int baudrate, uint64_t clock, uint32_t ibrd, uint32_t fbrd) "new baudrate %u (clk: %" PRIu64 "hz, ibrd: %" PRIu32 ", fbrd: %" PRIu32 ")" pl011_receive(int size) "recv %d chars" -- 2.47.1