From patchwork Tue Sep 2 17:56:21 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 36508 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qg0-f69.google.com (mail-qg0-f69.google.com [209.85.192.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 8A3262032B for ; Tue, 2 Sep 2014 17:58:44 +0000 (UTC) Received: by mail-qg0-f69.google.com with SMTP id a108sf22763838qge.8 for ; Tue, 02 Sep 2014 10:58:44 -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=2NDi1sfYElVm7Ifb5crUCOgEg0b5FyHSc4955Jev1nk=; b=AtxaV14Ic4ivM0uZWU4aLNTEXIEZ23SbPdLpuTuUUDh7w6ZOsW083HdygaEJu8bIos 3U5iWeeRttOFR8SaZryNaBOlyJM7oseTzYo12QALS51osyr9IFB+RwUbLv/RFQfLHEJC jRc3Sfvdes+PoXXNWVitj+gkHByTmelLhHENvU4sFFwD973+TS4kKP/uBINIutIJ2y8j aowWIG5I3WxZqoHI4WGAqog9fNxqVf4G6H1gijhZoDJdxOiiW+THqEYTWNoRUB7hoJ6e Oq0Qb9EGbeDyweXpG3d82nuQnSmu6DGxBfxbbw3gytZwTEIsgjoqrkQcYf+g0pz6JX+m k64g== X-Gm-Message-State: ALoCoQnZD8/4r1wiEGzgZ0VdJKEqZErFH7qOUN5rjqnN01twhC47ct09RYaFL51xnYapFyLrvcxf X-Received: by 10.236.112.234 with SMTP id y70mr19896159yhg.32.1409680724396; Tue, 02 Sep 2014 10:58:44 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.34.206 with SMTP id l72ls2512998qgl.46.gmail; Tue, 02 Sep 2014 10:58:44 -0700 (PDT) X-Received: by 10.220.95.132 with SMTP id d4mr1855780vcn.33.1409680724292; Tue, 02 Sep 2014 10:58:44 -0700 (PDT) Received: from mail-vc0-f174.google.com (mail-vc0-f174.google.com [209.85.220.174]) by mx.google.com with ESMTPS id k7si2651577vdf.18.2014.09.02.10.58.44 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 02 Sep 2014 10:58:44 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.174 as permitted sender) client-ip=209.85.220.174; Received: by mail-vc0-f174.google.com with SMTP id hy4so7513243vcb.33 for ; Tue, 02 Sep 2014 10:58:44 -0700 (PDT) X-Received: by 10.52.106.168 with SMTP id gv8mr408166vdb.80.1409680724206; Tue, 02 Sep 2014 10:58:44 -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 uj3csp565767vcb; Tue, 2 Sep 2014 10:58:43 -0700 (PDT) X-Received: by 10.70.42.135 with SMTP id o7mr14649178pdl.141.1409680723279; Tue, 02 Sep 2014 10:58:43 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id l5si6930660pdr.213.2014.09.02.10.58.42 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Sep 2014 10:58:43 -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 1XOsKn-0001p3-8N; Tue, 02 Sep 2014 17:57:37 +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 1XOsJw-0001CA-RH; Tue, 02 Sep 2014 17:56:45 +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 s82Hu9wo015645; Tue, 2 Sep 2014 18:56:09 +0100 (BST) Received: by edgewater-inn.cambridge.arm.com (Postfix, from userid 1000) id 3F7761AE0884; 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 1/7] iommu: provide early initialisation hook for IOMMU drivers Date: Tue, 2 Sep 2014 18:56:21 +0100 Message-Id: <1409680587-29818-2-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_105645_265727_A662A32E X-CRM114-Status: GOOD ( 13.99 ) 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.174 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 IOMMU drivers must be initialised before any of their upstream devices, otherwise the relevant iommu_ops won't be configured for the bus in question. To solve this, a number of IOMMU drivers use initcalls to initialise the driver before anything has a chance to be probed. Whilst this solves the immediate problem, it leaves the job of probing the IOMMU completely separate from the iommu_ops to configure the IOMMU, which are called on a per-bus basis and require the driver to figure out exactly which instance of the IOMMU is being requested. In particular, the add_device callback simply passes a struct device to the driver, which then has to parse firmware tables or probe buses to identify the relevant IOMMU instance. This patch takes the first step in addressing this problem by adding an early initialisation pass for IOMMU drivers, giving them the ability to set some per-instance data on their of_node in the form of a new iommu_data structure. This can later be used when parsing OF masters to identify the IOMMU instance in question. Signed-off-by: Will Deacon --- drivers/iommu/of_iommu.c | 14 ++++++++++++++ include/asm-generic/vmlinux.lds.h | 2 ++ include/linux/iommu.h | 6 ++++++ include/linux/of_iommu.h | 23 +++++++++++++++++++++++ 4 files changed, 45 insertions(+) diff --git a/drivers/iommu/of_iommu.c b/drivers/iommu/of_iommu.c index e550ccb7634e..f9209666157c 100644 --- a/drivers/iommu/of_iommu.c +++ b/drivers/iommu/of_iommu.c @@ -89,3 +89,17 @@ int of_get_dma_window(struct device_node *dn, const char *prefix, int index, return 0; } EXPORT_SYMBOL_GPL(of_get_dma_window); + +void __init of_iommu_init(void) +{ + struct device_node *np; + const struct of_device_id *match, *matches = &__iommu_of_table; + + for_each_matching_node_and_match(np, matches, &match) { + const int (*init_fn)(struct device_node *) = match->data; + + if (init_fn(np)) + pr_err("Failed to initialise IOMMU %s\n", + of_node_full_name(np)); + } +} diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index 5ba0360663a7..b75ede8f99ae 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -162,6 +162,7 @@ #define CLKSRC_OF_TABLES() OF_TABLE(CONFIG_CLKSRC_OF, clksrc) #define IRQCHIP_OF_MATCH_TABLE() OF_TABLE(CONFIG_IRQCHIP, irqchip) #define CLK_OF_TABLES() OF_TABLE(CONFIG_COMMON_CLK, clk) +#define IOMMU_OF_TABLES() OF_TABLE(CONFIG_OF_IOMMU, iommu) #define RESERVEDMEM_OF_TABLES() OF_TABLE(CONFIG_OF_RESERVED_MEM, reservedmem) #define CPU_METHOD_OF_TABLES() OF_TABLE(CONFIG_SMP, cpu_method) #define EARLYCON_OF_TABLES() OF_TABLE(CONFIG_SERIAL_EARLYCON, earlycon) @@ -495,6 +496,7 @@ CLK_OF_TABLES() \ RESERVEDMEM_OF_TABLES() \ CLKSRC_OF_TABLES() \ + IOMMU_OF_TABLES() \ CPU_METHOD_OF_TABLES() \ KERNEL_DTB() \ IRQCHIP_OF_MATCH_TABLE() \ diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 20f9a527922a..fdddb14cd8f5 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -57,6 +57,12 @@ struct iommu_domain { struct iommu_domain_geometry geometry; }; +struct iommu_data { + struct iommu_domain *domain; + struct iova_domain *iovad; + void *priv; +}; + #define IOMMU_CAP_CACHE_COHERENCY 0x1 #define IOMMU_CAP_INTR_REMAP 0x2 /* isolates device intrs */ diff --git a/include/linux/of_iommu.h b/include/linux/of_iommu.h index 51a560f34bca..a39e2d78f735 100644 --- a/include/linux/of_iommu.h +++ b/include/linux/of_iommu.h @@ -1,12 +1,17 @@ #ifndef __OF_IOMMU_H #define __OF_IOMMU_H +#include +#include + #ifdef CONFIG_OF_IOMMU extern int of_get_dma_window(struct device_node *dn, const char *prefix, int index, unsigned long *busno, dma_addr_t *addr, size_t *size); +extern void of_iommu_init(void); + #else static inline int of_get_dma_window(struct device_node *dn, const char *prefix, @@ -16,6 +21,24 @@ static inline int of_get_dma_window(struct device_node *dn, const char *prefix, return -EINVAL; } +static inline void of_iommu_init(void) { } + #endif /* CONFIG_OF_IOMMU */ +static inline void of_iommu_set_data(struct device_node *np, + struct iommu_data *data) +{ + np->data = data; +} + +static inline struct iommu_data *of_iommu_get_data(struct device_node *np) +{ + return np->data; +} + +extern struct of_device_id __iommu_of_table; + +#define IOMMU_OF_DECLARE(name, compat, fn) \ + OF_DECLARE_1(iommu, name, compat, fn) + #endif /* __OF_IOMMU_H */