Skip to contentSkip to conversation

add virtio-gpu with 2d support

PATCH In review Gerd Hoffmann 4 participants 25 messages Mar 13, 2015 – Mar 23, 2015 Kbuild

lore
Share & tools
lore
#0 lore raw

cover add virtio-gpu with 2d support

Hi,

Next round of virtio-gpu patches. Patches 1-8 are meant to be merged, patch 9 is a hack to simplify testing with libvirt and will not be merged.

Changes since the RfC submission earlier this month are a bunch of sanity checks being added (mostly pointed out by max) and the virtio-1.0 adaptions are squashed in now.

This series depends on virtio 1.0 patches still not merged.

This series is also available via git:
git://git.kraxel.org/qemu tags/virtio-gpu-2015-03-13

The virtio patches are here (mst's virtio-1.0 branch, rebased to master):
git://git.kraxel.org/qemu tags/virtio-mst-rebased-2015-03-13

Guest kernel driver is here:
git://git.kraxel.org/linux virtio-gpu

Usage:
qemu-system-x86_64 -vga virtio [ ... ] qemu-system-x86_64 -device virtio-vga [ ... ] qemu-system-ppc64 -M pseries -device virtio-gpu-pci [ ... ] qemu-system-arm -M virt -device virtio-gpu-device [ ... ]

Gerd Hoffmann (9):
virtio-gpu/2d: add hardware spec include file virtio-gpu/2d: add virtio gpu core code
virtio-gpu-pci: add virtio pci support
virtio-vga: add virtio gpu device with vga compatibility
virtio-vga: add '-vga virtio' support
virtio-vga: add vgabios configuration
virtio-vga: add vgabios binary
virtio-gpu: add to display-vga test
[hack] virtio-gpu: maskerade as -device VGA

 Makefile                           |   2 +-
 default-configs/x86_64-softmmu.mak |   1 +
 hw/display/Makefile.objs           |   4 +
 hw/display/vga-pci.c               |   2 +-
 hw/display/virtio-gpu-pci.c        |  68 +++
 hw/display/virtio-gpu.c            | 923 +++++++++++++++++++++++++++++++++++++
 hw/display/virtio-vga.c            | 152 ++++++
 hw/pci/pci.c                       |   2 +
 hw/virtio/virtio-pci.h             |  15 +
 include/hw/virtio/virtgpu_hw.h     | 203 ++++++++
 include/hw/virtio/virtio-gpu.h     | 147 ++++++
 include/sysemu/sysemu.h            |   2 +-
 pc-bios/vgabios-virtio.bin         | Bin 0 -> 37376 bytes
 qemu-options.hx                    |   4 +-
 roms/Makefile                      |   2 +-
 roms/config.vga-virtio             |   6 +
 tests/Makefile                     |   3 +
 tests/display-vga-test.c           |  18 +
 trace-events                       |  14 +
 vl.c                               |  13 +
 20 files changed, 1576 insertions(+), 5 deletions(-)
 create mode 100644 hw/display/virtio-gpu-pci.c
 create mode 100644 hw/display/virtio-gpu.c
 create mode 100644 hw/display/virtio-vga.c
 create mode 100644 include/hw/virtio/virtgpu_hw.h
 create mode 100644 include/hw/virtio/virtio-gpu.h
 create mode 100644 pc-bios/vgabios-virtio.bin
 create mode 100644 roms/config.vga-virtio
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/9 virtio-gpu/2d: add hardware spec include file

This patch adds the header file with structs and defines for the virtio based gpu device. Covers 2d operations only.

Written by Dave Airlie and Gerd Hoffmann.

---
 include/hw/virtio/virtgpu_hw.h | 203 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 203 insertions(+)
 create mode 100644 include/hw/virtio/virtgpu_hw.h
include/hw/virtio/virtgpu_hw.h new file +203 -0
new file mode 100644
index 0000000..d6641e8
@@ -0,0 +1,203 @@
+/*
+ * Virtio GPU Device
+ *
+ * Copyright Red Hat, Inc. 2013-2014
+ *
+ * Authors:
+ *     Dave Airlie <[email protected]>
+ *     Gerd Hoffmann <[email protected]>
+ *
+ * This header is BSD licensed so anyone can use the definitions
+ * to implement compatible drivers/servers:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of IBM nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL IBM OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef VIRTIO_GPU_HW_H
+#define VIRTIO_GPU_HW_H
+
+enum virtio_gpu_ctrl_type {
+    VIRTIO_GPU_UNDEFINED = 0,
+
+    /* 2d commands */
+    VIRTIO_GPU_CMD_GET_DISPLAY_INFO = 0x0100,
+    VIRTIO_GPU_CMD_RESOURCE_CREATE_2D,
+    VIRTIO_GPU_CMD_RESOURCE_UNREF,
+    VIRTIO_GPU_CMD_SET_SCANOUT,
+    VIRTIO_GPU_CMD_RESOURCE_FLUSH,
+    VIRTIO_GPU_CMD_TRANSFER_TO_HOST_2D,
+    VIRTIO_GPU_CMD_RESOURCE_ATTACH_BACKING,
+    VIRTIO_GPU_CMD_RESOURCE_DETACH_BACKING,
+
+    /* cursor commands */
+    VIRTIO_GPU_CMD_UPDATE_CURSOR = 0x0300,
+    VIRTIO_GPU_CMD_MOVE_CURSOR,
+
+    /* success responses */
+    VIRTIO_GPU_RESP_OK_NODATA = 0x1100,
+    VIRTIO_GPU_RESP_OK_DISPLAY_INFO,
+
+    /* error responses */
+    VIRTIO_GPU_RESP_ERR_UNSPEC = 0x1200,
+    VIRTIO_GPU_RESP_ERR_OUT_OF_MEMORY,
+    VIRTIO_GPU_RESP_ERR_INVALID_SCANOUT_ID,
+    VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID,
+    VIRTIO_GPU_RESP_ERR_INVALID_CONTEXT_ID,
+    VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER,
+};
+
+#define VIRTIO_GPU_FLAG_FENCE (1 << 0)
+
+struct virtio_gpu_ctrl_hdr {
+    uint32_t type;
+    uint32_t flags;
+    uint64_t fence_id;
+    uint32_t ctx_id;
+    uint32_t padding;
+};
+
+/* data passed in the cursor vq */
+
+struct virtio_gpu_cursor_pos {
+    uint32_t scanout_id;
+    uint32_t x, y;
+    uint32_t padding;
+};
+
+/* VIRTIO_GPU_CMD_UPDATE_CURSOR, VIRTIO_GPU_CMD_MOVE_CURSOR */
+struct virtio_gpu_update_cursor {
+    struct virtio_gpu_ctrl_hdr hdr;
+    struct virtio_gpu_cursor_pos pos;  /* update & move */
+    uint32_t resource_id;           /* update only */
+    uint32_t hot_x;                 /* update only */
+    uint32_t hot_y;                 /* update only */
+    uint32_t padding;
+};
+
+/* data passed in the control vq, 2d related */
+
+struct virtio_gpu_rect {
+    uint32_t x, y;
+    uint32_t width;
+    uint32_t height;
+};
+
+/* VIRTIO_GPU_CMD_RESOURCE_UNREF */
+struct virtio_gpu_resource_unref {
+    struct virtio_gpu_ctrl_hdr hdr;
+    uint32_t resource_id;
+    uint32_t padding;
+};
+
+/* VIRTIO_GPU_CMD_RESOURCE_CREATE_2D: create a 2d resource with a format */
+struct virtio_gpu_resource_create_2d {
+    struct virtio_gpu_ctrl_hdr hdr;
+    uint32_t resource_id;
+    uint32_t format;
+    uint32_t width;
+    uint32_t height;
+};
+
+/* VIRTIO_GPU_CMD_SET_SCANOUT */
+struct virtio_gpu_set_scanout {
+    struct virtio_gpu_ctrl_hdr hdr;
+    struct virtio_gpu_rect r;
+    uint32_t scanout_id;
+    uint32_t resource_id;
+};
+
+/* VIRTIO_GPU_CMD_RESOURCE_FLUSH */
+struct virtio_gpu_resource_flush {
+    struct virtio_gpu_ctrl_hdr hdr;
+    struct virtio_gpu_rect r;
+    uint32_t resource_id;
+    uint32_t padding;
+};
+
+/* VIRTIO_GPU_CMD_TRANSFER_TO_HOST_2D: simple transfer to_host */
+struct virtio_gpu_transfer_to_host_2d {
+    struct virtio_gpu_ctrl_hdr hdr;
+    struct virtio_gpu_rect r;
+    uint64_t offset;
+    uint32_t resource_id;
+    uint32_t padding;
+};
+
+struct virtio_gpu_mem_entry {
+    uint64_t addr;
+    uint32_t length;
+    uint32_t padding;
+};
+
+/* VIRTIO_GPU_CMD_RESOURCE_ATTACH_BACKING */
+struct virtio_gpu_resource_attach_backing {
+    struct virtio_gpu_ctrl_hdr hdr;
+    uint32_t resource_id;
+    uint32_t nr_entries;
+};
+
+/* VIRTIO_GPU_CMD_RESOURCE_DETACH_BACKING */
+struct virtio_gpu_resource_detach_backing {
+    struct virtio_gpu_ctrl_hdr hdr;
+    uint32_t resource_id;
+    uint32_t padding;
+};
+
+/* VIRTIO_GPU_RESP_OK_DISPLAY_INFO */
+#define VIRTIO_GPU_MAX_SCANOUTS 16
+struct virtio_gpu_resp_display_info {
+    struct virtio_gpu_ctrl_hdr hdr;
+    struct virtio_gpu_display_one {
+        struct virtio_gpu_rect r;
+        uint32_t enabled;
+        uint32_t flags;
+    } pmodes[VIRTIO_GPU_MAX_SCANOUTS];
+};
+
+#define VIRTIO_GPU_EVENT_DISPLAY (1 << 0)
+
+struct virtio_gpu_config {
+    uint32_t events_read;
+    uint32_t events_clear;
+    uint32_t num_scanouts;
+    uint32_t reserved;
+};
+
+/* simple formats for fbcon/X use */
+enum virtio_gpu_formats {
+    VIRTIO_GPU_FORMAT_B8G8R8A8_UNORM  = 1,
+    VIRTIO_GPU_FORMAT_B8G8R8X8_UNORM  = 2,
+    VIRTIO_GPU_FORMAT_A8R8G8B8_UNORM  = 3,
+    VIRTIO_GPU_FORMAT_X8R8G8B8_UNORM  = 4,
+
+    VIRTIO_GPU_FORMAT_R8G8B8A8_UNORM  = 67,
+    VIRTIO_GPU_FORMAT_X8B8G8R8_UNORM  = 68,
+
+    VIRTIO_GPU_FORMAT_A8B8G8R8_UNORM  = 121,
+    VIRTIO_GPU_FORMAT_R8G8B8X8_UNORM  = 134,
+
+};
+
+#endif
Signature · 1 line
1.8.3.1
#12 lore raw

