From: Benjamin Gaignard <benjamin.gaignard@collabora.com>
To: hverkuil@xs4all.nl, mchehab@kernel.org, tfiga@chromium.org,
m.szyprowski@samsung.com, matt.ranostay@konsulko.com
Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org,
linux-staging@lists.linux.dev, kernel@collabora.com,
Benjamin Gaignard <benjamin.gaignard@collabora.com>
Subject: [PATCH 35/55] videobuf2: core: Add min_dma_buffers_needed field to vb2_queue
Date: Mon, 27 Nov 2023 17:54:34 +0100 [thread overview]
Message-ID: <20231127165454.166373-36-benjamin.gaignard@collabora.com> (raw)
In-Reply-To: <20231127165454.166373-1-benjamin.gaignard@collabora.com>
'min_dma_buffers_needed' field is to clarify 'min_buffers_needed'
purpose versus 'min_reqbufs_allocation' usage.
'min_buffers_needed' is still used in few drivers so directly
rename it would be problematic.
The both will live together while fixing the drivers to use
'min_dma_buffers_needed' field instead.
Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
---
.../media/common/videobuf2/videobuf2-core.c | 28 ++++++++++++++-----
include/media/videobuf2-core.h | 7 +++++
2 files changed, 28 insertions(+), 7 deletions(-)
diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c
index c224d13b3105..a6ec55db8635 100644
--- a/drivers/media/common/videobuf2/videobuf2-core.c
+++ b/drivers/media/common/videobuf2/videobuf2-core.c
@@ -816,7 +816,7 @@ static bool verify_coherency_flags(struct vb2_queue *q, bool non_coherent_mem)
int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory,
unsigned int flags, unsigned int *count)
{
- unsigned int num_buffers, allocated_buffers, num_planes = 0;
+ unsigned int num_buffers, allocated_buffers, min_reqbufs_needed, num_planes = 0;
unsigned int q_num_bufs = vb2_get_num_buffers(q);
unsigned plane_sizes[VB2_MAX_PLANES] = { };
bool non_coherent_mem = flags & V4L2_MEMORY_FLAG_NON_COHERENT;
@@ -866,7 +866,11 @@ 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_buffers_needed);
- num_buffers = max_t(unsigned int, num_buffers, q->min_reqbufs_allocation);
+ if (q->min_reqbufs_allocation)
+ num_buffers = max_t(unsigned int, num_buffers, q->min_reqbufs_allocation);
+ else
+ num_buffers = max_t(unsigned int, num_buffers, q->min_dma_buffers_needed + 1);
+ min_reqbufs_needed = num_buffers;
num_buffers = min_t(unsigned int, num_buffers, q->max_num_buffers);
memset(q->alloc_devs, 0, sizeof(q->alloc_devs));
/*
@@ -918,7 +922,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_buffers_needed)
+ if (allocated_buffers < min_reqbufs_needed)
ret = -ENOMEM;
/*
@@ -1654,7 +1658,7 @@ EXPORT_SYMBOL_GPL(vb2_core_prepare_buf);
* @q: videobuf2 queue
*
* Attempt to start streaming. When this function is called there must be
- * at least q->min_buffers_needed buffers queued up (i.e. the minimum
+ * at least q->min_dma_buffers_needed queued up (i.e. the minimum
* number of buffers required for the DMA engine to function). If the
* @start_streaming op fails it is supposed to return all the driver-owned
* buffers back to vb2 in state QUEUED. Check if that happened and if
@@ -1847,7 +1851,8 @@ int vb2_core_qbuf(struct vb2_queue *q, struct vb2_buffer *vb, void *pb,
* then we can finally call start_streaming().
*/
if (q->streaming && !q->start_streaming_called &&
- q->queued_count >= q->min_buffers_needed) {
+ ((q->queued_count >= q->min_buffers_needed) ||
+ (q->queued_count >= q->min_dma_buffers_needed))) {
ret = vb2_start_streaming(q);
if (ret) {
/*
@@ -2217,6 +2222,12 @@ int vb2_core_streamon(struct vb2_queue *q, unsigned int type)
return -EINVAL;
}
+ if (q_num_bufs < q->min_dma_buffers_needed) {
+ dprintk(q, 1, "need at least %u allocated buffers\n",
+ q->min_dma_buffers_needed);
+ return -EINVAL;
+ }
+
ret = call_qop(q, prepare_streaming, q);
if (ret)
return ret;
@@ -2225,7 +2236,8 @@ int vb2_core_streamon(struct vb2_queue *q, unsigned int type)
* Tell driver to start streaming provided sufficient buffers
* are available.
*/
- if (q->queued_count >= q->min_buffers_needed) {
+ if (q->queued_count >= q->min_buffers_needed &&
+ q->queued_count >= q->min_dma_buffers_needed) {
ret = vb2_start_streaming(q);
if (ret)
goto unprepare;
@@ -2505,6 +2517,7 @@ int vb2_core_queue_init(struct vb2_queue *q)
return -EINVAL;
if (WARN_ON(q->max_num_buffers > MAX_BUFFER_INDEX) ||
+ WARN_ON(q->min_dma_buffers_needed > q->max_num_buffers) ||
WARN_ON(q->min_buffers_needed > q->max_num_buffers))
return -EINVAL;
@@ -2519,7 +2532,8 @@ int vb2_core_queue_init(struct vb2_queue *q)
* in that request) will always succeed. There is no method of
* propagating an error back to userspace.
*/
- if (WARN_ON(q->supports_requests && q->min_buffers_needed))
+ if (WARN_ON(q->supports_requests &&
+ (q->min_buffers_needed || q->min_dma_buffers_needed)))
return -EINVAL;
INIT_LIST_HEAD(&q->queued_list);
diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h
index 17cacd696ab4..0bc97f28a7ea 100644
--- a/include/media/videobuf2-core.h
+++ b/include/media/videobuf2-core.h
@@ -549,10 +549,16 @@ struct vb2_buf_ops {
* @min_buffers_needed: the minimum number of buffers needed before
* @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. (Deprecated)
+ * @min_dma_buffers_needed: the minimum number of buffers needed before
+ * @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.
* @min_reqbufs_allocation: the minimum number of buffers allocated when
* calling VIDIOC_REQBUFS. Used when drivers need a to
* specify a minimum buffers allocation before setup a queue.
+ * If set to 0 then min_dma_buffers_needed + 1 value is used
+ * as minimum numbers of buffers value.
*/
/*
* Private elements (won't appear at the uAPI book):
@@ -618,6 +624,7 @@ struct vb2_queue {
u32 timestamp_flags;
gfp_t gfp_flags;
u32 min_buffers_needed;
+ u32 min_dma_buffers_needed;
u32 min_reqbufs_allocation;
struct device *alloc_devs[VB2_MAX_PLANES];
--
2.39.2
next prev parent reply other threads:[~2023-11-27 16:55 UTC|newest]
Thread overview: 75+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-27 16:53 [PATCH 00/55] Clean up queue_setup()/min_buffers_needed (ab)use Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 01/55] videobuf2: Add min_reqbufs_allocation field to vb2_queue structure Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 02/55] media: test-drivers: Stop abusing of min_buffers_needed field Benjamin Gaignard
2023-11-27 17:00 ` Shuah Khan
2023-11-28 9:27 ` Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 03/55] media: usb: cx231xx: " Benjamin Gaignard
2023-11-28 10:18 ` Hans Verkuil
2023-11-28 10:23 ` Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 04/55] media: usb: dvb-usb: cxusb-analog: " Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 05/55] media: usb: gspca: " Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 06/55] media: atmel: " Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 07/55] media: imx8-isi: " Benjamin Gaignard
2023-11-27 17:07 ` Laurent Pinchart
2023-11-28 9:31 ` Benjamin Gaignard
2023-11-28 9:35 ` Tomasz Figa
2023-11-28 10:26 ` Benjamin Gaignard
2023-11-29 4:17 ` Tomasz Figa
2023-11-29 8:28 ` Benjamin Gaignard
2023-11-29 8:39 ` Tomasz Figa
2023-11-29 10:24 ` Laurent Pinchart
2023-11-28 10:31 ` Laurent Pinchart
2023-12-07 18:33 ` Nicolas Dufresne
2023-11-27 16:54 ` [PATCH 08/55] media: imx7-media-csi: " Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 09/55] media: chips-media: coda: " Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 10/55] media: nuvoton: " Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 11/55] media: sti: hva: " Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 12/55] media: rockchip: rkisp1: " Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 13/55] media: aspeed: " Benjamin Gaignard
2023-11-27 19:26 ` Eddie James
2023-11-27 16:54 ` [PATCH 14/55] media: microchip: " Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 15/55] media: amphion: " Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 16/55] media: qcom: venus: " Benjamin Gaignard
2023-11-28 10:26 ` Hans Verkuil
2023-11-29 9:48 ` Tomasz Figa
2023-11-27 16:54 ` [PATCH 17/55] media: sun4i-csi: " Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 18/55] media: sunxi: sun8i-di: " Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 19/55] media: sun8i-rotate: " Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 20/55] media: sunxi: sun6i-csi: " Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 21/55] media: i2c: video-i2c: " Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 22/55] media: dvb-core: " Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 23/55] media: imx: " Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 24/55] media: atmel: " Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 25/55] media: ipu3: " Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 26/55] media: starfive: " Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 27/55] media: sun6i-isp: " Benjamin Gaignard
2023-11-29 13:40 ` Paul Kocialkowski
2023-11-29 14:03 ` Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 28/55] media: tegra-video: " Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 29/55] media: ti: am437x: " Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 30/55] media: ti: cal: " Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 31/55] media: ti: davinci: " Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 32/55] media: saa7146: " Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 33/55] input: touchscreen: atmel: " Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 34/55] input: touchscreen: sur40: " Benjamin Gaignard
2023-11-27 16:54 ` Benjamin Gaignard [this message]
2023-11-27 16:54 ` [PATCH 36/55] media: stm32: stm32-dcmi: Use min_dma_buffers_needed field Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 37/55] media: renesas: " Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 38/55] media: ti: j721e-csi2rx: " Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 39/55] media: ti: omap: " Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 40/55] samples: v4l2: pci: " Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 41/55] media: pci: intel: ipu3: " Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 42/55] media: pci: dt3155: " Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 43/55] media: pci: bt8xx: " Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 44/55] media: pci: cx18: " Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 45/55] media: pci: mgb4: " Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 46/55] media: pci: tw68: " Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 47/55] media: pci: cx25821: " Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 48/55] media: pci: tw5864: " Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 49/55] media: pci: tw686x: " Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 50/55] media: pci: cx88: " Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 51/55] media: pci: cx23885: " Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 52/55] media: pci: zoran: " Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 53/55] media: pci: cobalt: " Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 54/55] media: meson: vdec: " Benjamin Gaignard
2023-11-27 16:54 ` [PATCH 55/55] media: videobuf2: core: Remove 'min_buffers_needed' field Benjamin Gaignard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231127165454.166373-36-benjamin.gaignard@collabora.com \
--to=benjamin.gaignard@collabora.com \
--cc=hverkuil@xs4all.nl \
--cc=kernel@collabora.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=m.szyprowski@samsung.com \
--cc=matt.ranostay@konsulko.com \
--cc=mchehab@kernel.org \
--cc=tfiga@chromium.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox