media: videobuf2: Add min_reqbufs_allocation field to vb2_queue structure

Add 'min_reqbufs_allocation' field in the vb2_queue structure so drivers
can specify the minimum number of buffers to allocate when calling
VIDIOC_REQBUFS.
When initializing the queue, v4l2 core makes sure that the following
constraints are respected:
- the minimum number of buffers to allocate must be at least 2 because
one buffer is used by the hardware while the other is being processed
by userspace.
-if the driver needs 'min_queued_buffers' in the queue before calling
start_streaming(), then the minimum requirement is 'min_queued_buffers + 1'
to keep at least one buffer available for userspace.

Simplify __vb2_init_fileio() by using 'min_reqbufs_allocation' directly
to avoid duplicating the minimum number of buffers to allocate computation.

Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
Reviewed-by: Mauro Carvalho Chehab <mchehab@kernel.org>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
This commit is contained in:
Benjamin Gaignard
2024-03-14 16:32:19 +01:00
committed by Hans Verkuil
parent d7cdb5946f
commit 6662edcd32
2 changed files with 37 additions and 16 deletions
+14 -1
View File
@@ -549,9 +549,21 @@ struct vb2_buf_ops {
* @start_streaming can be called. Used when a DMA engine
* cannot be started unless at least this number of buffers
* have been queued into the driver.
* VIDIOC_REQBUFS will ensure at least @min_queued_buffers
* VIDIOC_REQBUFS will ensure at least @min_queued_buffers + 1
* buffers will be allocated. Note that VIDIOC_CREATE_BUFS will not
* modify the requested buffer count.
* @min_reqbufs_allocation: the minimum number of buffers to be allocated when
* calling VIDIOC_REQBUFS. Note that VIDIOC_CREATE_BUFS will *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 calling VIDIOC_REQBUFS with a buffer count of 1 and
* it will be automatically adjusted to a workable buffer count.
* If set, then @min_reqbufs_allocation must be larger than
* @min_queued_buffers + 1.
* If this field is > 3, then it is highly recommended that the
* driver implements the V4L2_CID_MIN_BUFFERS_FOR_CAPTURE/OUTPUT
* control.
* @alloc_devs: &struct device memory type/allocator-specific per-plane device
*/
/*
@@ -622,6 +634,7 @@ struct vb2_queue {
u32 timestamp_flags;
gfp_t gfp_flags;
u32 min_queued_buffers;
u32 min_reqbufs_allocation;
struct device *alloc_devs[VB2_MAX_PLANES];