/** * enum pcm_msg_sg_index - Index values for the virtio_pcm_msg->sgs field in * an I/O message. * @PCM_MSG_SG_XFER: Element containing a virtio_snd_pcm_xfer structure. * @PCM_MSG_SG_STATUS: Element containing a virtio_snd_pcm_status structure. * @PCM_MSG_SG_DATA: The first element containing a data buffer.
*/ enum pcm_msg_sg_index {
PCM_MSG_SG_XFER = 0,
PCM_MSG_SG_STATUS,
PCM_MSG_SG_DATA
};
/** * virtsnd_pcm_sg_num() - Count the number of sg-elements required to represent * vmalloc'ed buffer. * @data: Pointer to vmalloc'ed buffer. * @length: Buffer size. * * Context: Any context. * Return: Number of physically contiguous parts in the @data.
*/ staticint virtsnd_pcm_sg_num(u8 *data, unsignedint length)
{
phys_addr_t sg_address; unsignedint sg_length; int num = 0;
/** * virtsnd_pcm_sg_from() - Build sg-list from vmalloc'ed buffer. * @sgs: Preallocated sg-list to populate. * @nsgs: The maximum number of elements in the @sgs. * @data: Pointer to vmalloc'ed buffer. * @length: Buffer size. * * Splits the buffer into physically contiguous parts and makes an sg-list of * such parts. * * Context: Any context.
*/ staticvoid virtsnd_pcm_sg_from(struct scatterlist *sgs, int nsgs, u8 *data, unsignedint length)
{ int idx = -1;
while (length) { struct page *pg = vmalloc_to_page(data);
size_t pg_length;
/** * virtsnd_pcm_msg_alloc() - Allocate I/O messages. * @vss: VirtIO PCM substream. * @periods: Current number of periods. * @period_bytes: Current period size in bytes. * * The function slices the buffer into @periods parts (each with the size of * @period_bytes), and creates @periods corresponding I/O messages. * * Context: Any context that permits to sleep. * Return: 0 on success, -ENOMEM on failure.
*/ int virtsnd_pcm_msg_alloc(struct virtio_pcm_substream *vss, unsignedint periods, unsignedint period_bytes)
{ struct snd_pcm_runtime *runtime = vss->substream->runtime; unsignedint i;
vss->msgs = kcalloc(periods, sizeof(*vss->msgs), GFP_KERNEL); if (!vss->msgs) return -ENOMEM;
vss->nmsgs = periods;
for (i = 0; i < periods; ++i) {
u8 *data = runtime->dma_area + period_bytes * i; int sg_num = virtsnd_pcm_sg_num(data, period_bytes); struct virtio_pcm_msg *msg;
for (i = 0; vss->msgs && i < vss->nmsgs; ++i)
kfree(vss->msgs[i]);
kfree(vss->msgs);
vss->msgs = NULL;
vss->nmsgs = 0;
}
/** * virtsnd_pcm_msg_send() - Send asynchronous I/O messages. * @vss: VirtIO PCM substream. * @offset: starting position that has been updated * @bytes: number of bytes that has been updated * * All messages are organized in an ordered circular list. Each time the * function is called, all currently non-enqueued messages are added to the * virtqueue. For this, the function uses offset and bytes to calculate the * messages that need to be added. * * Context: Any context. Expects the tx/rx queue and the VirtIO substream * spinlocks to be held by caller. * Return: 0 on success, -errno on failure.
*/ int virtsnd_pcm_msg_send(struct virtio_pcm_substream *vss, unsignedlong offset, unsignedlong bytes)
{ struct virtio_snd *snd = vss->snd; struct virtio_device *vdev = snd->vdev; struct virtqueue *vqueue = virtsnd_pcm_queue(vss)->vqueue; unsignedlong period_bytes = snd_pcm_lib_period_bytes(vss->substream); unsignedlong start, end, i; unsignedint msg_count = vss->msg_count; bool notify = false; int rc;
if (rc) {
dev_err(&vdev->dev, "SID %u: failed to send I/O message\n",
vss->sid); return rc;
}
vss->msg_count++;
}
offset = 0;
bytes -= n;
}
if (msg_count == vss->msg_count) return 0;
if (!(vss->features & (1U << VIRTIO_SND_PCM_F_MSG_POLLING)))
notify = virtqueue_kick_prepare(vqueue);
if (notify)
virtqueue_notify(vqueue);
return 0;
}
/** * virtsnd_pcm_msg_pending_num() - Returns the number of pending I/O messages. * @vss: VirtIO substream. * * Context: Any context. * Return: Number of messages.
*/ unsignedint virtsnd_pcm_msg_pending_num(struct virtio_pcm_substream *vss)
{ unsignedint num; unsignedlong flags;
spin_lock_irqsave(&vss->lock, flags);
num = vss->msg_count;
spin_unlock_irqrestore(&vss->lock, flags);
return num;
}
/** * virtsnd_pcm_msg_complete() - Complete an I/O message. * @msg: I/O message. * @written_bytes: Number of bytes written to the message. * * Completion of the message means the elapsed period. If transmission is * allowed, then each completed message is immediately placed back at the end * of the queue. * * For the playback substream, @written_bytes is equal to sizeof(msg->status). * * For the capture substream, @written_bytes is equal to sizeof(msg->status) * plus the number of captured bytes. * * Context: Interrupt context. Takes and releases the VirtIO substream spinlock.
*/ staticvoid virtsnd_pcm_msg_complete(struct virtio_pcm_msg *msg,
size_t written_bytes)
{ struct virtio_pcm_substream *vss = msg->substream;
/* * hw_ptr always indicates the buffer position of the first I/O message * in the virtqueue. Therefore, on each completion of an I/O message, * the hw_ptr value is unconditionally advanced.
*/
spin_lock(&vss->lock); /* * If the capture substream returned an incorrect status, then just * increase the hw_ptr by the message size.
*/ if (vss->direction == SNDRV_PCM_STREAM_PLAYBACK ||
written_bytes <= sizeof(msg->status))
vss->hw_ptr += msg->length; else
vss->hw_ptr += written_bytes - sizeof(msg->status);
if (vss->hw_ptr >= vss->buffer_bytes)
vss->hw_ptr -= vss->buffer_bytes;
msg->length = 0;
vss->xfer_xrun = false;
vss->msg_count--;
if (vss->xfer_enabled) { struct snd_pcm_runtime *runtime = vss->substream->runtime;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.