summary refs log tree commit diff
diff options
context:
space:
mode:
authorDylan Reid <dgreid@chromium.org>2018-06-18 18:35:19 -0700
committerchrome-bot <chrome-bot@chromium.org>2018-09-10 17:17:35 -0700
commit67afe44f80936615ff87648e32ca59d1cdc3826d (patch)
tree6d11c3365e095dbdc6ef2ec7da69ccc9a41aedb2
parent059a188d0dd7162315c1e15b8e11d1db8bf3e832 (diff)
downloadcrosvm-67afe44f80936615ff87648e32ca59d1cdc3826d.tar
crosvm-67afe44f80936615ff87648e32ca59d1cdc3826d.tar.gz
crosvm-67afe44f80936615ff87648e32ca59d1cdc3826d.tar.bz2
crosvm-67afe44f80936615ff87648e32ca59d1cdc3826d.tar.lz
crosvm-67afe44f80936615ff87648e32ca59d1cdc3826d.tar.xz
crosvm-67afe44f80936615ff87648e32ca59d1cdc3826d.tar.zst
crosvm-67afe44f80936615ff87648e32ca59d1cdc3826d.zip
devices: Move VirtioDevice to its own file
Currently VirtioDevice was only used by MmioDevice. Move it to a
separate file to allow it to be used by a PCI implementation in the
following commits.

Change-Id: Ie2de92d8876fdaa31d71341714681212d52a618c
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1208690
Commit-Ready: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
-rw-r--r--devices/src/virtio/mmio.rs58
-rw-r--r--devices/src/virtio/mod.rs2
-rw-r--r--devices/src/virtio/virtio_device.rs67
3 files changed, 69 insertions, 58 deletions
diff --git a/devices/src/virtio/mmio.rs b/devices/src/virtio/mmio.rs
index b142680..5e7226f 100644
--- a/devices/src/virtio/mmio.rs
+++ b/devices/src/virtio/mmio.rs
@@ -2,7 +2,6 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-use std::os::unix::io::RawFd;
 use std::sync::Arc;
 use std::sync::atomic::{AtomicUsize, Ordering};
 
@@ -17,63 +16,6 @@ const VENDOR_ID: u32 = 0;
 const MMIO_MAGIC_VALUE: u32 = 0x74726976;
 const MMIO_VERSION: u32 = 2;
 
-/// Trait for virtio devices to be driven by a virtio transport.
-///
-/// The lifecycle of a virtio device is to be moved to a virtio transport, which will then query the
-/// device. Once the guest driver has configured the device, `VirtioDevice::activate` will be called
-/// and all the events, memory, and queues for device operation will be moved into the device.
-/// Optionally, a virtio device can implement device reset in which it returns said resources and
-/// resets its internal.
-pub trait VirtioDevice: Send {
-    /// A vector of device-specific file descriptors that must be kept open
-    /// after jailing. Must be called before the process is jailed.
-    fn keep_fds(&self) -> Vec<RawFd>;
-
-    /// The virtio device type.
-    fn device_type(&self) -> u32;
-
-    /// The maximum size of each queue that this device supports.
-    fn queue_max_sizes(&self) -> &[u16];
-
-    /// The set of feature bits shifted by `page * 32`.
-    fn features(&self, page: u32) -> u32 {
-        let _ = page;
-        0
-    }
-
-    /// Acknowledges that this set of features should be enabled.
-    fn ack_features(&mut self, page: u32, value: u32) {
-        let _ = page;
-        let _ = value;
-    }
-
-    /// Reads this device configuration space at `offset`.
-    fn read_config(&self, offset: u64, data: &mut [u8]) {
-        let _ = offset;
-        let _ = data;
-    }
-
-    /// Writes to this device configuration space at `offset`.
-    fn write_config(&mut self, offset: u64, data: &[u8]) {
-        let _ = offset;
-        let _ = data;
-    }
-
-    /// Activates this device for real usage.
-    fn activate(&mut self,
-                mem: GuestMemory,
-                interrupt_evt: EventFd,
-                status: Arc<AtomicUsize>,
-                queues: Vec<Queue>,
-                queue_evts: Vec<EventFd>);
-
-    /// Optionally deactivates this device and returns ownership of the guest memory map, interrupt
-    /// event, and queue events.
-    fn reset(&mut self) -> Option<(EventFd, Vec<EventFd>)> {
-        None
-    }
-}
-
 /// Implements the
 /// [MMIO](http://docs.oasis-open.org/virtio/virtio/v1.0/cs04/virtio-v1.0-cs04.html#x1-1090002)
 /// transport for virtio devices.
