aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/iommu/Kconfig2
-rw-r--r--drivers/iommu/iommu.c2
-rw-r--r--drivers/iommu/of_iommu.c89
-rw-r--r--drivers/of/platform.c50
4 files changed, 117 insertions, 26 deletions
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
15 15
16config OF_IOMMU 16config OF_IOMMU
17 def_bool y 17 def_bool y
18 depends on OF 18 depends on OF && IOMMU_API
19 19
20config FSL_PAMU 20config FSL_PAMU
21 bool "Freescale IOMMU support" 21 bool "Freescale IOMMU support"
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index ed8b04867b1f..02f798b7e295 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -737,7 +737,7 @@ static int add_iommu_group(struct device *dev, void *data)
737 const struct iommu_ops *ops = cb->ops; 737 const struct iommu_ops *ops = cb->ops;
738 738
739 if (!ops->add_device) 739 if (!ops->add_device)
740 return -ENODEV; 740 return 0;
741 741
742 WARN_ON(dev->iommu_group); 742 WARN_ON(dev->iommu_group);
743 743
diff --git a/drivers/iommu/of_iommu.c b/drivers/iommu/of_iommu.c
index e550ccb7634e..af1dc6a1c0a1 100644
--- a/drivers/iommu/of_iommu.c
+++ b/drivers/iommu/of_iommu.c
@@ -18,9 +18,14 @@
18 */ 18 */
19 19
20#include <linux/export.h> 20#include <linux/export.h>
21#include <linux/iommu.h>
21#include <linux/limits.h> 22#include <linux/limits.h>
22#include <linux/of.h> 23#include <linux/of.h>
23#include <linux/of_iommu.h> 24#include <linux/of_iommu.h>
25#include <linux/slab.h>
26
27static const struct of_device_id __iommu_of_table_sentinel
28 __used __section(__iommu_of_table_end);
24 29
25/** 30/**
26 * of_get_dma_window - Parse *dma-window property and returns 0 if found. 31 * of_get_dma_window - Parse *dma-window property and returns 0 if found.
@@ -89,3 +94,87 @@ int of_get_dma_window(struct device_node *dn, const char *prefix, int index,
89 return 0; 94 return 0;
90} 95}
91EXPORT_SYMBOL_GPL(of_get_dma_window); 96EXPORT_SYMBOL_GPL(of_get_dma_window);
97
98struct of_iommu_node {
99 struct list_head list;
100 struct device_node *np;
101 struct iommu_ops *ops;
102};
103static LIST_HEAD(of_iommu_list);
104static DEFINE_SPINLOCK(of_iommu_lock);
105
106void of_iommu_set_ops(struct device_node *np, struct iommu_ops *ops)
107{
108 struct of_iommu_node *iommu = kzalloc(sizeof(*iommu), GFP_KERNEL);
109
110 if (WARN_ON(!iommu))
111 return;
112
113 INIT_LIST_HEAD(&iommu->list);
114 iommu->np = np;
115 iommu->ops = ops;
116 spin_lock(&of_iommu_lock);
117 list_add_tail(&iommu->list, &of_iommu_list);
118 spin_unlock(&of_iommu_lock);
119}
120
121struct iommu_ops *of_iommu_get_ops(struct device_node *np)
122{
123 struct of_iommu_node *node;
124 struct iommu_ops *ops = NULL;
125
126 spin_lock(&of_iommu_lock);
127 list_for_each_entry(node, &of_iommu_list, list)
128 if (node->np == np) {
129 ops = node->ops;
130 break;
131 }
132 spin_unlock(&of_iommu_lock);
133 return ops;
134}
135
136struct iommu_ops *of_iommu_configure(struct device *dev)
137{
138 struct of_phandle_args iommu_spec;
139 struct device_node *np;
140 struct iommu_ops *ops = NULL;
141 int idx = 0;
142
143 /*
144 * We don't currently walk up the tree looking for a parent IOMMU.
145 * See the `Notes:' section of
146 * Documentation/devicetree/bindings/iommu/iommu.txt
147 */
148 while (!of_parse_phandle_with_args(dev->of_node, "iommus",
149 "#iommu-cells", idx,
150 &iommu_spec)) {
151 np = iommu_spec.np;
152 ops = of_iommu_get_ops(np);
153
154 if (!ops || !ops->of_xlate || ops->of_xlate(dev, &iommu_spec))
155 goto err_put_node;
156
157 of_node_put(np);
158 idx++;
159 }
160
161 return ops;
162
163err_put_node:
164 of_node_put(np);
165 return NULL;
166}
167
168void __init of_iommu_init(void)
169{
170 struct device_node *np;
171 const struct of_device_id *match, *matches = &__iommu_of_table;
172
173 for_each_matching_node_and_match(np, matches, &match) {
174 const of_iommu_init_fn init_fn = match->data;
175
176 if (init_fn(np))
177 pr_err("Failed to initialise IOMMU %s\n",
178 of_node_full_name(np));
179 }
180}
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index 3b64d0bf5bba..b89caf8c7586 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -19,6 +19,7 @@
19#include <linux/slab.h> 19#include <linux/slab.h>
20#include <linux/of_address.h> 20#include <linux/of_address.h>
21#include <linux/of_device.h> 21#include <linux/of_device.h>
22#include <linux/of_iommu.h>
22#include <linux/of_irq.h> 23#include <linux/of_irq.h>
23#include <linux/of_platform.h> 24#include <linux/of_platform.h>
24#include <linux/platform_device.h> 25#include <linux/platform_device.h>
@@ -164,6 +165,9 @@ static void of_dma_configure(struct device *dev)
164{ 165{
165 u64 dma_addr, paddr, size; 166 u64 dma_addr, paddr, size;
166 int ret; 167 int ret;
168 bool coherent;
169 unsigned long offset;
170 struct iommu_ops *iommu;
167 171
168 /* 172 /*
169 * Set default dma-mask to 32 bit. Drivers are expected to setup 173 * Set default dma-mask to 32 bit. Drivers are expected to setup
@@ -178,28 +182,30 @@ static void of_dma_configure(struct device *dev)
178 if (!dev->dma_mask) 182 if (!dev->dma_mask)
179 dev->dma_mask = &dev->coherent_dma_mask; 183 dev->dma_mask = &dev->coherent_dma_mask;
180 184
181 /*
182 * if dma-coherent property exist, call arch hook to setup
183 * dma coherent operations.
184 */
185 if (of_dma_is_coherent(dev->of_node)) {
186 set_arch_dma_coherent_ops(dev);
187 dev_dbg(dev, "device is dma coherent\n");
188 }
189
190 /*
191 * if dma-ranges property doesn't exist - just return else
192 * setup the dma offset
193 */
194 ret = of_dma_get_range(dev->of_node, &dma_addr, &paddr, &size); 185 ret = of_dma_get_range(dev->of_node, &dma_addr, &paddr, &size);
195 if (ret < 0) { 186 if (ret < 0) {
196 dev_dbg(dev, "no dma range information to setup\n"); 187 dma_addr = offset = 0;
197 return; 188 size = dev->coherent_dma_mask;
189 } else {
190 offset = PFN_DOWN(paddr - dma_addr);
191 dev_dbg(dev, "dma_pfn_offset(%#08lx)\n", dev->dma_pfn_offset);
198 } 192 }
193 dev->dma_pfn_offset = offset;
194
195 coherent = of_dma_is_coherent(dev->of_node);
196 dev_dbg(dev, "device is%sdma coherent\n",
197 coherent ? " " : " not ");
198
199 iommu = of_iommu_configure(dev);
200 dev_dbg(dev, "device is%sbehind an iommu\n",
201 iommu ? " " : " not ");
199 202
200 /* DMA ranges found. Calculate and set dma_pfn_offset */ 203 arch_setup_dma_ops(dev, dma_addr, size, iommu, coherent);
201 dev->dma_pfn_offset = PFN_DOWN(paddr - dma_addr); 204}
202 dev_dbg(dev, "dma_pfn_offset(%#08lx)\n", dev->dma_pfn_offset); 205
206static void of_dma_deconfigure(struct device *dev)
207{
208 arch_teardown_dma_ops(dev);
203} 209}
204 210
205/** 211/**
@@ -228,16 +234,12 @@ static struct platform_device *of_platform_device_create_pdata(
228 if (!dev) 234 if (!dev)
229 goto err_clear_flag; 235 goto err_clear_flag;
230 236
231 of_dma_configure(&dev->dev);
232 dev->dev.bus = &platform_bus_type; 237 dev->dev.bus = &platform_bus_type;
233 dev->dev.platform_data = platform_data; 238 dev->dev.platform_data = platform_data;
234 239 of_dma_configure(&dev->dev);
235 /* We do not fill the DMA ops for platform devices by default.
236 * This is currently the responsibility of the platform code
237 * to do such, possibly using a device notifier
238 */
239 240
240 if (of_device_add(dev) != 0) { 241 if (of_device_add(dev) != 0) {
242 of_dma_deconfigure(&dev->dev);
241 platform_device_put(dev); 243 platform_device_put(dev);
242 goto err_clear_flag; 244 goto err_clear_flag;
243 } 245 }