summary refs log tree commit diff
diff options
context:
space:
mode:
authorGurchetan Singh <gurchetansingh@chromium.org>2019-11-25 09:07:01 -0800
committerCommit Bot <commit-bot@chromium.org>2020-01-25 02:28:10 +0000
commit8b8c01e1ad31718932491e4aee63f56109a138e2 (patch)
tree1896fd21f22a05d6f453fcaa6510ead97ee5636d
parent3c62aac88f829abd74cba7466e6a9e494af53b25 (diff)
downloadcrosvm-8b8c01e1ad31718932491e4aee63f56109a138e2.tar
crosvm-8b8c01e1ad31718932491e4aee63f56109a138e2.tar.gz
crosvm-8b8c01e1ad31718932491e4aee63f56109a138e2.tar.bz2
crosvm-8b8c01e1ad31718932491e4aee63f56109a138e2.tar.lz
crosvm-8b8c01e1ad31718932491e4aee63f56109a138e2.tar.xz
crosvm-8b8c01e1ad31718932491e4aee63f56109a138e2.tar.zst
crosvm-8b8c01e1ad31718932491e4aee63f56109a138e2.zip
devices: virtio/gpu: support PCI shared mem cap
The plan is to use shared mem cap for virtio-gpu.

BUG=chromium:924405
TEST=build

Change-Id: Id2829c2cd9883aca19641eff625c65a8db335e7a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1963334
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>
-rw-r--r--devices/src/virtio/gpu/mod.rs29
1 files changed, 24 insertions, 5 deletions
diff --git a/devices/src/virtio/gpu/mod.rs b/devices/src/virtio/gpu/mod.rs
index 143b9ef..877746e 100644
--- a/devices/src/virtio/gpu/mod.rs
+++ b/devices/src/virtio/gpu/mod.rs
@@ -34,9 +34,11 @@ use super::{
     Writer, TYPE_GPU, VIRTIO_F_VERSION_1,
 };
 
+use super::{PciCapabilityType, VirtioPciShmCap, VirtioPciShmCapID};
+
 use self::backend::Backend;
 use self::protocol::*;
-use crate::pci::{PciBarConfiguration, PciBarPrefetchable, PciBarRegionType};
+use crate::pci::{PciBarConfiguration, PciBarPrefetchable, PciBarRegionType, PciCapability};
 
 use vm_control::VmMemoryControlRequestSocket;
 
@@ -67,6 +69,10 @@ pub const DEFAULT_GPU_PARAMS: GpuParameters = GpuParameters {
 const QUEUE_SIZES: &[u16] = &[256, 16];
 const FENCE_POLL_MS: u64 = 1;
 
+const GPU_BAR_NUM: u8 = 4;
+const GPU_BAR_OFFSET: u64 = 0;
+const GPU_BAR_SIZE: u64 = 1 << 33;
+
 struct ReturnDescriptor {
     index: u16,
     len: u32,
@@ -971,13 +977,26 @@ impl VirtioDevice for Gpu {
 
     // Require 1 BAR for mapping 3D buffers
     fn get_device_bars(&mut self, bus: u8, dev: u8) -> Vec<PciBarConfiguration> {
-        let bar: u8 = 4;
-        self.pci_bar = Some(Alloc::PciBar { bus, dev, bar });
+        self.pci_bar = Some(Alloc::PciBar {
+            bus,
+            dev,
+            bar: GPU_BAR_NUM,
+        });
         vec![PciBarConfiguration::new(
-            bar as usize,
-            1 << 33,
+            GPU_BAR_NUM as usize,
+            GPU_BAR_SIZE,
             PciBarRegionType::Memory64BitRegion,
             PciBarPrefetchable::NotPrefetchable,
         )]
     }
+
+    fn get_device_caps(&self) -> Vec<Box<dyn PciCapability>> {
+        vec![Box::new(VirtioPciShmCap::new(
+            PciCapabilityType::SharedMemoryConfig,
+            GPU_BAR_NUM,
+            GPU_BAR_OFFSET,
+            GPU_BAR_SIZE,
+            VirtioPciShmCapID::Cache,
+        ))]
+    }
 }