Patchwork [3/4] qxl: implement VirtIO QXL (dummy) device support

login
register
mail settings
Submitter Erlon Cruz
Date Aug. 24, 2012, 7:14 p.m.
Message ID <1345835677-23371-4-git-send-email-erlon.cruz@br.flextronics.com>
Download mbox | patch
Permalink /patch/179887/
State New
Headers show

Comments

Erlon Cruz - Aug. 24, 2012, 7:14 p.m.
From: Fabiano FidĂȘncio <fabiano@fidencio.org>

This commit introduces the devices stubs that use Virtio infrastructure
to transport QXL commands.

Signed-off-by: Erlon R. Cruz <erlon.cruz@fit-tecnologia.org.br>
Signed-off-by: Fabiano FidĂȘncio <fabiano.fidencio@fit-tecnologia.org.br>
Signed-off-by: Rafael F. Santos <fonsecasantos.rafael@gmail.com>
---
 hw/i386/Makefile.objs |    2 +-
 hw/pci.h              |    1 +
 hw/qxl-virtio.c       |   93 +++++++++++++++++++++++++++++++++++++++++++++++++
 hw/virtio-pci.c       |    4 +-
 hw/virtio-pci.h       |    2 +
 hw/virtio.h           |    2 +
 qemu-config.c         |   13 +++++++
 qemu-options.hx       |    7 ++++
 vl.c                  |   15 +++++++-
 9 files changed, 135 insertions(+), 4 deletions(-)
 create mode 100644 hw/qxl-virtio.c

Patch

diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs
index 1953e7f..3cf5a24 100644
--- a/hw/i386/Makefile.objs
+++ b/hw/i386/Makefile.objs
@@ -10,6 +10,6 @@  obj-$(CONFIG_XEN) += xen_platform.o xen_apic.o
 obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen-host-pci-device.o
 obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pt.o xen_pt_config_init.o xen_pt_msi.o
 obj-y += kvm/
-obj-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.o qxl-pci.o
+obj-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.o qxl-pci.o qxl-virtio.o
 
 obj-y := $(addprefix ../,$(obj-y))
diff --git a/hw/pci.h b/hw/pci.h
index 4b6ab3d..9271f7a 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -76,6 +76,7 @@ 
 #define PCI_DEVICE_ID_VIRTIO_BALLOON     0x1002
 #define PCI_DEVICE_ID_VIRTIO_CONSOLE     0x1003
 #define PCI_DEVICE_ID_VIRTIO_SCSI        0x1004
+#define PCI_DEVICE_ID_VIRTIO_QXL         0x1005
 
 #define FMT_PCIBUS                      PRIx64
 
diff --git a/hw/qxl-virtio.c b/hw/qxl-virtio.c
new file mode 100644
index 0000000..d290de8
--- /dev/null
+++ b/hw/qxl-virtio.c
@@ -0,0 +1,93 @@ 
+/*
+ * VirtioQXL Device
+ *
+ * (C) Copyright IBM Corp. 2012
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "pci.h"
+#include "virtio.h"
+#include "virtio-pci.h"
+
+VirtIODevice *virtio_qxl_init(DeviceState *dev)
+{
+    return NULL;
+}
+
+void virtio_qxl_exit(VirtIODevice *vdev)
+{
+    return;
+}
+
+
+//setting up virtio device
+static int virtio_qxl_init_pci(PCIDevice *pci_dev)
+{
+    VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
+    VirtIODevice *vdev = NULL;
+
+    vdev = virtio_qxl_init(&pci_dev->qdev);
+    if (!vdev) {
+        return -1;
+    }
+    vdev->nvectors = proxy->nvectors;
+    virtio_init_pci(proxy, vdev);
+    /* make the actual value visible */
+    proxy->nvectors = vdev->nvectors;
+    return 0;
+}
+
+static void virtio_qxl_exit_pci(PCIDevice *pci_dev)
+{
+    VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
+
+    virtio_pci_stop_ioeventfd(proxy);
+    virtio_qxl_exit(proxy->vdev);
+    virtio_exit_pci(pci_dev);
+}
+
+static void virtio_qxl_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+    k->init = virtio_qxl_init_pci;
+    k->exit = virtio_qxl_exit_pci;
+    k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
+    k->device_id = PCI_DEVICE_ID_VIRTIO_QXL;
+    k->revision = VIRTIO_PCI_ABI_VERSION;
+    k->class_id = PCI_CLASS_COMMUNICATION_OTHER;
+    dc->reset = virtio_pci_reset;
+//    dc->props = qxl_properties; //we will use the same used by qxl-pci
+}
+
+static TypeInfo virtio_qxl_info = {
+    .name           = "virtio-qxl-pci",
+    .parent         = TYPE_PCI_DEVICE,
+    .instance_size  = sizeof(VirtIOPCIProxy),
+    .class_init     = virtio_qxl_class_init,
+};
+
+static void virtio_qxl_register_types(void)
+{
+    type_register_static(&virtio_qxl_info);
+}
+
+type_init(virtio_qxl_register_types);
diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 5e6e09e..2626a8a 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -221,7 +221,7 @@  assign_error:
     error_report("%s: failed. Fallback to a userspace (slower).", __func__);
 }
 
