]> Git Repo - qemu.git/blob - hw/display/virtio-gpu-pci.c
virtio-gpu: split virtio-gpu-pci & virtio-vga
[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 VirtIOGPUPCIBase VirtIOGPUPCIBase;
23
24 /*
25  * virtio-gpu-pci-base: This extends VirtioPCIProxy.
26  */
27 #define TYPE_VIRTIO_GPU_PCI_BASE "virtio-gpu-pci-base"
28 #define VIRTIO_GPU_PCI_BASE(obj) \
29         OBJECT_CHECK(VirtIOGPUPCIBase, (obj), TYPE_VIRTIO_GPU_PCI_BASE)
30
31 struct VirtIOGPUPCIBase {
32     VirtIOPCIProxy parent_obj;
33     VirtIOGPUBase *vgpu;
34 };
35
36 static Property virtio_gpu_pci_base_properties[] = {
37     DEFINE_VIRTIO_GPU_PCI_PROPERTIES(VirtIOPCIProxy),
38     DEFINE_PROP_END_OF_LIST(),
39 };
40
41 static void virtio_gpu_pci_base_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
42 {
43     VirtIOGPUPCIBase *vgpu = VIRTIO_GPU_PCI_BASE(vpci_dev);
44     VirtIOGPUBase *g = vgpu->vgpu;
45     DeviceState *vdev = DEVICE(g);
46     int i;
47     Error *local_error = NULL;
48
49     qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus));
50     if (!virtio_pci_force_virtio_1(vpci_dev, errp)) {
51         return;
52     }
53     object_property_set_bool(OBJECT(vdev), true, "realized", &local_error);
54
55     if (local_error) {
56         error_propagate(errp, local_error);
57         return;
58     }
59
60     for (i = 0; i < g->conf.max_outputs; i++) {
61         object_property_set_link(OBJECT(g->scanout[i].con),
62                                  OBJECT(vpci_dev),
63                                  "device", errp);
64     }
65 }
66
67 static void virtio_gpu_pci_base_class_init(ObjectClass *klass, void *data)
68 {
69     DeviceClass *dc = DEVICE_CLASS(klass);
70     VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
71     PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
72
73     set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories);
74     dc->props = virtio_gpu_pci_base_properties;
75     dc->hotpluggable = false;
76     k->realize = virtio_gpu_pci_base_realize;
77     pcidev_k->class_id = PCI_CLASS_DISPLAY_OTHER;
78 }
79
80 static const TypeInfo virtio_gpu_pci_base_info = {
81     .name = TYPE_VIRTIO_GPU_PCI_BASE,
82     .parent = TYPE_VIRTIO_PCI,
83     .instance_size = sizeof(VirtIOGPUPCIBase),
84     .class_init = virtio_gpu_pci_base_class_init,
85     .abstract = true
86 };
87
88 #define TYPE_VIRTIO_GPU_PCI "virtio-gpu-pci"
89 #define VIRTIO_GPU_PCI(obj)                                 \
90     OBJECT_CHECK(VirtIOGPUPCI, (obj), TYPE_VIRTIO_GPU_PCI)
91
92 typedef struct VirtIOGPUPCI {
93     VirtIOGPUPCIBase parent_obj;
94     VirtIOGPU vdev;
95 } VirtIOGPUPCI;
96
97 static void virtio_gpu_initfn(Object *obj)
98 {
99     VirtIOGPUPCI *dev = VIRTIO_GPU_PCI(obj);
100
101     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
102                                 TYPE_VIRTIO_GPU);
103     VIRTIO_GPU_PCI_BASE(obj)->vgpu = VIRTIO_GPU_BASE(&dev->vdev);
104 }
105
106 static const VirtioPCIDeviceTypeInfo virtio_gpu_pci_info = {
107     .generic_name = TYPE_VIRTIO_GPU_PCI,
108     .parent = TYPE_VIRTIO_GPU_PCI_BASE,
109     .instance_size = sizeof(VirtIOGPUPCI),
110     .instance_init = virtio_gpu_initfn,
111 };
112
113 static void virtio_gpu_pci_register_types(void)
114 {
115     type_register_static(&virtio_gpu_pci_base_info);
116     virtio_pci_types_register(&virtio_gpu_pci_info);
117 }
118
119 type_init(virtio_gpu_pci_register_types)
This page took 0.0269 seconds and 4 git commands to generate.