blob: 3ceee4e416fc7be8c016064bfe08f26f8fe86fb8 [file] [log] [blame]
Anton Yakovlevde3a99802021-03-02 17:47:02 +01001/* 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 Yakovlev9d45e512021-03-02 17:47:03 +010014#include "virtio_ctl_msg.h"
Anton Yakovlev29b96bf2021-03-02 17:47:04 +010015#include "virtio_pcm.h"
Anton Yakovlev9d45e512021-03-02 17:47:03 +010016
Anton Yakovlevde3a99802021-03-02 17:47:02 +010017#define VIRTIO_SND_CARD_DRIVER "virtio-snd"
18#define VIRTIO_SND_CARD_NAME "VirtIO SoundCard"
Anton Yakovlev29b96bf2021-03-02 17:47:04 +010019#define VIRTIO_SND_PCM_NAME "VirtIO PCM"
20
Anton Yakovlevca61a412021-03-02 17:47:07 +010021struct virtio_jack;
Anton Yakovlev29b96bf2021-03-02 17:47:04 +010022struct virtio_pcm_substream;
Anton Yakovlevde3a99802021-03-02 17:47:02 +010023
24/**
25 * struct virtio_snd_queue - Virtqueue wrapper structure.
26 * @lock: Used to synchronize access to a virtqueue.
27 * @vqueue: Underlying virtqueue.
28 */
29struct virtio_snd_queue {
30 spinlock_t lock;
31 struct virtqueue *vqueue;
32};
33
34/**
Anton Yakovlevd6568e32024-01-15 14:36:54 +010035 * struct virtio_kctl - VirtIO control element.
36 * @kctl: ALSA control element.
37 * @items: Items for the ENUMERATED element type.
38 */
39struct virtio_kctl {
40 struct snd_kcontrol *kctl;
41 struct virtio_snd_ctl_enum_item *items;
42};
43
44/**
Anton Yakovlevde3a99802021-03-02 17:47:02 +010045 * struct virtio_snd - VirtIO sound card device.
46 * @vdev: Underlying virtio device.
47 * @queues: Virtqueue wrappers.
48 * @card: ALSA sound card.
Anton Yakovlev9d45e512021-03-02 17:47:03 +010049 * @ctl_msgs: Pending control request list.
Anton Yakovlevde3a99802021-03-02 17:47:02 +010050 * @event_msgs: Device events.
Anton Yakovlev29b96bf2021-03-02 17:47:04 +010051 * @pcm_list: VirtIO PCM device list.
Anton Yakovlevca61a412021-03-02 17:47:07 +010052 * @jacks: VirtIO jacks.
53 * @njacks: Number of jacks.
Anton Yakovlev29b96bf2021-03-02 17:47:04 +010054 * @substreams: VirtIO PCM substreams.
55 * @nsubstreams: Number of PCM substreams.
Anton Yakovlev19325fe2021-03-02 17:47:08 +010056 * @chmaps: VirtIO channel maps.
57 * @nchmaps: Number of channel maps.
Anton Yakovlevd6568e32024-01-15 14:36:54 +010058 * @kctl_infos: VirtIO control element information.
59 * @kctls: VirtIO control elements.
60 * @nkctls: Number of control elements.
Anton Yakovlevde3a99802021-03-02 17:47:02 +010061 */
62struct virtio_snd {
63 struct virtio_device *vdev;
64 struct virtio_snd_queue queues[VIRTIO_SND_VQ_MAX];
65 struct snd_card *card;
Anton Yakovlev9d45e512021-03-02 17:47:03 +010066 struct list_head ctl_msgs;
Anton Yakovlevde3a99802021-03-02 17:47:02 +010067 struct virtio_snd_event *event_msgs;
Anton Yakovlev29b96bf2021-03-02 17:47:04 +010068 struct list_head pcm_list;
Anton Yakovlevca61a412021-03-02 17:47:07 +010069 struct virtio_jack *jacks;
70 u32 njacks;
Anton Yakovlev29b96bf2021-03-02 17:47:04 +010071 struct virtio_pcm_substream *substreams;
72 u32 nsubstreams;
Anton Yakovlev19325fe2021-03-02 17:47:08 +010073 struct virtio_snd_chmap_info *chmaps;
74 u32 nchmaps;
Anton Yakovlevd6568e32024-01-15 14:36:54 +010075 struct virtio_snd_ctl_info *kctl_infos;
76 struct virtio_kctl *kctls;
77 u32 nkctls;
Anton Yakovlevde3a99802021-03-02 17:47:02 +010078};
79
Anton Yakovlev9d45e512021-03-02 17:47:03 +010080/* Message completion timeout in milliseconds (module parameter). */
81extern u32 virtsnd_msg_timeout_ms;
82
Anton Yakovlevde3a99802021-03-02 17:47:02 +010083static inline struct virtio_snd_queue *
84virtsnd_control_queue(struct virtio_snd *snd)
85{
86 return &snd->queues[VIRTIO_SND_VQ_CONTROL];
87}
88
89static inline struct virtio_snd_queue *
90virtsnd_event_queue(struct virtio_snd *snd)
91{
92 return &snd->queues[VIRTIO_SND_VQ_EVENT];
93}
94
95static inline struct virtio_snd_queue *
96virtsnd_tx_queue(struct virtio_snd *snd)
97{
98 return &snd->queues[VIRTIO_SND_VQ_TX];
99}
100
101static inline struct virtio_snd_queue *
102virtsnd_rx_queue(struct virtio_snd *snd)
103{
104 return &snd->queues[VIRTIO_SND_VQ_RX];
105}
106
Anton Yakovlevf40a2862021-03-02 17:47:05 +0100107static inline struct virtio_snd_queue *
108virtsnd_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
Anton Yakovlevca61a412021-03-02 17:47:07 +0100116int virtsnd_jack_parse_cfg(struct virtio_snd *snd);
117
118int virtsnd_jack_build_devs(struct virtio_snd *snd);
119
120void virtsnd_jack_event(struct virtio_snd *snd,
121 struct virtio_snd_event *event);
122
Anton Yakovlev19325fe2021-03-02 17:47:08 +0100123int virtsnd_chmap_parse_cfg(struct virtio_snd *snd);
124
125int virtsnd_chmap_build_devs(struct virtio_snd *snd);
126
Anton Yakovlevd6568e32024-01-15 14:36:54 +0100127int virtsnd_kctl_parse_cfg(struct virtio_snd *snd);
128
129int virtsnd_kctl_build_devs(struct virtio_snd *snd);
130
131void virtsnd_kctl_event(struct virtio_snd *snd, struct virtio_snd_event *event);
132
Anton Yakovlevde3a99802021-03-02 17:47:02 +0100133#endif /* VIRTIO_SND_CARD_H */