PATCH 5/9 virtio-vga: add '-vga virtio' support

In reply to Gerd Hoffmann

Some convinience fluff: Add support for '-vga virtio', also add virtio-vga to the list of vga cards so '-device virtio-vga' will turn off the default vga.

Written by Dave Airlie and Gerd Hoffmann.

---
 hw/pci/pci.c            |  2 ++
 include/sysemu/sysemu.h |  2 +-
 qemu-options.hx         |  4 +++-
 vl.c                    | 13 +++++++++++++
 4 files changed, 19 insertions(+), 2 deletions(-)
hw/pci/pci.c +2 -0
index 6941a82..f6eeaa9 100644
@@ -1677,6 +1677,8 @@ PCIDevice *pci_vga_init(PCIBus *bus)
         return pci_create_simple(bus, -1, "VGA");
     case VGA_VMWARE:
         return pci_create_simple(bus, -1, "vmware-svga");
+    case VGA_VIRTIO:
+        return pci_create_simple(bus, -1, "virtio-vga");
     case VGA_NONE:
     default: /* Other non-PCI types. Checking for unsupported types is already
                 done in vl.c. */
include/sysemu/sysemu.h +1 -1
index 6e85097..4ee32bf 100644
@@ -104,7 +104,7 @@ extern int autostart;
 
 typedef enum {
     VGA_NONE, VGA_STD, VGA_CIRRUS, VGA_VMWARE, VGA_XENFB, VGA_QXL,
-    VGA_TCX, VGA_CG3, VGA_DEVICE
+    VGA_TCX, VGA_CG3, VGA_DEVICE, VGA_VIRTIO,
 } VGAInterfaceType;
 
 extern int vga_interface_type;
qemu-options.hx +3 -1
index 837624d..49b0f8f 100644
@@ -1089,7 +1089,7 @@ Rotate graphical output some deg left (only PXA LCD).
 ETEXI
 
 DEF("vga", HAS_ARG, QEMU_OPTION_vga,
-    "-vga [std|cirrus|vmware|qxl|xenfb|tcx|cg3|none]\n"
+    "-vga [std|cirrus|vmware|qxl|xenfb|tcx|cg3|virtio|none]\n"
     "                select video card type\n", QEMU_ARCH_ALL)
 STEXI
 @item -vga @var{type}
@@ -1122,6 +1122,8 @@ fixed resolution of 1024x768.
 (sun4m only) Sun cgthree framebuffer. This is a simple 8-bit framebuffer
 for sun4m machines available in both 1024x768 (OpenBIOS) and 1152x900 (OBP)
 resolutions aimed at people wishing to run older Solaris versions.
+@item virtio
+Virtio VGA card.
 @item none
 Disable VGA card.
 @end table
vl.c +13 -0
index eba5d4c..7f903a5 100644
@@ -231,6 +231,7 @@ static struct {
     { .driver = "isa-cirrus-vga",       .flag = &default_vga       },
     { .driver = "vmware-svga",          .flag = &default_vga       },
     { .driver = "qxl-vga",              .flag = &default_vga       },
+    { .driver = "virtio-vga",           .flag = &default_vga       },
 };
 
 static QemuOptsList qemu_rtc_opts = {
@@ -1871,6 +1872,11 @@ static bool cg3_vga_available(void)
     return object_class_by_name("cgthree");
 }
 
+static bool virtio_vga_available(void)
+{
+    return object_class_by_name("virtio-vga");
+}
+
 static void select_vgahw (const char *p)
 {
     const char *opts;
@@ -1897,6 +1903,13 @@ static void select_vgahw (const char *p)
             fprintf(stderr, "Error: VMWare SVGA not available\n");
             exit(0);
         }
