Skip to contentSkip to conversation

vga: new display devices

PATCH In review Gerd Hoffmann 6 participants 23 messages Mar 12, 2014 – Mar 17, 2014 Kbuild

lore
Share & tools
lore
#1 lore raw

PATCH 1/4 vga: allow non-global vmstate

In reply to Gerd Hoffmann

Need a way to opt-out from vga.vram being global vmstate, for secondary vga cards. Add a bool parameter to vga_common_init to support this.

---
 hw/display/cirrus_vga.c | 4 ++--
 hw/display/qxl.c        | 2 +-
 hw/display/vga-isa-mm.c | 2 +-
 hw/display/vga-isa.c    | 2 +-
 hw/display/vga-pci.c    | 2 +-
 hw/display/vga.c        | 4 ++--
 hw/display/vga_int.h    | 2 +-
 hw/display/vmware_vga.c | 2 +-
 8 files changed, 10 insertions(+), 10 deletions(-)
hw/display/cirrus_vga.c +2 -2
index 0d3127d..d1afc76 100644
@@ -2913,7 +2913,7 @@ static void isa_cirrus_vga_realizefn(DeviceState *dev, Error **errp)
     ISACirrusVGAState *d = ISA_CIRRUS_VGA(dev);
     VGACommonState *s = &d->cirrus_vga.vga;
 
-    vga_common_init(s, OBJECT(dev));
+    vga_common_init(s, OBJECT(dev), true);
     cirrus_init_common(&d->cirrus_vga, OBJECT(dev), CIRRUS_ID_CLGD5430, 0,
                        isa_address_space(isadev),
                        isa_address_space_io(isadev));
@@ -2960,7 +2960,7 @@ static int pci_cirrus_vga_initfn(PCIDevice *dev)
      int16_t device_id = pc->device_id;
 
      /* setup VGA */
-     vga_common_init(&s->vga, OBJECT(dev));
+     vga_common_init(&s->vga, OBJECT(dev), true);
      cirrus_init_common(s, OBJECT(dev), device_id, 1, pci_address_space(dev),
                         pci_address_space_io(dev));
      s->vga.con = graphic_console_init(DEVICE(dev), 0, s->vga.hw_ops, &s->vga);
hw/display/qxl.c +1 -1
index 47bbf1f..e9c54d7 100644
@@ -2061,7 +2061,7 @@ static int qxl_init_primary(PCIDevice *dev)
     qxl->id = 0;
     qxl_init_ramsize(qxl);
     vga->vram_size_mb = qxl->vga.vram_size >> 20;
