]>
Commit | Line | Data |
---|---|---|
9eafb62d GH |
1 | /* |
2 | * Virtio video device | |
3 | * | |
4 | * Copyright Red Hat | |
5 | * | |
6 | * Authors: | |
7 | * Dave Airlie | |
8 | * | |
2e252145 GH |
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. | |
9eafb62d GH |
11 | * |
12 | */ | |
e688df6b | 13 | |
9b8bfe21 | 14 | #include "qemu/osdep.h" |
e688df6b | 15 | #include "qapi/error.h" |
0b8fa32f | 16 | #include "qemu/module.h" |
9eafb62d | 17 | #include "hw/pci/pci.h" |
a27bd6c7 | 18 | #include "hw/qdev-properties.h" |
9eafb62d GH |
19 | #include "hw/virtio/virtio.h" |
20 | #include "hw/virtio/virtio-bus.h" | |
267f6646 | 21 | #include "hw/virtio/virtio-gpu-pci.h" |
7ecb381f | 22 | |
c68082c4 | 23 | static Property virtio_gpu_pci_base_properties[] = { |
9eafb62d GH |
24 | DEFINE_VIRTIO_GPU_PCI_PROPERTIES(VirtIOPCIProxy), |
25 | DEFINE_PROP_END_OF_LIST(), | |
26 | }; | |
27 | ||
c68082c4 | 28 | static void virtio_gpu_pci_base_realize(VirtIOPCIProxy *vpci_dev, Error **errp) |
9eafb62d | 29 | { |
c68082c4 MAL |
30 | VirtIOGPUPCIBase *vgpu = VIRTIO_GPU_PCI_BASE(vpci_dev); |
31 | VirtIOGPUBase *g = vgpu->vgpu; | |
32 | DeviceState *vdev = DEVICE(g); | |
e1888295 | 33 | int i; |
34e304e9 | 34 | Error *local_error = NULL; |
9eafb62d GH |
35 | |
36 | qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)); | |
dd56040d | 37 | virtio_pci_force_virtio_1(vpci_dev); |
34e304e9 PX |
38 | object_property_set_bool(OBJECT(vdev), true, "realized", &local_error); |
39 | ||
40 | if (local_error) { | |
41 | error_propagate(errp, local_error); | |
42 | return; | |
43 | } | |
e1888295 GH |
44 | |
45 | for (i = 0; i < g->conf.max_outputs; i++) { | |
46 | object_property_set_link(OBJECT(g->scanout[i].con), | |
47 | OBJECT(vpci_dev), | |
48 | "device", errp); | |
49 | } | |
9eafb62d GH |
50 | } |
51 | ||
c68082c4 | 52 | static void virtio_gpu_pci_base_class_init(ObjectClass *klass, void *data) |
9eafb62d GH |
53 | { |
54 | DeviceClass *dc = DEVICE_CLASS(klass); | |
55 | VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass); | |
56 | PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass); | |
57 | ||
58 | set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories); | |
c68082c4 | 59 | dc->props = virtio_gpu_pci_base_properties; |
597966d1 | 60 | dc->hotpluggable = false; |
c68082c4 | 61 | k->realize = virtio_gpu_pci_base_realize; |
9eafb62d GH |
62 | pcidev_k->class_id = PCI_CLASS_DISPLAY_OTHER; |
63 | } | |
64 | ||
c68082c4 MAL |
65 | static const TypeInfo virtio_gpu_pci_base_info = { |
66 | .name = TYPE_VIRTIO_GPU_PCI_BASE, | |
67 | .parent = TYPE_VIRTIO_PCI, | |
68 | .instance_size = sizeof(VirtIOGPUPCIBase), | |
69 | .class_init = virtio_gpu_pci_base_class_init, | |
70 | .abstract = true | |
71 | }; | |
72 | ||
73 | #define TYPE_VIRTIO_GPU_PCI "virtio-gpu-pci" | |
74 | #define VIRTIO_GPU_PCI(obj) \ | |
75 | OBJECT_CHECK(VirtIOGPUPCI, (obj), TYPE_VIRTIO_GPU_PCI) | |
76 | ||
77 | typedef struct VirtIOGPUPCI { | |
78 | VirtIOGPUPCIBase parent_obj; | |
79 | VirtIOGPU vdev; | |
80 | } VirtIOGPUPCI; | |
81 | ||
9eafb62d GH |
82 | static void virtio_gpu_initfn(Object *obj) |
83 | { | |
84 | VirtIOGPUPCI *dev = VIRTIO_GPU_PCI(obj); | |
b3409a31 GH |
85 | |
86 | virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), | |
87 | TYPE_VIRTIO_GPU); | |
c68082c4 | 88 | VIRTIO_GPU_PCI_BASE(obj)->vgpu = VIRTIO_GPU_BASE(&dev->vdev); |
9eafb62d GH |
89 | } |
90 | ||
a4ee4c8b EH |
91 | static const VirtioPCIDeviceTypeInfo virtio_gpu_pci_info = { |
92 | .generic_name = TYPE_VIRTIO_GPU_PCI, | |
c68082c4 | 93 | .parent = TYPE_VIRTIO_GPU_PCI_BASE, |
9eafb62d GH |
94 | .instance_size = sizeof(VirtIOGPUPCI), |
95 | .instance_init = virtio_gpu_initfn, | |
9eafb62d GH |
96 | }; |
97 | ||
98 | static void virtio_gpu_pci_register_types(void) | |
99 | { | |
c68082c4 | 100 | type_register_static(&virtio_gpu_pci_base_info); |
a4ee4c8b | 101 | virtio_pci_types_register(&virtio_gpu_pci_info); |
9eafb62d | 102 | } |
c68082c4 | 103 | |
9eafb62d | 104 | type_init(virtio_gpu_pci_register_types) |