diff mbox series

[v3,16/20] virtio-gpu: Add virtio_gpu_wait_flush API

Message ID 20210511080818.366985-17-vivek.kasireddy@intel.com (mailing list archive)
State New, archived
Headers show
Series virtio-gpu: Add support for Blob resources | expand

Commit Message

Kasireddy, Vivek May 11, 2021, 8:08 a.m. UTC
This new command can be used by the Guest Compositor as a way to
synchronize its updates (repaint/redraw) with Host UI buffer
submissions (redraw). In other words, the Guest can wait until
the buffer it has submitted has been used by the Host before it
starts it new repaint cycle.

Cc: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Vivek Kasireddy <vivek.kasireddy@intel.com>
---
 hw/display/virtio-gpu.c                     | 31 +++++++++++++++++++++
 include/standard-headers/linux/virtio_gpu.h | 10 +++++++
 2 files changed, 41 insertions(+)
diff mbox series

Patch

diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c
index 694d8f550c..59cbc2b1df 100644
--- a/hw/display/virtio-gpu.c
+++ b/hw/display/virtio-gpu.c
@@ -933,6 +933,30 @@  virtio_gpu_resource_detach_backing(VirtIOGPU *g,
     virtio_gpu_cleanup_mapping(g, res);
 }
 
+static void virtio_gpu_wait_flush(VirtIOGPU *g,
+                                  struct virtio_gpu_ctrl_command *cmd)
+{
+    struct virtio_gpu_simple_resource *res;
+    struct virtio_gpu_wait_flush wf;
+
+    VIRTIO_GPU_FILL_CMD(wf);
+    virtio_gpu_bswap_32(&wf, sizeof(wf));
+
+    res = virtio_gpu_find_check_resource(g, wf.resource_id, true,
+                                         __func__, &cmd->error);
+    if (!res) {
+        return;
+    }
+
+    if (res->blob) {
+        if (cmd->cmd_hdr.flags & VIRTIO_GPU_FLAG_FENCE &&
+            virtio_gpu_resource_has_sync(g, res)) {
+            virtio_gpu_resource_wait_sync(g, res);
+            cmd->finished = true;
+        }
+    }
+}
+
 void virtio_gpu_simple_process_cmd(VirtIOGPU *g,
                                    struct virtio_gpu_ctrl_command *cmd)
 {
@@ -981,6 +1005,13 @@  void virtio_gpu_simple_process_cmd(VirtIOGPU *g,
     case VIRTIO_GPU_CMD_RESOURCE_DETACH_BACKING:
         virtio_gpu_resource_detach_backing(g, cmd);
         break;
+    case VIRTIO_GPU_CMD_WAIT_FLUSH:
+        if (!virtio_gpu_expflush_enabled(g->parent_obj.conf)) {
+            cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER;
+            break;
+        }
+        virtio_gpu_wait_flush(g, cmd);
+        break;
     default:
         cmd->error = VIRTIO_GPU_RESP_ERR_UNSPEC;
         break;
diff --git a/include/standard-headers/linux/virtio_gpu.h b/include/standard-headers/linux/virtio_gpu.h
index d015741f0b..f9aba84174 100644
--- a/include/standard-headers/linux/virtio_gpu.h
+++ b/include/standard-headers/linux/virtio_gpu.h
@@ -60,6 +60,9 @@ 
  */
 #define VIRTIO_GPU_F_RESOURCE_BLOB       3
 
+/*
+ * VIRTIO_GPU_CMD_WAIT_FLUSH
+ */
 #define VIRTIO_GPU_F_EXPLICIT_FLUSH      4
 
 enum virtio_gpu_ctrl_type {
@@ -80,6 +83,7 @@  enum virtio_gpu_ctrl_type {
 	VIRTIO_GPU_CMD_RESOURCE_ASSIGN_UUID,
 	VIRTIO_GPU_CMD_RESOURCE_CREATE_BLOB,
 	VIRTIO_GPU_CMD_SET_SCANOUT_BLOB,
+	VIRTIO_GPU_CMD_WAIT_FLUSH,
 
 	/* 3d commands */
 	VIRTIO_GPU_CMD_CTX_CREATE = 0x0200,
@@ -443,4 +447,10 @@  struct virtio_gpu_resource_unmap_blob {
 	uint32_t padding;
 };
 
+/* VIRTIO_GPU_CMD_WAIT_FLUSH */
+struct virtio_gpu_wait_flush {
+	struct virtio_gpu_ctrl_hdr hdr;
+	uint32_t resource_id;
+};
+
 #endif