]>
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" |
9eafb62d GH |
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 | static Property virtio_gpu_pci_properties[] = { | |
9eafb62d GH |
23 | DEFINE_VIRTIO_GPU_PCI_PROPERTIES(VirtIOPCIProxy), |
24 | DEFINE_PROP_END_OF_LIST(), | |
25 | }; | |
26 | ||
27 | static void virtio_gpu_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) | |
28 | { | |
29 | VirtIOGPUPCI *vgpu = VIRTIO_GPU_PCI(vpci_dev); | |
e1888295 | 30 | VirtIOGPU *g = &vgpu->vdev; |
9eafb62d | 31 | DeviceState *vdev = DEVICE(&vgpu->vdev); |
e1888295 | 32 | int i; |
34e304e9 | 33 | Error *local_error = NULL; |
9eafb62d GH |
34 | |
35 | qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)); | |
9a4c0e22 | 36 | virtio_pci_force_virtio_1(vpci_dev); |
34e304e9 PX |
37 | object_property_set_bool(OBJECT(vdev), true, "realized", &local_error); |
38 | ||
39 | if (local_error) { | |
40 | error_propagate(errp, local_error); | |
41 | return; | |
42 | } | |
e1888295 GH |
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", errp); | |
48 | } | |
9eafb62d GH |
49 | } |
50 | ||
51 | static void virtio_gpu_pci_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 | dc->props = virtio_gpu_pci_properties; | |
597966d1 | 59 | dc->hotpluggable = false; |
9eafb62d GH |
60 | k->realize = virtio_gpu_pci_realize; |
61 | pcidev_k->class_id = PCI_CLASS_DISPLAY_OTHER; | |
62 | } | |
63 | ||
64 | static void virtio_gpu_initfn(Object *obj) | |
65 | { | |
66 | VirtIOGPUPCI *dev = VIRTIO_GPU_PCI(obj); | |
b3409a31 GH |
67 | |
68 | virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), | |
69 | TYPE_VIRTIO_GPU); | |
9eafb62d GH |
70 | } |
71 | ||
72 | static const TypeInfo virtio_gpu_pci_info = { | |
73 | .name = TYPE_VIRTIO_GPU_PCI, | |
74 | .parent = TYPE_VIRTIO_PCI, | |
75 | .instance_size = sizeof(VirtIOGPUPCI), | |
76 | .instance_init = virtio_gpu_initfn, | |
77 | .class_init = virtio_gpu_pci_class_init, | |
78 | }; | |
79 | ||
80 | static void virtio_gpu_pci_register_types(void) | |
81 | { | |
82 | type_register_static(&virtio_gpu_pci_info); | |
83 | } | |
84 | type_init(virtio_gpu_pci_register_types) |