linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Helen Koike <helen.koike@collabora.com>
To: linux-media@vger.kernel.org
Cc: hverkuil@xs4all.nl, mchehab@kernel.org, hans.verkuil@cisco.com,
	laurent.pinchart@ideasonboard.com, sakari.ailus@iki.fi,
	boris.brezillon@collabora.com, hiroh@chromium.org,
	nicolas@ndufresne.ca, Brian.Starkey@arm.com,
	kernel@collabora.com, narmstrong@baylibre.com,
	linux-kernel@vger.kernel.org, frkoenig@chromium.org,
	stanimir.varbanov@linaro.org, tfiga@chromium.org
Subject: [RFC PATCH v6 04/11] media: videobuf2-v4l2: reorganize flags handling
Date: Thu, 14 Jan 2021 15:07:31 -0300	[thread overview]
Message-ID: <20210114180738.1758707-5-helen.koike@collabora.com> (raw)
In-Reply-To: <20210114180738.1758707-1-helen.koike@collabora.com>

Reorganize flags handling to be easily reuseble when Ext functions get
added.
No logic is changed, just moving around code.

- Two new functions:
	v4l2_clear_buffer_flags()
	vb2_fill_vb2_v4l2_buffer_flags()
- set_buffer_cache_hints() receives a pointer to flags instead of the
  v4l2_buffer object, making it undependent of this struct.

Signed-off-by: Helen Koike <helen.koike@collabora.com>

---
Changes in v6:
- New patch
---
 .../media/common/videobuf2/videobuf2-v4l2.c   | 176 ++++++++++--------
 1 file changed, 97 insertions(+), 79 deletions(-)

diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c
index bb642c0775d1..aa4f17ec0982 100644
--- a/drivers/media/common/videobuf2/videobuf2-v4l2.c
+++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c
@@ -174,6 +174,43 @@ static void vb2_warn_zero_bytesused(struct vb2_buffer *vb)
 		pr_warn("use the actual size instead.\n");
 }
 
+static void
+vb2_fill_vb2_v4l2_buffer_flags(struct vb2_buffer *vb,
+			       u32 type, u32 field, u32 flags)
+{
+	struct vb2_queue *q = vb->vb2_queue;
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+
+	/* Zero flags that we handle */
+	vbuf->flags = flags & ~V4L2_BUFFER_MASK_FLAGS;
+	if (!vb->vb2_queue->copy_timestamp || V4L2_TYPE_IS_CAPTURE(type)) {
+		/*
+		 * Non-COPY timestamps and non-OUTPUT queues will get
+		 * their timestamp and timestamp source flags from the
+		 * queue.
+		 */
+		vbuf->flags &= ~V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
+	}
+
+	if (V4L2_TYPE_IS_OUTPUT(type)) {
+		/*
+		 * For output buffers mask out the timecode flag:
+		 * this will be handled later in vb2_qbuf().
+		 * The 'field' is valid metadata for this output buffer
+		 * and so that needs to be copied here.
+		 */
+		vbuf->flags &= ~V4L2_BUF_FLAG_TIMECODE;
+		vbuf->field = field;
+		if (!(q->subsystem_flags & VB2_V4L2_FL_SUPPORTS_M2M_HOLD_CAPTURE_BUF))
+			vbuf->flags &= ~V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF;
+	} else {
+		/* Zero any output buffer flags as this is a capture buffer */
+		vbuf->flags &= ~V4L2_BUFFER_OUT_FLAGS;
+		/* Zero last flag, this is a signal from driver to userspace */
+		vbuf->flags &= ~V4L2_BUF_FLAG_LAST;
+	}
+}
+
 static int vb2_fill_vb2_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b)
 {
 	struct vb2_queue *q = vb->vb2_queue;
@@ -310,41 +347,14 @@ static int vb2_fill_vb2_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b
 
 	}
 
