This patch series adds an audio device implementing the recent virtio
sound spec (1.2) and a corresponding PCI wrapper device.
v9 can be found online at:
https://gitlab.com/epilys/qemu/-/tree/virtio-snd-v9
Ref 06e6b17186
Main differences with v8 patch series [^v8]
:
- Addressed [^v8] review comments.
- Add cpu_to_le32(_) and le32_to_cpu(_) conversions for messages from/to
the guest according to the virtio spec.
- Inlined some functions and types to reduce review complexity.
- Corrected the replies to IO messages; now both Playback and Capture
work correctly for me. (If you hear cracks in pulseaudio+guest, try
pipewire+guest).
Previously:
[^v8]:
https://lore.kernel.org/qemu-devel/cover.1693252037.git.manos.pitsidiana...@linaro.org/
[^v7]:
https://lore.kernel.org/qemu-devel/cover.1692731646.git.manos.pitsidiana...@linaro.org/
[^v6]:
https://lore.kernel.org/qemu-devel/cover.1692089917.git.manos.pitsidiana...@linaro.org/
[^v5]:
https://lore.kernel.org/qemu-devel/cover.1690626150.git.manos.pitsidiana...@linaro.org/
[^v4]:
https://lore.kernel.org/qemu-devel/cover.1689857559.git.manos.pitsidiana...@linaro.org/
[^v3]:
https://lore.kernel.org/qemu-devel/cover.1689692765.git.manos.pitsidiana...@linaro.org/
Emmanouil Pitsidianakis (12):
Add virtio-sound device stub
Add virtio-sound-pci device
virtio-sound: handle control messages and streams
virtio-sound: set PCM stream parameters
virtio-sound: handle VIRTIO_SND_R_PCM_INFO request
virtio-sound: handle VIRTIO_SND_R_PCM_{START,STOP}
virtio-sound: handle VIRTIO_SND_R_PCM_SET_PARAMS
virtio-sound: handle VIRTIO_SND_R_PCM_PREPARE
virtio-sound: handle VIRTIO_SND_R_PCM_RELEASE
virtio-sound: implement audio output (TX)
virtio-sound: implement audio capture (RX)
docs/system: add basic virtio-snd documentation
MAINTAINERS|6 +
docs/system/device-emulation.rst |1 +
docs/system/devices/virtio-snd.rst | 49 +
hw/virtio/Kconfig |5 +
hw/virtio/meson.build |2 +
hw/virtio/trace-events | 20 +
hw/virtio/virtio-snd-pci.c | 93 ++
hw/virtio/virtio-snd.c | 1339
include/hw/virtio/virtio-snd.h | 193
softmmu/qdev-monitor.c |1 +
10 files changed, 1709 insertions(+)
create mode 100644 docs/system/devices/virtio-snd.rst
create mode 100644 hw/virtio/virtio-snd-pci.c
create mode 100644 hw/virtio/virtio-snd.c
create mode 100644 include/hw/virtio/virtio-snd.h
Range-diff against v8:
1: 238de1757e ! 1: 5173e2c243 Add virtio-sound device stub
@@ hw/virtio/virtio-snd.c (new)
+#include "trace.h"
+#include "qapi/error.h"
+#include "hw/virtio/virtio-snd.h"
++#include "hw/core/cpu.h"
+
+#define VIRTIO_SOUND_VM_VERSION 1
+#define VIRTIO_SOUND_JACK_DEFAULT 0
@@ hw/virtio/virtio-snd.c (new)
+};
+
+static Property virtio_snd_properties[] = {
++DEFINE_AUDIO_PROPERTIES(VirtIOSound, card),
+DEFINE_PROP_UINT32("jacks", VirtIOSound, snd_conf.jacks,
+ VIRTIO_SOUND_JACK_DEFAULT),
+DEFINE_PROP_UINT32("streams", VirtIOSound, snd_conf.streams,
@@ hw/virtio/virtio-snd.c (new)
+VirtIOSound *vsnd = VIRTIO_SND(dev);
+
+qemu_del_vm_change_state_handler(vsnd->vmstate);
-+virtio_del_queue(vdev, 0);
-+
+trace_virtio_snd_unrealize(vsnd);
+
+AUD_remove_card(>card);
++virtio_delete_queue(vsnd->queues[VIRTIO_SND_VQ_CONTROL]);
++virtio_delete_queue(vsnd->queues[VIRTIO_SND_VQ_EVENT]);
++virtio_delete_queue(vsnd->queues[VIRTIO_SND_VQ_TX]);
++virtio_delete_queue(vsnd->queues[VIRTIO_SND_VQ_RX]);
+virtio_cleanup(vdev);
+}
+
@@ include/hw/virtio/virtio-snd.h (new)
+
+typedef struct VirtIOSound {
+VirtIODevice parent_obj;
++
+VirtQueue *queues[VIRTIO_SND_VQ_MAX];
+uint64_t features;
+QEMUSoundCard card;
2: 8de966a86b ! 2: d2fdd5852d Add virtio-sound-pci device
@@ hw/virtio/virtio-snd-pci.c (new)
+ */
+
+#include "qemu/osdep.h"
++#include "qom/object.h"
+#include "qapi/error.h"
+#include "hw/audio/soundhw.h"
+#include "hw/virtio/virtio-pci.h"
+#include "hw/virtio/virtio-snd.h"
+
-+typedef struct VirtIOSoundPCI VirtIOSoundPCI;
-+
+/*
+ * virtio-snd-pci: This extends VirtioPCIProxy.
+ */
+#define TYPE_VIRTIO_SND_PCI "virtio-sound-pci"
-+DECLARE_INSTANCE_CHECKER(VirtIOSoundPCI, VIRTIO_SND_PCI,
-+ TYPE_VIRTIO_SND_PCI)
++OBJECT_DECLARE_SIMPLE_TYPE(VirtIOSoundPCI, VIRTIO_SND_PCI)
+
+struct VirtIOSoundPCI {
-+VirtIOPCIProxy parent;
++VirtIOPCIProxy parent_obj;
++
+VirtIOSound vdev;
+};
+
+static Property virtio_snd_pci_properties[] = {
-+