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

Re: [PATCH v8 12/26] emul/ns16x50: implement FCR register (write-only)





On 11/11/26 8:47 PM, dmukhin@xxxxxxxx wrote:
From: Denis Mukhin <dmukhin@xxxxxxxx>

Add emulation logic for FCR register.

Note, that does not hook FIFO interrupt moderation to the FIFO
management code for simplicity.

Signed-off-by: Denis Mukhin <dmukhin@xxxxxxxx>
---
  xen/common/emul/vuart/ns16x50.c | 33 +++++++++++++++++++++++++++++++++
  1 file changed, 33 insertions(+)

diff --git a/xen/common/emul/vuart/ns16x50.c b/xen/common/emul/vuart/ns16x50.c
index 8d3845a8a4cd..404e12311090 100644
--- a/xen/common/emul/vuart/ns16x50.c
+++ b/xen/common/emul/vuart/ns16x50.c
@@ -436,6 +436,39 @@ static int ns16x50_io_write8(
          }
          break;
+ case UART_FCR: /* WO */
+        if ( val & UART_FCR_RSRVD0 )
+            ns16x50_warn(vdev, "FCR: attempt to set reserved bit: %x\n",
+                         UART_FCR_RSRVD0);

Bits 4 and 5 are indeed reserved on the TL16C550C ("reserved for future
use"), so warning is fine; with a local mask (02/26) the two checks
collapse into one. Nit: %#x, as in the MCR warnings.

+
+        if ( val & UART_FCR_RSRVD1 )
+            ns16x50_warn(vdev, "FCR: attempt to set reserved bit: %x\n",
+                         UART_FCR_RSRVD1);
+
+        if ( val & UART_FCR_CLRX )
+        {
+            ns16x50_fifo_rx_reset(vdev);
+            regs[UART_LSR] &= ~UART_LSR_DR;
+        }

One of the places that keeps LSR.DR in sync by hand, see 10/26.

+
+        if ( val & UART_FCR_CLTX )
+        {
+            ns16x50_fifo_tx_reset(vdev);

The TX "FIFO" here is the line buffer of 11/26: everything in it has
already been reported to the guest as transmitted (THRE and TEMT are
set again right after each THR write), it just hasn't been printed yet
because no newline arrived. Resetting it discards output the guest
considers sent, e.g. a prompt without a trailing newline, whenever the
guest clears the TX FIFO. Linux does that in serial8250_do_startup()
and serial8250_do_shutdown(), via serial8250_clear_fifos(). Since TEMT
says the transmitter is empty, there is nothing left to clear from the
guest's point of view; I'd flush the buffer here instead of dropping
it (or leave it alone).
        
+
+            regs[UART_LSR] |= UART_LSR_THRE | UART_LSR_TEMT;
+            vdev->thr_pending = true;
+        }
+
+        if ( val & UART_FCR_ENABLE )
+            val &= UART_FCR_ENABLE | UART_FCR_DMA |
+                   UART_FCR_RTB0 | UART_FCR_RTB1;
+        else
+            val = 0;

The datasheet (SLLS177I, 7.7.2) also says for bit 0: "Changing this bit
clears the FIFOs", which isn't emulated: toggling FCR.ENABLE without
CLRX/CLTX leaves stale RX data in place. QEMU handles it by forcing
both clear bits when the enable bit changes:

    if ((val ^ s->fcr) & UART_FCR_FE) {
        val |= UART_FCR_XFR | UART_FCR_RFR;
    }

(and with the above, the TX part would then be a flush rather than a
drop.)

As for the mask, UART_FCR_RTB0 | UART_FCR_RTB1 is UART_FCR_TRG14, see
my reply to 02/26.

+
+        regs[UART_FCR] = val;
+
+        break;
+
      case UART_LCR:
          regs[UART_LCR] = val;
          break;

~ Oleksii



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.