[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 25/27] virtio-snd: Add tx vq and handler
From: |
Shreyansh Chouhan |
Subject: |
[RFC PATCH 25/27] virtio-snd: Add tx vq and handler |
Date: |
Thu, 29 Apr 2021 17:34:43 +0530 |
The handler demultiplexes the buffers recieved in the
tx virtqueue. It uses a helper function for adding these
buffers, (along with the entire virtqueue element,) to
their respective streams.
Signed-off-by: Shreyansh Chouhan <chouhan.shreyansh2702@gmail.com>
---
hw/audio/virtio-snd.c | 62 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 62 insertions(+)
diff --git a/hw/audio/virtio-snd.c b/hw/audio/virtio-snd.c
index e2e47e9467..be9ea05e3f 100644
--- a/hw/audio/virtio-snd.c
+++ b/hw/audio/virtio-snd.c
@@ -925,6 +925,66 @@ static void virtio_snd_handle_ctrl(VirtIODevice *vdev,
VirtQueue *vq)
}
}
+/*
+ * Adds a virtqueue element to a VirtIOSound card stream. Makes the buffer
+ * available to the stream for consumption.
+ *
+ * @s: VirtIOSound card
+ * @stream: stream id
+ * @elem: The tx virtqueue element that contains the I/O message
+ */
+static void virtio_snd_pcm_add_buf(VirtIOSound *s, uint32_t stream,
+ VirtQueueElement *elem)
+{
+ virtio_snd_pcm_stream *st = virtio_snd_pcm_get_stream(s, stream);
+ int nelems = virtio_snd_pcm_get_nelems(st);
+ st->tail++;
+ st->tail %= nelems;
+
+ if (st->elems[st->tail]) {
+ return;
+ }
+
+ st->elems[st->tail] = elem;
+ st->r_pos += iov_size(elem->out_sg, elem->out_num)
+ - sizeof(virtio_snd_pcm_xfer);
+ st->r_pos %= st->buffer_bytes + 1;
+}
+
+/*
+ * The tx virtqueue handler. Makes the buffers available to their respective
+ * streams for consumption.
+ *
+ * @vdev: VirtIOSound card
+ * @vq: tx virtqueue
+ */
+static void virtio_snd_handle_tx(VirtIODevice *vdev, VirtQueue *vq)
+{
+ VirtIOSound *s = VIRTIO_SOUND(vdev);
+ VirtQueueElement *elem;
+ size_t sz;
+ virtio_snd_pcm_xfer hdr;
+
+ for (;;) {
+ elem = virtqueue_pop(vq, sizeof(VirtQueueElement));
+ if (!elem) {
+ break;
+ }
+ if (iov_size(elem->in_sg, elem->in_num) <
sizeof(virtio_snd_pcm_status) ||
+ iov_size(elem->out_sg, elem->out_num) <
sizeof(virtio_snd_pcm_xfer)) {
+ virtqueue_detach_element(vq, elem, 0);
+ g_free(elem);
+ break;
+ }
+
+ /* get the message hdr object */
+ sz = iov_to_buf(elem->out_sg, elem->out_num, 0, &hdr, sizeof(hdr));
+ assert(sz == sizeof(virtio_snd_pcm_xfer));
+
+ virtio_snd_pcm_add_buf(s, hdr.stream_id, elem);
+ }
+}
+
/*
* Initializes the VirtIOSound card device. Validates the configuration
* passed by the command line. Initializes the virtqueues. Allocates resources
@@ -969,6 +1029,7 @@ static void virtio_snd_device_realize(DeviceState *dev,
Error **errp)
default_params.rate = VIRTIO_SND_PCM_RATE_44100;
s->ctrl_vq = virtio_add_queue(vdev, 64, virtio_snd_handle_ctrl);
+ s->tx_vq = virtio_add_queue(vdev, 64, virtio_snd_handle_tx);
s->streams = g_new0(virtio_snd_pcm_stream *, s->snd_conf.streams);
s->pcm_params = g_new0(virtio_snd_pcm_params *, s->snd_conf.streams);
@@ -1034,6 +1095,7 @@ static void virtio_snd_device_unrealize(DeviceState *dev)
s->jacks = NULL;
virtio_delete_queue(s->ctrl_vq);
+ virtio_delete_queue(s->tx_vq);
}
static void virtio_snd_reset(VirtIODevice *vdev)
--
2.25.1
- [RFC PATCH 14/27] virtio-snd: Add stub for VIRTIO_SND_R_JACK_REMAP handler, (continued)
- [RFC PATCH 14/27] virtio-snd: Add stub for VIRTIO_SND_R_JACK_REMAP handler, Shreyansh Chouhan, 2021/04/29
- [RFC PATCH 18/27] virtio-snd: Add default configs to realize fn, Shreyansh Chouhan, 2021/04/29
- [RFC PATCH 16/27] virtio-snd: Add VIRITO_SND_R_PCM_SET_PARAMS handle, Shreyansh Chouhan, 2021/04/29
- [RFC PATCH 21/27] virtio-snd: Add VIRTIO_SND_R_PCM_STOP handler, Shreyansh Chouhan, 2021/04/29
- [RFC PATCH 20/27] virtio-snd: Add VIRITO_SND_R_PCM_START handler, Shreyansh Chouhan, 2021/04/29
- [RFC PATCH 17/27] virtio-snd: Add VIRTIO_SND_R_PCM_PREPARE handler, Shreyansh Chouhan, 2021/04/29
- [RFC PATCH 19/27] virtio-snd: Add callback for SWVoiceOut, Shreyansh Chouhan, 2021/04/29
- [RFC PATCH 23/27] virtio-snd: Replaced goto with if else, Shreyansh Chouhan, 2021/04/29
- [RFC PATCH 22/27] virtio-snd: Add VIRTIO_SND_R_PCM_RELEASE handler, Shreyansh Chouhan, 2021/04/29
- [RFC PATCH 25/27] virtio-snd: Add tx vq and handler,
Shreyansh Chouhan <=
- [RFC PATCH 24/27] virtio-snd: Add code to device unrealize function, Shreyansh Chouhan, 2021/04/29
- [RFC PATCH 27/27] virtio-snd: Add rx vq and stub handler, Shreyansh Chouhan, 2021/04/29
- [RFC PATCH 26/27] virtio-snd: Add event vq and a handler stub, Shreyansh Chouhan, 2021/04/29
- Re: [RFC PATCH 00/27] Virtio sound card implementation, no-reply, 2021/04/29
- Re: [RFC PATCH 00/27] Virtio sound card implementation, Gerd Hoffmann, 2021/04/30