From e2b38cc0504d18c78f9ba27f3ab82c02ff791080 Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Mon, 5 Aug 2019 16:51:31 -0700 Subject: [PATCH] vm-virtio: Extend VirtioDevice trait to retrieve shared memory regions Based on the newly added SharedMemoryConfig capability to the virtio specification, and based on the fact that it is not tied to the type of transport (pci or mmio), we can create as part of the VirtioDevice trait a new method that will provide the shared memory regions associated with the device. Signed-off-by: Sebastien Boeuf --- vm-virtio/src/device.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/vm-virtio/src/device.rs b/vm-virtio/src/device.rs index d0a7a5b45..6c4a79088 100644 --- a/vm-virtio/src/device.rs +++ b/vm-virtio/src/device.rs @@ -9,7 +9,7 @@ use super::*; use pci::{PciBarConfiguration, PciCapability}; use std::sync::Arc; -use vm_memory::GuestMemoryMmap; +use vm_memory::{GuestAddress, GuestMemoryMmap, GuestUsize}; use vmm_sys_util::eventfd::EventFd; pub enum VirtioInterruptType { @@ -23,6 +23,19 @@ pub type VirtioInterrupt = Box< + Sync, >; +#[derive(Clone)] +pub struct VirtioSharedMemory { + pub offset: u64, + pub len: u64, +} + +#[derive(Clone)] +pub struct VirtioSharedMemoryList { + pub addr: GuestAddress, + pub len: GuestUsize, + pub region_list: Vec, +} + /// 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 @@ -76,4 +89,9 @@ pub trait VirtioDevice: Send { fn get_device_caps(&self) -> Vec> { Vec::new() } + + /// Returns the list of shared memory regions required by the device. + fn get_shm_regions(&self) -> Option { + None + } }