From patchwork Tue Sep 2 17:56:24 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 36505 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f197.google.com (mail-ie0-f197.google.com [209.85.223.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id BE89C2032B for ; Tue, 2 Sep 2014 17:58:39 +0000 (UTC) Received: by mail-ie0-f197.google.com with SMTP id rp18sf39019476iec.8 for ; Tue, 02 Sep 2014 10:58:39 -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=KXl86WP2gFFj75w980BSB9kEH4y0UecgqZVgRAbC6N0=; b=LwwQ4TF9QiVfoeDTOm95Zc21v1p5+SieCsGgPjrbLR2xr0JmPXIKLuV0zYaQcwwkRr XVT1KV6J8Guffq7yC0JdrN1xmmfn3sx0tUNavkBqhMxyWL0fmqSWTuBfFFQUdyMDHUPa ZwFhCXbq5sLMIlzT6FmpJK95rK2SYOIDJNTA60BN6dvjBCAxWuChowREmaj0AVEB5TCk rg/nPiDiMktskpG5SiNrYF0hrL3oLO2KnS/xDnkKud/hHqTd4zKwk75dk1Jws4XEKwa4 SuVRUdE8Y2NfO7B/5a6WqhpulgKkWFhLuhErDAXAW0z7Y9VIYUtuOBw5NQvrpGC0x0SB 0Q7g== X-Gm-Message-State: ALoCoQm0PTCism/9+2cghHQ9cFNZcHQMPBQfBQRTSOGB/pqXP/8dPk722CwkgVkuQOLNHTCCEkyE X-Received: by 10.182.43.164 with SMTP id x4mr20475621obl.5.1409680719384; Tue, 02 Sep 2014 10:58:39 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.19.203 with SMTP id 69ls2398884qgh.27.gmail; Tue, 02 Sep 2014 10:58:39 -0700 (PDT) X-Received: by 10.52.248.42 with SMTP id yj10mr1191797vdc.50.1409680719272; Tue, 02 Sep 2014 10:58:39 -0700 (PDT) Received: from mail-vc0-f180.google.com (mail-vc0-f180.google.com [209.85.220.180]) by mx.google.com with ESMTPS id fc9si2656357vdc.2.2014.09.02.10.58.39 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 02 Sep 2014 10:58:39 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.180 as permitted sender) client-ip=209.85.220.180; Received: by mail-vc0-f180.google.com with SMTP id lf12so7248411vcb.25 for ; Tue, 02 Sep 2014 10:58:39 -0700 (PDT) X-Received: by 10.52.52.136 with SMTP id t8mr26439236vdo.21.1409680719054; Tue, 02 Sep 2014 10:58:39 -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 uj3csp565756vcb; Tue, 2 Sep 2014 10:58:38 -0700 (PDT) X-Received: by 10.66.174.17 with SMTP id bo17mr48796155pac.98.1409680715987; Tue, 02 Sep 2014 10:58:35 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id km1si7077395pbd.132.2014.09.02.10.58.35 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Sep 2014 10:58:35 -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 1XOsJx-0001FL-Qy; Tue, 02 Sep 2014 17:56:45 +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 1XOsJu-0001Bg-MD; Tue, 02 Sep 2014 17:56:43 +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 s82Hu9wo015648; Tue, 2 Sep 2014 18:56:09 +0100 (BST) Received: by edgewater-inn.cambridge.arm.com (Postfix, from userid 1000) id 6F8CB1AE08D1; 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 4/7] iommu: provide helper function to configure an IOMMU for an of master Date: Tue, 2 Sep 2014 18:56:24 +0100 Message-Id: <1409680587-29818-5-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_094534_BA2CA657 X-CRM114-Status: GOOD ( 16.23 ) 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.180 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 The generic IOMMU device-tree bindings can be used to add arbitrary OF masters to an IOMMU with a compliant binding. This patch introduces of_iommu_configure, which does exactly that. Signed-off-by: Will Deacon --- drivers/iommu/Kconfig | 2 +- drivers/iommu/of_iommu.c | 52 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/dma-mapping.h | 7 ++++++ include/linux/of_iommu.h | 8 +++++++ 4 files changed, 68 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig index dd5112265cc9..6d13f962f156 100644 --- a/drivers/iommu/Kconfig +++ b/drivers/iommu/Kconfig @@ -15,7 +15,7 @@ if IOMMU_SUPPORT config OF_IOMMU def_bool y - depends on OF + depends on OF && IOMMU_API config FSL_PAMU bool "Freescale IOMMU support" diff --git a/drivers/iommu/of_iommu.c b/drivers/iommu/of_iommu.c index f9209666157c..1188c929ffa7 100644 --- a/drivers/iommu/of_iommu.c +++ b/drivers/iommu/of_iommu.c @@ -18,6 +18,7 @@ */ #include +#include #include #include #include @@ -90,6 +91,57 @@ int of_get_dma_window(struct device_node *dn, const char *prefix, int index, } EXPORT_SYMBOL_GPL(of_get_dma_window); +struct iommu_dma_mapping *of_iommu_configure(struct device *dev) +{ + struct of_phandle_args iommu_spec; + struct iommu_dma_mapping *mapping; + struct bus_type *bus = dev->bus; + const struct iommu_ops *ops = bus->iommu_ops; + struct iommu_data *iommu = NULL; + int idx = 0; + + if (!iommu_present(bus) || !ops->of_xlate) + return NULL; + + /* + * We don't currently walk up the tree looking for a parent IOMMU. + * See the `Notes:' section of + * Documentation/devicetree/bindings/iommu/iommu.txt + */ + while (!of_parse_phandle_with_args(dev->of_node, "iommus", + "#iommu-cells", idx, + &iommu_spec)) { + struct device_node *np = iommu_spec.np; + struct iommu_data *data = of_iommu_get_data(np); + + if (!iommu) { + if (!ops->of_xlate(dev, &iommu_spec)) + iommu = data; + } else if (iommu != data) { + pr_warn("Rejecting device %s with multiple IOMMU instances\n", + dev_name(dev)); + iommu = NULL; + } + + of_node_put(np); + + if (!iommu) + break; + + idx++; + } + + if (!iommu) + return NULL; + + mapping = devm_kzalloc(dev, sizeof(*mapping), GFP_KERNEL); + if (!mapping) + return NULL; + + mapping->iommu = iommu; + return mapping; +} + void __init of_iommu_init(void) { struct device_node *np; diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index 0f7f7b68b0db..16bf92f71c3e 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -62,6 +62,13 @@ struct dma_map_ops { int is_phys; }; +struct iommu_data; + +struct iommu_dma_mapping { + struct iommu_data *iommu; + struct list_head node; +}; + #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1)) #define DMA_MASK_NONE 0x0ULL diff --git a/include/linux/of_iommu.h b/include/linux/of_iommu.h index a39e2d78f735..f2d3b1e780d7 100644 --- a/include/linux/of_iommu.h +++ b/include/linux/of_iommu.h @@ -1,9 +1,12 @@ #ifndef __OF_IOMMU_H #define __OF_IOMMU_H +#include #include #include +struct iommu_dma_mapping; + #ifdef CONFIG_OF_IOMMU extern int of_get_dma_window(struct device_node *dn, const char *prefix, @@ -11,6 +14,7 @@ extern int of_get_dma_window(struct device_node *dn, const char *prefix, size_t *size); extern void of_iommu_init(void); +extern struct iommu_dma_mapping *of_iommu_configure(struct device *dev); #else @@ -22,6 +26,10 @@ static inline int of_get_dma_window(struct device_node *dn, const char *prefix, } static inline void of_iommu_init(void) { } +static inline struct iommu_dma_mapping *of_iommu_configure(struct device *dev) +{ + return NULL; +} #endif /* CONFIG_OF_IOMMU */