1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * virtio-snd: Virtio sound device
4 * Copyright (C) 2021 OpenSynergy GmbH
6 #ifndef VIRTIO_SND_CARD_H
7 #define VIRTIO_SND_CARD_H
9 #include <linux/slab.h>
10 #include <linux/virtio.h>
11 #include <sound/core.h>
12 #include <uapi/linux/virtio_snd.h>
14 #include "virtio_ctl_msg.h"
15 #include "virtio_pcm.h"
17 #define VIRTIO_SND_CARD_DRIVER "virtio-snd"
18 #define VIRTIO_SND_CARD_NAME "VirtIO SoundCard"
19 #define VIRTIO_SND_PCM_NAME "VirtIO PCM"
22 struct virtio_pcm_substream;
25 * struct virtio_snd_queue - Virtqueue wrapper structure.
26 * @lock: Used to synchronize access to a virtqueue.
27 * @vqueue: Underlying virtqueue.
29 struct virtio_snd_queue {
31 struct virtqueue *vqueue;
35 * struct virtio_snd - VirtIO sound card device.
36 * @vdev: Underlying virtio device.
37 * @queues: Virtqueue wrappers.
38 * @card: ALSA sound card.
39 * @ctl_msgs: Pending control request list.
40 * @event_msgs: Device events.
41 * @pcm_list: VirtIO PCM device list.
42 * @jacks: VirtIO jacks.
43 * @njacks: Number of jacks.
44 * @substreams: VirtIO PCM substreams.
45 * @nsubstreams: Number of PCM substreams.
46 * @chmaps: VirtIO channel maps.
47 * @nchmaps: Number of channel maps.
50 struct virtio_device *vdev;
51 struct virtio_snd_queue queues[VIRTIO_SND_VQ_MAX];
52 struct snd_card *card;
53 struct list_head ctl_msgs;
54 struct virtio_snd_event *event_msgs;
55 struct list_head pcm_list;
56 struct virtio_jack *jacks;
58 struct virtio_pcm_substream *substreams;
60 struct virtio_snd_chmap_info *chmaps;
64 /* Message completion timeout in milliseconds (module parameter). */
65 extern u32 virtsnd_msg_timeout_ms;
67 static inline struct virtio_snd_queue *
68 virtsnd_control_queue(struct virtio_snd *snd)
70 return &snd->queues[VIRTIO_SND_VQ_CONTROL];
73 static inline struct virtio_snd_queue *
74 virtsnd_event_queue(struct virtio_snd *snd)
76 return &snd->queues[VIRTIO_SND_VQ_EVENT];
79 static inline struct virtio_snd_queue *
80 virtsnd_tx_queue(struct virtio_snd *snd)
82 return &snd->queues[VIRTIO_SND_VQ_TX];
85 static inline struct virtio_snd_queue *
86 virtsnd_rx_queue(struct virtio_snd *snd)
88 return &snd->queues[VIRTIO_SND_VQ_RX];
91 static inline struct virtio_snd_queue *
92 virtsnd_pcm_queue(struct virtio_pcm_substream *vss)
94 if (vss->direction == SNDRV_PCM_STREAM_PLAYBACK)
95 return virtsnd_tx_queue(vss->snd);
97 return virtsnd_rx_queue(vss->snd);
100 int virtsnd_jack_parse_cfg(struct virtio_snd *snd);
102 int virtsnd_jack_build_devs(struct virtio_snd *snd);
104 void virtsnd_jack_event(struct virtio_snd *snd,
105 struct virtio_snd_event *event);
107 int virtsnd_chmap_parse_cfg(struct virtio_snd *snd);
109 int virtsnd_chmap_build_devs(struct virtio_snd *snd);
111 #endif /* VIRTIO_SND_CARD_H */