All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/8] virtio-gpu: Support Venus Vulkan driver
@ 2021-07-28 13:46 Antonio Caggiano
  2021-07-28 13:46 ` [PATCH v2 1/8] virtio-gpu: CONTEXT_INIT feature Antonio Caggiano
                   ` (7 more replies)
  0 siblings, 8 replies; 18+ messages in thread
From: Antonio Caggiano @ 2021-07-28 13:46 UTC (permalink / raw)
  To: qemu-devel

This series of patches enables support for the Venus VirtIO-GPU Vulkan
driver by adding some features required by the driver:

- CONTEXT_INIT
- HOSTMEM
- RESOURCE_UUID
- BLOB_RESOURCES

In addition to these features, Venus capset support was required
together with the implementation for Virgl blob resource commands.

With this in place, QEMU can take advantage of GPU acceleration to
render a simple program such as vkcube [0] in headless mode [1]. Further
work is needed to enable rendering with other kinds of surfaces.

Tested with Chia-I Wu kernel venus-5 branch [2], Mesa v21.1 [3], and my
WIP virglrenderer res-mapping branch [4].

Relevant QEMU command line parameters:

-m 4G \
-object memory-backend-memfd,id=mem1,size=4G \
-machine memory-backend=mem1 \
-display gtk,gl=on,show-cursor=on \
-vga none \
-device virtio-vga-gl,blob=true,hostmem=1G \

v2: Split shared memory capability commit.

[0] https://github.com/krh/vkcube
[1] https://share.collabora.com/index.php/s/RM5igzZMH2o749W/preview
[2] https://gitlab.freedesktop.org/olv/drm-misc-next/-/tree/venus-5
[3] https://gitlab.freedesktop.org/mesa/mesa/-/tree/21.1
[4] https://gitlab.freedesktop.org/Fahien/virglrenderer/-/tree/res-mapping

Antonio Caggiano (6):
  virtio-gpu: CONTEXT_INIT feature
  virtio-gpu: Shared memory capability
  virtio-gpu: Resource UUID
  virtio-gpu: Support Venus capset
  virtio-gpu: Initialize Venus
  virtio-gpu: Handle resource blob commands

Dr. David Alan Gilbert (1):
  virtio: Add shared memory capability

Gerd Hoffmann (1):
  virtio-gpu: hostmem [wip]

 hw/display/trace-events                     |   1 +
 hw/display/virtio-gpu-base.c                |   8 +
 hw/display/virtio-gpu-pci.c                 |  14 ++
 hw/display/virtio-gpu-virgl.c               | 184 +++++++++++++++++++-
 hw/display/virtio-gpu.c                     |  36 +++-
 hw/display/virtio-vga.c                     |  32 +++-
 hw/virtio/virtio-pci.c                      |  19 ++
 hw/virtio/virtio-pci.h                      |   4 +
 include/hw/virtio/virtio-gpu-bswap.h        |  20 ++-
 include/hw/virtio/virtio-gpu.h              |  10 ++
 include/standard-headers/linux/virtio_gpu.h |  16 +-
 meson.build                                 |   1 +
 12 files changed, 318 insertions(+), 27 deletions(-)

-- 
2.30.2



^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH v2 1/8] virtio-gpu: CONTEXT_INIT feature
  2021-07-28 13:46 [PATCH v2 0/8] virtio-gpu: Support Venus Vulkan driver Antonio Caggiano
@ 2021-07-28 13:46 ` Antonio Caggiano
  2021-07-30  9:45   ` Gerd Hoffmann
  2021-07-28 13:46 ` [PATCH v2 2/8] virtio-gpu: hostmem [wip] Antonio Caggiano
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 18+ messages in thread
From: Antonio Caggiano @ 2021-07-28 13:46 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Michael S. Tsirkin

Create virgl renderer context with flags using context_id when valid.

Signed-off-by: Antonio Caggiano <antonio.caggiano@collabora.com>
---
 hw/display/virtio-gpu-base.c                |  2 ++
 hw/display/virtio-gpu-virgl.c               | 10 ++++++++--
 include/hw/virtio/virtio-gpu-bswap.h        |  2 +-
 include/standard-headers/linux/virtio_gpu.h |  9 +++++++--
 4 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/hw/display/virtio-gpu-base.c b/hw/display/virtio-gpu-base.c
index c8da4806e0..619185a9d2 100644
--- a/hw/display/virtio-gpu-base.c
+++ b/hw/display/virtio-gpu-base.c
@@ -212,6 +212,8 @@ virtio_gpu_base_get_features(VirtIODevice *vdev, uint64_t features,
         features |= (1 << VIRTIO_GPU_F_RESOURCE_BLOB);
     }
 
+    features |= (1 << VIRTIO_GPU_F_CONTEXT_INIT);
+
     return features;
 }
 
diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c
index 18d054922f..5a184cf445 100644
--- a/hw/display/virtio-gpu-virgl.c
+++ b/hw/display/virtio-gpu-virgl.c
@@ -97,8 +97,14 @@ static void virgl_cmd_context_create(VirtIOGPU *g,
     trace_virtio_gpu_cmd_ctx_create(cc.hdr.ctx_id,
                                     cc.debug_name);
 
-    virgl_renderer_context_create(cc.hdr.ctx_id, cc.nlen,
-                                  cc.debug_name);
+    if (cc.context_init) {
+        virgl_renderer_context_create_with_flags(cc.hdr.ctx_id,
+                                                 cc.context_init,
+                                                 cc.nlen,
+                                                 cc.debug_name);
+    } else {
+        virgl_renderer_context_create(cc.hdr.ctx_id, cc.nlen, cc.debug_name);
+    }
 }
 
 static void virgl_cmd_context_destroy(VirtIOGPU *g,
diff --git a/include/hw/virtio/virtio-gpu-bswap.h b/include/hw/virtio/virtio-gpu-bswap.h
index e2bee8f595..6267cb57e5 100644
--- a/include/hw/virtio/virtio-gpu-bswap.h
+++ b/include/hw/virtio/virtio-gpu-bswap.h
@@ -24,7 +24,7 @@ virtio_gpu_ctrl_hdr_bswap(struct virtio_gpu_ctrl_hdr *hdr)
     le32_to_cpus(&hdr->flags);
     le64_to_cpus(&hdr->fence_id);
     le32_to_cpus(&hdr->ctx_id);
-    le32_to_cpus(&hdr->padding);
+    le32_to_cpus(&hdr->info);
 }
 
 static inline void
diff --git a/include/standard-headers/linux/virtio_gpu.h b/include/standard-headers/linux/virtio_gpu.h
index 1357e4774e..c9f9c24d6a 100644
--- a/include/standard-headers/linux/virtio_gpu.h
+++ b/include/standard-headers/linux/virtio_gpu.h
@@ -59,6 +59,11 @@
  * VIRTIO_GPU_CMD_RESOURCE_CREATE_BLOB
  */
 #define VIRTIO_GPU_F_RESOURCE_BLOB       3
+/*
+ * VIRTIO_GPU_CMD_CREATE_CONTEXT with
+ * context_init
+ */
+#define VIRTIO_GPU_F_CONTEXT_INIT        4
 
 enum virtio_gpu_ctrl_type {
 	VIRTIO_GPU_UNDEFINED = 0,
@@ -129,7 +134,7 @@ struct virtio_gpu_ctrl_hdr {
 	uint32_t flags;
 	uint64_t fence_id;
 	uint32_t ctx_id;
-	uint32_t padding;
+	uint32_t info;
 };
 
 /* data passed in the cursor vq */
@@ -272,7 +277,7 @@ struct virtio_gpu_resource_create_3d {
 struct virtio_gpu_ctx_create {
 	struct virtio_gpu_ctrl_hdr hdr;
 	uint32_t nlen;
-	uint32_t padding;
+	uint32_t context_init;
 	char debug_name[64];
 };
 
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v2 2/8] virtio-gpu: hostmem [wip]
  2021-07-28 13:46 [PATCH v2 0/8] virtio-gpu: Support Venus Vulkan driver Antonio Caggiano
  2021-07-28 13:46 ` [PATCH v2 1/8] virtio-gpu: CONTEXT_INIT feature Antonio Caggiano
