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 typedef struct VirtIOGPUPCI VirtIOGPUPCI; 23 24 /* 25 * virtio-gpu-pci: This extends VirtioPCIProxy. 26 */ 27 #define TYPE_VIRTIO_GPU_PCI "virtio-gpu-pci" 28 #define VIRTIO_GPU_PCI(obj) \ 29 OBJECT_CHECK(VirtIOGPUPCI, (obj), TYPE_VIRTIO_GPU_PCI) 30 31 struct VirtIOGPUPCI { 32 VirtIOPCIProxy parent_obj; 33 VirtIOGPU vdev; 34 }; 35 36 static Property virtio_gpu_pci_properties[] = { 37 DEFINE_VIRTIO_GPU_PCI_PROPERTIES(VirtIOPCIProxy), 38 DEFINE_PROP_END_OF_LIST(), 39 }; 40 41 static void virtio_gpu_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) 42 { 43 VirtIOGPUPCI *vgpu = VIRTIO_GPU_PCI(vpci_dev); 44 VirtIOGPU *g = &vgpu->vdev; 45 DeviceState *vdev = DEVICE(&vgpu->vdev); 46 int i; 47 Error *local_error = NULL; 48 49 qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)); 50 if (!virtio_pci_force_virtio_1(vpci_dev, errp)) { 51 return; 52 } 53 object_property_set_bool(OBJECT(vdev), true, "realized", &local_error); 54 55 if (local_error) { 56 error_propagate(errp, local_error); 57 return; 58 } 59 60 for (i = 0; i < g->conf.max_outputs; i++) { 61 object_property_set_link(OBJECT(g->scanout[i].con), 62 OBJECT(vpci_dev), 63 "device", errp); 64 } 65 } 66 67 static void virtio_gpu_pci_class_init(ObjectClass *klass, void *data) 68 { 69 DeviceClass *dc = DEVICE_CLASS(klass); 70 VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass); 71 PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass); 72 73 set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories); 74 dc->props = virtio_gpu_pci_properties; 75 dc->hotpluggable = false; 76 k->realize = virtio_gpu_pci_realize; 77 pcidev_k->class_id = PCI_CLASS_DISPLAY_OTHER; 78 } 79 80 static void virtio_gpu_initfn(Object *obj) 81 { 82 VirtIOGPUPCI *dev = VIRTIO_GPU_PCI(obj); 83 84 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), 85 TYPE_VIRTIO_GPU); 86 } 87 88 static const VirtioPCIDeviceTypeInfo virtio_gpu_pci_info = { 89 .generic_name = TYPE_VIRTIO_GPU_PCI, 90 .instance_size = sizeof(VirtIOGPUPCI), 91 .instance_init = virtio_gpu_initfn, 92 .class_init = virtio_gpu_pci_class_init, 93 }; 94 95 static void virtio_gpu_pci_register_types(void) 96 { 97 virtio_pci_types_register(&virtio_gpu_pci_info); 98 } 99 type_init(virtio_gpu_pci_register_types) 100