summary refs log tree commit diff
path: root/devices
diff options
context:
space:
mode:
authorKeiichi Watanabe <keiichiw@chromium.org>2020-02-10 17:06:34 +0900
committerCommit Bot <commit-bot@chromium.org>2020-03-06 13:27:50 +0000
commit9515b05c086c55b9e3fbddbc56fb6eb3e9a510a8 (patch)
tree5e18622a0bb8e4813af1217463cb23caf7204dd9 /devices
parent3f3c0a3f6ab82779b269446232e9134aa57ad7bc (diff)
downloadcrosvm-9515b05c086c55b9e3fbddbc56fb6eb3e9a510a8.tar
crosvm-9515b05c086c55b9e3fbddbc56fb6eb3e9a510a8.tar.gz
crosvm-9515b05c086c55b9e3fbddbc56fb6eb3e9a510a8.tar.bz2
crosvm-9515b05c086c55b9e3fbddbc56fb6eb3e9a510a8.tar.lz
crosvm-9515b05c086c55b9e3fbddbc56fb6eb3e9a510a8.tar.xz
crosvm-9515b05c086c55b9e3fbddbc56fb6eb3e9a510a8.tar.zst
crosvm-9515b05c086c55b9e3fbddbc56fb6eb3e9a510a8.zip
devices: virtio: resource_bridge: Transfer plane metadata
Transfer plane offsets and strides for exported GPU resource over resource
bridge as well as a resource itself.
These metadata will be required by virtio-video decoder and encoder.

BUG=b:120456557
TEST=Start ARCVM on atlas

Change-Id: Iaf539857c0f8525bd5be294521e75ad32cae05e7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1787032
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: David Stevens <stevensd@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: Keiichi Watanabe <keiichiw@chromium.org>
Diffstat (limited to 'devices')
-rw-r--r--devices/src/virtio/gpu/mod.rs13
-rw-r--r--devices/src/virtio/gpu/virtio_2d_backend.rs6
-rw-r--r--devices/src/virtio/gpu/virtio_3d_backend.rs18
-rw-r--r--devices/src/virtio/resource_bridge.rs21
-rw-r--r--devices/src/virtio/wl.rs8
5 files changed, 39 insertions, 27 deletions
diff --git a/devices/src/virtio/gpu/mod.rs b/devices/src/virtio/gpu/mod.rs
index 0fcc453..8cc211f 100644
--- a/devices/src/virtio/gpu/mod.rs
+++ b/devices/src/virtio/gpu/mod.rs
@@ -10,7 +10,6 @@ mod virtio_gfxstream_backend;
 
 use std::cell::RefCell;
 use std::collections::VecDeque;
-use std::fs::File;
 use std::i64;
 use std::io::Read;
 use std::mem::{self, size_of};
