xref: /openbmc/linux/sound/virtio/virtio_pcm.h (revision 29b96bf5)
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * virtio-snd: Virtio sound device
4  * Copyright (C) 2021 OpenSynergy GmbH
5  */
6 #ifndef VIRTIO_SND_PCM_H
7 #define VIRTIO_SND_PCM_H
8 
9 #include <linux/atomic.h>
10 #include <linux/virtio_config.h>
11 #include <sound/pcm.h>
12 
13 struct virtio_pcm;
14 struct virtio_pcm_msg;
15 
16 /**
17  * struct virtio_pcm_substream - VirtIO PCM substream.
18  * @snd: VirtIO sound device.
19  * @nid: Function group node identifier.
20  * @sid: Stream identifier.
21  * @direction: Stream data flow direction (SNDRV_PCM_STREAM_XXX).
22  * @features: Stream VirtIO feature bit map (1 << VIRTIO_SND_PCM_F_XXX).
23  * @substream: Kernel ALSA substream.
24  * @hw: Kernel ALSA substream hardware descriptor.
25  * @elapsed_period: Kernel work to handle the elapsed period state.
26  */
27 struct virtio_pcm_substream {
28 	struct virtio_snd *snd;
29 	u32 nid;
30 	u32 sid;
31 	u32 direction;
32 	u32 features;
33 	struct snd_pcm_substream *substream;
34 	struct snd_pcm_hardware hw;
35 	struct work_struct elapsed_period;
36 };
37 
38 /**
39  * struct virtio_pcm_stream - VirtIO PCM stream.
40  * @substreams: VirtIO substreams belonging to the stream.
41  * @nsubstreams: Number of substreams.
42  */
43 struct virtio_pcm_stream {
44 	struct virtio_pcm_substream **substreams;
45 	u32 nsubstreams;
46 };
47 
48 /**
49  * struct virtio_pcm - VirtIO PCM device.
50  * @list: VirtIO PCM list entry.
51  * @nid: Function group node identifier.
52  * @pcm: Kernel PCM device.
53  * @streams: VirtIO PCM streams (playback and capture).
54  */
55 struct virtio_pcm {
56 	struct list_head list;
57 	u32 nid;
58 	struct snd_pcm *pcm;
59 	struct virtio_pcm_stream streams[SNDRV_PCM_STREAM_LAST + 1];
60 };
61 
62 int virtsnd_pcm_validate(struct virtio_device *vdev);
63 
64 int virtsnd_pcm_parse_cfg(struct virtio_snd *snd);
65 
66 int virtsnd_pcm_build_devs(struct virtio_snd *snd);
67 
68 struct virtio_pcm *virtsnd_pcm_find(struct virtio_snd *snd, u32 nid);
69 
70 struct virtio_pcm *virtsnd_pcm_find_or_create(struct virtio_snd *snd, u32 nid);
71 
72 #endif /* VIRTIO_SND_PCM_H */
73