qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2 2/2] hw/char: sifive_uart: Print uart charecters async


From: Thomas Huth
Subject: Re: [PATCH v2 2/2] hw/char: sifive_uart: Print uart charecters async
Date: Tue, 3 Sep 2024 07:53:59 +0200
User-agent: Mozilla Thunderbird

On 19/08/2024 13.31, Alistair Francis wrote:
The current approach of using qemu_chr_fe_write() and ignoring the
return values results in dropped charecters [1].

s/charecters/characters/g

(also in the subject of the patch)

Let's update the SiFive UART to use a async sifive_uart_xmit() function
to transmit the charecters and apply back preassure to the guest with

s/preassure/pressure/

the SIFIVE_UART_TXFIFO_FULL status.

This should avoid dropped charecters and more realisiticly model the

s/realisiticly/realisticly/

hardware.

1: https://gitlab.com/qemu-project/qemu/-/issues/2114

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
---
  include/hw/char/sifive_uart.h | 17 ++++++-
  hw/char/sifive_uart.c         | 88 +++++++++++++++++++++++++++++++++--
  2 files changed, 99 insertions(+), 6 deletions(-)

diff --git a/include/hw/char/sifive_uart.h b/include/hw/char/sifive_uart.h
index 7f6c79f8bd..b43109bb8b 100644
--- a/include/hw/char/sifive_uart.h
+++ b/include/hw/char/sifive_uart.h
@@ -24,6 +24,7 @@
  #include "hw/qdev-properties.h"
  #include "hw/sysbus.h"
  #include "qom/object.h"
+#include "qemu/fifo8.h"
enum {
      SIFIVE_UART_TXFIFO        = 0,
@@ -48,9 +49,13 @@ enum {
      SIFIVE_UART_IP_RXWM       = 2  /* Receive watermark interrupt pending */
  };
+#define SIFIVE_UART_TXFIFO_FULL 0x80000000
+
  #define SIFIVE_UART_GET_TXCNT(txctrl)   ((txctrl >> 16) & 0x7)
  #define SIFIVE_UART_GET_RXCNT(rxctrl)   ((rxctrl >> 16) & 0x7)
+
  #define SIFIVE_UART_RX_FIFO_SIZE 8
+#define SIFIVE_UART_TX_FIFO_SIZE 8
#define TYPE_SIFIVE_UART "riscv.sifive.uart"
  OBJECT_DECLARE_SIMPLE_TYPE(SiFiveUARTState, SIFIVE_UART)
@@ -63,13 +68,21 @@ struct SiFiveUARTState {
      qemu_irq irq;
      MemoryRegion mmio;
      CharBackend chr;
-    uint8_t rx_fifo[SIFIVE_UART_RX_FIFO_SIZE];
-    uint8_t rx_fifo_len;
+
+    uint32_t txfifo;
      uint32_t ie;
      uint32_t ip;
      uint32_t txctrl;
      uint32_t rxctrl;
      uint32_t div;
+
+    uint8_t rx_fifo[SIFIVE_UART_RX_FIFO_SIZE];
+    uint8_t rx_fifo_len;
+
+    Fifo8 tx_fifo;
+
+    QEMUTimer *fifo_trigger_handle;
+    uint64_t char_tx_time;
  };
SiFiveUARTState *sifive_uart_create(MemoryRegion *address_space, hwaddr base,
diff --git a/hw/char/sifive_uart.c b/hw/char/sifive_uart.c
index 7fc6787f69..07730e241c 100644
--- a/hw/char/sifive_uart.c
+++ b/hw/char/sifive_uart.c
@@ -64,6 +64,72 @@ static void sifive_uart_update_irq(SiFiveUARTState *s)
      }
  }
+static gboolean sifive_uart_xmit(void *do_not_use, GIOCondition cond,
+                                 void *opaque)
+{
+    SiFiveUARTState *s = opaque;
+    int ret;
+    const uint8_t *charecters;
+    uint32_t numptr = 0;
+
+    /* instant drain the fifo when there's no back-end */
+    if (!qemu_chr_fe_backend_connected(&s->chr)) {
+        fifo8_reset(&s->tx_fifo);
+        return G_SOURCE_REMOVE;
+    }
+
+    if (fifo8_is_empty(&s->tx_fifo)) {
+        return G_SOURCE_REMOVE;
+    }
+
+    /* Don't pop the FIFO incase the write fails */

s/incase/in case/

+    charecters = fifo8_peek_bufptr(&s->tx_fifo,
+                                   fifo8_num_used(&s->tx_fifo), &numptr);
+    ret = qemu_chr_fe_write(&s->chr, charecters, numptr);
+
+    if (ret >= 0) {
+        /* We wrote the data, actuallly pop the fifo */

s/actuallly/actually/

I recommend running checkpatch.pl with the --codespell flag ;-)

Anyway, this indeed seems to fix the problem with the avocado test, thank you very much for tackling this!

Tested-by: Thomas Huth <thuth@redhat.com>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]