drivers/media/usb/uvc/uvc_queue.c
Source file repositories/reference/linux-study-clean/drivers/media/usb/uvc/uvc_queue.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/usb/uvc/uvc_queue.c- Extension
.c- Size
- 10997 bytes
- Lines
- 399
- Domain
- Driver Families
- Bucket
- drivers/media
- 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/atomic.hlinux/kernel.hlinux/mm.hlinux/list.hlinux/module.hlinux/usb.hlinux/videodev2.hlinux/vmalloc.hlinux/wait.hmedia/videobuf2-v4l2.hmedia/videobuf2-vmalloc.huvcvideo.h
Detected Declarations
function Copyrightfunction __uvc_queue_return_buffersfunction uvc_queue_return_buffersfunction uvc_queue_setupfunction uvc_buffer_preparefunction uvc_buffer_queuefunction uvc_buffer_finishfunction uvc_start_streaming_videofunction uvc_stop_streaming_videofunction uvc_stop_streaming_metafunction uvc_queue_initfunction uvc_queue_cancelfunction __uvc_queue_get_current_bufferfunction uvc_queue_buffer_requeuefunction uvc_queue_buffer_completefunction uvc_queue_buffer_releasefunction running
Annotated Snippet
vb2_get_plane_payload(vb, 0) > vb2_plane_size(vb, 0)) {
uvc_dbg(queue->stream->dev, CAPTURE,
"[E] Bytes used out of bounds\n");
return -EINVAL;
}
if (unlikely(queue->flags & UVC_QUEUE_DISCONNECTED))
return -ENODEV;
buf->state = UVC_BUF_STATE_QUEUED;
buf->error = 0;
buf->mem = vb2_plane_vaddr(vb, 0);
buf->length = vb2_plane_size(vb, 0);
if (vb->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
buf->bytesused = 0;
else
buf->bytesused = vb2_get_plane_payload(vb, 0);
return 0;
}
static void uvc_buffer_queue(struct vb2_buffer *vb)
{
struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
struct uvc_video_queue *queue = vb2_get_drv_priv(vb->vb2_queue);
struct uvc_buffer *buf = uvc_vbuf_to_buffer(vbuf);
unsigned long flags;
spin_lock_irqsave(&queue->irqlock, flags);
if (likely(!(queue->flags & UVC_QUEUE_DISCONNECTED))) {
kref_init(&buf->ref);
list_add_tail(&buf->queue, &queue->irqqueue);
} else {
/*
* If the device is disconnected return the buffer to userspace
* directly. The next QBUF call will fail with -ENODEV.
*/
buf->state = UVC_BUF_STATE_ERROR;
vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
}
spin_unlock_irqrestore(&queue->irqlock, flags);
}
static void uvc_buffer_finish(struct vb2_buffer *vb)
{
struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
struct uvc_video_queue *queue = vb2_get_drv_priv(vb->vb2_queue);
struct uvc_buffer *buf = uvc_vbuf_to_buffer(vbuf);
if (vb->state == VB2_BUF_STATE_DONE)
uvc_video_clock_update(queue->stream, vbuf, buf);
}
static int uvc_start_streaming_video(struct vb2_queue *vq, unsigned int count)
{
struct uvc_video_queue *queue = vb2_get_drv_priv(vq);
struct uvc_streaming *stream = queue->stream;
int ret;
lockdep_assert_irqs_enabled();
ret = uvc_pm_get(stream->dev);
if (ret)
goto err_buffers;
queue->buf_used = 0;
ret = uvc_video_start_streaming(stream);
if (ret)
goto err_pm;
return 0;
err_pm:
uvc_pm_put(stream->dev);
err_buffers:
uvc_queue_return_buffers(queue, UVC_BUF_STATE_QUEUED);
return ret;
}
static void uvc_stop_streaming_video(struct vb2_queue *vq)
{
struct uvc_video_queue *queue = vb2_get_drv_priv(vq);
struct uvc_streaming *stream = queue->stream;
lockdep_assert_irqs_enabled();
uvc_video_stop_streaming(stream);
Annotation
- Immediate include surface: `linux/atomic.h`, `linux/kernel.h`, `linux/mm.h`, `linux/list.h`, `linux/module.h`, `linux/usb.h`, `linux/videodev2.h`, `linux/vmalloc.h`.
- Detected declarations: `function Copyright`, `function __uvc_queue_return_buffers`, `function uvc_queue_return_buffers`, `function uvc_queue_setup`, `function uvc_buffer_prepare`, `function uvc_buffer_queue`, `function uvc_buffer_finish`, `function uvc_start_streaming_video`, `function uvc_stop_streaming_video`, `function uvc_stop_streaming_meta`.
- Atlas domain: Driver Families / drivers/media.
- 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.