qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: Evgeny Iakovlev <eiakovlev@linux.microsoft.com>, qemu-arm@nongnu.org
Cc: qemu-devel@nongnu.org, peter.maydell@linaro.org
Subject: Re: [PATCH v3 5/5] hw/char/pl011: check if UART is enabled before RX or TX operation
Date: Mon, 23 Jan 2023 09:14:21 +0100	[thread overview]
Message-ID: <fc01ef6d-73d7-af1a-3e59-bd4f1e3e83ba@linaro.org> (raw)
In-Reply-To: <20230120155447.31702-6-eiakovlev@linux.microsoft.com>

On 20/1/23 16:54, Evgeny Iakovlev wrote:
> UART should be enabled in general and have RX enabled specifically to be
> able to receive data from peripheral device. Same goes for transmitting
> data to peripheral device and a TXE flag.
> 
> Check if UART CR register has EN and RXE or TXE bits enabled before
> trying to receive or transmit data.
> 
> Signed-off-by: Evgeny Iakovlev <eiakovlev@linux.microsoft.com>
> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>   hw/char/pl011.c | 22 +++++++++++++++++++---
>   1 file changed, 19 insertions(+), 3 deletions(-)

> +static inline bool pl011_can_transmit(PL011State *s)
> +{
> +    return s->cr & PL011_CR_UARTEN && s->cr & PL011_CR_TXE;
> +}
> +
>   static void pl011_write(void *opaque, hwaddr offset,
>                           uint64_t value, unsigned size)
>   {
> @@ -221,7 +231,9 @@ static void pl011_write(void *opaque, hwaddr offset,
>   
>       switch (offset >> 2) {
>       case 0: /* UARTDR */
> -        /* ??? Check if transmitter is enabled.  */
> +        if (!pl011_can_transmit(s)) {
> +            break;
> +        }
>           ch = value;
>           /* XXX this blocks entire thread. Rewrite to use
>            * qemu_chr_fe_write and background I/O callbacks */
> @@ -292,7 +304,11 @@ static int pl011_can_receive(void *opaque)
>       PL011State *s = (PL011State *)opaque;
>       int r;
>   
> -    r = s->read_count < pl011_get_fifo_depth(s);
> +    if (!(s->cr & PL011_CR_UARTEN) || !(s->cr & PL011_CR_RXE)) {

Maybe add pl011_can_receive() similarly to pl011_can_transmit().

Otherwise:
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>

> +        r = 0;
> +    } else {
> +        r = s->read_count < pl011_get_fifo_depth(s);
> +    }
>       trace_pl011_can_receive(s->lcr, s->read_count, r);
>       return r;
>   }



  reply	other threads:[~2023-01-23  8:15 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-20 15:54 [PATCH v3 0/5] Series of fixes for PL011 char device Evgeny Iakovlev
2023-01-20 15:54 ` [PATCH v3 1/5] hw/char/pl011: refactor FIFO depth handling code Evgeny Iakovlev
2023-01-20 18:23   ` Peter Maydell
2023-01-23  7:29   ` Philippe Mathieu-Daudé
2023-01-20 15:54 ` [PATCH v3 2/5] hw/char/pl011: add post_load hook for backwards-compatibility Evgeny Iakovlev
2023-01-20 18:22   ` Peter Maydell
2023-01-23 14:39     ` Evgeny Iakovlev
2023-01-20 15:54 ` [PATCH v3 3/5] hw/char/pl011: implement a reset method Evgeny Iakovlev
2023-01-20 18:23   ` Peter Maydell
2023-01-23  7:25   ` Philippe Mathieu-Daudé
2023-01-20 15:54 ` [PATCH v3 4/5] hw/char/pl011: better handling of FIFO flags on LCR reset Evgeny Iakovlev
2023-01-20 18:23   ` Peter Maydell
2023-01-20 15:54 ` [PATCH v3 5/5] hw/char/pl011: check if UART is enabled before RX or TX operation Evgeny Iakovlev
2023-01-23  8:14   ` Philippe Mathieu-Daudé [this message]
2023-01-23 14:43     ` Evgeny Iakovlev
2023-01-23 15:21       ` Philippe Mathieu-Daudé
2023-01-23 15:59         ` Evgeny Iakovlev
2023-01-23 16:09           ` Evgeny Iakovlev
2023-01-23 16:45             ` Philippe Mathieu-Daudé
2023-01-23 16:23         ` Peter Maydell
2023-01-23 16:41           ` Philippe Mathieu-Daudé
2023-01-25 14:50             ` Evgeny Iakovlev

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=fc01ef6d-73d7-af1a-3e59-bd4f1e3e83ba@linaro.org \
    --to=philmd@linaro.org \
    --cc=eiakovlev@linux.microsoft.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).