From patchwork Fri Dec 15 09:08:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 754751 Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 99CD618C25; Fri, 15 Dec 2023 09:08:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="nqdzFFEr" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1702631303; bh=NDPl/ie9RRqLQFHhxt5FwuMbdN1XcwnSF9h29cUyGKM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nqdzFFErlPA5FayPgj4A8khMYbwrg7JJ1i6ojtSntXEX/WLT4l86QlOd0rT3KnRsu d2UjJw9U0MyyCsFIDTS4s3qDK88dTIpXivWvz/0H636s+4R2Tcjfv83GjXhyEioigM stoC9S0sun7ki6FEPSEcr7BROjbM75rW7sFc9nDRTWf9NCWEd+tRw2VqD30V+D5A1b trXPyWcw+pfb1Uc01bh8OhyVbV0juq72aMAvsNU5odc5Kfne9Z1HBt5TtCfkW00y5E KRotFV9cm1PJTX6NAjvneL+WjnnybOa/AVaEgAOpF1QCme67baZeQZZ9wBGZZmBO9/ bQtwQwRIKaqYA== Received: from benjamin-XPS-13-9310.. (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: benjamin.gaignard) by madrid.collaboradmins.com (Postfix) with ESMTPSA id B062037814A9; Fri, 15 Dec 2023 09:08:22 +0000 (UTC) From: Benjamin Gaignard To: hverkuil@xs4all.nl, mchehab@kernel.org Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, kernel@collabora.com, Benjamin Gaignard Subject: [PATCH v16 1/8] videobuf2: Add min_reqbufs_allocation field to vb2_queue structure Date: Fri, 15 Dec 2023 10:08:06 +0100 Message-Id: <20231215090813.15610-2-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231215090813.15610-1-benjamin.gaignard@collabora.com> References: <20231215090813.15610-1-benjamin.gaignard@collabora.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add 'min_reqbufs_allocation' field in vb2_queue structure so drivers can specificy the minimum number of buffers to allocate when calling VIDIOC_REQBUFS. If used this minimum should be higher than the minimum number of queued buffers needed to start streaming. Signed-off-by: Benjamin Gaignard --- drivers/media/common/videobuf2/videobuf2-core.c | 10 ++++++++-- include/media/videobuf2-core.h | 13 +++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index 41a832dd1426..a183edf11586 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -865,7 +865,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, /* * Make sure the requested values and current defaults are sane. */ - num_buffers = max_t(unsigned int, *count, q->min_queued_buffers); + num_buffers = max_t(unsigned int, *count, q->min_reqbufs_allocation); num_buffers = min_t(unsigned int, num_buffers, q->max_num_buffers); memset(q->alloc_devs, 0, sizeof(q->alloc_devs)); /* @@ -917,7 +917,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, * There is no point in continuing if we can't allocate the minimum * number of buffers needed by this vb2_queue. */ - if (allocated_buffers < q->min_queued_buffers) + if (allocated_buffers < q->min_reqbufs_allocation) ret = -ENOMEM; /* @@ -2521,6 +2521,12 @@ int vb2_core_queue_init(struct vb2_queue *q) if (WARN_ON(q->supports_requests && q->min_queued_buffers)) return -EINVAL; + q->min_reqbufs_allocation = max_t(unsigned int, + q->min_reqbufs_allocation, + q->min_queued_buffers + 1); + if (WARN_ON(q->min_reqbufs_allocation > q->max_num_buffers)) + return -EINVAL; + INIT_LIST_HEAD(&q->queued_list); INIT_LIST_HEAD(&q->done_list); spin_lock_init(&q->done_lock); diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h index 56719a26a46c..7b84b4e2e273 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h @@ -553,6 +553,18 @@ struct vb2_buf_ops { * VIDIOC_REQBUFS will ensure at least @min_queued_buffers * 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. Drivers can set this if there has to + * be a certain number of buffers available for the hardware to + * work effectively. If set, then @min_reqbufs_allocation must be + * larger than @min_queued_buffers + 1. + * This field is only used by VIDIOC_REQBUFS. This allows calling + * that ioctl with a buffer count of 1 and it will be automatically + * adjusted to a workable buffer count. VIDIOC_CREATE_BUFS will not + * modify the requested buffer count. + * If this field is > 3, then it is highly recommended that the + * driver implements the V4L2_CID_MIN_BUFFERS_FOR_CAPTURE/OUTPUT + * control. */ /* * Private elements (won't appear at the uAPI book): @@ -618,6 +630,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];