]> git.proxmox.com Git - mirror_qemu.git/blob - hw/display/virtio-gpu-pci.c
41b88b878d9e3df18d0f814e37c9ac0aa293cd7e
[mirror_qemu.git] / hw / display / virtio-gpu-pci.c
1 /*
2 * Virtio video device
3 *
4 * Copyright Red Hat
5 *
6 * Authors:
7 * Dave Airlie
8 *
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
11 *
12 */
13
14 #include "qemu/osdep.h"
15 #include "qapi/error.h"
16 #include "qemu/module.h"
17 #include "hw/pci/pci.h"
18 #include "hw/qdev-properties.h"
19 #include "hw/virtio/virtio.h"
20 #include "hw/virtio/virtio-bus.h"
21 #include "hw/virtio/virtio-gpu-pci.h"
22
23 static Property virtio_gpu_pci_base_properties[] = {
24 DEFINE_VIRTIO_GPU_PCI_PROPERTIES(VirtIOPCIProxy),
25 DEFINE_PROP_END_OF_LIST(),
26 };
27
28 static void virtio_gpu_pci_base_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
29 {
30 VirtIOGPUPCIBase *vgpu = VIRTIO_GPU_PCI_BASE(vpci_dev);
31 VirtIOGPUBase *g = vgpu->vgpu;
32 DeviceState *vdev = DEVICE(g);
33 int i;
34 Error *local_error = NULL;
35
36 virtio_pci_force_virtio_1(vpci_dev);
37 qdev_realize(vdev, BUS(&vpci_dev->bus), &local_error);
38
39 if (local_error) {
40 error_propagate(errp, local_error);
41 return;
42 }
43
44 for (i = 0; i < g->conf.max_outputs; i++) {
45 object_property_set_link(OBJECT(g->scanout[i].con),
46 OBJECT(vpci_dev),
47 "device", &error_abort);
48 }
49 }
50
51 static void virtio_gpu_pci_base_class_init(ObjectClass *klass, void *data)
52 {
53 DeviceClass *dc = DEVICE_CLASS(klass);
54 VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
55 PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
56
57 set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories);
58 device_class_set_props(dc, virtio_gpu_pci_base_properties);
59 dc->hotpluggable = false;
60 k->realize = virtio_gpu_pci_base_realize;
61 pcidev_k->class_id = PCI_CLASS_DISPLAY_OTHER;
62 }
63
64 static const TypeInfo virtio_gpu_pci_base_info = {
65 .name = TYPE_VIRTIO_GPU_PCI_BASE,
66 .parent = TYPE_VIRTIO_PCI,
67 .instance_size = sizeof(VirtIOGPUPCIBase),
68 .class_init = virtio_gpu_pci_base_class_init,
69 .abstract = true
70 };
71
72 #define TYPE_VIRTIO_GPU_PCI "virtio-gpu-pci"
73 #define VIRTIO_GPU_PCI(obj) \
74 OBJECT_CHECK(VirtIOGPUPCI, (obj), TYPE_VIRTIO_GPU_PCI)
75
76 typedef struct VirtIOGPUPCI {
77 VirtIOGPUPCIBase parent_obj;
78 VirtIOGPU vdev;
79 } VirtIOGPUPCI;
80
81 static void virtio_gpu_initfn(Object *obj)
82 {
83 VirtIOGPUPCI *dev = VIRTIO_GPU_PCI(obj);
84
85 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
86 TYPE_VIRTIO_GPU);
87 VIRTIO_GPU_PCI_BASE(obj)->vgpu = VIRTIO_GPU_BASE(&dev->vdev);
88 }
89
90 static const VirtioPCIDeviceTypeInfo virtio_gpu_pci_info = {
91 .generic_name = TYPE_VIRTIO_GPU_PCI,
92 .parent = TYPE_VIRTIO_GPU_PCI_BASE,
93 .instance_size = sizeof(VirtIOGPUPCI),
94 .instance_init = virtio_gpu_initfn,
95 };
96
97 static void virtio_gpu_pci_register_types(void)
98 {
99 type_register_static(&virtio_gpu_pci_base_info);
100 virtio_pci_types_register(&virtio_gpu_pci_info);
101 }
102
103 type_init(virtio_gpu_pci_register_types)