aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWill Deacon <will.deacon@arm.com>2014-08-27 09:40:58 -0400
committerWill Deacon <will.deacon@arm.com>2014-12-01 11:47:46 -0500
commit1cd076bf67793942ed921b766f7d461de2ebc0a2 (patch)
tree9be0b9940e90c029fa6e70c773b43d2baef5a8b6
parent5d01410fe4d92081f349b013a2e7a95429e4f2c9 (diff)
iommu: provide early initialisation hook for IOMMU drivers
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 store some per-instance data in their iommu_ops structure and store that in their of_node. This can later be used when parsing OF masters to identify the IOMMU instance in question. Acked-by: Arnd Bergmann <arnd@arndb.de> Acked-by: Joerg Roedel <jroedel@suse.de> Acked-by: Marek Szyprowski <m.szyprowski@samsung.com> Tested-by: Robin Murphy <robin.murphy@arm.com> Signed-off-by: Will Deacon <will.deacon@arm.com>
-rw-r--r--drivers/iommu/of_iommu.c17
-rw-r--r--include/asm-generic/vmlinux.lds.h2
-rw-r--r--include/linux/iommu.h2
-rw-r--r--include/linux/of_iommu.h25
4 files changed, 46 insertions, 0 deletions
diff --git a/drivers/iommu/of_iommu.c b/drivers/iommu/of_iommu.c
index e550ccb7634e..89b903406968 100644
--- a/drivers/iommu/of_iommu.c
+++ b/drivers/iommu/of_iommu.c
@@ -22,6 +22,9 @@
22#include <linux/of.h> 22#include <linux/of.h>
23#include <linux/of_iommu.h> 23#include <linux/of_iommu.h>
24 24
25static const struct of_device_id __iommu_of_table_sentinel
26 __used __section(__iommu_of_table_end);
27
25/** 28/**
26 * of_get_dma_window - Parse *dma-window property and returns 0 if found. 29 * of_get_dma_window - Parse *dma-window property and returns 0 if found.
27 * 30 *
@@ -89,3 +92,17 @@ int of_get_dma_window(struct device_node *dn, const char *prefix, int index,
89 return 0; 92 return 0;
90} 93}
91EXPORT_SYMBOL_GPL(of_get_dma_window); 94EXPORT_SYMBOL_GPL(of_get_dma_window);
95
96void __init of_iommu_init(void)
97{
98 struct device_node *np;
99 const struct of_device_id *match, *matches = &__iommu_of_table;
100
101 for_each_matching_node_and_match(np, matches, &match) {
102 const of_iommu_init_fn init_fn = match->data;
103
104 if (init_fn(np))
105 pr_err("Failed to initialise IOMMU %s\n",
106 of_node_full_name(np));
107 }
108}
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index aa70cbda327c..bee5d683074d 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -164,6 +164,7 @@
164#define CLKSRC_OF_TABLES() OF_TABLE(CONFIG_CLKSRC_OF, clksrc) 164#define CLKSRC_OF_TABLES() OF_TABLE(CONFIG_CLKSRC_OF, clksrc)
165#define IRQCHIP_OF_MATCH_TABLE() OF_TABLE(CONFIG_IRQCHIP, irqchip) 165#define IRQCHIP_OF_MATCH_TABLE() OF_TABLE(CONFIG_IRQCHIP, irqchip)
166#define CLK_OF_TABLES() OF_TABLE(CONFIG_COMMON_CLK, clk) 166#define CLK_OF_TABLES() OF_TABLE(CONFIG_COMMON_CLK, clk)
167#define IOMMU_OF_TABLES() OF_TABLE(CONFIG_OF_IOMMU, iommu)
167#define RESERVEDMEM_OF_TABLES() OF_TABLE(CONFIG_OF_RESERVED_MEM, reservedmem) 168#define RESERVEDMEM_OF_TABLES() OF_TABLE(CONFIG_OF_RESERVED_MEM, reservedmem)
168#define CPU_METHOD_OF_TABLES() OF_TABLE(CONFIG_SMP, cpu_method) 169#define CPU_METHOD_OF_TABLES() OF_TABLE(CONFIG_SMP, cpu_method)
169#define EARLYCON_OF_TABLES() OF_TABLE(CONFIG_SERIAL_EARLYCON, earlycon) 170#define EARLYCON_OF_TABLES() OF_TABLE(CONFIG_SERIAL_EARLYCON, earlycon)
@@ -497,6 +498,7 @@
497 CLK_OF_TABLES() \ 498 CLK_OF_TABLES() \
498 RESERVEDMEM_OF_TABLES() \ 499 RESERVEDMEM_OF_TABLES() \
499 CLKSRC_OF_TABLES() \ 500 CLKSRC_OF_TABLES() \
501 IOMMU_OF_TABLES() \
500 CPU_METHOD_OF_TABLES() \ 502 CPU_METHOD_OF_TABLES() \
501 KERNEL_DTB() \ 503 KERNEL_DTB() \
502 IRQCHIP_OF_MATCH_TABLE() \ 504 IRQCHIP_OF_MATCH_TABLE() \
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index e6a7c9ff72f2..7b83f9f8e11d 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -103,6 +103,7 @@ enum iommu_attr {
103 * @domain_get_attr: Query domain attributes 103 * @domain_get_attr: Query domain attributes
104 * @domain_set_attr: Change domain attributes 104 * @domain_set_attr: Change domain attributes
105 * @pgsize_bitmap: bitmap of supported page sizes 105 * @pgsize_bitmap: bitmap of supported page sizes
106 * @priv: per-instance data private to the iommu driver
106 */ 107 */
107struct iommu_ops { 108struct iommu_ops {
108 bool (*capable)(enum iommu_cap); 109 bool (*capable)(enum iommu_cap);
@@ -133,6 +134,7 @@ struct iommu_ops {
133 u32 (*domain_get_windows)(struct iommu_domain *domain); 134 u32 (*domain_get_windows)(struct iommu_domain *domain);
134 135
135 unsigned long pgsize_bitmap; 136 unsigned long pgsize_bitmap;
137 void *priv;
136}; 138};
137 139
138#define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */ 140#define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
diff --git a/include/linux/of_iommu.h b/include/linux/of_iommu.h
index 51a560f34bca..5762cdc8effe 100644
--- a/include/linux/of_iommu.h
+++ b/include/linux/of_iommu.h
@@ -1,12 +1,17 @@
1#ifndef __OF_IOMMU_H 1#ifndef __OF_IOMMU_H
2#define __OF_IOMMU_H 2#define __OF_IOMMU_H
3 3
4#include <linux/iommu.h>
5#include <linux/of.h>
6
4#ifdef CONFIG_OF_IOMMU 7#ifdef CONFIG_OF_IOMMU
5 8
6extern int of_get_dma_window(struct device_node *dn, const char *prefix, 9extern int of_get_dma_window(struct device_node *dn, const char *prefix,
7 int index, unsigned long *busno, dma_addr_t *addr, 10 int index, unsigned long *busno, dma_addr_t *addr,
8 size_t *size); 11 size_t *size);
9 12
13extern void of_iommu_init(void);
14
10#else 15#else
11 16
12static inline int of_get_dma_window(struct device_node *dn, const char *prefix, 17static inline int of_get_dma_window(struct device_node *dn, const char *prefix,
@@ -16,6 +21,26 @@ static inline int of_get_dma_window(struct device_node *dn, const char *prefix,
16 return -EINVAL; 21 return -EINVAL;
17} 22}
18 23
24static inline void of_iommu_init(void) { }
25
19#endif /* CONFIG_OF_IOMMU */ 26#endif /* CONFIG_OF_IOMMU */
20 27
28static inline void of_iommu_set_ops(struct device_node *np,
29 const struct iommu_ops *ops)
30{
31 np->data = (struct iommu_ops *)ops;
32}
33
34static inline struct iommu_ops *of_iommu_get_ops(struct device_node *np)
35{
36 return np->data;
37}
38
39extern struct of_device_id __iommu_of_table;
40
41typedef int (*of_iommu_init_fn)(struct device_node *);
42
43#define IOMMU_OF_DECLARE(name, compat, fn) \
44 _OF_DECLARE(iommu, name, compat, fn, of_iommu_init_fn)
45
21#endif /* __OF_IOMMU_H */ 46#endif /* __OF_IOMMU_H */