[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v5 13/16] hw/char/pl011: Introduce pl011_xmit() as GSource
From: |
Philippe Mathieu-Daudé |
Subject: |
[PATCH v5 13/16] hw/char/pl011: Introduce pl011_xmit() as GSource |
Date: |
Fri, 19 Jul 2024 20:10:38 +0200 |
Extract pl011_xmit() from pl011_write_txdata(). Use the
FIFO to pass the character to be transmitted.
Implement it using the FEWatchFunc prototype, since we want
to register it as GSource later. While the return value is
not yet used, we return G_SOURCE_REMOVE meaning the GSource
is removed from the main loop (because we only send one char).
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
hw/char/pl011.c | 30 +++++++++++++++++++++++++-----
hw/char/trace-events | 2 ++
2 files changed, 27 insertions(+), 5 deletions(-)
diff --git a/hw/char/pl011.c b/hw/char/pl011.c
index 6519340b50..6394d6eb36 100644
--- a/hw/char/pl011.c
+++ b/hw/char/pl011.c
@@ -226,6 +226,28 @@ static void pl011_loopback_tx(PL011State *s, uint32_t
value)
pl011_fifo_rx_put(s, value);
}
+static gboolean pl011_xmit(void *do_not_use, GIOCondition cond, void *opaque)
+{
+ PL011State *s = opaque;
+ int bytes_consumed;
+ uint8_t data;
+
+ data = 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, &data, bytes_consumed);
+ trace_pl011_fifo_tx_xmit(bytes_consumed);
+ s->int_level |= INT_TX;
+
+ pl011_update(s);
+
+ return G_SOURCE_REMOVE;
+}
+
static void pl011_write_txdata(PL011State *s, uint8_t data)
{
if (!(s->cr & CR_UARTEN)) {
@@ -235,12 +257,10 @@ static void pl011_write_txdata(PL011State *s, uint8_t
data)
qemu_log_mask(LOG_GUEST_ERROR, "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);
+ pl011_xmit(NULL, G_IO_OUT, s);
}
static uint32_t pl011_read_rxdata(PL011State *s)
diff --git a/hw/char/trace-events b/hw/char/trace-events
index 59e1f734a7..30d06a2383 100644
--- a/hw/char/trace-events
+++ b/hw/char/trace-events
@@ -60,6 +60,8 @@ pl011_write(uint32_t addr, uint32_t value, const char
*regname) "addr 0x%03x val
pl011_can_receive(uint32_t lcr, int read_count, int r) "LCR 0x%08x read_count
%d returning %d"
pl011_fifo_rx_put(uint32_t c, int read_count) "new char 0x%02x read_count now
%d"
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(int count) "TX FIFO pop %d 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 ")"
# cmsdk-apb-uart.c
--
2.41.0
- [PATCH v5 04/16] hw/char/pl011: Move pl011_loopback_enabled|tx() around, (continued)
- [PATCH v5 04/16] hw/char/pl011: Move pl011_loopback_enabled|tx() around, Philippe Mathieu-Daudé, 2024/07/19
- [PATCH v5 05/16] hw/char/pl011: Split RX/TX path of pl011_reset_fifo(), Philippe Mathieu-Daudé, 2024/07/19
- [PATCH v5 06/16] hw/char/pl011: Extract pl011_write_txdata() from pl011_write(), Philippe Mathieu-Daudé, 2024/07/19
- [PATCH v5 07/16] hw/char/pl011: Extract pl011_read_rxdata() from pl011_read(), Philippe Mathieu-Daudé, 2024/07/19
- [PATCH v5 08/16] hw/char/pl011: Warn when using disabled transmitter, Philippe Mathieu-Daudé, 2024/07/19
- [PATCH v5 09/16] tests/qtest: Update tests using PL011 UART, Philippe Mathieu-Daudé, 2024/07/19
- [PATCH v5 10/16] hw/char/pl011: Check if receiver is enabled, Philippe Mathieu-Daudé, 2024/07/19
- [PATCH v5 13/16] hw/char/pl011: Introduce pl011_xmit() as GSource,
Philippe Mathieu-Daudé <=
- [PATCH v5 11/16] hw/char/pl011: Rename RX FIFO methods, Philippe Mathieu-Daudé, 2024/07/19
- [RFC PATCH v5 16/16] hw/char/pl011: Implement TX FIFO, Philippe Mathieu-Daudé, 2024/07/19
- [PATCH v5 12/16] hw/char/pl011: Add transmit FIFO to PL011State, Philippe Mathieu-Daudé, 2024/07/19
- [PATCH v5 15/16] hw/char/pl011: Drain TX FIFO when no backend connected, Philippe Mathieu-Daudé, 2024/07/19
- [PATCH v5 14/16] hw/char/pl011: Consider TX FIFO overrun error, Philippe Mathieu-Daudé, 2024/07/19