drivers/usb/gadget/function/uvc_v4l2.c
Source file repositories/reference/linux-study-clean/drivers/usb/gadget/function/uvc_v4l2.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/gadget/function/uvc_v4l2.c- Extension
.c- Size
- 18936 bytes
- Lines
- 746
- Domain
- Driver Families
- Bucket
- drivers/usb
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/device.hlinux/errno.hlinux/kernel.hlinux/list.hlinux/usb/g_uvc.hlinux/usb/uvc.hlinux/videodev2.hlinux/vmalloc.hlinux/wait.hmedia/v4l2-dev.hmedia/v4l2-event.hmedia/v4l2-ioctl.hf_uvc.huvc.huvc_queue.huvc_video.huvc_v4l2.huvc_configfs.h
Detected Declarations
function Copyrightfunction uvc_v4l2_get_bytesperlinefunction uvc_get_frame_sizefunction list_for_each_entryfunction list_for_each_entryfunction list_for_each_entryfunction list_for_each_entryfunction list_for_each_entryfunction list_for_each_entryfunction uvc_send_responsefunction uvc_v4l2_querycapfunction uvc_v4l2_get_formatfunction uvc_v4l2_try_formatfunction uvc_v4l2_set_formatfunction uvc_v4l2_g_parmfunction uvc_v4l2_s_parmfunction uvc_v4l2_enum_frameintervalsfunction list_for_each_entryfunction uvc_v4l2_enum_framesizesfunction uvc_v4l2_enum_formatfunction uvc_v4l2_reqbufsfunction uvc_v4l2_querybuffunction uvc_v4l2_qbuffunction uvc_v4l2_dqbuffunction uvc_v4l2_streamonfunction uvc_v4l2_streamofffunction uvc_v4l2_subscribe_eventfunction uvc_v4l2_disablefunction uvc_v4l2_unsubscribe_eventfunction uvc_v4l2_ioctl_defaultfunction uvc_v4l2_openfunction uvc_v4l2_releasefunction uvc_v4l2_mmapfunction uvc_v4l2_pollfunction uvcg_v4l2_get_unmapped_area
Annotated Snippet
if (index == i) {
uformat = format->fmt;
break;
}
i++;
}
return uformat;
}
static struct uvcg_frame *find_frame_by_index(struct uvc_device *uvc,
struct uvcg_format *uformat,
int index)
{
struct uvcg_format_ptr *format;
struct uvcg_frame_ptr *frame;
struct uvcg_frame *uframe = NULL;
list_for_each_entry(format, &uvc->header->formats, entry) {
if (format->fmt->type != uformat->type)
continue;
list_for_each_entry(frame, &format->fmt->frames, entry) {
if (index == frame->frm->frame.b_frame_index) {
uframe = frame->frm;
break;
}
}
}
return uframe;
}
static struct uvcg_format *find_format_by_pix(struct uvc_device *uvc,
u32 pixelformat)
{
struct uvcg_format_ptr *format;
struct uvcg_format *uformat = NULL;
list_for_each_entry(format, &uvc->header->formats, entry) {
const struct uvc_format_desc *fmtdesc = to_uvc_format(format->fmt);
if (IS_ERR(fmtdesc))
continue;
if (fmtdesc->fcc == pixelformat) {
uformat = format->fmt;
break;
}
}
return uformat;
}
static struct uvcg_frame *find_closest_frame_by_size(struct uvc_device *uvc,
struct uvcg_format *uformat,
u16 rw, u16 rh)
{
struct uvc_video *video = &uvc->video;
struct uvcg_format_ptr *format;
struct uvcg_frame_ptr *frame;
struct uvcg_frame *uframe = NULL;
unsigned int d, maxd;
/* Find the closest image size. The distance between image sizes is
* the size in pixels of the non-overlapping regions between the
* requested size and the frame-specified size.
*/
maxd = (unsigned int)-1;
list_for_each_entry(format, &uvc->header->formats, entry) {
if (format->fmt->type != uformat->type)
continue;
list_for_each_entry(frame, &format->fmt->frames, entry) {
u16 w, h;
w = frame->frm->frame.w_width;
h = frame->frm->frame.w_height;
d = min(w, rw) * min(h, rh);
d = w*h + rw*rh - 2*d;
if (d < maxd) {
maxd = d;
uframe = frame->frm;
}
if (maxd == 0)
break;
}
}
Annotation
- Immediate include surface: `linux/device.h`, `linux/errno.h`, `linux/kernel.h`, `linux/list.h`, `linux/usb/g_uvc.h`, `linux/usb/uvc.h`, `linux/videodev2.h`, `linux/vmalloc.h`.
- Detected declarations: `function Copyright`, `function uvc_v4l2_get_bytesperline`, `function uvc_get_frame_size`, `function list_for_each_entry`, `function list_for_each_entry`, `function list_for_each_entry`, `function list_for_each_entry`, `function list_for_each_entry`, `function list_for_each_entry`, `function uvc_send_response`.
- Atlas domain: Driver Families / drivers/usb.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.