Browse Source

Update extern crate volatile to 0.3

Yuekai Jia 3 years ago
parent
commit
fbc5970724
4 changed files with 22 additions and 6 deletions
  1. 1 1
      Cargo.toml
  2. 11 2
      src/console.rs
  3. 10 2
      src/gpu.rs
  4. 0 1
      src/header.rs

+ 1 - 1
Cargo.toml

@@ -8,6 +8,6 @@ description = "VirtIO guest drivers."
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 
 [dependencies]
-volatile = "0.2"
+volatile = "0.3"
 log = "0.4"
 bitflags = "1.3"

+ 11 - 2
src/console.rs

@@ -1,7 +1,7 @@
 use super::*;
 use crate::queue::VirtQueue;
 use bitflags::*;
-use core::hint::spin_loop;
+use core::{fmt, hint::spin_loop};
 use log::*;
 use volatile::{ReadOnly, WriteOnly};
 
@@ -97,7 +97,6 @@ impl<'a> VirtIOConsole<'a> {
 }
 
 #[repr(C)]
-#[derive(Debug)]
 struct Config {
     cols: ReadOnly<u16>,
     rows: ReadOnly<u16>,
@@ -105,6 +104,16 @@ struct Config {
     emerg_wr: WriteOnly<u32>,
 }
 
+impl fmt::Debug for Config {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        f.debug_struct("Config")
+            .field("cols", &self.cols)
+            .field("rows", &self.rows)
+            .field("max_nr_ports", &self.max_nr_ports)
+            .finish()
+    }
+}
+
 bitflags! {
     struct Features: u64 {
         const SIZE                  = 1 << 0;

+ 10 - 2
src/gpu.rs

@@ -1,7 +1,7 @@
 use super::*;
 use crate::queue::VirtQueue;
 use bitflags::*;
-use core::hint::spin_loop;
+use core::{fmt, hint::spin_loop};
 use log::*;
 use volatile::{ReadOnly, Volatile, WriteOnly};
 
@@ -163,7 +163,6 @@ impl VirtIOGpu<'_> {
 }
 
 #[repr(C)]
-#[derive(Debug)]
 struct Config {
     /// Signals pending events to the driver。
     events_read: ReadOnly<u32>,
@@ -177,6 +176,15 @@ struct Config {
     num_scanouts: Volatile<u32>,
 }
 
+impl fmt::Debug for Config {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        f.debug_struct("Config")
+            .field("events_read", &self.events_read)
+            .field("num_scanouts", &self.num_scanouts)
+            .finish()
+    }
+}
+
 /// Display configuration has changed.
 const EVENT_DISPLAY: u32 = 1 << 0;
 

+ 0 - 1
src/header.rs

@@ -6,7 +6,6 @@ use volatile::{ReadOnly, Volatile, WriteOnly};
 ///
 /// Ref: 4.2.4 Legacy interface
 #[repr(C)]
-#[derive(Debug)]
 pub struct VirtIOHeader {
     /// Magic value
     magic: ReadOnly<u32>,