1 /* SPDX-License-Identifier: GPL-2.0+ */ 1 /* SPDX-License-Identifier: GPL-2.0+ */ 2 /* 2 /* 3 * virtio-snd: Virtio sound device 3 * virtio-snd: Virtio sound device 4 * Copyright (C) 2021 OpenSynergy GmbH 4 * Copyright (C) 2021 OpenSynergy GmbH 5 */ 5 */ 6 #ifndef VIRTIO_SND_CARD_H 6 #ifndef VIRTIO_SND_CARD_H 7 #define VIRTIO_SND_CARD_H 7 #define VIRTIO_SND_CARD_H 8 8 9 #include <linux/slab.h> 9 #include <linux/slab.h> 10 #include <linux/virtio.h> 10 #include <linux/virtio.h> 11 #include <sound/core.h> 11 #include <sound/core.h> 12 #include <uapi/linux/virtio_snd.h> 12 #include <uapi/linux/virtio_snd.h> 13 13 14 #include "virtio_ctl_msg.h" 14 #include "virtio_ctl_msg.h" 15 #include "virtio_pcm.h" 15 #include "virtio_pcm.h" 16 16 17 #define VIRTIO_SND_CARD_DRIVER "virtio-snd" 17 #define VIRTIO_SND_CARD_DRIVER "virtio-snd" 18 #define VIRTIO_SND_CARD_NAME "VirtIO SoundC 18 #define VIRTIO_SND_CARD_NAME "VirtIO SoundCard" 19 #define VIRTIO_SND_PCM_NAME "VirtIO PCM" 19 #define VIRTIO_SND_PCM_NAME "VirtIO PCM" 20 20 21 struct virtio_jack; 21 struct virtio_jack; 22 struct virtio_pcm_substream; 22 struct virtio_pcm_substream; 23 23 24 /** 24 /** 25 * struct virtio_snd_queue - Virtqueue wrapper 25 * struct virtio_snd_queue - Virtqueue wrapper structure. 26 * @lock: Used to synchronize access to a virt 26 * @lock: Used to synchronize access to a virtqueue. 27 * @vqueue: Underlying virtqueue. 27 * @vqueue: Underlying virtqueue. 28 */ 28 */ 29 struct virtio_snd_queue { 29 struct virtio_snd_queue { 30 spinlock_t lock; 30 spinlock_t lock; 31 struct virtqueue *vqueue; 31 struct virtqueue *vqueue; 32 }; 32 }; 33 33 34 /** 34 /** 35 * struct virtio_kctl - VirtIO control element << 36 * @kctl: ALSA control element. << 37 * @items: Items for the ENUMERATED element ty << 38 */ << 39 struct virtio_kctl { << 40 struct snd_kcontrol *kctl; << 41 struct virtio_snd_ctl_enum_item *items << 42 }; << 43 << 44 /** << 45 * struct virtio_snd - VirtIO sound card devic 35 * struct virtio_snd - VirtIO sound card device. 46 * @vdev: Underlying virtio device. 36 * @vdev: Underlying virtio device. 47 * @queues: Virtqueue wrappers. 37 * @queues: Virtqueue wrappers. 48 * @card: ALSA sound card. 38 * @card: ALSA sound card. 49 * @ctl_msgs: Pending control request list. 39 * @ctl_msgs: Pending control request list. 50 * @event_msgs: Device events. 40 * @event_msgs: Device events. 51 * @pcm_list: VirtIO PCM device list. 41 * @pcm_list: VirtIO PCM device list. 52 * @jacks: VirtIO jacks. 42 * @jacks: VirtIO jacks. 53 * @njacks: Number of jacks. 43 * @njacks: Number of jacks. 54 * @substreams: VirtIO PCM substreams. 44 * @substreams: VirtIO PCM substreams. 55 * @nsubstreams: Number of PCM substreams. 45 * @nsubstreams: Number of PCM substreams. 56 * @chmaps: VirtIO channel maps. 46 * @chmaps: VirtIO channel maps. 57 * @nchmaps: Number of channel maps. 47 * @nchmaps: Number of channel maps. 58 * @kctl_infos: VirtIO control element informa << 59 * @kctls: VirtIO control elements. << 60 * @nkctls: Number of control elements. << 61 */ 48 */ 62 struct virtio_snd { 49 struct virtio_snd { 63 struct virtio_device *vdev; 50 struct virtio_device *vdev; 64 struct virtio_snd_queue queues[VIRTIO_ 51 struct virtio_snd_queue queues[VIRTIO_SND_VQ_MAX]; 65 struct snd_card *card; 52 struct snd_card *card; 66 struct list_head ctl_msgs; 53 struct list_head ctl_msgs; 67 struct virtio_snd_event *event_msgs; 54 struct virtio_snd_event *event_msgs; 68 struct list_head pcm_list; 55 struct list_head pcm_list; 69 struct virtio_jack *jacks; 56 struct virtio_jack *jacks; 70 u32 njacks; 57 u32 njacks; 71 struct virtio_pcm_substream *substream 58 struct virtio_pcm_substream *substreams; 72 u32 nsubstreams; 59 u32 nsubstreams; 73 struct virtio_snd_chmap_info *chmaps; 60 struct virtio_snd_chmap_info *chmaps; 74 u32 nchmaps; 61 u32 nchmaps; 75 struct virtio_snd_ctl_info *kctl_infos << 76 struct virtio_kctl *kctls; << 77 u32 nkctls; << 78 }; 62 }; 79 63 80 /* Message completion timeout in milliseconds 64 /* Message completion timeout in milliseconds (module parameter). */ 81 extern u32 virtsnd_msg_timeout_ms; 65 extern u32 virtsnd_msg_timeout_ms; 82 66 83 static inline struct virtio_snd_queue * 67 static inline struct virtio_snd_queue * 84 virtsnd_control_queue(struct virtio_snd *snd) 68 virtsnd_control_queue(struct virtio_snd *snd) 85 { 69 { 86 return &snd->queues[VIRTIO_SND_VQ_CONT 70 return &snd->queues[VIRTIO_SND_VQ_CONTROL]; 87 } 71 } 88 72 89 static inline struct virtio_snd_queue * 73 static inline struct virtio_snd_queue * 90 virtsnd_event_queue(struct virtio_snd *snd) 74 virtsnd_event_queue(struct virtio_snd *snd) 91 { 75 { 92 return &snd->queues[VIRTIO_SND_VQ_EVEN 76 return &snd->queues[VIRTIO_SND_VQ_EVENT]; 93 } 77 } 94 78 95 static inline struct virtio_snd_queue * 79 static inline struct virtio_snd_queue * 96 virtsnd_tx_queue(struct virtio_snd *snd) 80 virtsnd_tx_queue(struct virtio_snd *snd) 97 { 81 { 98 return &snd->queues[VIRTIO_SND_VQ_TX]; 82 return &snd->queues[VIRTIO_SND_VQ_TX]; 99 } 83 } 100 84 101 static inline struct virtio_snd_queue * 85 static inline struct virtio_snd_queue * 102 virtsnd_rx_queue(struct virtio_snd *snd) 86 virtsnd_rx_queue(struct virtio_snd *snd) 103 { 87 { 104 return &snd->queues[VIRTIO_SND_VQ_RX]; 88 return &snd->queues[VIRTIO_SND_VQ_RX]; 105 } 89 } 106 90 107 static inline struct virtio_snd_queue * 91 static inline struct virtio_snd_queue * 108 virtsnd_pcm_queue(struct virtio_pcm_substream 92 virtsnd_pcm_queue(struct virtio_pcm_substream *vss) 109 { 93 { 110 if (vss->direction == SNDRV_PCM_STREAM 94 if (vss->direction == SNDRV_PCM_STREAM_PLAYBACK) 111 return virtsnd_tx_queue(vss->s 95 return virtsnd_tx_queue(vss->snd); 112 else 96 else 113 return virtsnd_rx_queue(vss->s 97 return virtsnd_rx_queue(vss->snd); 114 } 98 } 115 99 116 int virtsnd_jack_parse_cfg(struct virtio_snd * 100 int virtsnd_jack_parse_cfg(struct virtio_snd *snd); 117 101 118 int virtsnd_jack_build_devs(struct virtio_snd 102 int virtsnd_jack_build_devs(struct virtio_snd *snd); 119 103 120 void virtsnd_jack_event(struct virtio_snd *snd 104 void virtsnd_jack_event(struct virtio_snd *snd, 121 struct virtio_snd_even 105 struct virtio_snd_event *event); 122 106 123 int virtsnd_chmap_parse_cfg(struct virtio_snd 107 int virtsnd_chmap_parse_cfg(struct virtio_snd *snd); 124 108 125 int virtsnd_chmap_build_devs(struct virtio_snd 109 int virtsnd_chmap_build_devs(struct virtio_snd *snd); 126 << 127 int virtsnd_kctl_parse_cfg(struct virtio_snd * << 128 << 129 int virtsnd_kctl_build_devs(struct virtio_snd << 130 << 131 void virtsnd_kctl_event(struct virtio_snd *snd << 132 110 133 #endif /* VIRTIO_SND_CARD_H */ 111 #endif /* VIRTIO_SND_CARD_H */ 134 112
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.