Added the virito-snd.c file which contains a wrapper for combining the device with the VirtIOPCIProxy.
Signed-off-by: Shreyansh Chouhan <chouhan.shreyansh2...@gmail.com> --- hw/virtio/meson.build | 1 + hw/virtio/virtio-snd-pci.c | 72 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 hw/virtio/virtio-snd-pci.c diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build index 521f7d64a8..86d6594c20 100644 --- a/hw/virtio/meson.build +++ b/hw/virtio/meson.build @@ -49,6 +49,7 @@ virtio_pci_ss.add(when: 'CONFIG_VIRTIO_SERIAL', if_true: files('virtio-serial-pc virtio_pci_ss.add(when: 'CONFIG_VIRTIO_PMEM', if_true: files('virtio-pmem-pci.c')) virtio_pci_ss.add(when: 'CONFIG_VIRTIO_IOMMU', if_true: files('virtio-iommu-pci.c')) virtio_pci_ss.add(when: 'CONFIG_VIRTIO_MEM', if_true: files('virtio-mem-pci.c')) +virtio_pci_ss.add(when: 'CONFIG_VIRTIO_SND', if_true: files('virtio-snd-pci.c')) virtio_ss.add_all(when: 'CONFIG_VIRTIO_PCI', if_true: virtio_pci_ss) diff --git a/hw/virtio/virtio-snd-pci.c b/hw/virtio/virtio-snd-pci.c new file mode 100644 index 0000000000..8d8e4ffa51 --- /dev/null +++ b/hw/virtio/virtio-snd-pci.c @@ -0,0 +1,72 @@ +/* + * Virtio sound PCI Bindings + */ + +#include "qemu/osdep.h" +#include "hw/virtio/virtio-snd.h" +#include "hw/virtio/virtio-pci.h" +#include "qapi/error.h" +#include "qemu/module.h" +#include "qom/object.h" + +typedef struct VirtIOSoundPCI VirtIOSoundPCI; + +/* + * virtio-snd-pci: This extends VirtioPCIProxy. + */ +#define TYPE_VIRTIO_SOUND_PCI "virtio-sound-pci-base" +DECLARE_INSTANCE_CHECKER(VirtIOSoundPCI, VIRTIO_SOUND_PCI, + TYPE_VIRTIO_SOUND_PCI) + +struct VirtIOSoundPCI { + VirtIOPCIProxy parent_obj; + VirtIOSound vdev; +}; + +static Property virtio_sound_properties[] = { + DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, + VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true), + DEFINE_PROP_END_OF_LIST(), +}; + +static void virtio_snd_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) +{ + VirtIOSoundPCI *dev = VIRTIO_SOUND_PCI(vpci_dev); + DeviceState *vdev = DEVICE(&dev->vdev); + + qdev_realize(vdev, BUS(&vpci_dev->bus), errp); +} + +static void virtio_snd_pci_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); + VirtioPCIClass *vpciklass = VIRTIO_PCI_CLASS(klass); + + k->class_id = PCI_CLASS_MULTIMEDIA_AUDIO; + set_bit(DEVICE_CATEGORY_SOUND, dc->categories); + device_class_set_props(dc, virtio_sound_properties); + vpciklass->realize = virtio_snd_pci_realize; +} + +static void virtio_snd_pci_instance_init(Object *obj) +{ + VirtIOSoundPCI *dev = VIRTIO_SOUND_PCI(obj); + virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), + TYPE_VIRTIO_SOUND); +} + +static const VirtioPCIDeviceTypeInfo virtio_snd_pci_info = { + .base_name = TYPE_VIRTIO_SOUND_PCI, + .generic_name = "virtio-snd-pci", + .instance_size = sizeof(VirtIOSoundPCI), + .instance_init = virtio_snd_pci_instance_init, + .class_init = virtio_snd_pci_class_init, +}; + +static void virtio_snd_pci_register(void) +{ + virtio_pci_types_register(&virtio_snd_pci_info); +} + +type_init(virtio_snd_pci_register); -- 2.31.1