All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Dave Airlie <airlied@redhat.com>,
	Gerd Hoffmann <kraxel@redhat.com>,
	Anthony Liguori <aliguori@amazon.com>,
	"Michael S. Tsirkin" <mst@redhat.com>
Subject: [Qemu-devel] [RfC PATCH 09/15] virtio-vga: add virtio gpu device with vga compatibility
Date: Mon, 23 Feb 2015 11:23:25 +0100	[thread overview]
Message-ID: <1424687012-18524-10-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1424687012-18524-1-git-send-email-kraxel@redhat.com>

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.

Signed-off-by: Dave Airlie <airlied@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 default-configs/x86_64-softmmu.mak |   1 +
 hw/display/Makefile.objs           |   1 +
 hw/display/virtio-vga.c            | 153 +++++++++++++++++++++++++++++++++++++
 3 files changed, 155 insertions(+)
 create mode 100644 hw/display/virtio-vga.c

diff --git a/default-configs/x86_64-softmmu.mak b/default-configs/x86_64-softmmu.mak
index e7c2734..75a11c3 100644
--- a/default-configs/x86_64-softmmu.mak
+++ b/default-configs/x86_64-softmmu.mak
@@ -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
diff --git a/hw/display/Makefile.objs b/hw/display/Makefile.objs
index ab6b791..3da3f6c 100644
--- a/hw/display/Makefile.objs
+++ b/hw/display/Makefile.objs
@@ -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
diff --git a/hw/display/virtio-vga.c b/hw/display/virtio-vga.c
new file mode 100644
index 0000000..176821b
--- /dev/null
+++ b/hw/display/virtio-vga.c
@@ -0,0 +1,153 @@
+#include "hw/hw.h"
+#include "hw/pci/pci.h"
+#include "ui/console.h"
+#include "vga_int.h"
+#include "hw/virtio/virtio-pci.h"
+
+/*
+ * virtio-vga: This extends VirtioPCIProxy.
+ */
+#define TYPE_VIRTIO_VGA "virtio-vga"
+#define VIRTIO_VGA(obj) \
+        OBJECT_CHECK(VirtIOVGA, (obj), TYPE_VIRTIO_VGA)
+
+typedef struct VirtIOVGA {
+    VirtIOPCIProxy parent_obj;
+    VirtIOGPU      vdev;
+    VGACommonState vga;
+} VirtIOVGA;
+
+static void virtio_vga_invalidate_display(void *opaque)
+{
+    VirtIOVGA *vvga = opaque;
+
+    if (vvga->vdev.enable) {
+        virtio_gpu_ops.invalidate(&vvga->vdev);
+    } else {
+        vvga->vga.hw_ops->invalidate(&vvga->vga);
+    }
+}
+
+static void virtio_vga_update_display(void *opaque)
+{
+    VirtIOVGA *vvga = opaque;
+
+    if (vvga->vdev.enable) {
+        virtio_gpu_ops.gfx_update(&vvga->vdev);
+    } else {
+        vvga->vga.hw_ops->gfx_update(&vvga->vga);
+    }
+}
+
+static void virtio_vga_text_update(void *opaque, console_ch_t *chardata)
+{
+    VirtIOVGA *vvga = opaque;
+
+    if (vvga->vdev.enable) {
+        if (virtio_gpu_ops.text_update) {
+            virtio_gpu_ops.text_update(&vvga->vdev, chardata);
+        }
+    } else {
+        if (vvga->vga.hw_ops->text_update) {
+            vvga->vga.hw_ops->text_update(&vvga->vga, chardata);
+        }
+    }
+}
+
+static int virtio_vga_ui_info(void *opaque, uint32_t idx, QemuUIInfo *info)
+{
+    VirtIOVGA *vvga = opaque;
+
+    if (virtio_gpu_ops.ui_info) {
+        return virtio_gpu_ops.ui_info(&vvga->vdev, idx, info);
+    }
+    return -1;
+}
+
+static const GraphicHwOps virtio_vga_ops = {
+    .invalidate = virtio_vga_invalidate_display,
+    .gfx_update = virtio_vga_update_display,
+    .text_update = virtio_vga_text_update,
+    .ui_info = virtio_vga_ui_info,
+};
+
+/* VGA device wrapper around PCI device around virtio GPU */
+static int virtio_vga_init(VirtIOPCIProxy *vpci_dev)
+{
+    VirtIOVGA *vvga = VIRTIO_VGA(vpci_dev);
+    VirtIOGPU *g = &vvga->vdev;
+    VGACommonState *vga = &vvga->vga;
+
+    qdev_set_parent_bus(DEVICE(g), BUS(&vpci_dev->bus));
+    if (qdev_init(DEVICE(g)) < 0) {
+        return -1;
+    }
+
+    vga->vram_size_mb = 8;
+    vga_common_init(vga, OBJECT(vpci_dev), false);
+    vga_init(vga, OBJECT(vpci_dev), pci_address_space(&vpci_dev->pci_dev),
+             pci_address_space_io(&vpci_dev->pci_dev), true);
+
+    vga->con = g->scanout[0].con;
+    graphic_console_set_hwops(vga->con, &virtio_vga_ops, vvga);
+
+    pci_register_bar(&vpci_dev->pci_dev, 2,
+                     PCI_BASE_ADDRESS_MEM_PREFETCH, &vga->vram);
+
+    return 0;
+}
+
+static void virtio_vga_reset(DeviceState *dev)
+{
+    VirtIOVGA *vvga = VIRTIO_VGA(dev);
+    vvga->vdev.enable = 0;
+
+    vga_dirty_log_start(&vvga->vga);
+}
+
+static Property virtio_vga_properties[] = {
+    DEFINE_VIRTIO_GPU_PROPERTIES(VirtIOVGA, vdev.conf),
+    DEFINE_VIRTIO_GPU_PCI_PROPERTIES(VirtIOPCIProxy),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void virtio_vga_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_vga_properties;
+    dc->reset = virtio_vga_reset;
+    dc->hotpluggable = false;
+
+    k->init = virtio_vga_init;
+    pcidev_k->romfile = "vgabios-virtio.bin";
+    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_VGA;
+}
+
+static void virtio_vga_inst_initfn(Object *obj)
+{
+    VirtIOVGA *dev = VIRTIO_VGA(obj);
+    object_initialize(&dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_GPU);
+    object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
+}
+
+static TypeInfo virtio_vga_info = {
+    .name          = TYPE_VIRTIO_VGA,
+    .parent        = TYPE_VIRTIO_PCI,
+    .instance_size = sizeof(struct VirtIOVGA),
+    .instance_init = virtio_vga_inst_initfn,
+    .class_init    = virtio_vga_class_init,
+};
+
+static void virtio_vga_register_types(void)
+{
+    type_register_static(&virtio_vga_info);
+}
+
+type_init(virtio_vga_register_types)
-- 
1.8.3.1

  parent reply	other threads:[~2015-02-23 10:23 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-23 10:23 [Qemu-devel] [RfC PATCH 00/15] virtio-gpu: Gerd Hoffmann
2015-02-23 10:23 ` [Qemu-devel] [RfC PATCH 01/15] virtio-pci: add flags to enable/disable legacy/modern Gerd Hoffmann
2015-02-26 16:41   ` Max Reitz
2015-02-27 11:15     ` Gerd Hoffmann
2015-02-27 14:20       ` Max Reitz
2015-03-02 12:34   ` Michael S. Tsirkin
2015-03-02 13:25     ` Gerd Hoffmann
2015-02-23 10:23 ` [Qemu-devel] [RfC PATCH 02/15] virtio-pci: make QEMU_VIRTIO_PCI_QUEUE_MEM_MULT smaller Gerd Hoffmann
2015-02-23 10:23 ` [Qemu-devel] [RfC PATCH 03/15] virtio-pci: make pci bars configurable Gerd Hoffmann
2015-03-02 12:30   ` Michael S. Tsirkin
2015-03-02 13:10     ` Gerd Hoffmann
2015-02-23 10:23 ` [Qemu-devel] [RfC PATCH 04/15] virtio-pci: make modern bar 64bit prefetchable Gerd Hoffmann
2015-03-02 12:33   ` Michael S. Tsirkin
2015-02-23 10:23 ` [Qemu-devel] [RfC PATCH 05/15] virtio-gpu/2d: add hardware spec include file Gerd Hoffmann
2015-02-25 20:04   ` Max Reitz
2015-02-27  9:37     ` Gerd Hoffmann
2015-02-23 10:23 ` [Qemu-devel] [RfC PATCH 06/15] virtio-gpu/2d: add virtio gpu core code Gerd Hoffmann
2015-02-26 16:08   ` Max Reitz
2015-02-27 11:10     ` Gerd Hoffmann
2015-02-27 14:20       ` Max Reitz
2015-02-27 14:31         ` Gerd Hoffmann
2015-02-27 14:33           ` Max Reitz
2015-03-01 22:03     ` Dave Airlie
2015-03-02 12:57       ` Gerd Hoffmann
2015-02-23 10:23 ` [Qemu-devel] [RfC PATCH 07/15] virtio-gpu-pci: add virtio pci support Gerd Hoffmann
2015-02-26 16:25   ` Max Reitz
2015-02-27 11:13     ` Gerd Hoffmann
2015-02-23 10:23 ` [Qemu-devel] [RfC PATCH 08/15] virtio-gpu-pci: virtio-1.0 adaptions [fixup] Gerd Hoffmann
2015-02-26 16:46   ` Max Reitz
2015-02-27 11:18     ` Gerd Hoffmann
2015-02-27 14:30       ` Max Reitz
2015-02-23 10:23 ` Gerd Hoffmann [this message]
2015-02-23 10:23 ` [Qemu-devel] [RfC PATCH 10/15] virtio-vga: " Gerd Hoffmann
2015-02-23 10:23 ` [Qemu-devel] [RfC PATCH 11/15] virtio-vga: add '-vga virtio' support Gerd Hoffmann
2015-02-24 16:26   ` Marc-André Lureau
2015-02-27  9:27     ` Gerd Hoffmann
2015-02-23 10:23 ` [Qemu-devel] [RfC PATCH 12/15] virtio-vga: add vgabios configuration Gerd Hoffmann
2015-02-26 18:13   ` Max Reitz
2015-02-27 11:25     ` Gerd Hoffmann
2015-02-23 10:23 ` [Qemu-devel] [RfC PATCH 13/15] virtio-vga: add vgabios binary Gerd Hoffmann
2015-02-23 10:23 ` [Qemu-devel] [RfC PATCH 14/15] virtio-gpu: add to display-vga test Gerd Hoffmann
2015-02-23 10:23 ` [Qemu-devel] [RfC PATCH 15/15] [hack] virtio-gpu: maskerade as -device VGA Gerd Hoffmann
2015-02-26 18:40 ` [Qemu-devel] [RfC PATCH 00/15] virtio-gpu: Max Reitz
2015-02-27 11:30   ` Gerd Hoffmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1424687012-18524-10-git-send-email-kraxel@redhat.com \
    --to=kraxel@redhat.com \
    --cc=airlied@redhat.com \
    --cc=aliguori@amazon.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.