From patchwork Sat Mar 10 00:09:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 10272599 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 92D5B60594 for ; Sat, 10 Mar 2018 00:10:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 82B1C2A059 for ; Sat, 10 Mar 2018 00:10:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 73EDC2A057; Sat, 10 Mar 2018 00:10:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF4182A053 for ; Sat, 10 Mar 2018 00:10:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932866AbeCJAK4 (ORCPT ); Fri, 9 Mar 2018 19:10:56 -0500 Received: from bin-mail-out-05.binero.net ([195.74.38.228]:23793 "EHLO bin-vsp-out-02.atm.binero.net" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932857AbeCJAKy (ORCPT ); Fri, 9 Mar 2018 19:10:54 -0500 X-Halon-ID: 75fc61ae-23f7-11e8-9bc6-005056917f90 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA id 75fc61ae-23f7-11e8-9bc6-005056917f90; Sat, 10 Mar 2018 01:10:38 +0100 (CET) From: =?UTF-8?q?Niklas=20S=C3=B6derlund?= To: Laurent Pinchart , Hans Verkuil , linux-media@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, tomoharu.fukawa.eb@renesas.com, =?UTF-8?q?Niklas=20S=C3=B6derlund?= Subject: [PATCH 2/3] rcar-vin: allocate a scratch buffer at stream start Date: Sat, 10 Mar 2018 01:09:52 +0100 Message-Id: <20180310000953.25366-3-niklas.soderlund+renesas@ragnatech.se> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180310000953.25366-1-niklas.soderlund+renesas@ragnatech.se> References: <20180310000953.25366-1-niklas.soderlund+renesas@ragnatech.se> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Before starting capturing allocate a scratch buffer which can be used by the driver to give to the hardware if no buffers are available from userspace. The buffer is not used in this patch but prepares for future refactoring where the scratch buffer can be used to avoid the need to fallback on single capture mode if userspace don't queue buffers as fast as the VIN driver consumes them. Signed-off-by: Niklas Söderlund Reviewed-by: Kieran Bingham --- drivers/media/platform/rcar-vin/rcar-dma.c | 19 +++++++++++++++++++ drivers/media/platform/rcar-vin/rcar-vin.h | 4 ++++ 2 files changed, 23 insertions(+) diff --git a/drivers/media/platform/rcar-vin/rcar-dma.c b/drivers/media/platform/rcar-vin/rcar-dma.c index b4be75d5009080f7..8ea73cdc9a720abe 100644 --- a/drivers/media/platform/rcar-vin/rcar-dma.c +++ b/drivers/media/platform/rcar-vin/rcar-dma.c @@ -1070,6 +1070,17 @@ static int rvin_start_streaming(struct vb2_queue *vq, unsigned int count) unsigned long flags; int ret; + /* Allocate scratch buffer. */ + vin->scratch = dma_alloc_coherent(vin->dev, vin->format.sizeimage, + &vin->scratch_phys, GFP_KERNEL); + if (!vin->scratch) { + spin_lock_irqsave(&vin->qlock, flags); + return_all_buffers(vin, VB2_BUF_STATE_QUEUED); + spin_unlock_irqrestore(&vin->qlock, flags); + vin_err(vin, "Failed to allocate scratch buffer\n"); + return -ENOMEM; + } + sd = vin_to_source(vin); v4l2_subdev_call(sd, video, s_stream, 1); @@ -1085,6 +1096,10 @@ static int rvin_start_streaming(struct vb2_queue *vq, unsigned int count) spin_unlock_irqrestore(&vin->qlock, flags); + if (ret) + dma_free_coherent(vin->dev, vin->format.sizeimage, vin->scratch, + vin->scratch_phys); + return ret; } @@ -1135,6 +1150,10 @@ static void rvin_stop_streaming(struct vb2_queue *vq) /* disable interrupts */ rvin_disable_interrupts(vin); + + /* Free scratch buffer. */ + dma_free_coherent(vin->dev, vin->format.sizeimage, vin->scratch, + vin->scratch_phys); } static const struct vb2_ops rvin_qops = { diff --git a/drivers/media/platform/rcar-vin/rcar-vin.h b/drivers/media/platform/rcar-vin/rcar-vin.h index 5382078143fb3869..11a981d707c7ca47 100644 --- a/drivers/media/platform/rcar-vin/rcar-vin.h +++ b/drivers/media/platform/rcar-vin/rcar-vin.h @@ -102,6 +102,8 @@ struct rvin_graph_entity { * * @lock: protects @queue * @queue: vb2 buffers queue + * @scratch: cpu address for scratch buffer + * @scratch_phys: pysical address of the scratch buffer * * @qlock: protects @queue_buf, @buf_list, @continuous, @sequence * @state @@ -130,6 +132,8 @@ struct rvin_dev { struct mutex lock; struct vb2_queue queue; + void *scratch; + dma_addr_t scratch_phys; spinlock_t qlock; struct vb2_v4l2_buffer *queue_buf[HW_BUFFER_NUM];