brintos

brintos / linux-shallow public Read only

0
0
Text · 3.3 KiB · 3ceee4e Raw
134 lines · c
1/* SPDX-License-Identifier: GPL-2.0+ */2/*3 * virtio-snd: Virtio sound device4 * Copyright (C) 2021 OpenSynergy GmbH5 */6#ifndef VIRTIO_SND_CARD_H7#define VIRTIO_SND_CARD_H8 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#include "virtio_pcm.h"16 17#define VIRTIO_SND_CARD_DRIVER	"virtio-snd"18#define VIRTIO_SND_CARD_NAME	"VirtIO SoundCard"19#define VIRTIO_SND_PCM_NAME	"VirtIO PCM"20 21struct virtio_jack;22struct virtio_pcm_substream;23 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_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/**45 * struct virtio_snd - VirtIO sound card device.46 * @vdev: Underlying virtio device.47 * @queues: Virtqueue wrappers.48 * @card: ALSA sound card.49 * @ctl_msgs: Pending control request list.50 * @event_msgs: Device events.51 * @pcm_list: VirtIO PCM device list.52 * @jacks: VirtIO jacks.53 * @njacks: Number of jacks.54 * @substreams: VirtIO PCM substreams.55 * @nsubstreams: Number of PCM substreams.56 * @chmaps: VirtIO channel maps.57 * @nchmaps: Number of channel maps.58 * @kctl_infos: VirtIO control element information.59 * @kctls: VirtIO control elements.60 * @nkctls: Number of control elements.61 */62struct virtio_snd {63	struct virtio_device *vdev;64	struct virtio_snd_queue queues[VIRTIO_SND_VQ_MAX];65	struct snd_card *card;66	struct list_head ctl_msgs;67	struct virtio_snd_event *event_msgs;68	struct list_head pcm_list;69	struct virtio_jack *jacks;70	u32 njacks;71	struct virtio_pcm_substream *substreams;72	u32 nsubstreams;73	struct virtio_snd_chmap_info *chmaps;74	u32 nchmaps;75	struct virtio_snd_ctl_info *kctl_infos;76	struct virtio_kctl *kctls;77	u32 nkctls;78};79 80/* Message completion timeout in milliseconds (module parameter). */81extern u32 virtsnd_msg_timeout_ms;82 83static 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 107static 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	else113		return virtsnd_rx_queue(vss->snd);114}115 116int 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 123int virtsnd_chmap_parse_cfg(struct virtio_snd *snd);124 125int virtsnd_chmap_build_devs(struct virtio_snd *snd);126 127int 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 133#endif /* VIRTIO_SND_CARD_H */134