-static void virtio_pci_stop_ioeventfd(VirtIOPCIProxy *proxy)
+void virtio_pci_stop_ioeventfd(VirtIOPCIProxy *proxy)
 {
     int r;
     int n;
@@ -779,7 +779,7 @@  static int virtio_blk_init_pci(PCIDevice *pci_dev)
     return 0;
 }
 
-static void virtio_exit_pci(PCIDevice *pci_dev)
+void virtio_exit_pci(PCIDevice *pci_dev)
 {
     VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
 
diff --git a/hw/virtio-pci.h b/hw/virtio-pci.h
index ac9d522..4032b20 100644
--- a/hw/virtio-pci.h
+++ b/hw/virtio-pci.h
@@ -53,6 +53,8 @@  typedef struct {
 
 void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev);
 void virtio_pci_reset(DeviceState *d);
+void virtio_pci_stop_ioeventfd(VirtIOPCIProxy *proxy);
+void virtio_exit_pci(PCIDevice *pci_dev);
 
 /* Virtio ABI version, if we increment this, we break the guest driver. */
 #define VIRTIO_PCI_ABI_VERSION          0
diff --git a/hw/virtio.h b/hw/virtio.h
index 7a4f564..7a7566e 100644
--- a/hw/virtio.h
+++ b/hw/virtio.h
@@ -200,6 +200,7 @@  VirtIODevice *virtio_serial_init(DeviceState *dev, virtio_serial_conf *serial);
 VirtIODevice *virtio_balloon_init(DeviceState *dev);
 typedef struct VirtIOSCSIConf VirtIOSCSIConf;
 VirtIODevice *virtio_scsi_init(DeviceState *dev, VirtIOSCSIConf *conf);
+VirtIODevice *virtio_qxl_init(DeviceState *dev);
 #ifdef CONFIG_LINUX
 VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf);
 #endif
@@ -210,6 +211,7 @@  void virtio_blk_exit(VirtIODevice *vdev);
 void virtio_serial_exit(VirtIODevice *vdev);
 void virtio_balloon_exit(VirtIODevice *vdev);
 void virtio_scsi_exit(VirtIODevice *vdev);
+void virtio_qxl_exit(VirtIODevice *vdev);
 
 #define DEFINE_VIRTIO_COMMON_FEATURES(_state, _field) \
 	DEFINE_PROP_BIT("indirect_desc", _state, _field, \
diff --git a/qemu-config.c b/qemu-config.c
index c05ffbc..32a99db 100644
--- a/qemu-config.c
+++ b/qemu-config.c
@@ -643,6 +643,18 @@  QemuOptsList qemu_boot_opts = {
     },
 };
 
+QemuOptsList qemu_virtio_qxl_opts = {
+    .name = "virtio-qxl",
+    .head = QTAILQ_HEAD_INITIALIZER(qemu_virtio_qxl_opts.head),
+    .desc = {
+        /*
+         * no elements => accepty any
+         * sanity checking will happen later when setting device properties
+         */
+        { /* end of list */}
+    },
+};
+
 static QemuOptsList *vm_config_groups[32] = {
     &qemu_drive_opts,
     &qemu_chardev_opts,
@@ -659,6 +671,7 @@  static QemuOptsList *vm_config_groups[32] = {
     &qemu_boot_opts,
     &qemu_iscsi_opts,
     &qemu_sandbox_opts,
+    &qemu_virtio_qxl_opts,
     NULL,
 };
 
diff --git a/qemu-options.hx b/qemu-options.hx
index 3c411c4..41a6728 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -569,6 +569,13 @@  ETEXI
 
 DEFHEADING()
 
+DEFHEADING(QXL VirtIO option:)
+
+DEF("virtio-qxl", 0, QEMU_OPTION_virtio_qxl, "-virtio-qxl\n",
+QEMU_ARCH_ALL)
+
+DEFHEADING()
+
 DEFHEADING(File system options:)
 
 DEF("fsdev", HAS_ARG, QEMU_OPTION_fsdev,
diff --git a/vl.c b/vl.c
index 7c577fa..14c647f 100644
--- a/vl.c
+++ b/vl.c
@@ -233,6 +233,7 @@  int boot_menu;
 uint8_t *boot_splash_filedata;
 int boot_splash_filedata_size;
 uint8_t qemu_extra_params_fw[2];
+int virtio_qxl_enabled = 0;
 
 typedef struct FWBootEntry FWBootEntry;
 
@@ -2951,6 +2952,18 @@  int main(int argc, char **argv, char **envp)
                 qemu_opt_set(device, "mount_tag", "v_synth");
                 break;
             }
+            case QEMU_OPTION_virtio_qxl: {
+                QemuOpts *device;
+
+                virtio_qxl_enabled = 1;
+                vga_model = "none";
+                default_vga = 0;
+                device = qemu_opts_create(qemu_find_opts("device"), NULL, 0,
+                                          NULL);
+                qemu_opt_set(device, "driver", "virtio-qxl-pci");
+                break;
+
+            }
             case QEMU_OPTION_serial:
                 add_device_config(DEV_SERIAL, optarg);
                 default_serial = 0;
@@ -3692,7 +3705,7 @@  int main(int argc, char **argv, char **envp)
     }
 #endif
 #ifdef CONFIG_SPICE
-    if (using_spice && !qxl_enabled) {
+    if (using_spice && !qxl_enabled && !virtio_qxl_enabled) {
         qemu_spice_display_init(ds);
     }
 #endif