From patchwork Fri Sep 12 16:34:53 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 37356 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f198.google.com (mail-lb0-f198.google.com [209.85.217.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A8D98206A5 for ; Fri, 12 Sep 2014 16:37:43 +0000 (UTC) Received: by mail-lb0-f198.google.com with SMTP id 10sf650859lbg.5 for ; Fri, 12 Sep 2014 09:37:42 -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=m5GARPrOt4akNkqvvr6LK9hVv3O98hoyubxEVnXVH50=; b=SxZoa1PtkGI9LquKSnQwQQ0kFZxj22xr4PKegE5/2aFrkMRkACVrXveovrizBIhCDB VaGu0qBzet8G8yDaSxnLHBQlqhp5hqkvTS5/QMJe5JUh6UKmntl9mOAO7bLhVA6GK+/i Wmvf7VmbbvU3QH5X3qrG31Sqt7xVe1VLRnWL6tPIFZpWJZpfsz4Bhu80jEa02V98MjLZ M8S8mpH2QBfG8nJyFoTCErDkQ9H9j8CBs9OgE71m9hR53RzV+Qpbkm6NsbghKlEFItzg fiwQVgto3Y3R/FQ6NWg2zeUovhnmWWgvZSiSUth3+qOVfkE76TnT3CPhPzw9eKQdCJ8s x6NQ== X-Gm-Message-State: ALoCoQkYNSHOsL1hn8YBNRo/t/0Zzdd1GQPdBcOtvead2lhVE8A1aBF+pzkSSGqxf4Q91DEQbzsW X-Received: by 10.180.221.169 with SMTP id qf9mr954347wic.5.1410539862360; Fri, 12 Sep 2014 09:37:42 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.37.137 with SMTP id y9ls189064laj.93.gmail; Fri, 12 Sep 2014 09:37:42 -0700 (PDT) X-Received: by 10.152.20.1 with SMTP id j1mr10074450lae.57.1410539862037; Fri, 12 Sep 2014 09:37:42 -0700 (PDT) Received: from mail-la0-f51.google.com (mail-la0-f51.google.com [209.85.215.51]) by mx.google.com with ESMTPS id uo9si7252494lbb.134.2014.09.12.09.37.42 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 12 Sep 2014 09:37:42 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.51 as permitted sender) client-ip=209.85.215.51; Received: by mail-la0-f51.google.com with SMTP id gi9so1324894lab.10 for ; Fri, 12 Sep 2014 09:37:41 -0700 (PDT) X-Received: by 10.152.22.137 with SMTP id d9mr10226045laf.29.1410539861952; Fri, 12 Sep 2014 09:37:41 -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.112.141.42 with SMTP id rl10csp769239lbb; Fri, 12 Sep 2014 09:37:41 -0700 (PDT) X-Received: by 10.66.90.162 with SMTP id bx2mr13633461pab.39.1410539860343; Fri, 12 Sep 2014 09:37:40 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id iv3si9029546pbd.30.2014.09.12.09.37.39 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Sep 2014 09:37: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 1XSTpf-0002wQ-UY; Fri, 12 Sep 2014 16:36:23 +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 1XSToo-00020N-V1; Fri, 12 Sep 2014 16:35:32 +0000 Received: from edgewater-inn.cambridge.arm.com (edgewater-inn.cambridge.arm.com [10.1.203.204]) by cam-admin0.cambridge.arm.com (8.12.6/8.12.6) with ESMTP id s8CGYuwo029974; Fri, 12 Sep 2014 17:34:56 +0100 (BST) Received: by edgewater-inn.cambridge.arm.com (Postfix, from userid 1000) id 925671AE0BB1; Fri, 12 Sep 2014 17:34:57 +0100 (BST) From: Will Deacon To: linux-arm-kernel@lists.infradead.org, iommu@lists.linux-foundation.org Subject: [RFC PATCH v3 5/7] dma-mapping: detect and configure IOMMU in of_dma_configure Date: Fri, 12 Sep 2014 17:34:53 +0100 Message-Id: <1410539695-29128-6-git-send-email-will.deacon@arm.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1410539695-29128-1-git-send-email-will.deacon@arm.com> References: <1410539695-29128-1-git-send-email-will.deacon@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140912_093531_863429_341C8450 X-CRM114-Status: GOOD ( 13.75 ) X-Spam-Score: -7.2 (-------) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-7.2 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] -2.2 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -0.0 SPF_PASS SPF: sender matches SPF record 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.215.51 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 | 4 +++- drivers/of/platform.c | 24 +++++++++++++++++------- include/linux/dma-mapping.h | 8 +++++++- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/arch/arm/include/asm/dma-mapping.h b/arch/arm/include/asm/dma-mapping.h index 7e9ac4f604c3..a8bb0c494bb3 100644 --- a/arch/arm/include/asm/dma-mapping.h +++ b/arch/arm/include/asm/dma-mapping.h @@ -121,7 +121,9 @@ 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, bool coherent) +static inline void arch_setup_dma_ops(struct device *dev, u64 dma_base, + u64 size, struct iommu_dma_mapping *iommu, + bool coherent) { if (coherent) set_dma_ops(dev, &arm_coherent_dma_ops); diff --git a/drivers/of/platform.c b/drivers/of/platform.c index 946dd7ae0394..95ebd38db545 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -166,6 +167,7 @@ static void of_dma_configure(struct platform_device *pdev) int ret; bool coherent; unsigned long offset; + struct iommu_dma_mapping *iommu; struct device *dev = &pdev->dev; /* @@ -195,7 +197,19 @@ static void of_dma_configure(struct platform_device *pdev) dev_dbg(dev, "device is%sdma coherent\n", coherent ? " " : " not "); - arch_setup_dma_ops(dev, coherent); + iommu = of_iommu_configure(dev); + dev_dbg(dev, "device is%sbehind an iommu\n", + iommu ? " " : " not "); + + arch_setup_dma_ops(dev, dma_addr, size, iommu, coherent); + + if (iommu) + kref_put(&iommu->kref, of_iommu_deconfigure); +} + +static void of_dma_deconfigure(struct platform_device *pdev) +{ + arch_teardown_dma_ops(&pdev->dev); } /** @@ -224,16 +238,12 @@ 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) { + of_dma_deconfigure(dev); platform_device_put(dev); goto err_clear_flag; } diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index e60e52d82db9..47e1ac30e300 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -138,7 +138,13 @@ static inline int dma_coerce_mask_and_coherent(struct device *dev, u64 mask) extern u64 dma_get_required_mask(struct device *dev); #ifndef arch_setup_dma_ops -static inline void arch_setup_dma_ops(struct device *dev, bool coherent) { } +static inline void arch_setup_dma_ops(struct device *dev, u64 dma_base, + u64 size, struct iommu_dma_mapping *iommu, + bool coherent) { } +#endif + +#ifndef arch_teardown_dma_ops +static inline void arch_teardown_dma_ops(struct device *dev) { } #endif static inline unsigned int dma_get_max_seg_size(struct device *dev)