@ 2021-07-28 13:46 ` Antonio Caggiano
  2021-07-28 18:46   ` Philippe Mathieu-Daudé
  2021-07-30  9:49   ` Gerd Hoffmann
  2021-07-28 13:46 ` [PATCH v2 3/8] virtio: Add shared memory capability Antonio Caggiano
                   ` (5 subsequent siblings)
  7 siblings, 2 replies; 18+ messages in thread
From: Antonio Caggiano @ 2021-07-28 13:46 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Michael S. Tsirkin

From: Gerd Hoffmann <kraxel@redhat.com>

---
 hw/display/virtio-gpu-base.c                |  4 +++
 hw/display/virtio-gpu-pci.c                 | 14 +++++++++
 hw/display/virtio-gpu.c                     |  1 +
 hw/display/virtio-vga.c                     | 32 +++++++++++++++------
 include/hw/virtio/virtio-gpu.h              |  5 ++++
 include/standard-headers/linux/virtio_gpu.h |  5 ++++
 6 files changed, 52 insertions(+), 9 deletions(-)

diff --git a/hw/display/virtio-gpu-base.c b/hw/display/virtio-gpu-base.c
index 619185a9d2..31b430664f 100644
--- a/hw/display/virtio-gpu-base.c
+++ b/hw/display/virtio-gpu-base.c
@@ -214,6 +214,10 @@ virtio_gpu_base_get_features(VirtIODevice *vdev, uint64_t features,
 
     features |= (1 << VIRTIO_GPU_F_CONTEXT_INIT);
 
+    if (virtio_gpu_hostmem_enabled(g->conf)) {
+        features |= (1 << VIRTIO_GPU_F_HOSTMEM);
+    }
+
     return features;
 }
 
diff --git a/hw/display/virtio-gpu-pci.c b/hw/display/virtio-gpu-pci.c
index e36eee0c40..9808663d05 100644
--- a/hw/display/virtio-gpu-pci.c
+++ b/hw/display/virtio-gpu-pci.c
@@ -33,6 +33,20 @@ static void virtio_gpu_pci_base_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
     DeviceState *vdev = DEVICE(g);
     int i;
 
+    if (virtio_gpu_hostmem_enabled(g->conf)) {
+        vpci_dev->msix_bar_idx = 1;
+        vpci_dev->modern_mem_bar_idx = 2;
+        memory_region_init(&g->hostmem, OBJECT(g), "virtio-gpu-hostmem",
+                           g->conf.hostmem);
+        pci_register_bar(&vpci_dev->pci_dev, 4,
+                         PCI_BASE_ADDRESS_SPACE_MEMORY |
+                         PCI_BASE_ADDRESS_MEM_PREFETCH |
+                         PCI_BASE_ADDRESS_MEM_TYPE_64,
+                         &g->hostmem);
+        virtio_pci_add_shm_cap(vpci_dev, 4, 0, g->conf.hostmem, 0);
+    }
+
+    qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus), errp);
     virtio_pci_force_virtio_1(vpci_dev);
     if (!qdev_realize(vdev, BUS(&vpci_dev->bus), errp)) {
         return;
diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c
index 990e71fd40..9686f17d79 100644
--- a/hw/display/virtio-gpu.c
+++ b/hw/display/virtio-gpu.c
@@ -1392,6 +1392,7 @@ static Property virtio_gpu_properties[] = {
                      256 * MiB),
     DEFINE_PROP_BIT("blob", VirtIOGPU, parent_obj.conf.flags,
                     VIRTIO_GPU_FLAG_BLOB_ENABLED, false),
+    DEFINE_PROP_SIZE("hostmem", VirtIOGPU, parent_obj.conf.hostmem, 0),
     DEFINE_PROP_END_OF_LIST(),
 };
 
diff --git a/hw/display/virtio-vga.c b/hw/display/virtio-vga.c
index 9e57f61e9e..61993dd3f2 100644
--- a/hw/display/virtio-vga.c
+++ b/hw/display/virtio-vga.c
@@ -125,16 +125,30 @@ static void virtio_vga_base_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
     pci_register_bar(&vpci_dev->pci_dev, 0,
                      PCI_BASE_ADDRESS_MEM_PREFETCH, &vga->vram);
 
-    /*
-     * Configure virtio bar and regions
-     *
-     * We use bar #2 for the mmio regions, to be compatible with stdvga.
-     * virtio regions are moved to the end of bar #2, to make room for
-     * the stdvga mmio registers at the start of bar #2.
-     */
-    vpci_dev->modern_mem_bar_idx = 2;
-    vpci_dev->msix_bar_idx = 4;
     vpci_dev->modern_io_bar_idx = 5;
+  
+    if (!virtio_gpu_hostmem_enabled(g->conf)) {
+        /*
+        * Configure virtio bar and regions
+        *
+        * We use bar #2 for the mmio regions, to be compatible with stdvga.
+        * virtio regions are moved to the end of bar #2, to make room for
+        * the stdvga mmio registers at the start of bar #2.
+        */
+        vpci_dev->modern_mem_bar_idx = 2;
+        vpci_dev->msix_bar_idx = 4;
+    } else {
+        vpci_dev->msix_bar_idx = 1;
+        vpci_dev->modern_mem_bar_idx = 2;
+        memory_region_init(&g->hostmem, OBJECT(g), "virtio-gpu-hostmem",
+                           g->conf.hostmem);
+        pci_register_bar(&vpci_dev->pci_dev, 4,
+                         PCI_BASE_ADDRESS_SPACE_MEMORY |
+                         PCI_BASE_ADDRESS_MEM_PREFETCH |
+                         PCI_BASE_ADDRESS_MEM_TYPE_64,
+                         &g->hostmem);
+        virtio_pci_add_shm_cap(vpci_dev, 4, 0, g->conf.hostmem, 0);
+    }
 
     if (!(vpci_dev->flags & VIRTIO_PCI_FLAG_PAGE_PER_VQ)) {
         /*
diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h
index 24c6628944..835ebcb1a0 100644
--- a/include/hw/virtio/virtio-gpu.h
+++ b/include/hw/virtio/virtio-gpu.h
@@ -102,12 +102,15 @@ enum virtio_gpu_base_conf_flags {
     (_cfg.flags & (1 << VIRTIO_GPU_FLAG_DMABUF_ENABLED))
 #define virtio_gpu_blob_enabled(_cfg) \
     (_cfg.flags & (1 << VIRTIO_GPU_FLAG_BLOB_ENABLED))
+#define virtio_gpu_hostmem_enabled(_cfg) \
+    (_cfg.hostmem > 0)
 
 struct virtio_gpu_base_conf {
     uint32_t max_outputs;
     uint32_t flags;
     uint32_t xres;
     uint32_t yres;
+    uint64_t hostmem;
 };
 
 struct virtio_gpu_ctrl_command {
@@ -131,6 +134,8 @@ struct VirtIOGPUBase {
     int renderer_blocked;
     int enable;
 
+    MemoryRegion hostmem;
+
     struct virtio_gpu_scanout scanout[VIRTIO_GPU_MAX_SCANOUTS];
 
     int enabled_output_bitmask;
diff --git a/include/standard-headers/linux/virtio_gpu.h b/include/standard-headers/linux/virtio_gpu.h
index c9f9c24d6a..85898d41a7 100644
--- a/include/standard-headers/linux/virtio_gpu.h
+++ b/include/standard-headers/linux/virtio_gpu.h
@@ -65,6 +65,11 @@
  */
 #define VIRTIO_GPU_F_CONTEXT_INIT        4
 
+/*
+ * shared memory
+ */
+#define VIRTIO_GPU_F_HOSTMEM             5
+
 enum virtio_gpu_ctrl_type {
 	VIRTIO_GPU_UNDEFINED = 0,
 
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v2 3/8] virtio: Add shared memory capability
  2021-07-28 13:46 [PATCH v2 0/8] virtio-gpu: Support Venus Vulkan driver Antonio Caggiano
  2021-07-28 13:46 ` [PATCH v2 1/8] virtio-gpu: CONTEXT_INIT feature Antonio Caggiano
  2021-07-28 13:46 ` [PATCH v2 2/8] virtio-gpu: hostmem [wip] Antonio Caggiano
@ 2021-07-28 13:46 ` Antonio Caggiano
  2021-07-28 13:46 ` [PATCH v2 4/8] virtio-gpu: Shared " Antonio Caggiano
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 18+ messages in thread
From: Antonio Caggiano @ 2021-07-28 13:46 UTC (permalink / raw)
  To: qemu-devel; +Cc: Dr. David Alan Gilbert, Michael S. Tsirkin

From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>

Define a new capability type 'VIRTIO_PCI_CAP_SHARED_MEMORY_CFG'
and the data structure 'virtio_pci_shm_cap' to go with it.
They allow defining shared memory regions with sizes and offsets
of 2^32 and more.
Multiple instances of the capability are allowed and distinguished
by a device-specific 'id'.

Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
(cherry picked from commit a5d628a3a3c5e60b98b15ffff197c36a77056115)
---
 hw/virtio/virtio-pci.c                      | 19 +++++++++++++++++++
 hw/virtio/virtio-pci.h                      |  4 ++++
 include/standard-headers/linux/virtio_pci.h |  7 +++++++
 3 files changed, 30 insertions(+)

diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index 433060ac02..3589386412 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -1149,6 +1149,25 @@ static int virtio_pci_add_mem_cap(VirtIOPCIProxy *proxy,
     return offset;
 }
 
+int virtio_pci_add_shm_cap(VirtIOPCIProxy *proxy,
+                           uint8_t bar, uint64_t offset, uint64_t length,
+                           uint8_t id)
+{
+    struct virtio_pci_shm_cap cap = {
+        .cap.cap_len = sizeof cap,
+        .cap.cfg_type = VIRTIO_PCI_CAP_SHARED_MEMORY_CFG,
+    };
+    uint32_t mask32 = ~0;
+
+    cap.cap.bar = bar;
+    cap.cap.length = cpu_to_le32(length & mask32);
+    cap.length_hi = cpu_to_le32((length >> 32) & mask32);
+    cap.cap.offset = cpu_to_le32(offset & mask32);
+    cap.offset_hi = cpu_to_le32((offset >> 32) & mask32);
+    cap.id = id;
+    return virtio_pci_add_mem_cap(proxy, &cap.cap);
+}
+
 static uint64_t virtio_pci_common_read(void *opaque, hwaddr addr,
                                        unsigned size)
 {
diff --git a/hw/virtio/virtio-pci.h b/hw/virtio/virtio-pci.h
index 2446dcd9ae..5e5c4a4c6d 100644
--- a/hw/virtio/virtio-pci.h
+++ b/hw/virtio/virtio-pci.h
@@ -252,4 +252,8 @@ void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo *t);
  */
 unsigned virtio_pci_optimal_num_queues(unsigned fixed_queues);
 
+int virtio_pci_add_shm_cap(VirtIOPCIProxy *proxy,
+                           uint8_t bar, uint64_t offset, uint64_t length,
+                           uint8_t id);
+
 #endif
diff --git a/include/standard-headers/linux/virtio_pci.h b/include/standard-headers/linux/virtio_pci.h
index db7a8e2fcb..85d1420d29 100644
--- a/include/standard-headers/linux/virtio_pci.h
+++ b/include/standard-headers/linux/virtio_pci.h
@@ -172,6 +172,13 @@ struct virtio_pci_cfg_cap {
 	uint8_t pci_cfg_data[4]; /* Data for BAR access. */
 };
 
+struct virtio_pci_shm_cap {
+	struct virtio_pci_cap cap;
+	uint32_t offset_hi;             /* Most sig 32 bits of offset */
+	uint32_t length_hi;             /* Most sig 32 bits of length */
+	uint8_t  id;                    /* To distinguish shm chunks */
+};
+
 /* Macro versions of offsets for the Old Timers! */
 #define VIRTIO_PCI_CAP_VNDR		0
 #define VIRTIO_PCI_CAP_NEXT		1
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v2 4/8] virtio-gpu: Shared memory capability
  2021-07-28 13:46 [PATCH v2 0/8] virtio-gpu: Support Venus Vulkan driver Antonio Caggiano
                   ` (2 preceding siblings ...)
  2021-07-28 13:46 ` [PATCH v2 3/8] virtio: Add shared memory capability Antonio Caggiano
@ 2021-07-28 13:46 ` Antonio Caggiano
  2021-07-30  9:52   ` Gerd Hoffmann
  2021-07-28 13:46 ` [PATCH v2 5/8] virtio-gpu: Resource UUID Antonio Caggiano
                   ` (3 subsequent siblings)
  7 siblings, 1 reply; 18+ messages in thread
From: Antonio Caggiano @ 2021-07-28 13:46 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Michael S. Tsirkin

Use VIRTIO_GPU_SHM_ID_HOST_VISIBLE as id for virtio-gpu. Also, remove
struct virtio_pci_shm_cap as virtio_pci_cap64 can be used instead.

Signed-off-by: Antonio Caggiano <antonio.caggiano@collabora.com>
---
 hw/display/virtio-gpu-pci.c                 | 2 +-
 hw/display/virtio-vga.c                     | 2 +-
 hw/virtio/virtio-pci.c                      | 4 ++--
 include/standard-headers/linux/virtio_pci.h | 7 -------
 4 files changed, 4 insertions(+), 11 deletions(-)

diff --git a/hw/display/virtio-gpu-pci.c b/hw/display/virtio-gpu-pci.c
index 9808663d05..a79bd751b2 100644
--- a/hw/display/virtio-gpu-pci.c
+++ b/hw/display/virtio-gpu-pci.c
@@ -43,7 +43,7 @@ static void virtio_gpu_pci_base_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
                          PCI_BASE_ADDRESS_MEM_PREFETCH |
                          PCI_BASE_ADDRESS_MEM_TYPE_64,
                          &g->hostmem);
-        virtio_pci_add_shm_cap(vpci_dev, 4, 0, g->conf.hostmem, 0);
+        virtio_pci_add_shm_cap(vpci_dev, 4, 0, g->conf.hostmem, VIRTIO_GPU_SHM_ID_HOST_VISIBLE);
     }
 
     qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus), errp);
diff --git a/hw/display/virtio-vga.c b/hw/display/virtio-vga.c
index 61993dd3f2..ca841a0799 100644
--- a/hw/display/virtio-vga.c
+++ b/hw/display/virtio-vga.c
@@ -147,7 +147,7 @@ static void virtio_vga_base_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
                          PCI_BASE_ADDRESS_MEM_PREFETCH |
                          PCI_BASE_ADDRESS_MEM_TYPE_64,
                          &g->hostmem);
-        virtio_pci_add_shm_cap(vpci_dev, 4, 0, g->conf.hostmem, 0);
+        virtio_pci_add_shm_cap(vpci_dev, 4, 0, g->conf.hostmem, VIRTIO_GPU_SHM_ID_HOST_VISIBLE);
     }
 
     if (!(vpci_dev->flags & VIRTIO_PCI_FLAG_PAGE_PER_VQ)) {
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index 3589386412..37a50b4658 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -1153,7 +1153,7 @@ int virtio_pci_add_shm_cap(VirtIOPCIProxy *proxy,
                            uint8_t bar, uint64_t offset, uint64_t length,
                            uint8_t id)
 {
-    struct virtio_pci_shm_cap cap = {
+    struct virtio_pci_cap64 cap = {
         .cap.cap_len = sizeof cap,
         .cap.cfg_type = VIRTIO_PCI_CAP_SHARED_MEMORY_CFG,
     };
@@ -1164,7 +1164,7 @@ int virtio_pci_add_shm_cap(VirtIOPCIProxy *proxy,
     cap.length_hi = cpu_to_le32((length >> 32) & mask32);
     cap.cap.offset = cpu_to_le32(offset & mask32);
     cap.offset_hi = cpu_to_le32((offset >> 32) & mask32);
-    cap.id = id;
+    cap.cap.id = id;
     return virtio_pci_add_mem_cap(proxy, &cap.cap);
 }
 
diff --git a/include/standard-headers/linux/virtio_pci.h b/include/standard-headers/linux/virtio_pci.h
index 85d1420d29..db7a8e2fcb 100644
--- a/include/standard-headers/linux/virtio_pci.h
+++ b/include/standard-headers/linux/virtio_pci.h
@@ -172,13 +172,6 @@ struct virtio_pci_cfg_cap {
 	uint8_t pci_cfg_data[4]; /* Data for BAR access. */
 };
 
-struct virtio_pci_shm_cap {
-	struct virtio_pci_cap cap;
-	uint32_t offset_hi;             /* Most sig 32 bits of offset */
-	uint32_t length_hi;             /* Most sig 32 bits of length */
-	uint8_t  id;                    /* To distinguish shm chunks */
-};
-
 /* Macro versions of offsets for the Old Timers! */
 #define VIRTIO_PCI_CAP_VNDR		0
 #define VIRTIO_PCI_CAP_NEXT		1
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v2 5/8] virtio-gpu: Resource UUID
  2021-07-28 13:46 [PATCH v2 0/8] virtio-gpu: Support Venus Vulkan driver Antonio Caggiano
                   ` (3 preceding siblings ...)
  2021-07-28 13:46 ` [PATCH v2 4/8] virtio-gpu: Shared " Antonio Caggiano
@ 2021-07-28 13:46 ` Antonio Caggiano
  2021-07-30  9:57   ` Gerd Hoffmann
  2021-07-28 13:46 ` [PATCH v2 6/8] virtio-gpu: Support Venus capset Antonio Caggiano
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 18+ messages in thread
From: Antonio Caggiano @ 2021-07-28 13:46 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Michael S. Tsirkin

