]>
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" |
db1015e9 | 22 | #include "qom/object.h" |
7ecb381f | 23 | |
c68082c4 | 24 | static Property virtio_gpu_pci_base_properties[] = { |
9eafb62d GH |
25 | DEFINE_VIRTIO_GPU_PCI_PROPERTIES(VirtIOPCIProxy), |
26 | DEFINE_PROP_END_OF_LIST(), | |
27 | }; | |
28 | ||
c68082c4 | 29 | static void virtio_gpu_pci_base_realize(VirtIOPCIProxy *vpci_dev, Error **errp) |
9eafb62d | 30 | { |
c68082c4 MAL |
31 | VirtIOGPUPCIBase *vgpu = VIRTIO_GPU_PCI_BASE(vpci_dev); |
32 | VirtIOGPUBase *g = vgpu->vgpu; | |
33 | DeviceState *vdev = DEVICE(g); | |
e1888295 | 34 | int i; |
9eafb62d | 35 | |
dd56040d | 36 | virtio_pci_force_virtio_1(vpci_dev); |
668f62ec | 37 | if (!qdev_realize(vdev, BUS(&vpci_dev->bus), errp)) { |
34e304e9 PX |
38 | return; |
39 | } | |
e1888295 GH |
40 | |
41 | for (i = 0; i < g->conf.max_outputs; i++) { | |
5325cc34 MA |
42 | object_property_set_link(OBJECT(g->scanout[i].con), "device", |
43 | OBJECT(vpci_dev), &error_abort); | |
e1888295 | 44 | } |
9eafb62d GH |
45 | } |
46 | ||
c68082c4 | 47 | static void virtio_gpu_pci_base_class_init(ObjectClass *klass, void *data) |
9eafb62d GH |
48 | { |
49 | DeviceClass *dc = DEVICE_CLASS(klass); | |
50 | VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass); | |
51 | PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass); | |
52 | ||
53 | set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories); | |
4f67d30b | 54 | device_class_set_props(dc, virtio_gpu_pci_base_properties); |
597966d1 | 55 | dc->hotpluggable = false; |
c68082c4 | 56 | k->realize = virtio_gpu_pci_base_realize; |
9eafb62d GH |
57 | pcidev_k->class_id = PCI_CLASS_DISPLAY_OTHER; |
58 | } | |
59 | ||
c68082c4 MAL |
60 | static const TypeInfo virtio_gpu_pci_base_info = { |
61 | .name = TYPE_VIRTIO_GPU_PCI_BASE, | |
62 | .parent = TYPE_VIRTIO_PCI, | |
63 | .instance_size = sizeof(VirtIOGPUPCIBase), | |
64 | .class_init = virtio_gpu_pci_base_class_init, | |
65 | .abstract = true | |
66 | }; | |
561d0f45 | 67 | module_obj(TYPE_VIRTIO_GPU_PCI_BASE); |
24ce7aa7 | 68 | module_kconfig(VIRTIO_PCI); |
c68082c4 MAL |
69 | |
70 | #define TYPE_VIRTIO_GPU_PCI "virtio-gpu-pci" | |
db1015e9 | 71 | typedef struct VirtIOGPUPCI VirtIOGPUPCI; |
8110fa1d EH |
72 | DECLARE_INSTANCE_CHECKER(VirtIOGPUPCI, VIRTIO_GPU_PCI, |
73 | TYPE_VIRTIO_GPU_PCI) | |
c68082c4 | 74 | |
db1015e9 | 75 | struct VirtIOGPUPCI { |
c68082c4 MAL |
76 | VirtIOGPUPCIBase parent_obj; |
77 | VirtIOGPU vdev; | |
db1015e9 | 78 | }; |
c68082c4 | 79 | |
9eafb62d GH |
80 | static void virtio_gpu_initfn(Object *obj) |
81 | { | |
82 | VirtIOGPUPCI *dev = VIRTIO_GPU_PCI(obj); | |
b3409a31 GH |
83 | |
84 | virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), | |
85 | TYPE_VIRTIO_GPU); | |
c68082c4 | 86 | VIRTIO_GPU_PCI_BASE(obj)->vgpu = VIRTIO_GPU_BASE(&dev->vdev); |
9eafb62d GH |
87 | } |
88 | ||
a4ee4c8b EH |
89 | static const VirtioPCIDeviceTypeInfo virtio_gpu_pci_info = { |
90 | .generic_name = TYPE_VIRTIO_GPU_PCI, | |
c68082c4 | 91 | .parent = TYPE_VIRTIO_GPU_PCI_BASE, |
9eafb62d GH |
92 | .instance_size = sizeof(VirtIOGPUPCI), |
93 | .instance_init = virtio_gpu_initfn, | |
9eafb62d | 94 | }; |
561d0f45 | 95 | module_obj(TYPE_VIRTIO_GPU_PCI); |
9eafb62d GH |
96 | |
97 | static void virtio_gpu_pci_register_types(void) | |
98 | { | |
c68082c4 | 99 | type_register_static(&virtio_gpu_pci_base_info); |
a4ee4c8b | 100 | virtio_pci_types_register(&virtio_gpu_pci_info); |
9eafb62d | 101 | } |
c68082c4 | 102 | |
9eafb62d | 103 | type_init(virtio_gpu_pci_register_types) |