From patchwork Tue Sep 15 13:32:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 305231 Delivered-To: patch@linaro.org Received: by 2002:a92:5ad1:0:0:0:0:0 with SMTP id b78csp2562152ilg; Tue, 15 Sep 2020 06:42:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzGwf9dz5FyNRbaaBkjLqC6sFKArJtn8L5L3fLNrW0lkYScJrXJ5kyV3Loce6xl6fCPbUvy X-Received: by 2002:a17:906:fcc8:: with SMTP id qx8mr19684036ejb.13.1600177371196; Tue, 15 Sep 2020 06:42:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600177371; cv=none; d=google.com; s=arc-20160816; b=lIQYms7S16iQ0dw/+uWCaAcrhDI13tSl8Q+9LS6SZkEl1lshbII8qQoz513eZdqyTV whpH6jQGCab4I4AbL3XCF2Alwz4e4lxhxCv5irJ+rWMFyGwcxt9S3FwqX9p+SWTRytYF Ygqi99ynQ8smRJNBYD3FZ038oKbZYg5o2JweJeDsccul9vRtOIQJV8IZnuydl9qiDEgp uE2z0UyYq7MC/vwfY7VV99Iy4aBfgOPON2FVBCe93Hkdxpb4wt0kjBPZh6SI22LobOcW C3OI7XlsKFdWar9odhBjY0YI4/v9uFL57dDUGguhGcy53fv+tH8ehnIawBiXCyo7oT7L GtJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:cms-type:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:dkim-filter; bh=kCAb32KOoE4xPrYfNdilVMsiXgILf6ARsPY05j3OiaY=; b=Gs5o5mVTMmgRjfOns7+fkAMOrmgsHMJH8ZEES2UBgNwSl2/b7Gn4EvMM3j+kZy+tLA d51i32NgN9kzNehsaZdw+bPCDsxx86Tkqc6PIcwcRwAVv/ijY7plPFpAA6mnX2hUIVTU fIugReh67CJrSKBL9B6k+TSm+tSzEnRnVtKOUAXBA7hkSfGIbASXejBuIPTZjAqazcXb ykleTT2HdG32U/82BhBFpEUG5WdZWPOkB1JChFbxb69SOeCDGT2AbvThuhv+kxzeAKQX ptnWQOmBpYulZ/jWjFzYWqMBNoXFU/o24QuGpgPwF+ZrqMTc7wSU2LBSD2bV6EZgO3Tp WjIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=EQlp8pO8; spf=pass (google.com: domain of linux-samsung-soc-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-samsung-soc-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id pg3si9854149ejb.94.2020.09.15.06.42.50; Tue, 15 Sep 2020 06:42:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-samsung-soc-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=EQlp8pO8; spf=pass (google.com: domain of linux-samsung-soc-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-samsung-soc-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726463AbgIONmT (ORCPT + 4 others); Tue, 15 Sep 2020 09:42:19 -0400 Received: from mailout1.w1.samsung.com ([210.118.77.11]:45217 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726539AbgIONkr (ORCPT ); Tue, 15 Sep 2020 09:40:47 -0400 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20200915133309euoutp0129e6e9d1382065eaea1c688f50b04675~0_E-erpGW0438004380euoutp01M for ; Tue, 15 Sep 2020 13:33:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20200915133309euoutp0129e6e9d1382065eaea1c688f50b04675~0_E-erpGW0438004380euoutp01M DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1600176789; bh=kCAb32KOoE4xPrYfNdilVMsiXgILf6ARsPY05j3OiaY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EQlp8pO8osTlxr8cmjtqbv/djAI8BG53qHMVr2PN9DFwCZuCCknkrtQGHIVYYNzGV OfvVhIP7j69dxYQG7nHoR1bSpXZYtyJ/5nTqixuo+kkBvXcTi2NaABv40CXHdEH+/r MA52Nelzv3q/Vmn4SpchyHGuxnmHixPezhBub4K4= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20200915133309eucas1p2c488e984b5b7359953cc82e5dad7ce87~0_E-CjDA01823418234eucas1p2a; Tue, 15 Sep 2020 13:33:09 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 83.F5.06456.492C06F5; Tue, 15 Sep 2020 14:33:08 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20200915133308eucas1p20ad0dcd055de2d63abfbc0b385fd5369~0_E_qDOXB2313823138eucas1p2C; Tue, 15 Sep 2020 13:33:08 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200915133308eusmtrp1cc0c47c6904c9a8ccc282ddb88c0fd80~0_E_owNuo0801708017eusmtrp1T; Tue, 15 Sep 2020 13:33:08 +0000 (GMT) X-AuditID: cbfec7f2-7efff70000001938-b4-5f60c2946f74 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id D1.20.06314.492C06F5; Tue, 15 Sep 2020 14:33:08 +0100 (BST) Received: from AMDC2765.digital.local (unknown [106.120.51.73]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20200915133308eusmtip22b7cb2cdcbf9db6365ee4fde1f272d1a~0_E_NhbkF0118501185eusmtip2b; Tue, 15 Sep 2020 13:33:08 +0000 (GMT) From: Marek Szyprowski To: linux-media@vger.kernel.org, linux-samsung-soc@vger.kernel.org Cc: Marek Szyprowski , Sylwester Nawrocki , Krzysztof Kozlowski , Robin Murphy , Bartlomiej Zolnierkiewicz , Mauro Carvalho Chehab Subject: [PATCH 1/2] media: platform: exynos4-is: remove all references to physicall addresses Date: Tue, 15 Sep 2020 15:32:55 +0200 Message-Id: <20200915133256.1210-2-m.szyprowski@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200915133256.1210-1-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrLIsWRmVeSWpSXmKPExsWy7djP87pTDiXEG6xYY2WxccZ6Vovz5zew W/Rs2MpqMeP8PiaLtUfuslss2/SHyeLghyesFu1PXzI7cHismbeG0WPTqk42j74tqxg9Pm+S C2CJ4rJJSc3JLEst0rdL4Mq4+GM6a8H8JsaKOx2vWBsYb+V0MXJySAiYSBx50MLSxcjFISSw glHixo1XbBDOF0aJd59XMUI4nxkl2q5uASrjAGvZfskOIr6cUWLq5F5WuI5HP68xgsxlEzCU 6HrbxQZiiwg4SSyc9ZcdpIhZoI9J4sq8xawgCWGBBImn+76xgNgsAqoSn/f0gm3gFbCRmLhS GOI+eYnVGw4wg9icArYSN949YwaZIyHwnU1i/5U7TBBFLhLrmw6xQNjCEq+Ob2GHsGUkTk/u YYFoaGaUeHhuLTuE08MocblpBiNElbXEnXO/2EA2MwtoSqzfpQ8RdpToWbAP6mU+iRtvBUHC zEDmpG3TmSHCvBIdbUIQ1WoSs46vg1t78MIlZgjbQ+J/21V2SABNYJRY+/Qj8wRG+VkIyxYw Mq5iFE8tLc5NTy02zEst1ytOzC0uzUvXS87P3cQITBSn/x3/tIPx66WkQ4wCHIxKPLwJ5fHx QqyJZcWVuYcYJTiYlUR4nc6ejhPiTUmsrEotyo8vKs1JLT7EKM3BoiTOa7zoZayQQHpiSWp2 ampBahFMlomDU6qBse2N5+eONVk6UycYCqtW3VhYUuV1U3zbdieVZdarNz9g2FZudPhbMOu0 h5nNS18qH+8Jz+T8Xjql2qf1wuaXT5wSmTZGrruyJMr36/0nb8/I6n3p371C5tmJevnz3K+n hJ3dd8xyrsDSBHXmV9bWRQ8d5rD/cu268maP5KOQr0bT3HTjqoqD7ZVYijMSDbWYi4oTAc/O Hc4QAwAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrLLMWRmVeSWpSXmKPExsVy+t/xe7pTDiXEG/TdUrLYOGM9q8X58xvY LXo2bGW1mHF+H5PF2iN32S2WbfrDZHHwwxNWi/anL5kdODzWzFvD6LFpVSebR9+WVYwenzfJ BbBE6dkU5ZeWpCpk5BeX2CpFG1oY6RlaWugZmVjqGRqbx1oZmSrp29mkpOZklqUW6dsl6GVc /DGdtWB+E2PFnY5XrA2Mt3K6GDk4JARMJLZfsuti5OIQEljKKHFmxzKWLkZOoLiMxMlpDawQ trDEn2tdbBBFnxglrk97wASSYBMwlOh6C5Lg5BARcJHYv+cpM0gRs8AkJonf/dsZQRLCAnES +z8fZgexWQRUJT7v6WUB2cwrYCMxcaUwxAJ5idUbDjCD2JwCthI33j0Ds4WASh6t6WKbwMi3 gJFhFaNIamlxbnpusaFecWJucWleul5yfu4mRmDQbjv2c/MOxksbgw8xCnAwKvHwJpTHxwux JpYVV+YeYpTgYFYS4XU6ezpOiDclsbIqtSg/vqg0J7X4EKMp0E0TmaVEk/OBEZVXEm9oamhu YWlobmxubGahJM7bIXAwRkggPbEkNTs1tSC1CKaPiYNTqoHR5UjzyjCj75b3w+wW/G9d90cx 82SPfeyisPWC27dl9wo+CY468qD/lc+XXNN3B/dz9h4KvdXkERJmLMQc/lctYllp6+p/PxM+ lztc2LxpoQZr4rRHIWxCSzTLtsic2M7moCf/7ITUORvVsgP2C+beXT3ttEuSqKlL4L5AN3Zl Wc+gUk/vVRlKLMUZiYZazEXFiQBUGMotcAIAAA== X-CMS-MailID: 20200915133308eucas1p20ad0dcd055de2d63abfbc0b385fd5369 X-Msg-Generator: CA X-RootMTR: 20200915133308eucas1p20ad0dcd055de2d63abfbc0b385fd5369 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200915133308eucas1p20ad0dcd055de2d63abfbc0b385fd5369 References: <20200915133256.1210-1-m.szyprowski@samsung.com> Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org This driver always operates on the DMA/IOVA addresses, so calling them physicall addresses is misleading, although when no IOMMU is used they equal each other. Fix this by renaming all such entries just to 'addr' and adjusting comments. Signed-off-by: Marek Szyprowski --- .../media/platform/exynos4-is/fimc-capture.c | 6 ++-- drivers/media/platform/exynos4-is/fimc-core.c | 28 +++++++++---------- drivers/media/platform/exynos4-is/fimc-core.h | 18 ++++++------ drivers/media/platform/exynos4-is/fimc-is.c | 20 ++++++------- drivers/media/platform/exynos4-is/fimc-is.h | 6 ++-- .../media/platform/exynos4-is/fimc-lite-reg.c | 4 +-- drivers/media/platform/exynos4-is/fimc-lite.c | 2 +- drivers/media/platform/exynos4-is/fimc-lite.h | 4 +-- drivers/media/platform/exynos4-is/fimc-m2m.c | 8 +++--- drivers/media/platform/exynos4-is/fimc-reg.c | 18 ++++++------ drivers/media/platform/exynos4-is/fimc-reg.h | 4 +-- 11 files changed, 58 insertions(+), 60 deletions(-) -- 2.17.1 diff --git a/drivers/media/platform/exynos4-is/fimc-capture.c b/drivers/media/platform/exynos4-is/fimc-capture.c index 6000a4e789ad..13c838d3f947 100644 --- a/drivers/media/platform/exynos4-is/fimc-capture.c +++ b/drivers/media/platform/exynos4-is/fimc-capture.c @@ -201,7 +201,7 @@ void fimc_capture_irq_handler(struct fimc_dev *fimc, int deq_buf) if (!list_empty(&cap->pending_buf_q)) { v_buf = fimc_pending_queue_pop(cap); - fimc_hw_set_output_addr(fimc, &v_buf->paddr, cap->buf_index); + fimc_hw_set_output_addr(fimc, &v_buf->addr, cap->buf_index); v_buf->index = cap->buf_index; /* Move the buffer to the capture active queue */ @@ -410,7 +410,7 @@ static void buffer_queue(struct vb2_buffer *vb) int min_bufs; spin_lock_irqsave(&fimc->slock, flags); - fimc_prepare_addr(ctx, &buf->vb.vb2_buf, &ctx->d_frame, &buf->paddr); + fimc_prepare_addr(ctx, &buf->vb.vb2_buf, &ctx->d_frame, &buf->addr); if (!test_bit(ST_CAPT_SUSPENDED, &fimc->state) && !test_bit(ST_CAPT_STREAM, &fimc->state) && @@ -419,7 +419,7 @@ static void buffer_queue(struct vb2_buffer *vb) int buf_id = (vid_cap->reqbufs_count == 1) ? -1 : vid_cap->buf_index; - fimc_hw_set_output_addr(fimc, &buf->paddr, buf_id); + fimc_hw_set_output_addr(fimc, &buf->addr, buf_id); buf->index = vid_cap->buf_index; fimc_active_queue_add(vid_cap, buf); diff --git a/drivers/media/platform/exynos4-is/fimc-core.c b/drivers/media/platform/exynos4-is/fimc-core.c index 08d1f39a914c..c989abeb478e 100644 --- a/drivers/media/platform/exynos4-is/fimc-core.c +++ b/drivers/media/platform/exynos4-is/fimc-core.c @@ -325,7 +325,7 @@ static irqreturn_t fimc_irq_handler(int irq, void *priv) /* The color format (colplanes, memplanes) must be already configured. */ int fimc_prepare_addr(struct fimc_ctx *ctx, struct vb2_buffer *vb, - struct fimc_frame *frame, struct fimc_addr *paddr) + struct fimc_frame *frame, struct fimc_addr *addr) { int ret = 0; u32 pix_size; @@ -338,42 +338,40 @@ int fimc_prepare_addr(struct fimc_ctx *ctx, struct vb2_buffer *vb, dbg("memplanes= %d, colplanes= %d, pix_size= %d", frame->fmt->memplanes, frame->fmt->colplanes, pix_size); - paddr->y = vb2_dma_contig_plane_dma_addr(vb, 0); + addr->y = vb2_dma_contig_plane_dma_addr(vb, 0); if (frame->fmt->memplanes == 1) { switch (frame->fmt->colplanes) { case 1: - paddr->cb = 0; - paddr->cr = 0; + addr->cb = 0; + addr->cr = 0; break; case 2: /* decompose Y into Y/Cb */ - paddr->cb = (u32)(paddr->y + pix_size); - paddr->cr = 0; + addr->cb = (u32)(addr->y + pix_size); + addr->cr = 0; break; case 3: - paddr->cb = (u32)(paddr->y + pix_size); + addr->cb = (u32)(addr->y + pix_size); /* decompose Y into Y/Cb/Cr */ if (FIMC_FMT_YCBCR420 == frame->fmt->color) - paddr->cr = (u32)(paddr->cb - + (pix_size >> 2)); + addr->cr = (u32)(addr->cb + (pix_size >> 2)); else /* 422 */ - paddr->cr = (u32)(paddr->cb - + (pix_size >> 1)); + addr->cr = (u32)(addr->cb + (pix_size >> 1)); break; default: return -EINVAL; } } else if (!frame->fmt->mdataplanes) { if (frame->fmt->memplanes >= 2) - paddr->cb = vb2_dma_contig_plane_dma_addr(vb, 1); + addr->cb = vb2_dma_contig_plane_dma_addr(vb, 1); if (frame->fmt->memplanes == 3) - paddr->cr = vb2_dma_contig_plane_dma_addr(vb, 2); + addr->cr = vb2_dma_contig_plane_dma_addr(vb, 2); } - dbg("PHYS_ADDR: y= 0x%X cb= 0x%X cr= 0x%X ret= %d", - paddr->y, paddr->cb, paddr->cr, ret); + dbg("DMA ADDR: y= 0x%X cb= 0x%X cr= 0x%X ret= %d", + addr->y, addr->cb, addr->cr, ret); return ret; } diff --git a/drivers/media/platform/exynos4-is/fimc-core.h b/drivers/media/platform/exynos4-is/fimc-core.h index e4a56232907a..58b72a052cef 100644 --- a/drivers/media/platform/exynos4-is/fimc-core.h +++ b/drivers/media/platform/exynos4-is/fimc-core.h @@ -202,10 +202,10 @@ struct fimc_scaler { }; /** - * struct fimc_addr - the FIMC physical address set for DMA - * @y: luminance plane physical address - * @cb: Cb plane physical address - * @cr: Cr plane physical address + * struct fimc_addr - the FIMC address set for DMA + * @y: luminance plane address + * @cb: Cb plane address + * @cr: Cr plane address */ struct fimc_addr { u32 y; @@ -217,13 +217,13 @@ struct fimc_addr { * struct fimc_vid_buffer - the driver's video buffer * @vb: v4l videobuf buffer * @list: linked list structure for buffer queue - * @paddr: precalculated physical address set + * @addr: precalculated DMA address set * @index: buffer index for the output DMA engine */ struct fimc_vid_buffer { struct vb2_v4l2_buffer vb; struct list_head list; - struct fimc_addr paddr; + struct fimc_addr addr; int index; }; @@ -239,7 +239,7 @@ struct fimc_vid_buffer { * @height: image pixel weight * @payload: image size in bytes (w x h x bpp) * @bytesperline: bytesperline value for each plane - * @paddr: image frame buffer physical addresses + * @addr: image frame buffer DMA addresses * @dma_offset: DMA offset in bytes * @fmt: fimc color format pointer */ @@ -254,7 +254,7 @@ struct fimc_frame { u32 height; unsigned int payload[VIDEO_MAX_PLANES]; unsigned int bytesperline[VIDEO_MAX_PLANES]; - struct fimc_addr paddr; + struct fimc_addr addr; struct fimc_dma_offset dma_offset; struct fimc_fmt *fmt; u8 alpha; @@ -626,7 +626,7 @@ int fimc_check_scaler_ratio(struct fimc_ctx *ctx, int sw, int sh, int fimc_set_scaler_info(struct fimc_ctx *ctx); int fimc_prepare_config(struct fimc_ctx *ctx, u32 flags); int fimc_prepare_addr(struct fimc_ctx *ctx, struct vb2_buffer *vb, - struct fimc_frame *frame, struct fimc_addr *paddr); + struct fimc_frame *frame, struct fimc_addr *addr); void fimc_prepare_dma_offset(struct fimc_ctx *ctx, struct fimc_frame *f); void fimc_set_yuv_order(struct fimc_ctx *ctx); void fimc_capture_irq_handler(struct fimc_dev *fimc, int deq_buf); diff --git a/drivers/media/platform/exynos4-is/fimc-is.c b/drivers/media/platform/exynos4-is/fimc-is.c index 019bb47df915..41b841a96338 100644 --- a/drivers/media/platform/exynos4-is/fimc-is.c +++ b/drivers/media/platform/exynos4-is/fimc-is.c @@ -269,7 +269,7 @@ int fimc_is_cpu_set_power(struct fimc_is *is, int on) mcuctl_write(0, is, REG_WDT_ISP); /* Cortex-A5 start address setting */ - mcuctl_write(is->memory.paddr, is, MCUCTL_REG_BBOAR); + mcuctl_write(is->memory.addr, is, MCUCTL_REG_BBOAR); /* Enable and start Cortex-A5 */ pmuisp_write(0x18000, is, REG_PMU_ISP_ARM_OPTION); @@ -336,26 +336,26 @@ static int fimc_is_alloc_cpu_memory(struct fimc_is *is) struct device *dev = &is->pdev->dev; is->memory.vaddr = dma_alloc_coherent(dev, FIMC_IS_CPU_MEM_SIZE, - &is->memory.paddr, GFP_KERNEL); + &is->memory.addr, GFP_KERNEL); if (is->memory.vaddr == NULL) return -ENOMEM; is->memory.size = FIMC_IS_CPU_MEM_SIZE; - dev_info(dev, "FIMC-IS CPU memory base: %#x\n", (u32)is->memory.paddr); + dev_info(dev, "FIMC-IS CPU memory base: %pad\n", &is->memory.addr); - if (((u32)is->memory.paddr) & FIMC_IS_FW_ADDR_MASK) { + if (((u32)is->memory.addr) & FIMC_IS_FW_ADDR_MASK) { dev_err(dev, "invalid firmware memory alignment: %#x\n", - (u32)is->memory.paddr); + (u32)is->memory.addr); dma_free_coherent(dev, is->memory.size, is->memory.vaddr, - is->memory.paddr); + is->memory.addr); return -EIO; } is->is_p_region = (struct is_region *)(is->memory.vaddr + FIMC_IS_CPU_MEM_SIZE - FIMC_IS_REGION_SIZE); - is->is_dma_p_region = is->memory.paddr + + is->is_dma_p_region = is->memory.addr + FIMC_IS_CPU_MEM_SIZE - FIMC_IS_REGION_SIZE; is->is_shared_region = (struct is_share_region *)(is->memory.vaddr + @@ -371,7 +371,7 @@ static void fimc_is_free_cpu_memory(struct fimc_is *is) return; dma_free_coherent(dev, is->memory.size, is->memory.vaddr, - is->memory.paddr); + is->memory.addr); } static void fimc_is_load_firmware(const struct firmware *fw, void *context) @@ -416,7 +416,7 @@ static void fimc_is_load_firmware(const struct firmware *fw, void *context) dev_info(dev, "loaded firmware: %s, rev. %s\n", is->fw.info, is->fw.version); - dev_dbg(dev, "FW size: %zu, paddr: %pad\n", fw->size, &is->memory.paddr); + dev_dbg(dev, "FW size: %zu, DMA addr: %pad\n", fw->size, &is->memory.addr); is->is_shared_region->chip_id = 0xe4412; is->is_shared_region->chip_rev_no = 1; @@ -699,7 +699,7 @@ int fimc_is_hw_initialize(struct fimc_is *is) } pr_debug("shared region: %pad, parameter region: %pad\n", - &is->memory.paddr + FIMC_IS_SHARED_REGION_OFFSET, + &is->memory.addr + FIMC_IS_SHARED_REGION_OFFSET, &is->is_dma_p_region); is->setfile.sub_index = 0; diff --git a/drivers/media/platform/exynos4-is/fimc-is.h b/drivers/media/platform/exynos4-is/fimc-is.h index 7ee96a058d40..ce30b007bc55 100644 --- a/drivers/media/platform/exynos4-is/fimc-is.h +++ b/drivers/media/platform/exynos4-is/fimc-is.h @@ -174,7 +174,7 @@ struct is_af_info { struct fimc_is_firmware { const struct firmware *f_w; - dma_addr_t paddr; + dma_addr_t addr; void *vaddr; unsigned int size; @@ -185,8 +185,8 @@ struct fimc_is_firmware { }; struct fimc_is_memory { - /* physical base address */ - dma_addr_t paddr; + /* DMA base address */ + dma_addr_t addr; /* virtual base address */ void *vaddr; /* total length */ diff --git a/drivers/media/platform/exynos4-is/fimc-lite-reg.c b/drivers/media/platform/exynos4-is/fimc-lite-reg.c index 85f765e0f4e1..57996b4104b4 100644 --- a/drivers/media/platform/exynos4-is/fimc-lite-reg.c +++ b/drivers/media/platform/exynos4-is/fimc-lite-reg.c @@ -272,9 +272,9 @@ void flite_hw_set_dma_buffer(struct fimc_lite *dev, struct flite_buffer *buf) index = buf->index; if (index == 0) - writel(buf->paddr, dev->regs + FLITE_REG_CIOSA); + writel(buf->addr, dev->regs + FLITE_REG_CIOSA); else - writel(buf->paddr, dev->regs + FLITE_REG_CIOSAN(index - 1)); + writel(buf->addr, dev->regs + FLITE_REG_CIOSAN(index - 1)); cfg = readl(dev->regs + FLITE_REG_CIFCNTSEQ); cfg |= BIT(index); diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c b/drivers/media/platform/exynos4-is/fimc-lite.c index 9c666f663ab4..1576f273761b 100644 --- a/drivers/media/platform/exynos4-is/fimc-lite.c +++ b/drivers/media/platform/exynos4-is/fimc-lite.c @@ -409,7 +409,7 @@ static void buffer_queue(struct vb2_buffer *vb) unsigned long flags; spin_lock_irqsave(&fimc->slock, flags); - buf->paddr = vb2_dma_contig_plane_dma_addr(vb, 0); + buf->addr = vb2_dma_contig_plane_dma_addr(vb, 0); buf->index = fimc->buf_index++; if (fimc->buf_index >= fimc->reqbufs_count) diff --git a/drivers/media/platform/exynos4-is/fimc-lite.h b/drivers/media/platform/exynos4-is/fimc-lite.h index e6846c5fc9ac..e2d4d628b5aa 100644 --- a/drivers/media/platform/exynos4-is/fimc-lite.h +++ b/drivers/media/platform/exynos4-is/fimc-lite.h @@ -93,13 +93,13 @@ struct flite_frame { * struct flite_buffer - video buffer structure * @vb: vb2 buffer * @list: list head for the buffers queue - * @paddr: DMA buffer start address + * @addr: DMA buffer start address * @index: DMA start address register's index */ struct flite_buffer { struct vb2_v4l2_buffer vb; struct list_head list; - dma_addr_t paddr; + dma_addr_t addr; unsigned short index; }; diff --git a/drivers/media/platform/exynos4-is/fimc-m2m.c b/drivers/media/platform/exynos4-is/fimc-m2m.c index 4acb179556c4..c9704a147e5c 100644 --- a/drivers/media/platform/exynos4-is/fimc-m2m.c +++ b/drivers/media/platform/exynos4-is/fimc-m2m.c @@ -115,12 +115,12 @@ static void fimc_device_run(void *priv) } src_vb = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx); - ret = fimc_prepare_addr(ctx, &src_vb->vb2_buf, sf, &sf->paddr); + ret = fimc_prepare_addr(ctx, &src_vb->vb2_buf, sf, &sf->addr); if (ret) goto dma_unlock; dst_vb = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); - ret = fimc_prepare_addr(ctx, &dst_vb->vb2_buf, df, &df->paddr); + ret = fimc_prepare_addr(ctx, &dst_vb->vb2_buf, df, &df->addr); if (ret) goto dma_unlock; @@ -152,8 +152,8 @@ static void fimc_device_run(void *priv) fimc_hw_set_rgb_alpha(ctx); fimc_hw_set_output_path(ctx); } - fimc_hw_set_input_addr(fimc, &sf->paddr); - fimc_hw_set_output_addr(fimc, &df->paddr, -1); + fimc_hw_set_input_addr(fimc, &sf->addr); + fimc_hw_set_output_addr(fimc, &df->addr, -1); fimc_activate_capture(ctx); ctx->state &= (FIMC_CTX_M2M | FIMC_CTX_CAP); diff --git a/drivers/media/platform/exynos4-is/fimc-reg.c b/drivers/media/platform/exynos4-is/fimc-reg.c index 8764999a5fd7..95165a2cc7d1 100644 --- a/drivers/media/platform/exynos4-is/fimc-reg.c +++ b/drivers/media/platform/exynos4-is/fimc-reg.c @@ -526,30 +526,30 @@ void fimc_hw_set_output_path(struct fimc_ctx *ctx) writel(cfg, dev->regs + FIMC_REG_CISCCTRL); } -void fimc_hw_set_input_addr(struct fimc_dev *dev, struct fimc_addr *paddr) +void fimc_hw_set_input_addr(struct fimc_dev *dev, struct fimc_addr *addr) { u32 cfg = readl(dev->regs + FIMC_REG_CIREAL_ISIZE); cfg |= FIMC_REG_CIREAL_ISIZE_ADDR_CH_DIS; writel(cfg, dev->regs + FIMC_REG_CIREAL_ISIZE); - writel(paddr->y, dev->regs + FIMC_REG_CIIYSA(0)); - writel(paddr->cb, dev->regs + FIMC_REG_CIICBSA(0)); - writel(paddr->cr, dev->regs + FIMC_REG_CIICRSA(0)); + writel(addr->y, dev->regs + FIMC_REG_CIIYSA(0)); + writel(addr->cb, dev->regs + FIMC_REG_CIICBSA(0)); + writel(addr->cr, dev->regs + FIMC_REG_CIICRSA(0)); cfg &= ~FIMC_REG_CIREAL_ISIZE_ADDR_CH_DIS; writel(cfg, dev->regs + FIMC_REG_CIREAL_ISIZE); } void fimc_hw_set_output_addr(struct fimc_dev *dev, - struct fimc_addr *paddr, int index) + struct fimc_addr *addr, int index) { int i = (index == -1) ? 0 : index; do { - writel(paddr->y, dev->regs + FIMC_REG_CIOYSA(i)); - writel(paddr->cb, dev->regs + FIMC_REG_CIOCBSA(i)); - writel(paddr->cr, dev->regs + FIMC_REG_CIOCRSA(i)); + writel(addr->y, dev->regs + FIMC_REG_CIOYSA(i)); + writel(addr->cb, dev->regs + FIMC_REG_CIOCBSA(i)); + writel(addr->cr, dev->regs + FIMC_REG_CIOCRSA(i)); dbg("dst_buf[%d]: 0x%X, cb: 0x%X, cr: 0x%X", - i, paddr->y, paddr->cb, paddr->cr); + i, addr->y, addr->cb, addr->cr); } while (index == -1 && ++i < FIMC_MAX_OUT_BUFS); } diff --git a/drivers/media/platform/exynos4-is/fimc-reg.h b/drivers/media/platform/exynos4-is/fimc-reg.h index b81826d04936..d7a62465c14e 100644 --- a/drivers/media/platform/exynos4-is/fimc-reg.h +++ b/drivers/media/platform/exynos4-is/fimc-reg.h @@ -302,8 +302,8 @@ void fimc_hw_set_rgb_alpha(struct fimc_ctx *ctx); void fimc_hw_set_in_dma(struct fimc_ctx *ctx); void fimc_hw_set_input_path(struct fimc_ctx *ctx); void fimc_hw_set_output_path(struct fimc_ctx *ctx); -void fimc_hw_set_input_addr(struct fimc_dev *fimc, struct fimc_addr *paddr); -void fimc_hw_set_output_addr(struct fimc_dev *fimc, struct fimc_addr *paddr, +void fimc_hw_set_input_addr(struct fimc_dev *fimc, struct fimc_addr *addr); +void fimc_hw_set_output_addr(struct fimc_dev *fimc, struct fimc_addr *addr, int index); int fimc_hw_set_camera_source(struct fimc_dev *fimc, struct fimc_source_info *cam); From patchwork Tue Sep 15 13:32:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 305232 Delivered-To: patch@linaro.org Received: by 2002:a92:5ad1:0:0:0:0:0 with SMTP id b78csp2562486ilg; Tue, 15 Sep 2020 06:43:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwJ/7IJHknNwveHHi6/YepKLUpsdb5f+S2Hh9NLjsRhbhS1hXY4QWmkTw3abzfwJVVJ7bkF X-Received: by 2002:a17:906:60d3:: with SMTP id f19mr20777028ejk.141.1600177401628; Tue, 15 Sep 2020 06:43:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600177401; cv=none; d=google.com; s=arc-20160816; b=wSyBPGC0YbU/+WfdqSQ6QULmJrKxPuWuinxrAsdkvC24U4EZFEi0GOCXeGGDgA2/E7 KeaMStGLhVDXiJEq1Wyw6/TzvAJeV/xXOefIJbtWkY7TUZewtaNxO3fWOeC0jH6+up8U MaVkcTY3IthzuupLmflawHP7Cq3zfCJ5YVLIdbQaJnDz+EOvruwJIDahd5PAfWLJJk60 9OMzEtaq7nhMXZxHD8NbTdzW9vlvVTBCuidim1X52tBVO1h5RPVkWEUeVjg6Xq75XyLk n2hgS919d9xZdhUFsEQyn448sw64H35oc0SNTZr0vh8LgRQBA7JRURMsMPqXz+vYPwGu /AgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:cms-type:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:dkim-filter; bh=eCw5I8pYrfFFBjFsoG+EmC7RVNzBZd5XzgYc1xY4fjE=; b=QzeTyL/d4rpI04Iz+0IlyE7S1l2btIudjzcbeBu222gziL0xI/0CXVSbHAFZXShRUu f380QzwgGHBq5IpMnVBgRc6IAKksP9oXbrwAQuCvjs8OknWycULs3H92HlbPpsEyRLMz mX9lgM9cASoiRpOpavshDayV3UVo67Cx3mqzGThW2Bj3bzQRd5dm6yy67TNLm6gKl89x Cmjm4eyV5Qd9dIxZmHlN+qVeSQV2Zvp9kQAdMs/LLkD9ltrC3MlyZqXZc3vHaUd+QO91 4ZxO555fqWrYkth7lae9ifMNz9jCBijege7SHk7pN+ZKyFuffLVwBjfbPshvaUp5CYc4 +ang== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b="iTkCkO/f"; spf=pass (google.com: domain of linux-samsung-soc-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-samsung-soc-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id pg3si9854149ejb.94.2020.09.15.06.43.21; Tue, 15 Sep 2020 06:43:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-samsung-soc-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b="iTkCkO/f"; spf=pass (google.com: domain of linux-samsung-soc-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-samsung-soc-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726539AbgIONmU (ORCPT + 4 others); Tue, 15 Sep 2020 09:42:20 -0400 Received: from mailout1.w1.samsung.com ([210.118.77.11]:45220 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726507AbgIONkr (ORCPT ); Tue, 15 Sep 2020 09:40:47 -0400 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20200915133309euoutp01d6d56cca360f2559e3755f6d1c7ed302~0_E-s47p60402404024euoutp01q for ; Tue, 15 Sep 2020 13:33:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20200915133309euoutp01d6d56cca360f2559e3755f6d1c7ed302~0_E-s47p60402404024euoutp01q DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1600176789; bh=eCw5I8pYrfFFBjFsoG+EmC7RVNzBZd5XzgYc1xY4fjE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iTkCkO/fHbS2vFkNgbifPDhE9o0FQmEU7JsTfggXwYHd6cdCy8vAjMe2yrEuN8/9h sJhYyDqHK8OvA401Wa/EQni9+U2Ein1gi4liYSlPXLDc0zFwJXIHnhLLVdgq5cy4+k X2g6kamiVS5h2xDTAbKyf6cnuUx++wqYaLAv/snk= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20200915133309eucas1p1ddc99ebde39abfe133ba3aae0d52e79d~0_E-YJoin0220202202eucas1p1H; Tue, 15 Sep 2020 13:33:09 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id E8.11.05997.592C06F5; Tue, 15 Sep 2020 14:33:09 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20200915133309eucas1p27768c75d4391f646b3715f29ff0c452a~0_E-BcY6K2313723137eucas1p2D; Tue, 15 Sep 2020 13:33:09 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200915133309eusmtrp10283eb4504d067ea62811fd959cec066~0_E-ASkam0804908049eusmtrp1H; Tue, 15 Sep 2020 13:33:09 +0000 (GMT) X-AuditID: cbfec7f4-677ff7000000176d-8e-5f60c295ada6 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 62.20.06314.492C06F5; Tue, 15 Sep 2020 14:33:08 +0100 (BST) Received: from AMDC2765.digital.local (unknown [106.120.51.73]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20200915133308eusmtip2ca76179ebe2323342c260df289195709~0_E_lwbuQ0271402714eusmtip21; Tue, 15 Sep 2020 13:33:08 +0000 (GMT) From: Marek Szyprowski To: linux-media@vger.kernel.org, linux-samsung-soc@vger.kernel.org Cc: Marek Szyprowski , Sylwester Nawrocki , Krzysztof Kozlowski , Robin Murphy , Bartlomiej Zolnierkiewicz , Mauro Carvalho Chehab Subject: [PATCH 2/2] media: platform: exynos4-is: add support for generic IOMMU-DMA glue code Date: Tue, 15 Sep 2020 15:32:56 +0200 Message-Id: <20200915133256.1210-3-m.szyprowski@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200915133256.1210-1-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrLIsWRmVeSWpSXmKPExsWy7djPc7pTDyXEGyz+KW6xccZ6Vovz5zew W/Rs2MpqMeP8PiaLtUfuslss2/SHyeLghyesFu1PXzI7cHismbeG0WPTqk42j74tqxg9Pm+S C2CJ4rJJSc3JLEst0rdL4MpYMPsGU8FJw4q1E+4yNjDO0uxi5OSQEDCRmNV2nb2LkYtDSGAF o8Ti11OYIJwvjBKfVp6BynxmlJjw5TITTMuF3XPYIBLLGSU2LGlAaPn84wwbSBWbgKFE19su MFtEwEli4ay/YKOYBfqYJK7MW8wKkhAWiJfYMmM3C4jNIqAqcW7OdrAVvAI2Et/n/WOBWCcv sXrDAWYQm1PAVuLGu2fMEPH3bBLnv4lB2C4SbctvQ50nLPHq+BZ2CFtG4vTkHhaQxRICzYwS D8+tZYdwehglLjfNYISospa4c+4X0KkcQOdpSqzfpQ8RdpT49XMJI0hYQoBP4sZbQZAwM5A5 adt0Zogwr0RHmxBEtZrErOPr4NYevHAJ6kwPiabWNdAAmsAocXj7NsYJjPKzEJYtYGRcxSie Wlqcm55abJSXWq5XnJhbXJqXrpecn7uJEZgoTv87/mUH464/SYcYBTgYlXh4E8rj44VYE8uK K3MPMUpwMCuJ8DqdPR0nxJuSWFmVWpQfX1Sak1p8iFGag0VJnNd40ctYIYH0xJLU7NTUgtQi mCwTB6dUA6PGpJmMjvNrOD6vWjEx5Zzcq/06B/Zae4Tau06JOlbjx8xwNtZt67wVpZNrPC4I hKfPP2229k3F+eXtT5NyFy5b7GGxRCRJ02vnyle8GVbdlXc+W9rtMpJcszb//Kevev0y6o1+ ykLTJrG5xDytaefePe3o4k3K7v4G8gkWykmyeZpXyyfOV1diKc5INNRiLipOBADblqDbEAMA AA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrHLMWRmVeSWpSXmKPExsVy+t/xe7pTDiXEG9yZa22xccZ6Vovz5zew W/Rs2MpqMeP8PiaLtUfuslss2/SHyeLghyesFu1PXzI7cHismbeG0WPTqk42j74tqxg9Pm+S C2CJ0rMpyi8tSVXIyC8usVWKNrQw0jO0tNAzMrHUMzQ2j7UyMlXSt7NJSc3JLEst0rdL0MtY MPsGU8FJw4q1E+4yNjDO0uxi5OSQEDCRuLB7DlsXIxeHkMBSRonb0zYyQSRkJE5Oa2CFsIUl /lzrgir6xCgxfWYrO0iCTcBQoustSIKTQ0TARWL/nqfMIEXMApOYJH73b2cESQgLxErsPnII rIhFQFXi3JztYBt4BWwkvs/7xwKxQV5i9YYDzCA2p4CtxI13z8BsIaCaR2u62CYw8i1gZFjF KJJaWpybnltsqFecmFtcmpeul5yfu4kRGLbbjv3cvIPx0sbgQ4wCHIxKPLwJ5fHxQqyJZcWV uYcYJTiYlUR4nc6ejhPiTUmsrEotyo8vKs1JLT7EaAp01ERmKdHkfGBM5ZXEG5oamltYGpob mxubWSiJ83YIHIwREkhPLEnNTk0tSC2C6WPi4JRqYBTYvVTdl1O0M4vv+MyE+9rS1nuyC1en lH0+EmH7Me057823rFbz3VWU0r+6NTy8ldw6+VRXYcvN4oBz13qF787LZmR69NEmTTEqq3t6 tWlV7zd37Q0l9ka/9n+4z6D691RHh9SE7c3/QqYxv5wffccv+GTKSuZHF9t3aN7nqRH8GukZ onbslRJLcUaioRZzUXEiABWLlq5xAgAA X-CMS-MailID: 20200915133309eucas1p27768c75d4391f646b3715f29ff0c452a X-Msg-Generator: CA X-RootMTR: 20200915133309eucas1p27768c75d4391f646b3715f29ff0c452a X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200915133309eucas1p27768c75d4391f646b3715f29ff0c452a References: <20200915133256.1210-1-m.szyprowski@samsung.com> Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org Exynos4-IS driver relies on the way the ARM DMA-IOMMU glue code works: the IOVA allocator uses first-fit algorithm and the first allocated buffer is at 0x0 DMA/IOVA address. This is not true for the generic IOMMU-DMA glue code that will be used for ARM architecture soon, so add the needed code to support such case too. Signed-off-by: Marek Szyprowski --- drivers/media/platform/exynos4-is/fimc-is.c | 95 ++++++++++++++++++--- drivers/media/platform/exynos4-is/fimc-is.h | 6 +- 2 files changed, 88 insertions(+), 13 deletions(-) -- 2.17.1 diff --git a/drivers/media/platform/exynos4-is/fimc-is.c b/drivers/media/platform/exynos4-is/fimc-is.c index 41b841a96338..bdef61be0cad 100644 --- a/drivers/media/platform/exynos4-is/fimc-is.c +++ b/drivers/media/platform/exynos4-is/fimc-is.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -269,7 +270,7 @@ int fimc_is_cpu_set_power(struct fimc_is *is, int on) mcuctl_write(0, is, REG_WDT_ISP); /* Cortex-A5 start address setting */ - mcuctl_write(is->memory.addr, is, MCUCTL_REG_BBOAR); + mcuctl_write(is->memory.base, is, MCUCTL_REG_BBOAR); /* Enable and start Cortex-A5 */ pmuisp_write(0x18000, is, REG_PMU_ISP_ARM_OPTION); @@ -330,37 +331,105 @@ int fimc_is_start_firmware(struct fimc_is *is) return ret; } +#ifdef CONFIG_IOMMU_DMA +#define FIMC_IS_CPU_MEM_BASE (0) +static int fimc_iommu_remap_cpu_memory(struct fimc_is *is) +{ + struct device *dev = &is->pdev->dev; + struct iommu_domain *domain; + struct sg_table sgt; + int ret; + + domain = iommu_domain_alloc(&platform_bus_type); + if (!domain) + return -ENOMEM; + + ret = dma_get_sgtable(dev, &sgt, is->memory.vaddr, + is->memory.alloc_addr, FIMC_IS_CPU_MEM_SIZE); + if (ret) + goto err_free_domain; + + ret = iommu_attach_device(domain, dev); + if (ret) + goto err_free_sgt; + + ret = iommu_map_sgtable(domain, FIMC_IS_CPU_MEM_BASE, &sgt, + IOMMU_READ | IOMMU_WRITE); + if (ret != FIMC_IS_CPU_MEM_SIZE) { + ret = -EINVAL; + goto err_detach; + } + + is->memory.base = FIMC_IS_CPU_MEM_BASE; + is->memory.domain = domain; + sg_free_table(&sgt); + + return 0; + +err_detach: + iommu_detach_device(domain, dev); +err_free_sgt: + sg_free_table(&sgt); +err_free_domain: + iommu_domain_free(domain); + return ret; +} + +static void fimc_iommu_unmap_cpu_memory(struct fimc_is *is) +{ + struct iommu_domain *domain = is->memory.domain; + struct device *dev = &is->pdev->dev; + + iommu_unmap(domain, FIMC_IS_CPU_MEM_BASE, FIMC_IS_CPU_MEM_SIZE); + iommu_detach_device(domain, dev); + iommu_domain_free(domain); +} +#else +static inline int fimc_iommu_remap_cpu_memory(struct fimc_is *is) +{ + is->memory.base = is->memory.alloc_addr; + return 0; +} + +static void fimc_iommu_unmap_cpu_memory(struct fimc_is *is) { } +#endif + /* Allocate working memory for the FIMC-IS CPU. */ static int fimc_is_alloc_cpu_memory(struct fimc_is *is) { struct device *dev = &is->pdev->dev; is->memory.vaddr = dma_alloc_coherent(dev, FIMC_IS_CPU_MEM_SIZE, - &is->memory.addr, GFP_KERNEL); + &is->memory.alloc_addr, GFP_KERNEL); if (is->memory.vaddr == NULL) return -ENOMEM; + if (fimc_iommu_remap_cpu_memory(is)) + goto err; + is->memory.size = FIMC_IS_CPU_MEM_SIZE; - dev_info(dev, "FIMC-IS CPU memory base: %pad\n", &is->memory.addr); + dev_info(dev, "FIMC-IS CPU memory base: %pad\n", &is->memory.base); - if (((u32)is->memory.addr) & FIMC_IS_FW_ADDR_MASK) { + if (((u32)is->memory.base) & FIMC_IS_FW_ADDR_MASK) { dev_err(dev, "invalid firmware memory alignment: %#x\n", - (u32)is->memory.addr); - dma_free_coherent(dev, is->memory.size, is->memory.vaddr, - is->memory.addr); - return -EIO; + (u32)is->memory.base); + goto err; } is->is_p_region = (struct is_region *)(is->memory.vaddr + FIMC_IS_CPU_MEM_SIZE - FIMC_IS_REGION_SIZE); - is->is_dma_p_region = is->memory.addr + + is->is_dma_p_region = is->memory.base + FIMC_IS_CPU_MEM_SIZE - FIMC_IS_REGION_SIZE; is->is_shared_region = (struct is_share_region *)(is->memory.vaddr + FIMC_IS_SHARED_REGION_OFFSET); return 0; +err: + dma_free_coherent(dev, is->memory.size, is->memory.vaddr, + is->memory.alloc_addr); + return -EIO; } static void fimc_is_free_cpu_memory(struct fimc_is *is) @@ -370,8 +439,9 @@ static void fimc_is_free_cpu_memory(struct fimc_is *is) if (is->memory.vaddr == NULL) return; + fimc_iommu_unmap_cpu_memory(is); dma_free_coherent(dev, is->memory.size, is->memory.vaddr, - is->memory.addr); + is->memory.alloc_addr); } static void fimc_is_load_firmware(const struct firmware *fw, void *context) @@ -416,7 +486,8 @@ static void fimc_is_load_firmware(const struct firmware *fw, void *context) dev_info(dev, "loaded firmware: %s, rev. %s\n", is->fw.info, is->fw.version); - dev_dbg(dev, "FW size: %zu, DMA addr: %pad\n", fw->size, &is->memory.addr); + dev_dbg(dev, "FW size: %zu, DMA addr: %pad\n", fw->size, + &is->memory.base); is->is_shared_region->chip_id = 0xe4412; is->is_shared_region->chip_rev_no = 1; @@ -699,7 +770,7 @@ int fimc_is_hw_initialize(struct fimc_is *is) } pr_debug("shared region: %pad, parameter region: %pad\n", - &is->memory.addr + FIMC_IS_SHARED_REGION_OFFSET, + &is->memory.base + FIMC_IS_SHARED_REGION_OFFSET, &is->is_dma_p_region); is->setfile.sub_index = 0; diff --git a/drivers/media/platform/exynos4-is/fimc-is.h b/drivers/media/platform/exynos4-is/fimc-is.h index ce30b007bc55..e96bf9122e91 100644 --- a/drivers/media/platform/exynos4-is/fimc-is.h +++ b/drivers/media/platform/exynos4-is/fimc-is.h @@ -186,11 +186,15 @@ struct fimc_is_firmware { struct fimc_is_memory { /* DMA base address */ - dma_addr_t addr; + dma_addr_t base; + /* DMA address from allocator */ + dma_addr_t alloc_addr; /* virtual base address */ void *vaddr; /* total length */ unsigned int size; + /* optional IOMMU domain */ + struct iommu_domain *domain; }; #define FIMC_IS_I2H_MAX_ARGS 12