+    } else if (strstart(p, "virtio", &opts)) {
+        if (virtio_vga_available()) {
+            vga_interface_type = VGA_VIRTIO;
+        } else {
+            fprintf(stderr, "Error: Virtio VGA not available\n");
+            exit(0);
+        }
     } else if (strstart(p, "xenfb", &opts)) {
         vga_interface_type = VGA_XENFB;
     } else if (strstart(p, "qxl", &opts)) {
Signature · 1 line
1.8.3.1
#14 lore raw

PATCH 6/9 virtio-vga: add vgabios configuration

In reply to Gerd Hoffmann

Add seavgabios configuration for virtio-vga,
hook up the new vgabios in the makefiles.

---
 Makefile               | 2 +-
 roms/Makefile          | 2 +-
 roms/config.vga-virtio | 6 ++++++
 3 files changed, 8 insertions(+), 2 deletions(-)
 create mode 100644 roms/config.vga-virtio
Makefile +1 -1
index 884b59d..16899cc 100644
@@ -340,7 +340,7 @@ bepo    cz
 
 ifdef INSTALL_BLOBS
 BLOBS=bios.bin bios-256k.bin sgabios.bin vgabios.bin vgabios-cirrus.bin \
-vgabios-stdvga.bin vgabios-vmware.bin vgabios-qxl.bin \
+vgabios-stdvga.bin vgabios-vmware.bin vgabios-qxl.bin vgabios-virtio.bin \
 acpi-dsdt.aml q35-acpi-dsdt.aml \
 ppc_rom.bin openbios-sparc32 openbios-sparc64 openbios-ppc QEMU,tcx.bin QEMU,cgthree.bin \
 pxe-e1000.rom pxe-eepro100.rom pxe-ne2k_pci.rom \
roms/Makefile +1 -1
index 610b534..c76cd5b 100644
@@ -1,5 +1,5 @@
 
-vgabios_variants := stdvga cirrus vmware qxl isavga
+vgabios_variants := stdvga cirrus vmware qxl isavga virtio
 vgabios_targets  := $(subst -isavga,,$(patsubst %,vgabios-%.bin,$(vgabios_variants)))
 pxerom_variants  := e1000 eepro100 ne2k_pci pcnet rtl8139 virtio
 pxerom_targets   := 8086100e 80861209 10500940 10222000 10ec8139 1af41000
roms/config.vga-virtio new file +6 -0
new file mode 100644
index 0000000..aa7a15b
@@ -0,0 +1,6 @@
+CONFIG_BUILD_VGABIOS=y
+CONFIG_VGA_BOCHS=y
+CONFIG_VGA_PCI=y
+CONFIG_OVERRIDE_PCI_ID=y
+CONFIG_VGA_VID=0x1af4
+CONFIG_VGA_DID=0x1050
Signature · 1 line
1.8.3.1
#20 lore raw

PATCH 8/9 virtio-gpu: add to display-vga test

In reply to Gerd Hoffmann
---
 tests/Makefile           |  3 +++
 tests/display-vga-test.c | 18 ++++++++++++++++++
 2 files changed, 21 insertions(+)
tests/Makefile +3 -0
index 588f438..55ad89f 100644
@@ -133,6 +133,9 @@ check-qtest-pci-y += tests/display-vga-test$(EXESUF)
 gcov-files-pci-y += hw/display/vga.c
 gcov-files-pci-y += hw/display/cirrus_vga.c
 gcov-files-pci-y += hw/display/vga-pci.c
+gcov-files-pci-y += hw/display/virtio-gpu.c
+gcov-files-pci-y += hw/display/virtio-gpu-pci.c
+gcov-files-pci-y += hw/display/virtio-vga.c
 check-qtest-pci-y += tests/intel-hda-test$(EXESUF)
 gcov-files-pci-y += hw/audio/intel-hda.c hw/audio/hda-codec.c
 
tests/display-vga-test.c +18 -0
index 17f5910..cd0b873 100644
@@ -36,6 +36,20 @@ static void pci_multihead(void)
     qtest_end();
 }
 