Enable resource UUID feature and implement command resource assign UUID.
For the moment, use the resource ID as UUID.

Signed-off-by: Antonio Caggiano <antonio.caggiano@collabora.com>
---
 hw/display/trace-events        |  1 +
 hw/display/virtio-gpu-base.c   |  2 ++
 hw/display/virtio-gpu-virgl.c  |  3 +++
 hw/display/virtio-gpu.c        | 26 ++++++++++++++++++++++++++
 include/hw/virtio/virtio-gpu.h |  2 ++
 5 files changed, 34 insertions(+)

diff --git a/hw/display/trace-events b/hw/display/trace-events
index f03f6655bc..6b178fa75d 100644
--- a/hw/display/trace-events
+++ b/hw/display/trace-events
@@ -37,6 +37,7 @@ virtio_gpu_cmd_res_create_blob(uint32_t res, uint64_t size) "res 0x%x, size %" P
 virtio_gpu_cmd_res_unref(uint32_t res) "res 0x%x"
 virtio_gpu_cmd_res_back_attach(uint32_t res) "res 0x%x"
 virtio_gpu_cmd_res_back_detach(uint32_t res) "res 0x%x"
+virtio_gpu_cmd_res_assign_uuid(uint32_t res) "res 0x%x"
 virtio_gpu_cmd_res_xfer_toh_2d(uint32_t res) "res 0x%x"
 virtio_gpu_cmd_res_xfer_toh_3d(uint32_t res) "res 0x%x"
 virtio_gpu_cmd_res_xfer_fromh_3d(uint32_t res) "res 0x%x"
