From: Zhang Zheng <zhangzheng@iscas.ac.cn>
To: Oleksii Kurochko <oleksii.kurochko@gmail.com>
Cc: xen-devel@lists.xenproject.org,
"Alistair Francis" <alistair.francis@wdc.com>,
"Connor Davis" <connojdavis@gmail.com>,
"Baptiste Le Duc" <baptiste.le-duc@vates.tech>,
"Andrew Cooper" <andrew.cooper3@citrix.com>,
"Anthony PERARD" <anthony.perard@vates.tech>,
"Michal Orzel" <michal.orzel@amd.com>,
"Jan Beulich" <jbeulich@suse.com>,
"Julien Grall" <julien@xen.org>,
"Roger Pau Monné" <roger@xenproject.org>,
"Stefano Stabellini" <sstabellini@kernel.org>
Subject: Re: [PATCH v2 2/2] xen/ns16550: drain TX before reinitializing
Date: Thu, 15 Oct 2026 14:48:40 +0800 [thread overview]
Message-ID: <atB3OZfluh6Ceeni@iscas-ws> (raw)
In-Reply-To: <ec65306d-ec1d-4c5a-93f8-b37f7dfea8b5@gmail.com>
On Mon, Oct 12, 2026 at 12:20:50PM +0200, Oleksii Kurochko wrote:
>
>
> On 10/10/26 5:14 AM, Zhang Zheng wrote:
> > An SBI console call may return before the UART finishes transmitting.
> > Wait for UART_LSR_TEMT before ns16550 reprograms the UART and clears its
> > FIFO, preserving pending early-console output and legacy SBI v0.1 support.
>
> The problem isn't really specific to SBI: anything that wrote to the UART
> before ns16550 takes over (firmware, a bootloader, or Xen's own early
> console) can leave data in the TX FIFO or the shift register. I'd
> describe it in those terms.
Agreed.
> Could the comment say why the wait is needed at this point? Something
> like:
>
> /*
> * Output written before ns16550 takes over (e.g. by firmware or the
> * early console) may still be in the transmitter. Let it drain before
> * ns16550_setup_preirq() reprograms the line settings and resets the
> * FIFOs.
> */
>
Thanks, I will use it in next version.
> > + while ( !(ns_read_reg(uart, UART_LSR) & UART_LSR_TEMT) )
> > + cpu_relax();
> > +
>
> IMO waiting for TEMT rather than THRE is the right choice: besides
> resetting the FIFOs, ns16550_setup_preirq() reprograms the divisor and
> LCR, which would corrupt a character still being shifted out. (Linux
> waits for UART_LSR_BOTH_EMPTY, i.e. THRE | TEMT, but on a 16550 TEMT
> already implies THRE.)
>
Yes, I followed the Linux implementation, which waits in an unbounded loop
and theck UART_LSR_BOTH_EMPTY like you said:
for (;;) {
status = serial8250_early_in(port, UART_LSR);
if (uart_lsr_tx_empty(status)) /* checks UART_LSR_BOTH_EMPTY */
break;
cpu_relax();
}
So I didn't have timeout handling
Zhang
next prev parent reply other threads:[~2026-10-15 6:49 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-10 3:14 [PATCH v2 0/2] xen/ns16550: preserve UART operation across firmware handover Zhang Zheng
2026-10-10 3:14 ` [PATCH v2 1/2] xen/ns16550: detect and preserve UART_IER_UUE Zhang Zheng
2026-10-10 22:11 ` Baptiste Le Duc
2026-10-12 9:27 ` Oleksii Kurochko
2026-10-15 3:22 ` Zhang Zheng
2026-10-12 9:20 ` Oleksii Kurochko
2026-10-12 12:50 ` Jan Beulich
2026-10-12 13:24 ` Oleksii Kurochko
2026-10-15 4:50 ` Zhang Zheng
2026-10-15 3:44 ` Zhang Zheng
2026-10-12 12:52 ` Jan Beulich
2026-10-15 4:40 ` Zhang Zheng
2026-10-15 7:16 ` Jan Beulich
[not found] ` <20261010031406.2057735-3-zhangzheng@iscas.ac.cn>
2026-10-10 22:13 ` [PATCH v2 2/2] xen/ns16550: drain TX before reinitializing Baptiste Le Duc
2026-10-12 10:20 ` Oleksii Kurochko
2026-10-12 12:56 ` Jan Beulich
2026-10-12 13:25 ` Oleksii Kurochko
2026-10-15 4:52 ` Zhang Zheng
2026-10-12 13:00 ` Jan Beulich
2026-10-15 4:46 ` Zhang Zheng
2026-10-15 6:48 ` Zhang Zheng [this message]
[not found] ` <atB2HqxU_D481PBk@iscas-ws>
2026-10-15 7:54 ` Oleksii Kurochko
2026-10-15 8:49 ` Zhang Zheng
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=atB3OZfluh6Ceeni@iscas-ws \
--to=zhangzheng@iscas.ac.cn \
--cc=alistair.francis@wdc.com \
--cc=andrew.cooper3@citrix.com \
--cc=anthony.perard@vates.tech \
--cc=baptiste.le-duc@vates.tech \
--cc=connojdavis@gmail.com \
--cc=jbeulich@suse.com \
--cc=julien@xen.org \
--cc=michal.orzel@amd.com \
--cc=oleksii.kurochko@gmail.com \
--cc=roger@xenproject.org \
--cc=sstabellini@kernel.org \
--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.