summaryrefslogtreecommitdiff
path: root/sound/virtio/virtio_pcm.c
diff options
context:
space:
mode:
authorAnton Yakovlev <anton.yakovlev@opensynergy.com>2021-03-02 17:47:05 +0100
committerTakashi Iwai <tiwai@suse.de>2021-03-07 09:07:44 +0100
commitf40a28679e0b7cb3a9cc6627a8dbb40961990f0a (patch)
treef3666982bba98fc53612b03b559b80206d6bd7c9 /sound/virtio/virtio_pcm.c
parent29b96bf50ba958eb5f097cdc3fbd4c1acf9547a2 (diff)
ALSA: virtio: handling control and I/O messages for the PCM device
The driver implements a message-based transport for I/O substream operations. Before the start of the substream, the hardware buffer is sliced into I/O messages, the number of which is equal to the current number of periods. The size of each message is equal to the current size of one period. I/O messages are organized in an ordered queue. The completion of the I/O message indicates an elapsed period (the only exception is the end of the stream for the capture substream). Upon completion, the message is automatically re-added to the end of the queue. Signed-off-by: Anton Yakovlev <anton.yakovlev@opensynergy.com> Link: https://lore.kernel.org/r/20210302164709.3142702-6-anton.yakovlev@opensynergy.com Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/virtio/virtio_pcm.c')
-rw-r--r--sound/virtio/virtio_pcm.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/sound/virtio/virtio_pcm.c b/sound/virtio/virtio_pcm.c
index e16567e2e214..2dcd763efa29 100644
--- a/sound/virtio/virtio_pcm.c
+++ b/sound/virtio/virtio_pcm.c
@@ -353,6 +353,8 @@ int virtsnd_pcm_parse_cfg(struct virtio_snd *snd)
vss->snd = snd;
vss->sid = i;
INIT_WORK(&vss->elapsed_period, virtsnd_pcm_period_elapsed);
+ init_waitqueue_head(&vss->msg_empty);
+ spin_lock_init(&vss->lock);
rc = virtsnd_pcm_build_hw(vss, &info[i]);
if (rc)
@@ -477,3 +479,33 @@ int virtsnd_pcm_build_devs(struct virtio_snd *snd)
return 0;
}
+
+/**
+ * virtsnd_pcm_event() - Handle the PCM device event notification.
+ * @snd: VirtIO sound device.
+ * @event: VirtIO sound event.
+ *
+ * Context: Interrupt context.
+ */
+void virtsnd_pcm_event(struct virtio_snd *snd, struct virtio_snd_event *event)
+{
+ struct virtio_pcm_substream *vss;
+ u32 sid = le32_to_cpu(event->data);
+
+ if (sid >= snd->nsubstreams)
+ return;
+
+ vss = &snd->substreams[sid];
+
+ switch (le32_to_cpu(event->hdr.code)) {
+ case VIRTIO_SND_EVT_PCM_PERIOD_ELAPSED:
+ /* TODO: deal with shmem elapsed period */
+ break;
+ case VIRTIO_SND_EVT_PCM_XRUN:
+ spin_lock(&vss->lock);
+ if (vss->xfer_enabled)
+ vss->xfer_xrun = true;
+ spin_unlock(&vss->lock);
+ break;
+ }
+}