2016-01-26 21:17:07 +03:00
|
|
|
#include "qemu/osdep.h"
|
2014-09-10 16:25:45 +04:00
|
|
|
#include "hw/pci/pci.h"
|
2019-08-12 08:23:51 +03:00
|
|
|
#include "hw/qdev-properties.h"
|
2019-01-03 17:10:11 +03:00
|
|
|
#include "hw/virtio/virtio-gpu.h"
|
2016-05-19 13:25:56 +03:00
|
|
|
#include "qapi/error.h"
|
2019-05-23 17:35:07 +03:00
|
|
|
#include "qemu/module.h"
|
2019-05-24 16:09:45 +03:00
|
|
|
#include "virtio-vga.h"
|
2014-09-10 16:25:45 +04:00
|
|
|
|
2019-05-24 16:09:45 +03:00
|
|
|
static void virtio_vga_base_invalidate_display(void *opaque)
|
2014-09-10 16:25:45 +04:00
|
|
|
{
|
2019-05-24 16:09:45 +03:00
|
|
|
VirtIOVGABase *vvga = opaque;
|
|
|
|
VirtIOGPUBase *g = vvga->vgpu;
|
2014-09-10 16:25:45 +04:00
|
|
|
|
2019-05-24 16:09:44 +03:00
|
|
|
if (g->enable) {
|
2019-05-24 16:09:45 +03:00
|
|
|
virtio_gpu_ops.invalidate(g);
|
2014-09-10 16:25:45 +04:00
|
|
|
} else {
|
|
|
|
vvga->vga.hw_ops->invalidate(&vvga->vga);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-24 16:09:45 +03:00
|
|
|
static void virtio_vga_base_update_display(void *opaque)
|
2014-09-10 16:25:45 +04:00
|
|
|
{
|
2019-05-24 16:09:45 +03:00
|
|
|
VirtIOVGABase *vvga = opaque;
|
|
|
|
VirtIOGPUBase *g = vvga->vgpu;
|
2014-09-10 16:25:45 +04:00
|
|
|
|
2019-05-24 16:09:44 +03:00
|
|
|
if (g->enable) {
|
2019-05-24 16:09:45 +03:00
|
|
|
virtio_gpu_ops.gfx_update(g);
|
2014-09-10 16:25:45 +04:00
|
|
|
} else {
|
|
|
|
vvga->vga.hw_ops->gfx_update(&vvga->vga);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-24 16:09:45 +03:00
|
|
|
static void virtio_vga_base_text_update(void *opaque, console_ch_t *chardata)
|
2014-09-10 16:25:45 +04:00
|
|
|
{
|
2019-05-24 16:09:45 +03:00
|
|
|
VirtIOVGABase *vvga = opaque;
|
|
|
|
VirtIOGPUBase *g = vvga->vgpu;
|
2014-09-10 16:25:45 +04:00
|
|
|
|
2019-05-24 16:09:44 +03:00
|
|
|
if (g->enable) {
|
2014-09-10 16:25:45 +04:00
|
|
|
if (virtio_gpu_ops.text_update) {
|
2019-05-24 16:09:45 +03:00
|
|
|
virtio_gpu_ops.text_update(g, chardata);
|
2014-09-10 16:25:45 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (vvga->vga.hw_ops->text_update) {
|
|
|
|
vvga->vga.hw_ops->text_update(&vvga->vga, chardata);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-24 16:09:45 +03:00
|
|
|
static int virtio_vga_base_ui_info(void *opaque, uint32_t idx, QemuUIInfo *info)
|
2014-09-10 16:25:45 +04:00
|
|
|
{
|
2019-05-24 16:09:45 +03:00
|
|
|
VirtIOVGABase *vvga = opaque;
|
|
|
|
VirtIOGPUBase *g = vvga->vgpu;
|
2014-09-10 16:25:45 +04:00
|
|
|
|
|
|
|
if (virtio_gpu_ops.ui_info) {
|
2019-05-24 16:09:45 +03:00
|
|
|
return virtio_gpu_ops.ui_info(g, idx, info);
|
2014-09-10 16:25:45 +04:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-05-24 16:09:45 +03:00
|
|
|
static void virtio_vga_base_gl_block(void *opaque, bool block)
|
2015-12-02 10:17:24 +03:00
|
|
|
{
|
2019-05-24 16:09:45 +03:00
|
|
|
VirtIOVGABase *vvga = opaque;
|
|
|
|
VirtIOGPUBase *g = vvga->vgpu;
|
2015-12-02 10:17:24 +03:00
|
|
|
|
|
|
|
if (virtio_gpu_ops.gl_block) {
|
2019-05-24 16:09:45 +03:00
|
|
|
virtio_gpu_ops.gl_block(g, block);
|
2015-12-02 10:17:24 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-24 16:09:45 +03:00
|
|
|
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,
|
2014-09-10 16:25:45 +04:00
|
|
|
};
|
|
|
|
|
2019-05-24 16:09:45 +03:00
|
|
|
static const VMStateDescription vmstate_virtio_vga_base = {
|
2016-05-23 16:22:07 +03:00
|
|
|
.name = "virtio-vga",
|
|
|
|
.version_id = 2,
|
|
|
|
.minimum_version_id = 2,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
/* no pci stuff here, saving the virtio device will handle that */
|
2019-05-24 16:09:45 +03:00
|
|
|
VMSTATE_STRUCT(vga, VirtIOVGABase, 0,
|
|
|
|
vmstate_vga_common, VGACommonState),
|
2016-05-23 16:22:07 +03:00
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-09-10 16:25:45 +04:00
|
|
|
/* VGA device wrapper around PCI device around virtio GPU */
|
2019-05-24 16:09:45 +03:00
|
|
|
static void virtio_vga_base_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
|
2014-09-10 16:25:45 +04:00
|
|
|
{
|
2019-05-24 16:09:45 +03:00
|
|
|
VirtIOVGABase *vvga = VIRTIO_VGA_BASE(vpci_dev);
|
|
|
|
VirtIOGPUBase *g = vvga->vgpu;
|
2014-09-10 16:25:45 +04:00
|
|
|
VGACommonState *vga = &vvga->vga;
|
2016-05-19 13:25:56 +03:00
|
|
|
Error *err = NULL;
|
2014-09-10 16:25:45 +04:00
|
|
|
uint32_t offset;
|
2015-06-24 13:19:42 +03:00
|
|
|
int i;
|
2014-09-10 16:25:45 +04:00
|
|
|
|
|
|
|
/* init vga compat bits */
|
|
|
|
vga->vram_size_mb = 8;
|
2018-07-02 19:33:44 +03:00
|
|
|
vga_common_init(vga, OBJECT(vpci_dev));
|
2014-09-10 16:25:45 +04:00
|
|
|
vga_init(vga, OBJECT(vpci_dev), pci_address_space(&vpci_dev->pci_dev),
|
|
|
|
pci_address_space_io(&vpci_dev->pci_dev), true);
|
|
|
|
pci_register_bar(&vpci_dev->pci_dev, 0,
|
|
|
|
PCI_BASE_ADDRESS_MEM_PREFETCH, &vga->vram);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Configure virtio bar and regions
|
|
|
|
*
|
|
|
|
* We use bar #2 for the mmio regions, to be compatible with stdvga.
|
|
|
|
* virtio regions are moved to the end of bar #2, to make room for
|
|
|
|
* the stdvga mmio registers at the start of bar #2.
|
|
|
|
*/
|
2016-09-29 07:04:40 +03:00
|
|
|
vpci_dev->modern_mem_bar_idx = 2;
|
|
|
|
vpci_dev->msix_bar_idx = 4;
|
2020-04-23 00:54:54 +03:00
|
|
|
vpci_dev->modern_io_bar_idx = 5;
|
2016-09-08 10:16:52 +03:00
|
|
|
|
|
|
|
if (!(vpci_dev->flags & VIRTIO_PCI_FLAG_PAGE_PER_VQ)) {
|
|
|
|
/*
|
|
|
|
* with page-per-vq=off there is no padding space we can use
|
|
|
|
* for the stdvga registers. Make the common and isr regions
|
|
|
|
* smaller then.
|
|
|
|
*/
|
|
|
|
vpci_dev->common.size /= 2;
|
|
|
|
vpci_dev->isr.size /= 2;
|
|
|
|
}
|
|
|
|
|
2014-09-10 16:25:45 +04:00
|
|
|
offset = memory_region_size(&vpci_dev->modern_bar);
|
|
|
|
offset -= vpci_dev->notify.size;
|
|
|
|
vpci_dev->notify.offset = offset;
|
|
|
|
offset -= vpci_dev->device.size;
|
|
|
|
vpci_dev->device.offset = offset;
|
|
|
|
offset -= vpci_dev->isr.size;
|
|
|
|
vpci_dev->isr.offset = offset;
|
|
|
|
offset -= vpci_dev->common.size;
|
|
|
|
vpci_dev->common.offset = offset;
|
|
|
|
|
|
|
|
/* init virtio bits */
|
2019-07-29 19:29:03 +03:00
|
|
|
virtio_pci_force_virtio_1(vpci_dev);
|
qdev: Convert uses of qdev_set_parent_bus() with Coccinelle
In addition to the qdev_create() patterns converted so far, we have a
qdev_set_parent_bus() pattern. Mostly when we embed a device in a
parent device rather than allocating it on the heap.
This pattern also puts devices in the dangerous "no QOM parent, but
plugged into bus" state I explained in recent commit "qdev: New
qdev_new(), qdev_realize(), etc."
Apply same solution: convert to qdev_realize(). Coccinelle script:
@@
expression dev, bus, errp;
symbol true;
@@
- qdev_set_parent_bus(DEVICE(dev), bus);
...
- object_property_set_bool(OBJECT(dev), true, "realized", errp);
+ qdev_realize(DEVICE(dev), bus, errp);
@ depends on !(file in "qdev-monitor.c") && !(file in "hw/core/qdev.c")@
expression dev, bus, errp;
symbol true;
@@
- qdev_set_parent_bus(dev, bus);
...
- object_property_set_bool(OBJECT(dev), true, "realized", errp);
+ qdev_realize(dev, bus, errp);
@@
expression dev, bus;
symbol true;
@@
- qdev_set_parent_bus(DEVICE(dev), bus);
...
- qdev_init_nofail(DEVICE(dev));
+ qdev_realize(DEVICE(dev), bus, &error_fatal);
Unconverted uses of qdev_set_parent_bus() remain. They'll be
converted later in this series.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-12-armbru@redhat.com>
[Also convert new hw/virtio/vhost-user-vsock-pci.c]
2020-06-10 08:32:00 +03:00
|
|
|
qdev_realize(DEVICE(g), BUS(&vpci_dev->bus), &err);
|
2016-05-19 13:25:56 +03:00
|
|
|
if (err) {
|
|
|
|
error_propagate(errp, err);
|
|
|
|
return;
|
|
|
|
}
|
2014-09-10 16:25:45 +04:00
|
|
|
|
|
|
|
/* add stdvga mmio regions */
|
2018-06-26 09:09:41 +03:00
|
|
|
pci_std_vga_mmio_region_init(vga, OBJECT(vvga), &vpci_dev->modern_bar,
|
2018-09-25 10:56:46 +03:00
|
|
|
vvga->vga_mrs, true, false);
|
2014-09-10 16:25:45 +04:00
|
|
|
|
|
|
|
vga->con = g->scanout[0].con;
|
2019-05-24 16:09:45 +03:00
|
|
|
graphic_console_set_hwops(vga->con, &virtio_vga_base_ops, vvga);
|
2015-06-24 13:19:42 +03:00
|
|
|
|
|
|
|
for (i = 0; i < g->conf.max_outputs; i++) {
|
|
|
|
object_property_set_link(OBJECT(g->scanout[i].con),
|
|
|
|
OBJECT(vpci_dev),
|
hw: Fix error API violation around object_property_set_link()
The Error ** argument must be NULL, &error_abort, &error_fatal, or a
pointer to a variable containing NULL. Passing an argument of the
latter kind twice without clearing it in between is wrong: if the
first call sets an error, it no longer points to NULL for the second
call.
virtio_gpu_pci_base_realize(), virtio_vga_base_realize(),
sparc32_ledma_device_realize(), sparc32_dma_realize(),
sparc32_dma_realize() xilinx_axidma_realize(), mips_cps_realize(),
macio_realize_ide(), xilinx_enet_realize(), and
virtio_iommu_pci_realize() are wrong that way: they reuse the argument
they pass to object_property_set_link() for another call.
Harmless, because object_property_set_link() can't actually fail for
them: it fails when the property doesn't exist, is not settable, or
its .check() method fails. Fix by passing &error_abort instead.
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Cc: "Edgar E. Iglesias" <edgar.iglesias@gmail.com>
Cc: Alistair Francis <alistair@alistair23.me>
Cc: Peter Maydell <peter.maydell@linaro.org>
Cc: qemu-arm@nongnu.org
Cc: Aleksandar Markovic <aleksandar.qemu.devel@gmail.com>
Cc: Aurelien Jarno <aurelien@aurel32.net>
Cc: Aleksandar Rikalo <aleksandar.rikalo@syrmia.com>
Cc: Eric Auger <eric.auger@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-Id: <20200630090351.1247703-16-armbru@redhat.com>
Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
2020-06-30 12:03:40 +03:00
|
|
|
"device", &error_abort);
|
2015-06-24 13:19:42 +03:00
|
|
|
}
|
2014-09-10 16:25:45 +04:00
|
|
|
}
|
|
|
|
|
2019-05-24 16:09:45 +03:00
|
|
|
static void virtio_vga_base_reset(DeviceState *dev)
|
2014-09-10 16:25:45 +04:00
|
|
|
{
|
2019-05-24 16:09:45 +03:00
|
|
|
VirtIOVGABaseClass *klass = VIRTIO_VGA_BASE_GET_CLASS(dev);
|
|
|
|
VirtIOVGABase *vvga = VIRTIO_VGA_BASE(dev);
|
2014-09-10 16:25:45 +04:00
|
|
|
|
2018-08-21 14:13:12 +03:00
|
|
|
/* reset virtio-gpu */
|
2019-03-07 11:02:43 +03:00
|
|
|
klass->parent_reset(dev);
|
2018-08-21 14:13:12 +03:00
|
|
|
|
|
|
|
/* reset vga */
|
|
|
|
vga_common_reset(&vvga->vga);
|
2014-09-10 16:25:45 +04:00
|
|
|
vga_dirty_log_start(&vvga->vga);
|
|
|
|
}
|
|
|
|
|
2019-05-24 16:09:45 +03:00
|
|
|
static Property virtio_vga_base_properties[] = {
|
2014-09-10 16:25:45 +04:00
|
|
|
DEFINE_VIRTIO_GPU_PCI_PROPERTIES(VirtIOPCIProxy),
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
2019-05-24 16:09:45 +03:00
|
|
|
static void virtio_vga_base_class_init(ObjectClass *klass, void *data)
|
2014-09-10 16:25:45 +04:00
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
|
|
|
VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
|
2019-05-24 16:09:45 +03:00
|
|
|
VirtIOVGABaseClass *v = VIRTIO_VGA_BASE_CLASS(klass);
|
2014-09-10 16:25:45 +04:00
|
|
|
PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
|
|
|
|
|
|
|
|
set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories);
|
2020-01-10 18:30:32 +03:00
|
|
|
device_class_set_props(dc, virtio_vga_base_properties);
|
2019-05-24 16:09:45 +03:00
|
|
|
dc->vmsd = &vmstate_virtio_vga_base;
|
2014-09-10 16:25:45 +04:00
|
|
|
dc->hotpluggable = false;
|
2019-05-24 16:09:45 +03:00
|
|
|
device_class_set_parent_reset(dc, virtio_vga_base_reset,
|
2019-03-07 11:02:43 +03:00
|
|
|
&v->parent_reset);
|
2014-09-10 16:25:45 +04:00
|
|
|
|
2019-05-24 16:09:45 +03:00
|
|
|
k->realize = virtio_vga_base_realize;
|
2014-09-10 16:25:45 +04:00
|
|
|
pcidev_k->romfile = "vgabios-virtio.bin";
|
|
|
|
pcidev_k->class_id = PCI_CLASS_DISPLAY_VGA;
|
|
|
|
}
|
|
|
|
|
2019-05-24 16:09:45 +03:00
|
|
|
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;
|
|
|
|
|
2014-09-10 16:25:45 +04:00
|
|
|
static void virtio_vga_inst_initfn(Object *obj)
|
|
|
|
{
|
|
|
|
VirtIOVGA *dev = VIRTIO_VGA(obj);
|
2015-06-24 13:22:09 +03:00
|
|
|
|
|
|
|
virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
|
|
|
|
TYPE_VIRTIO_GPU);
|
2019-05-24 16:09:45 +03:00
|
|
|
VIRTIO_VGA_BASE(dev)->vgpu = VIRTIO_GPU_BASE(&dev->vdev);
|
2014-09-10 16:25:45 +04:00
|
|
|
}
|
|
|
|
|
2019-05-24 16:09:45 +03:00
|
|
|
|
2018-12-05 22:57:03 +03:00
|
|
|
static VirtioPCIDeviceTypeInfo virtio_vga_info = {
|
|
|
|
.generic_name = TYPE_VIRTIO_VGA,
|
2019-05-24 16:09:45 +03:00
|
|
|
.parent = TYPE_VIRTIO_VGA_BASE,
|
2014-09-10 16:25:45 +04:00
|
|
|
.instance_size = sizeof(struct VirtIOVGA),
|
|
|
|
.instance_init = virtio_vga_inst_initfn,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void virtio_vga_register_types(void)
|
|
|
|
{
|
2019-05-24 16:09:45 +03:00
|
|
|
type_register_static(&virtio_vga_base_info);
|
2018-12-05 22:57:03 +03:00
|
|
|
virtio_pci_types_register(&virtio_vga_info);
|
2014-09-10 16:25:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
type_init(virtio_vga_register_types)
|