diff --git a/hw/display/virtio-gpu-base.c b/hw/display/virtio-gpu-base.c
index 31b430664f..263a888922 100644
--- a/hw/display/virtio-gpu-base.c
+++ b/hw/display/virtio-gpu-base.c
@@ -218,6 +218,8 @@ virtio_gpu_base_get_features(VirtIODevice *vdev, uint64_t features,
         features |= (1 << VIRTIO_GPU_F_HOSTMEM);
     }
 
+    features |= (1 << VIRTIO_GPU_F_RESOURCE_UUID);
+
     return features;
 }
 
diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c
index 5a184cf445..38e5ca6c72 100644
--- a/hw/display/virtio-gpu-virgl.c
+++ b/hw/display/virtio-gpu-virgl.c
@@ -458,6 +458,9 @@ void virtio_gpu_virgl_process_cmd(VirtIOGPU *g,
         /* TODO add security */
         virgl_cmd_ctx_detach_resource(g, cmd);
         break;
+    case VIRTIO_GPU_CMD_RESOURCE_ASSIGN_UUID:
+        virtio_gpu_resource_assign_uuid(g, cmd);
+        break;
     case VIRTIO_GPU_CMD_GET_CAPSET_INFO:
         virgl_cmd_get_capset_info(g, cmd);
         break;
diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c
index 9686f17d79..26b819dd3d 100644
--- a/hw/display/virtio-gpu.c
+++ b/hw/display/virtio-gpu.c
@@ -932,6 +932,29 @@ virtio_gpu_resource_detach_backing(VirtIOGPU *g,
     virtio_gpu_cleanup_mapping(g, res);
 }
 
+void virtio_gpu_resource_assign_uuid(VirtIOGPU *g,
+                                     struct virtio_gpu_ctrl_command *cmd)
+{
+    struct virtio_gpu_simple_resource *res;
+    struct virtio_gpu_resource_assign_uuid assign;
+    struct virtio_gpu_resp_resource_uuid resp;
+
+    VIRTIO_GPU_FILL_CMD(assign);
+    virtio_gpu_bswap_32(&assign, sizeof(assign));
+    trace_virtio_gpu_cmd_res_assign_uuid(assign.resource_id);
+
+    res = virtio_gpu_find_check_resource(g, assign.resource_id, false, __func__, &cmd->error);
+    if (!res) {
+        return;
+    }
+
+    memset(&resp, 0, sizeof(resp));
+    resp.hdr.type = VIRTIO_GPU_RESP_OK_RESOURCE_UUID;
+    /* FIXME: for the moment use the resource id as UUID */
+    *((uint32_t*)(resp.uuid + 12)) = assign.resource_id;
+    virtio_gpu_ctrl_response(g, cmd, &resp.hdr, sizeof(resp));
+}
+
 void virtio_gpu_simple_process_cmd(VirtIOGPU *g,
                                    struct virtio_gpu_ctrl_command *cmd)
 {
@@ -980,6 +1003,9 @@ 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_RESOURCE_ASSIGN_UUID:
+        virtio_gpu_resource_assign_uuid(g, cmd);
+        break;
     default:
         cmd->error = VIRTIO_GPU_RESP_ERR_UNSPEC;
         break;
diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h
index 835ebcb1a0..5cab5f42ac 100644
--- a/include/hw/virtio/virtio-gpu.h
+++ b/include/hw/virtio/virtio-gpu.h
@@ -263,6 +263,8 @@ int virtio_gpu_create_mapping_iov(VirtIOGPU *g,
                                   uint32_t *niov);
 void virtio_gpu_cleanup_mapping_iov(VirtIOGPU *g,
                                     struct iovec *iov, uint32_t count);
+void virtio_gpu_resource_assign_uuid(VirtIOGPU *g,
+                                     struct virtio_gpu_ctrl_command *cmd);
 void virtio_gpu_process_cmdq(VirtIOGPU *g);
 void virtio_gpu_device_realize(DeviceState *qdev, Error **errp);
 void virtio_gpu_reset(VirtIODevice *vdev);
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v2 6/8] virtio-gpu: Support Venus capset
  2021-07-28 13:46 [PATCH v2 0/8] virtio-gpu: Support Venus Vulkan driver Antonio Caggiano
                   ` (4 preceding siblings ...)
  2021-07-28 13:46 ` [PATCH v2 5/8] virtio-gpu: Resource UUID Antonio Caggiano
@ 2021-07-28 13:46 ` Antonio Caggiano
  2021-07-30  9:59   ` Gerd Hoffmann
  2021-07-28 13:46 ` [PATCH v2 7/8] virtio-gpu: Initialize Venus Antonio Caggiano
  2021-07-28 13:46 ` [PATCH v2 8/8] virtio-gpu: Handle resource blob commands Antonio Caggiano
  7 siblings, 1 reply; 18+ messages in thread
From: Antonio Caggiano @ 2021-07-28 13:46 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Michael S. Tsirkin

Signed-off-by: Antonio Caggiano <antonio.caggiano@collabora.com>
---
 hw/display/virtio-gpu-virgl.c               | 21 +++++++++++++++++----
 include/standard-headers/linux/virtio_gpu.h |  2 ++
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c
index 38e5ca6c72..beb4b7d106 100644
--- a/hw/display/virtio-gpu-virgl.c
+++ b/hw/display/virtio-gpu-virgl.c
@@ -372,6 +372,11 @@ static void virgl_cmd_get_capset_info(VirtIOGPU *g,
         virgl_renderer_get_cap_set(resp.capset_id,
                                    &resp.capset_max_version,
                                    &resp.capset_max_size);
+    } else if (info.capset_index == 2) {
+        resp.capset_id = VIRTIO_GPU_CAPSET_VENUS;
+        virgl_renderer_get_cap_set(resp.capset_id,
+                                   &resp.capset_max_version,
+                                   &resp.capset_max_size);
     } else {
         resp.capset_max_version = 0;
         resp.capset_max_size = 0;
@@ -634,10 +639,18 @@ int virtio_gpu_virgl_init(VirtIOGPU *g)
 
 int virtio_gpu_virgl_get_num_capsets(VirtIOGPU *g)
 {
-    uint32_t capset2_max_ver, capset2_max_size;
+    uint32_t capset2_max_ver, capset2_max_size, num_capsets;
+    num_capsets = 1;
+
     virgl_renderer_get_cap_set(VIRTIO_GPU_CAPSET_VIRGL2,
-                              &capset2_max_ver,
-                              &capset2_max_size);
+                               &capset2_max_ver,
+                               &capset2_max_size);
+    num_capsets += capset2_max_ver ? 1 : 0;
+
+    virgl_renderer_get_cap_set(VIRTIO_GPU_CAPSET_VENUS,
+                               &capset2_max_ver,
+                               &capset2_max_size);
+    num_capsets += capset2_max_size ? 1 : 0;
 
-    return capset2_max_ver ? 2 : 1;
+    return num_capsets;
 }
diff --git a/include/standard-headers/linux/virtio_gpu.h b/include/standard-headers/linux/virtio_gpu.h
index 85898d41a7..28e863cd08 100644
--- a/include/standard-headers/linux/virtio_gpu.h
+++ b/include/standard-headers/linux/virtio_gpu.h
@@ -307,6 +307,8 @@ struct virtio_gpu_cmd_submit {
 
 #define VIRTIO_GPU_CAPSET_VIRGL 1
 #define VIRTIO_GPU_CAPSET_VIRGL2 2
+/* 3 is reserved for gfxstream */
+#define VIRTIO_GPU_CAPSET_VENUS 4
 
 /* VIRTIO_GPU_CMD_GET_CAPSET_INFO */
 struct virtio_gpu_get_capset_info {
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v2 7/8] virtio-gpu: Initialize Venus
  2021-07-28 13:46 [PATCH v2 0/8] virtio-gpu: Support Venus Vulkan driver Antonio Caggiano
                   ` (5 preceding siblings ...)
  2021-07-28 13:46 ` [PATCH v2 6/8] virtio-gpu: Support Venus capset Antonio Caggiano
@ 2021-07-28 13:46 ` Antonio Caggiano
  2021-07-28 18:44   ` Philippe Mathieu-Daudé
  2021-07-30 10:00   ` Gerd Hoffmann
  2021-07-28 13:46 ` [PATCH v2 8/8] virtio-gpu: Handle resource blob commands Antonio Caggiano
  7 siblings, 2 replies; 18+ messages in thread
From: Antonio Caggiano @ 2021-07-28 13:46 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Michael S. Tsirkin

Enable VirGL unstable APIs and request Venus when initializing VirGL.

Signed-off-by: Antonio Caggiano <antonio.caggiano@collabora.com>
---
 hw/display/virtio-gpu-virgl.c | 2 +-
 meson.build                   | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c
index beb4b7d106..ea903172dd 100644
--- a/hw/display/virtio-gpu-virgl.c
+++ b/hw/display/virtio-gpu-virgl.c
@@ -621,7 +621,7 @@ int virtio_gpu_virgl_init(VirtIOGPU *g)
 {
     int ret;
 
-    ret = virgl_renderer_init(g, 0, &virtio_gpu_3d_cbs);
+    ret = virgl_renderer_init(g, VIRGL_RENDERER_VENUS, &virtio_gpu_3d_cbs);
     if (ret != 0) {
         return ret;
     }
diff --git a/meson.build b/meson.build
index f2e148eaf9..31b65050b7 100644
--- a/meson.build
+++ b/meson.build
@@ -483,6 +483,7 @@ if not get_option('virglrenderer').auto() or have_system
                      method: 'pkg-config',
                      required: get_option('virglrenderer'),
                      kwargs: static_kwargs)
+  add_project_arguments('-DVIRGL_RENDERER_UNSTABLE_APIS', language : 'c')
 endif
 curl = not_found
 if not get_option('curl').auto() or have_block
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v2 8/8] virtio-gpu: Handle resource blob commands
  2021-07-28 13:46 [PATCH v2 0/8] virtio-gpu: Support Venus Vulkan driver Antonio Caggiano
                   ` (6 preceding siblings ...)
  2021-07-28 13:46 ` [PATCH v2 7/8] virtio-gpu: Initialize Venus Antonio Caggiano
@ 2021-07-28 13:46 ` Antonio Caggiano
  2021-07-30 10:04   ` Gerd Hoffmann
  7 siblings, 1 reply; 18+ messages in thread
From: Antonio Caggiano @ 2021-07-28 13:46 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Michael S. Tsirkin

Support BLOB resources creation by calling virgl_renderer_resource_create_blob.

Signed-off-by: Antonio Caggiano <antonio.caggiano@collabora.com>
---
 hw/display/virtio-gpu-virgl.c        | 148 +++++++++++++++++++++++++++
 hw/display/virtio-gpu.c              |   9 +-
 include/hw/virtio/virtio-gpu-bswap.h |  18 ++++
 include/hw/virtio/virtio-gpu.h       |   3 +
 4 files changed, 170 insertions(+), 8 deletions(-)

diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c
index ea903172dd..62ca9bacbf 100644
--- a/hw/display/virtio-gpu-virgl.c
+++ b/hw/display/virtio-gpu-virgl.c
@@ -16,6 +16,8 @@
 #include "trace.h"
 #include "hw/virtio/virtio.h"
 #include "hw/virtio/virtio-gpu.h"
+#include "hw/virtio/virtio-gpu-bswap.h"
+#include "hw/virtio/virtio-iommu.h"
 
 #include <virglrenderer.h>
 
@@ -409,6 +411,143 @@ static void virgl_cmd_get_capset(VirtIOGPU *g,
     g_free(resp);
 }
 
+static void virgl_cmd_resource_create_blob(VirtIOGPU *g,
+                                           struct virtio_gpu_ctrl_command *cmd)
+{
+    struct virtio_gpu_simple_resource *res;
+    struct virtio_gpu_resource_create_blob cblob;
+    int ret;
+
+    VIRTIO_GPU_FILL_CMD(cblob);
+    virtio_gpu_create_blob_bswap(&cblob);
+    trace_virtio_gpu_cmd_res_create_blob(cblob.resource_id, cblob.size);
+
+    if (cblob.resource_id == 0) {
+        qemu_log_mask(LOG_GUEST_ERROR, "%s: resource id 0 is not allowed\n",
+                      __func__);
+        cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID;
+        return;
+    }
+
+    res = virtio_gpu_find_resource(g, cblob.resource_id);
+    if (res) {
+        qemu_log_mask(LOG_GUEST_ERROR, "%s: resource already exists %d\n",
+                      __func__, cblob.resource_id);
+        cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID;
+        return;
+    }
+
+    res = g_new0(struct virtio_gpu_simple_resource, 1);
+    res->resource_id = cblob.resource_id;
+    res->blob_size = cblob.size;
+
+    if (res->iov) {
+        cmd->error = VIRTIO_GPU_RESP_ERR_UNSPEC;
+        return;
+    }
+
+    if (cblob.blob_mem != VIRTIO_GPU_BLOB_MEM_HOST3D) {
+        ret = virtio_gpu_create_mapping_iov(g, cblob.nr_entries, sizeof(cblob),
+                                            cmd, &res->addrs, &res->iov,
+                                            &res->iov_cnt);
+        if (ret != 0) {
+            cmd->error = VIRTIO_GPU_RESP_ERR_UNSPEC;
+            return;
+        }
+    }
+
+    if (cblob.blob_mem == VIRTIO_GPU_BLOB_MEM_GUEST) {
+        virtio_gpu_init_udmabuf(res);
+    }
+    QTAILQ_INSERT_HEAD(&g->reslist, res, next);
+
+    const struct virgl_renderer_resource_create_blob_args virgl_args = {
+        .res_handle = cblob.resource_id,
+        .ctx_id = cblob.hdr.ctx_id,
+        .blob_mem = cblob.blob_mem,
+        .blob_id = cblob.blob_id,
+        .blob_flags = cblob.blob_flags,
+        .size = cblob.size,
+        .iovecs = res->iov,
+        .num_iovs = res->iov_cnt,
+    };
+    ret = virgl_renderer_resource_create_blob(&virgl_args);
+    if (ret) {
+        g_print("Virgl blob create error: %s\n", strerror(-ret));
+    }
+}
+
+static void virgl_cmd_resource_map_blob(VirtIOGPU *g,
+                                        struct virtio_gpu_ctrl_command *cmd)
+{
+    struct virtio_gpu_simple_resource *res;
+    struct virtio_gpu_resource_map_blob mblob;
+    int ret;
+    void *data;
+    uint64_t size;
+    MemoryRegion *region;
+    struct virtio_gpu_resp_map_info resp;
+
+    VIRTIO_GPU_FILL_CMD(mblob);
+    virtio_gpu_map_blob_bswap(&mblob);
+
+    if (mblob.resource_id == 0) {
+        qemu_log_mask(LOG_GUEST_ERROR, "%s: resource id 0 is not allowed\n",
+                      __func__);
+        cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID;
+        return;
+    }
+
+    res = virtio_gpu_find_resource(g, mblob.resource_id);
+    if (!res) {
+        qemu_log_mask(LOG_GUEST_ERROR, "%s: resource does not exist %d\n",
+                      __func__, mblob.resource_id);
+        cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID;
+        return;
+    }
+
+    ret = virgl_renderer_resource_map(mblob.hdr.ctx_id, res->resource_id, &data, &size);
+    if (ret) {
+        g_print("Virgl blob resource map error: %s\n", strerror(-ret));
+    }
+
+    region = g_new0(MemoryRegion, 1);
+    memory_region_init_ram_device_ptr(region, OBJECT(g), NULL, size, data);
+    memory_region_add_subregion(&g->parent_obj.hostmem, mblob.offset, region);
+    memory_region_set_enabled(region, true);
+
+    memset(&resp, 0, sizeof(resp));
+    resp.hdr.type = VIRTIO_GPU_RESP_OK_MAP_INFO;
+    virgl_renderer_resource_get_map_info(mblob.resource_id, &resp.map_info);
+    virtio_gpu_ctrl_response(g, cmd, &resp.hdr, sizeof(resp));
+}
+
+static void virgl_cmd_resource_unmap_blob(VirtIOGPU *g,
+                                        struct virtio_gpu_ctrl_command *cmd)
+{
+    struct virtio_gpu_simple_resource *res;
+    struct virtio_gpu_resource_unmap_blob ublob;
+    VIRTIO_GPU_FILL_CMD(ublob);
+    virtio_gpu_unmap_blob_bswap(&ublob);
+
+    if (ublob.resource_id == 0) {
+        qemu_log_mask(LOG_GUEST_ERROR, "%s: resource id 0 is not allowed\n",
+                      __func__);
+        cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID;
+        return;
+    }
+
+    res = virtio_gpu_find_resource(g, ublob.resource_id);
+    if (!res) {
+        qemu_log_mask(LOG_GUEST_ERROR, "%s: resource does not exist %d\n",
+                      __func__, ublob.resource_id);
+        cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID;
+        return;
+    }
+
+    virgl_renderer_resource_unmap(ublob.hdr.ctx_id, ublob.resource_id);
+}
+
 void virtio_gpu_virgl_process_cmd(VirtIOGPU *g,
                                       struct virtio_gpu_ctrl_command *cmd)
 {
@@ -478,6 +617,15 @@ void virtio_gpu_virgl_process_cmd(VirtIOGPU *g,
     case VIRTIO_GPU_CMD_GET_EDID:
         virtio_gpu_get_edid(g, cmd);
         break;
+    case VIRTIO_GPU_CMD_RESOURCE_CREATE_BLOB:
+        virgl_cmd_resource_create_blob(g, cmd);
+        break;
+    case VIRTIO_GPU_CMD_RESOURCE_MAP_BLOB:
+        virgl_cmd_resource_map_blob(g, cmd);
+        break;
+    case VIRTIO_GPU_CMD_RESOURCE_UNMAP_BLOB:
+        virgl_cmd_resource_unmap_blob(g, cmd);
+        break;
     default:
         cmd->error = VIRTIO_GPU_RESP_ERR_UNSPEC;
         break;
diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c
index 26b819dd3d..c7ee584063 100644
--- a/hw/display/virtio-gpu.c
+++ b/hw/display/virtio-gpu.c
@@ -33,8 +33,6 @@
 
 #define VIRTIO_GPU_VM_VERSION 1
 
-static struct virtio_gpu_simple_resource*
-virtio_gpu_find_resource(VirtIOGPU *g, uint32_t resource_id);
 static struct virtio_gpu_simple_resource *
 virtio_gpu_find_check_resource(VirtIOGPU *g, uint32_t resource_id,
                                bool require_backing,
@@ -115,7 +113,7 @@ static void update_cursor(VirtIOGPU *g, struct virtio_gpu_update_cursor *cursor)
                   cursor->resource_id ? 1 : 0);
 }
 
-static struct virtio_gpu_simple_resource *
+struct virtio_gpu_simple_resource *
 virtio_gpu_find_resource(VirtIOGPU *g, uint32_t resource_id)
 {
     struct virtio_gpu_simple_resource *res;
@@ -1316,11 +1314,6 @@ void virtio_gpu_device_realize(DeviceState *qdev, Error **errp)
             error_setg(errp, "cannot enable blob resources without udmabuf");
             return;
         }
-
-        if (virtio_gpu_virgl_enabled(g->parent_obj.conf)) {
-            error_setg(errp, "blobs and virgl are not compatible (yet)");
-            return;
-        }
     }
 
     if (!virtio_gpu_base_device_realize(qdev,
diff --git a/include/hw/virtio/virtio-gpu-bswap.h b/include/hw/virtio/virtio-gpu-bswap.h
index 6267cb57e5..0d868f56f9 100644
--- a/include/hw/virtio/virtio-gpu-bswap.h
+++ b/include/hw/virtio/virtio-gpu-bswap.h
@@ -64,10 +64,28 @@ virtio_gpu_create_blob_bswap(struct virtio_gpu_resource_create_blob *cblob)
 {
     virtio_gpu_ctrl_hdr_bswap(&cblob->hdr);
     le32_to_cpus(&cblob->resource_id);
+    le32_to_cpus(&cblob->blob_mem);
     le32_to_cpus(&cblob->blob_flags);
+    le32_to_cpus(&cblob->nr_entries);
+    le64_to_cpus(&cblob->blob_id);
     le64_to_cpus(&cblob->size);
 }
 
+static inline void
+virtio_gpu_map_blob_bswap(struct virtio_gpu_resource_map_blob *mblob)
+{
+    virtio_gpu_ctrl_hdr_bswap(&mblob->hdr);
+    le32_to_cpus(&mblob->resource_id);
+    le64_to_cpus(&mblob->offset);
+}
+
+static inline void
+virtio_gpu_unmap_blob_bswap(struct virtio_gpu_resource_unmap_blob *ublob)
+{
+    virtio_gpu_ctrl_hdr_bswap(&ublob->hdr);
+    le32_to_cpus(&ublob->resource_id);
+}
+
 static inline void
 virtio_gpu_scanout_blob_bswap(struct virtio_gpu_set_scanout_blob *ssb)
 {
diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h
index 5cab5f42ac..050c8ee372 100644
--- a/include/hw/virtio/virtio-gpu.h
+++ b/include/hw/virtio/virtio-gpu.h
@@ -245,6 +245,9 @@ void virtio_gpu_base_fill_display_info(VirtIOGPUBase *g,
                         struct virtio_gpu_resp_display_info *dpy_info);
 
 /* virtio-gpu.c */
+struct virtio_gpu_simple_resource *
+virtio_gpu_find_resource(VirtIOGPU *g, uint32_t resource_id);
+
 void virtio_gpu_ctrl_response(VirtIOGPU *g,
                               struct virtio_gpu_ctrl_command *cmd,
                               struct virtio_gpu_ctrl_hdr *resp,
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 7/8] virtio-gpu: Initialize Venus
  2021-07-28 13:46 ` [PATCH v2 7/8] virtio-gpu: Initialize Venus Antonio Caggiano
@ 2021-07-28 18:44   ` Philippe Mathieu-Daudé
  2021-07-30 10:00   ` Gerd Hoffmann
  1 sibling, 0 replies; 18+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-07-28 18:44 UTC (permalink / raw)
  To: Antonio Caggiano, qemu-devel; +Cc: Gerd Hoffmann, Michael S. Tsirkin

On 7/28/21 3:46 PM, Antonio Caggiano wrote:
> Enable VirGL unstable APIs and request Venus when initializing VirGL.
> 
> Signed-off-by: Antonio Caggiano <antonio.caggiano@collabora.com>
> ---
>  hw/display/virtio-gpu-virgl.c | 2 +-
>  meson.build                   | 1 +
>  2 files changed, 2 insertions(+), 1 deletion(-)

> diff --git a/meson.build b/meson.build
> index f2e148eaf9..31b65050b7 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -483,6 +483,7 @@ if not get_option('virglrenderer').auto() or have_system
>                       method: 'pkg-config',
>                       required: get_option('virglrenderer'),
>                       kwargs: static_kwargs)
> +  add_project_arguments('-DVIRGL_RENDERER_UNSTABLE_APIS', language : 'c')

Unstable in mainstream repository doesn't sound right.
What is the plan for the project to stabilize it?



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 2/8] virtio-gpu: hostmem [wip]
  2021-07-28 13:46 ` [PATCH v2 2/8] virtio-gpu: hostmem [wip] Antonio Caggiano
@ 2021-07-28 18:46   ` Philippe Mathieu-Daudé
  2021-07-30  9:49   ` Gerd Hoffmann
  1 sibling, 0 replies; 18+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-07-28 18:46 UTC (permalink / raw)
  To: Antonio Caggiano, qemu-devel; +Cc: Gerd Hoffmann, Michael S. Tsirkin

On 7/28/21 3:46 PM, Antonio Caggiano wrote:
> From: Gerd Hoffmann <kraxel@redhat.com>
> 
> ---
>  hw/display/virtio-gpu-base.c                |  4 +++
>  hw/display/virtio-gpu-pci.c                 | 14 +++++++++
>  hw/display/virtio-gpu.c                     |  1 +
>  hw/display/virtio-vga.c                     | 32 +++++++++++++++------
>  include/hw/virtio/virtio-gpu.h              |  5 ++++
>  include/standard-headers/linux/virtio_gpu.h |  5 ++++
>  6 files changed, 52 insertions(+), 9 deletions(-)

WIP aims for a RFC series.



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 1/8] virtio-gpu: CONTEXT_INIT feature
  2021-07-28 13:46 ` [PATCH v2 1/8] virtio-gpu: CONTEXT_INIT feature Antonio Caggiano
@ 2021-07-30  9:45   ` Gerd Hoffmann
  0 siblings, 0 replies; 18+ messages in thread
From: Gerd Hoffmann @ 2021-07-30  9:45 UTC (permalink / raw)
  To: Antonio Caggiano; +Cc: qemu-devel, Michael S. Tsirkin

  Hi,

> +/*
> + * VIRTIO_GPU_CMD_CREATE_CONTEXT with
> + * context_init
> + */
> +#define VIRTIO_GPU_F_CONTEXT_INIT        4

Where is the virtio spec update for this?

take care,
  Gerd



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 2/8] virtio-gpu: hostmem [wip]
  2021-07-28 13:46 ` [PATCH v2 2/8] virtio-gpu: hostmem [wip] Antonio Caggiano
  2021-07-28 18:46   ` Philippe Mathieu-Daudé
@ 2021-07-30  9:49   ` Gerd Hoffmann
  1 sibling, 0 replies; 18+ messages in thread
From: Gerd Hoffmann @ 2021-07-30  9:49 UTC (permalink / raw)
  To: Antonio Caggiano; +Cc: qemu-devel, Michael S. Tsirkin

  Hi,

> +/*
> + * shared memory
> + */
> +#define VIRTIO_GPU_F_HOSTMEM             5

Leftover from early interface design attempts.

The blob resources (with VIRTIO_GPU_BLOB_MEM_HOST3D_GUEST)
should cover that now.

take care,
  Gerd



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 4/8] virtio-gpu: Shared memory capability
  2021-07-28 13:46 ` [PATCH v2 4/8] virtio-gpu: Shared " Antonio Caggiano
@ 2021-07-30  9:52   ` Gerd Hoffmann
  0 siblings, 0 replies; 18+ messages in thread
From: Gerd Hoffmann @ 2021-07-30  9:52 UTC (permalink / raw)
  To: Antonio Caggiano; +Cc: qemu-devel, Michael S. Tsirkin

> -        virtio_pci_add_shm_cap(vpci_dev, 4, 0, g->conf.hostmem, 0);
> +        virtio_pci_add_shm_cap(vpci_dev, 4, 0, g->conf.hostmem, VIRTIO_GPU_SHM_ID_HOST_VISIBLE);

Squash that into patch #2

> --- a/include/standard-headers/linux/virtio_pci.h
> +++ b/include/standard-headers/linux/virtio_pci.h
> @@ -172,13 +172,6 @@ struct virtio_pci_cfg_cap {
>  	uint8_t pci_cfg_data[4]; /* Data for BAR access. */
>  };
>  
> -struct virtio_pci_shm_cap {
> -	struct virtio_pci_cap cap;
> -	uint32_t offset_hi;             /* Most sig 32 bits of offset */
> -	uint32_t length_hi;             /* Most sig 32 bits of length */
> -	uint8_t  id;                    /* To distinguish shm chunks */
> -};
> -

Hmm?  I doubt this is correct ...

take care,
  Gerd



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 5/8] virtio-gpu: Resource UUID
  2021-07-28 13:46 ` [PATCH v2 5/8] virtio-gpu: Resource UUID Antonio Caggiano
@ 2021-07-30  9:57   ` Gerd Hoffmann
  0 siblings, 0 replies; 18+ messages in thread
From: Gerd Hoffmann @ 2021-07-30  9:57 UTC (permalink / raw)
  To: Antonio Caggiano; +Cc: qemu-devel, Michael S. Tsirkin

On Wed, Jul 28, 2021 at 03:46:31PM +0200, Antonio Caggiano wrote:
> Enable resource UUID feature and implement command resource assign UUID.
> For the moment, use the resource ID as UUID.

No, please do that properly right from start.

Needs a uuid -> resource-id table or hash in qemu.  Alternatively have
virglrenderer manage uuids too (which then probably needs some api
changes).  Not sure which is better, also depends on how you are going
to use that (i.e. who will lookup resources by uuid).

take care,
  Gerd



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 6/8] virtio-gpu: Support Venus capset
  2021-07-28 13:46 ` [PATCH v2 6/8] virtio-gpu: Support Venus capset Antonio Caggiano
@ 2021-07-30  9:59   ` Gerd Hoffmann
  0 siblings, 0 replies; 18+ messages in thread
From: Gerd Hoffmann @ 2021-07-30  9:59 UTC (permalink / raw)
  To: Antonio Caggiano; +Cc: qemu-devel, Michael S. Tsirkin

Looks sane on a quick glance, but please have a more verbose commit
message.  I can only guess this is a capset for vulkan support, but
readers of the patch should not need guess in the first place ;)

take care,
  Gerd



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 7/8] virtio-gpu: Initialize Venus
  2021-07-28 13:46 ` [PATCH v2 7/8] virtio-gpu: Initialize Venus Antonio Caggiano
  2021-07-28 18:44   ` Philippe Mathieu-Daudé
@ 2021-07-30 10:00   ` Gerd Hoffmann
  1 sibling, 0 replies; 18+ messages in thread
From: Gerd Hoffmann @ 2021-07-30 10:00 UTC (permalink / raw)
  To: Antonio Caggiano; +Cc: qemu-devel, Michael S. Tsirkin

On Wed, Jul 28, 2021 at 03:46:33PM +0200, Antonio Caggiano wrote:
> Enable VirGL unstable APIs and request Venus when initializing VirGL.

I guess having a runtime switch for that would be a good idea, and
probably have default it off while the API is unstable still.

take care,
  Gerd



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 8/8] virtio-gpu: Handle resource blob commands
  2021-07-28 13:46 ` [PATCH v2 8/8] virtio-gpu: Handle resource blob commands Antonio Caggiano
@ 2021-07-30 10:04   ` Gerd Hoffmann
  0 siblings, 0 replies; 18+ messages in thread
From: Gerd Hoffmann @ 2021-07-30 10:04 UTC (permalink / raw)
  To: Antonio Caggiano; +Cc: qemu-devel, Michael S. Tsirkin

  Hi,

> +    region = g_new0(MemoryRegion, 1);
> +    memory_region_init_ram_device_ptr(region, OBJECT(g), NULL, size, data);
> +    memory_region_add_subregion(&g->parent_obj.hostmem, mblob.offset, region);
> +    memory_region_set_enabled(region, true);

You leak the region instead of properly cleaning it up on unmap.

take care,
  Gerd



^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2021-07-30 10:06 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-28 13:46 [PATCH v2 0/8] virtio-gpu: Support Venus Vulkan driver Antonio Caggiano
2021-07-28 13:46 ` [PATCH v2 1/8] virtio-gpu: CONTEXT_INIT feature Antonio Caggiano
2021-07-30  9:45   ` Gerd Hoffmann
2021-07-28 13:46 ` [PATCH v2 2/8] virtio-gpu: hostmem [wip] Antonio Caggiano
2021-07-28 18:46   ` Philippe Mathieu-Daudé
2021-07-30  9:49   ` Gerd Hoffmann
2021-07-28 13:46 ` [PATCH v2 3/8] virtio: Add shared memory capability Antonio Caggiano
2021-07-28 13:46 ` [PATCH v2 4/8] virtio-gpu: Shared " Antonio Caggiano
2021-07-30  9:52   ` Gerd Hoffmann
2021-07-28 13:46 ` [PATCH v2 5/8] virtio-gpu: Resource UUID Antonio Caggiano
2021-07-30  9:57   ` Gerd Hoffmann
2021-07-28 13:46 ` [PATCH v2 6/8] virtio-gpu: Support Venus capset Antonio Caggiano
2021-07-30  9:59   ` Gerd Hoffmann
2021-07-28 13:46 ` [PATCH v2 7/8] virtio-gpu: Initialize Venus Antonio Caggiano
2021-07-28 18:44   ` Philippe Mathieu-Daudé
2021-07-30 10:00   ` Gerd Hoffmann
2021-07-28 13:46 ` [PATCH v2 8/8] virtio-gpu: Handle resource blob commands Antonio Caggiano
2021-07-30 10:04   ` Gerd Hoffmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.