From: Zhao Liu <zhao1.liu@intel.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org, philmd@linaro.org, qemu-rust@nongnu.org
Subject: Re: [PATCH 2/7] rust: pl011: match break logic of C version
Date: Thu, 19 Dec 2024 12:38:43 +0800 [thread overview]
Message-ID: <Z2OjU3CdoBFI7xA8@intel.com> (raw)
In-Reply-To: <20241212172209.533779-3-pbonzini@redhat.com>
On Thu, Dec 12, 2024 at 06:21:59PM +0100, Paolo Bonzini wrote:
> Date: Thu, 12 Dec 2024 18:21:59 +0100
> From: Paolo Bonzini <pbonzini@redhat.com>
> Subject: [PATCH 2/7] rust: pl011: match break logic of C version
> X-Mailer: git-send-email 2.47.1
>
> Check loopback_enabled(), not fifo_enabled(), like the C code.
>
> Also, set_break_error() must not happen until the break is read from
> the FIFO.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> rust/hw/char/pl011/src/device.rs | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
Now the logic here matches C version, so
Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
But...
> diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs
> index 41220c99a83..c6a8dbe1af4 100644
> --- a/rust/hw/char/pl011/src/device.rs
> +++ b/rust/hw/char/pl011/src/device.rs
> @@ -465,9 +465,8 @@ pub fn can_receive(&self) -> bool {
> }
>
> pub fn event(&mut self, event: QEMUChrEvent) {
> - if event == bindings::QEMUChrEvent::CHR_EVENT_BREAK && !self.fifo_enabled() {
> + if event == bindings::QEMUChrEvent::CHR_EVENT_BREAK && !self.loopback_enabled() {
> self.put_fifo(DATA_BREAK);
> - self.receive_status_error_clear.set_break_error(true);
> }
> }
>
...but when I double-check where to set up the rsr, I realized that the
rust version and the C version seem to be inconsistent?
C:
static uint32_t pl011_read_rxdata(PL011State *s)
{
...
c = s->read_fifo[s->read_pos];
...
s->rsr = c >> 8;
...
}
Rust:
pub fn read(&mut self, offset: hwaddr, _size: c_uint) -> std::ops::ControlFlow<u64, u64> {
...
std::ops::ControlFlow::Break(match RegisterOffset::try_from(offset) {
...
Ok(DR) => {
...
let c = self.read_fifo[self.read_pos];
...
// Update error bits.
self.receive_status_error_clear = c.to_be_bytes()[3].into();
...
}
...
}
`to_be_bytes()` retures a byte array in big-endian byte order [*], so rust
accesses the first 8 bits and C accesses the last 24 bits, am I understanding
this correctly and which one is correct?
IIUC, I guess Rust should uses to_be_bytes()[2].
[*]: https://doc.rust-lang.org/std/primitive.u32.html#method.to_be_bytes
Regards,
Zhao
next prev parent reply other threads:[~2024-12-19 4:20 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-12 17:21 [PATCH 0/7] rust: pl011: bug fixes Paolo Bonzini
2024-12-12 17:21 ` [PATCH 1/7] rust: pl011: fix declaration of LineControl bits Paolo Bonzini
2024-12-18 13:23 ` Philippe Mathieu-Daudé
2024-12-19 3:42 ` Zhao Liu
2024-12-12 17:21 ` [PATCH 2/7] rust: pl011: match break logic of C version Paolo Bonzini
2024-12-18 13:18 ` Philippe Mathieu-Daudé
2024-12-19 4:38 ` Zhao Liu [this message]
2024-12-19 6:31 ` Paolo Bonzini
2024-12-12 17:22 ` [PATCH 3/7] rust: pl011: always use reset() method on registers Paolo Bonzini
2024-12-18 13:28 ` Philippe Mathieu-Daudé
2024-12-19 6:55 ` Zhao Liu
2024-12-12 17:22 ` [PATCH 4/7] rust: pl011: fix break errors and definition of Data struct Paolo Bonzini
2024-12-18 14:49 ` Philippe Mathieu-Daudé
2024-12-19 7:17 ` Zhao Liu
2024-12-12 17:22 ` [PATCH 5/7] rust: pl011: extend registers to 32 bits Paolo Bonzini
2024-12-18 13:43 ` Philippe Mathieu-Daudé
2024-12-19 7:30 ` Zhao Liu
2024-12-12 17:22 ` [PATCH 6/7] rust: pl011: fix migration stream Paolo Bonzini
2024-12-18 14:50 ` Philippe Mathieu-Daudé
2024-12-19 7:52 ` Zhao Liu
2024-12-12 17:22 ` [PATCH 7/7] rust: pl011: simplify handling of the FIFO enabled bit in LCR Paolo Bonzini
2024-12-18 13:20 ` Philippe Mathieu-Daudé
2024-12-19 7:55 ` Zhao Liu
2024-12-18 11:17 ` [PATCH 0/7] rust: pl011: bug fixes 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=Z2OjU3CdoBFI7xA8@intel.com \
--to=zhao1.liu@intel.com \
--cc=pbonzini@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-rust@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 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.