drivers/gpu/drm/virtio/virtgpu_vq.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/virtio/virtgpu_vq.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/virtio/virtgpu_vq.c- Extension
.c- Size
- 42877 bytes
- Lines
- 1494
- Domain
- Driver Families
- Bucket
- drivers/gpu
- 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/dma-mapping.hlinux/virtio.hlinux/virtio_config.hlinux/virtio_ring.hdrm/drm_edid.hdrm/drm_print.hvirtgpu_drv.hvirtgpu_trace.h
Detected Declarations
function Copyrightfunction virtio_gpu_ctrl_ackfunction virtio_gpu_cursor_ackfunction virtio_gpu_alloc_vbufsfunction virtio_gpu_free_vbufsfunction virtio_gpu_panic_get_vbuffunction virtio_gpu_get_vbuffunction virtio_gpu_vbuf_ctrl_hdrfunction virtio_gpu_alloc_cursorfunction free_vbuffunction reclaim_vbufsfunction virtio_gpu_dequeue_ctrl_funcfunction list_for_each_entryfunction list_for_each_entry_safefunction virtio_gpu_dequeue_cursor_funcfunction list_for_each_entry_safefunction for_each_sgtable_sgfunction virtio_gpu_panic_queue_ctrl_sgsfunction virtio_gpu_queue_ctrl_sgsfunction virtio_gpu_panic_queue_ctrl_bufferfunction virtio_gpu_queue_fenced_ctrl_bufferfunction virtio_gpu_panic_notifyfunction virtio_gpu_notifyfunction virtio_gpu_queue_ctrl_bufferfunction virtio_gpu_queue_cursorfunction virtio_gpu_cmd_create_resourcefunction virtio_gpu_cmd_unref_cbfunction virtio_gpu_cmd_unref_resourcefunction virtio_gpu_cmd_set_scanoutfunction virtio_gpu_panic_cmd_resource_flushfunction virtio_gpu_cmd_resource_flushfunction virtio_gpu_panic_cmd_transfer_to_host_2dfunction virtio_gpu_cmd_transfer_to_host_2dfunction virtio_gpu_cmd_resource_attach_backingfunction virtio_gpu_cmd_resource_detach_backingfunction virtio_gpu_cmd_get_display_info_cbfunction virtio_gpu_cmd_get_capset_info_cbfunction virtio_gpu_cmd_capset_cbfunction virtio_get_edid_blockfunction virtio_gpu_cmd_get_edid_cbfunction virtio_gpu_cmd_get_display_infofunction virtio_gpu_cmd_get_capset_infofunction virtio_gpu_cmd_get_capsetfunction virtio_gpu_cmd_get_edidsfunction virtio_gpu_cmd_context_createfunction virtio_gpu_cmd_context_destroyfunction virtio_gpu_cmd_context_attach_resourcefunction virtio_gpu_cmd_context_detach_resource
Annotated Snippet
if (resp->type != cpu_to_le32(VIRTIO_GPU_RESP_OK_NODATA)) {
if (le32_to_cpu(resp->type) >= VIRTIO_GPU_RESP_ERR_UNSPEC) {
struct virtio_gpu_ctrl_hdr *cmd;
cmd = virtio_gpu_vbuf_ctrl_hdr(entry);
DRM_ERROR_RATELIMITED("response 0x%x (command 0x%x)\n",
le32_to_cpu(resp->type),
le32_to_cpu(cmd->type));
} else
DRM_DEBUG("response 0x%x\n", le32_to_cpu(resp->type));
}
if (resp->flags & cpu_to_le32(VIRTIO_GPU_FLAG_FENCE)) {
fence_id = le64_to_cpu(resp->fence_id);
virtio_gpu_fence_event_process(vgdev, fence_id);
}
if (entry->resp_cb)
entry->resp_cb(vgdev, entry);
}
wake_up(&vgdev->ctrlq.ack_queue);
list_for_each_entry_safe(entry, tmp, &reclaim_list, list) {
if (entry->objs)
virtio_gpu_array_put_free_delayed(vgdev, entry->objs);
list_del(&entry->list);
free_vbuf(vgdev, entry);
}
}
void virtio_gpu_dequeue_cursor_func(struct work_struct *work)
{
struct virtio_gpu_device *vgdev =
container_of(work, struct virtio_gpu_device,
cursorq.dequeue_work);
struct list_head reclaim_list;
struct virtio_gpu_vbuffer *entry, *tmp;
INIT_LIST_HEAD(&reclaim_list);
spin_lock(&vgdev->cursorq.qlock);
do {
virtqueue_disable_cb(vgdev->cursorq.vq);
reclaim_vbufs(vgdev->cursorq.vq, &reclaim_list);
} while (!virtqueue_enable_cb(vgdev->cursorq.vq));
spin_unlock(&vgdev->cursorq.qlock);
list_for_each_entry_safe(entry, tmp, &reclaim_list, list) {
struct virtio_gpu_ctrl_hdr *resp =
(struct virtio_gpu_ctrl_hdr *)entry->resp_buf;
trace_virtio_gpu_cmd_response(vgdev->cursorq.vq, resp, entry->seqno);
list_del(&entry->list);
free_vbuf(vgdev, entry);
}
wake_up(&vgdev->cursorq.ack_queue);
}
/* Create sg_table from a vmalloc'd buffer. */
static struct sg_table *vmalloc_to_sgt(char *data, uint32_t size, int *sg_ents)
{
int ret, s, i;
struct sg_table *sgt;
struct scatterlist *sg;
struct page *pg;
if (WARN_ON(!PAGE_ALIGNED(data)))
return NULL;
sgt = kmalloc_obj(*sgt);
if (!sgt)
return NULL;
*sg_ents = DIV_ROUND_UP(size, PAGE_SIZE);
ret = sg_alloc_table(sgt, *sg_ents, GFP_KERNEL);
if (ret) {
kfree(sgt);
return NULL;
}
for_each_sgtable_sg(sgt, sg, i) {
pg = vmalloc_to_page(data);
if (!pg) {
sg_free_table(sgt);
kfree(sgt);
return NULL;
}
s = min_t(int, PAGE_SIZE, size);
sg_set_page(sg, pg, s, 0);
size -= s;
data += s;
Annotation
- Immediate include surface: `linux/dma-mapping.h`, `linux/virtio.h`, `linux/virtio_config.h`, `linux/virtio_ring.h`, `drm/drm_edid.h`, `drm/drm_print.h`, `virtgpu_drv.h`, `virtgpu_trace.h`.
- Detected declarations: `function Copyright`, `function virtio_gpu_ctrl_ack`, `function virtio_gpu_cursor_ack`, `function virtio_gpu_alloc_vbufs`, `function virtio_gpu_free_vbufs`, `function virtio_gpu_panic_get_vbuf`, `function virtio_gpu_get_vbuf`, `function virtio_gpu_vbuf_ctrl_hdr`, `function virtio_gpu_alloc_cursor`, `function free_vbuf`.
- Atlas domain: Driver Families / drivers/gpu.
- 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.