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_PCM_H 6 #ifndef VIRTIO_SND_PCM_H 7 #define VIRTIO_SND_PCM_H 7 #define VIRTIO_SND_PCM_H 8 8 9 #include <linux/atomic.h> 9 #include <linux/atomic.h> 10 #include <linux/virtio_config.h> 10 #include <linux/virtio_config.h> 11 #include <sound/pcm.h> 11 #include <sound/pcm.h> 12 #include <sound/pcm-indirect.h> << 13 12 14 struct virtio_pcm; 13 struct virtio_pcm; 15 struct virtio_pcm_msg; 14 struct virtio_pcm_msg; 16 15 17 /** 16 /** 18 * struct virtio_pcm_substream - VirtIO PCM su 17 * struct virtio_pcm_substream - VirtIO PCM substream. 19 * @snd: VirtIO sound device. 18 * @snd: VirtIO sound device. 20 * @nid: Function group node identifier. 19 * @nid: Function group node identifier. 21 * @sid: Stream identifier. 20 * @sid: Stream identifier. 22 * @direction: Stream data flow direction (SND 21 * @direction: Stream data flow direction (SNDRV_PCM_STREAM_XXX). 23 * @features: Stream VirtIO feature bit map (1 22 * @features: Stream VirtIO feature bit map (1 << VIRTIO_SND_PCM_F_XXX). 24 * @substream: Kernel ALSA substream. 23 * @substream: Kernel ALSA substream. 25 * @pcm_indirect: Kernel indirect pcm structur << 26 * @hw: Kernel ALSA substream hardware descrip 24 * @hw: Kernel ALSA substream hardware descriptor. 27 * @elapsed_period: Kernel work to handle the 25 * @elapsed_period: Kernel work to handle the elapsed period state. 28 * @lock: Spinlock that protects fields shared 26 * @lock: Spinlock that protects fields shared by interrupt handlers and 29 * substream operators. 27 * substream operators. 30 * @buffer_bytes: Current buffer size in bytes 28 * @buffer_bytes: Current buffer size in bytes. 31 * @hw_ptr: Substream hardware pointer value i 29 * @hw_ptr: Substream hardware pointer value in bytes [0 ... buffer_bytes). 32 * @xfer_enabled: Data transfer state (0 - off 30 * @xfer_enabled: Data transfer state (0 - off, 1 - on). 33 * @xfer_xrun: Data underflow/overflow state ( 31 * @xfer_xrun: Data underflow/overflow state (0 - no xrun, 1 - xrun). 34 * @stopped: True if the substream is stopped 32 * @stopped: True if the substream is stopped and must be released on the device 35 * side. 33 * side. 36 * @suspended: True if the substream is suspen 34 * @suspended: True if the substream is suspended and must be reconfigured on 37 * the device side at resume. 35 * the device side at resume. 38 * @msgs: Allocated I/O messages. 36 * @msgs: Allocated I/O messages. 39 * @nmsgs: Number of allocated I/O messages. 37 * @nmsgs: Number of allocated I/O messages. 40 * @msg_last_enqueued: Index of the last I/O m 38 * @msg_last_enqueued: Index of the last I/O message added to the virtqueue. 41 * @msg_count: Number of pending I/O messages 39 * @msg_count: Number of pending I/O messages in the virtqueue. 42 * @msg_empty: Notify when msg_count is zero. 40 * @msg_empty: Notify when msg_count is zero. 43 */ 41 */ 44 struct virtio_pcm_substream { 42 struct virtio_pcm_substream { 45 struct virtio_snd *snd; 43 struct virtio_snd *snd; 46 u32 nid; 44 u32 nid; 47 u32 sid; 45 u32 sid; 48 u32 direction; 46 u32 direction; 49 u32 features; 47 u32 features; 50 struct snd_pcm_substream *substream; 48 struct snd_pcm_substream *substream; 51 struct snd_pcm_indirect pcm_indirect; << 52 struct snd_pcm_hardware hw; 49 struct snd_pcm_hardware hw; 53 struct work_struct elapsed_period; 50 struct work_struct elapsed_period; 54 spinlock_t lock; 51 spinlock_t lock; 55 size_t buffer_bytes; 52 size_t buffer_bytes; 56 size_t hw_ptr; 53 size_t hw_ptr; 57 bool xfer_enabled; 54 bool xfer_enabled; 58 bool xfer_xrun; 55 bool xfer_xrun; 59 bool stopped; 56 bool stopped; 60 bool suspended; 57 bool suspended; 61 struct virtio_pcm_msg **msgs; 58 struct virtio_pcm_msg **msgs; 62 unsigned int nmsgs; 59 unsigned int nmsgs; >> 60 int msg_last_enqueued; 63 unsigned int msg_count; 61 unsigned int msg_count; 64 wait_queue_head_t msg_empty; 62 wait_queue_head_t msg_empty; 65 }; 63 }; 66 64 67 /** 65 /** 68 * struct virtio_pcm_stream - VirtIO PCM strea 66 * struct virtio_pcm_stream - VirtIO PCM stream. 69 * @substreams: VirtIO substreams belonging to 67 * @substreams: VirtIO substreams belonging to the stream. 70 * @nsubstreams: Number of substreams. 68 * @nsubstreams: Number of substreams. 71 * @chmaps: Kernel channel maps belonging to t 69 * @chmaps: Kernel channel maps belonging to the stream. 72 * @nchmaps: Number of channel maps. 70 * @nchmaps: Number of channel maps. 73 */ 71 */ 74 struct virtio_pcm_stream { 72 struct virtio_pcm_stream { 75 struct virtio_pcm_substream **substrea 73 struct virtio_pcm_substream **substreams; 76 u32 nsubstreams; 74 u32 nsubstreams; 77 struct snd_pcm_chmap_elem *chmaps; 75 struct snd_pcm_chmap_elem *chmaps; 78 u32 nchmaps; 76 u32 nchmaps; 79 }; 77 }; 80 78 81 /** 79 /** 82 * struct virtio_pcm - VirtIO PCM device. 80 * struct virtio_pcm - VirtIO PCM device. 83 * @list: VirtIO PCM list entry. 81 * @list: VirtIO PCM list entry. 84 * @nid: Function group node identifier. 82 * @nid: Function group node identifier. 85 * @pcm: Kernel PCM device. 83 * @pcm: Kernel PCM device. 86 * @streams: VirtIO PCM streams (playback and 84 * @streams: VirtIO PCM streams (playback and capture). 87 */ 85 */ 88 struct virtio_pcm { 86 struct virtio_pcm { 89 struct list_head list; 87 struct list_head list; 90 u32 nid; 88 u32 nid; 91 struct snd_pcm *pcm; 89 struct snd_pcm *pcm; 92 struct virtio_pcm_stream streams[SNDRV 90 struct virtio_pcm_stream streams[SNDRV_PCM_STREAM_LAST + 1]; 93 }; 91 }; 94 92 95 extern const struct snd_pcm_ops virtsnd_pcm_op !! 93 extern const struct snd_pcm_ops virtsnd_pcm_ops; 96 94 97 int virtsnd_pcm_validate(struct virtio_device 95 int virtsnd_pcm_validate(struct virtio_device *vdev); 98 96 99 int virtsnd_pcm_parse_cfg(struct virtio_snd *s 97 int virtsnd_pcm_parse_cfg(struct virtio_snd *snd); 100 98 101 int virtsnd_pcm_build_devs(struct virtio_snd * 99 int virtsnd_pcm_build_devs(struct virtio_snd *snd); 102 100 103 void virtsnd_pcm_event(struct virtio_snd *snd, 101 void virtsnd_pcm_event(struct virtio_snd *snd, struct virtio_snd_event *event); 104 102 105 void virtsnd_pcm_tx_notify_cb(struct virtqueue 103 void virtsnd_pcm_tx_notify_cb(struct virtqueue *vqueue); 106 104 107 void virtsnd_pcm_rx_notify_cb(struct virtqueue 105 void virtsnd_pcm_rx_notify_cb(struct virtqueue *vqueue); 108 106 109 struct virtio_pcm *virtsnd_pcm_find(struct vir 107 struct virtio_pcm *virtsnd_pcm_find(struct virtio_snd *snd, u32 nid); 110 108 111 struct virtio_pcm *virtsnd_pcm_find_or_create( 109 struct virtio_pcm *virtsnd_pcm_find_or_create(struct virtio_snd *snd, u32 nid); 112 110 113 struct virtio_snd_msg * 111 struct virtio_snd_msg * 114 virtsnd_pcm_ctl_msg_alloc(struct virtio_pcm_su 112 virtsnd_pcm_ctl_msg_alloc(struct virtio_pcm_substream *vss, 115 unsigned int command 113 unsigned int command, gfp_t gfp); 116 114 117 int virtsnd_pcm_msg_alloc(struct virtio_pcm_su 115 int virtsnd_pcm_msg_alloc(struct virtio_pcm_substream *vss, 118 unsigned int periods 116 unsigned int periods, unsigned int period_bytes); 119 117 120 void virtsnd_pcm_msg_free(struct virtio_pcm_su 118 void virtsnd_pcm_msg_free(struct virtio_pcm_substream *vss); 121 119 122 int virtsnd_pcm_msg_send(struct virtio_pcm_sub !! 120 int virtsnd_pcm_msg_send(struct virtio_pcm_substream *vss); 123 unsigned long bytes); << 124 121 125 unsigned int virtsnd_pcm_msg_pending_num(struc 122 unsigned int virtsnd_pcm_msg_pending_num(struct virtio_pcm_substream *vss); 126 123 127 #endif /* VIRTIO_SND_PCM_H */ 124 #endif /* VIRTIO_SND_PCM_H */ 128 125
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.