// SPDX-License-Identifier: GPL-2.0+ /* * virtio-snd: Virtio sound device * Copyright (C) 2021 OpenSynergy GmbH */ #include <linux/moduleparam.h> #include <linux/virtio_config.h> #include "virtio_card.h" /** * struct virtio_snd_msg - Control message. * @sg_request: Scattergather list containing a device request (header). * @sg_response: Scattergather list containing a device response (status). * @list: Pending message list entry. * @notify: Request completed notification. * @ref_count: Reference count used to manage a message lifetime. */ struct virtio_snd_msg { … }; /** * virtsnd_ctl_msg_ref() - Increment reference counter for the message. * @msg: Control message. * * Context: Any context. */ void virtsnd_ctl_msg_ref(struct virtio_snd_msg *msg) { … } /** * virtsnd_ctl_msg_unref() - Decrement reference counter for the message. * @msg: Control message. * * The message will be freed when the ref_count value is 0. * * Context: Any context. */ void virtsnd_ctl_msg_unref(struct virtio_snd_msg *msg) { … } /** * virtsnd_ctl_msg_request() - Get a pointer to the request header. * @msg: Control message. * * Context: Any context. */ void *virtsnd_ctl_msg_request(struct virtio_snd_msg *msg) { … } /** * virtsnd_ctl_msg_response() - Get a pointer to the response header. * @msg: Control message. * * Context: Any context. */ void *virtsnd_ctl_msg_response(struct virtio_snd_msg *msg) { … } /** * virtsnd_ctl_msg_alloc() - Allocate and initialize a control message. * @request_size: Size of request header. * @response_size: Size of response header. * @gfp: Kernel flags for memory allocation. * * The message will be automatically freed when the ref_count value is 0. * * Context: Any context. May sleep if @gfp flags permit. * Return: Allocated message on success, NULL on failure. */ struct virtio_snd_msg *virtsnd_ctl_msg_alloc(size_t request_size, size_t response_size, gfp_t gfp) { … } /** * virtsnd_ctl_msg_send() - Send a control message. * @snd: VirtIO sound device. * @msg: Control message. * @out_sgs: Additional sg-list to attach to the request header (may be NULL). * @in_sgs: Additional sg-list to attach to the response header (may be NULL). * @nowait: Flag indicating whether to wait for completion. * * Context: Any context. Takes and releases the control queue spinlock. * May sleep if @nowait is false. * Return: 0 on success, -errno on failure. */ int virtsnd_ctl_msg_send(struct virtio_snd *snd, struct virtio_snd_msg *msg, struct scatterlist *out_sgs, struct scatterlist *in_sgs, bool nowait) { … } /** * virtsnd_ctl_msg_complete() - Complete a control message. * @msg: Control message. * * Context: Any context. Expects the control queue spinlock to be held by * caller. */ void virtsnd_ctl_msg_complete(struct virtio_snd_msg *msg) { … } /** * virtsnd_ctl_msg_cancel_all() - Cancel all pending control messages. * @snd: VirtIO sound device. * * Context: Any context. */ void virtsnd_ctl_msg_cancel_all(struct virtio_snd *snd) { … } /** * virtsnd_ctl_query_info() - Query the item configuration from the device. * @snd: VirtIO sound device. * @command: Control request code (VIRTIO_SND_R_XXX_INFO). * @start_id: Item start identifier. * @count: Item count to query. * @size: Item information size in bytes. * @info: Buffer for storing item information. * * Context: Any context that permits to sleep. * Return: 0 on success, -errno on failure. */ int virtsnd_ctl_query_info(struct virtio_snd *snd, int command, int start_id, int count, size_t size, void *info) { … } /** * virtsnd_ctl_notify_cb() - Process all completed control messages. * @vqueue: Underlying control virtqueue. * * This callback function is called upon a vring interrupt request from the * device. * * Context: Interrupt context. Takes and releases the control queue spinlock. */ void virtsnd_ctl_notify_cb(struct virtqueue *vqueue) { … }