From: Benjamin Gaignard <benjamin.gaignard@collabora.com>
To: mchehab@kernel.org, tfiga@chromium.org, m.szyprowski@samsung.com,
ming.qian@nxp.com, ezequiel@vanguardiasur.com.ar,
p.zabel@pengutronix.de, gregkh@linuxfoundation.org,
hverkuil-cisco@xs4all.nl, nicolas.dufresne@collabora.com
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org,
linux-arm-msm@vger.kernel.org,
linux-rockchip@lists.infradead.org,
linux-staging@lists.linux.dev, kernel@collabora.com,
Benjamin Gaignard <benjamin.gaignard@collabora.com>
Subject: [PATCH v4 03/10] media: videobuf2: Rework offset 'cookie' encoding pattern
Date: Wed, 5 Jul 2023 14:10:49 +0200 [thread overview]
Message-ID: <20230705121056.37017-4-benjamin.gaignard@collabora.com> (raw)
In-Reply-To: <20230705121056.37017-1-benjamin.gaignard@collabora.com>
Change how offset 'cookie' field value is computed to make possible
to use more buffers.
With this encoding pattern we know the maximum number that a queue
could store so we can check ing at queue init time.
It also make easier and faster to find buffer and plane from using
the offset field.
Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
---
.../media/common/videobuf2/videobuf2-core.c | 63 +++++++++----------
1 file changed, 29 insertions(+), 34 deletions(-)
diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c
index 77e69b01d88d..70e36389b704 100644
--- a/drivers/media/common/videobuf2/videobuf2-core.c
+++ b/drivers/media/common/videobuf2/videobuf2-core.c
@@ -31,6 +31,10 @@
#include <trace/events/vb2.h>
+#define PLANE_INDEX_SHIFT 3
+#define PLANE_INDEX_MASK 0x7
+#define MAX_BUFFERS 0xffff
+
static int debug;
module_param(debug, int, 0644);
@@ -358,29 +362,23 @@ static void __setup_offsets(struct vb2_buffer *vb)
unsigned int plane;
unsigned long off = 0;
- if (vb->index) {
- struct vb2_buffer *prev;
- struct vb2_plane *p;
-
- prev = vb2_get_buffer(q, vb->index - 1);
- if (!prev) {
- dprintk(q, 1, "can't find the requested buffer\n");
- return;
- }
-
- p = &prev->planes[prev->num_planes - 1];
-
- off = PAGE_ALIGN(p->m.offset + p->length);
- }
+ /*
+ * Offsets cookies value have the following constraints:
+ * - a buffer could have up to 8 planes.
+ * - v4l2 mem2mem use bit 30 to distinguish between source and destination buffers.
+ * - must be page aligned
+ * That led to this bit mapping:
+ * |30 |29 15|14 12|11 0|
+ * |DST_QUEUE_OFF_BASE|buffer index|plane index| 0 |
+ * where there is 16 bits to store buffer index.
+ */
+ off = vb->index << (PLANE_INDEX_SHIFT + PAGE_SHIFT);
for (plane = 0; plane < vb->num_planes; ++plane) {
- vb->planes[plane].m.offset = off;
+ vb->planes[plane].m.offset = off + (plane << PAGE_SHIFT);
dprintk(q, 3, "buffer %d, plane %d offset 0x%08lx\n",
vb->index, plane, off);
-
- off += vb->planes[plane].length;
- off = PAGE_ALIGN(off);
}
}
@@ -2294,24 +2292,18 @@ static int __find_plane_by_offset(struct vb2_queue *q, unsigned long off,
return -EBUSY;
}
- /*
- * Go over all buffers and their planes, comparing the given offset
- * with an offset assigned to each plane. If a match is found,
- * return its buffer and plane numbers.
- */
- for (buffer = 0; buffer < q->num_buffers; ++buffer) {
- vb = vb2_get_buffer(q, buffer);
+ /* Get buffer and plane from the offset */
+ buffer = (off >> (PLANE_INDEX_SHIFT + PAGE_SHIFT)) & MAX_BUFFERS;
+ plane = (off >> PAGE_SHIFT) & PLANE_INDEX_MASK;
- if (!vb)
- continue;
+ vb = vb2_get_buffer(q, buffer);
+ if (!vb)
+ return -EINVAL;
- for (plane = 0; plane < vb->num_planes; ++plane) {
- if (vb->planes[plane].m.offset == off) {
- *_buffer = buffer;
- *_plane = plane;
- return 0;
- }
- }
+ if (vb->planes[plane].m.offset == off) {
+ *_buffer = buffer;
+ *_plane = plane;
+ return 0;
}
return -EINVAL;
@@ -2552,6 +2544,9 @@ int vb2_core_queue_init(struct vb2_queue *q)
if (!q->max_allowed_buffers)
q->max_allowed_buffers = VB2_MAX_FRAME;
+ /* The maximum is limited by offset cookie encoding pattern */
+ q->max_allowed_buffers = min_t(unsigned int, q->max_allowed_buffers, MAX_BUFFERS);
+
q->bufs = kcalloc(q->max_allowed_buffers, sizeof(*q->bufs), GFP_KERNEL);
if (q->buf_struct_size == 0)
--
2.39.2
next prev parent reply other threads:[~2023-07-05 12:11 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-05 12:10 [PATCH v4 00/10] Add DELETE_BUF ioctl Benjamin Gaignard
2023-07-05 12:10 ` [PATCH v4 01/10] media: videobuf2: Access vb2_queue bufs array through helper functions Benjamin Gaignard
2023-08-21 14:24 ` Hans Verkuil
2023-08-21 14:31 ` Hans Verkuil
2023-08-22 12:49 ` Benjamin Gaignard
2023-07-05 12:10 ` [PATCH v4 02/10] media: videobuf2: Be more flexible on the number of queue stored buffers Benjamin Gaignard
2023-07-05 12:10 ` Benjamin Gaignard [this message]
2023-07-05 12:10 ` [PATCH v4 04/10] media: verisilicon: Refactor postprocessor to store more buffers Benjamin Gaignard
2023-08-21 14:38 ` Hans Verkuil
2023-07-05 12:10 ` [PATCH v4 05/10] media: verisilicon: Store chroma and motion vectors offset Benjamin Gaignard
2023-08-21 14:41 ` Hans Verkuil
2023-08-22 12:55 ` Benjamin Gaignard
2023-07-05 12:10 ` [PATCH v4 06/10] media: verisilicon: vp9: Use destination buffer height to compute chroma offset Benjamin Gaignard
2023-07-05 12:10 ` [PATCH v4 07/10] media: verisilicon: postproc: Fix down scale test Benjamin Gaignard
2023-07-05 12:10 ` [PATCH v4 08/10] media: verisilicon: vp9: Allow to change resolution while streaming Benjamin Gaignard
2023-07-05 12:10 ` [PATCH v4 09/10] media: v4l2: Add DELETE_BUFS ioctl Benjamin Gaignard
2023-07-05 12:10 ` [PATCH v4 10/10] media: v4l2: Add mem2mem helpers for " 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=20230705121056.37017-4-benjamin.gaignard@collabora.com \
--to=benjamin.gaignard@collabora.com \
--cc=ezequiel@vanguardiasur.com.ar \
--cc=gregkh@linuxfoundation.org \
--cc=hverkuil-cisco@xs4all.nl \
--cc=kernel@collabora.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=linux-staging@lists.linux.dev \
--cc=m.szyprowski@samsung.com \
--cc=mchehab@kernel.org \
--cc=ming.qian@nxp.com \
--cc=nicolas.dufresne@collabora.com \
--cc=p.zabel@pengutronix.de \
--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