[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v7 7/8] virtio-gpu: split virtio-gpu-pci & virtio-vg
From: |
Marc-André Lureau |
Subject: |
[Qemu-devel] [PATCH v7 7/8] virtio-gpu: split virtio-gpu-pci & virtio-vga |
Date: |
Mon, 13 May 2019 20:44:32 +0200 |
Add base classes that are common to vhost-user-gpu-pci and
vhost-user-vga.
Signed-off-by: Marc-André Lureau <address@hidden>
---
hw/display/virtio-vga.h | 32 +++++++++
hw/display/virtio-gpu-pci.c | 52 +++++++++-----
hw/display/virtio-vga.c | 135 ++++++++++++++++++------------------
MAINTAINERS | 2 +-
4 files changed, 137 insertions(+), 84 deletions(-)
create mode 100644 hw/display/virtio-vga.h
diff --git a/hw/display/virtio-vga.h b/hw/display/virtio-vga.h
new file mode 100644
index 0000000000..f03e1ba619
--- /dev/null
+++ b/hw/display/virtio-vga.h
@@ -0,0 +1,32 @@
+#ifndef VIRTIO_VGA_H_
+#define VIRTIO_VGA_H_
+
+#include "hw/virtio/virtio-pci.h"
+#include "vga_int.h"
+
+/*
+ * virtio-vga-base: This extends VirtioPCIProxy.
+ */
+#define TYPE_VIRTIO_VGA_BASE "virtio-vga-base"
+#define VIRTIO_VGA_BASE(obj) \
+ OBJECT_CHECK(VirtIOVGABase, (obj), TYPE_VIRTIO_VGA_BASE)
+#define VIRTIO_VGA_BASE_GET_CLASS(obj) \
+ OBJECT_GET_CLASS(VirtIOVGABaseClass, obj, TYPE_VIRTIO_VGA_BASE)
+#define VIRTIO_VGA_BASE_CLASS(klass) \
+ OBJECT_CLASS_CHECK(VirtIOVGABaseClass, klass, TYPE_VIRTIO_VGA_BASE)
+
+typedef struct VirtIOVGABase {
+ VirtIOPCIProxy parent_obj;
+
+ VirtIOGPUBase *vgpu;
+ VGACommonState vga;
+ MemoryRegion vga_mrs[3];
+} VirtIOVGABase;
+
+typedef struct VirtIOVGABaseClass {
+ VirtioPCIClass parent_class;
+
+ DeviceReset parent_reset;
+} VirtIOVGABaseClass;
+
+#endif /* VIRTIO_VGA_H_ */
diff --git a/hw/display/virtio-gpu-pci.c b/hw/display/virtio-gpu-pci.c
index 305ea5fff3..3b88bf4d1f 100644
--- a/hw/display/virtio-gpu-pci.c
+++ b/hw/display/virtio-gpu-pci.c
@@ -19,30 +19,30 @@
#include "hw/virtio/virtio-pci.h"
#include "hw/virtio/virtio-gpu.h"
-typedef struct VirtIOGPUPCI VirtIOGPUPCI;
+typedef struct VirtIOGPUPCIBase VirtIOGPUPCIBase;
/*
- * virtio-gpu-pci: This extends VirtioPCIProxy.
+ * virtio-gpu-pci-base: This extends VirtioPCIProxy.
*/
-#define TYPE_VIRTIO_GPU_PCI "virtio-gpu-pci"
-#define VIRTIO_GPU_PCI(obj) \
- OBJECT_CHECK(VirtIOGPUPCI, (obj), TYPE_VIRTIO_GPU_PCI)
+#define TYPE_VIRTIO_GPU_PCI_BASE "virtio-gpu-pci-base"
+#define VIRTIO_GPU_PCI_BASE(obj) \
+ OBJECT_CHECK(VirtIOGPUPCIBase, (obj), TYPE_VIRTIO_GPU_PCI_BASE)
-struct VirtIOGPUPCI {
+struct VirtIOGPUPCIBase {
VirtIOPCIProxy parent_obj;
- VirtIOGPU vdev;
+ VirtIOGPUBase *vgpu;
};
-static Property virtio_gpu_pci_properties[] = {
+static Property virtio_gpu_pci_base_properties[] = {
DEFINE_VIRTIO_GPU_PCI_PROPERTIES(VirtIOPCIProxy),
DEFINE_PROP_END_OF_LIST(),
};
-static void virtio_gpu_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
+static void virtio_gpu_pci_base_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
{
- VirtIOGPUPCI *vgpu = VIRTIO_GPU_PCI(vpci_dev);
- VirtIOGPUBase *g = VIRTIO_GPU_BASE(&vgpu->vdev);
- DeviceState *vdev = DEVICE(&vgpu->vdev);
+ VirtIOGPUPCIBase *vgpu = VIRTIO_GPU_PCI_BASE(vpci_dev);
+ VirtIOGPUBase *g = vgpu->vgpu;
+ DeviceState *vdev = DEVICE(g);
int i;
Error *local_error = NULL;
@@ -62,36 +62,56 @@ static void virtio_gpu_pci_realize(VirtIOPCIProxy
*vpci_dev, Error **errp)
}
}
-static void virtio_gpu_pci_class_init(ObjectClass *klass, void *data)
+static void virtio_gpu_pci_base_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;
+ dc->props = virtio_gpu_pci_base_properties;
dc->hotpluggable = false;
- k->realize = virtio_gpu_pci_realize;
+ k->realize = virtio_gpu_pci_base_realize;
pcidev_k->class_id = PCI_CLASS_DISPLAY_OTHER;
}
+static const TypeInfo virtio_gpu_pci_base_info = {
+ .name = TYPE_VIRTIO_GPU_PCI_BASE,
+ .parent = TYPE_VIRTIO_PCI,
+ .instance_size = sizeof(VirtIOGPUPCIBase),
+ .class_init = virtio_gpu_pci_base_class_init,
+ .abstract = true
+};
+
+#define TYPE_VIRTIO_GPU_PCI "virtio-gpu-pci"
+#define VIRTIO_GPU_PCI(obj) \
+ OBJECT_CHECK(VirtIOGPUPCI, (obj), TYPE_VIRTIO_GPU_PCI)
+
+typedef struct VirtIOGPUPCI {
+ VirtIOGPUPCIBase parent_obj;
+ VirtIOGPU vdev;
+} VirtIOGPUPCI;
+
static void virtio_gpu_initfn(Object *obj)
{
VirtIOGPUPCI *dev = VIRTIO_GPU_PCI(obj);
virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
TYPE_VIRTIO_GPU);
+ VIRTIO_GPU_PCI_BASE(obj)->vgpu = VIRTIO_GPU_BASE(&dev->vdev);
}
static const VirtioPCIDeviceTypeInfo virtio_gpu_pci_info = {
.generic_name = TYPE_VIRTIO_GPU_PCI,
+ .parent = TYPE_VIRTIO_GPU_PCI_BASE,
.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_base_info);
virtio_pci_types_register(&virtio_gpu_pci_info);
}
+
type_init(virtio_gpu_pci_register_types)
diff --git a/hw/display/virtio-vga.c b/hw/display/virtio-vga.c
index 33af54d44f..caa3e138b0 100644
--- a/hw/display/virtio-vga.c
+++ b/hw/display/virtio-vga.c
@@ -1,66 +1,42 @@
#include "qemu/osdep.h"
#include "hw/hw.h"
#include "hw/pci/pci.h"
-#include "vga_int.h"
-#include "hw/virtio/virtio-pci.h"
#include "hw/virtio/virtio-gpu.h"
#include "qapi/error.h"
+#include "virtio-vga.h"
-/*
- * virtio-vga: This extends VirtioPCIProxy.
- */
-#define TYPE_VIRTIO_VGA "virtio-vga"
-#define VIRTIO_VGA(obj) \
- OBJECT_CHECK(VirtIOVGA, (obj), TYPE_VIRTIO_VGA)
-#define VIRTIO_VGA_GET_CLASS(obj) \
- OBJECT_GET_CLASS(VirtIOVGAClass, obj, TYPE_VIRTIO_VGA)
-#define VIRTIO_VGA_CLASS(klass) \
- OBJECT_CLASS_CHECK(VirtIOVGAClass, klass, TYPE_VIRTIO_VGA)
-
-typedef struct VirtIOVGA {
- VirtIOPCIProxy parent_obj;
- VirtIOGPU vdev;
- VGACommonState vga;
- MemoryRegion vga_mrs[3];
-} VirtIOVGA;
-
-typedef struct VirtIOVGAClass {
- VirtioPCIClass parent_class;
- DeviceReset parent_reset;
-} VirtIOVGAClass;
-
-static void virtio_vga_invalidate_display(void *opaque)
+static void virtio_vga_base_invalidate_display(void *opaque)
{
- VirtIOVGA *vvga = opaque;
- VirtIOGPUBase *g = VIRTIO_GPU_BASE(&vvga->vdev);
+ VirtIOVGABase *vvga = opaque;
+ VirtIOGPUBase *g = vvga->vgpu;
if (g->enable) {
- virtio_gpu_ops.invalidate(&vvga->vdev);
+ virtio_gpu_ops.invalidate(g);
} else {
vvga->vga.hw_ops->invalidate(&vvga->vga);
}
}
-static void virtio_vga_update_display(void *opaque)
+static void virtio_vga_base_update_display(void *opaque)
{
- VirtIOVGA *vvga = opaque;
- VirtIOGPUBase *g = VIRTIO_GPU_BASE(&vvga->vdev);
+ VirtIOVGABase *vvga = opaque;
+ VirtIOGPUBase *g = vvga->vgpu;
if (g->enable) {
- virtio_gpu_ops.gfx_update(&vvga->vdev);
+ virtio_gpu_ops.gfx_update(g);
} else {
vvga->vga.hw_ops->gfx_update(&vvga->vga);
}
}
-static void virtio_vga_text_update(void *opaque, console_ch_t *chardata)
+static void virtio_vga_base_text_update(void *opaque, console_ch_t *chardata)
{
- VirtIOVGA *vvga = opaque;
- VirtIOGPUBase *g = VIRTIO_GPU_BASE(&vvga->vdev);
+ VirtIOVGABase *vvga = opaque;
+ VirtIOGPUBase *g = vvga->vgpu;
if (g->enable) {
if (virtio_gpu_ops.text_update) {
- virtio_gpu_ops.text_update(&vvga->vdev, chardata);
+ virtio_gpu_ops.text_update(g, chardata);
}
} else {
if (vvga->vga.hw_ops->text_update) {
@@ -69,49 +45,52 @@ static void virtio_vga_text_update(void *opaque,
console_ch_t *chardata)
}
}
-static int virtio_vga_ui_info(void *opaque, uint32_t idx, QemuUIInfo *info)
+static int virtio_vga_base_ui_info(void *opaque, uint32_t idx, QemuUIInfo
*info)
{
- VirtIOVGA *vvga = opaque;
+ VirtIOVGABase *vvga = opaque;
+ VirtIOGPUBase *g = vvga->vgpu;
if (virtio_gpu_ops.ui_info) {
- return virtio_gpu_ops.ui_info(&vvga->vdev, idx, info);
+ return virtio_gpu_ops.ui_info(g, idx, info);
}
return -1;
}
-static void virtio_vga_gl_block(void *opaque, bool block)
+static void virtio_vga_base_gl_block(void *opaque, bool block)
{
- VirtIOVGA *vvga = opaque;
+ VirtIOVGABase *vvga = opaque;
+ VirtIOGPUBase *g = vvga->vgpu;
if (virtio_gpu_ops.gl_block) {
- virtio_gpu_ops.gl_block(&vvga->vdev, block);
+ virtio_gpu_ops.gl_block(g, block);
}
}
-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,
- .gl_block = virtio_vga_gl_block,
+static const GraphicHwOps virtio_vga_base_ops = {
+ .invalidate = virtio_vga_base_invalidate_display,
+ .gfx_update = virtio_vga_base_update_display,
+ .text_update = virtio_vga_base_text_update,
+ .ui_info = virtio_vga_base_ui_info,
+ .gl_block = virtio_vga_base_gl_block,
};
-static const VMStateDescription vmstate_virtio_vga = {
+static const VMStateDescription vmstate_virtio_vga_base = {
.name = "virtio-vga",
.version_id = 2,
.minimum_version_id = 2,
.fields = (VMStateField[]) {
/* no pci stuff here, saving the virtio device will handle that */
- VMSTATE_STRUCT(vga, VirtIOVGA, 0, vmstate_vga_common, VGACommonState),
+ VMSTATE_STRUCT(vga, VirtIOVGABase, 0,
+ vmstate_vga_common, VGACommonState),
VMSTATE_END_OF_LIST()
}
};
/* VGA device wrapper around PCI device around virtio GPU */
-static void virtio_vga_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
+static void virtio_vga_base_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
{
- VirtIOVGA *vvga = VIRTIO_VGA(vpci_dev);
- VirtIOGPUBase *g = VIRTIO_GPU_BASE(&vvga->vdev);
+ VirtIOVGABase *vvga = VIRTIO_VGA_BASE(vpci_dev);
+ VirtIOGPUBase *g = vvga->vgpu;
VGACommonState *vga = &vvga->vga;
Error *err = NULL;
uint32_t offset;
@@ -169,7 +148,7 @@ static void virtio_vga_realize(VirtIOPCIProxy *vpci_dev,
Error **errp)
vvga->vga_mrs, true, false);
vga->con = g->scanout[0].con;
- graphic_console_set_hwops(vga->con, &virtio_vga_ops, vvga);
+ graphic_console_set_hwops(vga->con, &virtio_vga_base_ops, vvga);
for (i = 0; i < g->conf.max_outputs; i++) {
object_property_set_link(OBJECT(g->scanout[i].con),
@@ -178,10 +157,10 @@ static void virtio_vga_realize(VirtIOPCIProxy *vpci_dev,
Error **errp)
}
}
-static void virtio_vga_reset(DeviceState *dev)
+static void virtio_vga_base_reset(DeviceState *dev)
{
- VirtIOVGAClass *klass = VIRTIO_VGA_GET_CLASS(dev);
- VirtIOVGA *vvga = VIRTIO_VGA(dev);
+ VirtIOVGABaseClass *klass = VIRTIO_VGA_BASE_GET_CLASS(dev);
+ VirtIOVGABase *vvga = VIRTIO_VGA_BASE(dev);
/* reset virtio-gpu */
klass->parent_reset(dev);
@@ -191,48 +170,70 @@ static void virtio_vga_reset(DeviceState *dev)
vga_dirty_log_start(&vvga->vga);
}
-static Property virtio_vga_properties[] = {
+static Property virtio_vga_base_properties[] = {
DEFINE_VIRTIO_GPU_PCI_PROPERTIES(VirtIOPCIProxy),
DEFINE_PROP_END_OF_LIST(),
};
-static void virtio_vga_class_init(ObjectClass *klass, void *data)
+static void virtio_vga_base_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
- VirtIOVGAClass *v = VIRTIO_VGA_CLASS(klass);
+ VirtIOVGABaseClass *v = VIRTIO_VGA_BASE_CLASS(klass);
PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories);
- dc->props = virtio_vga_properties;
- dc->vmsd = &vmstate_virtio_vga;
+ dc->props = virtio_vga_base_properties;
+ dc->vmsd = &vmstate_virtio_vga_base;
dc->hotpluggable = false;
- device_class_set_parent_reset(dc, virtio_vga_reset,
+ device_class_set_parent_reset(dc, virtio_vga_base_reset,
&v->parent_reset);
- k->realize = virtio_vga_realize;
+ k->realize = virtio_vga_base_realize;
pcidev_k->romfile = "vgabios-virtio.bin";
pcidev_k->class_id = PCI_CLASS_DISPLAY_VGA;
}
+static TypeInfo virtio_vga_base_info = {
+ .name = TYPE_VIRTIO_VGA_BASE,
+ .parent = TYPE_VIRTIO_PCI,
+ .instance_size = sizeof(struct VirtIOVGABase),
+ .class_size = sizeof(struct VirtIOVGABaseClass),
+ .class_init = virtio_vga_base_class_init,
+ .abstract = true,
+};
+
+#define TYPE_VIRTIO_VGA "virtio-vga"
+
+#define VIRTIO_VGA(obj) \
+ OBJECT_CHECK(VirtIOVGA, (obj), TYPE_VIRTIO_VGA)
+
+typedef struct VirtIOVGA {
+ VirtIOVGABase parent_obj;
+
+ VirtIOGPU vdev;
+} VirtIOVGA;
+
static void virtio_vga_inst_initfn(Object *obj)
{
VirtIOVGA *dev = VIRTIO_VGA(obj);
virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
TYPE_VIRTIO_GPU);
+ VIRTIO_VGA_BASE(dev)->vgpu = VIRTIO_GPU_BASE(&dev->vdev);
}
+
static VirtioPCIDeviceTypeInfo virtio_vga_info = {
.generic_name = TYPE_VIRTIO_VGA,
+ .parent = TYPE_VIRTIO_VGA_BASE,
.instance_size = sizeof(struct VirtIOVGA),
.instance_init = virtio_vga_inst_initfn,
- .class_size = sizeof(struct VirtIOVGAClass),
- .class_init = virtio_vga_class_init,
};
static void virtio_vga_register_types(void)
{
+ type_register_static(&virtio_vga_base_info);
virtio_pci_types_register(&virtio_vga_info);
}
diff --git a/MAINTAINERS b/MAINTAINERS
index a2ea99f4cd..1eee26a951 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1672,7 +1672,7 @@ virtio-gpu
M: Gerd Hoffmann <address@hidden>
S: Maintained
F: hw/display/virtio-gpu*
-F: hw/display/virtio-vga.c
+F: hw/display/virtio-vga.*
F: include/hw/virtio/virtio-gpu.h
vhost-user-gpu
--
2.21.0.777.g83232e3864
- [Qemu-devel] [PATCH v7 0/8] Add vhost-user-gpu, Marc-André Lureau, 2019/05/13
- [Qemu-devel] [PATCH v7 2/8] virtio-gpu: add bswap helpers header, Marc-André Lureau, 2019/05/13
- [Qemu-devel] [PATCH v7 3/8] virtio-gpu: add a pixman helper header, Marc-André Lureau, 2019/05/13
- [Qemu-devel] [PATCH v7 4/8] util: compile drm.o on Linux, Marc-André Lureau, 2019/05/13
- [Qemu-devel] [PATCH v7 5/8] contrib: add vhost-user-gpu, Marc-André Lureau, 2019/05/13
- [Qemu-devel] [PATCH v7 6/8] virtio-gpu: split virtio-gpu, introduce virtio-gpu-base, Marc-André Lureau, 2019/05/13
- [Qemu-devel] [PATCH v7 7/8] virtio-gpu: split virtio-gpu-pci & virtio-vga,
Marc-André Lureau <=
- [Qemu-devel] [PATCH v7 8/8] hw/display: add vhost-user-vga & gpu-pci, Marc-André Lureau, 2019/05/13