From patchwork Mon Feb 6 04:33:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Randy Li X-Patchwork-Id: 52979 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2049484wrn; Sun, 5 Feb 2023 20:36:01 -0800 (PST) X-Google-Smtp-Source: AK7set/LKkfZaLgec41MgbBWBaFB0oEIbDBs+fmL1UzzewfvaAJCxkWIbnuQ9BbO+MlLN/Cqa9Xs X-Received: by 2002:a17:907:8a1c:b0:78d:f456:1ed0 with SMTP id sc28-20020a1709078a1c00b0078df4561ed0mr11281895ejc.33.1675658161695; Sun, 05 Feb 2023 20:36:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675658161; cv=none; d=google.com; s=arc-20160816; b=HBRQ8YJDJH0dQX460o5gizh0MQq4bkPwo0/IS9cOVrL9F1ZFGTvlw8IaKcqvesRyES 5RXwVM39BPLn6d0s/+OOpbBF0dRGFTK0CRunB5qPDXZ9EvRL14xAYfyRX9K1ihWOa6fU GOhGM7C7ZpfubqJzkL262TD5v4yPcRHASwyIoUmuGadW0ey7jwhmMDjJKini3irv20kq 8h0Xx2VO0Q0tx9ZKeM1DE7pqpMgfQfZI3+WwHLxpZcKLc5xklr/M7mp+XKpHqbUPUdm5 cdYgAm5vcMqwoxZjRxc8s2DI3tzcnPa0pYalowJBd5VITik/N3gOgCWJXY2w6Oqd6SU+ ixtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=TLZE0dc57xBdoK7K8LaU2bPbRs6LHNTcHmgQNb7D1Zo=; b=jAF97A+jT0/JwvgyXDpM463c487OLwJrEPUxXuf8/KGS3dxC7Ou5z1f2FthelEc9aF fCGnJtniOX14DPMyQhu0xXKt9moJmnWiP+FvdqRNaGVbbhLBUvz2p8tkXIOZs5O2b7X+ BLuRk4UKAm/6ilE/AYeFWGLRkNoS+Ny03TyzHTClbvtkWm1/p77Ag8tvLrPR7sMilFF1 ec7Kdcbby6TM0fOWf9vTc8ESObR+ooh53xxtl/YL4acQdTTj6HSvxgK4YQsOXz5TGynU /fHh6BtSRQDMgNvb2GBM611LVCy7qWcQEPvUdfjDCRD9ysbuzeExNw7EnBwXY0jQ7O7K i7eA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id eb11-20020a0564020d0b00b0049dc6d14d61si10312873edb.63.2023.02.05.20.35.38; Sun, 05 Feb 2023 20:36:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229501AbjBFEeZ (ORCPT + 99 others); Sun, 5 Feb 2023 23:34:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229558AbjBFEeO (ORCPT ); Sun, 5 Feb 2023 23:34:14 -0500 Received: from kozue.soulik.info (kozue.soulik.info [IPv6:2001:19f0:7000:8404:5054:ff:fe75:428f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE1FE19F02; Sun, 5 Feb 2023 20:34:02 -0800 (PST) Received: from misaki.sumomo.pri (unknown [192.168.0.134]) by kozue.soulik.info (Postfix) with ESMTPA id 9F426100DAB; Mon, 6 Feb 2023 13:33:48 +0900 (JST) From: ayaka To: linux-media@vger.kernel.org Cc: randy.li@synaptics.com, Brian.Starkey@arm.com, boris.brezillon@collabora.com, frkoenig@chromium.org, hans.verkuil@cisco.com, hiroh@chromium.org, hverkuil@xs4all.nl, kernel@collabora.com, laurent.pinchart@ideasonboard.com, linux-kernel@vger.kernel.org, mchehab@kernel.org, narmstrong@baylibre.com, nicolas@ndufresne.ca, sakari.ailus@iki.fi, stanimir.varbanov@linaro.org, tfiga@chromium.org, Helen Koike Subject: [PATCH v7 4/9] media: videobuf2-v4l2: reorganize flags handling Date: Mon, 6 Feb 2023 12:33:03 +0800 Message-Id: <20230206043308.28365-5-ayaka@soulik.info> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230206043308.28365-1-ayaka@soulik.info> References: <20230206043308.28365-1-ayaka@soulik.info> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757054932944378636?= X-GMAIL-MSGID: =?utf-8?q?1757054932944378636?= From: Helen Koike 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 --- Changes in v7: - Refresh and rebase 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 1f5d235a8441..eb158de7d14a 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -173,6 +173,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; @@ -309,41 +346,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) { if (!vb2_queue_allows_cache_hints(q)) { /* @@ -351,15 +361,15 @@ 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; } - if (b->flags & V4L2_BUF_FLAG_NO_CACHE_INVALIDATE) + if (*flags & V4L2_BUF_FLAG_NO_CACHE_INVALIDATE) vb->skip_cache_sync_on_finish = 1; - if (b->flags & V4L2_BUF_FLAG_NO_CACHE_CLEAN) + if (*flags & V4L2_BUF_FLAG_NO_CACHE_CLEAN) vb->skip_cache_sync_on_prepare = 1; } @@ -407,7 +417,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); @@ -485,6 +495,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 @@ -546,51 +608,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); } /*