summary refs log tree commit diff
path: root/devices/src/virtio/virtio_pci_device.rs
diff options
context:
space:
mode:
authorDaniel Prilik <prilik@google.com>2019-03-05 12:54:03 -0800
committerCommit Bot <commit-bot@chromium.org>2019-12-12 10:28:34 +0000
commitafa30327f8db8b23e517d2aec70d8cc2823c84a0 (patch)
tree867a63a32400a5fbeb8f73cbac8e21f816b6c4a3 /devices/src/virtio/virtio_pci_device.rs
parentbf19558be57556bb92696827c31c1f0cba035801 (diff)
downloadcrosvm-afa30327f8db8b23e517d2aec70d8cc2823c84a0.tar
crosvm-afa30327f8db8b23e517d2aec70d8cc2823c84a0.tar.gz
crosvm-afa30327f8db8b23e517d2aec70d8cc2823c84a0.tar.bz2
crosvm-afa30327f8db8b23e517d2aec70d8cc2823c84a0.tar.lz
crosvm-afa30327f8db8b23e517d2aec70d8cc2823c84a0.tar.xz
crosvm-afa30327f8db8b23e517d2aec70d8cc2823c84a0.tar.zst
crosvm-afa30327f8db8b23e517d2aec70d8cc2823c84a0.zip
devices: virtio: add support for VIRTIO_PCI_CAP_SHARED_MEMORY_CFG
Could be used by virtio-fs and virtio-gpu.

(cherry picked from crrev.com/c/1493014)
[took out PCI portions and modified commit message -- @gsingh]

BUG=chromium:924405
TEST=build and run

Change-Id: I47fd4482aa7c11e08bfb4f6c990221ae7a11a11d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1963333
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
Diffstat (limited to 'devices/src/virtio/virtio_pci_device.rs')
-rw-r--r--devices/src/virtio/virtio_pci_device.rs56
1 files changed, 56 insertions, 0 deletions
diff --git a/devices/src/virtio/virtio_pci_device.rs b/devices/src/virtio/virtio_pci_device.rs
index 91e139b..dbfaa69 100644
--- a/devices/src/virtio/virtio_pci_device.rs
+++ b/devices/src/virtio/virtio_pci_device.rs
@@ -30,6 +30,7 @@ pub enum PciCapabilityType {
     IsrConfig = 3,
     DeviceConfig = 4,
     PciConfig = 5,
+    SharedMemoryConfig = 8,
 }
 
 #[allow(dead_code)]
@@ -118,6 +119,61 @@ impl VirtioPciNotifyCap {
     }
 }
 
+#[repr(C)]
+#[derive(Clone, Copy)]
+pub struct VirtioPciShmCap {
+    cap: VirtioPciCap,
+    offset_hi: Le32,       // Most sig 32 bits of offset
+    length_hi: Le32,       // Most sig 32 bits of length
+    id: VirtioPciShmCapID, // To distinguish shm chunks
+}
+// It is safe to implement DataInit; all members are simple numbers and any value is valid.
+unsafe impl DataInit for VirtioPciShmCap {}
+
+#[repr(u8)]
+#[derive(Clone, Copy)]
+pub enum VirtioPciShmCapID {
+    Cache = 0,
+    Vertab = 1,
+    Journal = 2,
+}
+
+impl PciCapability for VirtioPciShmCap {
+    fn bytes(&self) -> &[u8] {
+        self.as_slice()
+    }
+
+    fn id(&self) -> PciCapabilityID {
+        PciCapabilityID::VendorSpecific
+    }
+}
+
+impl VirtioPciShmCap {
+    pub fn new(
+        cfg_type: PciCapabilityType,
+        bar: u8,
+        offset: u64,
+        length: u64,
+        id: VirtioPciShmCapID,
+    ) -> Self {
+        VirtioPciShmCap {
+            cap: VirtioPciCap {
+                _cap_vndr: 0,
+                _cap_next: 0,
+                cap_len: std::mem::size_of::<VirtioPciShmCap>() as u8,
+                cfg_type: cfg_type as u8,
+                bar,
+                padding: [0; 3],
+                offset: Le32::from(offset as u32),
+                length: Le32::from(length as u32),
+            },
+            offset_hi: Le32::from((offset >> 32) as u32),
+            length_hi: Le32::from((length >> 32) as u32),
+            id,
+        }
+    }
+}
+
 /// Subclasses for virtio.
 #[allow(dead_code)]
 #[derive(Copy, Clone)]