| 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_kctl - VirtIO control element. |
| 36 |
* @kctl: ALSA control element. |
| 37 |
* @items: Items for the ENUMERATED element type. |
| 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 device. |
| 46 |
* @vdev: Underlying virtio device. |
| 47 |
* @queues: Virtqueue wrappers. |
| 48 |
* @card: ALSA sound card. |
| 49 |
* @ctl_msgs: Pending control request list. |
| 50 |
* @event_msgs: Device events. |
| 51 |
* @pcm_list: VirtIO PCM device list. |
| 52 |
* @jacks: VirtIO jacks. |
| 53 |
* @njacks: Number of jacks. |
| 54 |
* @substreams: VirtIO PCM substreams. |
| 55 |
* @nsubstreams: Number of PCM substreams. |
| 56 |
* @chmaps: VirtIO channel maps. |
| 57 |
* @nchmaps: Number of channel maps. |
| 58 |
* @kctl_infos: VirtIO control element information. |
| 59 |
* @kctls: VirtIO control elements. |
| 60 |
* @nkctls: Number of control elements. |
| 61 |
*/ |
| 62 |
struct virtio_snd { |
| 63 |
struct virtio_device *vdev; |
| 64 |
struct virtio_snd_queue queues[VIRTIO_SND_VQ_MAX]; |
| 65 |
struct snd_card *card; |
| 66 |
struct list_head ctl_msgs; |
| 67 |
struct virtio_snd_event *event_msgs; |
| 68 |
struct list_head pcm_list; |
| 69 |
struct virtio_jack *jacks; |
| 70 |
u32 njacks; |
| 71 |
struct virtio_pcm_substream *substreams; |
| 72 |
u32 nsubstreams; |
| 73 |
struct virtio_snd_chmap_info *chmaps; |
| 74 |
u32 nchmaps; |
| 75 |
struct virtio_snd_ctl_info *kctl_infos; |
| 76 |
struct virtio_kctl *kctls; |
| 77 |
u32 nkctls; |
| 78 |
}; |
| 79 |
|
| 80 |
/* Message completion timeout in milliseconds (module parameter). */ |
| 81 |
extern u32 virtsnd_msg_timeout_ms; |
| 82 |
|
| 83 |
static inline struct virtio_snd_queue * |
| 84 |
virtsnd_control_queue(struct virtio_snd *snd) |
| 85 |
{ |
| 86 |
return &snd->queues[VIRTIO_SND_VQ_CONTROL]; |
| 87 |
} |
| 88 |
|
| 89 |
static inline struct virtio_snd_queue * |
| 90 |
virtsnd_event_queue(struct virtio_snd *snd) |
| 91 |
{ |
| 92 |
return &snd->queues[VIRTIO_SND_VQ_EVENT]; |
| 93 |
} |
| 94 |
|
| 95 |
static inline struct virtio_snd_queue * |
| 96 |
virtsnd_tx_queue(struct virtio_snd *snd) |
| 97 |
{ |
| 98 |
return &snd->queues[VIRTIO_SND_VQ_TX]; |
| 99 |
} |
| 100 |
|
| 101 |
static inline struct virtio_snd_queue * |
| 102 |
virtsnd_rx_queue(struct virtio_snd *snd) |
| 103 |
{ |
| 104 |
return &snd->queues[VIRTIO_SND_VQ_RX]; |
| 105 |
} |
| 106 |
|
| 107 |
static inline struct virtio_snd_queue * |
| 108 |
virtsnd_pcm_queue(struct virtio_pcm_substream *vss) |
| 109 |
{ |
| 110 |
if (vss->direction == SNDRV_PCM_STREAM_PLAYBACK) |
| 111 |
return virtsnd_tx_queue(vss->snd); |
| 112 |
else |
| 113 |
return virtsnd_rx_queue(vss->snd); |
| 114 |
} |
| 115 |
|
| 116 |
int virtsnd_jack_parse_cfg(struct virtio_snd *snd); |
| 117 |
|
| 118 |
int virtsnd_jack_build_devs(struct virtio_snd *snd); |
| 119 |
|
| 120 |
void virtsnd_jack_event(struct virtio_snd *snd, |
| 121 |
struct virtio_snd_event *event); |
| 122 |
|
| 123 |
int virtsnd_chmap_parse_cfg(struct virtio_snd *snd); |
| 124 |
|
| 125 |
int virtsnd_chmap_build_devs(struct virtio_snd *snd); |
| 126 |
|
| 127 |
int virtsnd_kctl_parse_cfg(struct virtio_snd *snd); |
| 128 |
|
| 129 |
int virtsnd_kctl_build_devs(struct virtio_snd *snd); |
| 130 |
|
| 131 |
void virtsnd_kctl_event(struct virtio_snd *snd, struct virtio_snd_event *event); |
| 132 |
|
| 133 |
#endif /* VIRTIO_SND_CARD_H */ |