diff mbox series

[11/11] rust/pl011: log guest/unimp errors

Message ID 20241024-rust-round-2-v1-11-051e7a25b978@linaro.org (mailing list archive)
State New
Headers show
Series Rust device model patches and misc cleanups | expand

Commit Message

Manos Pitsidianakis Oct. 24, 2024, 2:03 p.m. UTC
Use the qemu_log_mask() functions introduced in previous commit to log
errors like the C pl011 device does.

Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
---
 rust/hw/char/pl011/src/device.rs | 37 +++++++++++++++++++++++++++++++------
 1 file changed, 31 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs
index 6d1353dafc14bfe73703b5cff7e1ff7659de220e..57b38f44f90d74d0c1a94bb9144eff08db94fadf 100644
--- a/rust/hw/char/pl011/src/device.rs
+++ b/rust/hw/char/pl011/src/device.rs
@@ -9,6 +9,7 @@ 
 
 use qemu_api::{
     bindings::{self, *},
+    log::*,
     objects::*,
     vmstate_clock, vmstate_fields, vmstate_int32, vmstate_subsections, vmstate_uint32,
     vmstate_uint32_array, vmstate_unused,
@@ -343,7 +344,14 @@  pub fn read(
                 u64::from(self.device_id[(offset - 0xfe0) >> 2])
             }
             Err(_) => {
-                // qemu_log_mask(LOG_GUEST_ERROR, "pl011_read: Bad offset 0x%x\n", (int)offset);
+                qemu_log_mask(
+                    LogMask::GUEST_ERROR,
+                    &format!(
+                        "pl011:{file}:{line}: Bad offset 0x{offset:x}",
+                        file = file!(),
+                        line = line!(),
+                    ),
+                );
                 0
             }
             Ok(DR) => {
@@ -389,15 +397,30 @@  pub fn read(
     }
 
     pub fn write(&mut self, offset: hwaddr, value: u64) {
-        // eprintln!("write offset {offset} value {value}");
         use RegisterOffset::*;
         let value: u32 = value as u32;
         match RegisterOffset::try_from(offset) {
             Err(_bad_offset) => {
-                eprintln!("write bad offset {offset} value {value}");
+                qemu_log_mask(
+                    LogMask::GUEST_ERROR,
+                    &format!(
+                        "pl011:{file}:{line}: Bad write offset 0x{offset:x} of value 0x:{value:x}",
+                        file = file!(),
+                        line = line!(),
+                    ),
+                );
             }
             Ok(DR) => {
-                // ??? Check if transmitter is enabled.
+                // Check if transmitter is enabled.
+                if !self.control.enable_uart() {
+                    qemu_log_mask(LogMask::GUEST_ERROR, "PL011 data written to disabled UART");
+                }
+                if !self.control.enable_transmit() {
+                    qemu_log_mask(
+                        LogMask::GUEST_ERROR,
+                        "PL011 data written to disabled TX UART",
+                    );
+                }
                 let ch: u8 = value as u8;
                 // XXX this blocks entire thread. Rewrite to use
                 // qemu_chr_fe_write and background I/O callbacks
@@ -474,8 +497,10 @@  pub fn write(&mut self, offset: hwaddr, value: u64) {
             Ok(DMACR) => {
                 self.dmacr = value;
                 if value & 3 > 0 {
-                    // qemu_log_mask(LOG_UNIMP, "pl011: DMA not implemented\n");
-                    eprintln!("pl011: DMA not implemented");
+                    qemu_log_mask(
+                        LogMask::UNIMPLEMENTED,
+                        "pl011: DMA functionality is not implemented",
+                    );
                 }
             }
         }