virtio-gpu-pci.c (2919B)
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 "qemu/module.h" 17#include "hw/pci/pci.h" 18#include "hw/qdev-properties.h" 19#include "hw/virtio/virtio.h" 20#include "hw/virtio/virtio-bus.h" 21#include "hw/virtio/virtio-gpu-pci.h" 22#include "qom/object.h" 23 24static Property virtio_gpu_pci_base_properties[] = { 25 DEFINE_VIRTIO_GPU_PCI_PROPERTIES(VirtIOPCIProxy), 26 DEFINE_PROP_END_OF_LIST(), 27}; 28 29static void virtio_gpu_pci_base_realize(VirtIOPCIProxy *vpci_dev, Error **errp) 30{ 31 VirtIOGPUPCIBase *vgpu = VIRTIO_GPU_PCI_BASE(vpci_dev); 32 VirtIOGPUBase *g = vgpu->vgpu; 33 DeviceState *vdev = DEVICE(g); 34 int i; 35 36 virtio_pci_force_virtio_1(vpci_dev); 37 if (!qdev_realize(vdev, BUS(&vpci_dev->bus), errp)) { 38 return; 39 } 40 41 for (i = 0; i < g->conf.max_outputs; i++) { 42 object_property_set_link(OBJECT(g->scanout[i].con), "device", 43 OBJECT(vpci_dev), &error_abort); 44 } 45} 46 47static void virtio_gpu_pci_base_class_init(ObjectClass *klass, void *data) 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); 54 device_class_set_props(dc, virtio_gpu_pci_base_properties); 55 dc->hotpluggable = false; 56 k->realize = virtio_gpu_pci_base_realize; 57 pcidev_k->class_id = PCI_CLASS_DISPLAY_OTHER; 58} 59 60static 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}; 67module_obj(TYPE_VIRTIO_GPU_PCI_BASE); 68 69#define TYPE_VIRTIO_GPU_PCI "virtio-gpu-pci" 70typedef struct VirtIOGPUPCI VirtIOGPUPCI; 71DECLARE_INSTANCE_CHECKER(VirtIOGPUPCI, VIRTIO_GPU_PCI, 72 TYPE_VIRTIO_GPU_PCI) 73 74struct VirtIOGPUPCI { 75 VirtIOGPUPCIBase parent_obj; 76 VirtIOGPU vdev; 77}; 78 79static void virtio_gpu_initfn(Object *obj) 80{ 81 VirtIOGPUPCI *dev = VIRTIO_GPU_PCI(obj); 82 83 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), 84 TYPE_VIRTIO_GPU); 85 VIRTIO_GPU_PCI_BASE(obj)->vgpu = VIRTIO_GPU_BASE(&dev->vdev); 86} 87 88static const VirtioPCIDeviceTypeInfo virtio_gpu_pci_info = { 89 .generic_name = TYPE_VIRTIO_GPU_PCI, 90 .parent = TYPE_VIRTIO_GPU_PCI_BASE, 91 .instance_size = sizeof(VirtIOGPUPCI), 92 .instance_init = virtio_gpu_initfn, 93}; 94module_obj(TYPE_VIRTIO_GPU_PCI); 95 96static void virtio_gpu_pci_register_types(void) 97{ 98 type_register_static(&virtio_gpu_pci_base_info); 99 virtio_pci_types_register(&virtio_gpu_pci_info); 100} 101 102type_init(virtio_gpu_pci_register_types)