-	/* Zero flags that we handle */
-	vbuf->flags = b->flags & ~V4L2_BUFFER_MASK_FLAGS;
-	if (!vb->vb2_queue->copy_timestamp || V4L2_TYPE_IS_CAPTURE(b->type)) {
-		/*
-		 * Non-COPY timestamps and non-OUTPUT queues will get
-		 * their timestamp and timestamp source flags from the
-		 * queue.
-		 */
-		vbuf->flags &= ~V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
-	}
-
-	if (V4L2_TYPE_IS_OUTPUT(b->type)) {
-		/*
-		 * For output buffers mask out the timecode flag:
-		 * this will be handled later in vb2_qbuf().
-		 * The 'field' is valid metadata for this output buffer
-		 * and so that needs to be copied here.
-		 */
-		vbuf->flags &= ~V4L2_BUF_FLAG_TIMECODE;
-		vbuf->field = b->field;
-		if (!(q->subsystem_flags & VB2_V4L2_FL_SUPPORTS_M2M_HOLD_CAPTURE_BUF))
-			vbuf->flags &= ~V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF;
-	} else {
-		/* Zero any output buffer flags as this is a capture buffer */
-		vbuf->flags &= ~V4L2_BUFFER_OUT_FLAGS;
-		/* Zero last flag, this is a signal from driver to userspace */
-		vbuf->flags &= ~V4L2_BUF_FLAG_LAST;
-	}
+	vb2_fill_vb2_v4l2_buffer_flags(vb, b->type, b->field, b->flags);
 
 	return 0;
 }
 
 static void set_buffer_cache_hints(struct vb2_queue *q,
 				   struct vb2_buffer *vb,
-				   struct v4l2_buffer *b)
+				   u32 *flags)
 {
 	/*
 	 * DMA exporter should take care of cache syncs, so we can avoid
@@ -370,8 +380,8 @@ static void set_buffer_cache_hints(struct vb2_queue *q,
 		 * space hints. That's to indicate to userspace that these
 		 * flags won't work.
 		 */
-		b->flags &= ~V4L2_BUF_FLAG_NO_CACHE_INVALIDATE;
-		b->flags &= ~V4L2_BUF_FLAG_NO_CACHE_CLEAN;
+		*flags &= ~V4L2_BUF_FLAG_NO_CACHE_INVALIDATE;
+		*flags &= ~V4L2_BUF_FLAG_NO_CACHE_CLEAN;
 		return;
 	}
 
@@ -382,10 +392,10 @@ static void set_buffer_cache_hints(struct vb2_queue *q,
 	if (q->dma_dir == DMA_TO_DEVICE)
 		vb->need_cache_sync_on_finish = 0;
 
-	if (b->flags & V4L2_BUF_FLAG_NO_CACHE_INVALIDATE)
+	if (*flags & V4L2_BUF_FLAG_NO_CACHE_INVALIDATE)
 		vb->need_cache_sync_on_finish = 0;
 
-	if (b->flags & V4L2_BUF_FLAG_NO_CACHE_CLEAN)
+	if (*flags & V4L2_BUF_FLAG_NO_CACHE_CLEAN)
 		vb->need_cache_sync_on_prepare = 0;
 }
 
