From patchwork Fri Sep 25 14:12:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 257131 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5CF24C4727D for ; Fri, 25 Sep 2020 14:13:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1EAAD208A9 for ; Fri, 25 Sep 2020 14:13:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="VjaUG617" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728996AbgIYOMd (ORCPT ); Fri, 25 Sep 2020 10:12:33 -0400 Received: from mailout1.w1.samsung.com ([210.118.77.11]:50584 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728973AbgIYOMd (ORCPT ); Fri, 25 Sep 2020 10:12:33 -0400 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20200925141232euoutp01e2afabe28921841a9a6d730000b040e1~4DEOhyKdI1106011060euoutp01f for ; Fri, 25 Sep 2020 14:12:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20200925141232euoutp01e2afabe28921841a9a6d730000b040e1~4DEOhyKdI1106011060euoutp01f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1601043152; bh=09pv1gfbrMxHYJO8AD2snW5aXubFJIYR4lyEPqOH5uU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VjaUG617xjpS25xHY+2VFzQl2odlMBm65cz5PGEeXU08wEE9pZ/qW13B0SPqT0kru G+jd1sq7hMKaX1w99LfqXun38Lh1Fnp3A82MAj4qwqJUiGuI63nRzS9JpZHSC3mlW+ hNVAyJHqupO6778Su8pTHRaPVGYyTym+/3Zjkq1c= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20200925141231eucas1p20d3233eb3232f4d36c19cfa361272ddf~4DEOAP91c3256732567eucas1p2i; Fri, 25 Sep 2020 14:12:31 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id CB.E4.06456.FCAFD6F5; Fri, 25 Sep 2020 15:12:31 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20200925141231eucas1p223c342cc989df23e4fc28d97fe3010c5~4DENtkpoZ3253732537eucas1p2z; Fri, 25 Sep 2020 14:12:31 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20200925141231eusmtrp2883de88f9ea00225cba96e6eb43335bb~4DENs9Nam2598725987eusmtrp2i; Fri, 25 Sep 2020 14:12:31 +0000 (GMT) X-AuditID: cbfec7f2-7efff70000001938-5b-5f6dfacfef32 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id FE.39.06314.FCAFD6F5; Fri, 25 Sep 2020 15:12:31 +0100 (BST) Received: from AMDC2765.digital.local (unknown [106.120.51.73]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200925141230eusmtip1b4b74b11e2277e18fef6a5019d2e2f2b~4DENMB_3U1229912299eusmtip1y; Fri, 25 Sep 2020 14:12:30 +0000 (GMT) From: Marek Szyprowski To: Linux IOMMU , linux-media@vger.kernel.org, linux-samsung-soc@vger.kernel.org Cc: Marek Szyprowski , Robin Murphy , Joerg Roedel , Christoph Hellwig , Sylwester Nawrocki , Krzysztof Kozlowski , Bartlomiej Zolnierkiewicz , Tomasz Figa , linux-kernel@vger.kernel.org Subject: [PATCH 1/8] dma-mapping: add DMA_ATTR_LOW_ADDRESS attribute Date: Fri, 25 Sep 2020 16:12:11 +0200 Message-Id: <20200925141218.13550-2-m.szyprowski@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200925141218.13550-1-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA0WSbUhTURjHObu7d3fD2W0KniwTBgUaqbOgC5ZYWtz6EFKSINS85UWtTWXz JQVrJL4NNU2wobZsOa053RLzZVq5ZToyNd9AwUBjFgZaqYGt1Dav2pfD7zzn9/yfw+HgiEiH +uLJKemMIoWWiTEBt73/9/DREadcGqKv9SNfaEwo+bzpHYesexNGFteYeeTIiGsZt9RiZIn5 JUpqRl5zyOa+TzzS+sOBkoXzCwi5kr+BRXhQDquWQxm1RkDVqEa5VKuhGKMqpxoB1T2twqiy NgOgVloPRuNxgpMJjCw5k1EEh8cLkkz6ejRtiX970rbIU4FSXA34OCSOw8H3E5gaCHAR8QzA PKuVy25WAeyoesJxWyJiBUBbYehOh7OhgsdKjQC+qp/g7HaYR/sRt4UREqheVLtycdybSIcN dk+3gxAODuxZZ1O9iCj4p8nCdTOXOATtk28xNwuJU7D8wybKTvOHTeberUw+EQ7nRnuBOwgS Bh4sKp3nsVIUtGvyuSx7wW8Dbdv1A3Cz6zGHbcgDcG64mcduSgAcv6cBrBUGZ4adW1dFi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UBLn7RA4GCMk kJ5YkpqdmlqQWgTTx8TBKdXA6PJgjXyaSIa8D9MpcVaDHQzdzz2OflwRwXT5okTF3V/fKqW0 6grcMhmeie+crLN49dfZ7DOF/ZaKSbv0PA7Y2ONSY+1fdODhHPsQ+9JME/+5XwQ9Yw5cMNqj eHfaDe64e5tX9CamWEXPdV+pqRoWlDTrftmRxgfmEknsnDfnTFycrxtkZh2mxFKckWioxVxU nAgAEI6bVpcCAAA= X-CMS-MailID: 20200925141231eucas1p223c342cc989df23e4fc28d97fe3010c5 X-Msg-Generator: CA X-RootMTR: 20200925141231eucas1p223c342cc989df23e4fc28d97fe3010c5 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200925141231eucas1p223c342cc989df23e4fc28d97fe3010c5 References: <20200925141218.13550-1-m.szyprowski@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org Some devices require to allocate a special buffer (usually for the firmware) just at the beginning of the address space to ensure that all further allocations can be expressed as a positive offset from that special buffer. When IOMMU is used for managing the DMA address space, such requirement can be easily fulfilled, simply by enforcing the 'first-fit' IOVA allocation algorithm. This patch adds a DMA attribute for such case. Signed-off-by: Marek Szyprowski --- include/linux/dma-mapping.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index bb138ac6f5e6..c8c568ba375b 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -66,6 +66,12 @@ * at least read-only at lesser-privileged levels). */ #define DMA_ATTR_PRIVILEGED (1UL << 9) +/* + * DMA_ATTR_LOW_ADDRESS: used to indicate that the buffer should be allocated + * at the lowest possible DMA address, usually just at the beginning of the + * DMA/IOVA address space ('first-fit' allocation algorithm). + */ +#define DMA_ATTR_LOW_ADDRESS (1UL << 10) /* * A dma_addr_t can hold any valid DMA or bus address for the platform. From patchwork Fri Sep 25 14:12:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 257132 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B4CD4C4727D for ; Fri, 25 Sep 2020 14:13:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 77B9820BED for ; Fri, 25 Sep 2020 14:13:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="nOx6+j2s" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729133AbgIYOND (ORCPT ); Fri, 25 Sep 2020 10:13:03 -0400 Received: from mailout1.w1.samsung.com ([210.118.77.11]:50609 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728999AbgIYOMf (ORCPT ); Fri, 25 Sep 2020 10:12:35 -0400 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20200925141232euoutp0141303e48ffcad334c56077f103f9e831~4DEOy479D1194811948euoutp01D for ; Fri, 25 Sep 2020 14:12:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20200925141232euoutp0141303e48ffcad334c56077f103f9e831~4DEOy479D1194811948euoutp01D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1601043152; bh=LBafGxduMqujCqtcOuirj0eG6IiPYgtYMNGxyXBJvis=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nOx6+j2sXDHU/xINZqYKAsyrvjroAGVdX/bTJwfZ3Vl8x8Bz7m8ejaAl7IxTa2jlh yYFaIsrKVXOOBC+DK7BomZBd7XR2OFe9f8ApWwQ6SbWuTsCtartpK2B9mVzMrrUTX3 KPjLlElgGeOIa8QYkkFopKpUWY/D/GoZPypcNbBQ= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20200925141232eucas1p1ee7c71a2e779ace903809af6f434547a~4DEOhU5xP1940819408eucas1p1l; Fri, 25 Sep 2020 14:12:32 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 4D.E4.06456.0DAFD6F5; Fri, 25 Sep 2020 15:12:32 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20200925141231eucas1p22043424ba07b99f7727f750487a55b6d~4DEORWFls3257132571eucas1p26; Fri, 25 Sep 2020 14:12:31 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20200925141231eusmtrp2b4443a9b08f293ad547fa29babed9335~4DEOQwrTc2598725987eusmtrp2j; Fri, 25 Sep 2020 14:12:31 +0000 (GMT) X-AuditID: cbfec7f2-809ff70000001938-5e-5f6dfad042e5 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 30.49.06314.FCAFD6F5; Fri, 25 Sep 2020 15:12:31 +0100 (BST) Received: from AMDC2765.digital.local (unknown [106.120.51.73]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200925141231eusmtip190c22a68db9519674c016d8da3aa68f7~4DENsaA9_1697816978eusmtip15; Fri, 25 Sep 2020 14:12:31 +0000 (GMT) From: Marek Szyprowski To: Linux IOMMU , linux-media@vger.kernel.org, linux-samsung-soc@vger.kernel.org Cc: Marek Szyprowski , Robin Murphy , Joerg Roedel , Christoph Hellwig , Sylwester Nawrocki , Krzysztof Kozlowski , Bartlomiej Zolnierkiewicz , Tomasz Figa , linux-kernel@vger.kernel.org Subject: [PATCH 2/8] iommu: iova: properly handle 0 as a valid IOVA address Date: Fri, 25 Sep 2020 16:12:12 +0200 Message-Id: <20200925141218.13550-3-m.szyprowski@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200925141218.13550-1-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrMKsWRmVeSWpSXmKPExsWy7djPc7oXfuXGG3TuZ7PYOGM9q8XK1UeZ LBbst7bonL2B3eL8eSBxedccNoueDVtZLWac38dksfbIXXaLgx+esFq0P33JbPG59R+bA4/H k4PzmDzWzFvD6DG74SKLx6ZVnWwek28sZ/TYfbOBzaNvyypGj8+b5AI4orhsUlJzMstSi/Tt Ergy2pcvZSn4ZFKx/YtVA+N3rS5GTg4JAROJSbM6mLsYuTiEBFYwSlyavJkVwvnCKNH+5BtU 5jOjxIwPH5lgWrZ1n2eBSCxnlNh6fR0zXEtz1xk2kCo2AUOJrrddQDYHh4hAicSyE3wgNcwC T5gk9vxdCDZJWMBb4vibeywgNouAqsST3jfMIDavgK3EhWlrGSG2yUus3nAALM4pYCfx8OIB RpBBEgKr2CUuXj8PVeQi0bpiAhuELSzx6vgWdghbRuL/zvlMEA3NjBIPz61lh3B6GCUuN82A 6raWuHPuF9ipzAKaEut36UOEHSWuXXzIBBKWEOCTuPFWECTMDGRO2jadGSLMK9HRJgRRrSYx 6/g6uLUHL1xihrA9JB7O+c4ICaCJjBILdvWzTmCUn4WwbAEj4ypG8dTS4tz01GLDvNRyveLE 3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eiJveG9ba2yT8EJDKjD8sc5P/mL7r4R7RLBts8H/cNj3mv116Km5pttnBPMKvKn+OP zk11qHAKLD1k/s2A6eysPZ/tYs7uXec/6eGVuFiZupsHXrj3v2Oe+PFBetUqJZbijERDLeai 4kQAhqQOLpUCAAA= X-CMS-MailID: 20200925141231eucas1p22043424ba07b99f7727f750487a55b6d X-Msg-Generator: CA X-RootMTR: 20200925141231eucas1p22043424ba07b99f7727f750487a55b6d X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200925141231eucas1p22043424ba07b99f7727f750487a55b6d References: <20200925141218.13550-1-m.szyprowski@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org Zero is a valid DMA and IOVA address on many architectures, so adjust the IOVA management code to properly handle it. A new value IOVA_BAD_ADDR (~0UL) is introduced as a generic value for the error case. Adjust all callers of the alloc_iova_fast() function for the new return value. Signed-off-by: Marek Szyprowski --- drivers/iommu/dma-iommu.c | 18 ++++++++++-------- drivers/iommu/intel/iommu.c | 12 ++++++------ drivers/iommu/iova.c | 10 ++++++---- include/linux/iova.h | 2 ++ 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index cd6e3c70ebb3..91dd8f46dae1 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -405,7 +405,7 @@ static dma_addr_t iommu_dma_alloc_iova(struct iommu_domain *domain, { struct iommu_dma_cookie *cookie = domain->iova_cookie; struct iova_domain *iovad = &cookie->iovad; - unsigned long shift, iova_len, iova = 0; + unsigned long shift, iova_len, iova = IOVA_BAD_ADDR; if (cookie->type == IOMMU_DMA_MSI_COOKIE) { cookie->msi_iova += size; @@ -433,11 +433,13 @@ static dma_addr_t iommu_dma_alloc_iova(struct iommu_domain *domain, iova = alloc_iova_fast(iovad, iova_len, DMA_BIT_MASK(32) >> shift, false); - if (!iova) + if (iova == IOVA_BAD_ADDR) iova = alloc_iova_fast(iovad, iova_len, dma_limit >> shift, true); - return (dma_addr_t)iova << shift; + if (iova != IOVA_BAD_ADDR) + return (dma_addr_t)iova << shift; + return DMA_MAPPING_ERROR; } static void iommu_dma_free_iova(struct iommu_dma_cookie *cookie, @@ -493,8 +495,8 @@ static dma_addr_t __iommu_dma_map(struct device *dev, phys_addr_t phys, size = iova_align(iovad, size + iova_off); iova = iommu_dma_alloc_iova(domain, size, dma_mask, dev); - if (!iova) - return DMA_MAPPING_ERROR; + if (iova == DMA_MAPPING_ERROR) + return iova; if (iommu_map_atomic(domain, iova, phys - iova_off, size, prot)) { iommu_dma_free_iova(cookie, iova, size); @@ -617,7 +619,7 @@ static void *iommu_dma_alloc_remap(struct device *dev, size_t size, size = iova_align(iovad, size); iova = iommu_dma_alloc_iova(domain, size, dev->coherent_dma_mask, dev); - if (!iova) + if (iova == DMA_MAPPING_ERROR) goto out_free_pages; if (sg_alloc_table_from_pages(&sgt, pages, count, 0, size, GFP_KERNEL)) @@ -887,7 +889,7 @@ static int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg, } iova = iommu_dma_alloc_iova(domain, iova_len, dma_get_mask(dev), dev); - if (!iova) + if (iova == DMA_MAPPING_ERROR) goto out_restore_sg; /* @@ -1181,7 +1183,7 @@ static struct iommu_dma_msi_page *iommu_dma_get_msi_page(struct device *dev, return NULL; iova = iommu_dma_alloc_iova(domain, size, dma_get_mask(dev), dev); - if (!iova) + if (iova == DMA_MAPPING_ERROR) goto out_free_page; if (iommu_map(domain, iova, msi_addr, size, prot)) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 00963cedfd83..885d0dee39cc 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -3416,15 +3416,15 @@ static unsigned long intel_alloc_iova(struct device *dev, */ iova_pfn = alloc_iova_fast(&domain->iovad, nrpages, IOVA_PFN(DMA_BIT_MASK(32)), false); - if (iova_pfn) + if (iova_pfn != IOVA_BAD_ADDR) return iova_pfn; } iova_pfn = alloc_iova_fast(&domain->iovad, nrpages, IOVA_PFN(dma_mask), true); - if (unlikely(!iova_pfn)) { + if (unlikely(iova_pfn == IOVA_BAD_ADDR)) { dev_err_once(dev, "Allocating %ld-page iova failed\n", nrpages); - return 0; + return IOVA_BAD_ADDR; } return iova_pfn; @@ -3454,7 +3454,7 @@ static dma_addr_t __intel_map_single(struct device *dev, phys_addr_t paddr, size = aligned_nrpages(paddr, size); iova_pfn = intel_alloc_iova(dev, domain, dma_to_mm_pfn(size), dma_mask); - if (!iova_pfn) + if (iova_pfn == IOVA_BAD_ADDR) goto error; /* @@ -3663,7 +3663,7 @@ static int intel_map_sg(struct device *dev, struct scatterlist *sglist, int nele iova_pfn = intel_alloc_iova(dev, domain, dma_to_mm_pfn(size), *dev->dma_mask); - if (!iova_pfn) { + if (iova_pfn == IOVA_BAD_ADDR) { sglist->dma_length = 0; return 0; } @@ -3760,7 +3760,7 @@ bounce_map_single(struct device *dev, phys_addr_t paddr, size_t size, nrpages = aligned_nrpages(0, size); iova_pfn = intel_alloc_iova(dev, domain, dma_to_mm_pfn(nrpages), dma_mask); - if (!iova_pfn) + if (iova_pfn == IOVA_BAD_ADDR) return DMA_MAPPING_ERROR; /* diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c index 30d969a4c5fd..87555ed1737a 100644 --- a/drivers/iommu/iova.c +++ b/drivers/iommu/iova.c @@ -407,6 +407,8 @@ EXPORT_SYMBOL_GPL(free_iova); * This function tries to satisfy an iova allocation from the rcache, * and falls back to regular allocation on failure. If regular allocation * fails too and the flush_rcache flag is set then the rcache will be flushed. + * Returns a pfn the allocated iova starts at or IOVA_BAD_ADDR in the case + * of a failure. */ unsigned long alloc_iova_fast(struct iova_domain *iovad, unsigned long size, @@ -416,7 +418,7 @@ alloc_iova_fast(struct iova_domain *iovad, unsigned long size, struct iova *new_iova; iova_pfn = iova_rcache_get(iovad, size, limit_pfn + 1); - if (iova_pfn) + if (iova_pfn != IOVA_BAD_ADDR) return iova_pfn; retry: @@ -425,7 +427,7 @@ alloc_iova_fast(struct iova_domain *iovad, unsigned long size, unsigned int cpu; if (!flush_rcache) - return 0; + return IOVA_BAD_ADDR; /* Try replenishing IOVAs by flushing rcache. */ flush_rcache = false; @@ -956,7 +958,7 @@ static unsigned long __iova_rcache_get(struct iova_rcache *rcache, unsigned long limit_pfn) { struct iova_cpu_rcache *cpu_rcache; - unsigned long iova_pfn = 0; + unsigned long iova_pfn = IOVA_BAD_ADDR; bool has_pfn = false; unsigned long flags; @@ -998,7 +1000,7 @@ static unsigned long iova_rcache_get(struct iova_domain *iovad, unsigned int log_size = order_base_2(size); if (log_size >= IOVA_RANGE_CACHE_MAX_SIZE) - return 0; + return IOVA_BAD_ADDR; return __iova_rcache_get(&iovad->rcaches[log_size], limit_pfn - size); } diff --git a/include/linux/iova.h b/include/linux/iova.h index a0637abffee8..69737e6bcef6 100644 --- a/include/linux/iova.h +++ b/include/linux/iova.h @@ -22,6 +22,8 @@ struct iova { unsigned long pfn_lo; /* Lowest allocated pfn */ }; +#define IOVA_BAD_ADDR (~0UL) + struct iova_magazine; struct iova_cpu_rcache; From patchwork Fri Sep 25 14:12:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 313505 Delivered-To: patch@linaro.org Received: by 2002:a92:5ad1:0:0:0:0:0 with SMTP id b78csp1179832ilg; Fri, 25 Sep 2020 07:13:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy03dhd/ouoqlKS/+plAdwjPWCndYCQUCUa757i58wIv2yaXHfwFwBuzYQ7uV6GA67kAXmQ X-Received: by 2002:aa7:c896:: with SMTP id p22mr1531014eds.382.1601043184685; Fri, 25 Sep 2020 07:13:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601043184; cv=none; d=google.com; s=arc-20160816; b=cewyGf6PLcXjSw+cre+AEK2D4BUVzaJYuQn/QEy4Hg/RT3sG4RQgJXIgbSCWP9N1/L +QZoPDQdhS+p9ZCtO1wi3s8EIcWf2I1g4ic0Uz04lyt4oTTf+izXr9jiWyAPpGt6UVqg mSucrFdq+CDiQKsHzKKpepIiZbeBJwXLem8dY5XSLy8WUvp6kVBThIFfayanS+yORG3p IdWGg2Ohza4hcig1nD4bIw+1PteF9Z+yPBpfEbDcvurlmW2Hs7DRfJ8e48rpfW73AgMN e85ZDXaYLOU2j5KeqNHvGI5SA/w40fz06uFrOEPdQRVb/M/U+FK9TS0di+bnd+4HSFsm qhWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:cms-type:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter; bh=3ltQiItP68nXp8N3IBI3XXVcqofC79een0tYDl29GjA=; b=eN95i5aYlvslwppu6DU65J3A5p0JpPa5pdTxW8EKy7BRHOtkUHVfQ2VFleEzKt/btl Irt48oRAwsPzdcGNzn2swyZYtUTMwRsTWmokV9Fta/Jbm22Q8VDGarpfuMi8o+JIgLQQ 1DgZIMnRosJKHYBzuqC8V9J/5n7bTjb5KmqElfWAt0mVcxtVVDy2DfKsRGi5G17UhT7u dUfpblQsk+g4aThQrGCMxgFHp2ifxD7WcxeG4NOcW+9uwNRfwT/3W0hjvQQzoIZfoDxO +c1q59TNdlCaqk3kjF7/Kv5gReY8ZQF0E8ja06a3jktvjpo6feRqJOmY1K2zgEQmRtyi MvVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=vVRMoukX; 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 d21si1865418edn.173.2020.09.25.07.13.04; Fri, 25 Sep 2020 07:13:04 -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=vVRMoukX; 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 S1728999AbgIYOND (ORCPT + 4 others); Fri, 25 Sep 2020 10:13:03 -0400 Received: from mailout1.w1.samsung.com ([210.118.77.11]:50612 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729003AbgIYOMf (ORCPT ); Fri, 25 Sep 2020 10:12:35 -0400 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20200925141232euoutp019046fb950a94f8cfb3fa648125de5595~4DEPUStcA1106011060euoutp01i for ; Fri, 25 Sep 2020 14:12:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20200925141232euoutp019046fb950a94f8cfb3fa648125de5595~4DEPUStcA1106011060euoutp01i DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1601043153; bh=3ltQiItP68nXp8N3IBI3XXVcqofC79een0tYDl29GjA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vVRMoukXJ5HNYLbm748H4LiTBAJa0ousS/FoLUWf49ulTtpogh7VHSSK3dIhd5Y2V 9mYe8/JrMzg0FIIi+EZJCIn5ASUj6MS8mjwrPnLhHzvnDvdzcRoSJxeWkcBD61Zr/s Snm7LpQRmyKDSeQ5vzQrKAmPHgNEbu04gon+RrQk= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20200925141232eucas1p10fb238168f0c99e32b62d941069b65fe~4DEPB2K6q1940819408eucas1p1n; Fri, 25 Sep 2020 14:12:32 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 7E.E4.06456.0DAFD6F5; Fri, 25 Sep 2020 15:12:32 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20200925141232eucas1p1c021913b0c2505e6c77e5078cf2be74f~4DEOvTZXi1940419404eucas1p1a; Fri, 25 Sep 2020 14:12:32 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20200925141232eusmtrp284b523f34bd8d1593911fae5fa0c6843~4DEOumih02568825688eusmtrp2H; Fri, 25 Sep 2020 14:12:32 +0000 (GMT) X-AuditID: cbfec7f2-809ff70000001938-64-5f6dfad09031 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 01.49.06314.0DAFD6F5; Fri, 25 Sep 2020 15:12:32 +0100 (BST) Received: from AMDC2765.digital.local (unknown [106.120.51.73]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200925141231eusmtip14a76b08e359f1b36da078e53a06d6557~4DEOMkMY61699716997eusmtip1l; Fri, 25 Sep 2020 14:12:31 +0000 (GMT) From: Marek Szyprowski To: Linux IOMMU , linux-media@vger.kernel.org, linux-samsung-soc@vger.kernel.org Cc: Marek Szyprowski , Robin Murphy , Joerg Roedel , Christoph Hellwig , Sylwester Nawrocki , Krzysztof Kozlowski , Bartlomiej Zolnierkiewicz , Tomasz Figa , linux-kernel@vger.kernel.org Subject: [PATCH 3/8] iommu: iova: add support for 'first-fit' algorithm Date: Fri, 25 Sep 2020 16:12:13 +0200 Message-Id: <20200925141218.13550-4-m.szyprowski@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200925141218.13550-1-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrAKsWRmVeSWpSXmKPExsWy7djP87oXfuXGG9yfp2axccZ6VouVq48y WSzYb23ROXsDu8X580Di8q45bBY9G7ayWsw4v4/JYu2Ru+wWBz88YbVof/qS2eJz6z82Bx6P JwfnMXmsmbeG0WN2w0UWj02rOtk8Jt9Yzuix+2YDm0ffllWMHp83yQVwRHHZpKTmZJalFunb JXBl7Dv2hLXgnWzF/OvzmRoYj0p0MXJwSAiYSNxsLOpi5OIQEljBKNG1/iorhPOFUWJp60Nm COczo8S/rn1sMB0vO0Ih4ssZJY5OuckM13HrdR9LFyMnB5uAoUTX2y6wBhGBEollJ/hAapgF njBJ7Pm7kAkkLizgLtH/qxCknEVAVWL3/YlgrbwCthJ7e84ygtgSAvISqzccYAaxOQXsJB5e PMAIMkdCYB27xPSuJhaIIheJ11c3sUPYwhKvjm+BsmUk/u+czwTR0Mwo8fDcWnYIp4dR4nLT DKgV1hJ3zv0Cu5RZQFNi/S59iLCjxN9ji5ggPuaTuPFWECTMDGRO2jadGSLMK9HRJgRRrSYx 6/g6uLUHL1yCKvGQmL3JBhI8ExklOvs3MU1glJ+FsGsBI+MqRvHU0uLc9NRiw7zUcr3ixNzi 0rx0veT83E2MwHRz+t/xTzsYv15KOsQowMGoxMN74lFuvBBrYllxZe4hRgkOZiURXqezp+OE eFMSK6tSi/Lji0pzUosPMUpzsCiJ8xovehkrJJCeWJKanZpakFoEk2Xi4JRqYJy7ZvOClsNV Xy6GWE9L0O1YN8v0XsDZ6EteN4s+lLSr6Xc/07G1/OO5ViQ3RFr8/zpnlz/7fv4Jq8/iCzUN XZ1XH1n86ubSRzuctA/pzDN8VcnXKBh2K6yGv/DI5iXyuU9ffDSXiI1L71adEfWb8fz2k31C Na/L9Xy+vPuXu/Sr4cEnvzasSlViKc5INNRiLipOBAAjRxZMMwMAAA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpkkeLIzCtJLcpLzFFi42I5/e/4Xd0Lv3LjDQ7eFLbYOGM9q8XK1UeZ LBbst7bonL2B3eL8eSBxedccNoueDVtZLWac38dksfbIXXaLgx+esFq0P33JbPG59R+bA4/H k4PzmDzWzFvD6DG74SKLx6ZVnWwek28sZ/TYfbOBzaNvyypGj8+b5AI4ovRsivJLS1IVMvKL S2yVog0tjPQMLS30jEws9QyNzWOtjEyV9O1sUlJzMstSi/TtEvQy9h17wlrwTrZi/vX5TA2M RyW6GDk4JARMJF52hHYxcnIICSxllNj7UxLElhCQkTg5rYEVwhaW+HOti62LkQuo5hOjxOqz 19hBEmwChhJdb0ESnBwiAmUSHVe2MoMUMQu8YZK4++oHO8gCYQF3if5fhSA1LAKqErvvT2QB sXkFbCX29pxlhFggL7F6wwFmEJtTwE7i4cUDjCCtQkA1+x86TWDkW8DIsIpRJLW0ODc9t9hQ rzgxt7g0L10vOT93EyMw+Lcd+7l5B+OljcGHGAU4GJV4eE88yo0XYk0sK67MPcQowcGsJMLr dPZ0nBBvSmJlVWpRfnxRaU5q8SFGU6CbJjJLiSbnAyMzryTe0NTQ3MLS0NzY3NjMQkmct0Pg YIyQQHpiSWp2ampBahFMHxMHp1QDY5CPwBnv7NDUstnPZp7Q9bpVMj323tcLUbFXJzlmf2o2 vPd12tcL70u+Nr4IjV9q5Gun4vhfa18mx8o1njtYj9nmFqXPCzhsy/1+3+RYNe7tPw7xcfap +n/79Pcpw7a5JWVTghOPdFVpvDjVwn2Xsc8nmSmtVr6Cv2J7+bd1By88DH+/7V7WOyWW4oxE Qy3mouJEAI9Y0oSUAgAA X-CMS-MailID: 20200925141232eucas1p1c021913b0c2505e6c77e5078cf2be74f X-Msg-Generator: CA X-RootMTR: 20200925141232eucas1p1c021913b0c2505e6c77e5078cf2be74f X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200925141232eucas1p1c021913b0c2505e6c77e5078cf2be74f References: <20200925141218.13550-1-m.szyprowski@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org Add support for the 'first-fit' allocation algorithm. It will be used for the special case of implementing DMA_ATTR_LOW_ADDRESS, so this path doesn't use IOVA cache. Signed-off-by: Marek Szyprowski --- drivers/iommu/iova.c | 78 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/iova.h | 2 ++ 2 files changed, 80 insertions(+) -- 2.17.1 diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c index 87555ed1737a..0911d36f7ee5 100644 --- a/drivers/iommu/iova.c +++ b/drivers/iommu/iova.c @@ -227,6 +227,59 @@ static int __alloc_and_insert_iova_range(struct iova_domain *iovad, return -ENOMEM; } +static unsigned long +__iova_get_aligned_start(unsigned long start, unsigned long size) +{ + unsigned long mask = __roundup_pow_of_two(size) - 1; + + return (start + mask) & ~mask; +} + +static int __alloc_and_insert_iova_range_forward(struct iova_domain *iovad, + unsigned long size, unsigned long limit_pfn, + struct iova *new) +{ + struct rb_node *curr; + unsigned long flags; + unsigned long start, limit; + + spin_lock_irqsave(&iovad->iova_rbtree_lock, flags); + + curr = rb_first(&iovad->rbroot); + limit = limit_pfn; + start = __iova_get_aligned_start(iovad->start_pfn, size); + + while (curr) { + struct iova *curr_iova = rb_entry(curr, struct iova, node); + struct rb_node *next = rb_next(curr); + + start = __iova_get_aligned_start(curr_iova->pfn_hi + 1, size); + if (next) { + struct iova *next_iova = rb_entry(next, struct iova, node); + limit = next_iova->pfn_lo - 1; + } else { + limit = limit_pfn; + } + + if ((start + size) <= limit) + break; /* found a free slot */ + curr = next; + } + + if (!curr && start + size > limit) { + spin_unlock_irqrestore(&iovad->iova_rbtree_lock, flags); + return -ENOMEM; + } + + new->pfn_lo = start; + new->pfn_hi = new->pfn_lo + size - 1; + iova_insert_rbtree(&iovad->rbroot, new, curr); + + spin_unlock_irqrestore(&iovad->iova_rbtree_lock, flags); + + return 0; +} + static struct kmem_cache *iova_cache; static unsigned int iova_cache_users; static DEFINE_MUTEX(iova_cache_mutex); @@ -398,6 +451,31 @@ free_iova(struct iova_domain *iovad, unsigned long pfn) } EXPORT_SYMBOL_GPL(free_iova); +/** + * alloc_iova_first_fit - allocates an iova from the beginning of address space + * @iovad: - iova domain in question + * @size: - size of page frames to allocate + * @limit_pfn: - max limit address + * Returns a pfn the allocated iova starts at or IOVA_BAD_ADDR in the case + * of a failure. +*/ +unsigned long +alloc_iova_first_fit(struct iova_domain *iovad, unsigned long size, + unsigned long limit_pfn) +{ + struct iova *new_iova = alloc_iova_mem(); + + if (!new_iova) + return IOVA_BAD_ADDR; + + if (__alloc_and_insert_iova_range_forward(iovad, size, limit_pfn, new_iova)) { + free_iova_mem(new_iova); + return IOVA_BAD_ADDR; + } + return new_iova->pfn_lo; +} +EXPORT_SYMBOL_GPL(alloc_iova_first_fit); + /** * alloc_iova_fast - allocates an iova from rcache * @iovad: - iova domain in question diff --git a/include/linux/iova.h b/include/linux/iova.h index 69737e6bcef6..01c29044488c 100644 --- a/include/linux/iova.h +++ b/include/linux/iova.h @@ -152,6 +152,8 @@ void queue_iova(struct iova_domain *iovad, unsigned long data); unsigned long alloc_iova_fast(struct iova_domain *iovad, unsigned long size, unsigned long limit_pfn, bool flush_rcache); +unsigned long alloc_iova_first_fit(struct iova_domain *iovad, unsigned long size, + unsigned long limit_pfn); struct iova *reserve_iova(struct iova_domain *iovad, unsigned long pfn_lo, unsigned long pfn_hi); void copy_reserved_iova(struct iova_domain *from, struct iova_domain *to); From patchwork Fri Sep 25 14:12:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 313504 Delivered-To: patch@linaro.org Received: by 2002:a92:5ad1:0:0:0:0:0 with SMTP id b78csp1179624ilg; Fri, 25 Sep 2020 07:12:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxagHni/S7t+WWKm2iym2zG+1mSFfJlezoVWKeTSRoBTTwypwg184G+k0ESGnyJ23UxUy0s X-Received: by 2002:a17:906:2c14:: with SMTP id e20mr3047735ejh.205.1601043170376; Fri, 25 Sep 2020 07:12:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601043170; cv=none; d=google.com; s=arc-20160816; b=zPuxId8WxXXvGvAhpEAUtkkRLKQ6cZq9qOMXqL+Ovu+Sf1TIjgzODRgoUIGC3Ru+3i xs4RRTGEfwYw4jGT5qOGnv/TT4gB/N0x2yM2DoeGzn2LEPPtChqqTfRbgrfhUvHuKXvQ qwu9jPxqVi4Fj/3YMsi0i2JIHxUnlFE5Ygq5hrh2mL76kuo3u0f4vLqaIW6eBgWOL70l CUf7AVPOkZ8orAw4TiXFn8Si66v6UScyiNDTwPXFFKqDpEerXB5J67Y5y8Su+aPMJjAI KP4xPfeqNDf9I267HWqL4TzGR5iWHZnRE7SCFFySabNAegtPfqGtC/Nd7sJg1EPLkC0+ 8akQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:cms-type:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter; bh=ne9u7VvtcKUtNJGd6gpwAnIIX9HybL1toIE7vYsodus=; b=ERRH56t112UDzGo8/HgiyoYGVzQNgz9/eV9RZ/mWHJ2m8U8Kv0hWORoC5EUMUx86h3 iLqri+zEbbASCVD+dM1vQCT1wlnT2B8BDCEOdr9tXbcagG2ZBBCC/4XYta/hOy48aLWQ 9BrJB3S5gn8Q5HdIg7ub6XsUxsaOXmve2oUVEN/ebqeCBJdeb3KSTMRNPkmEyYjUCCLo 8iXiqdDH1Ty7UxGt25H+xI0lMGv4mya6DfDjQtqO+Bu2rdD2eTGRdf57qeurUqvI5tNq JYoUBqYAyNJDqIIpOQUvA1ctnpPSE64YsG6bqqszgIcfGjJVEYjTpSwXFZY5o/F9mKY7 dzXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b="r4uF/aox"; 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 lu21si1908320ejb.482.2020.09.25.07.12.50; Fri, 25 Sep 2020 07:12: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="r4uF/aox"; 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 S1729066AbgIYOMt (ORCPT + 4 others); Fri, 25 Sep 2020 10:12:49 -0400 Received: from mailout1.w1.samsung.com ([210.118.77.11]:50627 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729058AbgIYOMg (ORCPT ); Fri, 25 Sep 2020 10:12:36 -0400 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20200925141234euoutp0159ed880eb451ac1e92a6c7cf7f22ad84~4DEQfQRHL1038410384euoutp01H for ; Fri, 25 Sep 2020 14:12:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20200925141234euoutp0159ed880eb451ac1e92a6c7cf7f22ad84~4DEQfQRHL1038410384euoutp01H DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1601043154; bh=ne9u7VvtcKUtNJGd6gpwAnIIX9HybL1toIE7vYsodus=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r4uF/aoxITpAjSLsg7hVtIW/4nmNKTFksX95LoeSEKU1dkHOLLpnzpmqwSPhp+1RW tgQRyWvGivBhxKBcfHp63r08sTn/S6dKUxpOblxp1Zr37Jihpdw4shWVckzIbbupVf wSH18f0De37EsOVLAQ38sl/6cVOJKzTPUv14E4Wg= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20200925141233eucas1p2cca36e0b11cc5db9cbda616b70e7a9fe~4DEQAmdTr3045930459eucas1p2x; Fri, 25 Sep 2020 14:12:33 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id C8.D3.06318.1DAFD6F5; Fri, 25 Sep 2020 15:12:33 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20200925141233eucas1p2148ace93f157bd631edd8db4e8df664b~4DEPw4PUF3139231392eucas1p21; Fri, 25 Sep 2020 14:12:33 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20200925141233eusmtrp2ff5345af0a8d80a26e9c2b715254c4ed~4DEPwRptr2568825688eusmtrp2J; Fri, 25 Sep 2020 14:12:33 +0000 (GMT) X-AuditID: cbfec7f5-371ff700000018ae-81-5f6dfad1ad2a Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id D2.49.06314.1DAFD6F5; Fri, 25 Sep 2020 15:12:33 +0100 (BST) Received: from AMDC2765.digital.local (unknown [106.120.51.73]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200925141232eusmtip1a73066b6d091025c6bf9b7bd592e77e2~4DEPNuSm21158111581eusmtip1J; Fri, 25 Sep 2020 14:12:32 +0000 (GMT) From: Marek Szyprowski To: Linux IOMMU , linux-media@vger.kernel.org, linux-samsung-soc@vger.kernel.org Cc: Marek Szyprowski , Robin Murphy , Joerg Roedel , Christoph Hellwig , Sylwester Nawrocki , Krzysztof Kozlowski , Bartlomiej Zolnierkiewicz , Tomasz Figa , linux-kernel@vger.kernel.org Subject: [PATCH 5/8] iommu: dma-iommu: add support for DMA_ATTR_LOW_ADDRESS Date: Fri, 25 Sep 2020 16:12:15 +0200 Message-Id: <20200925141218.13550-6-m.szyprowski@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200925141218.13550-1-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA0VSb0hTURzt7m1vb8vJazO8aCkMDMrU/EM9MKWi8EVf+lBEiq6lDxV9U/bU 0g8xkpYuFTNiS0MtKm1zOpdKrlJn6oSRa0mlaIpmlJYQTTP/pPl8al8u53d+59xzuFwMkT4S +GHpqhxKrVJmylExv61vcSDEvUQrDpl7g4lmQ5OAeGrq5RG1ndFEcZVFSLhc68eg7T5KlFha BYTB1cEjzD2fhIT955SAuPllGiE8N1bRY17klL2aRzZUNwCySuPmk1ZjMUreGaoD5IthDUqW tRgB6bEGnMXixUdTqMz0PEodFntJnFb9+gOS3RxydfGbAdWAuiAdEGEQj4JW87RQB8SYFK8H cKXehHLDHIDGMg+fGzwAVo/OoFsWzZoN4RZ1AC6PVPC3LY52LZ9VoXg41M3q1h0Y5oPnwCf9 3qwGwad48OXfBzxWI8PPwP7vywiL+XgQHG8cE7JYgsfA7o/DCJcWCE2Wrg0swmPhhLsLsBdB 3CiEc9Mtm6KTUDtn2awngzOOFiGH98C19hoeZygEcGLALOSGEgAHrxsAp4qGowNLG1URfD9s soVx9HHoqvkNWBri3nBodhdLI+uwok2PcLQEFmmlnHofrHQ0bsfa377brEbCsrXPgHug2wDe m3yMloPAyv9htQAYgS+Vy9CpFBOpoq6EMkqayVWlhiZn0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M60QmhmcER5ctNJOJ3z/yeHN0re2eN/7sPLvFaLU1zuf6c j6lddOFpHdNx8UNPThQ9T+la5S0RITzjodnt/G0rfmux2Riv9DrGXMwoa6LEUpyRaKjFXFSc CAAJRGSXlwIAAA== X-CMS-MailID: 20200925141233eucas1p2148ace93f157bd631edd8db4e8df664b X-Msg-Generator: CA X-RootMTR: 20200925141233eucas1p2148ace93f157bd631edd8db4e8df664b X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200925141233eucas1p2148ace93f157bd631edd8db4e8df664b References: <20200925141218.13550-1-m.szyprowski@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org Implement support for the DMA_ATTR_LOW_ADDRESS DMA attribute. If it has been set, call alloc_iova_first_fit() instead of the alloc_iova_fast() to allocate the new IOVA from the beginning of the address space. Signed-off-by: Marek Szyprowski --- drivers/iommu/dma-iommu.c | 50 +++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 12 deletions(-) -- 2.17.1 diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 0ea87023306f..ab39659c727a 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -401,6 +401,18 @@ static int dma_info_to_prot(enum dma_data_direction dir, bool coherent, } #define DMA_ALLOC_IOVA_COHERENT BIT(0) +#define DMA_ALLOC_IOVA_FIRST_FIT BIT(1) + +static unsigned int dma_attrs_to_alloc_flags(unsigned long attrs, bool coherent) +{ + unsigned int flags = 0; + + if (coherent) + flags |= DMA_ALLOC_IOVA_COHERENT; + if (attrs & DMA_ATTR_LOW_ADDRESS) + flags |= DMA_ALLOC_IOVA_FIRST_FIT; + return flags; +} static dma_addr_t iommu_dma_alloc_iova(struct iommu_domain *domain, struct device *dev, size_t size, unsigned int flags) @@ -433,13 +445,23 @@ static dma_addr_t iommu_dma_alloc_iova(struct iommu_domain *domain, dma_limit = min(dma_limit, (u64)domain->geometry.aperture_end); /* Try to get PCI devices a SAC address */ - if (dma_limit > DMA_BIT_MASK(32) && dev_is_pci(dev)) - iova = alloc_iova_fast(iovad, iova_len, - DMA_BIT_MASK(32) >> shift, false); + if (dma_limit > DMA_BIT_MASK(32) && dev_is_pci(dev)) { + if (unlikely(flags & DMA_ALLOC_IOVA_FIRST_FIT)) + iova = alloc_iova_first_fit(iovad, iova_len, + DMA_BIT_MASK(32) >> shift); + else + iova = alloc_iova_fast(iovad, iova_len, + DMA_BIT_MASK(32) >> shift, false); + } - if (iova == IOVA_BAD_ADDR) - iova = alloc_iova_fast(iovad, iova_len, dma_limit >> shift, - true); + if (iova == IOVA_BAD_ADDR) { + if (unlikely(flags & DMA_ALLOC_IOVA_FIRST_FIT)) + iova = alloc_iova_first_fit(iovad, iova_len, + dma_limit >> shift); + else + iova = alloc_iova_fast(iovad, iova_len, + dma_limit >> shift, true); + } if (iova != IOVA_BAD_ADDR) return (dma_addr_t)iova << shift; @@ -593,6 +615,7 @@ static void *iommu_dma_alloc_remap(struct device *dev, size_t size, struct iova_domain *iovad = &cookie->iovad; bool coherent = dev_is_dma_coherent(dev); int ioprot = dma_info_to_prot(DMA_BIDIRECTIONAL, coherent, attrs); + unsigned int flags = dma_attrs_to_alloc_flags(attrs, true); pgprot_t prot = dma_pgprot(dev, PAGE_KERNEL, attrs); unsigned int count, min_size, alloc_sizes = domain->pgsize_bitmap; struct page **pages; @@ -622,7 +645,7 @@ static void *iommu_dma_alloc_remap(struct device *dev, size_t size, return NULL; size = iova_align(iovad, size); - iova = iommu_dma_alloc_iova(domain, dev, size, DMA_ALLOC_IOVA_COHERENT); + iova = iommu_dma_alloc_iova(domain, dev, size, flags); if (iova == DMA_MAPPING_ERROR) goto out_free_pages; @@ -732,12 +755,13 @@ static dma_addr_t iommu_dma_map_page(struct device *dev, struct page *page, unsigned long offset, size_t size, enum dma_data_direction dir, unsigned long attrs) { + unsigned int flags = dma_attrs_to_alloc_flags(attrs, false); phys_addr_t phys = page_to_phys(page) + offset; bool coherent = dev_is_dma_coherent(dev); int prot = dma_info_to_prot(dir, coherent, attrs); dma_addr_t dma_handle; - dma_handle = __iommu_dma_map(dev, phys, size, prot, 0); + dma_handle = __iommu_dma_map(dev, phys, size, prot, flags); if (!coherent && !(attrs & DMA_ATTR_SKIP_CPU_SYNC) && dma_handle != DMA_MAPPING_ERROR) arch_sync_dma_for_device(phys, size, dir); @@ -842,6 +866,7 @@ static int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg, struct iova_domain *iovad = &cookie->iovad; struct scatterlist *s, *prev = NULL; int prot = dma_info_to_prot(dir, dev_is_dma_coherent(dev), attrs); + unsigned int flags = dma_attrs_to_alloc_flags(attrs, false); dma_addr_t iova; size_t iova_len = 0; unsigned long mask = dma_get_seg_boundary(dev); @@ -892,7 +917,7 @@ static int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg, prev = s; } - iova = iommu_dma_alloc_iova(domain, dev, iova_len, 0); + iova = iommu_dma_alloc_iova(domain, dev, iova_len, flags); if (iova == DMA_MAPPING_ERROR) goto out_restore_sg; @@ -940,7 +965,8 @@ static dma_addr_t iommu_dma_map_resource(struct device *dev, phys_addr_t phys, size_t size, enum dma_data_direction dir, unsigned long attrs) { return __iommu_dma_map(dev, phys, size, - dma_info_to_prot(dir, false, attrs) | IOMMU_MMIO, 0); + dma_info_to_prot(dir, false, attrs) | IOMMU_MMIO, + dma_attrs_to_alloc_flags(attrs, false)); } static void iommu_dma_unmap_resource(struct device *dev, dma_addr_t handle, @@ -1027,6 +1053,7 @@ static void *iommu_dma_alloc_pages(struct device *dev, size_t size, static void *iommu_dma_alloc(struct device *dev, size_t size, dma_addr_t *handle, gfp_t gfp, unsigned long attrs) { + unsigned int flags = dma_attrs_to_alloc_flags(attrs, true); bool coherent = dev_is_dma_coherent(dev); int ioprot = dma_info_to_prot(DMA_BIDIRECTIONAL, coherent, attrs); struct page *page = NULL; @@ -1047,8 +1074,7 @@ static void *iommu_dma_alloc(struct device *dev, size_t size, if (!cpu_addr) return NULL; - *handle = __iommu_dma_map(dev, page_to_phys(page), size, ioprot, - DMA_ALLOC_IOVA_COHERENT); + *handle = __iommu_dma_map(dev, page_to_phys(page), size, ioprot, flags); if (*handle == DMA_MAPPING_ERROR) { __iommu_dma_free(dev, size, cpu_addr); return NULL; From patchwork Fri Sep 25 14:12:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 257133 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E341AC4727D for ; Fri, 25 Sep 2020 14:12:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9F39A20936 for ; Fri, 25 Sep 2020 14:12:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="nkc7oWKE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729040AbgIYOMs (ORCPT ); Fri, 25 Sep 2020 10:12:48 -0400 Received: from mailout2.w1.samsung.com ([210.118.77.12]:48860 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729066AbgIYOMg (ORCPT ); Fri, 25 Sep 2020 10:12:36 -0400 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20200925141234euoutp0229b2bcb85cd76e687eaf0880f34a0236~4DEQ-jEpH0580805808euoutp02- for ; Fri, 25 Sep 2020 14:12:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20200925141234euoutp0229b2bcb85cd76e687eaf0880f34a0236~4DEQ-jEpH0580805808euoutp02- DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1601043154; bh=9CE6iiMKRXDrSc5Ywn3xo3KvMo/QgjPcqFMYHr22ArI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nkc7oWKE/tnx9QS3LqwiW6uiLXsIZ62s3nwkWf00PzJNQnN9qKRUftktGWL0KU0i/ T6c8aLjJ+n4fiqU0xanyIYZaBUGAVjZceBVHFC88tOEQF7tTttl9yomMIF9Qgf4l0O qpPVcj4KhDSXOwJwSvqX1npd6895+ZR0dcfrI7N8= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20200925141234eucas1p115abf7d0d5af792ff10abab0adc70c05~4DEQtKIQa2131721317eucas1p1Z; Fri, 25 Sep 2020 14:12:34 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id CF.E4.06456.2DAFD6F5; Fri, 25 Sep 2020 15:12:34 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20200925141234eucas1p13ab5a15da95185dcc99300772d0d72ce~4DEQVaiXg1940419404eucas1p1d; Fri, 25 Sep 2020 14:12:34 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200925141234eusmtrp121f952957ba05d6361967c7e2ae9dd31~4DEQUsHWJ1676616766eusmtrp1j; Fri, 25 Sep 2020 14:12:34 +0000 (GMT) X-AuditID: cbfec7f2-809ff70000001938-68-5f6dfad2453e Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 4E.7B.06017.1DAFD6F5; Fri, 25 Sep 2020 15:12:33 +0100 (BST) Received: from AMDC2765.digital.local (unknown [106.120.51.73]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200925141233eusmtip13cef9bafb9f5c4dede41b7b90c27a9c2~4DEPuzSgK1697816978eusmtip16; Fri, 25 Sep 2020 14:12:33 +0000 (GMT) From: Marek Szyprowski To: Linux IOMMU , linux-media@vger.kernel.org, linux-samsung-soc@vger.kernel.org Cc: Marek Szyprowski , Robin Murphy , Joerg Roedel , Christoph Hellwig , Sylwester Nawrocki , Krzysztof Kozlowski , Bartlomiej Zolnierkiewicz , Tomasz Figa , linux-kernel@vger.kernel.org Subject: [PATCH 6/8] media: platform: exynos4-is: remove all references to physicall addresses Date: Fri, 25 Sep 2020 16:12:16 +0200 Message-Id: <20200925141218.13550-7-m.szyprowski@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200925141218.13550-1-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA0VSa0hTURzn7N7dXYeT67Q8aCSMCjLykQoXNCkJutGXiOqDlDr1oiPvlN3N NBDGzMyxajU0mSUq5GO+ljizpfkonTKc+ci0DPJFKJiiqSimeb1qXw6/83v8f38OB0ekZUJf XKFU0yqlPFWGidHmng3X2aFNJi74y6+j5JuiBiFZXdMtIEvbI8j8YquIHBjYPYbtLzHSYLUJ yaKBDwKy7tMPEdm5NCMk82bnEHIldxu74E7NdJYIqNqSWkAVawdRqtGSj1GmsUpAvR/XYtST JgugVhqPX8NjxJFJdKoig1YFRcWLU0yVwnSzDmSWtpqEWjCaqgduOCTCYN9UsUAPxLiUqAKw pr0fcIKU+ANgQ7+GF1YAnC2oRw8ST7sLRbypcleoVR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eAA2mYrsf+h0wRGvgWMDKsYRVJLi3PTc4uN9IoT c4tL89L1kvNzNzECY2DbsZ9bdjB2vQs+xCjAwajEw6vwNDdeiDWxrLgy9xCjBAezkgiv09nT cUK8KYmVValF+fFFpTmpxYcYTYFumsgsJZqcD4zPvJJ4Q1NDcwtLQ3Njc2MzCyVx3g6BgzFC AumJJanZqakFqUUwfUwcnFINjLpn7mfUm+YLC169VP04+b/vgZN9EeeTwybL7c/hWS9TdG6x 9oLIF27n91wTi0u1ZT282NHYWkM56PGB1YVTfppNj1NMuTxBo+FQVn27q2cyd7Dul4oo9lvT 95X5iVi2BTBP9hax6b/2PNnAu5FH5pZ+uILFC6kryWt9P2n/DavzUirbvVpZiaU4I9FQi7mo OBEALv7o85cCAAA= X-CMS-MailID: 20200925141234eucas1p13ab5a15da95185dcc99300772d0d72ce X-Msg-Generator: CA X-RootMTR: 20200925141234eucas1p13ab5a15da95185dcc99300772d0d72ce X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200925141234eucas1p13ab5a15da95185dcc99300772d0d72ce References: <20200925141218.13550-1-m.szyprowski@samsung.com> 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 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(-) 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 Fri Sep 25 14:12:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 257134 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D085CC47428 for ; Fri, 25 Sep 2020 14:12:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 963B320BED for ; Fri, 25 Sep 2020 14:12:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="JHN70VRT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729089AbgIYOMj (ORCPT ); Fri, 25 Sep 2020 10:12:39 -0400 Received: from mailout2.w1.samsung.com ([210.118.77.12]:48873 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729074AbgIYOMh (ORCPT ); Fri, 25 Sep 2020 10:12:37 -0400 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20200925141235euoutp02e98d096c7bfd4f21eec462f5b70dd0d3~4DERuCvjA0555705557euoutp02j for ; Fri, 25 Sep 2020 14:12:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20200925141235euoutp02e98d096c7bfd4f21eec462f5b70dd0d3~4DERuCvjA0555705557euoutp02j DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1601043155; bh=WyoHT5SEz9Amsu38i1vI5h0g/DzRPuCz+HV37m4rE/0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JHN70VRT6Annnh4FHxUM8nafCP6lnQCa3ucMIgkZCJiDVhGld7mIeMMcnOos4NrBP qCO+EJYbPfApiSqfykrvKyRcXKn0Tuz72jtgXeG6xm8u9paS/1kVrtUmYsCzb6fXSH ZlLgl0g0fmlNqR+7lHm+P3wS/EtF3wDZT+VHNquo= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20200925141234eucas1p1385edc8c0b11f161b65e63baa9eaf358~4DERJ5gUu1940419404eucas1p1e; Fri, 25 Sep 2020 14:12:34 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id CC.49.05997.2DAFD6F5; Fri, 25 Sep 2020 15:12:34 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20200925141234eucas1p2876321230b7f0910242e0e28b3a8388b~4DEQzM1ze3255932559eucas1p2q; Fri, 25 Sep 2020 14:12:34 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200925141234eusmtrp139714b168f691a2ededd30a7ff7f959e~4DEQyhqQz1719217192eusmtrp1F; Fri, 25 Sep 2020 14:12:34 +0000 (GMT) X-AuditID: cbfec7f4-677ff7000000176d-07-5f6dfad2266a Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 1F.7B.06017.2DAFD6F5; Fri, 25 Sep 2020 15:12:34 +0100 (BST) Received: from AMDC2765.digital.local (unknown [106.120.51.73]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200925141234eusmtip1cfb375be450a315315d51288ee078386~4DEQQ1Wta1699416994eusmtip1l; Fri, 25 Sep 2020 14:12:33 +0000 (GMT) From: Marek Szyprowski To: Linux IOMMU , linux-media@vger.kernel.org, linux-samsung-soc@vger.kernel.org Cc: Marek Szyprowski , Robin Murphy , Joerg Roedel , Christoph Hellwig , Sylwester Nawrocki , Krzysztof Kozlowski , Bartlomiej Zolnierkiewicz , Tomasz Figa , linux-kernel@vger.kernel.org Subject: [PATCH 7/8] media: platform: exynos4-is: use DMA_ATTR_LOW_ADDRESS Date: Fri, 25 Sep 2020 16:12:17 +0200 Message-Id: <20200925141218.13550-8-m.szyprowski@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200925141218.13550-1-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrMKsWRmVeSWpSXmKPExsWy7djP87qXfuXGG+y+Y2yxccZ6VouVq48y WSzYb23ROXsDu8X580Di8q45bBY9G7ayWsw4v4/JYu2Ru+wWBz88YbVof/qS2eJz6z82Bx6P JwfnMXmsmbeG0WN2w0UWj02rOtk8Jt9Yzuix+2YDm0ffllWMHp83yQVwRHHZpKTmZJalFunb JXBl3Ll0ja3gFWfFrO1bmBsYZ3F0MXJySAiYSKzp2MTYxcjFISSwglHi95EbzBDOF0aJ9d9P QDmfGSWeLt3JDNPS+fMaO0RiOaPEzI1nGeFaXn/byghSxSZgKNH1touti5GDQ0SgRGLZCT6Q GmaBJ0wSe/4uZAKpERbwkvj2ZA0LiM0ioCqx/sRTNhCbV8BWYvb9iVDb5CVWbzgAZnMK2Ek8 vHgAbJmEwCp2iYYH09lBFkgIuEhc2RUIUS8s8er4FnYIW0bi9OQeFoj6ZkaJh+fWskM4PYwS l5tmMEJUWUvcOfcL7FJmAU2J9bv0IcKOEpdPXoKazydx460gSJgZyJy0bTozRJhXoqNNCKJa TWLW8XVwaw9euAR1vofE444TbJDwmcgocWH5RpYJjPKzEJYtYGRc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6XOSq9/Apl j3J0X+6QUKpu/vJP9efphzs+Hbw5O83haFbYZZ96p+oZjZs/q2iX3p3ar7/rR66wQ9kbs7kn RQrD9mvMUhLUOVx/w7FGKWLKGfFA9yRjMTsbJ6Fvk0Q0313Ju5pwZIpQttIcJZbijERDLeai 4kQAELzNQ5cCAAA= X-CMS-MailID: 20200925141234eucas1p2876321230b7f0910242e0e28b3a8388b X-Msg-Generator: CA X-RootMTR: 20200925141234eucas1p2876321230b7f0910242e0e28b3a8388b X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200925141234eucas1p2876321230b7f0910242e0e28b3a8388b References: <20200925141218.13550-1-m.szyprowski@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org Exynos4-IS driver relied on the way the ARM DMA-IOMMU glue code worked - mainly it relied on the fact that the allocator used first-fit algorithm and the first allocated buffer were 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 DMA attribute to force such behavior of the DMA-mapping code. Signed-off-by: Marek Szyprowski --- drivers/media/platform/exynos4-is/fimc-is.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/exynos4-is/fimc-is.c b/drivers/media/platform/exynos4-is/fimc-is.c index 41b841a96338..9d3556eae5d3 100644 --- a/drivers/media/platform/exynos4-is/fimc-is.c +++ b/drivers/media/platform/exynos4-is/fimc-is.c @@ -335,8 +335,9 @@ 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.vaddr = dma_alloc_attrs(dev, FIMC_IS_CPU_MEM_SIZE, + &is->memory.addr, GFP_KERNEL, + DMA_ATTR_LOW_ADDRESS); if (is->memory.vaddr == NULL) return -ENOMEM; From patchwork Fri Sep 25 14:12:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 313501 Delivered-To: patch@linaro.org Received: by 2002:a92:5ad1:0:0:0:0:0 with SMTP id b78csp1179473ilg; Fri, 25 Sep 2020 07:12:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy93jNojyMB1WwBioQ3gmTWQGvUcrhoGOUsSbbviWbmdNP1F2IQYJ0L2LtqxbR8/fHYNuMg X-Received: by 2002:a05:6402:1007:: with SMTP id c7mr1522605edu.339.1601043160158; Fri, 25 Sep 2020 07:12:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601043160; cv=none; d=google.com; s=arc-20160816; b=liRndQY4bTAxqOgedGgZHEhEdNrIjKkTftpuMCawPxaXHsbHX1FCV97lHZgJQ56Vtc yauPhBO9TcLpUgRNMTOExdnh0b0Wz3KPc/JdH19hH35bsF82a4CWdOmpZyQzqgEcWp/j lW0SeSnWJlVrjujwDVjYlDCmJUXn6tH9zCPw8xYhmqBBusCiF051IRbXaTyfs+wGjSOK IUqJpxvEk1T7TpO6ckFjFww99X0SYmL2iiNN8v+aOMR0q5GONLQC/hJ9thWVuZEqC0k4 S5muHcBsvzyKfuziG5Tdot9Jf41Tc19T0+ktWiH+80PFCMwn7InyfQHx4g3Sufna9zj/ c6ew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:cms-type:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter; bh=A2laEXZodce4y5WBoAT6Pjadi2R3gn3tegjGhZC+nCo=; b=VKLvbFHHo5qVH9PGlQUTHkWVC8hj5VQxwJ3oBLaI5C9ZdPHvSFJpu0Z8ev1MBeZnYw Q7iTm2E7k37ywTEJlOqwosOQ58DVA/4zuvSbXnVbtEa+yg/esF4AL3xaSelErTvYygTU QXRT/NY1ccEf7FiUwMyA1xs2jzGiMZurY8+/6/FDc3b2xknXOJIx8bIGrfU751xCTP31 Nb8KvYPUpONmdjD2CYPR7fRnSdi2CGBZMACFieEf+m6Qya93q4XESAwe9VYik1Ln9nM7 ste5dkpV/7Thtmwpd1fIQDiUk1cPMWBYVp5AI54KtlC7JgpJGw3vlvrf9BF51Ifif7GT 5Iig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=c5dlImAA; 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 p26si1892592ejf.86.2020.09.25.07.12.39; Fri, 25 Sep 2020 07:12:40 -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=c5dlImAA; 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 S1728963AbgIYOMi (ORCPT + 4 others); Fri, 25 Sep 2020 10:12:38 -0400 Received: from mailout2.w1.samsung.com ([210.118.77.12]:48838 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728976AbgIYOMi (ORCPT ); Fri, 25 Sep 2020 10:12:38 -0400 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20200925141236euoutp02401368d465bb27e27fb7067f13693fc6~4DESiDUar0567505675euoutp02R for ; Fri, 25 Sep 2020 14:12:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20200925141236euoutp02401368d465bb27e27fb7067f13693fc6~4DESiDUar0567505675euoutp02R DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1601043156; bh=A2laEXZodce4y5WBoAT6Pjadi2R3gn3tegjGhZC+nCo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c5dlImAAGjXOLALkzLSxco9t+hTfogWjaJOeNlQGh/CgYJrjw6R1p5pLqLivUlPcX Kt6aPDPww8d7smnGyynpZya+ZyDxqhiLYVK8fJtXndWO6fLSJOiWe4u3ZoLiMfilnp Q/cnMeLsA4XspYMcPoV9wWiYMaLush7x3iSeRnkM= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20200925141235eucas1p2c0fd6d41a1e32313a7f76616c49dff0d~4DERuK1tA3259232592eucas1p24; Fri, 25 Sep 2020 14:12:35 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 0E.49.05997.3DAFD6F5; Fri, 25 Sep 2020 15:12:35 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20200925141235eucas1p17c6aceae82acfc424cdc7521938c1510~4DERWTSVx1940819408eucas1p1q; Fri, 25 Sep 2020 14:12:35 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20200925141235eusmtrp2e2c691b27fc90284bfacfb0221b2003a~4DERVo8Ja2568825688eusmtrp2K; Fri, 25 Sep 2020 14:12:35 +0000 (GMT) X-AuditID: cbfec7f4-65dff7000000176d-0a-5f6dfad3ea5b Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id D3.49.06314.3DAFD6F5; Fri, 25 Sep 2020 15:12:35 +0100 (BST) Received: from AMDC2765.digital.local (unknown [106.120.51.73]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200925141234eusmtip1f8fd73db4a18c7c8418ebe0d2e207e9a~4DEQwxQIX1229912299eusmtip10; Fri, 25 Sep 2020 14:12:34 +0000 (GMT) From: Marek Szyprowski To: Linux IOMMU , linux-media@vger.kernel.org, linux-samsung-soc@vger.kernel.org Cc: Marek Szyprowski , Robin Murphy , Joerg Roedel , Christoph Hellwig , Sylwester Nawrocki , Krzysztof Kozlowski , Bartlomiej Zolnierkiewicz , Tomasz Figa , linux-kernel@vger.kernel.org Subject: [PATCH 8/8] media: platform: s5p-mfc: use DMA_ATTR_LOW_ADDRESS Date: Fri, 25 Sep 2020 16:12:18 +0200 Message-Id: <20200925141218.13550-9-m.szyprowski@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200925141218.13550-1-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrIKsWRmVeSWpSXmKPExsWy7djP87qXf+XGGyw/KG+xccZ6VouVq48y WSzYb23ROXsDu8X580Di8q45bBY9G7ayWsw4v4/JYu2Ru+wWBz88YbVof/qS2eJz6z82Bx6P JwfnMXmsmbeG0WN2w0UWj02rOtk8Jt9Yzuix+2YDm0ffllWMHp83yQVwRHHZpKTmZJalFunb JXBlTLg6kblgO0/FrKM2DYzbuLoYOTkkBEwkrq87wdTFyMUhJLCCUeLp8pmsEM4XRomrv/qZ IZzPjBKPfs5nhGnZfHEpG0RiOaPE8lkHGOFaXu6fyA5SxSZgKNH1tguoioNDRKBEYtkJPpAa ZoEnTBJ7/i5kAqkRFnCX2Nj/Hmwqi4CqxKZPk1lAbF4BW4lHr0B6QbbJS6zecIAZxOYUsJN4 eBFimYTAKnaJn4ufMEMUuQAl/rBC2MISr45vYYewZST+75zPBNHQzCjx8Nxadginh1HictMM qIesJe6c+wV2KrOApsT6XfoQYUeJfY9fs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WlOanFhxhNgW6ayCwlmpwPjM68knhDU0NzC0tDc2NzYzMLJXHeDoGDMUIC 6YklqdmpqQWpRTB9TBycUg2MDi373oU+l+O6xWgu3sz0qKb1hZG7OG/0PLVf7tFsfbduWpps fdvqHs2zSrYx5jdHnMK6OCNDq2NRUx+sr2iZart96jEBw7RPH39P310/Kf/q9kz3QM+nNoHG 8W0skjWztdI4V02Mqzf6pXzP656faeHd7i3vrp8ItZ9luUXweHrshemlLzuVWIozEg21mIuK EwHdk2WglgIAAA== X-CMS-MailID: 20200925141235eucas1p17c6aceae82acfc424cdc7521938c1510 X-Msg-Generator: CA X-RootMTR: 20200925141235eucas1p17c6aceae82acfc424cdc7521938c1510 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200925141235eucas1p17c6aceae82acfc424cdc7521938c1510 References: <20200925141218.13550-1-m.szyprowski@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org S5P-MFC driver relied on the way the ARM DMA-IOMMU glue code worked - mainly it relied on the fact that the allocator used first-fit algorithm and the first allocated buffer were 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 limit the dma_mask to size of the DMA window the hardware can use and add the needed DMA attribute to force proper IOVA allocation of the firmware buffer. Signed-off-by: Marek Szyprowski --- drivers/media/platform/s5p-mfc/s5p_mfc.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) -- 2.17.1 diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c b/drivers/media/platform/s5p-mfc/s5p_mfc.c index eba2b9f040df..171fd9fd22e4 100644 --- a/drivers/media/platform/s5p-mfc/s5p_mfc.c +++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c @@ -1199,8 +1199,12 @@ static int s5p_mfc_configure_common_memory(struct s5p_mfc_dev *mfc_dev) if (!mfc_dev->mem_bitmap) return -ENOMEM; - mfc_dev->mem_virt = dma_alloc_coherent(dev, mem_size, - &mfc_dev->mem_base, GFP_KERNEL); + /* MFC v5 can access memory only via the 256M window */ + if (exynos_is_iommu_available(dev) && !IS_MFCV6_PLUS(mfc_dev)) + dma_set_mask_and_coherent(dev, SZ_256M - 1); + + mfc_dev->mem_virt = dma_alloc_attrs(dev, mem_size, &mfc_dev->mem_base, + GFP_KERNEL, DMA_ATTR_LOW_ADDRESS); if (!mfc_dev->mem_virt) { kfree(mfc_dev->mem_bitmap); dev_err(dev, "failed to preallocate %ld MiB for the firmware and context buffers\n",