-    vga_common_init(vga, OBJECT(dev));
+    vga_common_init(vga, OBJECT(dev), true);
     vga_init(vga, OBJECT(dev),
              pci_address_space(dev), pci_address_space_io(dev), false);
     portio_list_init(qxl_vga_port_list, OBJECT(dev), qxl_vga_portio_list,
hw/display/vga-isa-mm.c +1 -1
index afc46b8..4efc222 100644
@@ -132,7 +132,7 @@ int isa_vga_mm_init(hwaddr vram_base,
     s = g_malloc0(sizeof(*s));
 
     s->vga.vram_size_mb = VGA_RAM_SIZE >> 20;
-    vga_common_init(&s->vga, NULL);
+    vga_common_init(&s->vga, NULL, true);
     vga_mm_init(s, vram_base, ctrl_base, it_shift, address_space);
 
     s->vga.con = graphic_console_init(NULL, 0, s->vga.hw_ops, s);
hw/display/vga-isa.c +1 -1
index 1d9ea6b..2b480bd 100644
@@ -56,7 +56,7 @@ static void vga_isa_realizefn(DeviceState *dev, Error **errp)
     MemoryRegion *vga_io_memory;
     const MemoryRegionPortio *vga_ports, *vbe_ports;
 
-    vga_common_init(s, OBJECT(dev));
+    vga_common_init(s, OBJECT(dev), true);
     s->legacy_address_space = isa_address_space(isadev);
     vga_io_memory = vga_init_io(s, OBJECT(dev), &vga_ports, &vbe_ports);
     isa_register_portio_list(isadev, 0x3b0, vga_ports, s, "vga");
hw/display/vga-pci.c +1 -1
index 574ea0e..ad49156 100644
@@ -147,7 +147,7 @@ static int pci_std_vga_initfn(PCIDevice *dev)
     VGACommonState *s = &d->vga;
 
     /* vga + console init */
-    vga_common_init(s, OBJECT(dev));
+    vga_common_init(s, OBJECT(dev), true);
     vga_init(s, OBJECT(dev), pci_address_space(dev), pci_address_space_io(dev),
              true);
 
hw/display/vga.c +2 -2
index 063319d..8891e0a 100644
@@ -2252,7 +2252,7 @@ static const GraphicHwOps vga_ops = {
     .text_update = vga_update_text,
 };
 
-void vga_common_init(VGACommonState *s, Object *obj)
+void vga_common_init(VGACommonState *s, Object *obj, bool global_vmstate)
 {
     int i, j, v, b;
 
@@ -2289,7 +2289,7 @@ void vga_common_init(VGACommonState *s, Object *obj)
 
     s->is_vbe_vmstate = 1;
     memory_region_init_ram(&s->vram, obj, "vga.vram", s->vram_size);
-    vmstate_register_ram_global(&s->vram);
+    vmstate_register_ram(&s->vram, global_vmstate ? NULL : DEVICE(obj));
     xen_register_framebuffer(&s->vram);
     s->vram_ptr = memory_region_get_ram_ptr(&s->vram);
     s->get_bpp = vga_get_bpp;
hw/display/vga_int.h +1 -1
index e641890..d42ac92 100644
@@ -177,7 +177,7 @@ static inline int c6_to_8(int v)
     return (v << 2) | (b << 1) | b;
 }
 
-void vga_common_init(VGACommonState *s, Object *obj);
+void vga_common_init(VGACommonState *s, Object *obj, bool global_vmstate);
 void vga_init(VGACommonState *s, Object *obj, MemoryRegion *address_space,
               MemoryRegion *address_space_io, bool init_vga_ports);
 MemoryRegion *vga_init_io(VGACommonState *s, Object *obj,
hw/display/vmware_vga.c +1 -1
index bd2c108..89f139f 100644
@@ -1206,7 +1206,7 @@ static void vmsvga_init(DeviceState *dev, struct vmsvga_state_s *s,
     vmstate_register_ram_global(&s->fifo_ram);
     s->fifo_ptr = memory_region_get_ram_ptr(&s->fifo_ram);
 
-    vga_common_init(&s->vga, OBJECT(dev));
+    vga_common_init(&s->vga, OBJECT(dev), true);
     vga_init(&s->vga, OBJECT(dev), address_space, io, true);
     vmstate_register(NULL, 0, &vmstate_vga_common, &s->vga);
     s->new_depth = 32;
Signature · 1 line
1.8.3.1
#0 lore raw

cover vga: new display devices

Hi,

This patch series adds new display devices.

Number one is secondary-vga. That is identical to VGA (aka -vga std), except that it doesn't occupy all the legacy vga stuff (ioports, memory window @ 0xa0000), so you can have more than one of these in the system. It has one pci memory bar for the framebuffer and one mmio bar for registers. OVMF can drive it. Doesn't use it as console for some reason, but initializes it and the linux kernel will see it as efifb. Cutting edge linux kernels can drive it too (bochs-drm driver in 3.14+).

Number two is virtio-gpu-pci. That is the virtio graphics card written by Dave Airlie. Only 2d for now, 3d support is to be tackled later on.

Linux kernel driver:
http://www.kraxel.org/cgit/linux/log/?h=virtio-vga-3d.kraxel
http://cgit.freedesktop.org/~airlied/linux/log/?h=virtio-vga-3d

Number three is virtio-vga. That is virtio-gpu-pci with all the vga compatibility fluff added. Firmware builder has cutting edge seavgabios.git packages which include a virtio vgabios for it, see
http://www.kraxel.org/repos/

cheers,
Gerd

Dave Airlie (2):
virtio-gpu: v0.3 of the virtio based GPU code.
virtio-vga: v1

Gerd Hoffmann (2):
vga: allow non-global vmstate
vga: add secondary stdvga variant

 Makefile                           |   2 +-
 default-configs/x86_64-softmmu.mak |   2 +
 docs/specs/standard-vga.txt        |  13 +-
 docs/specs/virtio-gpu.txt          |  89 +++++
 hw/display/Makefile.objs           |   4 +
 hw/display/cirrus_vga.c            |   4 +-
 hw/display/qxl.c                   |   2 +-
 hw/display/vga-isa-mm.c            |   2 +-
 hw/display/vga-isa.c               |   2 +-
 hw/display/vga-pci.c               |  63 +++-
 hw/display/vga.c                   |   8 +-
 hw/display/vga_int.h               |   2 +-
 hw/display/virtgpu_hw.h            | 149 ++++++++
 hw/display/virtio-gpu-pci.c        |  80 +++++
 hw/display/virtio-gpu.c            | 689 +++++++++++++++++++++++++++++++++++++
 hw/display/virtio-vga.c            | 169 +++++++++
 hw/display/vmware_vga.c            |   2 +-
 hw/pci/pci.c                       |   2 +
 hw/virtio/virtio-pci.h             |  15 +
 include/hw/pci/pci.h               |   1 +
 include/hw/virtio/virtio-gpu.h     |  91 +++++
 include/sysemu/sysemu.h            |   2 +-
 pc-bios/vgabios-virtio.bin         | Bin 0 -> 40448 bytes
 roms/Makefile                      |   2 +-
 roms/config.vga.virtio             |   6 +
 vl.c                               |  13 +
 26 files changed, 1398 insertions(+), 16 deletions(-)
 create mode 100644 docs/specs/virtio-gpu.txt
 create mode 100644 hw/display/virtgpu_hw.h
 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/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
#2 lore raw

PATCH 2/4 vga: add secondary stdvga variant

Add a standard vga variant which doesn't occupy any legacy ressources and thus can easily be used as secondary (or legacy-free) graphics adapter. Programming must be done using the MMIO bar.

---
 docs/specs/standard-vga.txt | 13 +++++++---
 hw/display/vga-pci.c        | 61 +++++++++++++++++++++++++++++++++++++++++++++
 hw/display/vga.c            |  4 +++
 3 files changed, 75 insertions(+), 3 deletions(-)
docs/specs/standard-vga.txt +10 -3
index 8a4c1e9..f82773e 100644
@@ -5,9 +5,10 @@ QEMU Standard VGA
 Exists in two variants, for isa and pci.
 
 command line switches:
-    -vga std            [ picks isa for -M isapc, otherwise pci ]
-    -device VGA         [ pci variant ]
-    -device isa-vga     [ isa variant ]
+    -vga std               [ picks isa for -M isapc, otherwise pci ]
+    -device VGA            [ pci variant ]
+    -device isa-vga        [ isa variant ]
+    -device secondary-vga  [ legacy-free pci variant ]
 
 
 PCI spec
@@ -31,9 +32,15 @@ PCI ROM Region:
    Holds the vgabios (qemu 0.14+).
 
 
+The legacy-free variant has no ROM and has PCI_CLASS_DISPLAY_OTHER
+instead of PCI_CLASS_DISPLAY_VGA.
+
+
 IO ports used
 -------------
 
+Doesn't apply to the legacy-free pci variant, use the MMIO bar instead.
+
 03c0 - 03df : standard vga ports
 01ce        : bochs vbe interface index port
 01cf        : bochs vbe interface data port (x86 only)
hw/display/vga-pci.c +61 -0

88 lines not on this page · raw message

hw/display/vga.c +4 -0
index 8891e0a..c4c3238 100644
@@ -171,6 +171,10 @@ static void vga_update_memory_access(VGACommonState *s)
     MemoryRegion *region, *old_region = s->chain4_alias;
     hwaddr base, offset, size;
 
+    if (s->legacy_address_space == NULL) {
+        return;
+    }
+
     s->chain4_alias = NULL;
 
     if ((s->sr[VGA_SEQ_PLANE_WRITE] & VGA_SR02_ALL_PLANES) ==
Signature · 1 line
1.8.3.1
#4 lore raw

PATCH 3/4 virtio-gpu: v0.3 of the virtio based GPU code.

In reply to Gerd Hoffmann

From: Dave Airlie <[email protected]>

This is the basic virtio-gpu which is

multi-head capable,
ARGB cursor support,
unaccelerated.

Some more info is in docs/specs/virtio-gpu.txt.

changes by kraxel:
* adapt to changes in master.
* move from hw/virtio to hw/display.
* codestyle cleanups.
* misc minor fixes.

virtio-gpu codestyle

---
 default-configs/x86_64-softmmu.mak |   1 +
 docs/specs/virtio-gpu.txt          |  89 +++++
 hw/display/Makefile.objs           |   3 +
 hw/display/virtgpu_hw.h            | 149 ++++++++
 hw/display/virtio-gpu-pci.c        |  80 +++++
 hw/display/virtio-gpu.c            | 689 +++++++++++++++++++++++++++++++++++++
 hw/virtio/virtio-pci.h             |  15 +
 include/hw/pci/pci.h               |   1 +
 include/hw/virtio/virtio-gpu.h     |  91 +++++
 9 files changed, 1118 insertions(+)
 create mode 100644 docs/specs/virtio-gpu.txt
 create mode 100644 hw/display/virtgpu_hw.h
 create mode 100644 hw/display/virtio-gpu-pci.c
 create mode 100644 hw/display/virtio-gpu.c
 create mode 100644 include/hw/virtio/virtio-gpu.h
default-configs/x86_64-softmmu.mak +1 -0
index 31bddce..1a00b78 100644
@@ -9,6 +9,7 @@ CONFIG_VGA_PCI=y
 CONFIG_VGA_ISA=y
 CONFIG_VGA_CIRRUS=y
 CONFIG_VMWARE_VGA=y
+CONFIG_VIRTIO_GPU=y
 CONFIG_VMMOUSE=y
 CONFIG_SERIAL=y
 CONFIG_PARALLEL=y
docs/specs/virtio-gpu.txt new file +89 -0

89 lines not on this page · raw message

hw/display/Makefile.objs +3 -0
index 7ed76a9..6574830 100644
@@ -33,3 +33,6 @@ 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_GPU) += virtio-gpu.o
+obj-$(CONFIG_VIRTIO_GPU) += virtio-gpu-pci.o
hw/display/virtgpu_hw.h new file +149 -0

149 lines not on this page · raw message

hw/display/virtio-gpu-pci.c new file +80 -0

80 lines not on this page · raw message

hw/display/virtio-gpu.c new file +689 -0

689 lines not on this page · raw message

hw/virtio/virtio-pci.h +15 -0
index dc332ae..fecb801 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 */
 
@@ -199,6 +201,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
 
include/hw/pci/pci.h +1 -0
index 693dd6b..7fc96d2 100644
@@ -80,6 +80,7 @@
 #define PCI_DEVICE_ID_VIRTIO_SCSI        0x1004
 #define PCI_DEVICE_ID_VIRTIO_RNG         0x1005
 #define PCI_DEVICE_ID_VIRTIO_9P          0x1009
+#define PCI_DEVICE_ID_VIRTIO_GPU         0x1010
 
 #define PCI_VENDOR_ID_REDHAT             0x1b36
 #define PCI_DEVICE_ID_REDHAT_BRIDGE      0x0001
include/hw/virtio/virtio-gpu.h new file +91 -0

91 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#17 lore raw

PATCH 4/4 virtio-vga: v1

In reply to Gerd Hoffmann

From: Dave Airlie <[email protected]>

This is a virtio-vga device built on top of the virtio-gpu device.

changes by kraxel:
* adapt to changes in master.
* codestyle cleanups.

---
 Makefile                           |   2 +-
 default-configs/x86_64-softmmu.mak |   1 +
 hw/display/Makefile.objs           |   1 +
 hw/display/virtio-vga.c            | 169 +++++++++++++++++++++++++++++++++++++
 hw/pci/pci.c                       |   2 +
 include/sysemu/sysemu.h            |   2 +-
 pc-bios/vgabios-virtio.bin         | Bin 0 -> 40448 bytes
 roms/Makefile                      |   2 +-
 roms/config.vga.virtio             |   6 ++
 vl.c                               |  13 +++
 10 files changed, 195 insertions(+), 3 deletions(-)
 create mode 100644 hw/display/virtio-vga.c
 create mode 100644 pc-bios/vgabios-virtio.bin
 create mode 100644 roms/config.vga.virtio
Makefile +1 -1
index bd9cd4f..d971e32 100644
@@ -318,7 +318,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 \
default-configs/x86_64-softmmu.mak +1 -0
index 1a00b78..22d8587 100644
@@ -10,6 +10,7 @@ CONFIG_VGA_ISA=y
 CONFIG_VGA_CIRRUS=y
 CONFIG_VMWARE_VGA=y
 CONFIG_VIRTIO_GPU=y
+CONFIG_VIRTIO_VGA=y
 CONFIG_VMMOUSE=y
 CONFIG_SERIAL=y
 CONFIG_PARALLEL=y
hw/display/Makefile.objs +1 -0
index 6574830..6d5b792 100644
@@ -36,3 +36,4 @@ common-obj-$(CONFIG_QXL) += qxl.o qxl-logger.o qxl-render.o
 
 obj-$(CONFIG_VIRTIO_GPU) += virtio-gpu.o
 obj-$(CONFIG_VIRTIO_GPU) += virtio-gpu-pci.o
+obj-$(CONFIG_VIRTIO_VGA) += virtio-vga.o
hw/display/virtio-vga.c new file +169 -0

169 lines not on this page · raw message

hw/pci/pci.c +2 -0
index 4e0701d..971b3ba 100644
@@ -1647,6 +1647,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 b90df9a..35358b8 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_TCX, VGA_CG3, VGA_VIRTIO,
 } VGAInterfaceType;
 
 extern int vga_interface_type;
pc-bios/vgabios-virtio.bin new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..2b70d272f2704e7839712a61613844321b93b465
GIT binary patch
roms/Makefile +1 -1
index 2721b02..b88a3fd 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..9a78983
@@ -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=0x1010
vl.c +13 -0
index bca5c95..e3ede89 100644
@@ -243,6 +243,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 = {
@@ -2085,6 +2086,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;
@@ -2111,6 +2117,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
#3 lore raw

Re: [Qemu-devel] [PATCH 2/4] vga: add secondary stdvga variant

In reply to Gerd Hoffmann
Quoted 2 lines · Gerd Hoffmann

Add a standard vga variant which doesn't occupy any legacy ressources and thus can easily be used as secondary (or legacy-free)

s/ressources/resources/

Quoted 3 lines

graphics adapter. Programming must be done using the MMIO bar.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#18 lore raw
In reply to Gerd Hoffmann
Quoted 10 lines · Gerd Hoffmann

Hi,

This patch series adds new display devices.

Number one is secondary-vga. That is identical to VGA (aka -vga std), except that it doesn't occupy all the legacy vga stuff (ioports, memory window @ 0xa0000), so you can have more than one of these in the system. It has one pci memory bar for the framebuffer and one mmio bar for registers. OVMF can drive it. Doesn't use it as console for some reason, but initializes it and the linux kernel will see it as efifb.

My take is, due to the UEFI driver model, QemuVideoDxe is connected to this secondary VGA (and so another GOP instance is created). It's then probably up to GraphicsConsoleDxe to provide a SimpleTextOutput on top. My guess (without looking) is that this too happens, again thanks to the UEFI driver model.

What could be amiss is likely something in ConSplitterDxe, which accepts input from all consoles, and mirrors output to all of them as well. Perhaps it doesn't expect multiple GOPs.

Laszlo

#19 lore raw
Quoted 18 lines · Laszlo Ersek
Quoted 10 lines · Gerd Hoffmann

Hi,

This patch series adds new display devices.

Number one is secondary-vga. That is identical to VGA (aka -vga std), except that it doesn't occupy all the legacy vga stuff (ioports, memory window @ 0xa0000), so you can have more than one of these in the system. It has one pci memory bar for the framebuffer and one mmio bar for registers. OVMF can drive it. Doesn't use it as console for some reason, but initializes it and the linux kernel will see it as efifb.

My take is, due to the UEFI driver model, QemuVideoDxe is connected to this secondary VGA (and so another GOP instance is created). It's then probably up to GraphicsConsoleDxe to provide a SimpleTextOutput on top. My guess (without looking) is that this too happens, again thanks to the UEFI driver model.

Quoted 3 lines

What could be amiss is likely something in ConSplitterDxe, which accepts input from all consoles, and mirrors output to all of them as well. Perhaps it doesn't expect multiple GOPs.

Must be something else, I see this behavior with secondary-vga being the only display device. It prints a single line saying something along the lines "display initialized", so SimpleTextOutput seems to be active.

cheers,
Gerd

#20 lore raw
Quoted 21 lines · Gerd Hoffmann
Quoted 19 lines · Laszlo Ersek
Quoted 11 lines · Gerd Hoffmann

Hi,

This patch series adds new display devices.

Number one is secondary-vga. That is identical to VGA (aka -vga std), except that it doesn't occupy all the legacy vga stuff (ioports, memory window @ 0xa0000), so you can have more than one of these in the system. It has one pci memory bar for the framebuffer and one mmio bar for registers. OVMF can drive it. Doesn't use it as console for some reason, but initializes it and the linux kernel will see it as efifb.

My take is, due to the UEFI driver model, QemuVideoDxe is connected to this secondary VGA (and so another GOP instance is created). It's then probably up to GraphicsConsoleDxe to provide a SimpleTextOutput on top. My guess (without looking) is that this too happens, again thanks to the UEFI driver model.

Quoted 8 lines
Quoted 3 lines

What could be amiss is likely something in ConSplitterDxe, which accepts input from all consoles, and mirrors output to all of them as well. Perhaps it doesn't expect multiple GOPs.

Must be something else, I see this behavior with secondary-vga being the only display device. It prints a single line saying something along the lines "display initialized", so SimpleTextOutput seems to be active.

OK, maybe I got some further clues; see
"OvmfPkg/Library/PlatformBdsLib/BdsPlatform.c".

PlatformBdsPolicyBehavior()

    PlatformBdsConnectConsole()
      DetectAndPreparePlatformPciDevicePaths()
        VisitAllPciInstances()
          VisitAllInstancesOfProtocol()
            VisitingAPciInstance()
              DetectAndPreparePlatformPciDevicePath()
    +---------->IS_PCI_VGA (Pci):
    |             "Found PCI VGA device"
    |             PreparePciVgaDevicePath()
    |               GetGopDevicePath()
    |               BdsLibUpdateConsoleVariable()
    |

The IS_PCI_VGA() macro in "MdePkg/Include/IndustryStandard/Pci22.h" says:

Quoted 10 lines

/**
Macro that checks whether device is a VGA-compatible controller.

@param _p Specified device.

@retval TRUE Device is a VGA-compatible controller.
@retval FALSE Device is not a VGA-compatible controller.

**/
#define IS_PCI_VGA(_p) IS_CLASS3 (_p, PCI_CLASS_DISPLAY, PCI_CLASS_DISPLAY_VGA, PCI_IF_VGA_VGA)

Plus

Quoted 3 lines

#define PCI_CLASS_DISPLAY 0x03
#define PCI_CLASS_DISPLAY_VGA 0x00
#define PCI_IF_VGA_VGA 0x00

In your patch 2/4 (secondary_class_init()):

Quoted 1 line

+ k->class_id = PCI_CLASS_DISPLAY_OTHER;

and from qemu's "include/hw/pci/pci_ids.h":

Quoted 2 lines

#define PCI_CLASS_DISPLAY_VGA 0x0300
#define PCI_CLASS_DISPLAY_OTHER 0x0380

I think this is the cause of the mismatch.

In vga_class_init(), PCI_CLASS_DISPLAY_VGA is used.

Note: build_pci_bus_end() [hw/i386/acpi-build.c] also seems to depend on PCI_CLASS_DISPLAY_VGA. (Of course you could be wanting to avoid exactly that branch, by setting the class to "other".)

In edk2, there's another relevant-looking (laxer) macro:

Quoted 10 lines

/**
Macro that checks whether device is a display controller.

@param _p Specified device.

@retval TRUE Device is a display controller.
@retval FALSE Device is not a display controller.

**/
#define IS_PCI_DISPLAY(_p) IS_CLASS1 (_p, PCI_CLASS_DISPLAY)

Does the following OVMF patch help?

OvmfPkg/Library/PlatformBdsLib/BdsPlatform.c DetectAndPreparePlatformPciDevicePath ( · line 599

Quoted 13 lines
OvmfPkg/Library/PlatformBdsLib/BdsPlatform.c +1 -1
index 9f953ac..33d8c5d 100644
@@ -593,7 +593,7 @@ DetectAndPreparePlatformPciDevicePath (
   //
   // Here we decide which VGA device to enable in PCI bus
   //
-  if (IS_PCI_VGA (Pci)) {
+  if (IS_PCI_DISPLAY (Pci)) {
     //
     // Add them to ConOut.
     //

Thanks
Laszlo

#5 lore raw

Re: [Qemu-devel] [PATCH 3/4] virtio-gpu: v0.3 of the virtio based GPU code.

In reply to Gerd Hoffmann
Quoted 18 lines · Gerd Hoffmann

From: Dave Airlie <[email protected]>

This is the basic virtio-gpu which is

multi-head capable,
ARGB cursor support,
unaccelerated.

Some more info is in docs/specs/virtio-gpu.txt.

changes by kraxel:
* adapt to changes in master.
* move from hw/virtio to hw/display.
* codestyle cleanups.
* misc minor fixes.

Quoted 3 lines

virtio-gpu codestyle

Still reviewing.
One thing to do is add this to the virtio spec.
Need help with that?

Quoted 1,222 lines
---
 default-configs/x86_64-softmmu.mak |   1 +
 docs/specs/virtio-gpu.txt          |  89 +++++
 hw/display/Makefile.objs           |   3 +
 hw/display/virtgpu_hw.h            | 149 ++++++++
 hw/display/virtio-gpu-pci.c        |  80 +++++
 hw/display/virtio-gpu.c            | 689 +++++++++++++++++++++++++++++++++++++
 hw/virtio/virtio-pci.h             |  15 +
 include/hw/pci/pci.h               |   1 +
 include/hw/virtio/virtio-gpu.h     |  91 +++++
 9 files changed, 1118 insertions(+)
 create mode 100644 docs/specs/virtio-gpu.txt
 create mode 100644 hw/display/virtgpu_hw.h
 create mode 100644 hw/display/virtio-gpu-pci.c
 create mode 100644 hw/display/virtio-gpu.c
 create mode 100644 include/hw/virtio/virtio-gpu.h
default-configs/x86_64-softmmu.mak +1 -0
index 31bddce..1a00b78 100644
@@ -9,6 +9,7 @@ CONFIG_VGA_PCI=y
 CONFIG_VGA_ISA=y
 CONFIG_VGA_CIRRUS=y
 CONFIG_VMWARE_VGA=y
+CONFIG_VIRTIO_GPU=y
 CONFIG_VMMOUSE=y
 CONFIG_SERIAL=y
 CONFIG_PARALLEL=y
docs/specs/virtio-gpu.txt new file +89 -0
new file mode 100644
index 0000000..987d807
@@ -0,0 +1,89 @@
+Initial info on virtio-gpu:
+
+virtio-gpu is a virtio based graphics adapter. The initial version provides support for:
+
+- ARGB Hardware cursors
+- multiple outputs
+
+There are no acceleration features available in the first release of this device, 3D acceleration features will be provided later via an interface to an external renderer.
+
+The virtio-gpu exposes 3 vqs to the guest,
+
+1) control vq - guest->host queue for sending commands and getting responses when required.
+2) cursor vq - guest->host queue for sending cursor position and resource updates
+3) event vq - host->guest queue for sending async events like display topography updates and errors (todo).
+
+How to use the virtio-gpu:
+
+The virtio-gpu is based around the concept of resources private to the host, the guest must DMA transfer into these resources. This is a design requirement in order to interface with future 3D rendering. In the unaccelerated there is no support for DMA transfers from resources, just to them.
+
+Resources are initially simple 2D resources, consisting of a width, height and format along with an identifier. The guest must then attach backing store to the resources in order for DMA transfers to work. This is like a GART in a real GPU.
+
+A typical guest user would create a 2D resource using VIRTGPU_CMD_RESOURCE_CREATE_2D, attach backing store using VIRTGPU_CMD_RESOURCE_ATTACH_BACKING, then attach the resource to a scanout using VIRTGPU_CMD_SET_SCANOUT, then use VIRTGPU_CMD_TRANSFER_SEND_2D to send updates to the resource, and finally VIRTGPU_CMD_RESOURCE_FLUSH to flush the scanout buffers to screen.
+
+Command queue:
+
+VIRTGPU_CMD_GET_DISPLAY_INFO:
+Retrieve the current output configuration.
+
+This sends a response in the same queue slot. The response contains the max number of scanouts the host can support,
+along with a list of per-scanout information. The info contains whether the
+scanout is enabled, what its preferred x, y, width and height are and some future flags.
+
+VIRTGPU_CMD_RESOURCE_CREATE_2D:
+Create a 2D resource on the host.
+
+This creates a 2D resource on the host with the specified width, height and format. Only a small subset of formats are support. The resource ids are generated by the guest.
+
+VIRTGPU_CMD_RESOURCE_UNREF:
+Destroy a resource.
+
+This informs the host that a resource is no longer required by the guest.
+
+VIRTGPU_CMD_SET_SCANOUT:
+Set the scanout parameters for a single output.
+
+This sets the scanout parameters for a single scanout. The resource_id is the
+resource to be scanned out from, along with a rectangle specified by x, y, width and height.
+
+VIRTGPU_CMD_RESOURCE_FLUSH:
+Flush a scanout resource
+
+This flushes a resource to screen, it takes a rectangle and a resource id,
+and flushes any scanouts the resource is being used on.
+
+VIRTGPU_CMD_TRANSFER_TO_HOST_2D:
+Transfer from guest memory to host resource.
+
+This takes a resource id along with an destination offset into the resource,
+and a box to transfer from the host backing for the resource.
+
+VIRTGPU_CMD_RESOURCE_ATTACH_BACKING:
+Assign backing pages to a resource.
+
+This assign an array of guest pages as the backing store for a resource. These
+pages are then used for the transfer operations for that resource from that
+point on.
+
+VIRTGPU_CMD_RESOURCE_DETACH_BACKING:
+Detach backing pages from a resource.
+
+This detaches any backing pages from a resource, to be used in case of
+guest swapping or object destruction.
+
+Cursor queue:
+The cursor queue accepts on structure per vq entry. The cursor is just a standard 2D resource that is 64x64 sized. Transfers are used to upload the cursor contents.
+
+For cursor movement, the cursor_x and cursor_y fields only need to be updated.
+
+For a cursor update where the guest has transferred a new cursor into the resource, the hotspot, cursor id, should be updated, but the generation_id should also be increased by one, so the host knows to refresh its copy of the cursor data from the resource.
+
+Event queue:
+The only current event passed is a message to denote the host wants to update the layout of the screens. It contains the same info as the response to VIRTGPU_CMD_GET_DISPLAY_INFO.
+
+
+
+
+
+
+
hw/display/Makefile.objs +3 -0
index 7ed76a9..6574830 100644
@@ -33,3 +33,6 @@ 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_GPU) += virtio-gpu.o
+obj-$(CONFIG_VIRTIO_GPU) += virtio-gpu-pci.o
hw/display/virtgpu_hw.h new file +149 -0
new file mode 100644
index 0000000..0709922
@@ -0,0 +1,149 @@
+/*
+ * virtgpu_hw.h - describe the virtgpu hw interface.
+ *
+ * this file is shared with the kernel and follow kernel coding
+ * conventions, we can write a qemu specific one once everything is stable,
+ * but it will make merging things messier.
+ */
+#ifndef VIRTGPU_HW_H
+#define VIRTGPU_HW_H
+
+#define VIRTGPU_CMD_HAS_RESP (1 << 31)
+
+enum virtgpu_ctrl_cmd {
+        VIRTGPU_CMD_NOP,
+        VIRTGPU_CMD_GET_DISPLAY_INFO = (1 | VIRTGPU_CMD_HAS_RESP),
+        /* reserved */
+        VIRTGPU_CMD_RESOURCE_CREATE_2D = 3,
+        VIRTGPU_CMD_RESOURCE_UNREF = 4,
+        VIRTGPU_CMD_SET_SCANOUT = 5,
+        VIRTGPU_CMD_RESOURCE_FLUSH = 6,
+        VIRTGPU_CMD_TRANSFER_TO_HOST_2D = 7,
+        VIRTGPU_CMD_RESOURCE_ATTACH_BACKING = 8,
+        VIRTGPU_CMD_RESOURCE_INVAL_BACKING = 9,
+};
+
+enum virtgpu_ctrl_event {
+        VIRTGPU_EVENT_NOP,
+        VIRTGPU_EVENT_DISPLAY_CHANGE,
+};
+
+/* data passed in the cursor vq */
+struct virtgpu_hw_cursor_page {
+        uint32_t cursor_x, cursor_y;
+        uint32_t cursor_hot_x, cursor_hot_y;
+        uint32_t cursor_id;
+        uint32_t generation_id;
+};
+
+struct virtgpu_resource_unref {
+        uint32_t resource_id;
+};
+
+/* create a simple 2d resource with a format */
+struct virtgpu_resource_create_2d {
+        uint32_t resource_id;
+        uint32_t format;
+        uint32_t width;
+        uint32_t height;
+};
+
+struct virtgpu_set_scanout {
+        uint32_t scanout_id;
+        uint32_t resource_id;
+        uint32_t width;
+        uint32_t height;
+        uint32_t x;
+        uint32_t y;
+};
+
+struct virtgpu_resource_flush {
+        uint32_t resource_id;
+        uint32_t width;
+        uint32_t height;
+        uint32_t x;
+        uint32_t y;
+};
+
+/* simple transfer to_host */
+struct virtgpu_transfer_to_host_2d {
+        uint32_t resource_id;
+        uint32_t offset;
+        uint32_t width;
+        uint32_t height;
+        uint32_t x;
+        uint32_t y;
+};
+
+struct virtgpu_mem_entry {
+        uint64_t addr;
+        uint32_t length;
+        uint32_t pad;
+};
+
+struct virtgpu_resource_attach_backing {
+        uint32_t resource_id;
+        uint32_t nr_entries;
+};
+
+struct virtgpu_resource_inval_backing {
+        uint32_t resource_id;
+};
+
+#define VIRTGPU_MAX_SCANOUTS 16
+struct virtgpu_display_info {
+        uint32_t num_scanouts;
+        struct {
+                uint32_t enabled;
+                uint32_t width;
+                uint32_t height;
+                uint32_t x;
+                uint32_t y;
+                uint32_t flags;
+        } pmodes[VIRTGPU_MAX_SCANOUTS];
+};
+
+struct virtgpu_command {
+        uint32_t type;
+        uint32_t flags;
+        uint64_t rsvd;
+        union virtgpu_cmds {
+                struct virtgpu_resource_create_2d resource_create_2d;
+                struct virtgpu_resource_unref resource_unref;
+                struct virtgpu_resource_flush resource_flush;
+                struct virtgpu_set_scanout set_scanout;
+                struct virtgpu_transfer_to_host_2d transfer_to_host_2d;
+                struct virtgpu_resource_attach_backing resource_attach_backing;
+                struct virtgpu_resource_inval_backing resource_inval_backing;
+        } u;
+};
+
+struct virtgpu_response {
+        uint32_t type;
+        uint32_t flags;
+        union virtgpu_resps {
+                struct virtgpu_display_info display_info;
+        } u;
+};
+
+struct virtgpu_event {
+        uint32_t type;
+        uint32_t err_code;
+        union virtgpu_events {
+                struct virtgpu_display_info display_info;
+        } u;
+};
+
+/* simple formats for fbcon/X use */
+enum virtgpu_formats {
+       VIRGL_FORMAT_B8G8R8A8_UNORM          = 1,
+       VIRGL_FORMAT_B8G8R8X8_UNORM          = 2,
+       VIRGL_FORMAT_A8R8G8B8_UNORM          = 3,
+       VIRGL_FORMAT_X8R8G8B8_UNORM          = 4,
+
+       VIRGL_FORMAT_B5G5R5A1_UNORM          = 5,
+
+       VIRGL_FORMAT_R8_UNORM                = 64,
+};
+
+#endif
hw/display/virtio-gpu-pci.c new file +80 -0
new file mode 100644
index 0000000..642b293
@@ -0,0 +1,80 @@
+/*
+ * Virtio video device
+ *
+ * Copyright Red Hat
+ *
+ * Authors:
+ *  Dave Airlie
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+#include "hw/pci/pci.h"
+#include "hw/virtio/virtio.h"
+#include "hw/virtio/virtio-bus.h"
+#include "hw/virtio/virtio-pci.h"
+#include "hw/virtio/virtio-gpu.h"
+
+static Property virtio_gpu_pci_properties[] = {
+    DEFINE_VIRTIO_GPU_PCI_PROPERTIES(VirtIOPCIProxy),
+    DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static int virtio_gpu_pci_init(VirtIOPCIProxy *vpci_dev)
+{
+    VirtIOGPUPCI *vgpu = VIRTIO_GPU_PCI(vpci_dev);
+    DeviceState *vdev = DEVICE(&vgpu->vdev);
+    VirtIOGPU *g = &vgpu->vdev;
+    int i;
+
+    qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus));
+    if (qdev_init(vdev) < 0) {
+        return -1;
+    }
+
+    for (i = 0; i < g->conf.max_outputs; i++) {
+        g->con[i] = graphic_console_init(DEVICE(g), i, &virtio_gpu_ops, g);
+        if (i > 0) {
+            dpy_gfx_replace_surface(g->con[i], NULL);
+        }
+    }
+    return 0;
+}
+
+static void virtio_gpu_pci_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
+    PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
+
+    set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories);
+    dc->props = virtio_gpu_pci_properties;
+    k->init = virtio_gpu_pci_init;
+    pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
+    pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_GPU;
+    pcidev_k->revision = VIRTIO_PCI_ABI_VERSION;
+    pcidev_k->class_id = PCI_CLASS_DISPLAY_OTHER;
+}
+
+static void virtio_gpu_initfn(Object *obj)
+{
+    VirtIOGPUPCI *dev = VIRTIO_GPU_PCI(obj);
+    object_initialize(&dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_GPU);
+    object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
+}
+
+static const TypeInfo virtio_gpu_pci_info = {
+    .name = TYPE_VIRTIO_GPU_PCI,
+    .parent = TYPE_VIRTIO_PCI,
+    .instance_size = sizeof(VirtIOGPUPCI),
+    .instance_init = virtio_gpu_initfn,
+    .class_init = virtio_gpu_pci_class_init,
+};
+
+static void virtio_gpu_pci_register_types(void)
+{
+    type_register_static(&virtio_gpu_pci_info);
+}
+type_init(virtio_gpu_pci_register_types)
hw/display/virtio-gpu.c new file +689 -0
new file mode 100644
index 0000000..cf7c0a2
@@ -0,0 +1,689 @@
+/*
+ * Virtio video device
+ *
+ * Copyright Red Hat
+ *
+ * Authors:
+ *  Dave Airlie
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#include "qemu-common.h"
+#include "qemu/iov.h"
+#include "ui/console.h"
+#include "hw/virtio/virtio.h"
+#include "hw/virtio/virtio-gpu.h"
+#include "hw/virtio/virtio-bus.h"
+
+#include "virtgpu_hw.h"
+
+static struct virtgpu_simple_resource *virtgpu_find_resource(VirtIOGPU *g,
+                                                          uint32_t resource_id);
+
+static void update_cursor_data(VirtIOGPU *g,
+                               struct virtgpu_simple_resource *res)
+{
+    uint32_t pixels;
+    int i;
+
+    pixels = g->current_cursor->width * g->current_cursor->height;
+    for (i = 0; i < pixels; i++) {
+        uint32_t value = ((uint32_t *)pixman_image_get_data(res->image))[i];
+        g->current_cursor->data[i] = value;
+    }
+}
+
+static void update_cursor(VirtIOGPU *g, struct virtgpu_hw_cursor_page *cursor)
+{
+    if (g->cursor_generation_id != cursor->generation_id) {
+
+        if (!g->current_cursor) {
+            g->current_cursor = cursor_alloc(64, 64);
+        }
+
+        g->current_cursor->hot_x = cursor->cursor_hot_x;
+        g->current_cursor->hot_y = cursor->cursor_hot_y;
+
+        if (cursor->cursor_id > 0) {
+            struct virtgpu_simple_resource *res;
+
+            res = virtgpu_find_resource(g, cursor->cursor_id);
+            if (res) {
+                update_cursor_data(g, res);
+            }
+        }
+        g->cursor_generation_id = cursor->generation_id;
+        g->current_cursor_id = cursor->cursor_id;
+        dpy_cursor_define(g->con[0], g->current_cursor);
+    }
+
+    dpy_mouse_set(g->con[0], cursor->cursor_x, cursor->cursor_y,
+                  cursor->cursor_id ? 1 : 0);
+}
+
+static void virtio_gpu_get_config(VirtIODevice *vdev, uint8_t *config)
+{
+}
+
+static void virtio_gpu_set_config(VirtIODevice *vdev, const uint8_t *config)
+{
+}
+
+static uint32_t virtio_gpu_get_features(VirtIODevice *vdev, uint32_t features)
+{
+    return features;
+}
+
+static void virtio_gpu_set_features(VirtIODevice *vdev, uint32_t features)
+{
+}
+
+static struct virtgpu_simple_resource *virtgpu_find_resource(VirtIOGPU *g,
+                                                          uint32_t resource_id)
+{
+    struct virtgpu_simple_resource *res;
+
+    QLIST_FOREACH(res, &g->reslist, next) {
+        if (res->resource_id == resource_id) {
+            return res;
+        }
+    }
+    return NULL;
+}
+
+static void virtgpu_fill_display_info(VirtIOGPU *g,
+                                      struct virtgpu_display_info *dpy_info)
+{
+    int i;
+
+    memset(dpy_info, 0, sizeof(*dpy_info));
+    dpy_info->num_scanouts = g->conf.max_outputs;
+    for (i = 0; i < g->conf.max_outputs; i++) {
+        if (g->enabled_output_bitmask & (1 << i)) {
+            dpy_info->pmodes[i].enabled = 1;
+            dpy_info->pmodes[i].width = g->req_state[i].width;
+            dpy_info->pmodes[i].height = g->req_state[i].height;
+        }
+    }
+}
+
+static void virtgpu_get_display_info(VirtIOGPU *g,
+                                     struct iovec *iov,
+                                     unsigned int iov_cnt)
+{
+    struct virtgpu_response resp;
+
+    resp.type = VIRTGPU_CMD_GET_DISPLAY_INFO;
+    resp.flags = 0;
+    virtgpu_fill_display_info(g, &resp.u.display_info);
+
+    iov_from_buf(iov, iov_cnt, 0, &resp, sizeof(struct virtgpu_response));
+}
+
+static pixman_format_code_t get_pixman_format(uint32_t virtgpu_format)
+{
+    switch (virtgpu_format) {
+    case VIRGL_FORMAT_B8G8R8X8_UNORM:
+        return PIXMAN_x8r8g8b8;
+    case VIRGL_FORMAT_B8G8R8A8_UNORM:
+        return PIXMAN_a8r8g8b8;
+    default:
+        assert(0);
+        break;
+    }
+    return 0;
+}
+
+static void virtgpu_resource_create_2d(VirtIOGPU *g,
+                                       struct virtgpu_resource_create_2d *c2d)
+{
+    pixman_format_code_t pformat;
+    struct virtgpu_simple_resource *res;
+
+    res = g_new0(struct virtgpu_simple_resource, 1);
+    if (!res) {
+        return;
+    }
+
+    res->width = c2d->width;
+    res->height = c2d->height;
+    res->format = c2d->format;
+    res->resource_id = c2d->resource_id;
+
+    pformat = get_pixman_format(c2d->format);
+    res->image = pixman_image_create_bits(pformat,
+                                          c2d->width,
+                                          c2d->height,
+                                          NULL, 0);
+
+    QLIST_INSERT_HEAD(&g->reslist, res, next);
+}
+
+static void virtgpu_resource_destroy(struct virtgpu_simple_resource *res)
+{
+    pixman_image_unref(res->image);
+    QLIST_REMOVE(res, next);
+    g_free(res);
+}
+
+static void virtgpu_resource_unref(VirtIOGPU *g,
+                                   uint32_t resource_id)
+{
+    struct virtgpu_simple_resource *res = virtgpu_find_resource(g, resource_id);
+
+    if (!res) {
+        return;
+    }
+    virtgpu_resource_destroy(res);
+}
+
+static void virtgpu_transfer_to_host_2d(VirtIOGPU *g,
+                                     struct virtgpu_transfer_to_host_2d *t2d)
+{
+    struct virtgpu_simple_resource *res =
+        virtgpu_find_resource(g, t2d->resource_id);
+    int h;
+    uint32_t src_offset, dst_offset, stride;
+    int bpp;
+    pixman_format_code_t format;
+
+    if (!res || !res->iov) {
+        return;
+    }
+
+    format = pixman_image_get_format(res->image);
+    bpp = (PIXMAN_FORMAT_BPP(format) + 7) / 8;
+    stride = pixman_image_get_stride(res->image);
+
+    if (t2d->offset || t2d->x || t2d->y ||
+        t2d->width != pixman_image_get_width(res->image)) {
+        for (h = 0; h < t2d->height; h++) {
+            src_offset = t2d->offset + stride * h;
+            dst_offset = (t2d->y + h) * stride + (t2d->x * bpp);
+
+            iov_to_buf(res->iov, res->iov_cnt, src_offset,
+                       (uint8_t *)pixman_image_get_data(res->image)
+                       + dst_offset, t2d->width * bpp);
+        }
+    } else {
+        iov_to_buf(res->iov, res->iov_cnt, 0,
+                   pixman_image_get_data(res->image),
+                   pixman_image_get_stride(res->image)
+                   * pixman_image_get_height(res->image));
+    }
+}
+
+static void virtgpu_resource_flush(VirtIOGPU *g,
+                                   struct virtgpu_resource_flush *rf)
+{
+    struct virtgpu_simple_resource *res =
+        virtgpu_find_resource(g, rf->resource_id);
+    pixman_region16_t flush_region;
+    int i;
+
+    pixman_region_init_rect(&flush_region,
+                            rf->x, rf->y, rf->width, rf->height);
+    for (i = 0; i < VIRTGPU_MAX_SCANOUT; i++) {
+        struct virtgpu_scanout *scanout;
+        pixman_region16_t region, finalregion;
+        pixman_box16_t *extents;
+
+        if (!(res->scanout_bitmask & (1 << i))) {
+            continue;
+        }
+        scanout = &g->scanout[i];
+
+        pixman_region_init(&finalregion);
+        pixman_region_init_rect(&region, scanout->x, scanout->y,
+                                scanout->width, scanout->height);
+
+        pixman_region_intersect(&finalregion, &flush_region, &region);
+        pixman_region_translate(&finalregion, -scanout->x, -scanout->y);
+        extents = pixman_region_extents(&finalregion);
+        /* work out the area we need to update for each console */
+        dpy_gfx_update(g->con[i], extents->x1, extents->y1,
+                       extents->x2 - extents->x1,
+                       extents->y2 - extents->y1);
+
+        pixman_region_fini(&region);
+        pixman_region_fini(&finalregion);
+    }
+    pixman_region_fini(&flush_region);
+}
+
+static void virtgpu_set_scanout(VirtIOGPU *g,
+                                struct virtgpu_set_scanout *ss)
+{
+    struct virtgpu_simple_resource *res =
+        virtgpu_find_resource(g, ss->resource_id);
+    struct virtgpu_scanout *scanout;
+    pixman_format_code_t format;
+    uint32_t offset;
+    int bpp;
+
+    g->enable = 1;
+    if (ss->resource_id == 0) {
+        scanout = &g->scanout[ss->scanout_id];
+        if (g->scanout[ss->scanout_id].resource_id) {
+            res = virtgpu_find_resource(g, scanout->resource_id);
+            if (res) {
+                res->scanout_bitmask &= ~(1 << ss->scanout_id);
+            }
+        }
+        if (ss->scanout_id == 0) {
+            return;
+        }
+        dpy_gfx_replace_surface(g->con[ss->scanout_id], NULL);
+        scanout->ds = NULL;
+        scanout->width = 0;
+        scanout->height = 0;
+
+#if 0
+        dpy_notify_state(g->con[ss->scanout_id], 0, 0, 0, 0);
+#endif
+        return;
+    }
+    /* create a surface for this scanout */
+
+    if (ss->scanout_id >= VIRTGPU_MAX_SCANOUT) {
+        fprintf(stderr, "set scanout for non-0 surface %d\n", ss->scanout_id);
+        return;
+    }
+    scanout = &g->scanout[ss->scanout_id];
+
+    format = pixman_image_get_format(res->image);
+    bpp = (PIXMAN_FORMAT_BPP(format) + 7) / 8;
+    offset = (ss->x * bpp) + ss->y * pixman_image_get_stride(res->image);
+
+#if 0
+    dpy_notify_state(g->con[ss->scanout_id], ss->x, ss->y,
+                     ss->width, ss->height);
+#endif
+    if (!scanout->ds || surface_data(scanout->ds)
+        != ((uint8_t *)pixman_image_get_data(res->image) + offset) ||
+        scanout->width != ss->width ||
+        scanout->height != ss->height) {
+        /* realloc the surface ptr */
+        scanout->ds = qemu_create_displaysurface_from
+            (ss->width, ss->height, 32,
+             pixman_image_get_stride(res->image),
+             (uint8_t *)pixman_image_get_data(res->image) + offset, FALSE);
+        if (!scanout->ds) {
+            return;
+        }
+        dpy_gfx_replace_surface(g->con[ss->scanout_id], scanout->ds);
+    }
+
+    res->scanout_bitmask |= (1 << ss->scanout_id);
+    scanout->resource_id = ss->resource_id;
+    scanout->x = ss->x;
+    scanout->y = ss->y;
+    scanout->width = ss->width;
+    scanout->height = ss->height;
+}
+
+static void
+virtgpu_resource_attach_backing(VirtIOGPU *g,
+                                struct virtgpu_resource_attach_backing *att_rb,
+                                struct iovec *iov,
+                                unsigned int iov_cnt)
+{
+    struct virtgpu_simple_resource *res =
+        virtgpu_find_resource(g, att_rb->resource_id);
+    uint32_t gsize = iov_size(iov, iov_cnt);
+    struct iovec *res_iovs;
+    int i;
+    void *data;
+
+    if (!res) {
+        return;
+    }
+
+#if 0
+    res_iovs = g_new0(struct iovec, att_rb->nr_entries);
+#else
+    res_iovs = g_malloc0(sizeof(struct iovec) * att_rb->nr_entries);
+#endif
+
+    if (iov_cnt > 1) {
+        data = g_malloc(gsize);
+        iov_to_buf(iov, iov_cnt, 0, data, gsize);
+    } else {
+        data = iov[0].iov_base;
+    }
+
+    for (i = 0; i < att_rb->nr_entries; i++) {
+        struct virtgpu_mem_entry *ent = ((struct virtgpu_mem_entry *)data) + i;
+        hwaddr len;
+        res_iovs[i].iov_len = ent->length;
+
+        len = ent->length;
+        res_iovs[i].iov_base = cpu_physical_memory_map(ent->addr, &len, 1);
+        if (!res_iovs[i].iov_base || len != ent->length) {
+            fprintf(stderr, "virtgp: trying to map MMIO memory");
+            exit(1);
+        }
+    }
+
+    res->iov = res_iovs;
+    res->iov_cnt = att_rb->nr_entries;
+
+    if (iov_cnt > 1) {
+        g_free(data);
+    }
+}
+
+static void virtgpu_resource_inval_backing(VirtIOGPU *g,
+                                           uint32_t resource_id)
+{
+    struct virtgpu_simple_resource *res
+        = virtgpu_find_resource(g, resource_id);
+    int i;
+
+    if (!res || !res->iov) {
+        return;
+    }
+
+    for (i = 0; i < res->iov_cnt; i++) {
+        cpu_physical_memory_unmap(res->iov[i].iov_base, res->iov[i].iov_len, 1,
+                                  res->iov[i].iov_len);
+    }
+    g_free(res->iov);
+    res->iov_cnt = 0;
+    res->iov = NULL;
+}
+
+static void virtio_gpu_process_cmd(VirtIOGPU *g,
+                                   struct virtgpu_command *cmd,
+                                   struct iovec *iov,
+                                   unsigned int iov_cnt)
+{
+    switch (cmd->type) {
+    case VIRTGPU_CMD_GET_DISPLAY_INFO:
+        if (iov_cnt < 1) {
+            return;
+        }
+        virtgpu_get_display_info(g, iov, iov_cnt);
+        break;
+    case VIRTGPU_CMD_RESOURCE_CREATE_2D:
+        virtgpu_resource_create_2d(g, &cmd->u.resource_create_2d);
+        break;
+    case VIRTGPU_CMD_RESOURCE_UNREF:
+        virtgpu_resource_unref(g, cmd->u.resource_unref.resource_id);
+        break;
+    case VIRTGPU_CMD_RESOURCE_FLUSH:
+        virtgpu_resource_flush(g, &cmd->u.resource_flush);
+        break;
+    case VIRTGPU_CMD_TRANSFER_TO_HOST_2D:
+        virtgpu_transfer_to_host_2d(g, &cmd->u.transfer_to_host_2d);
+        break;
+    case VIRTGPU_CMD_SET_SCANOUT:
+        virtgpu_set_scanout(g, &cmd->u.set_scanout);
+        break;
+    case VIRTGPU_CMD_RESOURCE_ATTACH_BACKING:
+        virtgpu_resource_attach_backing(g, &cmd->u.resource_attach_backing,
+                                        iov, iov_cnt);
+        break;
+    case VIRTGPU_CMD_RESOURCE_INVAL_BACKING:
+        virtgpu_resource_inval_backing
+            (g, cmd->u.resource_inval_backing.resource_id);
+        break;
+    case VIRTGPU_CMD_NOP:
+        break;
+    default:
+        fprintf(stderr, "got bad command from host %d\n", cmd->type);
+        break;
+    }
+}
+
+static void virtio_gpu_handle_ctrl_cb(VirtIODevice *vdev, VirtQueue *vq)
+{
+    VirtIOGPU *g = VIRTIO_GPU(vdev);
+    qemu_bh_schedule(g->ctrl_bh);
+}
+
+static void virtio_gpu_handle_cursor_cb(VirtIODevice *vdev, VirtQueue *vq)
+{
+    VirtIOGPU *g = VIRTIO_GPU(vdev);
+    qemu_bh_schedule(g->cursor_bh);
+}
+
+static void virtio_gpu_handle_event_cb(VirtIODevice *vdev, VirtQueue *vq)
+{
+}
+
+
+static void virtio_gpu_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
+{
+    VirtIOGPU *g = VIRTIO_GPU(vdev);
+    struct iovec *iov;
+    VirtQueueElement elem;
+    struct virtgpu_command cmd;
+    size_t s;
+    unsigned int iov_cnt;
+
+    if (!virtio_queue_ready(vq)) {
+        return;
+    }
+    while (virtqueue_pop(vq, &elem)) {
+
+        iov = elem.out_sg;
+        iov_cnt = elem.out_num;
+
+        s = iov_to_buf(iov, iov_cnt, 0, &cmd, sizeof(cmd));
+        if (s != sizeof(cmd)) {
+            fprintf(stderr, "error\n");
+        } else {
+            if (elem.in_num > 0) {
+                virtio_gpu_process_cmd(g, &cmd, elem.in_sg, elem.in_num);
+            } else {
+                virtio_gpu_process_cmd(g, &cmd, &iov[1], iov_cnt - 1);
+            }
+        }
+        virtqueue_push(vq, &elem, 0);
+        virtio_notify(vdev, vq);
+    }
+}
+
+static void virtio_gpu_ctrl_bh(void *opaque)
+{
+    VirtIOGPU *g = opaque;
+    virtio_gpu_handle_ctrl(&g->parent_obj, g->ctrl_vq);
+}
+
+static void virtio_gpu_handle_cursor(VirtIODevice *vdev, VirtQueue *vq)
+{
+    VirtIOGPU *g = VIRTIO_GPU(vdev);
+    VirtQueueElement elem;
+    size_t s;
+    struct virtgpu_hw_cursor_page cursor_info;
+
+    if (!virtio_queue_ready(vq)) {
+        return;
+    }
+    while (virtqueue_pop(vq, &elem)) {
+        s = iov_to_buf(elem.out_sg, elem.out_num, 0,
+                       &cursor_info, sizeof(cursor_info));
+        if (s != sizeof(cursor_info)) {
+            fprintf(stderr, "error\n");
+        } else {
+            update_cursor(g, &cursor_info);
+        }
+        virtqueue_push(vq, &elem, 0);
+        virtio_notify(vdev, vq);
+    }
+}
+
+static void virtio_gpu_cursor_bh(void *opaque)
+{
+    VirtIOGPU *g = opaque;
+    virtio_gpu_handle_cursor(&g->parent_obj, g->cursor_vq);
+}
+
+static int virtio_gpu_send_event(VirtIOGPU *g, struct virtgpu_event *event)
+{
+    VirtQueueElement elem;
+
+    if (!virtio_queue_ready(g->event_vq)) {
+        return -1;
+    }
+
+    if (!virtqueue_pop(g->event_vq, &elem)) {
+        return -1;
+    }
+
+    iov_from_buf(elem.in_sg, elem.in_num, 0, event,
+                 sizeof(struct virtgpu_event));
+
+    virtqueue_push(g->event_vq, &elem, sizeof(struct virtgpu_event));
+    virtio_notify(&g->parent_obj, g->event_vq);
+    return 0;
+}
+
+static void virtio_gpu_invalidate_display(void *opaque)
+{
+}
+
+static void virtio_gpu_update_display(void *opaque)
+{
+}
+
+static void virtio_gpu_text_update(void *opaque, console_ch_t *chardata)
+{
+}
+
+static int virtio_gpu_ui_info(void *opaque, uint32_t idx, QemuUIInfo *info)
+{
+    VirtIOGPU *g = opaque;
+    struct virtgpu_event event;
+
+    if (idx > g->conf.max_outputs) {
+        return -1;
+    }
+
+    g->req_state[idx].x = info->xoff;
+    g->req_state[idx].y = info->yoff;
+    g->req_state[idx].width = info->width;
+    g->req_state[idx].height = info->height;
+
+    if (info->width && info->height) {
+        g->enabled_output_bitmask |= (1 << idx);
+    } else {
+        g->enabled_output_bitmask &= ~(1 << idx);
+    }
+
+    /* send event to guest */
+    event.type = VIRTGPU_EVENT_DISPLAY_CHANGE;
+    event.err_code = 0;
+    virtgpu_fill_display_info(g, &event.u.display_info);
+    virtio_gpu_send_event(g, &event);
+    return 0;
+}
+
+const GraphicHwOps virtio_gpu_ops = {
+    .invalidate = virtio_gpu_invalidate_display,
+    .gfx_update = virtio_gpu_update_display,
+    .text_update = virtio_gpu_text_update,
+    .ui_info = virtio_gpu_ui_info,
+};
+
+static void virtio_gpu_device_realize(DeviceState *qdev, Error **errp)
+{
+    VirtIODevice *vdev = VIRTIO_DEVICE(qdev);
+    VirtIOGPU *g = VIRTIO_GPU(qdev);
+
+    g->cursor_generation_id = 0xffffffff;
+    g->config_size = 0;
+    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, 64, 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);
+
+    g->event_vq = virtio_add_queue(vdev, 64, virtio_gpu_handle_event_cb);
+
+    g->enabled_output_bitmask = 1;
+    g->qdev = qdev;
+}
+
+static void virtio_gpu_instance_init(Object *obj)
+{
+}
+
+static void virtio_gpu_reset(VirtIODevice *vdev)
+{
+    VirtIOGPU *g = VIRTIO_GPU(vdev);
+    struct virtgpu_simple_resource *res, *tmp;
+    int i;
+
+    g->cursor_generation_id = 0xffffffff;
+    g->current_cursor_id = 0;
+    g->enable = 0;
+
+    QLIST_FOREACH_SAFE(res, &g->reslist, next, tmp) {
+        virtgpu_resource_destroy(res);
+    }
+    for (i = 0; i < g->conf.max_outputs; i++) {
+        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;
+        }
+        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)
hw/virtio/virtio-pci.h +15 -0
index dc332ae..fecb801 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 */
 
@@ -199,6 +201,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
 
include/hw/pci/pci.h +1 -0
index 693dd6b..7fc96d2 100644
@@ -80,6 +80,7 @@
 #define PCI_DEVICE_ID_VIRTIO_SCSI        0x1004
 #define PCI_DEVICE_ID_VIRTIO_RNG         0x1005
 #define PCI_DEVICE_ID_VIRTIO_9P          0x1009
+#define PCI_DEVICE_ID_VIRTIO_GPU         0x1010
 
 #define PCI_VENDOR_ID_REDHAT             0x1b36
 #define PCI_DEVICE_ID_REDHAT_BRIDGE      0x0001
include/hw/virtio/virtio-gpu.h new file +91 -0
new file mode 100644
index 0000000..9ad5802
@@ -0,0 +1,91 @@
+#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"
+
+#define TYPE_VIRTIO_GPU "virtio-gpu-device"
+#define VIRTIO_GPU(obj)                                        \
+        OBJECT_CHECK(VirtIOGPU, (obj), TYPE_VIRTIO_GPU)
+
+#define VIRTIO_ID_GPU 16
+
+#define VIRTGPU_MAX_RES 16
+
+#define VIRTGPU_MAX_SCANOUT 4
+
+struct virtgpu_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;
+    QLIST_ENTRY(virtgpu_simple_resource) next;
+};
+
+struct virtgpu_scanout {
+    DisplaySurface *ds;
+    uint32_t width, height;
+    int x, y;
+    int invalidate;
+    uint32_t resource_id;
+};
+
+struct virtgpu_requested_state {
+    uint32_t width, height;
+    int x, y;
+};
+
+struct virtio_gpu_conf {
+    uint32_t max_outputs;
+};
+
+typedef struct VirtIOGPU {
+    VirtIODevice parent_obj;
+
+    /* qemu console for this GPU */
+    QemuConsole *con[VIRTGPU_MAX_SCANOUT];
+
+    QEMUBH *ctrl_bh;
+    QEMUBH *cursor_bh;
+    VirtQueue *ctrl_vq;
+    VirtQueue *cursor_vq;
+    VirtQueue *event_vq;
+
+    int enable;
+
+    uint32_t current_cursor_id;
+    uint32_t cursor_generation_id;
+
+    int config_size;
+    DeviceState *qdev;
+
+    QLIST_HEAD(, virtgpu_simple_resource) reslist;
+
+    struct virtgpu_scanout scanout[VIRTGPU_MAX_SCANOUT];
+    struct virtgpu_requested_state req_state[VIRTGPU_MAX_SCANOUT];
+    QEMUCursor *current_cursor;
+
+    struct virtio_gpu_conf conf;
+    int enabled_output_bitmask;
+} 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, 4)
+
+#define DEFINE_VIRTIO_GPU_PROPERTIES(_state, _conf_field)        \
+    DEFINE_PROP_UINT32("max_outputs", _state, _conf_field.max_outputs, 2)
+
+#endif
+
Signature · 1 line
1.8.3.1
#21 lore raw
In reply to Laszlo Ersek
Quoted 11 lines
    +---------->IS_PCI_VGA (Pci):
    |             "Found PCI VGA device"
