/src/qemu/hw/audio/virtio-snd-pci.c
Line | Count | Source |
1 | | /* |
2 | | * VIRTIO Sound Device PCI Bindings |
3 | | * |
4 | | * Copyright (c) 2023 Emmanouil Pitsidianakis <manos.pitsidianakis@linaro.org> |
5 | | * |
6 | | * This work is licensed under the terms of the GNU GPL, version 2 or |
7 | | * (at your option) any later version. See the COPYING file in the |
8 | | * top-level directory. |
9 | | */ |
10 | | |
11 | | #include "qemu/osdep.h" |
12 | | #include "qom/object.h" |
13 | | #include "qapi/error.h" |
14 | | #include "hw/audio/model.h" |
15 | | #include "hw/virtio/virtio-pci.h" |
16 | | #include "hw/audio/virtio-snd.h" |
17 | | |
18 | | /* |
19 | | * virtio-snd-pci: This extends VirtioPCIProxy. |
20 | | */ |
21 | 61 | #define TYPE_VIRTIO_SND_PCI "virtio-sound-pci" |
22 | | OBJECT_DECLARE_SIMPLE_TYPE(VirtIOSoundPCI, VIRTIO_SND_PCI) |
23 | | |
24 | | struct VirtIOSoundPCI { |
25 | | VirtIOPCIProxy parent_obj; |
26 | | |
27 | | VirtIOSound vdev; |
28 | | }; |
29 | | |
30 | | static const Property virtio_snd_pci_properties[] = { |
31 | | DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, |
32 | | VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true), |
33 | | DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2), |
34 | | }; |
35 | | |
36 | | static void virtio_snd_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) |
37 | 0 | { |
38 | 0 | VirtIOSoundPCI *dev = VIRTIO_SND_PCI(vpci_dev); |
39 | 0 | DeviceState *vdev = DEVICE(&dev->vdev); |
40 | |
|
41 | 0 | virtio_pci_force_virtio_1(vpci_dev); |
42 | 0 | qdev_realize(vdev, BUS(&vpci_dev->bus), errp); |
43 | 0 | } |
44 | | |
45 | | static void virtio_snd_pci_class_init(ObjectClass *klass, const void *data) |
46 | 61 | { |
47 | 61 | DeviceClass *dc = DEVICE_CLASS(klass); |
48 | 61 | VirtioPCIClass *vpciklass = VIRTIO_PCI_CLASS(klass); |
49 | 61 | PCIDeviceClass *pcidevklass = PCI_DEVICE_CLASS(klass); |
50 | | |
51 | 61 | device_class_set_props(dc, virtio_snd_pci_properties); |
52 | 61 | dc->desc = "Virtio Sound"; |
53 | 61 | set_bit(DEVICE_CATEGORY_SOUND, dc->categories); |
54 | | |
55 | 61 | vpciklass->realize = virtio_snd_pci_realize; |
56 | 61 | pcidevklass->class_id = PCI_CLASS_MULTIMEDIA_AUDIO; |
57 | 61 | } |
58 | | |
59 | | static void virtio_snd_pci_instance_init(Object *obj) |
60 | 0 | { |
61 | 0 | VirtIOSoundPCI *dev = VIRTIO_SND_PCI(obj); |
62 | |
|
63 | 0 | virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), |
64 | 0 | TYPE_VIRTIO_SND); |
65 | 0 | } |
66 | | |
67 | | static const VirtioPCIDeviceTypeInfo virtio_snd_pci_info = { |
68 | | .generic_name = TYPE_VIRTIO_SND_PCI, |
69 | | .instance_size = sizeof(VirtIOSoundPCI), |
70 | | .instance_init = virtio_snd_pci_instance_init, |
71 | | .class_init = virtio_snd_pci_class_init, |
72 | | }; |
73 | | |
74 | | static void virtio_snd_pci_register(void) |
75 | 61 | { |
76 | 61 | virtio_pci_types_register(&virtio_snd_pci_info); |
77 | 61 | audio_register_model("virtio", "Virtio Sound", TYPE_VIRTIO_SND_PCI); |
78 | 61 | } |
79 | | |
80 | | type_init(virtio_snd_pci_register); |