Skip to content

Commit

Permalink
ALSA: virtio: build PCM devices and substream hardware descriptors
Browse files Browse the repository at this point in the history
Like the HDA specification, the virtio sound device specification links
PCM substreams, jacks and PCM channel maps into functional groups. For
each discovered group, a PCM device is created, the number of which
coincides with the group number.

Introduce the module parameters for setting the hardware buffer
parameters:
  pcm_buffer_ms [=160]
  pcm_periods_min [=2]
  pcm_periods_max [=16]
  pcm_period_ms_min [=10]
  pcm_period_ms_max [=80]

Signed-off-by: Anton Yakovlev <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Takashi Iwai <[email protected]>
  • Loading branch information
heneko-de authored and tiwai committed Mar 7, 2021
1 parent 9d45e51 commit 29b96bf
Show file tree
Hide file tree
Showing 5 changed files with 581 additions and 1 deletion.
3 changes: 2 additions & 1 deletion sound/virtio/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ obj-$(CONFIG_SND_VIRTIO) += virtio_snd.o

virtio_snd-objs := \
virtio_card.o \
virtio_ctl_msg.o
virtio_ctl_msg.o \
virtio_pcm.o

18 changes: 18 additions & 0 deletions sound/virtio/virtio_card.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,16 @@ static int virtsnd_build_devs(struct virtio_snd *snd)
VIRTIO_SND_CARD_NAME " at %s/%s",
dev_name(dev->parent), dev_name(dev));

rc = virtsnd_pcm_parse_cfg(snd);
if (rc)
return rc;

if (snd->nsubstreams) {
rc = virtsnd_pcm_build_devs(snd);
if (rc)
return rc;
}

return snd_card_register(snd->card);
}

Expand Down Expand Up @@ -237,6 +247,9 @@ static int virtsnd_validate(struct virtio_device *vdev)
return -EINVAL;
}

if (virtsnd_pcm_validate(vdev))
return -EINVAL;

return 0;
}

Expand All @@ -259,6 +272,7 @@ static int virtsnd_probe(struct virtio_device *vdev)

snd->vdev = vdev;
INIT_LIST_HEAD(&snd->ctl_msgs);
INIT_LIST_HEAD(&snd->pcm_list);

vdev->priv = snd;

Expand Down Expand Up @@ -293,6 +307,7 @@ static int virtsnd_probe(struct virtio_device *vdev)
static void virtsnd_remove(struct virtio_device *vdev)
{
struct virtio_snd *snd = vdev->priv;
unsigned int i;

virtsnd_disable_event_vq(snd);
virtsnd_ctl_msg_cancel_all(snd);
Expand All @@ -303,6 +318,9 @@ static void virtsnd_remove(struct virtio_device *vdev)
vdev->config->del_vqs(vdev);
vdev->config->reset(vdev);

for (i = 0; snd->substreams && i < snd->nsubstreams; ++i)
cancel_work_sync(&snd->substreams[i].elapsed_period);

kfree(snd->event_msgs);
}

Expand Down
10 changes: 10 additions & 0 deletions sound/virtio/virtio_card.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@
#include <uapi/linux/virtio_snd.h>

#include "virtio_ctl_msg.h"
#include "virtio_pcm.h"

#define VIRTIO_SND_CARD_DRIVER "virtio-snd"
#define VIRTIO_SND_CARD_NAME "VirtIO SoundCard"
#define VIRTIO_SND_PCM_NAME "VirtIO PCM"

struct virtio_pcm_substream;

/**
* struct virtio_snd_queue - Virtqueue wrapper structure.
Expand All @@ -33,13 +37,19 @@ struct virtio_snd_queue {
* @card: ALSA sound card.
* @ctl_msgs: Pending control request list.
* @event_msgs: Device events.
* @pcm_list: VirtIO PCM device list.
* @substreams: VirtIO PCM substreams.
* @nsubstreams: Number of PCM substreams.
*/
struct virtio_snd {
struct virtio_device *vdev;
struct virtio_snd_queue queues[VIRTIO_SND_VQ_MAX];
struct snd_card *card;
struct list_head ctl_msgs;
struct virtio_snd_event *event_msgs;
struct list_head pcm_list;
struct virtio_pcm_substream *substreams;
u32 nsubstreams;
};

/* Message completion timeout in milliseconds (module parameter). */
Expand Down
Loading

0 comments on commit 29b96bf

Please sign in to comment.