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.
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"
23 static Property virtio_gpu_pci_base_properties
[] = {
24 DEFINE_VIRTIO_GPU_PCI_PROPERTIES(VirtIOPCIProxy
),
25 DEFINE_PROP_END_OF_LIST(),
28 static void virtio_gpu_pci_base_realize(VirtIOPCIProxy
*vpci_dev
, Error
**errp
)
30 VirtIOGPUPCIBase
*vgpu
= VIRTIO_GPU_PCI_BASE(vpci_dev
);
31 VirtIOGPUBase
*g
= vgpu
->vgpu
;
32 DeviceState
*vdev
= DEVICE(g
);
35 virtio_pci_force_virtio_1(vpci_dev
);
36 if (!qdev_realize(vdev
, BUS(&vpci_dev
->bus
), errp
)) {
40 for (i
= 0; i
< g
->conf
.max_outputs
; i
++) {
41 object_property_set_link(OBJECT(g
->scanout
[i
].con
), "device",
42 OBJECT(vpci_dev
), &error_abort
);
46 static void virtio_gpu_pci_base_class_init(ObjectClass
*klass
, void *data
)
48 DeviceClass
*dc
= DEVICE_CLASS(klass
);
49 VirtioPCIClass
*k
= VIRTIO_PCI_CLASS(klass
);
50 PCIDeviceClass
*pcidev_k
= PCI_DEVICE_CLASS(klass
);
52 set_bit(DEVICE_CATEGORY_DISPLAY
, dc
->categories
);
53 device_class_set_props(dc
, virtio_gpu_pci_base_properties
);
54 dc
->hotpluggable
= false;
55 k
->realize
= virtio_gpu_pci_base_realize
;
56 pcidev_k
->class_id
= PCI_CLASS_DISPLAY_OTHER
;
59 static const TypeInfo virtio_gpu_pci_base_info
= {
60 .name
= TYPE_VIRTIO_GPU_PCI_BASE
,
61 .parent
= TYPE_VIRTIO_PCI
,
62 .instance_size
= sizeof(VirtIOGPUPCIBase
),
63 .class_init
= virtio_gpu_pci_base_class_init
,
67 #define TYPE_VIRTIO_GPU_PCI "virtio-gpu-pci"
68 #define VIRTIO_GPU_PCI(obj) \
69 OBJECT_CHECK(VirtIOGPUPCI, (obj), TYPE_VIRTIO_GPU_PCI)
71 typedef struct VirtIOGPUPCI
{
72 VirtIOGPUPCIBase parent_obj
;
76 static void virtio_gpu_initfn(Object
*obj
)
78 VirtIOGPUPCI
*dev
= VIRTIO_GPU_PCI(obj
);
80 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
82 VIRTIO_GPU_PCI_BASE(obj
)->vgpu
= VIRTIO_GPU_BASE(&dev
->vdev
);
85 static const VirtioPCIDeviceTypeInfo virtio_gpu_pci_info
= {
86 .generic_name
= TYPE_VIRTIO_GPU_PCI
,
87 .parent
= TYPE_VIRTIO_GPU_PCI_BASE
,
88 .instance_size
= sizeof(VirtIOGPUPCI
),
89 .instance_init
= virtio_gpu_initfn
,
92 static void virtio_gpu_pci_register_types(void)
94 type_register_static(&virtio_gpu_pci_base_info
);
95 virtio_pci_types_register(&virtio_gpu_pci_info
);
98 type_init(virtio_gpu_pci_register_types
)