All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kuan-Wei Chiu <visitorckw@gmail.com>
To: Yifan Wang <w-yf22@mails.tsinghua.edu.cn>
Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org,
	qemu-block@nongnu.org, kvm@vger.kernel.org,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"Pierrick Bouvier" <pierrick.bouvier@oss.qualcomm.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Alistair Francis" <alistair@alistair23.me>,
	"Kevin Wolf" <kwolf@redhat.com>,
	"Hanna Reitz" <hreitz@redhat.com>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	bin.meng@processmission.com, tangtao1634@phytium.com.cn,
	"Chao Liu" <chao.liu@processmission.com>
Subject: Re: [RFC PATCH 01/20] hw/char/dw8250: implement the UART status register
Date: Sat, 28 Nov 2026 21:17:33 +0800	[thread overview]
Message-ID: <awrUbRVDRJWkfjD1@google.com> (raw)
In-Reply-To: <b5f1bddaaa4e4d16aaba94267475140c8e6be74b.1794555589.git.w-yf22@mails.tsinghua.edu.cn>

On Fri, Nov 13, 2026 at 05:47:35PM +0800, Yifan Wang wrote:
> From: Chao Liu <chao.liu@processmission.com>
> 
> The Rock 5B machine runs a vendor U-Boot and Linux that read the UART
> status register to check the transmitter and FIFO state. Implement the
> register.
> 
> Signed-off-by: Chao Liu <chao.liu@processmission.com>
> Signed-off-by: Yifan Wang <w-yf22@mails.tsinghua.edu.cn>
> ---
>  hw/char/dw8250.c | 43 +++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 43 insertions(+)
> 
> diff --git a/hw/char/dw8250.c b/hw/char/dw8250.c
> index 50baeae62c..4f9a8ea989 100644
> --- a/hw/char/dw8250.c
> +++ b/hw/char/dw8250.c
> @@ -6,6 +6,7 @@
>   */
>  
>  #include "qemu/osdep.h"
> +#include "qemu/bitops.h"
>  #include "qemu/log.h"
>  #include "qapi/error.h"
>  #include "hw/char/dw8250.h"
> @@ -14,20 +15,62 @@
>  
>  #define DW_UART_REGION_SIZE 0x100
>  
> +#define DW_UART_USR   (0x7C >> 2) /* UART Status Register */
>  #define DW_UART_RE_EN (0xB4 >> 2) /* Receiver Output Enable Register */
>  #define DW_UART_DLF   (0xC0 >> 2) /* Divisor Latch Fraction Register */
>  #define DW_UART_CPR   (0xF4 >> 2) /* Component Parameter Register */
>  #define DW_UART_UCV   (0xF8 >> 2) /* UART Component Version */
>  #define DW_UART_CTR   (0xFC >> 2) /* Component Type Register */
>  
> +/* UART Status Register bits */
> +#define DW_UART_USR_BUSY BIT(0) /* UART busy */
> +#define DW_UART_USR_TFNF BIT(1) /* Transmit FIFO not full */
> +#define DW_UART_USR_TFE  BIT(2) /* Transmit FIFO empty */
> +#define DW_UART_USR_RFNE BIT(3) /* Receive FIFO not empty */
> +#define DW_UART_USR_RFF  BIT(4) /* Receive FIFO full */
> +
> +/* FIFO Control Register bits */
> +#define DW_UART_FCR_FIFO_EN BIT(0) /* FIFO enable */
> +
> +/* Line Status Register bits */
> +#define DW_UART_LSR_DR   BIT(0) /* Receiver data ready */
> +#define DW_UART_LSR_THRE BIT(5) /* Transmitter holding register empty */
> +#define DW_UART_LSR_TEMT BIT(6) /* Transmitter empty */

Aren't these standard 16550A register bits already defined in
hw/char/serial.c?

Regards,
Kuan-Wei

