blob: eef137f8130a2737bcf4cd0e40b98c5ce6a020b2 [file] [log] [blame]
Gerd Hoffmann9eafb622014-09-10 14:20:34 +02001/*
2 * Virtio video device
3 *
4 * Copyright Red Hat
5 *
6 * Authors:
7 * Dave Airlie
8 *
Gerd Hoffmann2e252142015-09-16 09:15:15 +02009 * 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.
Gerd Hoffmann9eafb622014-09-10 14:20:34 +020011 *
12 */
13#include "hw/pci/pci.h"
14#include "hw/virtio/virtio.h"
15#include "hw/virtio/virtio-bus.h"
16#include "hw/virtio/virtio-pci.h"
17#include "hw/virtio/virtio-gpu.h"
18
19static Property virtio_gpu_pci_properties[] = {
Gerd Hoffmann9eafb622014-09-10 14:20:34 +020020 DEFINE_VIRTIO_GPU_PCI_PROPERTIES(VirtIOPCIProxy),
21 DEFINE_PROP_END_OF_LIST(),
22};
23
24static void virtio_gpu_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
25{
26 VirtIOGPUPCI *vgpu = VIRTIO_GPU_PCI(vpci_dev);
Gerd Hoffmanne1888292015-06-24 12:19:42 +020027 VirtIOGPU *g = &vgpu->vdev;
Gerd Hoffmann9eafb622014-09-10 14:20:34 +020028 DeviceState *vdev = DEVICE(&vgpu->vdev);
Gerd Hoffmanne1888292015-06-24 12:19:42 +020029 int i;
Gerd Hoffmann9eafb622014-09-10 14:20:34 +020030
31 qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus));
32 /* force virtio-1.0 */
33 vpci_dev->flags &= ~VIRTIO_PCI_FLAG_DISABLE_MODERN;
34 vpci_dev->flags |= VIRTIO_PCI_FLAG_DISABLE_LEGACY;
35 object_property_set_bool(OBJECT(vdev), true, "realized", errp);
Gerd Hoffmanne1888292015-06-24 12:19:42 +020036
37 for (i = 0; i < g->conf.max_outputs; i++) {
38 object_property_set_link(OBJECT(g->scanout[i].con),
39 OBJECT(vpci_dev),
40 "device", errp);
41 }
Gerd Hoffmann9eafb622014-09-10 14:20:34 +020042}
43
44static void virtio_gpu_pci_class_init(ObjectClass *klass, void *data)
45{
46 DeviceClass *dc = DEVICE_CLASS(klass);
47 VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
48 PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
49
50 set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories);
51 dc->props = virtio_gpu_pci_properties;
52 k->realize = virtio_gpu_pci_realize;
53 pcidev_k->class_id = PCI_CLASS_DISPLAY_OTHER;
54}
55
56static void virtio_gpu_initfn(Object *obj)
57{
58 VirtIOGPUPCI *dev = VIRTIO_GPU_PCI(obj);
Gerd Hoffmannb3409a32015-06-24 12:22:09 +020059
60 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
61 TYPE_VIRTIO_GPU);
Gerd Hoffmann9eafb622014-09-10 14:20:34 +020062}
63
64static const TypeInfo virtio_gpu_pci_info = {
65 .name = TYPE_VIRTIO_GPU_PCI,
66 .parent = TYPE_VIRTIO_PCI,
67 .instance_size = sizeof(VirtIOGPUPCI),
68 .instance_init = virtio_gpu_initfn,
69 .class_init = virtio_gpu_pci_class_init,
70};
71
72static void virtio_gpu_pci_register_types(void)
73{
74 type_register_static(&virtio_gpu_pci_info);
75}
76type_init(virtio_gpu_pci_register_types)