From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org, "Marc-André Lureau" <marcandre.lureau@redhat.com>
Cc: "Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Alex Bennée" <alex.bennee@linaro.org>,
"Magnus Damm" <magnus.damm@gmail.com>,
"Thomas Huth" <huth@tuxfamily.org>,
"Shin'ichiro Kawasaki" <shinichiro.kawasaki@wdc.com>,
"Rayhan Faizel" <rayhan.faizel@gmail.com>,
qemu-arm@nongnu.org,
"Evgeny Iakovlev" <eiakovlev@linux.microsoft.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Luc Michel" <luc.michel@amd.com>,
"Yoshinori Sato" <ysato@users.sourceforge.jp>
Subject: [PATCH v2 9/9] hw/char/sh_serial: Return correct number of empty RX FIFO elements
Date: Thu, 20 Feb 2025 10:29:02 +0100 [thread overview]
Message-ID: <20250220092903.3726-10-philmd@linaro.org> (raw)
In-Reply-To: <20250220092903.3726-1-philmd@linaro.org>
In the IOCanReadHandler sh_serial_can_receive(), if the Serial
Control Register 'Receive Enable' bit is set (bit 4), then we
return a size of (1 << 4) which happens to be equal to 16, so
effectively SH_RX_FIFO_LENGTH.
The IOReadHandler, sh_serial_receive1() takes care to receive
multiple chars, but if the FIFO is partly filled, we only process
the number of free slots in the FIFO, discarding the other chars!
Fix by returning how many elements the FIFO can queue in the
IOCanReadHandler, so we don't have to process more than that in
the IOReadHandler, thus not discarding anything.
Remove the now unnecessary check on 's->rx_cnt < SH_RX_FIFO_LENGTH'
in IOReadHandler, reducing the block indentation.
Fixes: 63242a007a1 ("SH4: Serial controller improvement")
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Luc Michel <luc.michel@amd.com>
---
hw/char/sh_serial.c | 30 ++++++++++++++----------------
1 file changed, 14 insertions(+), 16 deletions(-)
diff --git a/hw/char/sh_serial.c b/hw/char/sh_serial.c
index 247aeb071ac..41c8175a638 100644
--- a/hw/char/sh_serial.c
+++ b/hw/char/sh_serial.c
@@ -320,7 +320,7 @@ static uint64_t sh_serial_read(void *opaque, hwaddr offs,
static int sh_serial_can_receive(SHSerialState *s)
{
- return s->scr & (1 << 4);
+ return s->scr & (1 << 4) ? SH_RX_FIFO_LENGTH - s->rx_head : 0;
}
static void sh_serial_receive_break(SHSerialState *s)
@@ -353,22 +353,20 @@ static void sh_serial_receive1(void *opaque, const uint8_t *buf, int size)
if (s->feat & SH_SERIAL_FEAT_SCIF) {
int i;
for (i = 0; i < size; i++) {
- if (s->rx_cnt < SH_RX_FIFO_LENGTH) {
- s->rx_fifo[s->rx_head++] = buf[i];
- if (s->rx_head == SH_RX_FIFO_LENGTH) {
- s->rx_head = 0;
- }
- s->rx_cnt++;
- if (s->rx_cnt >= s->rtrg) {
- s->flags |= SH_SERIAL_FLAG_RDF;
- if (s->scr & (1 << 6) && s->rxi) {
- timer_del(&s->fifo_timeout_timer);
- qemu_set_irq(s->rxi, 1);
- }
- } else {
- timer_mod(&s->fifo_timeout_timer,
- qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + 15 * s->etu);
+ s->rx_fifo[s->rx_head++] = buf[i];
+ if (s->rx_head == SH_RX_FIFO_LENGTH) {
+ s->rx_head = 0;
+ }
+ s->rx_cnt++;
+ if (s->rx_cnt >= s->rtrg) {
+ s->flags |= SH_SERIAL_FLAG_RDF;
+ if (s->scr & (1 << 6) && s->rxi) {
+ timer_del(&s->fifo_timeout_timer);
+ qemu_set_irq(s->rxi, 1);
}
+ } else {
+ timer_mod(&s->fifo_timeout_timer,
+ qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + 15 * s->etu);
}
}
} else {
--
2.47.1
next prev parent reply other threads:[~2025-02-20 9:31 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-20 9:28 [PATCH v2 0/9] hw/char: Improve RX FIFO depth uses Philippe Mathieu-Daudé
2025-02-20 9:28 ` [PATCH v2 1/9] hw/char/pl011: Warn when using disabled receiver Philippe Mathieu-Daudé
2025-02-20 9:52 ` Luc Michel
2025-02-20 9:28 ` [PATCH v2 2/9] hw/char/pl011: Simplify a bit pl011_can_receive() Philippe Mathieu-Daudé
2025-02-23 17:45 ` Richard Henderson
2025-02-20 9:28 ` [PATCH v2 3/9] hw/char/pl011: Improve RX flow tracing events Philippe Mathieu-Daudé
2025-02-23 17:49 ` Richard Henderson
2025-02-20 9:28 ` [PATCH v2 4/9] hw/char/pl011: Really use RX FIFO depth Philippe Mathieu-Daudé
2025-02-23 18:02 ` Richard Henderson
2025-02-20 9:28 ` [PATCH v2 5/9] hw/char/bcm2835_aux: " Philippe Mathieu-Daudé
2025-02-23 18:02 ` Richard Henderson
2025-02-20 9:28 ` [PATCH v2 6/9] hw/char/imx_serial: " Philippe Mathieu-Daudé
2025-02-23 18:03 ` Richard Henderson
2025-02-24 11:04 ` Bernhard Beschow
2025-02-20 9:29 ` [PATCH v2 7/9] hw/char/mcf_uart: Use FIFO_DEPTH definition instead of magic values Philippe Mathieu-Daudé
2025-02-21 10:10 ` Thomas Huth
2025-02-23 18:04 ` Richard Henderson
2025-02-20 9:29 ` [PATCH v2 8/9] hw/char/mcf_uart: Really use RX FIFO depth Philippe Mathieu-Daudé
2025-02-22 9:41 ` Thomas Huth
2025-02-23 18:04 ` Richard Henderson
2025-02-20 9:29 ` Philippe Mathieu-Daudé [this message]
2025-02-23 18:07 ` [PATCH v2 9/9] hw/char/sh_serial: Return correct number of empty RX FIFO elements Richard Henderson
2025-03-03 12:38 ` [PATCH v2 0/9] hw/char: Improve RX FIFO depth uses Philippe Mathieu-Daudé
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=20250220092903.3726-10-philmd@linaro.org \
--to=philmd@linaro.org \
--cc=alex.bennee@linaro.org \
--cc=eiakovlev@linux.microsoft.com \
--cc=huth@tuxfamily.org \
--cc=luc.michel@amd.com \
--cc=magnus.damm@gmail.com \
--cc=marcandre.lureau@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=rayhan.faizel@gmail.com \
--cc=shinichiro.kawasaki@wdc.com \
--cc=ysato@users.sourceforge.jp \
/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).