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 16 #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 */ 24 struct 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. 34 * @ctl_msgs: Pending control request list. 35 * @event_msgs: Device events. 36 */ 37 struct virtio_snd { 38 struct virtio_device *vdev; 39 struct virtio_snd_queue queues[VIRTIO_SND_VQ_MAX]; 40 struct snd_card *card; 41 struct list_head ctl_msgs; 42 struct virtio_snd_event *event_msgs; 43 }; 44 45 /* Message completion timeout in milliseconds (module parameter). */ 46 extern u32 virtsnd_msg_timeout_ms; 47 48 static inline struct virtio_snd_queue * 49 virtsnd_control_queue(struct virtio_snd *snd) 50 { 51 return &snd->queues[VIRTIO_SND_VQ_CONTROL]; 52 } 53 54 static inline struct virtio_snd_queue * 55 virtsnd_event_queue(struct virtio_snd *snd) 56 { 57 return &snd->queues[VIRTIO_SND_VQ_EVENT]; 58 } 59 60 static inline struct virtio_snd_queue * 61 virtsnd_tx_queue(struct virtio_snd *snd) 62 { 63 return &snd->queues[VIRTIO_SND_VQ_TX]; 64 } 65 66 static inline struct virtio_snd_queue * 67 virtsnd_rx_queue(struct virtio_snd *snd) 68 { 69 return &snd->queues[VIRTIO_SND_VQ_RX]; 70 } 71 72 #endif /* VIRTIO_SND_CARD_H */ 73