All of lore.kernel.org
 help / color / mirror / Atom feed
From: dmukhin@xen.org
To: Mykola Kvach <xakep.amatop@gmail.com>
Cc: xen-devel@lists.xenproject.org, andrew.cooper3@citrix.com,
	anthony.perard@vates.tech, jbeulich@suse.com, julien@xen.org,
	michal.orzel@amd.com, roger.pau@citrix.com,
	sstabellini@kernel.org, dmukhin@ford.com
Subject: Re: [PATCH v6 04/15] emul/ns16x50: implement DLL/DLM registers
Date: Sun, 7 Sep 2025 23:41:29 -0700	[thread overview]
Message-ID: <aL56mf3H4/TohRFZ@kraken> (raw)
In-Reply-To: <CAGeoDV9wbhkDr7MSOVCZoiu8xqzmtwPY4hUdBtmeZiNKqj8=-w@mail.gmail.com>

On Sun, Sep 07, 2025 at 12:12:08AM +0300, Mykola Kvach wrote:
> Hi Denis,
> 
> On Sat, Sep 6, 2025 at 3:11 AM <dmukhin@xen.org> wrote:
> >
> > From: Denis Mukhin <dmukhin@ford.com>
> >
> > Add DLL/DLM registers emulation.
> >
> > DLL/DLM registers report hardcoded 115200 baud rate to the guest OS.
> >
> > Add stub for ns16x50_dlab_get() helper.
> >
> > Signed-off-by: Denis Mukhin <dmukhin@ford.com>
> > ---
> > Changes since v5:
> > - dropped ns16x50_dlab_get() hunk (moved to emulator stub)
> > - Link to v5: https://lore.kernel.org/xen-devel/20250828235409.2835815-5-dmukhin@ford.com/
> > ---
> >  xen/common/emul/vuart/ns16x50.c | 29 +++++++++++++++++++++++++++++
> >  1 file changed, 29 insertions(+)
> >
> > diff --git a/xen/common/emul/vuart/ns16x50.c b/xen/common/emul/vuart/ns16x50.c
> > index 0462a961e785..7f479a5be4a2 100644
> > --- a/xen/common/emul/vuart/ns16x50.c
> > +++ b/xen/common/emul/vuart/ns16x50.c
> > @@ -97,8 +97,13 @@ static uint8_t ns16x50_dlab_get(const struct vuart_ns16x50 *vdev)
> >  static int ns16x50_io_write8(
> >      struct vuart_ns16x50 *vdev, uint32_t reg, uint8_t *data)
> >  {
> > +    uint8_t *regs = vdev->regs;
> > +    uint8_t val = *data;
> >      int rc = 0;
> >
> > +    if ( ns16x50_dlab_get(vdev) && (reg == UART_DLL || reg == UART_DLM) )
> > +        regs[NS16X50_REGS_NUM + reg] = val;
> 
> Some documentation (e.g., DesignWare DW_apb_uart Databook, v3.04a)
> notes that if the Divisor Latch Registers (DLL and DLH) are set to
> zero, the baud clock is disabled and no serial communications occur.
> 
> Should we handle the zero-divisor case to emulate this behavior more
> accurately?

Good idea, thanks!
I will plumb zero-divisor logic into RBR/THR handling.

> 
> > +
> >      return rc;
> >  }
> >
> > @@ -109,8 +114,16 @@ static int ns16x50_io_write8(
> >  static int ns16x50_io_write16(
> >      struct vuart_ns16x50 *vdev, uint32_t reg, uint16_t *data)
> >  {
> > +    uint16_t val = *data;
> >      int rc = -EINVAL;
> >
> > +    if ( ns16x50_dlab_get(vdev) && reg == UART_DLL )
> > +    {
> > +        vdev->regs[NS16X50_REGS_NUM + UART_DLL] = val & 0xff;
> > +        vdev->regs[NS16X50_REGS_NUM + UART_DLM] = (val >> 8) & 0xff;
> 
> Instead of hardcoding 0xff here (and in similar lines below), consider
> using UINT8_MAX. This makes it explicit that the value is the maximum
> for a uint8_t and avoids magic numbers.

Thanks for suggestion!
Will update.


  reply	other threads:[~2025-09-08  6:41 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-05 23:26 [PATCH v6 00/15] x86: introduce NS16550-compatible UART emulator dmukhin
2025-09-05 23:27 ` [PATCH v6 01/15] emul/vuart: introduce framework for UART emulators dmukhin
2025-09-06  2:02   ` Stefano Stabellini
2025-09-06  9:43   ` Mykola Kvach
2025-09-08  7:16     ` dmukhin
2025-09-08  8:29   ` Mykola Kvach
2025-09-08  8:43     ` Jan Beulich
2025-09-08  9:45     ` dmukhin
2025-09-05 23:27 ` [PATCH v6 02/15] xen/8250-uart: update definitions dmukhin
2025-09-06  2:02   ` Stefano Stabellini
2025-09-06 14:57   ` Mykola Kvach
2025-09-08  8:36     ` dmukhin
2025-09-05 23:27 ` [PATCH v6 03/15] emul/ns16x50: implement emulator stub dmukhin
2025-09-06  0:34   ` dmukhin
2025-09-06  2:03   ` Stefano Stabellini
2025-09-06  4:18     ` dmukhin
2025-09-06 20:37   ` Mykola Kvach
2025-09-08  8:32     ` dmukhin
2025-09-08  8:37   ` Mykola Kvach
2025-09-08  9:59     ` dmukhin
2025-09-05 23:27 ` [PATCH v6 04/15] emul/ns16x50: implement DLL/DLM registers dmukhin
2025-09-06  2:03   ` Stefano Stabellini
2025-09-06 21:12   ` Mykola Kvach
2025-09-08  6:41     ` dmukhin [this message]
2025-09-05 23:27 ` [PATCH v6 05/15] emul/ns16x50: implement SCR register dmukhin
2025-09-06  2:03   ` Stefano Stabellini
2025-09-06 21:24   ` Mykola Kvach
2025-09-08  3:37     ` dmukhin
2025-09-05 23:27 ` [PATCH v6 06/15] emul/ns16x50: implement IER/IIR registers dmukhin
2025-09-06  1:42   ` Stefano Stabellini
2025-09-08  2:37     ` dmukhin
2025-09-05 23:27 ` [PATCH v6 07/15] emul/ns16x50: implement LCR/LSR registers dmukhin
2025-09-06  2:04   ` Stefano Stabellini
2025-09-05 23:27 ` [PATCH v6 08/15] emul/ns16x50: implement MCR/MSR registers dmukhin
2025-09-06  1:42   ` Stefano Stabellini
2025-09-08  2:35     ` dmukhin
2025-09-05 23:27 ` [PATCH v6 09/15] emul/ns16x50: implement RBR register dmukhin
2025-09-06  2:04   ` Stefano Stabellini
2025-09-05 23:27 ` [PATCH v6 10/15] emul/ns16x50: implement THR register dmukhin
2025-09-06  1:59   ` Stefano Stabellini
2025-09-08  2:50     ` dmukhin
2025-09-08  3:15       ` dmukhin
2025-09-05 23:27 ` [PATCH v6 11/15] emul/ns16x50: implement FCR register (write-only) dmukhin
2025-09-06  2:04   ` Stefano Stabellini
2025-09-05 23:27 ` [PATCH v6 12/15] emul/ns16550: implement dump_state() hook dmukhin
2025-09-05 23:27 ` [PATCH v6 13/15] x86/domain: enable per-domain I/O port bitmaps dmukhin
2025-09-05 23:27 ` [PATCH v6 14/15] xen/domain: allocate d->irq_caps before arch-specific initialization dmukhin
2025-09-05 23:27 ` [PATCH v6 15/15] emul/ns16x50: implement IRQ emulation via vIOAPIC dmukhin
2025-09-06  0:33 ` [PATCH v6 00/15] x86: introduce NS16550-compatible UART emulator dmukhin
2025-09-06  2:01 ` Stefano Stabellini
2025-09-08  9:04   ` Mykola Kvach
2025-09-08 14:19     ` Oleksii Kurochko
2025-09-08 14:23     ` Oleksii Kurochko
2025-09-08 23:51       ` Stefano Stabellini

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=aL56mf3H4/TohRFZ@kraken \
    --to=dmukhin@xen.org \
    --cc=andrew.cooper3@citrix.com \
    --cc=anthony.perard@vates.tech \
    --cc=dmukhin@ford.com \
    --cc=jbeulich@suse.com \
    --cc=julien@xen.org \
    --cc=michal.orzel@amd.com \
    --cc=roger.pau@citrix.com \
    --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.