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

Re: [PATCH v8 08/26] emul/ns16x50: implement LCR/LSR registers





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

Add LCR/LSR registers implementation to the I/O port handler.

Add implementation of ns16x50_dlab_get() and ns16x50_iir_check_lsi().

There's no ns16x50_dlab_get() in this patch, or anywhere in the series;
DLAB is tested open-coded as regs[UART_LCR] & UART_LCR_DLAB. Either the
sentence is stale or the helper got lost (a helper would indeed be nice,
as that expression appears four times by now).


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

diff --git a/xen/common/emul/vuart/ns16x50.c b/xen/common/emul/vuart/ns16x50.c
index 7c5cdc99cfa7..e80815ccf6e2 100644
--- a/xen/common/emul/vuart/ns16x50.c
+++ b/xen/common/emul/vuart/ns16x50.c
@@ -64,6 +64,11 @@ do { \
  #define ns16x50_debug(vdev, fmt, args...) \
      ns16x50_log(3, XENLOG_DEBUG, vdev, fmt, ## args)
+/*
+ * Helper register definitions.
+ */

Nit: Single line comment should be enough here so please use /* ... */

+#define UART_LSR_MASK           (UART_LSR_OE | UART_LSR_BI)

Nit: this is local to the emulator, but uses the UART_ prefix of
xen/8250-uart.h, so it looks like a register definition from there. Also
"MASK" doesn't say what it is: these are the LSR bits that raise the LSI
and are cleared by reading LSR. On a 16550 that's all four error bits
(OE, PE, FE, BI); the emulator never sets PE and FE (nor BI, as far as I
can see), but including them would match the datasheet and cost
nothing. Maybe NS16X50_LSR_ERRORS?

+
  /*
   * Number of supported registers in the UART.
   */


Nit: Single line comment should be enough here so please use /* ... */

@@ -116,7 +121,7 @@ static inline void ns16x50_unlock(struct vuart_ns16x50 
*vdev,
static bool cf_check ns16x50_iir_check_lsi(const struct vuart_ns16x50 *vdev)
  {
-    return false;
+    return vdev->regs[UART_LSR] & UART_LSR_MASK;
  }
static bool cf_check ns16x50_iir_check_rda(const struct vuart_ns16x50 *vdev)
@@ -245,11 +250,16 @@ static int ns16x50_io_write8(
          }
          break;
+ case UART_LCR:
+        regs[UART_LCR] = val;
+        break;
+
      /* NB: Firmware (e.g. OVMF) may rely on SCR presence. */
      case UART_SCR:
          regs[UART_SCR] = val;
          break;
+ case UART_LSR: /* RO */
      default:

A write to LSR (or later MSR) ends up in ns16x50_err(), i.e. a
guest-triggerable error message per access. Real 16550s ignore such
writes (the TL16C550C datasheet only says writing LSR isn't
recommended), so silently ignoring them, or at most a debug message,
seems more appropriate. The same applies to the other "unsupported
access" paths in ns16x50_access().

          rc = -EINVAL;
          break;
@@ -346,6 +356,15 @@ static int ns16x50_io_read8(
          val = ns16x50_iir_get(vdev);
          break;
+ case UART_LCR:
+        val = regs[UART_LCR];
+        break;
+
+    case UART_LSR:
+        val = regs[UART_LSR];
+        regs[UART_LSR] = val & ~UART_LSR_MASK;
+        break;
+
      case UART_SCR:
          val = regs[UART_SCR];
          break;
@@ -509,6 +528,8 @@ static void ns16x50_reset(struct vuart_ns16x50 *vdev)
      memset(vdev->regs, 0, sizeof(vdev->regs));
      vdev->irq_asserted = false;
+ vdev->regs[UART_LSR] = UART_LSR_THRE | UART_LSR_TEMT;
+

Matches the 16550 reset value of LSR (0x60).

      /* NB: report 115200 baud rate. */
      vdev->regs[NS16X50_REGS_NUM + UART_DLL] = divisor & UINT8_MAX;
      vdev->regs[NS16X50_REGS_NUM + UART_DLM] = (divisor >> 8) & UINT8_MAX;

~ Oleksii



 


Rackspace

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