+#ifdef CONFIG_VIRTIO_GPU
+static void pci_virtio_gpu(void)
+{
+    qtest_start("-vga none -device virtio-gpu-pci");
+    qtest_end();
+}
+
+static void pci_virtio_vga(void)
+{
+    qtest_start("-vga none -device virtio-vga");
+    qtest_end();
+}
+#endif
+
 int main(int argc, char **argv)
 {
     int ret;
@@ -46,6 +60,10 @@ int main(int argc, char **argv)
     qtest_add_func("/display/pci/stdvga", pci_stdvga);
     qtest_add_func("/display/pci/secondary", pci_secondary);
     qtest_add_func("/display/pci/multihead", pci_multihead);
+#ifdef CONFIG_VIRTIO_GPU
+    qtest_add_func("/display/pci/virtio-gpu", pci_virtio_gpu);
+    qtest_add_func("/display/pci/virtio-vga", pci_virtio_vga);
+#endif
     ret = g_test_run();
 
     return ret;
Signature · 1 line
1.8.3.1
#23 lore raw

PATCH 9/9 virtio-gpu: maskerade as -device VGA

In reply to Gerd Hoffmann

Newer libvirt versions start looking up VGA in the QOM tree. So tricking libvirt this way ...

    <qemu:arg value='-set'/>
    <qemu:arg value='device.video0.driver=virtio-vga'/>

... to test virtio-vga stopped working.

Lets rename VGA to stdvga and virtio-vga to VGA to get things going again. A simple ...

      <model type='vga' vram='16384' heads='1'/>

... will give you virtio-vga when building qemu with this patch applied.

---
 hw/display/vga-pci.c    | 2 +-
 hw/display/virtio-vga.c | 4 +++-
 2 files changed, 4 insertions(+), 2 deletions(-)
hw/display/vga-pci.c +1 -1
index aabfc23..8ed1ebd 100644
@@ -349,7 +349,7 @@ static void secondary_class_init(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo vga_info = {
-    .name          = "VGA",
+    .name          = "stdvga",
     .parent        = TYPE_PCI_DEVICE,
     .instance_init = pci_std_vga_init,
     .instance_size = sizeof(PCIVGAState),
hw/display/virtio-vga.c +3 -1
index bbde750..ded28c1 100644
@@ -7,7 +7,7 @@
 /*
  * virtio-vga: This extends VirtioPCIProxy.
  */
-#define TYPE_VIRTIO_VGA "virtio-vga"
+#define TYPE_VIRTIO_VGA "VGA"
 #define VIRTIO_VGA(obj) \
         OBJECT_CHECK(VirtIOVGA, (obj), TYPE_VIRTIO_VGA)
 
@@ -15,6 +15,7 @@ typedef struct VirtIOVGA {
     VirtIOPCIProxy parent_obj;
     VirtIOGPU      vdev;
     VGACommonState vga;
+    uint32_t       dummy;
 } VirtIOVGA;
 
 static void virtio_vga_invalidate_display(void *opaque)
@@ -108,6 +109,7 @@ static void virtio_vga_reset(DeviceState *dev)
 static Property virtio_vga_properties[] = {
     DEFINE_VIRTIO_GPU_PROPERTIES(VirtIOVGA, vdev.conf),
     DEFINE_VIRTIO_GPU_PCI_PROPERTIES(VirtIOPCIProxy),
+    DEFINE_PROP_UINT32("vgamem_mb", VirtIOVGA, dummy, 16),
     DEFINE_PROP_END_OF_LIST(),
 };
 
Signature · 1 line
1.8.3.1
#4 lore raw

PATCH 2/9 virtio-gpu/2d: add virtio gpu core code

In reply to Gerd Hoffmann

This patch adds the core code for virtio gpu emulation, covering 2d support.

Written by Dave Airlie and Gerd Hoffmann.

---
 hw/display/Makefile.objs       |   2 +
 hw/display/virtio-gpu.c        | 923 +++++++++++++++++++++++++++++++++++++++++
 include/hw/virtio/virtio-gpu.h | 147 +++++++
 trace-events                   |  14 +
 4 files changed, 1086 insertions(+)
 create mode 100644 hw/display/virtio-gpu.c
 create mode 100644 include/hw/virtio/virtio-gpu.h
hw/display/Makefile.objs +2 -0
index 7ed76a9..6990634 100644
@@ -33,3 +33,5 @@ obj-$(CONFIG_CG3) += cg3.o
 obj-$(CONFIG_VGA) += vga.o
 
 common-obj-$(CONFIG_QXL) += qxl.o qxl-logger.o qxl-render.o
+
+obj-$(CONFIG_VIRTIO) += virtio-gpu.o
hw/display/virtio-gpu.c new file +923 -0

923 lines not on this page · raw message

include/hw/virtio/virtio-gpu.h new file +147 -0

147 lines not on this page · raw message

trace-events +14 -0
index 30eba92..a3d6fff 100644
@@ -1167,6 +1167,20 @@ vmware_scratch_read(uint32_t index, uint32_t value) "index %d, value 0x%x"
 vmware_scratch_write(uint32_t index, uint32_t value) "index %d, value 0x%x"
 vmware_setmode(uint32_t w, uint32_t h, uint32_t bpp) "%dx%d @ %d bpp"
 
+# hw/display/virtio-gpu.c
+virtio_gpu_cmd_get_display_info(void) ""
+virtio_gpu_cmd_get_caps(void) ""
+virtio_gpu_cmd_set_scanout(uint32_t id, uint32_t res, uint32_t w, uint32_t h, uint32_t x, uint32_t y) "id %d, res 0x%x, w %d, h %d, x %d, y %d"
+virtio_gpu_cmd_res_create_2d(uint32_t res, uint32_t fmt, uint32_t w, uint32_t h) "res 0x%x, fmt 0x%x, w %d, h %d"
+virtio_gpu_cmd_res_create_3d(uint32_t res, uint32_t fmt, uint32_t w, uint32_t h, uint32_t d) "res 0x%x, fmt 0x%x, w %d, h %d, d %d"
+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_xfer_toh_2d(uint32_t res) "res 0x%x"
+virtio_gpu_cmd_res_flush(uint32_t res, uint32_t w, uint32_t h, uint32_t x, uint32_t y) "res 0x%x, w %d, h %d, x %d, y %d"
+virtio_gpu_fence_ctrl(uint64_t fence, uint32_t type) "fence 0x%" PRIx64 ", type 0x%x"
+virtio_gpu_fence_resp(uint64_t fence) "fence 0x%" PRIx64
+
 # savevm.c
 qemu_loadvm_state_section(unsigned int section_type) "%d"
 qemu_loadvm_state_section_partend(uint32_t section_id) "%u"
Signature · 1 line
1.8.3.1
#16 lore raw

PATCH 7/9 virtio-vga: add vgabios binary

In reply to Gerd Hoffmann

Add prebuilt vgabios-virtio.bin binary.

---
 pc-bios/vgabios-virtio.bin | Bin 0 -> 37376 bytes
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 pc-bios/vgabios-virtio.bin
pc-bios/vgabios-virtio.bin new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..7febcb660b23ba1fb6d0d52d9f08458b86cd8c15
GIT binary patch
Signature · 1 line
1.8.3.1
#10 lore raw

PATCH 4/9 virtio-vga: add virtio gpu device with vga compatibility

In reply to Gerd Hoffmann

This patch adds a virtio-vga device. It is simliar to virtio-gpu-pci, but it also adds in vga compatibility, so guests without native virtio-gpu support can drive the device in vga mode.

Written by Dave Airlie and Gerd Hoffmann.

---
 default-configs/x86_64-softmmu.mak |   1 +
 hw/display/Makefile.objs           |   1 +
 hw/display/virtio-vga.c            | 150 +++++++++++++++++++++++++++++++++++++
 3 files changed, 152 insertions(+)
 create mode 100644 hw/display/virtio-vga.c
default-configs/x86_64-softmmu.mak +1 -0
index 46b87dd..9a313d9 100644
@@ -7,6 +7,7 @@ CONFIG_QXL=$(CONFIG_SPICE)
 CONFIG_VGA_ISA=y
 CONFIG_VGA_CIRRUS=y
 CONFIG_VMWARE_VGA=y
+CONFIG_VIRTIO_VGA=y
 CONFIG_VMMOUSE=y
 CONFIG_SERIAL=y
 CONFIG_PARALLEL=y
hw/display/Makefile.objs +1 -0
index ab6b791..3da3f6c 100644
@@ -36,3 +36,4 @@ common-obj-$(CONFIG_QXL) += qxl.o qxl-logger.o qxl-render.o
 
 obj-$(CONFIG_VIRTIO) += virtio-gpu.o
 obj-$(CONFIG_VIRTIO_PCI) += virtio-gpu-pci.o
+obj-$(CONFIG_VIRTIO_VGA) += virtio-vga.o
hw/display/virtio-vga.c new file +150 -0

150 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#18 lore raw

PATCH 1/1 opengl: require glx

In reply to Gerd Hoffmann

hw/display/milkymist-tmu2.c uses glx. That will be replaced with egl in the future, with qemu getting more opengl support. But we are not there yet, so put it back into configure to fix build failures on machines without glx (i.e. macos, possibly windows too).

---
 configure | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
configure +1 -1
index bd55786..ed49990 100755
@@ -3120,7 +3120,7 @@ libs_softmmu="$libs_softmmu $fdt_libs"
 ##########################################
 # opengl probe (for sdl2, milkymist-tmu2)
 if test "$opengl" != "no" ; then
-  opengl_pkgs="egl gl glesv2"
+  opengl_pkgs="glx egl gl glesv2"
   if $pkg_config $opengl_pkgs x11; then
     opengl_cflags="$($pkg_config --cflags $opengl_pkgs) $x11_cflags"
     opengl_libs="$($pkg_config --libs $opengl_pkgs) $x11_libs"
Signature · 1 line
1.8.3.1
#8 lore raw

PATCH 3/9 virtio-gpu-pci: add virtio pci support

In reply to Gerd Hoffmann

This patch adds virtio-gpu-pci, which is the pci proxy for the virtio gpu device. With this patch in place virtio-gpu is functional. You need a linux guest with a virtio-gpu driver though, and output will appear pretty late in boot, once the kernel initialized drm and fbcon.

Written by Dave Airlie and Gerd Hoffmann.

---
 hw/display/Makefile.objs    |  1 +
 hw/display/virtio-gpu-pci.c | 68 +++++++++++++++++++++++++++++++++++++++++++++
 hw/virtio/virtio-pci.h      | 15 ++++++++++
 3 files changed, 84 insertions(+)
 create mode 100644 hw/display/virtio-gpu-pci.c
hw/display/Makefile.objs +1 -0
index 6990634..ab6b791 100644
@@ -35,3 +35,4 @@ obj-$(CONFIG_VGA) += vga.o
 common-obj-$(CONFIG_QXL) += qxl.o qxl-logger.o qxl-render.o
 
 obj-$(CONFIG_VIRTIO) += virtio-gpu.o
+obj-$(CONFIG_VIRTIO_PCI) += virtio-gpu-pci.o
hw/display/virtio-gpu-pci.c new file +68 -0

68 lines not on this page · raw message

hw/virtio/virtio-pci.h +15 -0
index b382688..efe8d31 100644
@@ -24,6 +24,7 @@
 #include "hw/virtio/virtio-balloon.h"
 #include "hw/virtio/virtio-bus.h"
 #include "hw/virtio/virtio-9p.h"
+#include "hw/virtio/virtio-gpu.h"
 #ifdef CONFIG_VIRTFS
 #include "hw/9pfs/virtio-9p.h"
 #endif
@@ -39,6 +40,7 @@ typedef struct VirtIOSerialPCI VirtIOSerialPCI;
 typedef struct VirtIONetPCI VirtIONetPCI;
 typedef struct VHostSCSIPCI VHostSCSIPCI;
 typedef struct VirtIORngPCI VirtIORngPCI;
+typedef struct VirtIOGPUPCI VirtIOGPUPCI;
 
 /* virtio-pci-bus */
 
@@ -225,6 +227,19 @@ struct VirtIORngPCI {
     VirtIORNG vdev;
 };
 
+/*
+ * virtio-gpu-pci: This extends VirtioPCIProxy.
+ */
+#define TYPE_VIRTIO_GPU_PCI "virtio-gpu-pci"
+#define VIRTIO_GPU_PCI(obj) \
+        OBJECT_CHECK(VirtIOGPUPCI, (obj), TYPE_VIRTIO_GPU_PCI)
+
+struct VirtIOGPUPCI {
+    VirtIOPCIProxy parent_obj;
+    VirtIOGPU vdev;
+};
+
+
 /* Virtio ABI version, if we increment this, we break the guest driver. */
 #define VIRTIO_PCI_ABI_VERSION          0
 
Signature · 1 line
1.8.3.1
#19 lore raw

Re: [Qemu-devel] [PATCH] opengl: require glx

In reply to Gerd Hoffmann
Quoted 4 lines · Gerd Hoffmann

hw/display/milkymist-tmu2.c uses glx. That will be replaced with egl in the future, with qemu getting more opengl support. But we are not there yet, so put it back into configure to fix build failures on machines without glx (i.e. macos, possibly windows too).

Oops, scratch that one, old leftover *.patch file.

sorry,
Gerd

Reviewed-by on v1 1/9
#2 lore raw

Re: [Qemu-devel] [PATCH 1/9] virtio-gpu/2d: add hardware spec include file

In reply to Gerd Hoffmann
Quoted 11 lines · Gerd Hoffmann

This patch adds the header file with structs and defines for the virtio based gpu device. Covers 2d operations only.

Written by Dave Airlie and Gerd Hoffmann.

---
  include/hw/virtio/virtgpu_hw.h | 203 +++++++++++++++++++++++++++++++++++++++++
  1 file changed, 203 insertions(+)

create mode 100644 include/hw/virtio/virtgpu_hw.h

There are some conflicts with the latest specification I was able to obtain (https://www.kraxel.org/virtio/virtio-v1.0-csprd03-virtio-gpu.pdf); for instance, the ordering of the fields in virtio_gpu_resp_display_info is different there, some GPU formats are different (but no conflict), and so on.

However, I guess this file will be pretty much the specification for the interface, so as long as it makes sense and it compiles, it's correct.

#21 lore raw

Re: [Qemu-devel] [PATCH 8/9] virtio-gpu: add to display-vga test

In reply to Gerd Hoffmann
Quoted 47 lines · Gerd Hoffmann
---
 tests/Makefile           |  3 +++
 tests/display-vga-test.c | 18 ++++++++++++++++++
 2 files changed, 21 insertions(+)
tests/Makefile +3 -0
index 588f438..55ad89f 100644
@@ -133,6 +133,9 @@ check-qtest-pci-y += tests/display-vga-test$(EXESUF)
 gcov-files-pci-y += hw/display/vga.c
 gcov-files-pci-y += hw/display/cirrus_vga.c
 gcov-files-pci-y += hw/display/vga-pci.c
+gcov-files-pci-y += hw/display/virtio-gpu.c
+gcov-files-pci-y += hw/display/virtio-gpu-pci.c
+gcov-files-pci-y += hw/display/virtio-vga.c
 check-qtest-pci-y += tests/intel-hda-test$(EXESUF)
 gcov-files-pci-y += hw/audio/intel-hda.c hw/audio/hda-codec.c
 
tests/display-vga-test.c +14 -0
index 17f5910..cd0b873 100644
@@ -36,6 +36,20 @@ static void pci_multihead(void)
     qtest_end();
 }
 
+#ifdef CONFIG_VIRTIO_GPU
+static void pci_virtio_gpu(void)
+{
+    qtest_start("-vga none -device virtio-gpu-pci");
+    qtest_end();
+}
+
+static void pci_virtio_vga(void)
+{
+    qtest_start("-vga none -device virtio-vga");
+    qtest_end();
+}
+#endif
+
 int main(int argc, char **argv)
 {
     int ret;

tests/display-vga-test.c int main(int argc, char **argv) · line 69

Quoted 10 lines
tests/display-vga-test.c +4 -0
@@ -46,6 +60,10 @@ int main(int argc, char **argv)
     qtest_add_func("/display/pci/stdvga", pci_stdvga);
     qtest_add_func("/display/pci/secondary", pci_secondary);
     qtest_add_func("/display/pci/multihead", pci_multihead);
+#ifdef CONFIG_VIRTIO_GPU
+    qtest_add_func("/display/pci/virtio-gpu", pci_virtio_gpu);
+    qtest_add_func("/display/pci/virtio-vga", pci_virtio_vga);
+#endif
     ret = g_test_run();
 
     return ret;

Which config file is defining this?

Paolo

Reviewed-by on v1 2/9
#5 lore raw

Re: [Qemu-devel] [PATCH 2/9] virtio-gpu/2d: add virtio gpu core code

In reply to Gerd Hoffmann
Quoted 21 lines · Gerd Hoffmann

This patch adds the core code for virtio gpu emulation, covering 2d support.

Written by Dave Airlie and Gerd Hoffmann.

---
  hw/display/Makefile.objs       |   2 +
  hw/display/virtio-gpu.c        | 923 +++++++++++++++++++++++++++++++++++++++++
  include/hw/virtio/virtio-gpu.h | 147 +++++++
  trace-events                   |  14 +
  4 files changed, 1086 insertions(+)

create mode 100644 hw/display/virtio-gpu.c create mode 100644 include/hw/virtio/virtio-gpu.h

hw/display/virtio-gpu.c new file +0 -0
new file mode 100644
index 0000000..ab71291

[snip]

hw/display/virtio-gpu.c line 542

Quoted 12 lines
hw/display/virtio-gpu.c new file +12 -0
+int virtio_gpu_create_mapping_iov(struct virtio_gpu_resource_attach_backing *ab,
+                                  struct virtio_gpu_ctrl_command *cmd,
+                                  struct iovec **iov)
+{
+    struct virtio_gpu_mem_entry *ents;
+    size_t esize, s;
+    int i;
+
+    if (ab->nr_entries > 1024) {
+        qemu_log_mask(LOG_GUEST_ERROR,
+                      "%s: nr_entries is too big (%d > 1024)\n",
+                      __func__, ab->nr_entries);

You said that maybe you wanted to go for 16384 instead of 1024.

[snip]

Quoted 26 lines
include/hw/virtio/virtio-gpu.h new file +20 -0
new file mode 100644
index 0000000..5d26ca9
@@ -0,0 +1,147 @@
+/*
+ * Virtio GPU Device
+ *
+ * Copyright Red Hat, Inc. 2013-2014
+ *
+ * Authors:
+ *     Dave Airlie <[email protected]>
+ *     Gerd Hoffmann <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.
+ * See the COPYING file in the top-level directory.
+ */
+
+#ifndef _QEMU_VIRTIO_VGA_H
+#define _QEMU_VIRTIO_VGA_H
+
+#include "qemu/queue.h"
+#include "ui/qemu-pixman.h"
+#include "ui/console.h"
+#include "hw/virtio/virtio.h"

include/hw/virtio/virtio-gpu.h line 30

Quoted 10 lines
include/hw/virtio/virtio-gpu.h new file +10 -0
+#include "hw/pci/pci.h"
+
+#include "hw/virtio/virtgpu_hw.h"
+#define TYPE_VIRTIO_GPU "virtio-gpu-device"
+#define VIRTIO_GPU(obj)                                        \
+        OBJECT_CHECK(VirtIOGPU, (obj), TYPE_VIRTIO_GPU)
+
+#define VIRTIO_ID_GPU 16
+
+#define VIRTIO_GPU_MAX_RES 16

Unused in this series. Is that intentional?

Independent of whether you keep it or remove it, and independent of whether you increase the ab->nr_entries limit:

Reviewed-by on v1 3/9
#9 lore raw

Re: [Qemu-devel] [PATCH 3/9] virtio-gpu-pci: add virtio pci support

In reply to Gerd Hoffmann
Quoted 7 lines · Gerd Hoffmann

This patch adds virtio-gpu-pci, which is the pci proxy for the virtio gpu device. With this patch in place virtio-gpu is functional. You need a linux guest with a virtio-gpu driver though, and output will appear pretty late in boot, once the kernel initialized drm and fbcon.

Written by Dave Airlie and Gerd Hoffmann.

Quoted 8 lines
---
  hw/display/Makefile.objs    |  1 +
  hw/display/virtio-gpu-pci.c | 68 +++++++++++++++++++++++++++++++++++++++++++++
  hw/virtio/virtio-pci.h      | 15 ++++++++++
  3 files changed, 84 insertions(+)

create mode 100644 hw/display/virtio-gpu-pci.c

#11 lore raw

Re: [Qemu-devel] [PATCH 4/9] virtio-vga: add virtio gpu device with vga compatibility

In reply to Gerd Hoffmann
Quoted 6 lines · Gerd Hoffmann

This patch adds a virtio-vga device. It is simliar to virtio-gpu-pci, but it also adds in vga compatibility, so guests without native virtio-gpu support can drive the device in vga mode.

Written by Dave Airlie and Gerd Hoffmann.

Quoted 8 lines
---
  default-configs/x86_64-softmmu.mak |   1 +
  hw/display/Makefile.objs           |   1 +
  hw/display/virtio-vga.c            | 150 +++++++++++++++++++++++++++++++++++++
  3 files changed, 152 insertions(+)

create mode 100644 hw/display/virtio-vga.c

Looks good to me, but I can't really give an R-b because I'm really unfamiliar with all things concerning VGA.

Max

#13 lore raw

Re: [Qemu-devel] [PATCH 5/9] virtio-vga: add '-vga virtio' support

In reply to Gerd Hoffmann
Quoted 6 lines · Gerd Hoffmann

Some convinience fluff: Add support for '-vga virtio', also add virtio-vga to the list of vga cards so '-device virtio-vga' will turn off the default vga.

Written by Dave Airlie and Gerd Hoffmann.

Quoted 8 lines
---
  hw/pci/pci.c            |  2 ++
  include/sysemu/sysemu.h |  2 +-
  qemu-options.hx         |  4 +++-
  vl.c                    | 13 +++++++++++++
  4 files changed, 19 insertions(+), 2 deletions(-)

Hm, the other VGA devices which support only PCI ("vmware" and "qxl") emit explicit error messages in isa_vga_init(). Maybe we should do the same? Without, the initialization fails silently and qemu starts, but there is no display ("-machine isapc -display virtio").

Max

Reviewed-by on v1 6/9
#15 lore raw

Re: [Qemu-devel] [PATCH 6/9] virtio-vga: add vgabios configuration

In reply to Gerd Hoffmann
Quoted 10 lines · Gerd Hoffmann

Add seavgabios configuration for virtio-vga,
hook up the new vgabios in the makefiles.

---
  Makefile               | 2 +-
  roms/Makefile          | 2 +-
  roms/config.vga-virtio | 6 ++++++
  3 files changed, 8 insertions(+), 2 deletions(-)

create mode 100644 roms/config.vga-virtio

#17 lore raw

Re: [Qemu-devel] [PATCH 7/9] virtio-vga: add vgabios binary

In reply to Gerd Hoffmann
Quoted 7 lines · Gerd Hoffmann

Add prebuilt vgabios-virtio.bin binary.

---
  pc-bios/vgabios-virtio.bin | Bin 0 -> 37376 bytes
  1 file changed, 0 insertions(+), 0 deletions(-)

create mode 100644 pc-bios/vgabios-virtio.bin

Well, I can't really review this, sorry...

Max

#6 lore raw

Re: [Qemu-devel] [PATCH 2/9] virtio-gpu/2d: add virtio gpu core code

In reply to Gerd Hoffmann
Quoted 21 lines · Gerd Hoffmann

This patch adds the core code for virtio gpu emulation, covering 2d support.

Written by Dave Airlie and Gerd Hoffmann.

---
  hw/display/Makefile.objs       |   2 +
  hw/display/virtio-gpu.c        | 923 +++++++++++++++++++++++++++++++++++++++++
  include/hw/virtio/virtio-gpu.h | 147 +++++++
  trace-events                   |  14 +
  4 files changed, 1086 insertions(+)

create mode 100644 hw/display/virtio-gpu.c create mode 100644 include/hw/virtio/virtio-gpu.h

hw/display/virtio-gpu.c new file +0 -0
new file mode 100644
index 0000000..ab71291

[snip]

Quoted 20 lines
hw/display/virtio-gpu.c new file +20 -0
+static void virtio_gpu_device_realize(DeviceState *qdev, Error **errp)
+{
+    VirtIODevice *vdev = VIRTIO_DEVICE(qdev);
+    VirtIOGPU *g = VIRTIO_GPU(qdev);
+    int i;
+
+    g->config_size = sizeof(struct virtio_gpu_config);
+    g->virtio_config.num_scanouts = g->conf.max_outputs;
+    virtio_init(VIRTIO_DEVICE(g), "virtio-gpu", VIRTIO_ID_GPU,
+                g->config_size);
+
+    g->req_state[0].width = 1024;
+    g->req_state[0].height = 768;
+
+    g->ctrl_vq   = virtio_add_queue(vdev, 256, virtio_gpu_handle_ctrl_cb);
+    g->cursor_vq = virtio_add_queue(vdev, 256, virtio_gpu_handle_cursor_cb);
+
+    g->ctrl_bh = qemu_bh_new(virtio_gpu_ctrl_bh, g);
+    g->cursor_bh = qemu_bh_new(virtio_gpu_cursor_bh, g);
+    QTAILQ_INIT(&g->reslist);

hw/display/virtio-gpu.c line 835

Quoted 10 lines
hw/display/virtio-gpu.c new file +10 -0
+    QTAILQ_INIT(&g->fenceq);
+
+    g->enabled_output_bitmask = 1;
+    g->qdev = qdev;
+
+    for (i = 0; i < g->conf.max_outputs; i++) {
+        g->scanout[i].con =
+            graphic_console_init(DEVICE(g), i, &virtio_gpu_ops, g);
+        if (i > 0) {
+            dpy_gfx_replace_surface(g->scanout[i].con, NULL);

GTK can't cope very well with NULL surfaces (read: after patch 7 (when using -vga virtio finally works) "x86_64-softmmu/qemu-system-x86_64 -vga virtio -display gtk" segfaults). With SDL (SDL2), it works fine.

A simple block like "if (!surface) { if (vc->gfx.surface) { cairo_surface_destroy(vc->gfx.surface); } vc->gfx.surface = NULL; return; }" at the beginning of gd_switch() in ui/gtk.c seems to work for me, though.

A similar problem exists with SDL1: Using Ctrl-Alt-2 segfaults (which is due to new_surface being NULL in sdl_switch(), and thus new_surface->format in the very first statement failing).

Max

Quoted 266 lines
hw/display/virtio-gpu.c new file +88 -0
+        }
+    }
+}
+
+static void virtio_gpu_instance_init(Object *obj)
+{
+}
+
+static void virtio_gpu_reset(VirtIODevice *vdev)
+{
+    VirtIOGPU *g = VIRTIO_GPU(vdev);
+    struct virtio_gpu_simple_resource *res, *tmp;
+    int i;
+
+    g->enable = 0;
+
+    QTAILQ_FOREACH_SAFE(res, &g->reslist, next, tmp) {
+        virtio_gpu_resource_destroy(g, res);
+    }
+    for (i = 0; i < g->conf.max_outputs; i++) {
+#if 0
+        g->req_state[i].x = 0;
+        g->req_state[i].y = 0;
+        if (i == 0) {
+            g->req_state[0].width = 1024;
+            g->req_state[0].height = 768;
+        } else {
+            g->req_state[i].width = 0;
+            g->req_state[i].height = 0;
+        }
+#endif
+        g->scanout[i].resource_id = 0;
+        g->scanout[i].width = 0;
+        g->scanout[i].height = 0;
+        g->scanout[i].x = 0;
+        g->scanout[i].y = 0;
+        g->scanout[i].ds = NULL;
+    }
+    g->enabled_output_bitmask = 1;
+}
+
+static Property virtio_gpu_properties[] = {
+    DEFINE_VIRTIO_GPU_PROPERTIES(VirtIOGPU, conf),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void virtio_gpu_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
+
+    vdc->realize = virtio_gpu_device_realize;
+    vdc->get_config = virtio_gpu_get_config;
+    vdc->set_config = virtio_gpu_set_config;
+    vdc->get_features = virtio_gpu_get_features;
+    vdc->set_features = virtio_gpu_set_features;
+
+    vdc->reset = virtio_gpu_reset;
+
+    dc->props = virtio_gpu_properties;
+}
+
+static const TypeInfo virtio_gpu_info = {
+    .name = TYPE_VIRTIO_GPU,
+    .parent = TYPE_VIRTIO_DEVICE,
+    .instance_size = sizeof(VirtIOGPU),
+    .instance_init = virtio_gpu_instance_init,
+    .class_init = virtio_gpu_class_init,
+};
+
+static void virtio_register_types(void)
+{
+    type_register_static(&virtio_gpu_info);
+}
+
+type_init(virtio_register_types)
+
+QEMU_BUILD_BUG_ON(sizeof(struct virtio_gpu_ctrl_hdr)                != 24);
+QEMU_BUILD_BUG_ON(sizeof(struct virtio_gpu_update_cursor)           != 56);
+QEMU_BUILD_BUG_ON(sizeof(struct virtio_gpu_resource_unref)          != 32);
+QEMU_BUILD_BUG_ON(sizeof(struct virtio_gpu_resource_create_2d)      != 40);
+QEMU_BUILD_BUG_ON(sizeof(struct virtio_gpu_set_scanout)             != 48);
+QEMU_BUILD_BUG_ON(sizeof(struct virtio_gpu_resource_flush)          != 48);
+QEMU_BUILD_BUG_ON(sizeof(struct virtio_gpu_transfer_to_host_2d)     != 56);
+QEMU_BUILD_BUG_ON(sizeof(struct virtio_gpu_mem_entry)               != 16);
+QEMU_BUILD_BUG_ON(sizeof(struct virtio_gpu_resource_attach_backing) != 32);
+QEMU_BUILD_BUG_ON(sizeof(struct virtio_gpu_resource_detach_backing) != 32);
+QEMU_BUILD_BUG_ON(sizeof(struct virtio_gpu_resp_display_info)       != 408);
include/hw/virtio/virtio-gpu.h new file +147 -0
new file mode 100644
index 0000000..5d26ca9
@@ -0,0 +1,147 @@
+/*
+ * Virtio GPU Device
+ *
+ * Copyright Red Hat, Inc. 2013-2014
+ *
+ * Authors:
+ *     Dave Airlie <[email protected]>
+ *     Gerd Hoffmann <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.
+ * See the COPYING file in the top-level directory.
+ */
+
+#ifndef _QEMU_VIRTIO_VGA_H
+#define _QEMU_VIRTIO_VGA_H
+
+#include "qemu/queue.h"
+#include "ui/qemu-pixman.h"
+#include "ui/console.h"
+#include "hw/virtio/virtio.h"
+#include "hw/pci/pci.h"
+
+#include "hw/virtio/virtgpu_hw.h"
+#define TYPE_VIRTIO_GPU "virtio-gpu-device"
+#define VIRTIO_GPU(obj)                                        \
+        OBJECT_CHECK(VirtIOGPU, (obj), TYPE_VIRTIO_GPU)
+
+#define VIRTIO_ID_GPU 16
+
+#define VIRTIO_GPU_MAX_RES 16
+
+#define VIRTIO_GPU_MAX_SCANOUT 4
+
+struct virtio_gpu_simple_resource {
+    uint32_t resource_id;
+    uint32_t width;
+    uint32_t height;
+    uint32_t format;
+    struct iovec *iov;
+    unsigned int iov_cnt;
+    uint32_t scanout_bitmask;
+    pixman_image_t *image;
+    QTAILQ_ENTRY(virtio_gpu_simple_resource) next;
+};
+
+struct virtio_gpu_scanout {
+    QemuConsole *con;
+    DisplaySurface *ds;
+    uint32_t width, height;
+    int x, y;
+    int invalidate;
+    uint32_t resource_id;
+    QEMUCursor *current_cursor;
+};
+
+struct virtio_gpu_requested_state {
+    uint32_t width, height;
+    int x, y;
+};
+
+struct virtio_gpu_conf {
+    uint32_t max_outputs;
+};
+
+struct virtio_gpu_ctrl_command {
+    VirtQueueElement elem;
+    VirtQueue *vq;
+    struct virtio_gpu_ctrl_hdr cmd_hdr;
+    uint32_t error;
+    bool finished;
+    QTAILQ_ENTRY(virtio_gpu_ctrl_command) next;
+};
+
+typedef struct VirtIOGPU {
+    VirtIODevice parent_obj;
+
+    QEMUBH *ctrl_bh;
+    QEMUBH *cursor_bh;
+    VirtQueue *ctrl_vq;
+    VirtQueue *cursor_vq;
+
+    int enable;
+
+    int config_size;
+    DeviceState *qdev;
+
+    QTAILQ_HEAD(, virtio_gpu_simple_resource) reslist;
+    QTAILQ_HEAD(, virtio_gpu_ctrl_command) fenceq;
+
+    struct virtio_gpu_scanout scanout[VIRTIO_GPU_MAX_SCANOUT];
+    struct virtio_gpu_requested_state req_state[VIRTIO_GPU_MAX_SCANOUT];
+
+    struct virtio_gpu_conf conf;
+    int enabled_output_bitmask;
+    struct virtio_gpu_config virtio_config;
+
+    QEMUTimer *fence_poll;
+    QEMUTimer *print_stats;
+
+    struct {
+        uint32_t inflight;
+        uint32_t max_inflight;
+        uint32_t requests;
+        uint32_t req_3d;
+        uint32_t bytes_3d;
+    } stats;
+} VirtIOGPU;
+
+extern const GraphicHwOps virtio_gpu_ops;
+
+/* to share between PCI and VGA */
+#define DEFINE_VIRTIO_GPU_PCI_PROPERTIES(_state)               \
+    DEFINE_PROP_BIT("ioeventfd", _state, flags,                \
+                    VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, false), \
+    DEFINE_PROP_UINT32("vectors", _state, nvectors, 3)
+
+#define DEFINE_VIRTIO_GPU_PROPERTIES(_state, _conf_field)               \
+    DEFINE_PROP_UINT32("max_outputs", _state, _conf_field.max_outputs, 2)
+
+#define VIRTIO_GPU_FILL_CMD(out) do {                                   \
+        size_t s;                                                       \
+        s = iov_to_buf(cmd->elem.out_sg, cmd->elem.out_num, 0,          \
+                       &out, sizeof(out));                              \
+        if (s != sizeof(out)) {                                         \
+            qemu_log_mask(LOG_GUEST_ERROR,                              \
+                          "%s: command size incorrect %zu vs %zu\n",    \
+                          __func__, s, sizeof(out));                    \
+            return;                                                     \
+        }                                                               \
+    } while (0)
+
+/* virtio-gpu.c */
+void virtio_gpu_ctrl_response(VirtIOGPU *g,
+                              struct virtio_gpu_ctrl_command *cmd,
+                              struct virtio_gpu_ctrl_hdr *resp,
+                              size_t resp_len);
+void virtio_gpu_ctrl_response_nodata(VirtIOGPU *g,
+                                     struct virtio_gpu_ctrl_command *cmd,
+                                     enum virtio_gpu_ctrl_type type);
+void virtio_gpu_get_display_info(VirtIOGPU *g,
+                                 struct virtio_gpu_ctrl_command *cmd);
+int virtio_gpu_create_mapping_iov(struct virtio_gpu_resource_attach_backing *ab,
+                                  struct virtio_gpu_ctrl_command *cmd,
+                                  struct iovec **iov);
+void virtio_gpu_cleanup_mapping_iov(struct iovec *iov, uint32_t count);
+
+#endif
trace-events +14 -0
index 30eba92..a3d6fff 100644
@@ -1167,6 +1167,20 @@ vmware_scratch_read(uint32_t index, uint32_t value) "index %d, value 0x%x"
  vmware_scratch_write(uint32_t index, uint32_t value) "index %d, value 0x%x"
  vmware_setmode(uint32_t w, uint32_t h, uint32_t bpp) "%dx%d @ %d bpp"
 
+# hw/display/virtio-gpu.c
+virtio_gpu_cmd_get_display_info(void) ""
+virtio_gpu_cmd_get_caps(void) ""
+virtio_gpu_cmd_set_scanout(uint32_t id, uint32_t res, uint32_t w, uint32_t h, uint32_t x, uint32_t y) "id %d, res 0x%x, w %d, h %d, x %d, y %d"
+virtio_gpu_cmd_res_create_2d(uint32_t res, uint32_t fmt, uint32_t w, uint32_t h) "res 0x%x, fmt 0x%x, w %d, h %d"
+virtio_gpu_cmd_res_create_3d(uint32_t res, uint32_t fmt, uint32_t w, uint32_t h, uint32_t d) "res 0x%x, fmt 0x%x, w %d, h %d, d %d"
+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_xfer_toh_2d(uint32_t res) "res 0x%x"
+virtio_gpu_cmd_res_flush(uint32_t res, uint32_t w, uint32_t h, uint32_t x, uint32_t y) "res 0x%x, w %d, h %d, x %d, y %d"
+virtio_gpu_fence_ctrl(uint64_t fence, uint32_t type) "fence 0x%" PRIx64 ", type 0x%x"
+virtio_gpu_fence_resp(uint64_t fence) "fence 0x%" PRIx64
+
  # savevm.c
  qemu_loadvm_state_section(unsigned int section_type) "%d"
  qemu_loadvm_state_section_partend(uint32_t section_id) "%u"
#3 lore raw

Re: [Qemu-devel] [PATCH 1/9] virtio-gpu/2d: add hardware spec include file

In reply to Max Reitz

Hi,

Quoted 6 lines

There are some conflicts with the latest specification I was able to obtain
(https://www.kraxel.org/virtio/virtio-v1.0-csprd03-virtio-gpu.pdf); for instance, the ordering of the fields in virtio_gpu_resp_display_info is different there, some GPU formats are different (but no conflict), and so on.

Good point, I should update the specs.

thanks,
Gerd

#7 lore raw

Re: [Qemu-devel] [PATCH 2/9] virtio-gpu/2d: add virtio gpu core code

In reply to Max Reitz

Hi,

Quoted 9 lines

hw/display/virtio-gpu.c line 835

Quoted 5 lines
hw/display/virtio-gpu.c new file +5 -0
+    for (i = 0; i < g->conf.max_outputs; i++) {
+        g->scanout[i].con =
+            graphic_console_init(DEVICE(g), i, &virtio_gpu_ops, g);
+        if (i > 0) {
+            dpy_gfx_replace_surface(g->scanout[i].con, NULL);

GTK can't cope very well with NULL surfaces (read: after patch 7 (when using -vga virtio finally works) "x86_64-softmmu/qemu-system-x86_64 -vga virtio -display gtk" segfaults). With SDL (SDL2), it works fine.

Yes, I know. I have a gtk patch for that in the pipeline.

But that alone doesn't get multihead work sanely as there is at least one more problem to tackle: Mouse coordinates are not correct. Our options are:

(a) Have guest notify host about screen arrangement, then transform coordinates in qemu. Dave did that initially.
(b) Have a guest agent (spice style).
(c) Have one tablet per head and link them. That is very simliar to physical hardware (think touchscreen).

I think (c) will work best long-term, but it is also the most difficult one as various projects are involved here to get the guest-side configuration done.

I've changed the number of heads to be 1 by default, we better sort all those issues before we flip the multihead default switch.

cheers,
Gerd

#22 lore raw

Re: [Qemu-devel] [PATCH 8/9] virtio-gpu: add to display-vga test

In reply to Paolo Bonzini

Hi,

Quoted 10 lines

tests/display-vga-test.c int main(int argc, char **argv) · line 69

Quoted 8 lines
tests/display-vga-test.c +4 -0
+#ifdef CONFIG_VIRTIO_GPU
+    qtest_add_func("/display/pci/virtio-gpu", pci_virtio_gpu);
+    qtest_add_func("/display/pci/virtio-vga", pci_virtio_vga);
+#endif
     ret = g_test_run();
 
     return ret;

Which config file is defining this?

Ahem, good point, CONFIG_VIRTIO_GPU used to be there but is gone now. I'll fixup the test.

thanks,
Gerd

#24 lore raw
In reply to Gerd Hoffmann

Hi Gerd,

This looks great, thanks for your work on this. Unfortunately, I'm seeing the segfault below.

Alex, do you have any thoughts on how well this might be able to replace the Goldfish Framebuffer on the Android Emulator?

Quoted 18 lines · Gerd Hoffmann

Hi,

Next round of virtio-gpu patches. Patches 1-8 are meant to be merged, patch 9 is a hack to simplify testing with libvirt and will not be merged.

Changes since the RfC submission earlier this month are a bunch of sanity checks being added (mostly pointed out by max) and the virtio-1.0 adaptions are squashed in now.

This series depends on virtio 1.0 patches still not merged.

This series is also available via git:
git://git.kraxel.org/qemu tags/virtio-gpu-2015-03-13

The virtio patches are here (mst's virtio-1.0 branch, rebased to master):
git://git.kraxel.org/qemu tags/virtio-mst-rebased-2015-03-13

Quoted 8 lines

Guest kernel driver is here:
git://git.kraxel.org/linux virtio-gpu

Usage:
qemu-system-x86_64 -vga virtio [ ... ] qemu-system-x86_64 -device virtio-vga [ ... ] qemu-system-ppc64 -M pseries -device virtio-gpu-pci [ ... ] qemu-system-arm -M virt -device virtio-gpu-device [ ... ]

git remote add kraxel git://git.kraxel.org/qemu
git fetch kraxel
git checkout tags/virtio-gpu-2015-03-13
./configure --target-list=aarch64-softmmu
make -j 12
gdb --args aarch64-softmmu/qemu-system-aarch64 -M virt -cpu cortex-a57 \
-device virtio-gpu-device
[...]
Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 0x7ffff7fb0ac0 (LWP 26568)]
gd_switch (dcl=0x5555563285d0, surface=0x0) at ui/gtk.c:565
565 trace_gd_switch(vc->label, surface_width(surface), surface_heigh
t(surface));
(gdb) bt
#0 gd_switch (dcl=0x5555563285d0, surface=0x0) at ui/gtk.c:565 #1 0x00005555558ba706 in register_displaychangelistener (

    dcl=0x5555563285d0) at ui/console.c:1353
#2  0x00005555558dcd80 in gd_vc_gfx_init (view_menu=0x555556bf4220,
    group=<optimized out>, idx=<optimized out>, con=0x555556333de0,
    vc=0x555556328598, s=0x555556328470) at ui/gtk.c:1705
#3  gd_create_menu_view (s=0x555556328470) at ui/gtk.c:1781
#4  gd_create_menus (s=0x555556328470) at ui/gtk.c:1807
#5  gtk_display_init (ds=<optimized out>, full_screen=false,
    grab_on_hover=false) at ui/gtk.c:1894

#6 0x0000555555609247 in main (argc=<optimized out>,
argv=<optimized out>, envp=<optimized out>) at vl.c:4292

Thanks,
Chris

Signature · 3 lines
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project