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_CARD_H 7 #define VIRTIO_SND_CARD_H 8 9 #include <linux/slab.h> 10 #include <linux/virtio.h> 11 #include <sound/core.h> 12 #include <uapi/linux/virtio_snd.h> 13 14 #include "virtio_ctl_msg.h" 15 #include "virtio_pcm.h" 16 17 #define VIRTIO_SND_CARD_DRIVER "virtio-snd" 18 #define VIRTIO_SND_CARD_NAME "VirtIO SoundCard" 19 #define VIRTIO_SND_PCM_NAME "VirtIO PCM" 20 21 struct virtio_jack; 22 struct virtio_pcm_substream; 23 24 /** 25 * struct virtio_snd_queue - Virtqueue wrapper structure. 26 * @lock: Used to synchronize access to a virtqueue. 27 * @vqueue: Underlying virtqueue. 28 */ 29 struct virtio_snd_queue { 30 spinlock_t lock; 31 struct virtqueue *vqueue; 32 }; 33 34 /** 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 */ 47 struct virtio_snd { 48 struct virtio_device *vdev; 49 struct virtio_snd_queue queues[VIRTIO_SND_VQ_MAX]; 50 struct snd_card *card; 51 struct list_head ctl_msgs; 52 struct virtio_snd_event *event_msgs; 53 struct list_head pcm_list; 54 struct virtio_jack *jacks; 55 u32 njacks; 56 struct virtio_pcm_substream *substreams; 57 u32 nsubstreams; 58 }; 59 60 /* Message completion timeout in milliseconds (module parameter). */ 61 extern u32 virtsnd_msg_timeout_ms; 62 63 static inline struct virtio_snd_queue * 64 virtsnd_control_queue(struct virtio_snd *snd) 65 { 66 return &snd->queues[VIRTIO_SND_VQ_CONTROL]; 67 } 68 69 static inline struct virtio_snd_queue * 70 virtsnd_event_queue(struct virtio_snd *snd) 71 { 72 return &snd->queues[VIRTIO_SND_VQ_EVENT]; 73 } 74 75 static inline struct virtio_snd_queue * 76 virtsnd_tx_queue(struct virtio_snd *snd) 77 { 78 return &snd->queues[VIRTIO_SND_VQ_TX]; 79 } 80 81 static inline struct virtio_snd_queue * 82 virtsnd_rx_queue(struct virtio_snd *snd) 83 { 84 return &snd->queues[VIRTIO_SND_VQ_RX]; 85 } 86 87 static inline struct virtio_snd_queue * 88 virtsnd_pcm_queue(struct virtio_pcm_substream *vss) 89 { 90 if (vss->direction == SNDRV_PCM_STREAM_PLAYBACK) 91 return virtsnd_tx_queue(vss->snd); 92 else 93 return virtsnd_rx_queue(vss->snd); 94 } 95 96 int virtsnd_jack_parse_cfg(struct virtio_snd *snd); 97 98 int virtsnd_jack_build_devs(struct virtio_snd *snd); 99 100 void virtsnd_jack_event(struct virtio_snd *snd, 101 struct virtio_snd_event *event); 102 103 #endif /* VIRTIO_SND_CARD_H */ 104