vb2_mmap(9)
π vb2_mmap π
okay so we're in the Kernel API Manual today bestie, and the star of the show is vb2_mmap β she maps video buffers into application address space and she does it flawlessly, no cap π
β¨ NAME β¨
vb2_mmap β map video buffers into application address space. literally her whole job π
πΈ SYNOPSIS πΈ
int vb2_mmap (struct vb2_queue *q , struct vm_area_struct *vma );
π¦ ARGUMENTS π¦
qβ pointer tostruct vb2_queuewith videobuf2 queue. that's the queue, she's holding everything together, main character energy fr π«Άvmaβ pointer tostruct vm_area_structwith the vma passed to themmapfile operation handler in the driver. yep, the same vma your driver got handed, just pass her straight through π«
π₯ DESCRIPTION π₯
Should be called from the mmap file operation handler of a driver. like, that's where she lives. π‘
This function maps one plane of one of the available video buffers to userspace. just one plane, okay? don't be greedy. π
To map whole video memory allocated on reqbufs, this function has to be called once per each plane per each buffer previously allocated. so if you've got lots of planes and lots of buffers, yeah, you're calling her a bunch of times. that's just how it is, periodt. π
When the userspace application calls mmap, it passes to it an offset returned to it earlier by the means of v4l2_ioctl_ops->vidioc_querybuf handler. That offset acts as a "cookie", which is then used to identify the plane to be mapped. πͺ yes a cookie. we love a cookie-based identification system, iykyk.
This function finds a plane with a matching offset and a mapping is performed by the means of a provided memory operation. she's out here matching offsets like a matchmaker, lowkey iconic π
The return values from this function are intended to be directly returned from the mmap handler in driver. so don't overthink it β whatever she gives you back, hand it right on up. easy. β¨
ngl the "directly returned" part is not a suggestion, bestie β those return values are meant to go straight back out of your driver's mmap handler, no remixing π
π SEE ALSO π
Kernel file ./include/media/videobuf2-core.h plus this whole iconic friend group:
enum vb2_memory(9)struct vb2_mem_ops(9)struct vb2_plane(9)enum vb2_io_modes(9)enum vb2_buffer_state(9)struct vb2_buffer(9)struct vb2_ops(9)struct vb2_buf_ops(9)struct vb2_queue(9)vb2_queue_allows_cache_hints(9)vb2_plane_vaddr(9)vb2_plane_cookie(9)vb2_buffer_done(9)vb2_discard_done(9)vb2_wait_for_all_buffers(9)vb2_core_querybuf(9)vb2_core_reqbufs(9)vb2_core_create_bufs(9)vb2_core_prepare_buf(9)vb2_core_remove_bufs(9)vb2_core_qbuf(9)vb2_core_dqbuf(9)vb2_core_streamon(9)vb2_core_streamoff(9)vb2_core_expbuf(9)vb2_core_queue_init(9)vb2_core_queue_release(9)vb2_queue_error(9)vb2_get_unmapped_area(9)vb2_core_poll(9)vb2_read(9)vb2_write(9)vb2_thread_fnc(9)vb2_thread_start(9)vb2_thread_stop(9)vb2_is_streaming(9)vb2_fileio_is_active(9)vb2_get_num_buffers(9)vb2_is_busy(9)vb2_get_drv_priv(9)vb2_set_plane_payload(9)vb2_get_plane_payload(9)vb2_plane_size(9)vb2_start_streaming_called(9)vb2_clear_last_buffer_dequeued(9)vb2_get_buffer(9)vb2_buffer_in_use(9)vb2_verify_memory_type(9)vb2_request_object_is_buffer(9)vb2_request_buffer_cnt(9)
that's the whole page bestie, you ate that π
this lil gem comes to you from ./include/media, dated October 2026, and the whole thing is filed under vb2_mmap(9) β go forth and map those planes ππ§ββοΈ
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms