From patchwork Fri Aug 29 15:54:27 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 36310 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f199.google.com (mail-ie0-f199.google.com [209.85.223.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A79F1202DD for ; Fri, 29 Aug 2014 15:56:56 +0000 (UTC) Received: by mail-ie0-f199.google.com with SMTP id tr6sf15330621ieb.6 for ; Fri, 29 Aug 2014 08:56:56 -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=jm/6X58q0scCyOk9a3JbXc1huDVi8D8KfRUv4yxVa1M=; b=RzwQ6RY/ThEGpWj46HKuQq7TLt3QZsshlsEy8ozY0x1cRU23skolOwphK3QerKXCL7 +P1xqqtTsJfbbxfye29Q8zOZYKgZUu1erch40DAMUdscsJdD2125PySyT1waEd/zZ3dz JJFzZcW0r5cgrVr0SlZac3bNfbs/QXQvQdn1+fOmeL2MznsvRTKXpoR0mlS4iGUQaTzs Zu3tar2gHrAphToF6qmhbz+2K+zsAE+BO4cgRKBAunIqYRtYod3xq9835wwM+mKlqY/X 6WURwsiQj6EQnK1/bYFJ+jckEBAptdHimGSfzAIDFnkOPAejL0u/fjLBYwpf3FE0QOsH 7qBg== X-Gm-Message-State: ALoCoQmkL09LFaJpib1XwKQdkW3b2a9Vh+JL5jtYj9mQrzjjDcgdpZDF0huL8wLYt6kla0MwfEef X-Received: by 10.182.4.73 with SMTP id i9mr6267335obi.28.1409327816245; Fri, 29 Aug 2014 08:56:56 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.93.228 with SMTP id d91ls1109779qge.41.gmail; Fri, 29 Aug 2014 08:56:56 -0700 (PDT) X-Received: by 10.220.192.196 with SMTP id dr4mr761811vcb.70.1409327816140; Fri, 29 Aug 2014 08:56:56 -0700 (PDT) Received: from mail-vc0-f171.google.com (mail-vc0-f171.google.com [209.85.220.171]) by mx.google.com with ESMTPS id k3si476162vdq.67.2014.08.29.08.56.56 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 29 Aug 2014 08:56:56 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.171 as permitted sender) client-ip=209.85.220.171; Received: by mail-vc0-f171.google.com with SMTP id id10so2679497vcb.30 for ; Fri, 29 Aug 2014 08:56:56 -0700 (PDT) X-Received: by 10.52.3.40 with SMTP id 8mr9342052vdz.24.1409327816051; Fri, 29 Aug 2014 08:56:56 -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 uj3csp37861vcb; Fri, 29 Aug 2014 08:56:55 -0700 (PDT) X-Received: by 10.66.159.8 with SMTP id wy8mr16660303pab.17.1409327814962; Fri, 29 Aug 2014 08:56:54 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id tk2si731340pac.83.2014.08.29.08.56.51 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 29 Aug 2014 08:56:52 -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 1XNOW7-0002M0-Uz; Fri, 29 Aug 2014 15:55:11 +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 1XNOVh-0000SF-9F; Fri, 29 Aug 2014 15:54:46 +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 s7TFsAwo008642; Fri, 29 Aug 2014 16:54:10 +0100 (BST) Received: by edgewater-inn.cambridge.arm.com (Postfix, from userid 1000) id CD4011AE067D; Fri, 29 Aug 2014 16:54:31 +0100 (BST) From: Will Deacon To: linux-arm-kernel@lists.infradead.org, iommu@lists.linux-foundation.org Subject: [RFC PATCH 4/7] iommu: provide helper function to configure an IOMMU for an of master Date: Fri, 29 Aug 2014 16:54:27 +0100 Message-Id: <1409327670-3495-5-git-send-email-will.deacon@arm.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1409327670-3495-1-git-send-email-will.deacon@arm.com> References: <1409327670-3495-1-git-send-email-will.deacon@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140829_085445_694889_34F40BEE X-CRM114-Status: GOOD ( 15.38 ) X-Spam-Score: -5.0 (-----) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-5.0 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 0.0 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, 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.171 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 | 36 ++++++++++++++++++++++++++++++++++++ include/linux/of_iommu.h | 6 ++++++ 3 files changed, 43 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..a7d3b3a13b83 100644 --- a/drivers/iommu/of_iommu.c +++ b/drivers/iommu/of_iommu.c @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -90,6 +91,41 @@ int of_get_dma_window(struct device_node *dn, const char *prefix, int index, } EXPORT_SYMBOL_GPL(of_get_dma_window); +int of_iommu_configure(struct device *dev) +{ + struct of_phandle_args iommu_spec; + struct bus_type *bus = dev->bus; + const struct iommu_ops *ops = bus->iommu_ops; + int ret = -EINVAL, idx = 0; + + if (!iommu_present(bus)) + return -ENODEV; + + /* + * 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)) { + void *data = of_iommu_get_data(iommu_spec.np); + + of_node_put(iommu_spec.np); + if (!ops->add_device_master_ids) + return -ENODEV; + + ret = ops->add_device_master_ids(dev, iommu_spec.args_count, + iommu_spec.args, data); + if (ret) + break; + + idx++; + } + + return ret; +} + void __init of_iommu_init(void) { struct device_node *np; diff --git a/include/linux/of_iommu.h b/include/linux/of_iommu.h index 29f2f3f88d6a..85c6d1152624 100644 --- a/include/linux/of_iommu.h +++ b/include/linux/of_iommu.h @@ -1,6 +1,7 @@ #ifndef __OF_IOMMU_H #define __OF_IOMMU_H +#include #include #ifdef CONFIG_OF_IOMMU @@ -10,6 +11,7 @@ extern int of_get_dma_window(struct device_node *dn, const char *prefix, size_t *size); extern void of_iommu_init(void); +extern int of_iommu_configure(struct device *dev); #else @@ -21,6 +23,10 @@ static inline int of_get_dma_window(struct device_node *dn, const char *prefix, } static inline void of_iommu_init(void) { } +static inline int of_iommu_configure(struct device *dev) +{ + return -ENODEV; +} #endif /* CONFIG_OF_IOMMU */