From patchwork Tue Sep 2 17:56:25 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 36507 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f70.google.com (mail-pa0-f70.google.com [209.85.220.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id AD20D2032B for ; Tue, 2 Sep 2014 17:58:43 +0000 (UTC) Received: by mail-pa0-f70.google.com with SMTP id lf10sf74892079pab.5 for ; Tue, 02 Sep 2014 10:58:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id :in-reply-to:references:cc:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:content-type:content-transfer-encoding; bh=onqx1B6d9VKUYx49F/aSgM4JnkpoJB2sHOY1BaYoNag=; b=SRN+HwZgSSpkRsONokKZoj3KrxbGzy22yxrol3s5PFNLIy/nDdZ+FnTQSTtqczDSPC mYwV/p2zfHrSSCqwtlrhX0mRtBR3+BdB9/r5khVtOLU0PQOLc+zqnxoshKXtQqMDqHWh 3aBRJI0w0HYUwxDdCYn6MJBT5HhxASZ9O2ntuOhX1XNND8Qqv20oxJkmCH5RWuiCAC2h eKwgWgDZk0xDqzqGTajPooVMO7luMx7RJqrGs7VJN+ErnBY863lLBFKU2OlB0WwAiHmx ABbvXAwChRIvkIOwRZWhgJmIS70QFaY+c5ObOme+VNGzlvYurwYr2jCJI0BWIO+Omb4v +g+Q== X-Gm-Message-State: ALoCoQldzTo5ZgLcdbXvD+9WPJUC5LHr1kJnfns+d/tHrCmP3UIIQWXXb9j4qHvKQIhosrGFkgDk X-Received: by 10.68.69.98 with SMTP id d2mr19875742pbu.0.1409680723024; Tue, 02 Sep 2014 10:58:43 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.83.49 with SMTP id i46ls1706330qgd.10.gmail; Tue, 02 Sep 2014 10:58:42 -0700 (PDT) X-Received: by 10.221.49.133 with SMTP id va5mr1805476vcb.37.1409680722776; Tue, 02 Sep 2014 10:58:42 -0700 (PDT) Received: from mail-vc0-f176.google.com (mail-vc0-f176.google.com [209.85.220.176]) by mx.google.com with ESMTPS id f2si2631115vdf.74.2014.09.02.10.58.42 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 02 Sep 2014 10:58:42 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.176 as permitted sender) client-ip=209.85.220.176; Received: by mail-vc0-f176.google.com with SMTP id ik5so7474492vcb.35 for ; Tue, 02 Sep 2014 10:58:42 -0700 (PDT) X-Received: by 10.52.249.66 with SMTP id ys2mr1503260vdc.41.1409680722662; Tue, 02 Sep 2014 10:58:42 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.45.67 with SMTP id uj3csp565765vcb; Tue, 2 Sep 2014 10:58:42 -0700 (PDT) X-Received: by 10.66.249.34 with SMTP id yr2mr5575818pac.149.1409680720403; Tue, 02 Sep 2014 10:58:40 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id qw2si7186138pbb.80.2014.09.02.10.58.40 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Sep 2014 10:58:40 -0700 (PDT) Received-SPF: none (google.com: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org does not designate permitted sender hosts) client-ip=2001:1868:205::9; 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 1XOsKG-0001Ly-VO; Tue, 02 Sep 2014 17:57:04 +0000 Received: from cam-admin0.cambridge.arm.com ([217.140.96.50]) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XOsJv-0001Cb-AE; Tue, 02 Sep 2014 17:56:44 +0000 Received: from edgewater-inn.cambridge.arm.com (edgewater-inn.cambridge.arm.com [10.1.203.34]) by cam-admin0.cambridge.arm.com (8.12.6/8.12.6) with ESMTP id s82HuBwo015655; Tue, 2 Sep 2014 18:56:11 +0100 (BST) Received: by edgewater-inn.cambridge.arm.com (Postfix, from userid 1000) id 7DCDF1AE08D7; Tue, 2 Sep 2014 18:56:33 +0100 (BST) From: Will Deacon To: linux-arm-kernel@lists.infradead.org, iommu@lists.linux-foundation.org Subject: [RFC PATCH v2 5/7] dma-mapping: detect and configure IOMMU in of_dma_configure Date: Tue, 2 Sep 2014 18:56:25 +0100 Message-Id: <1409680587-29818-6-git-send-email-will.deacon@arm.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1409680587-29818-1-git-send-email-will.deacon@arm.com> References: <1409680587-29818-1-git-send-email-will.deacon@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140902_105643_773194_AF3242E2 X-CRM114-Status: GOOD ( 14.62 ) X-Spam-Score: -6.7 (------) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-6.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [217.140.96.50 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.7 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain Cc: jroedel@suse.de, arnd@arndb.de, Will Deacon , thierry.reding@gmail.com, laurent.pinchart@ideasonboard.com, Varun.Sethi@freescale.com, m.szyprowski@samsung.com, dwmw2@infradead.org, hdoyu@nvidia.com 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+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: will.deacon@arm.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.176 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 This patch extends of_dma_configure so that it sets up the IOMMU for a device, as well as the coherent/non-coherent DMA mapping ops. Signed-off-by: Will Deacon --- arch/arm/include/asm/dma-mapping.h | 5 ++++- drivers/of/platform.c | 36 ++++++++++++++++++++++-------------- include/linux/dma-mapping.h | 5 ++++- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/arch/arm/include/asm/dma-mapping.h b/arch/arm/include/asm/dma-mapping.h index dad006dabbe6..788b8eef40e8 100644 --- a/arch/arm/include/asm/dma-mapping.h +++ b/arch/arm/include/asm/dma-mapping.h @@ -122,7 +122,10 @@ static inline unsigned long dma_max_pfn(struct device *dev) #define dma_max_pfn(dev) dma_max_pfn(dev) static inline void arch_setup_dma_ops(struct device *dev, u64 mask, - unsigned long offset, bool coherent) + u64 dma_base, u64 size, + unsigned long offset, + struct iommu_dma_mapping *iommu, + bool coherent) { dev->coherent_dma_mask = mask; dev->dma_mask = &dev->coherent_dma_mask; diff --git a/drivers/of/platform.c b/drivers/of/platform.c index 484c558c63a6..6067f6423674 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -162,25 +163,37 @@ EXPORT_SYMBOL(of_device_alloc); */ static void of_dma_configure(struct platform_device *pdev) { - u64 dma_addr, paddr, size; + u64 dma_addr, paddr, size, mask; int ret; bool coherent; unsigned long offset; + struct iommu_dma_mapping *iommu; struct device *dev = &pdev->dev; + /* + * Set default dma-mask to 32 bit. Drivers are expected to setup + * the correct supported dma_mask. + */ + mask = DMA_BIT_MASK(32); + ret = of_dma_get_range(dev->of_node, &dma_addr, &paddr, &size); - offset = ret < 0 ? 0 : PFN_DOWN(paddr - dma_addr); - dev_dbg(dev, "dma_pfn_offset(%#08lx)\n", dev->dma_pfn_offset); + if (ret < 0) { + dma_addr = offset = 0; + size = mask; + } else { + offset = PFN_DOWN(paddr - dma_addr); + dev_dbg(dev, "dma_pfn_offset(%#08lx)\n", dev->dma_pfn_offset); + } coherent = of_dma_is_coherent(dev->of_node); dev_dbg(dev, "device is%sdma coherent\n", coherent ? " " : " not "); - /* - * Set default dma-mask to 32 bit. Drivers are expected to setup - * the correct supported dma_mask. - */ - arch_setup_dma_ops(dev, DMA_BIT_MASK(32), offset, coherent); + iommu = of_iommu_configure(dev); + dev_dbg(dev, "device is%sbehind an iommu\n", + iommu ? " " : " not "); + + arch_setup_dma_ops(dev, mask, dma_addr, size, offset, iommu, coherent); } /** @@ -209,14 +222,9 @@ static struct platform_device *of_platform_device_create_pdata( if (!dev) goto err_clear_flag; - of_dma_configure(dev); dev->dev.bus = &platform_bus_type; dev->dev.platform_data = platform_data; - - /* We do not fill the DMA ops for platform devices by default. - * This is currently the responsibility of the platform code - * to do such, possibly using a device notifier - */ + of_dma_configure(dev); if (of_device_add(dev) != 0) { platform_device_put(dev); diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index 16bf92f71c3e..19a31f55a5d0 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -138,7 +138,10 @@ extern u64 dma_get_required_mask(struct device *dev); #ifndef arch_setup_dma_ops static inline void arch_setup_dma_ops(struct device *dev, u64 mask, - unsigned long offset, bool coherent) { } + u64 dma_base, u64 size, + unsigned long offset, + struct iommu_dma_mapping *iommu, + bool coherent) { } #endif static inline unsigned int dma_get_max_seg_size(struct device *dev)