diff --git a/devices/src/virtio/mod.rs b/devices/src/virtio/mod.rs
index 91a2c23..d716f2c 100644
--- a/devices/src/virtio/mod.rs
+++ b/devices/src/virtio/mod.rs
@@ -13,6 +13,7 @@ mod net;
 #[cfg(feature = "gpu")]
 mod gpu;
 mod p9;
+mod virtio_device;
 mod wl;
 
 pub mod vhost;
@@ -26,6 +27,7 @@ pub use self::net::*;
 #[cfg(feature = "gpu")]
 pub use self::gpu::*;
 pub use self::p9::*;
+pub use self::virtio_device::*;
 pub use self::wl::*;
 
 const DEVICE_ACKNOWLEDGE: u32 = 0x01;
diff --git a/devices/src/virtio/virtio_device.rs b/devices/src/virtio/virtio_device.rs
new file mode 100644
index 0000000..7458be8
--- /dev/null
+++ b/devices/src/virtio/virtio_device.rs
@@ -0,0 +1,67 @@
+// Copyright 2018 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+use std::os::unix::io::RawFd;
+use std::sync::Arc;
+use std::sync::atomic::AtomicUsize;
+
+use super::*;
+use sys_util::{EventFd, GuestMemory};
+
+/// Trait for virtio devices to be driven by a virtio transport.
+///
+/// The lifecycle of a virtio device is to be moved to a virtio transport, which will then query the
+/// device. Once the guest driver has configured the device, `VirtioDevice::activate` will be called
+/// and all the events, memory, and queues for device operation will be moved into the device.
+/// Optionally, a virtio device can implement device reset in which it returns said resources and
+/// resets its internal.
+pub trait VirtioDevice: Send {
+    /// A vector of device-specific file descriptors that must be kept open
+    /// after jailing. Must be called before the process is jailed.
+    fn keep_fds(&self) -> Vec<RawFd>;
+
+    /// The virtio device type.
+    fn device_type(&self) -> u32;
+
+    /// The maximum size of each queue that this device supports.
+    fn queue_max_sizes(&self) -> &[u16];
+
+    /// The set of feature bits shifted by `page * 32`.
+    fn features(&self, page: u32) -> u32 {
+        let _ = page;
+        0
+    }
+
+    /// Acknowledges that this set of features should be enabled.
+    fn ack_features(&mut self, page: u32, value: u32) {
+        let _ = page;
+        let _ = value;
+    }
+
+    /// Reads this device configuration space at `offset`.
+    fn read_config(&self, offset: u64, data: &mut [u8]) {
+        let _ = offset;
+        let _ = data;
+    }
+
+    /// Writes to this device configuration space at `offset`.
+    fn write_config(&mut self, offset: u64, data: &[u8]) {
+        let _ = offset;
+        let _ = data;
+    }
+
+    /// Activates this device for real usage.
+    fn activate(&mut self,
+                mem: GuestMemory,
+                interrupt_evt: EventFd,
+                status: Arc<AtomicUsize>,
+                queues: Vec<Queue>,
+                queue_evts: Vec<EventFd>);
+
+    /// Optionally deactivates this device and returns ownership of the guest memory map, interrupt
+    /// event, and queue events.
+    fn reset(&mut self) -> Option<(EventFd, Vec<EventFd>)> {
+        None
+    }
+}