blob: 1e76eeff160f4415db063ff5551843a5a96aa586 [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"
15
Anton Yakovlevde3a99802021-03-02 17:47:02 +010016#define VIRTIO_SND_CARD_DRIVER "virtio-snd"
17#define VIRTIO_SND_CARD_NAME "VirtIO SoundCard"
18
19/**
20 * struct virtio_snd_queue - Virtqueue wrapper structure.
21 * @lock: Used to synchronize access to a virtqueue.
22 * @vqueue: Underlying virtqueue.
23 */
24struct virtio_snd_queue {
25 spinlock_t lock;
26 struct virtqueue *vqueue;
27};
28
29/**
30 * struct virtio_snd - VirtIO sound card device.
31 * @vdev: Underlying virtio device.
32 * @queues: Virtqueue wrappers.
33 * @card: ALSA sound card.
Anton Yakovlev9d45e512021-03-02 17:47:03 +010034 * @ctl_msgs: Pending control request list.
Anton Yakovlevde3a99802021-03-02 17:47:02 +010035 * @event_msgs: Device events.
36 */
37struct virtio_snd {
38 struct virtio_device *vdev;
39 struct virtio_snd_queue queues[VIRTIO_SND_VQ_MAX];
40 struct snd_card *card;
Anton Yakovlev9d45e512021-03-02 17:47:03 +010041 struct list_head ctl_msgs;
Anton Yakovlevde3a99802021-03-02 17:47:02 +010042 struct virtio_snd_event *event_msgs;
43};
44
Anton Yakovlev9d45e512021-03-02 17:47:03 +010045/* Message completion timeout in milliseconds (module parameter). */
46extern u32 virtsnd_msg_timeout_ms;
47
Anton Yakovlevde3a99802021-03-02 17:47:02 +010048static inline struct virtio_snd_queue *
49virtsnd_control_queue(struct virtio_snd *snd)
50{
51 return &snd->queues[VIRTIO_SND_VQ_CONTROL];
52}
53
54static inline struct virtio_snd_queue *
55virtsnd_event_queue(struct virtio_snd *snd)
56{
57 return &snd->queues[VIRTIO_SND_VQ_EVENT];
58}
59
60static inline struct virtio_snd_queue *
61virtsnd_tx_queue(struct virtio_snd *snd)
62{
63 return &snd->queues[VIRTIO_SND_VQ_TX];
64}
65
66static inline struct virtio_snd_queue *
67virtsnd_rx_queue(struct virtio_snd *snd)
68{
69 return &snd->queues[VIRTIO_SND_VQ_RX];
70}
71
72#endif /* VIRTIO_SND_CARD_H */