| 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 | #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 | { |
| 38 | VirtIOSoundPCI *dev = VIRTIO_SND_PCI(vpci_dev); |
| 39 | DeviceState *vdev = DEVICE(&dev->vdev); |
| 40 | |
| 41 | virtio_pci_force_virtio_1(vpci_dev); |
| 42 | qdev_realize(vdev, BUS(&vpci_dev->bus), errp); |
| 43 | } |
| 44 | |
| 45 | static void virtio_snd_pci_class_init(ObjectClass *klass, const void *data) |
| 46 | { |
| 47 | DeviceClass *dc = DEVICE_CLASS(klass); |
| 48 | VirtioPCIClass *vpciklass = VIRTIO_PCI_CLASS(klass); |
| 49 | PCIDeviceClass *pcidevklass = PCI_DEVICE_CLASS(klass); |
| 50 | |
| 51 | device_class_set_props(dc, virtio_snd_pci_properties); |
| 52 | dc->desc = "Virtio Sound"; |
| 53 | set_bit(DEVICE_CATEGORY_SOUND, dc->categories); |
| 54 | |
| 55 | vpciklass->realize = virtio_snd_pci_realize; |
| 56 | pcidevklass->class_id = PCI_CLASS_MULTIMEDIA_AUDIO; |
| 57 | } |
| 58 | |
| 59 | static void virtio_snd_pci_instance_init(Object *obj) |
| 60 | { |
| 61 | VirtIOSoundPCI *dev = VIRTIO_SND_PCI(obj); |
| 62 | |
| 63 | virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), |
| 64 | TYPE_VIRTIO_SND); |
| 65 | } |
| 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 | { |
| 76 | virtio_pci_types_register(&virtio_snd_pci_info); |
| 77 | audio_register_model("virtio", "Virtio Sound", TYPE_VIRTIO_SND_PCI); |
| 78 | } |
| 79 | |
| 80 | type_init(virtio_snd_pci_register); |