@@ -141,7 +140,7 @@ trait Backend {
     fn import_event_device(&mut self, event_device: EventDevice, scanout: u32);
 
     /// If supported, export the resource with the given id to a file.
-    fn export_resource(&mut self, id: u32) -> Option<File>;
+    fn export_resource(&mut self, id: u32) -> ResourceResponse;
 
     /// Gets the list of supported display resolutions as a slice of `(width, height)` tuples.
     fn display_info(&self) -> [(u32, u32); 1];
@@ -416,7 +415,7 @@ impl Frontend {
     }
 
     fn process_resource_bridge(&mut self, resource_bridge: &ResourceResponseSocket) {
-        let request = match resource_bridge.recv() {
+        let ResourceRequest::GetResource { id } = match resource_bridge.recv() {
             Ok(msg) => msg,
             Err(e) => {
                 error!("error receiving resource bridge request: {}", e);
@@ -424,13 +423,7 @@ impl Frontend {
             }
         };
 
-        let response = match request {
-            ResourceRequest::GetResource { id } => self
-                .backend
-                .export_resource(id)
-                .map(ResourceResponse::Resource)
-                .unwrap_or(ResourceResponse::Invalid),
-        };
+        let response = self.backend.export_resource(id);
 
         if let Err(e) = resource_bridge.send(&response) {
             error!("error sending resource bridge request: {}", e);
diff --git a/devices/src/virtio/gpu/virtio_2d_backend.rs b/devices/src/virtio/gpu/virtio_2d_backend.rs
index d92b015..a51a664 100644
--- a/devices/src/virtio/gpu/virtio_2d_backend.rs
+++ b/devices/src/virtio/gpu/virtio_2d_backend.rs
@@ -9,7 +9,6 @@ use std::cmp::{max, min};
 use std::collections::btree_map::Entry;
 use std::collections::BTreeMap as Map;
 use std::fmt::{self, Display};
-use std::fs::File;
 use std::marker::PhantomData;
 use std::rc::Rc;
 use std::usize;
@@ -24,6 +23,7 @@ use vm_control::VmMemoryControlRequestSocket;
 use super::protocol::GpuResponse;
 pub use super::virtio_backend::{VirtioBackend, VirtioResource};
 use crate::virtio::gpu::{Backend, DisplayBackend, VIRTIO_F_VERSION_1};
+use crate::virtio::resource_bridge::ResourceResponse;
 
 #[derive(Debug)]
 pub enum Error {
@@ -481,8 +481,8 @@ impl Backend for Virtio2DBackend {
     }
 
     /// If supported, export the resource with the given id to a file.
-    fn export_resource(&mut self, _id: u32) -> Option<File> {
-        None
+    fn export_resource(&mut self, _id: u32) -> ResourceResponse {
+        ResourceResponse::Invalid
     }
 
     /// Creates a fence with the given id that can be used to determine when the previous command
diff --git a/devices/src/virtio/gpu/virtio_3d_backend.rs b/devices/src/virtio/gpu/virtio_3d_backend.rs
index 21a5ac1..7ae044c 100644
--- a/devices/src/virtio/gpu/virtio_3d_backend.rs
+++ b/devices/src/virtio/gpu/virtio_3d_backend.rs
@@ -8,7 +8,6 @@
 use std::cell::RefCell;
 use std::collections::btree_map::Entry;
 use std::collections::BTreeMap as Map;
-use std::fs::File;
 use std::os::unix::io::AsRawFd;
 use std::rc::Rc;
 use std::usize;
@@ -35,6 +34,7 @@ use crate::virtio::gpu::{
     Backend, DisplayBackend, VIRTIO_F_VERSION_1, VIRTIO_GPU_F_HOST_COHERENT, VIRTIO_GPU_F_MEMORY,
     VIRTIO_GPU_F_VIRGL,
 };
+use crate::virtio::resource_bridge::{PlaneInfo, ResourceInfo, ResourceResponse};
 
 use vm_control::{MaybeOwnedFd, VmMemoryControlRequestSocket, VmMemoryRequest, VmMemoryResponse};
 
@@ -319,13 +319,19 @@ impl Backend for Virtio3DBackend {
     }
 
     /// If supported, export the resource with the given id to a file.
-    fn export_resource(&mut self, id: u32) -> Option<File> {
-        let test: Option<File> = self
-            .resources
+    fn export_resource(&mut self, id: u32) -> ResourceResponse {
+        self
+             .resources
             .get(&id) // Option<resource>
             .and_then(|resource| resource.gpu_resource.export().ok()) // Option<(Query, File)>
-            .and_then(|t| Some(t.1)); // Option<File>
-        return test;
+            .map(|(q, file)| {
+                ResourceResponse::Resource(ResourceInfo{file, planes: [
+                    PlaneInfo{offset: q.out_offsets[0], stride: q.out_strides[0]},
+                    PlaneInfo{offset: q.out_offsets[1], stride: q.out_strides[1]},
+                    PlaneInfo{offset: q.out_offsets[2], stride: q.out_strides[2]},
+                    PlaneInfo{offset: q.out_offsets[3], stride: q.out_strides[3]},
+                ]})
+            }).unwrap_or(ResourceResponse::Invalid)
     }
 
     /// Creates a fence with the given id that can be used to determine when the previous command
diff --git a/devices/src/virtio/resource_bridge.rs b/devices/src/virtio/resource_bridge.rs
index aaf776c..2a2343f 100644
--- a/devices/src/virtio/resource_bridge.rs
+++ b/devices/src/virtio/resource_bridge.rs
@@ -16,9 +16,22 @@ pub enum ResourceRequest {
     GetResource { id: u32 },
 }
 
+#[derive(MsgOnSocket, Clone)]
+pub struct PlaneInfo {
+    pub offset: u32,
+    pub stride: u32,
+}
+
+const RESOURE_PLANE_NUM: usize = 4;
+#[derive(MsgOnSocket)]
+pub struct ResourceInfo {
+    pub file: File,
+    pub planes: [PlaneInfo; RESOURE_PLANE_NUM],
+}
+
 #[derive(MsgOnSocket)]
 pub enum ResourceResponse {
-    Resource(File),
+    Resource(ResourceInfo),
     Invalid,
 }
 
@@ -58,16 +71,16 @@ impl fmt::Display for ResourceBridgeError {
 
 impl std::error::Error for ResourceBridgeError {}
 
-pub fn get_resource_fd(
+pub fn get_resource_info(
     sock: &ResourceRequestSocket,
     id: u32,
-) -> std::result::Result<File, ResourceBridgeError> {
+) -> std::result::Result<ResourceInfo, ResourceBridgeError> {
     if let Err(e) = sock.send(&ResourceRequest::GetResource { id }) {
         return Err(ResourceBridgeError::SendFailure(id, e));
     }
 
     match sock.recv() {
-        Ok(ResourceResponse::Resource(bridged_file)) => Ok(bridged_file),
+        Ok(ResourceResponse::Resource(info)) => Ok(info),
         Ok(ResourceResponse::Invalid) => Err(ResourceBridgeError::InvalidResource(id)),
         Err(e) => Err(ResourceBridgeError::RecieveFailure(id, e)),
     }
diff --git a/devices/src/virtio/wl.rs b/devices/src/virtio/wl.rs
index 5ace29c..65ad1cf 100644
--- a/devices/src/virtio/wl.rs
+++ b/devices/src/virtio/wl.rs
@@ -1093,10 +1093,10 @@ impl WlState {
                 #[cfg(feature = "gpu")]
                 VIRTIO_WL_CTRL_VFD_SEND_KIND_VIRTGPU if self.resource_bridge.is_some() => {
                     let sock = self.resource_bridge.as_ref().unwrap();
-                    match get_resource_fd(sock, id) {
-                        Ok(bridged_file) => {
-                            *fd = bridged_file.as_raw_fd();
-                            bridged_files.push(bridged_file);
+                    match get_resource_info(sock, id) {
+                        Ok(info) => {
+                            *fd = info.file.as_raw_fd();
+                            bridged_files.push(info.file);
                         }
                         Err(ResourceBridgeError::InvalidResource(id)) => {
                             warn!("attempt to send non-existent gpu resource {}", id);