Quoted 1 line

+ k->class_id = PCI_CLASS_DISPLAY_OTHER;

and from qemu's "include/hw/pci/pci_ids.h":

Quoted 2 lines

#define PCI_CLASS_DISPLAY_VGA 0x0300
#define PCI_CLASS_DISPLAY_OTHER 0x0380

I think this is the cause of the mismatch.

Yes, it is. First byte (0x03) of the class says what it is, second byte of class (0x00 / 0x80) specifies the programming interface.

So, it is a display adapter, but it isn't vga compatible, therefore specifying PCI_CLASS_DISPLAY_VGA would be asking for trouble as trying to program it using the standard vga io ports isn't going to work ...

[ same picture with virtio-gpu btw: The variant with the vga compat
bits declares itself as PCI_CLASS_DISPLAY_VGA whereas the variant without is PCI_CLASS_DISPLAY_OTHER ]

Quoted 4 lines

Does the following OVMF patch help?

Quoted 2 lines
(quoted diff) +1 -1
-  if (IS_PCI_VGA (Pci)) {
+  if (IS_PCI_DISPLAY (Pci)) {

Yes.

thanks,
Gerd

#22 lore raw
Quoted 23 lines · Gerd Hoffmann
Quoted 11 lines
    +---------->IS_PCI_VGA (Pci):
    |             "Found PCI VGA device"
Quoted 1 line

+ k->class_id = PCI_CLASS_DISPLAY_OTHER;

and from qemu's "include/hw/pci/pci_ids.h":

Quoted 2 lines

#define PCI_CLASS_DISPLAY_VGA 0x0300
#define PCI_CLASS_DISPLAY_OTHER 0x0380

I think this is the cause of the mismatch.

Yes, it is. First byte (0x03) of the class says what it is, second byte of class (0x00 / 0x80) specifies the programming interface.

So, it is a display adapter, but it isn't vga compatible, therefore specifying PCI_CLASS_DISPLAY_VGA would be asking for trouble as trying to program it using the standard vga io ports isn't going to work ...

[ same picture with virtio-gpu btw: The variant with the vga compat
bits declares itself as PCI_CLASS_DISPLAY_VGA whereas the variant without is PCI_CLASS_DISPLAY_OTHER ]

Quoted 6 lines
Quoted 4 lines

Does the following OVMF patch help?

Quoted 2 lines
(quoted diff) +1 -1
-  if (IS_PCI_VGA (Pci)) {
+  if (IS_PCI_DISPLAY (Pci)) {

Yes.

Please ping me when the series is merged and I will submit the patch (possibly also correcting the related "Vga" references throughout the file).

Thanks
Laszlo

#6 lore raw

Re: [Qemu-devel] [PATCH 3/4] virtio-gpu: v0.3 of the virtio based GPU code.

In reply to Michael S. Tsirkin

Hi,

Quoted 2 lines

One thing to do is add this to the virtio spec.
Need help with that?

What is the authoritative spec these days? The virtio 1.0 draft?
Where can I find the latest revision? Where should I send patches?

Quoted 1 line
Quoted 1 line
 docs/specs/virtio-gpu.txt          |  89 +++++

Some docs are here.

cheers,
Gerd

#9 lore raw

Re: [Qemu-devel] [PATCH 3/4] virtio-gpu: v0.3 of the virtio based GPU code.

In reply to Michael S. Tsirkin

Il 12/03/2014 21:26, Michael S. Tsirkin ha scritto:

Quoted 4 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+Event queue:
+The only current event passed is a message to denote the host
+wants to update the layout of the screens. It contains the same
+info as the response to VIRTGPU_CMD_GET_DISPLAY_INFO.

I wonder if an event queue is the best mechanism if you can get the same info from a command anyway. For virtio-scsi I used a queue because I needed to specify which target or LUN the event applied to, but here you do not need it and a queue is susceptible to dropped events.

Perhaps a configuration field is better, like this:

    u32 events_read;
    u32 events_clear;

A new event sets a bit in events_read and generates a configuration change interrupt. The guest should never write to events_read.

Writing to events_clear has the side effect of the device doing "events_read &= ~events_clear". We cannot have R/W1C fields in virtio, but this approximation is good enough.

When the guest receives a configuration change interrupt, it reads event_read. If it is nonzero, it writes the same value it read to events_clear, and sends the necessary commands to the card in order to retrieve the event data. It can then read again event_read, and loop if it is again nonzero.

Paolo

#7 lore raw

Re: [Qemu-devel] [PATCH 3/4] virtio-gpu: v0.3 of the virtio based GPU code.

In reply to Gerd Hoffmann
Quoted 8 lines · Gerd Hoffmann

Hi,

Quoted 2 lines

One thing to do is add this to the virtio spec.
Need help with that?

What is the authoritative spec these days?
The virtio 1.0 draft?
Where can I find the latest revision?

Seems to be this:

https://github.com/rustyrussell/virtio-wip.git

After figthing with texlive package splitting for a while I seem to have all needed *.sty files installed now. Now I'm facing this:

kpathsea: Running mktextfm Arial /usr/share/texlive/texmf/web2c/mktexnam: Could not map source abbreviation for Arial. /usr/share/texlive/texmf/web2c/mktexnam: Need to update ?
mktextfm: Running mf-nowin -progname=mf \mode:=ljfour; mag:=1; nonstopmode; input Arial
This is METAFONT, Version 2.718281 (TeX Live 2013)

kpathsea: Running mktexmf Arial
! I can't find file `Arial'.
<*> ...e:=ljfour; mag:=1; nonstopmode; input Arial

Suggestions?

Quoted 1 line

Where should I send patches?

virtio-comments list?

cheers,
Gerd

#10 lore raw

Re: [Qemu-devel] [PATCH 3/4] virtio-gpu: v0.3 of the virtio based GPU code.

In reply to Paolo Bonzini

Hi,

Quoted 7 lines

Perhaps a configuration field is better, like this:

     u32 events_read;
     u32 events_clear;

A new event sets a bit in events_read and generates a configuration change interrupt. The guest should never write to events_read.

Makes sense to me. I think I'll go write up things as diff against virtio-wip, then post it for review.

cheers,
Gerd

#8 lore raw

Re: [Qemu-devel] [PATCH 3/4] virtio-gpu: v0.3 of the virtio based GPU code.

In reply to Gerd Hoffmann
Quoted 26 lines · Gerd Hoffmann
Quoted 8 lines · Gerd Hoffmann

Hi,

Quoted 2 lines

One thing to do is add this to the virtio spec.
Need help with that?

What is the authoritative spec these days?
The virtio 1.0 draft?
Where can I find the latest revision?

Seems to be this:

https://github.com/rustyrussell/virtio-wip.git

After figthing with texlive package splitting for a while I seem to have all needed *.sty files installed now. Now I'm facing this:

kpathsea: Running mktextfm Arial /usr/share/texlive/texmf/web2c/mktexnam: Could not map source abbreviation for Arial. /usr/share/texlive/texmf/web2c/mktexnam: Need to update ?
mktextfm: Running mf-nowin -progname=mf \mode:=ljfour; mag:=1; nonstopmode; input Arial
This is METAFONT, Version 2.718281 (TeX Live 2013)

Quoted 5 lines

kpathsea: Running mktexmf Arial
! I can't find file `Arial'.
<*> ...e:=ljfour; mag:=1; nonstopmode; input Arial

Suggestions?

Do you have tex4ht installed?

I don't think I saw this specific error, but check out t4ht-workaround/README for a description of a known Fedora bug and workarounds.

Quoted 7 lines
Quoted 1 line

Where should I send patches?

virtio-comments list?

cheers,
Gerd

#11 lore raw

Re: [Qemu-devel] [PATCH 3/4] virtio-gpu: v0.3 of the virtio based GPU code.

In reply to Gerd Hoffmann
Quoted 7 lines · Gerd Hoffmann

Hi,

Quoted 5 lines

Perhaps a configuration field is better, like this:

     u32 events_read;
     u32 events_clear;
Quoted 9 lines
Quoted 2 lines

A new event sets a bit in events_read and generates a configuration change interrupt. The guest should never write to events_read.

Makes sense to me. I think I'll go write up things as diff against virtio-wip, then post it for review.

cheers,
Gerd

Net device has a similar problem with gratitious packet sending. What we are doing there is VIRTIO_NET_S_ANNOUNCE bit in the status field in the configuration, coupled with VIRTIO_NET_CTRL_ANNOUNCE_ACK command to clear it.

Signature · 1 line
MST
#12 lore raw

Re: [Qemu-devel] [PATCH 3/4] virtio-gpu: v0.3 of the virtio based GPU code.

In reply to Paolo Bonzini
Quoted 25 lines · Paolo Bonzini

Il 12/03/2014 21:26, Michael S. Tsirkin ha scritto:

Quoted 5 lines

Review

Quoted 5 lines
(quoted diff) +4 -0
+Event queue:
+The only current event passed is a message to denote the host
+wants to update the layout of the screens. It contains the same
+info as the response to VIRTGPU_CMD_GET_DISPLAY_INFO.

I wonder if an event queue is the best mechanism if you can get the same info from a command anyway. For virtio-scsi I used a queue because I needed to specify which target or LUN the event applied to, but here you do not need it and a queue is susceptible to dropped events.

Perhaps a configuration field is better, like this:

    u32 events_read;
    u32 events_clear;

A new event sets a bit in events_read and generates a configuration change interrupt. The guest should never write to events_read.

Writing to events_clear has the side effect of the device doing "events_read &= ~events_clear". We cannot have R/W1C fields in virtio, but this approximation is good enough.

Quoted 6 lines

When the guest receives a configuration change interrupt, it reads event_read. If it is nonzero, it writes the same value it read to events_clear, and sends the necessary commands to the card in order to retrieve the event data. It can then read again event_read, and loop if it is again nonzero.

I steered away from using config space for anything for the normal operation of the GPU after looking at overheads and hearing from S390 people that config space has some special properties on their hw,

The number of these events should be small in a running system, and I'm not sure how we'd lose one.

Dave.

#13 lore raw

Re: [Qemu-devel] [PATCH 3/4] virtio-gpu: v0.3 of the virtio based GPU code.

Quoted 33 lines · Dave Airlie
Quoted 25 lines · Paolo Bonzini

Il 12/03/2014 21:26, Michael S. Tsirkin ha scritto:

Quoted 5 lines

Review

Quoted 5 lines
(quoted diff) +4 -0
+Event queue:
+The only current event passed is a message to denote the host
+wants to update the layout of the screens. It contains the same
+info as the response to VIRTGPU_CMD_GET_DISPLAY_INFO.

I wonder if an event queue is the best mechanism if you can get the same info from a command anyway. For virtio-scsi I used a queue because I needed to specify which target or LUN the event applied to, but here you do not need it and a queue is susceptible to dropped events.

Perhaps a configuration field is better, like this:

    u32 events_read;
    u32 events_clear;

A new event sets a bit in events_read and generates a configuration change interrupt. The guest should never write to events_read.

Writing to events_clear has the side effect of the device doing "events_read &= ~events_clear". We cannot have R/W1C fields in virtio, but this approximation is good enough.

Quoted 6 lines

When the guest receives a configuration change interrupt, it reads event_read. If it is nonzero, it writes the same value it read to events_clear, and sends the necessary commands to the card in order to retrieve the event data. It can then read again event_read, and loop if it is again nonzero.

Quoted 6 lines

I steered away from using config space for anything for the normal operation of the GPU after looking at overheads and hearing from S390 people that config space has some special properties on their hw,

The number of these events should be small in a running system, and I'm not sure how we'd lose one.

Oh I was also going to use this queue to report HW error events from the guest to the host,

like if the guest tries an illegal operation,

Dave.

#15 lore raw

Re: [Qemu-devel] [PATCH 3/4] virtio-gpu: v0.3 of the virtio based GPU code.

In reply to Dave Airlie

Il 17/03/2014 05:36, Dave Airlie ha scritto:

Quoted 3 lines

I steered away from using config space for anything for the normal operation of the GPU after looking at overheads and hearing from S390 people that config space has some special properties on their hw,

Right, but this is only for the old s390-virtio implementation, and it means that the cursor would not work on s390-virtio either. The new one, which looks like real s390 hardware, doesn't have the problem.

Quoted 2 lines

The number of these events should be small in a running system, and I'm not sure how we'd lose one.

Are they few even if you resize the viewer window, and this causes a stream of display-size changes?

Paolo

#14 lore raw

Re: [Qemu-devel] [PATCH 3/4] virtio-gpu: v0.3 of the virtio based GPU code.

In reply to Dave Airlie

Il 17/03/2014 06:21, Dave Airlie ha scritto:

Quoted 4 lines

Oh I was also going to use this queue to report HW error events from the guest to the host,

like if the guest tries an illegal operation,

What fields would be present for such an error?

Paolo

#16 lore raw

Re: [Qemu-devel] [PATCH 3/4] virtio-gpu: v0.3 of the virtio based GPU code.

In reply to Dave Airlie
Quoted 33 lines · Dave Airlie
Quoted 25 lines · Paolo Bonzini

Il 12/03/2014 21:26, Michael S. Tsirkin ha scritto:

Quoted 5 lines

Review

Quoted 5 lines
(quoted diff) +4 -0
+Event queue:
+The only current event passed is a message to denote the host
+wants to update the layout of the screens. It contains the same
+info as the response to VIRTGPU_CMD_GET_DISPLAY_INFO.

I wonder if an event queue is the best mechanism if you can get the same info from a command anyway. For virtio-scsi I used a queue because I needed to specify which target or LUN the event applied to, but here you do not need it and a queue is susceptible to dropped events.

Perhaps a configuration field is better, like this:

    u32 events_read;
    u32 events_clear;

A new event sets a bit in events_read and generates a configuration change interrupt. The guest should never write to events_read.

Writing to events_clear has the side effect of the device doing "events_read &= ~events_clear". We cannot have R/W1C fields in virtio, but this approximation is good enough.

Quoted 6 lines

When the guest receives a configuration change interrupt, it reads event_read. If it is nonzero, it writes the same value it read to events_clear, and sends the necessary commands to the card in order to retrieve the event data. It can then read again event_read, and loop if it is again nonzero.

Quoted 8 lines

I steered away from using config space for anything for the normal operation of the GPU after looking at overheads and hearing from S390 people that config space has some special properties on their hw,

The number of these events should be small in a running system, and I'm not sure how we'd lose one.

Dave.

I think Paolo refers to a case where these events
arrive faster than guest can handle them.

As long as there's a single event like this, it seems possible to avoid such under-runs by guest, by first making a new buffer available, then processing a used buffer.

If we want this extendable to multiple events,
make guest prepend an out buffer with a header, saying what kind of event is expected in a given buffer.

Yes, config space is slow and should be avoided for normal operation. I'm not sure how common this specific operation is. For reporting guest errors config space has some advantages as it can be read even if driver/device communication is completely wedged.

Signature · 1 line
MST