From: Evgeny Iakovlev <eiakovlev@linux.microsoft.com>
To: qemu-arm@nongnu.org
Cc: qemu-devel@nongnu.org, marcandre.lureau@redhat.com,
pbonzini@redhat.com, peter.maydell@linaro.org
Subject: [PATCH 2/2] hw/char/pl011: check if UART is enabled before RX or TX operation
Date: Fri, 6 Jan 2023 18:28:51 +0100 [thread overview]
Message-ID: <20230106172851.2430-3-eiakovlev@linux.microsoft.com> (raw)
In-Reply-To: <20230106172851.2430-1-eiakovlev@linux.microsoft.com>
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>
---
hw/char/pl011.c | 22 +++++++++++++++++++---
1 file changed, 19 insertions(+), 3 deletions(-)
diff --git a/hw/char/pl011.c b/hw/char/pl011.c
index 9108ed2be9..fcc2600944 100644
--- a/hw/char/pl011.c
+++ b/hw/char/pl011.c
@@ -54,6 +54,11 @@
#define INT_E (INT_OE | INT_BE | INT_PE | INT_FE)
#define INT_MS (INT_RI | INT_DSR | INT_DCD | INT_CTS)
+/* UARTCR bits */
+#define PL011_CR_UARTEN (1 << 0)
+#define PL011_CR_TXE (1 << 8)
+#define PL011_CR_RXE (1 << 9)
+
static const unsigned char pl011_id_arm[8] =
{ 0x11, 0x10, 0x14, 0x00, 0x0d, 0xf0, 0x05, 0xb1 };
static const unsigned char pl011_id_luminary[8] =
@@ -203,6 +208,11 @@ static void pl011_trace_baudrate_change(const PL011State *s)
s->ibrd, s->fbrd);
}
+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)
{
@@ -213,7 +223,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 */
@@ -284,7 +296,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)) {
+ r = 0;
+ } else {
+ r = s->read_count < pl011_get_fifo_depth(s);
+ }
trace_pl011_can_receive(s->lcr, s->read_count, r);
return r;
}
@@ -405,7 +421,7 @@ static void pl011_init(Object *obj)
s->read_trigger = 1;
s->ifl = 0x12;
- s->cr = 0x300;
+ s->cr = PL011_CR_RXE | PL011_CR_TXE;
pl011_reset_pipe(s);
s->id = pl011_id_arm;
--
2.34.1
next prev parent reply other threads:[~2023-01-06 17:29 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-06 17:28 [PATCH 0/2] Series of fixes for PL011 char device Evgeny Iakovlev
2023-01-06 17:28 ` [PATCH 1/2] hw/char/pl011: better handling of FIFO flags on LCR reset Evgeny Iakovlev
2023-01-17 15:24 ` Peter Maydell
2023-01-17 15:54 ` Evgeny Iakovlev
2023-01-17 16:02 ` Peter Maydell
2023-01-17 22:06 ` eiakovlev
2023-01-06 17:28 ` Evgeny Iakovlev [this message]
2023-01-17 15:38 ` [PATCH 2/2] hw/char/pl011: check if UART is enabled before RX or TX operation Peter Maydell
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=20230106172851.2430-3-eiakovlev@linux.microsoft.com \
--to=eiakovlev@linux.microsoft.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 \
/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).