sound/virtio/virtio_card.c
Source file repositories/reference/linux-study-clean/sound/virtio/virtio_card.c
File Facts
- System
- Linux kernel
- Corpus path
sound/virtio/virtio_card.c- Extension
.c- Size
- 10381 bytes
- Lines
- 450
- Domain
- Driver Families
- Bucket
- sound/virtio
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/moduleparam.hlinux/virtio_config.hsound/initval.huapi/linux/virtio_ids.hvirtio_card.h
Detected Declarations
function virtsnd_event_sendfunction virtsnd_event_dispatchfunction virtsnd_event_notify_cbfunction virtsnd_find_vqsfunction virtsnd_enable_event_vqfunction virtsnd_disable_event_vqfunction virtsnd_build_devsfunction virtsnd_validatefunction virtsnd_probefunction virtsnd_removefunction virtsnd_freezefunction virtsnd_restore
Annotated Snippet
while ((event = virtqueue_get_buf(vqueue, &length))) {
virtsnd_event_dispatch(snd, event);
virtsnd_event_send(vqueue, event, true, GFP_ATOMIC);
}
} while (!virtqueue_enable_cb(vqueue));
}
/**
* virtsnd_find_vqs() - Enumerate and initialize all virtqueues.
* @snd: VirtIO sound device.
*
* After calling this function, the event queue is disabled.
*
* Context: Any context.
* Return: 0 on success, -errno on failure.
*/
static int virtsnd_find_vqs(struct virtio_snd *snd)
{
struct virtio_device *vdev = snd->vdev;
struct virtqueue_info vqs_info[VIRTIO_SND_VQ_MAX] = {
[VIRTIO_SND_VQ_CONTROL] = { "virtsnd-ctl",
virtsnd_ctl_notify_cb },
[VIRTIO_SND_VQ_EVENT] = { "virtsnd-event",
virtsnd_event_notify_cb },
[VIRTIO_SND_VQ_TX] = { "virtsnd-tx",
virtsnd_pcm_tx_notify_cb },
[VIRTIO_SND_VQ_RX] = { "virtsnd-rx",
virtsnd_pcm_rx_notify_cb },
};
struct virtqueue *vqs[VIRTIO_SND_VQ_MAX] = { 0 };
unsigned int i;
unsigned int n;
int rc;
rc = virtio_find_vqs(vdev, VIRTIO_SND_VQ_MAX, vqs, vqs_info, NULL);
if (rc) {
dev_err(&vdev->dev, "failed to initialize virtqueues\n");
return rc;
}
for (i = 0; i < VIRTIO_SND_VQ_MAX; ++i)
snd->queues[i].vqueue = vqs[i];
/* Allocate events and populate the event queue */
virtqueue_disable_cb(vqs[VIRTIO_SND_VQ_EVENT]);
n = virtqueue_get_vring_size(vqs[VIRTIO_SND_VQ_EVENT]);
snd->event_msgs = kmalloc_objs(*snd->event_msgs, n);
if (!snd->event_msgs)
return -ENOMEM;
for (i = 0; i < n; ++i)
virtsnd_event_send(vqs[VIRTIO_SND_VQ_EVENT],
&snd->event_msgs[i], false, GFP_KERNEL);
return 0;
}
/**
* virtsnd_enable_event_vq() - Enable the event virtqueue.
* @snd: VirtIO sound device.
*
* Context: Any context.
*/
static void virtsnd_enable_event_vq(struct virtio_snd *snd)
{
struct virtio_snd_queue *queue = virtsnd_event_queue(snd);
if (!virtqueue_enable_cb(queue->vqueue))
virtsnd_event_notify_cb(queue->vqueue);
}
/**
* virtsnd_disable_event_vq() - Disable the event virtqueue.
* @snd: VirtIO sound device.
*
* Context: Any context.
*/
static void virtsnd_disable_event_vq(struct virtio_snd *snd)
{
struct virtio_snd_queue *queue = virtsnd_event_queue(snd);
struct virtio_snd_event *event;
u32 length;
if (queue->vqueue) {
guard(spinlock_irqsave)(&queue->lock);
virtqueue_disable_cb(queue->vqueue);
while ((event = virtqueue_get_buf(queue->vqueue, &length)))
virtsnd_event_dispatch(snd, event);
Annotation
- Immediate include surface: `linux/module.h`, `linux/moduleparam.h`, `linux/virtio_config.h`, `sound/initval.h`, `uapi/linux/virtio_ids.h`, `virtio_card.h`.
- Detected declarations: `function virtsnd_event_send`, `function virtsnd_event_dispatch`, `function virtsnd_event_notify_cb`, `function virtsnd_find_vqs`, `function virtsnd_enable_event_vq`, `function virtsnd_disable_event_vq`, `function virtsnd_build_devs`, `function virtsnd_validate`, `function virtsnd_probe`, `function virtsnd_remove`.
- Atlas domain: Driver Families / sound/virtio.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.