From patchwork Tue May 10 11:51:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 15870 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id EBE6AC3274 for ; Tue, 10 May 2022 11:52:31 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A1E4E65697; Tue, 10 May 2022 13:52:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1652183551; bh=ugFiXGKljdu4sLM/6x0wIcV2N3AEtbDAbQDr0izYfQg=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=Ps11ts0RhJS0FtBu1jV8J8uVsaeUshto90hViFqmZ8GWMHdZOgqmVPTNMuYYu3I38 tcD+2DW9s0YdJMBFX7tqenwtkzPpatUOewV1QKTfeQ0w+C74Aeyvbl8HkN2gZ20pZa qVYff8AL3KTmNdOro82pRGxLIO64RSYoEtddcCkDux4elqanAQ1yn8pqV1y6YLuL2o 12KPsVTURC7lPTbkhDx1lT0Qbli32S0rCszaVkng6iaCzC4ytmP7CULAjIWPicFDF8 RwEvLb2EeQ2WQCf++9S21z7/Z3xjjjKBLnpmXfGm+NH8uBKi0ZtExAm6DPgjKBdSZg 8P5MYd0rJSpig== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BB8DE65675 for ; Tue, 10 May 2022 13:52:22 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="hOR3WCFM"; dkim-atps=neutral Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id CE45FDFF; Tue, 10 May 2022 13:52:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1652183542; bh=ugFiXGKljdu4sLM/6x0wIcV2N3AEtbDAbQDr0izYfQg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hOR3WCFMQwJ+Scg0B0/2RwsnaSJD0h5a7JdgHtij4GqxvGcm4TT22gf+dRi9e+nOM HaSLyY1wXM2JCt6R/RI+i2xY6uoURmG/qXnPLeAnm+idci+3i8xgTA/YBb8gj+dZ+y 6TttvRhAxTgqLHtJ7dL3eA0oJ7N7D+M0fBc0vvB4= To: libcamera-devel@lists.libcamera.org Date: Tue, 10 May 2022 14:51:27 +0300 Message-Id: <20220510115147.19360-31-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220510115147.19360-1-laurent.pinchart@ideasonboard.com> References: <20220510115147.19360-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 30/50] staging: media: imx: imx7-media-csi: Decouple from imx_media_dma_buf X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Cc: Martin Kepplinger , kernel@pengutronix.de, Dorota Czaplejewicz , Alexander Stein , Rui Miguel Silva , Philipp Zabel , Steve Longerbeam Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Decouple from the imx_media_dma_buf structure defined in shared helpers by duplicating it in the imx7-media-csi driver, along with the two small alloc and free functions. No functional change intended. Signed-off-by: Laurent Pinchart --- drivers/staging/media/imx/imx7-media-csi.c | 40 +++++++++++++++++++--- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c index 5a5157d8b27b..05907d6257a8 100644 --- a/drivers/staging/media/imx/imx7-media-csi.c +++ b/drivers/staging/media/imx/imx7-media-csi.c @@ -184,6 +184,12 @@ to_imx7_csi_vb2_buffer(struct vb2_buffer *vb) return container_of(vbuf, struct imx7_csi_vb2_buffer, vbuf); } +struct imx7_csi_dma_buf { + void *virt; + dma_addr_t phys; + unsigned long len; +}; + struct imx7_csi { struct device *dev; @@ -227,7 +233,7 @@ struct imx7_csi { /* Buffers and streaming state */ struct imx7_csi_vb2_buffer *active_vb2_buf[2]; - struct imx_media_dma_buf underrun_buf; + struct imx7_csi_dma_buf underrun_buf; bool is_streaming; int buf_num; @@ -415,12 +421,38 @@ static void imx7_csi_dma_unsetup_vb2_buf(struct imx7_csi *csi, } } +static void imx7_csi_free_dma_buf(struct imx7_csi *csi, + struct imx7_csi_dma_buf *buf) +{ + if (buf->virt) + dma_free_coherent(csi->dev, buf->len, buf->virt, buf->phys); + + buf->virt = NULL; + buf->phys = 0; +} + +static int imx7_csi_alloc_dma_buf(struct imx7_csi *csi, + struct imx7_csi_dma_buf *buf, int size) +{ + imx7_csi_free_dma_buf(csi, buf); + + buf->len = PAGE_ALIGN(size); + buf->virt = dma_alloc_coherent(csi->dev, buf->len, &buf->phys, + GFP_DMA | GFP_KERNEL); + if (!buf->virt) { + dev_err(csi->dev, "%s: failed\n", __func__); + return -ENOMEM; + } + + return 0; +} + static int imx7_csi_dma_setup(struct imx7_csi *csi) { int ret; - ret = imx_media_alloc_dma_buf(csi->dev, &csi->underrun_buf, - csi->vdev_fmt.sizeimage); + ret = imx7_csi_alloc_dma_buf(csi, &csi->underrun_buf, + csi->vdev_fmt.sizeimage); if (ret < 0) { v4l2_warn(&csi->sd, "consider increasing the CMA area\n"); return ret; @@ -439,7 +471,7 @@ static void imx7_csi_dma_cleanup(struct imx7_csi *csi, enum vb2_buffer_state return_status) { imx7_csi_dma_unsetup_vb2_buf(csi, return_status); - imx_media_free_dma_buf(csi->dev, &csi->underrun_buf); + imx7_csi_free_dma_buf(csi, &csi->underrun_buf); } static void imx7_csi_dma_stop(struct imx7_csi *csi)