]> git.proxmox.com Git - mirror_qemu.git/blob - hw/display/virtio-gpu-pci.c
Merge remote-tracking branch 'remotes/kraxel/tags/vga-20190222-pull-request' into...
[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 "hw/pci/pci.h"
17 #include "hw/virtio/virtio.h"
18 #include "hw/virtio/virtio-bus.h"
19 #include "hw/virtio/virtio-pci.h"
20 #include "hw/virtio/virtio-gpu.h"
21
22 typedef struct VirtIOGPUPCI VirtIOGPUPCI;
23
24 /*
25 * virtio-gpu-pci: This extends VirtioPCIProxy.
26 */
27 #define TYPE_VIRTIO_GPU_PCI "virtio-gpu-pci"
28 #define VIRTIO_GPU_PCI(obj) \
29 OBJECT_CHECK(VirtIOGPUPCI, (obj), TYPE_VIRTIO_GPU_PCI)
30
31 struct VirtIOGPUPCI {
32 VirtIOPCIProxy parent_obj;
33 VirtIOGPU vdev;
34 };
35
36 static Property virtio_gpu_pci_properties[] = {
37 DEFINE_VIRTIO_GPU_PCI_PROPERTIES(VirtIOPCIProxy),
38 DEFINE_PROP_END_OF_LIST(),
39 };
40
41 static void virtio_gpu_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
42 {
43 VirtIOGPUPCI *vgpu = VIRTIO_GPU_PCI(vpci_dev);
44 VirtIOGPU *g = &vgpu->vdev;
45 DeviceState *vdev = DEVICE(&vgpu->vdev);
46 int i;
47 Error *local_error = NULL;
48
49 qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus));
50 virtio_pci_force_virtio_1(vpci_dev);
51 object_property_set_bool(OBJECT(vdev), true, "realized", &local_error);
52
53 if (local_error) {
54 error_propagate(errp, local_error);
55 return;
56 }
57
58 for (i = 0; i < g->conf.max_outputs; i++) {
59 object_property_set_link(OBJECT(g->scanout[i].con),
60 OBJECT(vpci_dev),
61 "device", errp);
62 }
63 }
64
65 static void virtio_gpu_pci_class_init(ObjectClass *klass, void *data)
66 {
67 DeviceClass *dc = DEVICE_CLASS(klass);
68 VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
69 PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
70
71 set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories);
72 dc->props = virtio_gpu_pci_properties;
73 dc->hotpluggable = false;
74 k->realize = virtio_gpu_pci_realize;
75 pcidev_k->class_id = PCI_CLASS_DISPLAY_OTHER;
76 }
77
78 static void virtio_gpu_initfn(Object *obj)
79 {
80 VirtIOGPUPCI *dev = VIRTIO_GPU_PCI(obj);
81
82 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
83 TYPE_VIRTIO_GPU);
84 }
85
86 static const VirtioPCIDeviceTypeInfo virtio_gpu_pci_info = {
87 .generic_name = TYPE_VIRTIO_GPU_PCI,
88 .instance_size = sizeof(VirtIOGPUPCI),
89 .instance_init = virtio_gpu_initfn,
90 .class_init = virtio_gpu_pci_class_init,
91 };
92
93 static void virtio_gpu_pci_register_types(void)
94 {
95 virtio_pci_types_register(&virtio_gpu_pci_info);
96 }
97 type_init(virtio_gpu_pci_register_types)