drivers/media/v4l2-core/v4l2-mem2mem.c
Source file repositories/reference/linux-study-clean/drivers/media/v4l2-core/v4l2-mem2mem.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/v4l2-core/v4l2-mem2mem.c- Extension
.c- Size
- 45138 bytes
- Lines
- 1644
- Domain
- Driver Families
- Bucket
- drivers/media
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/sched.hlinux/slab.hmedia/media-device.hmedia/videobuf2-v4l2.hmedia/v4l2-mem2mem.hmedia/v4l2-dev.hmedia/v4l2-device.hmedia/v4l2-fh.hmedia/v4l2-event.h
Detected Declarations
struct v4l2_m2m_devenum v4l2_m2m_entity_typefunction v4l2_m2m_buf_remove_by_buffunction v4l2_m2m_buf_remove_by_idxfunction v4l2_m2m_try_runfunction __v4l2_m2m_try_queuefunction v4l2_m2m_try_schedulefunction v4l2_m2m_device_run_workfunction v4l2_m2m_cancel_jobfunction v4l2_m2m_buf_done_and_job_finishfunction v4l2_m2m_buf_done_and_job_finishfunction v4l2_m2m_job_finishfunction v4l2_m2m_buf_done_and_job_finishfunction v4l2_m2m_suspendfunction v4l2_m2m_resumefunction v4l2_m2m_reqbufsfunction v4l2_m2m_adjust_mem_offsetfunction v4l2_m2m_querybuffunction v4l2_update_last_buf_statefunction v4l2_update_last_buf_statefunction v4l2_m2m_update_start_streaming_statefunction v4l2_m2m_update_stop_streaming_statefunction v4l2_m2m_force_last_buf_donefunction v4l2_m2m_qbuffunction v4l2_m2m_dqbuffunction v4l2_m2m_prepare_buffunction v4l2_m2m_create_bufsfunction v4l2_m2m_expbuffunction v4l2_m2m_streamonfunction v4l2_m2m_streamofffunction v4l2_m2m_poll_for_datafunction v4l2_m2m_pollfunction v4l2_m2m_mmapfunction v4l2_m2m_get_unmapped_areafunction v4l2_m2m_unregister_media_controllerfunction v4l2_m2m_register_entityfunction v4l2_m2m_register_media_controllerfunction v4l2_m2m_releasefunction v4l2_m2m_getfunction v4l2_m2m_release_from_kreffunction v4l2_m2m_putfunction intfunction v4l2_m2m_ctx_releasefunction v4l2_m2m_buf_queuefunction v4l2_m2m_buf_copy_metadatafunction v4l2_m2m_request_queuefunction list_for_each_entry_safefunction v4l2_m2m_ioctl_reqbufs
Annotated Snippet
struct v4l2_m2m_dev {
struct v4l2_m2m_ctx *curr_ctx;
#ifdef CONFIG_MEDIA_CONTROLLER
struct media_entity *source;
struct media_pad source_pad;
struct media_entity sink;
struct media_pad sink_pad;
struct media_entity proc;
struct media_pad proc_pads[2];
struct media_intf_devnode *intf_devnode;
#endif
struct list_head job_queue;
spinlock_t job_spinlock;
struct work_struct job_work;
unsigned long job_queue_flags;
const struct v4l2_m2m_ops *m2m_ops;
struct kref kref;
};
static struct v4l2_m2m_queue_ctx *get_queue_ctx(struct v4l2_m2m_ctx *m2m_ctx,
enum v4l2_buf_type type)
{
if (V4L2_TYPE_IS_OUTPUT(type))
return &m2m_ctx->out_q_ctx;
else
return &m2m_ctx->cap_q_ctx;
}
struct vb2_queue *v4l2_m2m_get_vq(struct v4l2_m2m_ctx *m2m_ctx,
enum v4l2_buf_type type)
{
return &get_queue_ctx(m2m_ctx, type)->q;
}
EXPORT_SYMBOL(v4l2_m2m_get_vq);
struct vb2_v4l2_buffer *v4l2_m2m_next_buf(struct v4l2_m2m_queue_ctx *q_ctx)
{
struct v4l2_m2m_buffer *b;
unsigned long flags;
spin_lock_irqsave(&q_ctx->rdy_spinlock, flags);
if (list_empty(&q_ctx->rdy_queue)) {
spin_unlock_irqrestore(&q_ctx->rdy_spinlock, flags);
return NULL;
}
b = list_first_entry(&q_ctx->rdy_queue, struct v4l2_m2m_buffer, list);
spin_unlock_irqrestore(&q_ctx->rdy_spinlock, flags);
return &b->vb;
}
EXPORT_SYMBOL_GPL(v4l2_m2m_next_buf);
struct vb2_v4l2_buffer *v4l2_m2m_last_buf(struct v4l2_m2m_queue_ctx *q_ctx)
{
struct v4l2_m2m_buffer *b;
unsigned long flags;
spin_lock_irqsave(&q_ctx->rdy_spinlock, flags);
if (list_empty(&q_ctx->rdy_queue)) {
spin_unlock_irqrestore(&q_ctx->rdy_spinlock, flags);
return NULL;
}
b = list_last_entry(&q_ctx->rdy_queue, struct v4l2_m2m_buffer, list);
spin_unlock_irqrestore(&q_ctx->rdy_spinlock, flags);
return &b->vb;
}
EXPORT_SYMBOL_GPL(v4l2_m2m_last_buf);
struct vb2_v4l2_buffer *v4l2_m2m_buf_remove(struct v4l2_m2m_queue_ctx *q_ctx)
{
struct v4l2_m2m_buffer *b;
unsigned long flags;
spin_lock_irqsave(&q_ctx->rdy_spinlock, flags);
if (list_empty(&q_ctx->rdy_queue)) {
spin_unlock_irqrestore(&q_ctx->rdy_spinlock, flags);
return NULL;
}
b = list_first_entry(&q_ctx->rdy_queue, struct v4l2_m2m_buffer, list);
list_del(&b->list);
q_ctx->num_rdy--;
spin_unlock_irqrestore(&q_ctx->rdy_spinlock, flags);
return &b->vb;
Annotation
- Immediate include surface: `linux/module.h`, `linux/sched.h`, `linux/slab.h`, `media/media-device.h`, `media/videobuf2-v4l2.h`, `media/v4l2-mem2mem.h`, `media/v4l2-dev.h`, `media/v4l2-device.h`.
- Detected declarations: `struct v4l2_m2m_dev`, `enum v4l2_m2m_entity_type`, `function v4l2_m2m_buf_remove_by_buf`, `function v4l2_m2m_buf_remove_by_idx`, `function v4l2_m2m_try_run`, `function __v4l2_m2m_try_queue`, `function v4l2_m2m_try_schedule`, `function v4l2_m2m_device_run_work`, `function v4l2_m2m_cancel_job`, `function v4l2_m2m_buf_done_and_job_finish`.
- Atlas domain: Driver Families / drivers/media.
- Implementation status: integration 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.