STRUCT VB2_QUEUE(9)
๐ struct vb2_queue(9) ๐
Hiii bestie, welcome to the Kernel API Manual!! ๐ Todayโs main character is struct vb2_queue, aka a videobuf2 queue, and she is literally the blueprint for how buffers get queued, owned, allocated, and streamed. Buckle up, because this struct has lore. ๐ฆ
๐ NAME ๐
struct vb2_queue โ a videobuf2 queue. Thatโs the whole name, bestie, no cap.
๐ฆ SYNOPSIS ๐ฆ
okay so the vibe is this exact struct, and yes every field matters:
struct vb2_queue {
unsigned int type;
unsigned int io_modes;
struct device *dev;
unsigned long dma_attrs;
unsigned int bidirectional:1;
unsigned int fileio_read_once:1;
unsigned int fileio_write_immediately:1;
unsigned int allow_zero_bytesused:1;
unsigned int
quirk_poll_must_check_waiting_for_buffers:1;
unsigned int supports_requests:1;
unsigned int requires_requests:1;
unsigned int uses_qbuf:1;
unsigned int uses_requests:1;
unsigned int allow_cache_hints:1;
unsigned int non_coherent_mem:1;
struct mutex *lock;
void *owner;
const struct vb2_ops *ops;
const struct vb2_mem_ops *mem_ops;
const struct vb2_buf_ops *buf_ops;
void *drv_priv;
u32 subsystem_flags;
unsigned int buf_struct_size;
u32 timestamp_flags;
gfp_t gfp_flags;
u32 min_queued_buffers;
u32 min_reqbufs_allocation;
struct device *alloc_devs[VB2_MAX_PLANES];
};
๐ Members ๐
typeโ this is the private buffer type, and the vb2-core caller defines what it means. For V4L2 girlies, it should match the types defined onenum v4l2_buf_type. ๐io_modesโ the supported io methods for this queue; peepenum vb2_io_modesfor the menu. โจdevโ the device used for the default allocation context when the driver doesnโt fill in thealloc_devsarray. ๐ซถdma_attrsโ the DMA attributes to use for the DMA. Simple as that. ๐bidirectionalโ when this flag is set, the DMA direction for the buffers of this queue gets overridden with theDMA_BIDIRECTIONALdirection. This is useful when the hardware/firmware writes to a buffer thatโs mapped as read (DMA_TO_DEVICE), or reads from a buffer mapped for write (DMA_FROM_DEVICE), because of some internal hardware restrictions or because it adds padding needed by the processing algorithm. But listen: if the DMA mapping is not bidirectional and the hardware/firmware tries to access the buffer in the opposite direction, this could lead to IOMMU protection faults. ๐fileio_read_onceโ reportEOFafter reading the first buffer. ๐fileio_write_immediatelyโ queue the buffer after each write call. ๐ธallow_zero_bytesusedโ allowbytesused == 0to be passed to the driver. โจquirk_poll_must_check_waiting_for_buffersโ returnEPOLLERRat poll whenQBUFhas not been called. This is a vb1 idiom that has been adopted also by vb2. Quirky, but valid. ๐supports_requestsโ this queue supports the Request API. ๐requires_requestsโ this queue requires the Request API. If this is set to1, thensupports_requestsmust be set to1as well. No exceptions, bestie. ๐จuses_qbufโqbufwas used directly for this queue. It gets set to1the first time this is called, and set to0when the queue is canceled. If this is1, then you cannot queue buffers from a request. ๐ฅuses_requestsโ requests are used for this queue. It gets set to1the first time a request is queued, and set to0when the queue is canceled. If this is1, then you cannot queue buffers directly. ๐allow_cache_hintsโ when set, user-space can pass cache management hints in order to skip cache flush/invalidation on->prepareor/and->finish. ๐งnon_coherent_memโ when set, the queue will attempt to allocate buffers using non-coherent memory. ๐lockโ pointer to a mutex that protects thestruct vb2_queue. The driver must set this to a mutex to let the v4l2 core serialize the queuing ioctls. This lock is used when waiting for a new buffer to arrive: the lock is released, we wait for the new buffer, and then itโs retaken. ๐ownerโ the filehandle that โownsโ the buffers, i.e. the filehandle that calledreqbufs,create_buffersor startedfileio. This field is not used by the videobuf2 core API, but it allows drivers to easily associate an owner filehandle with the queue. ๐ซถopsโ driver-specific callbacks. ๐ ๏ธmem_opsโ memory allocator specific callbacks. ๐งbuf_opsโ callbacks to deliver buffer information between user-space and kernel-space. ๐ฌdrv_privโ driver private data. ๐subsystem_flagsโ flags specific to the subsystem (V4L2/DVB/etc.). Not used by the vb2 core. ๐๏ธbuf_struct_sizeโ size of the driver-specific buffer structure;"0"indicates the driver doesnโt want to use a custom buffer structure type. In that case a subsystem-specific struct will be used (in the case of V4L2 that issizeof(struct vb2_v4l2_buffer)). The first field of the driver-specific buffer structure must be the subsystem-specific struct (vb2_v4l2_bufferin the case of V4L2). ๐timestamp_flagsโ timestamp flags;V4L2_BUF_FLAG_TIMESTAMP_*andV4L2_BUF_FLAG_TSTAMP_SRC_*. โฐgfp_flagsโ additional gfp flags used when allocating the buffers. Typically this is0, but it may be e.g.GFP_DMAor__GFP_DMA32to force the buffer allocation to a specific memory zone. ๐ฑmin_queued_buffersโ the minimum number of queued buffers needed beforestart_streamingcan be called. Used when a DMA engine cannot be started unless at least this number of buffers have been queued into the driver.VIDIOC_REQBUFSwill ensure at leastmin_queued_buffers + 1buffers will be allocated. Note thatVIDIOC_CREATE_BUFSwill not modify the requested buffer count. ๐ฆmin_reqbufs_allocationโ the minimum number of buffers to be allocated when callingVIDIOC_REQBUFS. Note thatVIDIOC_CREATE_BUFSwill not modify the requested buffer count and does not use this field. Drivers can set this if there has to be a certain number of buffers available for the hardware to work effectively. This allows callingVIDIOC_REQBUFSwith a buffer count of1and it will be automatically adjusted to a workable buffer count. If set, thenmin_reqbufs_allocationmust be larger thanmin_queued_buffers + 1. If this field is> 3, then it is highly recommended that the driver implements theV4L2_CID_MIN_BUFFERS_FOR_CAPTURE/OUTPUTcontrol. ๐งฎalloc_devsโstruct devicememory type/allocator-specific per-plane device. ๐งฉ
๐ SEE ALSO ๐
Kernel file ./include/media/videobuf2-core.h โ and the whole friend group is:
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)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_mmap(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)
okay bye bestie!! ๐ this page came from ./include/media, dated October 2026, and itโs all the lore for struct vb2_queue(9) โจ๐
๐ฆ 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