// SPDX-License-Identifier: GPL-2.0+ /* * virtio-snd: Virtio sound device * Copyright (C) 2021 OpenSynergy GmbH */ #include <linux/moduleparam.h> #include <linux/virtio_config.h> #include "virtio_card.h" static u32 pcm_buffer_ms = …; module_param(pcm_buffer_ms, uint, 0644); MODULE_PARM_DESC(…) …; static u32 pcm_periods_min = …; module_param(pcm_periods_min, uint, 0644); MODULE_PARM_DESC(…) …; static u32 pcm_periods_max = …; module_param(pcm_periods_max, uint, 0644); MODULE_PARM_DESC(…) …; static u32 pcm_period_ms_min = …; module_param(pcm_period_ms_min, uint, 0644); MODULE_PARM_DESC(…) …; static u32 pcm_period_ms_max = …; module_param(pcm_period_ms_max, uint, 0644); MODULE_PARM_DESC(…) …; /* Map for converting VirtIO format to ALSA format. */ static const snd_pcm_format_t g_v2a_format_map[] = …; /* Map for converting VirtIO frame rate to ALSA frame rate. */ struct virtsnd_v2a_rate { … }; static const struct virtsnd_v2a_rate g_v2a_rate_map[] = …; /** * virtsnd_pcm_build_hw() - Parse substream config and build HW descriptor. * @vss: VirtIO substream. * @info: VirtIO substream information entry. * * Context: Any context. * Return: 0 on success, -EINVAL if configuration is invalid. */ static int virtsnd_pcm_build_hw(struct virtio_pcm_substream *vss, struct virtio_snd_pcm_info *info) { … } /** * virtsnd_pcm_find() - Find the PCM device for the specified node ID. * @snd: VirtIO sound device. * @nid: Function node ID. * * Context: Any context. * Return: a pointer to the PCM device or ERR_PTR(-ENOENT). */ struct virtio_pcm *virtsnd_pcm_find(struct virtio_snd *snd, u32 nid) { … } /** * virtsnd_pcm_find_or_create() - Find or create the PCM device for the * specified node ID. * @snd: VirtIO sound device. * @nid: Function node ID. * * Context: Any context that permits to sleep. * Return: a pointer to the PCM device or ERR_PTR(-errno). */ struct virtio_pcm *virtsnd_pcm_find_or_create(struct virtio_snd *snd, u32 nid) { … } /** * virtsnd_pcm_validate() - Validate if the device can be started. * @vdev: VirtIO parent device. * * Context: Any context. * Return: 0 on success, -EINVAL on failure. */ int virtsnd_pcm_validate(struct virtio_device *vdev) { … } /** * virtsnd_pcm_period_elapsed() - Kernel work function to handle the elapsed * period state. * @work: Elapsed period work. * * The main purpose of this function is to call snd_pcm_period_elapsed() in * a process context, not in an interrupt context. This is necessary because PCM * devices operate in non-atomic mode. * * Context: Process context. */ static void virtsnd_pcm_period_elapsed(struct work_struct *work) { … } /** * virtsnd_pcm_parse_cfg() - Parse the stream configuration. * @snd: VirtIO sound device. * * This function is called during initial device initialization. * * Context: Any context that permits to sleep. * Return: 0 on success, -errno on failure. */ int virtsnd_pcm_parse_cfg(struct virtio_snd *snd) { … } /** * virtsnd_pcm_build_devs() - Build ALSA PCM devices. * @snd: VirtIO sound device. * * Context: Any context that permits to sleep. * Return: 0 on success, -errno on failure. */ int virtsnd_pcm_build_devs(struct virtio_snd *snd) { … } /** * 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) { … }