> +
>  #define DW_UART_UCV_VALUE 0x3332332A /* "323*" -> v3.23a */
>  #define DW_UART_CTR_VALUE 0x44570110 /* "DW" */
>  
>  static uint64_t dw8250_ext_read(void *opaque, hwaddr addr, unsigned int size)
>  {
>      DW8250State *s = opaque;
> +    SerialState *serial = &s->serial_mm.serial;
>  
>      switch (addr >> s->regshift) {
> +    case DW_UART_USR: {
> +        bool fifo_enabled = serial->fcr & DW_UART_FCR_FIFO_EN;
> +        bool thr_empty = serial->lsr & DW_UART_LSR_THRE;
> +        bool tx_idle = serial->lsr & DW_UART_LSR_TEMT;
> +        bool rx_ready = serial->lsr & DW_UART_LSR_DR;
> +        bool tx_empty;
> +        bool tx_full;
> +        bool rx_full;
> +
> +        if (fifo_enabled) {
> +            tx_empty = fifo8_is_empty(&serial->xmit_fifo);
> +            tx_full = fifo8_is_full(&serial->xmit_fifo);
> +            rx_full = fifo8_is_full(&serial->recv_fifo);
> +        } else {
> +            tx_empty = thr_empty;
> +            tx_full = !thr_empty;
> +            rx_full = rx_ready;
> +        }
> +
> +        return (!tx_idle ? DW_UART_USR_BUSY : 0) |
> +               (!tx_full ? DW_UART_USR_TFNF : 0) |
> +               (tx_empty ? DW_UART_USR_TFE : 0) |
> +               (rx_ready ? DW_UART_USR_RFNE : 0) |
> +               (rx_full ? DW_UART_USR_RFF : 0);
> +    }
>      case DW_UART_UCV:
>          return DW_UART_UCV_VALUE;
>      case DW_UART_CPR:
> -- 
> 2.53.0
> 

  reply	other threads:[~2026-11-28 13:17 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-13  9:47 [RFC PATCH 00/20] hw/arm: Add initial RK3588 and ROCK 5B support Yifan Wang
2026-11-13  9:47 ` [RFC PATCH 01/20] hw/char/dw8250: implement the UART status register Yifan Wang
2026-11-28 13:17   ` Kuan-Wei Chiu [this message]
2026-11-13  9:47 ` [RFC PATCH 02/20] hw/char/dw8250: expose the baudbase property Yifan Wang
2026-11-13  9:47 ` [RFC PATCH 03/20] target/arm: report SMCCC v1.1 support Yifan Wang
2026-11-13  9:47 ` [RFC PATCH 04/20] target/arm: allow machines to handle SMC calls Yifan Wang
2026-11-13  9:47 ` [RFC PATCH 05/20] hw/block/m25p80: add the XTX XT25F128 SPI NOR flash Yifan Wang
2026-11-13  9:47 ` [RFC PATCH 06/20] hw/arm: add the Rockchip RK3588 SoC Yifan Wang
2026-11-13  9:47 ` [RFC PATCH 07/20] hw/timer: add Rockchip HPTIMER boot control Yifan Wang
2026-11-13  9:47 ` [RFC PATCH 08/20] hw/arm/rk3588: add the unimplemented device map Yifan Wang
2026-11-13  9:47 ` [RFC PATCH 09/20] hw/arm/rk3588: add the GICv3 interrupt controller Yifan Wang
2026-11-13  9:47 ` [RFC PATCH 10/20] hw/arm/rk3588: add the UARTs Yifan Wang
2026-11-13  9:47 ` [RFC PATCH 11/20] hw/misc: add the RK3588 clock and reset unit Yifan Wang
2026-11-13  9:47 ` [RFC PATCH 12/20] hw/misc: add the RK3588 OTP controller Yifan Wang
2026-11-13  9:47 ` [RFC PATCH 13/20] hw/ssi: add the Rockchip SPI flash controller Yifan Wang
2026-11-13  9:47 ` [RFC PATCH 14/20] hw/misc: add RK3588 SCMI server Yifan Wang
2026-11-13  9:47 ` [RFC PATCH 15/20] hw/arm/rk3588: wire up the " Yifan Wang
2026-11-13  9:47 ` [RFC PATCH 16/20] hw/arm: add Radxa ROCK 5B board Yifan Wang
2026-11-13  9:47 ` [RFC PATCH 17/20] hw/arm/rock-5b: connect the XTX XT25F128 SPI NOR flash Yifan Wang
2026-11-13  9:47 ` [RFC PATCH 18/20] hw/arm/rock-5b: add firmware booting Yifan Wang
2026-11-13  9:47 ` [RFC PATCH 19/20] tests/functional: add ROCK 5B boot tests Yifan Wang
2026-11-13  9:47 ` [RFC PATCH 20/20] docs/system/arm: document the Radxa ROCK 5B machine Yifan Wang

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=awrUbRVDRJWkfjD1@google.com \
    --to=visitorckw@gmail.com \
    --cc=alistair@alistair23.me \
    --cc=bin.meng@processmission.com \
    --cc=chao.liu@processmission.com \
    --cc=hreitz@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=kwolf@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=pierrick.bouvier@oss.qualcomm.com \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=tangtao1634@phytium.com.cn \
    --cc=w-yf22@mails.tsinghua.edu.cn \
    /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.