Anton Yakovlev | de3a9980 | 2021-03-02 17:47:02 +0100 | [diff] [blame] | 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 | |
Anton Yakovlev | 9d45e51 | 2021-03-02 17:47:03 +0100 | [diff] [blame] | 14 | #include "virtio_ctl_msg.h" |
Anton Yakovlev | 29b96bf | 2021-03-02 17:47:04 +0100 | [diff] [blame] | 15 | #include "virtio_pcm.h" |
Anton Yakovlev | 9d45e51 | 2021-03-02 17:47:03 +0100 | [diff] [blame] | 16 | |
Anton Yakovlev | de3a9980 | 2021-03-02 17:47:02 +0100 | [diff] [blame] | 17 | #define VIRTIO_SND_CARD_DRIVER "virtio-snd" |
| 18 | #define VIRTIO_SND_CARD_NAME "VirtIO SoundCard" |
Anton Yakovlev | 29b96bf | 2021-03-02 17:47:04 +0100 | [diff] [blame] | 19 | #define VIRTIO_SND_PCM_NAME "VirtIO PCM" |
| 20 | |
Anton Yakovlev | ca61a41 | 2021-03-02 17:47:07 +0100 | [diff] [blame] | 21 | struct virtio_jack; |
Anton Yakovlev | 29b96bf | 2021-03-02 17:47:04 +0100 | [diff] [blame] | 22 | struct virtio_pcm_substream; |
Anton Yakovlev | de3a9980 | 2021-03-02 17:47:02 +0100 | [diff] [blame] | 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. |
Anton Yakovlev | 9d45e51 | 2021-03-02 17:47:03 +0100 | [diff] [blame] | 39 | * @ctl_msgs: Pending control request list. |
Anton Yakovlev | de3a9980 | 2021-03-02 17:47:02 +0100 | [diff] [blame] | 40 | * @event_msgs: Device events. |
Anton Yakovlev | 29b96bf | 2021-03-02 17:47:04 +0100 | [diff] [blame] | 41 | * @pcm_list: VirtIO PCM device list. |
Anton Yakovlev | ca61a41 | 2021-03-02 17:47:07 +0100 | [diff] [blame] | 42 | * @jacks: VirtIO jacks. |
| 43 | * @njacks: Number of jacks. |
Anton Yakovlev | 29b96bf | 2021-03-02 17:47:04 +0100 | [diff] [blame] | 44 | * @substreams: VirtIO PCM substreams. |
| 45 | * @nsubstreams: Number of PCM substreams. |
Anton Yakovlev | 19325fe | 2021-03-02 17:47:08 +0100 | [diff] [blame] | 46 | * @chmaps: VirtIO channel maps. |
| 47 | * @nchmaps: Number of channel maps. |
Anton Yakovlev | de3a9980 | 2021-03-02 17:47:02 +0100 | [diff] [blame] | 48 | */ |
| 49 | struct virtio_snd { |
| 50 | struct virtio_device *vdev; |
| 51 | struct virtio_snd_queue queues[VIRTIO_SND_VQ_MAX]; |
| 52 | struct snd_card *card; |
Anton Yakovlev | 9d45e51 | 2021-03-02 17:47:03 +0100 | [diff] [blame] | 53 | struct list_head ctl_msgs; |
Anton Yakovlev | de3a9980 | 2021-03-02 17:47:02 +0100 | [diff] [blame] | 54 | struct virtio_snd_event *event_msgs; |
Anton Yakovlev | 29b96bf | 2021-03-02 17:47:04 +0100 | [diff] [blame] | 55 | struct list_head pcm_list; |
Anton Yakovlev | ca61a41 | 2021-03-02 17:47:07 +0100 | [diff] [blame] | 56 | struct virtio_jack *jacks; |
| 57 | u32 njacks; |
Anton Yakovlev | 29b96bf | 2021-03-02 17:47:04 +0100 | [diff] [blame] | 58 | struct virtio_pcm_substream *substreams; |
| 59 | u32 nsubstreams; |
Anton Yakovlev | 19325fe | 2021-03-02 17:47:08 +0100 | [diff] [blame] | 60 | struct virtio_snd_chmap_info *chmaps; |
| 61 | u32 nchmaps; |
Anton Yakovlev | de3a9980 | 2021-03-02 17:47:02 +0100 | [diff] [blame] | 62 | }; |
| 63 | |
Anton Yakovlev | 9d45e51 | 2021-03-02 17:47:03 +0100 | [diff] [blame] | 64 | /* Message completion timeout in milliseconds (module parameter). */ |
| 65 | extern u32 virtsnd_msg_timeout_ms; |
| 66 | |
Anton Yakovlev | de3a9980 | 2021-03-02 17:47:02 +0100 | [diff] [blame] | 67 | static inline struct virtio_snd_queue * |
| 68 | virtsnd_control_queue(struct virtio_snd *snd) |
| 69 | { |
| 70 | return &snd->queues[VIRTIO_SND_VQ_CONTROL]; |
| 71 | } |
| 72 | |
| 73 | static inline struct virtio_snd_queue * |
| 74 | virtsnd_event_queue(struct virtio_snd *snd) |
| 75 | { |
| 76 | return &snd->queues[VIRTIO_SND_VQ_EVENT]; |
| 77 | } |
| 78 | |
| 79 | static inline struct virtio_snd_queue * |
| 80 | virtsnd_tx_queue(struct virtio_snd *snd) |
| 81 | { |
| 82 | return &snd->queues[VIRTIO_SND_VQ_TX]; |
| 83 | } |
| 84 | |
| 85 | static inline struct virtio_snd_queue * |
| 86 | virtsnd_rx_queue(struct virtio_snd *snd) |
| 87 | { |
| 88 | return &snd->queues[VIRTIO_SND_VQ_RX]; |
| 89 | } |
| 90 | |
Anton Yakovlev | f40a286 | 2021-03-02 17:47:05 +0100 | [diff] [blame] | 91 | static inline struct virtio_snd_queue * |
| 92 | virtsnd_pcm_queue(struct virtio_pcm_substream *vss) |
| 93 | { |
| 94 | if (vss->direction == SNDRV_PCM_STREAM_PLAYBACK) |
| 95 | return virtsnd_tx_queue(vss->snd); |
| 96 | else |
| 97 | return virtsnd_rx_queue(vss->snd); |
| 98 | } |
| 99 | |
Anton Yakovlev | ca61a41 | 2021-03-02 17:47:07 +0100 | [diff] [blame] | 100 | int virtsnd_jack_parse_cfg(struct virtio_snd *snd); |
| 101 | |
| 102 | int virtsnd_jack_build_devs(struct virtio_snd *snd); |
| 103 | |
| 104 | void virtsnd_jack_event(struct virtio_snd *snd, |
| 105 | struct virtio_snd_event *event); |
| 106 | |
Anton Yakovlev | 19325fe | 2021-03-02 17:47:08 +0100 | [diff] [blame] | 107 | int virtsnd_chmap_parse_cfg(struct virtio_snd *snd); |
| 108 | |
| 109 | int virtsnd_chmap_build_devs(struct virtio_snd *snd); |
| 110 | |
Anton Yakovlev | de3a9980 | 2021-03-02 17:47:02 +0100 | [diff] [blame] | 111 | #endif /* VIRTIO_SND_CARD_H */ |