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 "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[] = { 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); 30 VirtIOGPU *g = &vgpu->vdev; 31 DeviceState *vdev = DEVICE(&vgpu->vdev); 32 int i; 33 Error *local_error = NULL; 34 35 qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)); 36 virtio_pci_force_virtio_1(vpci_dev); 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 } 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 } 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; 59 dc->hotpluggable = false; 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); 67 68 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), 69 TYPE_VIRTIO_GPU); 70 } 71 72 static const VirtioPCIDeviceTypeInfo virtio_gpu_pci_info = { 73 .generic_name = TYPE_VIRTIO_GPU_PCI, 74 .instance_size = sizeof(VirtIOGPUPCI), 75 .instance_init = virtio_gpu_initfn, 76 .class_init = virtio_gpu_pci_class_init, 77 }; 78 79 static void virtio_gpu_pci_register_types(void) 80 { 81 virtio_pci_types_register(&virtio_gpu_pci_info); 82 } 83 type_init(virtio_gpu_pci_register_types) 84