blob: 86ef3941895ed25c9bfa1d46267bef99f2ad7101 [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/**
35 * struct virtio_snd - VirtIO sound card device.
36 * @vdev: Underlying virtio device.
37 * @queues: Virtqueue wrappers.
38 * @card: ALSA sound card.
Anton Yakovlev9d45e512021-03-02 17:47:03 +010039 * @ctl_msgs: Pending control request list.
Anton Yakovlevde3a99802021-03-02 17:47:02 +010040 * @event_msgs: Device events.
Anton Yakovlev29b96bf2021-03-02 17:47:04 +010041 * @pcm_list: VirtIO PCM device list.
Anton Yakovlevca61a412021-03-02 17:47:07 +010042 * @jacks: VirtIO jacks.
43 * @njacks: Number of jacks.
Anton Yakovlev29b96bf2021-03-02 17:47:04 +010044 * @substreams: VirtIO PCM substreams.
45 * @nsubstreams: Number of PCM substreams.
Anton Yakovlev19325fe2021-03-02 17:47:08 +010046 * @chmaps: VirtIO channel maps.
47 * @nchmaps: Number of channel maps.
Anton Yakovlevde3a99802021-03-02 17:47:02 +010048 */
49struct virtio_snd {
50 struct virtio_device *vdev;
51 struct virtio_snd_queue queues[VIRTIO_SND_VQ_MAX];
52 struct snd_card *card;
Anton Yakovlev9d45e512021-03-02 17:47:03 +010053 struct list_head ctl_msgs;
Anton Yakovlevde3a99802021-03-02 17:47:02 +010054 struct virtio_snd_event *event_msgs;
Anton Yakovlev29b96bf2021-03-02 17:47:04 +010055 struct list_head pcm_list;
Anton Yakovlevca61a412021-03-02 17:47:07 +010056 struct virtio_jack *jacks;
57 u32 njacks;
Anton Yakovlev29b96bf2021-03-02 17:47:04 +010058 struct virtio_pcm_substream *substreams;
59 u32 nsubstreams;
Anton Yakovlev19325fe2021-03-02 17:47:08 +010060 struct virtio_snd_chmap_info *chmaps;
61 u32 nchmaps;
Anton Yakovlevde3a99802021-03-02 17:47:02 +010062};
63
Anton Yakovlev9d45e512021-03-02 17:47:03 +010064/* Message completion timeout in milliseconds (module parameter). */
65extern u32 virtsnd_msg_timeout_ms;
66
Anton Yakovlevde3a99802021-03-02 17:47:02 +010067static inline struct virtio_snd_queue *
68virtsnd_control_queue(struct virtio_snd *snd)
69{
70 return &snd->queues[VIRTIO_SND_VQ_CONTROL];
71}
72
73static inline struct virtio_snd_queue *
74virtsnd_event_queue(struct virtio_snd *snd)
75{
76 return &snd->queues[VIRTIO_SND_VQ_EVENT];
77}
78
79static inline struct virtio_snd_queue *
80virtsnd_tx_queue(struct virtio_snd *snd)
81{
82 return &snd->queues[VIRTIO_SND_VQ_TX];
83}
84
85static inline struct virtio_snd_queue *
86virtsnd_rx_queue(struct virtio_snd *snd)
87{
88 return &snd->queues[VIRTIO_SND_VQ_RX];
89}
90
Anton Yakovlevf40a2862021-03-02 17:47:05 +010091static inline struct virtio_snd_queue *
92virtsnd_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 Yakovlevca61a412021-03-02 17:47:07 +0100100int virtsnd_jack_parse_cfg(struct virtio_snd *snd);
101
102int virtsnd_jack_build_devs(struct virtio_snd *snd);
103
104void virtsnd_jack_event(struct virtio_snd *snd,
105 struct virtio_snd_event *event);
106
Anton Yakovlev19325fe2021-03-02 17:47:08 +0100107int virtsnd_chmap_parse_cfg(struct virtio_snd *snd);
108
109int virtsnd_chmap_build_devs(struct virtio_snd *snd);
110
Anton Yakovlevde3a99802021-03-02 17:47:02 +0100111#endif /* VIRTIO_SND_CARD_H */