@@ -433,7 +443,7 @@ static int vb2_queue_or_prepare_buf(struct vb2_queue *q, struct media_device *md
 	}
 
 	if (!vb->prepared) {
-		set_buffer_cache_hints(q, vb, b);
+		set_buffer_cache_hints(q, vb, &b->flags);
 		/* Copy relevant information provided by the userspace */
 		memset(vbuf->planes, 0,
 		       sizeof(vbuf->planes[0]) * vb->num_planes);
@@ -511,6 +521,58 @@ static int vb2_queue_or_prepare_buf(struct vb2_queue *q, struct media_device *md
 	return 0;
 }
 
+/*
+ * Clear any buffer state related flags.
+ */
+static void v4l2_clear_buffer_flags(struct vb2_buffer *vb, u32 *flags,
+				    struct vb2_queue *q,
+				    struct vb2_v4l2_buffer *vbuf,
+				    u32* request_fd)
+{
+	*flags &= ~V4L2_BUFFER_MASK_FLAGS;
+	*flags |= q->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK;
+	if (!q->copy_timestamp) {
+		/*
+		 * For non-COPY timestamps, drop timestamp source bits
+		 * and obtain the timestamp source from the queue.
+		 */
+		*flags &= ~V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
+		*flags |= q->timestamp_flags & V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
+	}
+
+	switch (vb->state) {
+	case VB2_BUF_STATE_QUEUED:
+	case VB2_BUF_STATE_ACTIVE:
+		*flags |= V4L2_BUF_FLAG_QUEUED;
+		break;
+	case VB2_BUF_STATE_IN_REQUEST:
+		*flags |= V4L2_BUF_FLAG_IN_REQUEST;
+		break;
+	case VB2_BUF_STATE_ERROR:
+		*flags |= V4L2_BUF_FLAG_ERROR;
+		fallthrough;
+	case VB2_BUF_STATE_DONE:
+		*flags |= V4L2_BUF_FLAG_DONE;
+		break;
+	case VB2_BUF_STATE_PREPARING:
+	case VB2_BUF_STATE_DEQUEUED:
+		/* nothing */
+		break;
+	}
+
+	if ((vb->state == VB2_BUF_STATE_DEQUEUED ||
+	     vb->state == VB2_BUF_STATE_IN_REQUEST) &&
+	    vb->synced && vb->prepared)
+		*flags |= V4L2_BUF_FLAG_PREPARED;
+
+	if (vb2_buffer_in_use(q, vb))
+		*flags |= V4L2_BUF_FLAG_MAPPED;
+	if (vbuf->request_fd >= 0) {
+		*flags |= V4L2_BUF_FLAG_REQUEST_FD;
+		*request_fd = vbuf->request_fd;
+	}
+}
+
 /*
  * __fill_v4l2_buffer() - fill in a struct v4l2_buffer with information to be
  * returned to userspace
@@ -572,51 +634,7 @@ static void __fill_v4l2_buffer(struct vb2_buffer *vb, void *pb)
 			b->m.fd = vb->planes[0].m.fd;
 	}
 
-	/*
-	 * Clear any buffer state related flags.
-	 */
-	b->flags &= ~V4L2_BUFFER_MASK_FLAGS;
-	b->flags |= q->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK;
-	if (!q->copy_timestamp) {
-		/*
-		 * For non-COPY timestamps, drop timestamp source bits
-		 * and obtain the timestamp source from the queue.
-		 */
-		b->flags &= ~V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
-		b->flags |= q->timestamp_flags & V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
-	}
-
-	switch (vb->state) {
-	case VB2_BUF_STATE_QUEUED:
-	case VB2_BUF_STATE_ACTIVE:
-		b->flags |= V4L2_BUF_FLAG_QUEUED;
-		break;
-	case VB2_BUF_STATE_IN_REQUEST:
-		b->flags |= V4L2_BUF_FLAG_IN_REQUEST;
-		break;
-	case VB2_BUF_STATE_ERROR:
-		b->flags |= V4L2_BUF_FLAG_ERROR;
-		fallthrough;
-	case VB2_BUF_STATE_DONE:
-		b->flags |= V4L2_BUF_FLAG_DONE;
-		break;
-	case VB2_BUF_STATE_PREPARING:
-	case VB2_BUF_STATE_DEQUEUED:
-		/* nothing */
-		break;
-	}
-
-	if ((vb->state == VB2_BUF_STATE_DEQUEUED ||
-	     vb->state == VB2_BUF_STATE_IN_REQUEST) &&
-	    vb->synced && vb->prepared)
-		b->flags |= V4L2_BUF_FLAG_PREPARED;
-
-	if (vb2_buffer_in_use(q, vb))
-		b->flags |= V4L2_BUF_FLAG_MAPPED;
-	if (vbuf->request_fd >= 0) {
-		b->flags |= V4L2_BUF_FLAG_REQUEST_FD;
-		b->request_fd = vbuf->request_fd;
-	}
+	v4l2_clear_buffer_flags(vb, &b->flags, q, vbuf, &b->request_fd);
 }
 
 /*
-- 
2.29.2


  parent reply	other threads:[~2021-01-14 18:08 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-14 18:07 [RFC PATCH v6 00/11] media: v4l2: Add extended fmt and buffer ioctls Helen Koike
2021-01-14 18:07 ` [RFC PATCH v6 01/11] media: v4l2-common: add normalized pixelformat field to struct v4l2_format_info Helen Koike
2021-02-10 12:37   ` Dafna Hirschfeld
2021-01-14 18:07 ` [RFC PATCH v6 02/11] media: v4l2: Extend pixel formats to unify single/multi-planar handling (and more) Helen Koike
2021-02-10 15:02   ` Dafna Hirschfeld
2021-02-23 12:35   ` Hans Verkuil
2021-02-24 15:12     ` Helen Koike
2022-11-05 15:19       ` Hsia-Jun Li
2022-11-06 19:24         ` Laurent Pinchart
2022-11-07  1:54           ` Hsia-Jun Li
2022-11-07  8:28             ` Laurent Pinchart
2022-11-07  8:49               ` Hsia-Jun Li
2022-11-06 22:11         ` Dmitry Osipenko
2022-11-07  2:04           ` Hsia-Jun Li
2022-11-07  8:30           ` Laurent Pinchart
2022-11-08 14:58             ` Dmitry Osipenko
2022-11-07 16:50           ` Fritz Koenig
2022-11-07  8:42         ` Hans Verkuil
2022-11-10 17:06         ` Nicolas Dufresne
2022-11-11  3:03           ` Hsia-Jun Li
2022-11-11  5:48             ` Tomasz Figa
2022-11-11  6:30               ` Hsia-Jun Li
2022-11-11  8:52                 ` Tomasz Figa
2022-11-11  9:13                   ` Hsia-Jun Li
2022-11-15 16:03                   ` Nicolas Dufresne
2022-11-16 12:38                     ` ayaka
2022-11-11  8:42               ` Laurent Pinchart
2022-11-11  8:54                 ` Tomasz Figa
2022-11-15 16:19                   ` Nicolas Dufresne
2022-11-15 15:57             ` Nicolas Dufresne
2021-01-14 18:07 ` [RFC PATCH v6 03/11] media: v4l2: Add extended buffer (de)queue operations for video types Helen Koike
2021-02-23 12:58   ` Hans Verkuil
2023-01-26  7:07     ` ayaka
     [not found]   ` <20230125200026.16643-1-ayaka@soulik.info>
2023-01-26  8:57     ` Hans Verkuil
2023-01-26 11:02       ` Laurent Pinchart
2023-01-26 18:36         ` ayaka
2023-01-27  8:11           ` Hans Verkuil
2023-01-30 10:07             ` Hsia-Jun Li
2023-01-30 12:17               ` Hans Verkuil
2021-01-14 18:07 ` Helen Koike [this message]
2021-01-14 18:07 ` [RFC PATCH v6 05/11] media: videobuf2: Expose helpers for Ext qbuf/dqbuf Helen Koike
2021-01-14 18:07 ` [RFC PATCH v6 06/11] media: vivid: use vb2_ioctls_ext_{d}qbuf hooks Helen Koike
2021-01-14 18:07 ` [RFC PATCH v6 07/11] media: vimc: " Helen Koike
2021-01-14 18:07 ` [RFC PATCH v6 08/11] media: mediabus: Add helpers to convert a ext_pix format to/from a mbus_fmt Helen Koike
2021-01-14 18:07 ` [RFC PATCH v6 09/11] media: vivid: Convert to v4l2_ext_pix_format Helen Koike
2021-01-14 18:07 ` [RFC PATCH v6 10/11] media: vimc: " Helen Koike
2021-01-14 18:07 ` [RFC PATCH v6 11/11] media: docs: add documentation for the Extended API Helen Koike
2021-02-05 18:39 ` [RFC PATCH v6 00/11] media: v4l2: Add extended fmt and buffer ioctls Helen Koike

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=20210114180738.1758707-5-helen.koike@collabora.com \
    --to=helen.koike@collabora.com \
    --cc=Brian.Starkey@arm.com \
    --cc=boris.brezillon@collabora.com \
    --cc=frkoenig@chromium.org \
    --cc=hans.verkuil@cisco.com \
    --cc=hiroh@chromium.org \
    --cc=hverkuil@xs4all.nl \
    --cc=kernel@collabora.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=narmstrong@baylibre.com \
    --cc=nicolas@ndufresne.ca \
    --cc=sakari.ailus@iki.fi \
    --cc=stanimir.varbanov@linaro.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;
as well as URLs for NNTP newsgroup(s).