drivers/media/common/videobuf2/videobuf2-core.c
Source file repositories/reference/linux-study-clean/drivers/media/common/videobuf2/videobuf2-core.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/common/videobuf2/videobuf2-core.c- Extension
.c- Size
- 86082 bytes
- Lines
- 3309
- 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/err.hlinux/kernel.hlinux/module.hlinux/mm.hlinux/poll.hlinux/slab.hlinux/sched.hlinux/freezer.hlinux/kthread.hmedia/videobuf2-core.hmedia/v4l2-mc.htrace/events/vb2.h
Detected Declarations
struct vb2_fileio_bufstruct vb2_fileio_datastruct vb2_threadio_datafunction __vb2_buf_mem_allocfunction __vb2_buf_mem_freefunction __vb2_buf_userptr_putfunction __vb2_plane_dmabuf_putfunction __vb2_buf_dmabuf_putfunction __vb2_buf_mem_preparefunction __vb2_buf_mem_finishfunction __setup_offsetsfunction init_buffer_cache_hintsfunction vb2_queue_add_bufferfunction vb2_queue_remove_bufferfunction __vb2_queue_allocfunction __vb2_free_memfunction __vb2_queue_freefunction vb2_buffer_in_usefunction __buffers_in_usefunction vb2_core_querybuffunction __verify_userptr_opsfunction __verify_mmap_opsfunction __verify_dmabuf_opsfunction vb2_verify_memory_typefunction set_queue_coherencyfunction verify_coherency_flagsfunction vb2_core_allocated_buffers_storagefunction vb2_core_free_buffers_storagefunction vb2_core_reqbufsfunction vb2_core_create_bufsfunction vb2_buffer_donefunction vb2_discard_donefunction __prepare_mmapfunction __prepare_userptrfunction __prepare_dmabuffunction __enqueue_in_driverfunction __buf_preparefunction vb2_req_preparefunction vb2_req_unpreparefunction vb2_req_queuefunction vb2_req_unbindfunction vb2_req_releasefunction vb2_request_object_is_bufferfunction vb2_request_buffer_cntfunction vb2_core_prepare_buffunction vb2_core_remove_bufsfunction vb2_start_streamingfunction start_streaming
Annotated Snippet
struct vb2_fileio_buf {
void *vaddr;
unsigned int size;
unsigned int pos;
unsigned int queued:1;
};
/*
* struct vb2_fileio_data - queue context used by file io emulator
*
* @cur_index: the index of the buffer currently being read from or
* written to. If equal to number of buffers in the vb2_queue
* then a new buffer must be dequeued.
* @initial_index: in the read() case all buffers are queued up immediately
* in __vb2_init_fileio() and __vb2_perform_fileio() just cycles
* buffers. However, in the write() case no buffers are initially
* queued, instead whenever a buffer is full it is queued up by
* __vb2_perform_fileio(). Only once all available buffers have
* been queued up will __vb2_perform_fileio() start to dequeue
* buffers. This means that initially __vb2_perform_fileio()
* needs to know what buffer index to use when it is queuing up
* the buffers for the first time. That initial index is stored
* in this field. Once it is equal to number of buffers in the
* vb2_queue all available buffers have been queued and
* __vb2_perform_fileio() should start the normal dequeue/queue cycle.
*
* vb2 provides a compatibility layer and emulator of file io (read and
* write) calls on top of streaming API. For proper operation it required
* this structure to save the driver state between each call of the read
* or write function.
*/
struct vb2_fileio_data {
unsigned int count;
unsigned int type;
unsigned int memory;
struct vb2_fileio_buf bufs[VB2_MAX_FRAME];
unsigned int cur_index;
unsigned int initial_index;
unsigned int q_count;
unsigned int dq_count;
unsigned read_once:1;
unsigned write_immediately:1;
};
/*
* __vb2_init_fileio() - initialize file io emulator
* @q: videobuf2 queue
* @read: mode selector (1 means read, 0 means write)
*/
static int __vb2_init_fileio(struct vb2_queue *q, int read)
{
struct vb2_fileio_data *fileio;
struct vb2_buffer *vb;
int i, ret;
/*
* Sanity check
*/
if (WARN_ON((read && !(q->io_modes & VB2_READ)) ||
(!read && !(q->io_modes & VB2_WRITE))))
return -EINVAL;
/*
* Check if device supports mapping buffers to kernel virtual space.
*/
if (!q->mem_ops->vaddr)
return -EBUSY;
/*
* Check if streaming api has not been already activated.
*/
if (q->streaming || vb2_get_num_buffers(q) > 0)
return -EBUSY;
dprintk(q, 3, "setting up file io: mode %s, count %d, read_once %d, write_immediately %d\n",
(read) ? "read" : "write", q->min_reqbufs_allocation, q->fileio_read_once,
q->fileio_write_immediately);
fileio = kzalloc_obj(*fileio);
if (fileio == NULL)
return -ENOMEM;
fileio->read_once = q->fileio_read_once;
fileio->write_immediately = q->fileio_write_immediately;
/*
* Request buffers and use MMAP type to force driver
* to allocate buffers by itself.
*/
fileio->count = q->min_reqbufs_allocation;
Annotation
- Immediate include surface: `linux/err.h`, `linux/kernel.h`, `linux/module.h`, `linux/mm.h`, `linux/poll.h`, `linux/slab.h`, `linux/sched.h`, `linux/freezer.h`.
- Detected declarations: `struct vb2_fileio_buf`, `struct vb2_fileio_data`, `struct vb2_threadio_data`, `function __vb2_buf_mem_alloc`, `function __vb2_buf_mem_free`, `function __vb2_buf_userptr_put`, `function __vb2_plane_dmabuf_put`, `function __vb2_buf_dmabuf_put`, `function __vb2_buf_mem_prepare`, `function __vb2_buf_mem_finish`.
- Atlas domain: Driver Families / drivers/media.
- Implementation status: integration implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.