From: Oleksii Kurochko <oleksii.kurochko@gmail.com>
To: dmukhin@ford.com, xen-devel@lists.xenproject.org
Cc: andrew.cooper3@citrix.com, anthony.perard@vates.tech,
jbeulich@suse.com, julien@xen.org, michal.orzel@amd.com,
roger@xenproject.org, sstabellini@kernel.org,
xakep.amatop@gmail.com, dmukhin@xen.org
Subject: Re: [PATCH v8 09/26] emul/ns16x50: implement MCR/MSR registers
Date: Tue, 17 Nov 2026 19:32:38 +0100 [thread overview]
Message-ID: <4f8ecef8-0c2f-43df-bd03-036e1e3f2be9@gmail.com> (raw)
In-Reply-To: <20261111194800.1070016-10-dmukhin@ford.com>
On 11/11/26 8:47 PM, dmukhin@ford.com wrote:
> From: Denis Mukhin <dmukhin@ford.com>
>
> Add MCR/MSR registers emulation to the I/O port handler.
>
> Add implementation of ns16x50_iir_check_msi().
>
> Signed-off-by: Denis Mukhin <dmukhin@ford.com>
> ---
> xen/common/emul/vuart/ns16x50.c | 76 ++++++++++++++++++++++++++++++++-
> 1 file changed, 75 insertions(+), 1 deletion(-)
>
> diff --git a/xen/common/emul/vuart/ns16x50.c b/xen/common/emul/vuart/ns16x50.c
> index e80815ccf6e2..9f530e589495 100644
> --- a/xen/common/emul/vuart/ns16x50.c
> +++ b/xen/common/emul/vuart/ns16x50.c
> @@ -69,6 +69,10 @@ do { \
> */
> #define UART_LSR_MASK (UART_LSR_OE | UART_LSR_BI)
>
> +#define UART_MCR_MASK (UART_MCR_DTR | UART_MCR_RTS | \
> + UART_MCR_OUT1 | UART_MCR_OUT2 | \
> + UART_MCR_LOOP)
> +
> /*
> * Number of supported registers in the UART.
> */
> @@ -136,7 +140,7 @@ static bool cf_check ns16x50_iir_check_thr(const struct vuart_ns16x50 *vdev)
>
> static bool cf_check ns16x50_iir_check_msi(const struct vuart_ns16x50 *vdev)
> {
> - return false;
> + return vdev->regs[UART_MSR] & UART_MSR_CHANGE;
> }
>
> /*
> @@ -193,6 +197,13 @@ static void ns16x50_irq_check(struct vuart_ns16x50 *vdev)
> uint8_t iir = ns16x50_iir_get(vdev);
> bool asserted = !(iir & UART_IIR_NOINT);
>
> + /*
> + * On a PC-compatible UART OUT2 gates the ISA interrupt.
> + * Linux'es autoconfig_irq() expects when it toggles MCR.OUT2 during IRQ
> + * probing.
> + */
> + asserted &= !!(vdev->regs[UART_MCR] & UART_MCR_OUT2);
> +
> if ( asserted == vdev->irq_asserted )
> return;
>
> @@ -254,12 +265,63 @@ static int ns16x50_io_write8(
> regs[UART_LCR] = val;
> break;
>
> + case UART_MCR: {
Nit: I think '{' should be on the next line.
> + uint8_t msr_curr, msr_next, msr_delta;
> +
> + msr_curr = regs[UART_MSR];
> + msr_next = 0;
> + msr_delta = 0;
> +
> + if ( val & UART_MCR_RSRVD0 )
> + ns16x50_warn(vdev, "MCR: attempt to set reserved bit: %#x\n",
> + UART_MCR_RSRVD0);
> +
> + if ( val & UART_MCR_TCRTLR )
> + ns16x50_warn(vdev, "MCR: not supported: %#x\n",
> + UART_MCR_TCRTLR);
> +
> + if ( val & UART_MCR_RSRVD1 )
> + ns16x50_warn(vdev, "MCR: attempt to set reserved bit: %#x\n",
> + UART_MCR_RSRVD1);
> +
See my reply to 02/26: bit 5 is AFE on the TL16C550C itself. With a
local mask, these three checks become one
"if ( val & ~UART_MCR_MASK )".
> + /* Set modem status */
> + if ( val & UART_MCR_LOOP )
> + {
I am curious if loopback mode used somewhere except PC? I did a trace
for RISC-V for example and I see only the following writes to MCR:
0x00, 0x01, 0x09, 0x0b.
> + if ( val & UART_MCR_DTR )
> + msr_next |= UART_MSR_DSR;
> + if ( val & UART_MCR_RTS )
> + msr_next |= UART_MSR_CTS;
> + if ( val & UART_MCR_OUT1 )
> + msr_next |= UART_MSR_RI;
> + if ( val & UART_MCR_OUT2 )
> + msr_next |= UART_MSR_DCD;
> + }
> + else
> + msr_next |= UART_MSR_DCD | UART_MSR_DSR | UART_MSR_CTS;
> +
> + /* Calculate changes in modem status */
> + if ( (msr_curr & UART_MSR_CTS) ^ (msr_next & UART_MSR_CTS) )
> + msr_delta |= UART_MSR_DCTS;
> + if ( (msr_curr & UART_MSR_DSR) ^ (msr_next & UART_MSR_DSR) )
> + msr_delta |= UART_MSR_DDSR;
> + if ( !(msr_curr & UART_MSR_RI) && (msr_next & UART_MSR_RI) )
> + msr_delta |= UART_MSR_TERI;
This is the leading edge. MSR.RI is the complement of the RI input, and
TERI is set when the input goes from low to high (SLLS177I, 7.7.10, bits
2 and 6), i.e. when MSR.RI goes from 1 to 0. QEMU does the same
(hw/char/serial.c: "UART_MSR_TERI only if change was from 1 -> 0"). So:
if ( (msr_curr & UART_MSR_RI) && !(msr_next & UART_MSR_RI) )
> + if ( (msr_curr & UART_MSR_DCD) ^ (msr_next & UART_MSR_DCD) )
> + msr_delta |= UART_MSR_DDCD;
> +
> + regs[UART_MCR] = val & UART_MCR_MASK;
> + regs[UART_MSR] = msr_next | msr_delta;
This drops delta bits that are still pending. The change bits are only
cleared "when the CPU reads the MSR" (7.7.10), so e.g. with DTR and RTS
toggled by two separate MCR writes in loopback mode before the guest
reads MSR, ΔCTS from the first write is lost. Keeping them:
regs[UART_MSR] = msr_next | msr_delta |
(msr_curr & UART_MSR_CHANGE);ч
> +
> + break;
> + }
> +
~ Oleksii
next prev parent reply other threads:[~2026-11-17 18:32 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-11 19:47 [PATCH v8 00/26] x86: introduce NS16550-compatible UART emulator dmukhin
2026-11-11 19:47 ` [PATCH v8 01/26] emul/vuart: introduce framework for UART emulators dmukhin
2026-11-12 15:35 ` Oleksii Kurochko
2026-11-11 19:47 ` [PATCH v8 02/26] xen/8250-uart: update definitions dmukhin
2026-11-12 14:49 ` Jan Beulich
2026-11-12 16:34 ` Oleksii Kurochko
2026-11-11 19:47 ` [PATCH v8 03/26] x86: fixup dependencies for asm/x86_emulate.h dmukhin
2026-11-12 20:25 ` Oleksii Kurochko
2026-11-13 7:20 ` Jan Beulich
2026-11-11 19:47 ` [PATCH v8 04/26] emul/ns16x50: implement emulator stub dmukhin
2026-11-13 11:48 ` Oleksii Kurochko
2026-11-11 19:47 ` [PATCH v8 05/26] emul/ns16x50: implement DLL/DLM registers dmukhin
2026-11-16 10:36 ` Oleksii Kurochko
2026-11-11 19:47 ` [PATCH v8 06/26] emul/ns16x50: implement SCR register dmukhin
2026-11-16 10:42 ` Oleksii Kurochko
2026-11-11 19:47 ` [PATCH v8 07/26] emul/ns16x50: implement IER/IIR registers dmukhin
2026-11-16 16:59 ` Oleksii Kurochko
2026-11-11 19:47 ` [PATCH v8 08/26] emul/ns16x50: implement LCR/LSR registers dmukhin
2026-11-17 16:33 ` Oleksii Kurochko
2026-11-11 19:47 ` [PATCH v8 09/26] emul/ns16x50: implement MCR/MSR registers dmukhin
2026-11-17 18:32 ` Oleksii Kurochko [this message]
2026-11-11 19:47 ` [PATCH v8 10/26] emul/ns16x50: implement RBR register dmukhin
2026-11-11 19:47 ` [PATCH v8 11/26] emul/ns16x50: implement THR register dmukhin
2026-11-11 19:47 ` [PATCH v8 12/26] emul/ns16x50: implement FCR register (write-only) dmukhin
2026-11-11 19:47 ` [PATCH v8 13/26] emul/ns16550: implement dump_state() hook dmukhin
2026-11-11 19:47 ` [PATCH v8 14/26] emul/vuart: add global UART emulator configuration knob dmukhin
2026-11-11 19:47 ` [PATCH v8 15/26] emul/ns16x50: enable emulator dmukhin
2026-11-11 19:47 ` [PATCH v8 16/26] emul/ns16x50: add Kconfig options dmukhin
2026-11-11 19:47 ` [PATCH v8 17/26] x86/domain: enable per-domain I/O port bitmaps dmukhin
2026-11-11 19:47 ` [PATCH v8 18/26] emul/ns16x50: resolve physical I/O port sharing dmukhin
2026-11-11 19:47 ` [PATCH v8 19/26] xen/domain: allocate d->irq_caps before arch-specific initialization dmukhin
2026-11-11 19:47 ` [PATCH v8 20/26] emul/ns16x50: resolve physical IRQ sharing dmukhin
2026-11-11 19:47 ` [PATCH v8 21/26] emul/ns16x50: implement IRQ emulation via vIOAPIC dmukhin
2026-11-11 19:47 ` [PATCH v8 22/26] MAINTAINERS: add myself as vUART framework maintainer dmukhin
2026-11-11 19:47 ` [PATCH v8 23/26] docs/fusa: add NS16x50 UART requirements for x86 dmukhin
2026-11-11 19:47 ` [PATCH v8 24/26] ci: add initial NS16550-compatible XTF test dmukhin
2026-11-11 19:47 ` [PATCH v8 25/26] ci: add smoke NS16550-compatible PVH Linux test dmukhin
2026-11-11 19:48 ` [PATCH v8 26/26] ci: do not merge: test dmukhin
2026-11-12 14:53 ` [PATCH v8 00/26] x86: introduce NS16550-compatible UART emulator Oleksii Kurochko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4f8ecef8-0c2f-43df-bd03-036e1e3f2be9@gmail.com \
--to=oleksii.kurochko@gmail.com \
--cc=andrew.cooper3@citrix.com \
--cc=anthony.perard@vates.tech \
--cc=dmukhin@ford.com \
--cc=dmukhin@xen.org \
--cc=jbeulich@suse.com \
--cc=julien@xen.org \
--cc=michal.orzel@amd.com \
--cc=roger@xenproject.org \
--cc=sstabellini@kernel.org \
--cc=xakep.amatop@gmail.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.