From patchwork Fri Jan 22 00:57:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 8086311 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: X-Original-To: patchwork-linux-renesas-soc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id EB9DF9F744 for ; Fri, 22 Jan 2016 00:57:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 49AFF2034C for ; Fri, 22 Jan 2016 00:57:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 92E612042A for ; Fri, 22 Jan 2016 00:57:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751249AbcAVA5t (ORCPT ); Thu, 21 Jan 2016 19:57:49 -0500 Received: from galahad.ideasonboard.com ([185.26.127.97]:58725 "EHLO galahad.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751113AbcAVA5s (ORCPT ); Thu, 21 Jan 2016 19:57:48 -0500 Received: from avalon.access.network (nblzone-211-213.nblnetworks.fi [83.145.211.213]) by galahad.ideasonboard.com (Postfix) with ESMTPSA id D033320B64 for ; Fri, 22 Jan 2016 01:56:43 +0100 (CET) From: Laurent Pinchart To: linux-renesas-soc@vger.kernel.org Subject: [PATCH/RFC v2 37/56] vb2: Add helper function to queue request-specific buffer. Date: Fri, 22 Jan 2016 02:57:06 +0200 Message-Id: <1453424245-18782-38-git-send-email-laurent.pinchart+renesas@ideasonboard.com> X-Mailer: git-send-email 2.4.10 In-Reply-To: <1453424245-18782-1-git-send-email-laurent.pinchart+renesas@ideasonboard.com> References: <1453424245-18782-1-git-send-email-laurent.pinchart+renesas@ideasonboard.com> Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Hans Verkuil The vb2_qbuf_request() function will queue any buffers for the given request that are in state PREPARED. Useful when drivers have to implement the req_queue callback. Signed-off-by: Hans Verkuil --- drivers/media/v4l2-core/videobuf2-v4l2.c | 31 +++++++++++++++++++++++++++++++ include/media/videobuf2-v4l2.h | 1 + 2 files changed, 32 insertions(+) diff --git a/drivers/media/v4l2-core/videobuf2-v4l2.c b/drivers/media/v4l2-core/videobuf2-v4l2.c index be0c0ff06979..bbbd8e1b1a99 100644 --- a/drivers/media/v4l2-core/videobuf2-v4l2.c +++ b/drivers/media/v4l2-core/videobuf2-v4l2.c @@ -120,6 +120,9 @@ static void __copy_timestamp(struct vb2_buffer *vb, const void *pb) struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); struct vb2_queue *q = vb->vb2_queue; + if (!pb) + return; + if (q->is_output) { /* * For output buffers copy the timestamp if needed, @@ -193,6 +196,9 @@ static void __fill_v4l2_buffer(struct vb2_buffer *vb, void *pb) struct vb2_queue *q = vb->vb2_queue; unsigned int plane; + if (!pb) + return; + /* Copy back data such as timestamp, flags, etc. */ b->index = vb->index; b->type = vb->type; @@ -622,6 +628,31 @@ int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b) } EXPORT_SYMBOL_GPL(vb2_qbuf); +int vb2_qbuf_request(struct vb2_queue *q, u16 request, struct vb2_buffer **p_buf) +{ + unsigned int buffer; + + for (buffer = 0; buffer < q->num_buffers; buffer++) { + struct vb2_buffer *vb = q->bufs[buffer]; + struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); + + if (vbuf->request == request && + vb->state == VB2_BUF_STATE_PREPARED) { + if (p_buf) + *p_buf = vb; + /* + * The buffer has already been prepared so we can skip + * the vb2_queue_or_prepare_buf() call in vb2_qbuf() and + * call the core function directly. + */ + return vb2_core_qbuf(q, vb->index, NULL); + } + } + + return -ENOENT; +} +EXPORT_SYMBOL_GPL(vb2_qbuf_request); + static int vb2_internal_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool nonblocking) { diff --git a/include/media/videobuf2-v4l2.h b/include/media/videobuf2-v4l2.h index 0c5e47919607..ed1a5753adbd 100644 --- a/include/media/videobuf2-v4l2.h +++ b/include/media/videobuf2-v4l2.h @@ -57,6 +57,7 @@ int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create); int vb2_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b); int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b); +int vb2_qbuf_request(struct vb2_queue *q, u16 request, struct vb2_buffer **p_buf); int vb2_expbuf(struct vb2_queue *q, struct v4l2_exportbuffer *eb); int vb2_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool nonblocking);