vb2_mmap(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– 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 to struct vb2_queue with videobuf2 queue. that's the queue, she's holding everything together, main character energy fr 🫢
  • vma β€” pointer to struct vm_area_struct with the vma passed to the mmap file 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:


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