162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0+ */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * virtio-snd: Virtio sound device 462306a36Sopenharmony_ci * Copyright (C) 2021 OpenSynergy GmbH 562306a36Sopenharmony_ci */ 662306a36Sopenharmony_ci#ifndef VIRTIO_SND_MSG_H 762306a36Sopenharmony_ci#define VIRTIO_SND_MSG_H 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci#include <linux/atomic.h> 1062306a36Sopenharmony_ci#include <linux/virtio.h> 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_cistruct virtio_snd; 1362306a36Sopenharmony_cistruct virtio_snd_msg; 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_civoid virtsnd_ctl_msg_ref(struct virtio_snd_msg *msg); 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_civoid virtsnd_ctl_msg_unref(struct virtio_snd_msg *msg); 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_civoid *virtsnd_ctl_msg_request(struct virtio_snd_msg *msg); 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_civoid *virtsnd_ctl_msg_response(struct virtio_snd_msg *msg); 2262306a36Sopenharmony_ci 2362306a36Sopenharmony_cistruct virtio_snd_msg *virtsnd_ctl_msg_alloc(size_t request_size, 2462306a36Sopenharmony_ci size_t response_size, gfp_t gfp); 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ciint virtsnd_ctl_msg_send(struct virtio_snd *snd, struct virtio_snd_msg *msg, 2762306a36Sopenharmony_ci struct scatterlist *out_sgs, 2862306a36Sopenharmony_ci struct scatterlist *in_sgs, bool nowait); 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_ci/** 3162306a36Sopenharmony_ci * virtsnd_ctl_msg_send_sync() - Simplified sending of synchronous message. 3262306a36Sopenharmony_ci * @snd: VirtIO sound device. 3362306a36Sopenharmony_ci * @msg: Control message. 3462306a36Sopenharmony_ci * 3562306a36Sopenharmony_ci * After returning from this function, the message will be deleted. If message 3662306a36Sopenharmony_ci * content is still needed, the caller must additionally to 3762306a36Sopenharmony_ci * virtsnd_ctl_msg_ref/unref() it. 3862306a36Sopenharmony_ci * 3962306a36Sopenharmony_ci * The msg_timeout_ms module parameter defines the message completion timeout. 4062306a36Sopenharmony_ci * If the message is not completed within this time, the function will return an 4162306a36Sopenharmony_ci * error. 4262306a36Sopenharmony_ci * 4362306a36Sopenharmony_ci * Context: Any context that permits to sleep. 4462306a36Sopenharmony_ci * Return: 0 on success, -errno on failure. 4562306a36Sopenharmony_ci * 4662306a36Sopenharmony_ci * The return value is a message status code (VIRTIO_SND_S_XXX) converted to an 4762306a36Sopenharmony_ci * appropriate -errno value. 4862306a36Sopenharmony_ci */ 4962306a36Sopenharmony_cistatic inline int virtsnd_ctl_msg_send_sync(struct virtio_snd *snd, 5062306a36Sopenharmony_ci struct virtio_snd_msg *msg) 5162306a36Sopenharmony_ci{ 5262306a36Sopenharmony_ci return virtsnd_ctl_msg_send(snd, msg, NULL, NULL, false); 5362306a36Sopenharmony_ci} 5462306a36Sopenharmony_ci 5562306a36Sopenharmony_ci/** 5662306a36Sopenharmony_ci * virtsnd_ctl_msg_send_async() - Simplified sending of asynchronous message. 5762306a36Sopenharmony_ci * @snd: VirtIO sound device. 5862306a36Sopenharmony_ci * @msg: Control message. 5962306a36Sopenharmony_ci * 6062306a36Sopenharmony_ci * Context: Any context. 6162306a36Sopenharmony_ci * Return: 0 on success, -errno on failure. 6262306a36Sopenharmony_ci */ 6362306a36Sopenharmony_cistatic inline int virtsnd_ctl_msg_send_async(struct virtio_snd *snd, 6462306a36Sopenharmony_ci struct virtio_snd_msg *msg) 6562306a36Sopenharmony_ci{ 6662306a36Sopenharmony_ci return virtsnd_ctl_msg_send(snd, msg, NULL, NULL, true); 6762306a36Sopenharmony_ci} 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_civoid virtsnd_ctl_msg_cancel_all(struct virtio_snd *snd); 7062306a36Sopenharmony_ci 7162306a36Sopenharmony_civoid virtsnd_ctl_msg_complete(struct virtio_snd_msg *msg); 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_ciint virtsnd_ctl_query_info(struct virtio_snd *snd, int command, int start_id, 7462306a36Sopenharmony_ci int count, size_t size, void *info); 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_civoid virtsnd_ctl_notify_cb(struct virtqueue *vqueue); 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_ci#endif /* VIRTIO_SND_MSG_H */ 79