From patchwork Tue Aug 5 10:47:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 4677551 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 088F7C0338 for ; Tue, 5 Aug 2014 10:52:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3771320160 for ; Tue, 5 Aug 2014 10:52:31 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 69C2120172 for ; Tue, 5 Aug 2014 10:52:30 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XEcJk-0000ig-EY; Tue, 05 Aug 2014 10:50:08 +0000 Received: from mailout4.w1.samsung.com ([210.118.77.14]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XEcIv-0007Zz-1P for linux-arm-kernel@lists.infradead.org; Tue, 05 Aug 2014 10:49:18 +0000 Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout4.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0N9T00BFOY19V200@mailout4.w1.samsung.com> for linux-arm-kernel@lists.infradead.org; Tue, 05 Aug 2014 11:48:46 +0100 (BST) X-AuditID: cbfec7f4-b7f156d0000063c7-b2-53e0b697f7a0 Received: from eusync3.samsung.com ( [203.254.199.213]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id 9F.0C.25543.796B0E35; Tue, 05 Aug 2014 11:48:55 +0100 (BST) Received: from amdc1339.digital.local ([106.116.147.30]) by eusync3.samsung.com (Oracle Communications Messaging Server 7u4-23.01 (7.0.4.23.0) 64bit (built Aug 10 2011)) with ESMTPA id <0N9T0057MY17SE80@eusync3.samsung.com>; Tue, 05 Aug 2014 11:48:55 +0100 (BST) From: Marek Szyprowski To: iommu@lists.linux-foundation.org, linux-samsung-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 08/29] ARM: dma-mapping: add helpers for managing default per-device dma mappings Date: Tue, 05 Aug 2014 12:47:36 +0200 Message-id: <1407235677-26324-9-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.2 In-reply-to: <1407235677-26324-1-git-send-email-m.szyprowski@samsung.com> References: <1407235677-26324-1-git-send-email-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrOLMWRmVeSWpSXmKPExsVy+t/xq7rTtz0INnixy9zi76Rj7BbNi9ez WUy6P4HFYsF+a4vO2RvYLXoXXGWzONv0ht2ic+ISdosvVx4yWWx6fI3V4vKuOWwWM87vY7JY e+Quu8Wp65/ZLP71HmS0OHP6EqvF/z072C0Ov2lntTjycDe7xapdfxgtbv/mcxD1eHJwHpPH 71+TGD12zrrL7jG7Yyarx6ZVnWwe++euYffYvKTe4/a/x8wek28sZ/S4cqKJ1aO3+R2bx5ar 7SwefVtWMXp83iQXwBfFZZOSmpNZllqkb5fAldG4XKhgsmBFz+4LbA2MZ/i6GDk5JARMJO6t XcACYYtJXLi3nq2LkYtDSGApo8SU6/OYIJw+JolzDQtZQarYBAwlut52gVWJCPQySvQ3/QCr YhZYxyqxv/c62CxhgWSJiWd3s4PYLAKqEncWPWACsXkFPCRebTjPDLFPTuL/yxVgcU4BT4nD Nw+AbRACqvm5YQ37BEbeBYwMqxhFU0uTC4qT0nMN9YoTc4tL89L1kvNzNzFCIufLDsbFx6wO MQpwMCrx8BqcvhssxJpYVlyZe4hRgoNZSYRXYs2DYCHelMTKqtSi/Pii0pzU4kOMTBycUg2M +uqvTNunTrh0wlzv6U0n2/vMM3inJR5S9yt+wZxmycxp6p6xK/OA3EPxZ0y3Tc9U/b9Y4Pb/ bsW3dqXbHs0SV1fPvyYxo37m2W3/dG4sfZ7IPnsKq3jLHvl11SHOr9mizW4w9W6wWZN+a+Kx C6zNSp3p7KeVH9pfO/clZPpP+T1uuyv8CpInKrEUZyQaajEXFScCAJzxRH16AgAA X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140805_034917_230689_F01E66EB X-CRM114-Status: GOOD ( 11.78 ) X-Spam-Score: -5.7 (-----) Cc: Rob Herring , Thierry Reding , Shaik Ameer Basha , Arnd Bergmann , Inki Dae , Greg Kroah-Hartman , Joerg Roedel , "Rafael J. Wysocki" , Tomasz Figa , linaro-mm-sig@lists.linaro.org, Kyungmin Park , Kukjin Kim , Laurent Pinchart , Sylwester Nawrocki , Olof Johansson , Cho KyongHo , Marek Szyprowski X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds 2 helpers: arm_iommu_create_default_mapping and arm_iommu_release_default_mapping for managing default iommu-based dma-mapping address space, created for exlusive use only by the given device. Those helpers are convenient for setting up iommu-based dma-mapping for most typical devices in the system. Signed-off-by: Marek Szyprowski --- arch/arm/include/asm/dma-iommu.h | 5 +++++ arch/arm/mm/dma-mapping.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/arch/arm/include/asm/dma-iommu.h b/arch/arm/include/asm/dma-iommu.h index 8e3fcb9..ae3dac0 100644 --- a/arch/arm/include/asm/dma-iommu.h +++ b/arch/arm/include/asm/dma-iommu.h @@ -33,5 +33,10 @@ int arm_iommu_attach_device(struct device *dev, struct dma_iommu_mapping *mapping); void arm_iommu_detach_device(struct device *dev); +int arm_iommu_create_default_mapping(struct device *dev, dma_addr_t base, + size_t size); + +void arm_iommu_release_default_mapping(struct device *dev); + #endif /* __KERNEL__ */ #endif diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index 8161102..233a8cf 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -2106,4 +2106,35 @@ void arm_iommu_detach_device(struct device *dev) } EXPORT_SYMBOL_GPL(arm_iommu_detach_device); +int arm_iommu_create_default_mapping(struct device *dev, dma_addr_t base, + size_t size) +{ + struct dma_iommu_mapping *mapping; + int ret; + + mapping = arm_iommu_create_mapping(dev->bus, base, size); + if (IS_ERR(mapping)) + return PTR_ERR(mapping); + + ret = arm_iommu_attach_device(dev, mapping); + if (ret) { + arm_iommu_release_mapping(mapping); + return ret; + } + + return 0; +} +EXPORT_SYMBOL_GPL(arm_iommu_create_default_mapping); + +void arm_iommu_release_default_mapping(struct device *dev) +{ + struct dma_iommu_mapping *mapping = to_dma_iommu_mapping(dev); + if (!mapping) + return; + + arm_iommu_detach_device(dev); + arm_iommu_release_mapping(mapping); +} +EXPORT_SYMBOL_GPL(arm_iommu_release_default_mapping); + #endif