2021-03-02 17:47:02 +01:00
/* SPDX-License-Identifier: GPL-2.0+ */
/*
* virtio - snd : Virtio sound device
* Copyright ( C ) 2021 OpenSynergy GmbH
*/
# ifndef VIRTIO_SND_CARD_H
# define VIRTIO_SND_CARD_H
# include <linux/slab.h>
# include <linux/virtio.h>
# include <sound/core.h>
# include <uapi/linux/virtio_snd.h>
2021-03-02 17:47:03 +01:00
# include "virtio_ctl_msg.h"
2021-03-02 17:47:04 +01:00
# include "virtio_pcm.h"
2021-03-02 17:47:03 +01:00
2021-03-02 17:47:02 +01:00
# define VIRTIO_SND_CARD_DRIVER "virtio-snd"
# define VIRTIO_SND_CARD_NAME "VirtIO SoundCard"
2021-03-02 17:47:04 +01:00
# define VIRTIO_SND_PCM_NAME "VirtIO PCM"
2021-03-02 17:47:07 +01:00
struct virtio_jack ;
2021-03-02 17:47:04 +01:00
struct virtio_pcm_substream ;
2021-03-02 17:47:02 +01:00
/**
* struct virtio_snd_queue - Virtqueue wrapper structure .
* @ lock : Used to synchronize access to a virtqueue .
* @ vqueue : Underlying virtqueue .
*/
struct virtio_snd_queue {
spinlock_t lock ;
struct virtqueue * vqueue ;
} ;
/**
* struct virtio_snd - VirtIO sound card device .
* @ vdev : Underlying virtio device .
* @ queues : Virtqueue wrappers .
* @ card : ALSA sound card .
2021-03-02 17:47:03 +01:00
* @ ctl_msgs : Pending control request list .
2021-03-02 17:47:02 +01:00
* @ event_msgs : Device events .
2021-03-02 17:47:04 +01:00
* @ pcm_list : VirtIO PCM device list .
2021-03-02 17:47:07 +01:00
* @ jacks : VirtIO jacks .
* @ njacks : Number of jacks .
2021-03-02 17:47:04 +01:00
* @ substreams : VirtIO PCM substreams .
* @ nsubstreams : Number of PCM substreams .
2021-03-02 17:47:08 +01:00
* @ chmaps : VirtIO channel maps .
* @ nchmaps : Number of channel maps .
2021-03-02 17:47:02 +01:00
*/
struct virtio_snd {
struct virtio_device * vdev ;
struct virtio_snd_queue queues [ VIRTIO_SND_VQ_MAX ] ;
struct snd_card * card ;
2021-03-02 17:47:03 +01:00
struct list_head ctl_msgs ;
2021-03-02 17:47:02 +01:00
struct virtio_snd_event * event_msgs ;
2021-03-02 17:47:04 +01:00
struct list_head pcm_list ;
2021-03-02 17:47:07 +01:00
struct virtio_jack * jacks ;
u32 njacks ;
2021-03-02 17:47:04 +01:00
struct virtio_pcm_substream * substreams ;
u32 nsubstreams ;
2021-03-02 17:47:08 +01:00
struct virtio_snd_chmap_info * chmaps ;
u32 nchmaps ;
2021-03-02 17:47:02 +01:00
} ;
2021-03-02 17:47:03 +01:00
/* Message completion timeout in milliseconds (module parameter). */
extern u32 virtsnd_msg_timeout_ms ;
2021-03-02 17:47:02 +01:00
static inline struct virtio_snd_queue *
virtsnd_control_queue ( struct virtio_snd * snd )
{
return & snd - > queues [ VIRTIO_SND_VQ_CONTROL ] ;
}
static inline struct virtio_snd_queue *
virtsnd_event_queue ( struct virtio_snd * snd )
{
return & snd - > queues [ VIRTIO_SND_VQ_EVENT ] ;
}
static inline struct virtio_snd_queue *
virtsnd_tx_queue ( struct virtio_snd * snd )
{
return & snd - > queues [ VIRTIO_SND_VQ_TX ] ;
}
static inline struct virtio_snd_queue *
virtsnd_rx_queue ( struct virtio_snd * snd )
{
return & snd - > queues [ VIRTIO_SND_VQ_RX ] ;
}
2021-03-02 17:47:05 +01:00
static inline struct virtio_snd_queue *
virtsnd_pcm_queue ( struct virtio_pcm_substream * vss )
{
if ( vss - > direction = = SNDRV_PCM_STREAM_PLAYBACK )
return virtsnd_tx_queue ( vss - > snd ) ;
else
return virtsnd_rx_queue ( vss - > snd ) ;
}
2021-03-02 17:47:07 +01:00
int virtsnd_jack_parse_cfg ( struct virtio_snd * snd ) ;
int virtsnd_jack_build_devs ( struct virtio_snd * snd ) ;
void virtsnd_jack_event ( struct virtio_snd * snd ,
struct virtio_snd_event * event ) ;
2021-03-02 17:47:08 +01:00
int virtsnd_chmap_parse_cfg ( struct virtio_snd * snd ) ;
int virtsnd_chmap_build_devs ( struct virtio_snd * snd ) ;
2021-03-02 17:47:02 +01:00
# endif /* VIRTIO_SND_CARD_H */