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 #include "qemu/osdep.h" 14 #include "hw/pci/pci.h" 15 #include "hw/virtio/virtio.h" 16 #include "hw/virtio/virtio-bus.h" 17 #include "hw/virtio/virtio-pci.h" 18 #include "hw/virtio/virtio-gpu.h" 19 20 static Property virtio_gpu_pci_properties[] = { 21 DEFINE_VIRTIO_GPU_PCI_PROPERTIES(VirtIOPCIProxy), 22 DEFINE_PROP_END_OF_LIST(), 23 }; 24 25 static void virtio_gpu_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) 26 { 27 VirtIOGPUPCI *vgpu = VIRTIO_GPU_PCI(vpci_dev); 28 VirtIOGPU *g = &vgpu->vdev; 29 DeviceState *vdev = DEVICE(&vgpu->vdev); 30 int i; 31 Error *local_error = NULL; 32 33 qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)); 34 virtio_pci_force_virtio_1(vpci_dev); 35 object_property_set_bool(OBJECT(vdev), true, "realized", &local_error); 36 37 if (local_error) { 38 error_propagate(errp, local_error); 39 return; 40 } 41 42 for (i = 0; i < g->conf.max_outputs; i++) { 43 object_property_set_link(OBJECT(g->scanout[i].con), 44 OBJECT(vpci_dev), 45 "device", errp); 46 } 47 } 48 49 static void virtio_gpu_pci_class_init(ObjectClass *klass, void *data) 50 { 51 DeviceClass *dc = DEVICE_CLASS(klass); 52 VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass); 53 PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass); 54 55 set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories); 56 dc->props = virtio_gpu_pci_properties; 57 dc->hotpluggable = false; 58 k->realize = virtio_gpu_pci_realize; 59 pcidev_k->class_id = PCI_CLASS_DISPLAY_OTHER; 60 } 61 62 static void virtio_gpu_initfn(Object *obj) 63 { 64 VirtIOGPUPCI *dev = VIRTIO_GPU_PCI(obj); 65 66 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), 67 TYPE_VIRTIO_GPU); 68 } 69 70 static const TypeInfo virtio_gpu_pci_info = { 71 .name = TYPE_VIRTIO_GPU_PCI, 72 .parent = TYPE_VIRTIO_PCI, 73 .instance_size = sizeof(VirtIOGPUPCI), 74 .instance_init = virtio_gpu_initfn, 75 .class_init = virtio_gpu_pci_class_init, 76 }; 77 78 static void virtio_gpu_pci_register_types(void) 79 { 80 type_register_static(&virtio_gpu_pci_info); 81 } 82 type_init(virtio_gpu_pci_register_types) 83