blob: 28bc631432790bde5bba70261a85865a73fd576a [file] [log] [blame]
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +02001/*
2 * omap iommu: tlb and pagetable primitives
3 *
Hiroshi DOYUc127c7d2010-02-15 10:03:32 -08004 * Copyright (C) 2008-2010 Nokia Corporation
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +02005 *
6 * Written by Hiroshi DOYU <Hiroshi.DOYU@nokia.com>,
7 * Paul Mundt and Toshihiro Kobayashi
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
14#include <linux/err.h>
15#include <linux/module.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090016#include <linux/slab.h>
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +020017#include <linux/interrupt.h>
18#include <linux/ioport.h>
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +020019#include <linux/platform_device.h>
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +030020#include <linux/iommu.h>
Tony Lindgrenc8d35c82012-11-02 12:24:03 -070021#include <linux/omap-iommu.h>
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +030022#include <linux/mutex.h>
23#include <linux/spinlock.h>
Tony Lindgrened1c7de2012-11-02 12:24:06 -070024#include <linux/io.h>
Omar Ramirez Lunaebf7cda2012-11-19 19:05:51 -060025#include <linux/pm_runtime.h>
Florian Vaussard3c927482014-02-28 14:42:36 -060026#include <linux/of.h>
27#include <linux/of_iommu.h>
28#include <linux/of_irq.h>
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +020029
30#include <asm/cacheflush.h>
31
Tony Lindgren2ab7c842012-11-02 12:24:14 -070032#include <linux/platform_data/iommu-omap.h>
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +020033
Ido Yariv2f7702a2012-11-02 12:24:00 -070034#include "omap-iopgtable.h"
Tony Lindgrened1c7de2012-11-02 12:24:06 -070035#include "omap-iommu.h"
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +020036
Hiroshi DOYU37c28362010-04-27 05:37:12 +000037#define for_each_iotlb_cr(obj, n, __i, cr) \
38 for (__i = 0; \
39 (__i < (n)) && (cr = __iotlb_read_cr((obj), __i), true); \
40 __i++)
41
Ohad Ben-Cohen66bc8cf2011-11-10 11:32:27 +020042/* bitmap of the page sizes currently supported */
43#define OMAP_IOMMU_PGSIZES (SZ_4K | SZ_64K | SZ_1M | SZ_16M)
44
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +030045/**
46 * struct omap_iommu_domain - omap iommu domain
47 * @pgtable: the page table
48 * @iommu_dev: an omap iommu device attached to this domain. only a single
49 * iommu device can be attached for now.
Omar Ramirez Luna803b5272012-04-18 13:09:41 -050050 * @dev: Device using this domain.
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +030051 * @lock: domain lock, should be taken when attaching/detaching
52 */
53struct omap_iommu_domain {
54 u32 *pgtable;
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +030055 struct omap_iommu *iommu_dev;
Omar Ramirez Luna803b5272012-04-18 13:09:41 -050056 struct device *dev;
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +030057 spinlock_t lock;
58};
59
Ido Yariv7bd9e252012-11-02 12:24:09 -070060#define MMU_LOCK_BASE_SHIFT 10
61#define MMU_LOCK_BASE_MASK (0x1f << MMU_LOCK_BASE_SHIFT)
62#define MMU_LOCK_BASE(x) \
63 ((x & MMU_LOCK_BASE_MASK) >> MMU_LOCK_BASE_SHIFT)
64
65#define MMU_LOCK_VICT_SHIFT 4
66#define MMU_LOCK_VICT_MASK (0x1f << MMU_LOCK_VICT_SHIFT)
67#define MMU_LOCK_VICT(x) \
68 ((x & MMU_LOCK_VICT_MASK) >> MMU_LOCK_VICT_SHIFT)
69
70struct iotlb_lock {
71 short base;
72 short vict;
73};
74
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +020075/* accommodate the difference between omap1 and omap2/3 */
76static const struct iommu_functions *arch_iommu;
77
78static struct platform_driver omap_iommu_driver;
79static struct kmem_cache *iopte_cachep;
80
81/**
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +030082 * omap_install_iommu_arch - Install archtecure specific iommu functions
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +020083 * @ops: a pointer to architecture specific iommu functions
84 *
85 * There are several kind of iommu algorithm(tlb, pagetable) among
86 * omap series. This interface installs such an iommu algorighm.
87 **/
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +030088int omap_install_iommu_arch(const struct iommu_functions *ops)
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +020089{
90 if (arch_iommu)
91 return -EBUSY;
92
93 arch_iommu = ops;
94 return 0;
95}
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +030096EXPORT_SYMBOL_GPL(omap_install_iommu_arch);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +020097
98/**
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +030099 * omap_uninstall_iommu_arch - Uninstall archtecure specific iommu functions
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200100 * @ops: a pointer to architecture specific iommu functions
101 *
102 * This interface uninstalls the iommu algorighm installed previously.
103 **/
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300104void omap_uninstall_iommu_arch(const struct iommu_functions *ops)
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200105{
106 if (arch_iommu != ops)
107 pr_err("%s: not your arch\n", __func__);
108
109 arch_iommu = NULL;
110}
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300111EXPORT_SYMBOL_GPL(omap_uninstall_iommu_arch);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200112
113/**
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300114 * omap_iommu_save_ctx - Save registers for pm off-mode support
Ohad Ben-Cohenfabdbca2011-10-11 00:18:33 +0200115 * @dev: client device
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200116 **/
Ohad Ben-Cohenfabdbca2011-10-11 00:18:33 +0200117void omap_iommu_save_ctx(struct device *dev)
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200118{
Ohad Ben-Cohenfabdbca2011-10-11 00:18:33 +0200119 struct omap_iommu *obj = dev_to_omap_iommu(dev);
120
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200121 arch_iommu->save_ctx(obj);
122}
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300123EXPORT_SYMBOL_GPL(omap_iommu_save_ctx);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200124
125/**
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300126 * omap_iommu_restore_ctx - Restore registers for pm off-mode support
Ohad Ben-Cohenfabdbca2011-10-11 00:18:33 +0200127 * @dev: client device
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200128 **/
Ohad Ben-Cohenfabdbca2011-10-11 00:18:33 +0200129void omap_iommu_restore_ctx(struct device *dev)
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200130{
Ohad Ben-Cohenfabdbca2011-10-11 00:18:33 +0200131 struct omap_iommu *obj = dev_to_omap_iommu(dev);
132
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200133 arch_iommu->restore_ctx(obj);
134}
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300135EXPORT_SYMBOL_GPL(omap_iommu_restore_ctx);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200136
137/**
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300138 * omap_iommu_arch_version - Return running iommu arch version
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200139 **/
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300140u32 omap_iommu_arch_version(void)
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200141{
142 return arch_iommu->version;
143}
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300144EXPORT_SYMBOL_GPL(omap_iommu_arch_version);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200145
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300146static int iommu_enable(struct omap_iommu *obj)
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200147{
148 int err;
Omar Ramirez Luna72b15b62012-11-19 19:05:50 -0600149 struct platform_device *pdev = to_platform_device(obj->dev);
150 struct iommu_platform_data *pdata = pdev->dev.platform_data;
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200151
Martin Hostettleref4815a2011-02-24 12:51:31 -0800152 if (!arch_iommu)
153 return -ENODEV;
154
Florian Vaussard90e569c2014-02-28 14:42:34 -0600155 if (pdata && pdata->deassert_reset) {
Omar Ramirez Luna72b15b62012-11-19 19:05:50 -0600156 err = pdata->deassert_reset(pdev, pdata->reset_name);
157 if (err) {
158 dev_err(obj->dev, "deassert_reset failed: %d\n", err);
159 return err;
160 }
161 }
162
Omar Ramirez Lunaebf7cda2012-11-19 19:05:51 -0600163 pm_runtime_get_sync(obj->dev);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200164
165 err = arch_iommu->enable(obj);
166
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200167 return err;
168}
169
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300170static void iommu_disable(struct omap_iommu *obj)
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200171{
Omar Ramirez Luna72b15b62012-11-19 19:05:50 -0600172 struct platform_device *pdev = to_platform_device(obj->dev);
173 struct iommu_platform_data *pdata = pdev->dev.platform_data;
174
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200175 arch_iommu->disable(obj);
176
Omar Ramirez Lunaebf7cda2012-11-19 19:05:51 -0600177 pm_runtime_put_sync(obj->dev);
Omar Ramirez Luna72b15b62012-11-19 19:05:50 -0600178
Florian Vaussard90e569c2014-02-28 14:42:34 -0600179 if (pdata && pdata->assert_reset)
Omar Ramirez Luna72b15b62012-11-19 19:05:50 -0600180 pdata->assert_reset(pdev, pdata->reset_name);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200181}
182
183/*
184 * TLB operations
185 */
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300186void omap_iotlb_cr_to_e(struct cr_regs *cr, struct iotlb_entry *e)
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200187{
188 BUG_ON(!cr || !e);
189
190 arch_iommu->cr_to_e(cr, e);
191}
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300192EXPORT_SYMBOL_GPL(omap_iotlb_cr_to_e);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200193
194static inline int iotlb_cr_valid(struct cr_regs *cr)
195{
196 if (!cr)
197 return -EINVAL;
198
199 return arch_iommu->cr_valid(cr);
200}
201
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300202static inline struct cr_regs *iotlb_alloc_cr(struct omap_iommu *obj,
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200203 struct iotlb_entry *e)
204{
205 if (!e)
206 return NULL;
207
208 return arch_iommu->alloc_cr(obj, e);
209}
210
Ohad Ben-Cohene1f23812011-08-16 14:58:14 +0300211static u32 iotlb_cr_to_virt(struct cr_regs *cr)
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200212{
213 return arch_iommu->cr_to_virt(cr);
214}
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200215
216static u32 get_iopte_attr(struct iotlb_entry *e)
217{
218 return arch_iommu->get_pte_attr(e);
219}
220
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300221static u32 iommu_report_fault(struct omap_iommu *obj, u32 *da)
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200222{
223 return arch_iommu->fault_isr(obj, da);
224}
225
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300226static void iotlb_lock_get(struct omap_iommu *obj, struct iotlb_lock *l)
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200227{
228 u32 val;
229
230 val = iommu_read_reg(obj, MMU_LOCK);
231
232 l->base = MMU_LOCK_BASE(val);
233 l->vict = MMU_LOCK_VICT(val);
234
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200235}
236
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300237static void iotlb_lock_set(struct omap_iommu *obj, struct iotlb_lock *l)
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200238{
239 u32 val;
240
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200241 val = (l->base << MMU_LOCK_BASE_SHIFT);
242 val |= (l->vict << MMU_LOCK_VICT_SHIFT);
243
244 iommu_write_reg(obj, val, MMU_LOCK);
245}
246
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300247static void iotlb_read_cr(struct omap_iommu *obj, struct cr_regs *cr)
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200248{
249 arch_iommu->tlb_read_cr(obj, cr);
250}
251
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300252static void iotlb_load_cr(struct omap_iommu *obj, struct cr_regs *cr)
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200253{
254 arch_iommu->tlb_load_cr(obj, cr);
255
256 iommu_write_reg(obj, 1, MMU_FLUSH_ENTRY);
257 iommu_write_reg(obj, 1, MMU_LD_TLB);
258}
259
260/**
261 * iotlb_dump_cr - Dump an iommu tlb entry into buf
262 * @obj: target iommu
263 * @cr: contents of cam and ram register
264 * @buf: output buffer
265 **/
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300266static inline ssize_t iotlb_dump_cr(struct omap_iommu *obj, struct cr_regs *cr,
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200267 char *buf)
268{
269 BUG_ON(!cr || !buf);
270
271 return arch_iommu->dump_cr(obj, cr, buf);
272}
273
Hiroshi DOYU37c28362010-04-27 05:37:12 +0000274/* only used in iotlb iteration for-loop */
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300275static struct cr_regs __iotlb_read_cr(struct omap_iommu *obj, int n)
Hiroshi DOYU37c28362010-04-27 05:37:12 +0000276{
277 struct cr_regs cr;
278 struct iotlb_lock l;
279
280 iotlb_lock_get(obj, &l);
281 l.vict = n;
282 iotlb_lock_set(obj, &l);
283 iotlb_read_cr(obj, &cr);
284
285 return cr;
286}
287
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200288/**
289 * load_iotlb_entry - Set an iommu tlb entry
290 * @obj: target iommu
291 * @e: an iommu tlb entry info
292 **/
Ohad Ben-Cohen5da14a42011-08-16 15:19:10 +0300293#ifdef PREFETCH_IOTLB
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300294static int load_iotlb_entry(struct omap_iommu *obj, struct iotlb_entry *e)
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200295{
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200296 int err = 0;
297 struct iotlb_lock l;
298 struct cr_regs *cr;
299
300 if (!obj || !obj->nr_tlb_entries || !e)
301 return -EINVAL;
302
Omar Ramirez Lunaebf7cda2012-11-19 19:05:51 -0600303 pm_runtime_get_sync(obj->dev);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200304
Kanigeri, Haribe6d8022010-04-22 23:26:11 +0000305 iotlb_lock_get(obj, &l);
306 if (l.base == obj->nr_tlb_entries) {
307 dev_warn(obj->dev, "%s: preserve entries full\n", __func__);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200308 err = -EBUSY;
309 goto out;
310 }
Kanigeri, Haribe6d8022010-04-22 23:26:11 +0000311 if (!e->prsvd) {
Hiroshi DOYU37c28362010-04-27 05:37:12 +0000312 int i;
313 struct cr_regs tmp;
Kanigeri, Haribe6d8022010-04-22 23:26:11 +0000314
Hiroshi DOYU37c28362010-04-27 05:37:12 +0000315 for_each_iotlb_cr(obj, obj->nr_tlb_entries, i, tmp)
Kanigeri, Haribe6d8022010-04-22 23:26:11 +0000316 if (!iotlb_cr_valid(&tmp))
317 break;
Hiroshi DOYU37c28362010-04-27 05:37:12 +0000318
Kanigeri, Haribe6d8022010-04-22 23:26:11 +0000319 if (i == obj->nr_tlb_entries) {
320 dev_dbg(obj->dev, "%s: full: no entry\n", __func__);
321 err = -EBUSY;
322 goto out;
323 }
Hiroshi DOYU37c28362010-04-27 05:37:12 +0000324
325 iotlb_lock_get(obj, &l);
Kanigeri, Haribe6d8022010-04-22 23:26:11 +0000326 } else {
327 l.vict = l.base;
328 iotlb_lock_set(obj, &l);
329 }
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200330
331 cr = iotlb_alloc_cr(obj, e);
332 if (IS_ERR(cr)) {
Omar Ramirez Lunaebf7cda2012-11-19 19:05:51 -0600333 pm_runtime_put_sync(obj->dev);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200334 return PTR_ERR(cr);
335 }
336
337 iotlb_load_cr(obj, cr);
338 kfree(cr);
339
Kanigeri, Haribe6d8022010-04-22 23:26:11 +0000340 if (e->prsvd)
341 l.base++;
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200342 /* increment victim for next tlb load */
343 if (++l.vict == obj->nr_tlb_entries)
Kanigeri, Haribe6d8022010-04-22 23:26:11 +0000344 l.vict = l.base;
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200345 iotlb_lock_set(obj, &l);
346out:
Omar Ramirez Lunaebf7cda2012-11-19 19:05:51 -0600347 pm_runtime_put_sync(obj->dev);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200348 return err;
349}
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200350
Ohad Ben-Cohen5da14a42011-08-16 15:19:10 +0300351#else /* !PREFETCH_IOTLB */
352
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300353static int load_iotlb_entry(struct omap_iommu *obj, struct iotlb_entry *e)
Ohad Ben-Cohen5da14a42011-08-16 15:19:10 +0300354{
355 return 0;
356}
357
358#endif /* !PREFETCH_IOTLB */
359
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300360static int prefetch_iotlb_entry(struct omap_iommu *obj, struct iotlb_entry *e)
Ohad Ben-Cohen5da14a42011-08-16 15:19:10 +0300361{
362 return load_iotlb_entry(obj, e);
363}
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200364
365/**
366 * flush_iotlb_page - Clear an iommu tlb entry
367 * @obj: target iommu
368 * @da: iommu device virtual address
369 *
370 * Clear an iommu tlb entry which includes 'da' address.
371 **/
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300372static void flush_iotlb_page(struct omap_iommu *obj, u32 da)
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200373{
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200374 int i;
Hiroshi DOYU37c28362010-04-27 05:37:12 +0000375 struct cr_regs cr;
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200376
Omar Ramirez Lunaebf7cda2012-11-19 19:05:51 -0600377 pm_runtime_get_sync(obj->dev);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200378
Hiroshi DOYU37c28362010-04-27 05:37:12 +0000379 for_each_iotlb_cr(obj, obj->nr_tlb_entries, i, cr) {
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200380 u32 start;
381 size_t bytes;
382
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200383 if (!iotlb_cr_valid(&cr))
384 continue;
385
386 start = iotlb_cr_to_virt(&cr);
387 bytes = iopgsz_to_bytes(cr.cam & 3);
388
389 if ((start <= da) && (da < start + bytes)) {
390 dev_dbg(obj->dev, "%s: %08x<=%08x(%x)\n",
391 __func__, start, da, bytes);
Hari Kanigeri0fa035e2010-08-20 13:50:18 +0000392 iotlb_load_cr(obj, &cr);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200393 iommu_write_reg(obj, 1, MMU_FLUSH_ENTRY);
394 }
395 }
Omar Ramirez Lunaebf7cda2012-11-19 19:05:51 -0600396 pm_runtime_put_sync(obj->dev);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200397
398 if (i == obj->nr_tlb_entries)
399 dev_dbg(obj->dev, "%s: no page for %08x\n", __func__, da);
400}
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200401
402/**
403 * flush_iotlb_all - Clear all iommu tlb entries
404 * @obj: target iommu
405 **/
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300406static void flush_iotlb_all(struct omap_iommu *obj)
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200407{
408 struct iotlb_lock l;
409
Omar Ramirez Lunaebf7cda2012-11-19 19:05:51 -0600410 pm_runtime_get_sync(obj->dev);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200411
412 l.base = 0;
413 l.vict = 0;
414 iotlb_lock_set(obj, &l);
415
416 iommu_write_reg(obj, 1, MMU_GFLUSH);
417
Omar Ramirez Lunaebf7cda2012-11-19 19:05:51 -0600418 pm_runtime_put_sync(obj->dev);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200419}
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200420
Arnd Bergmanne4efd942011-10-02 14:34:05 -0400421#if defined(CONFIG_OMAP_IOMMU_DEBUG) || defined(CONFIG_OMAP_IOMMU_DEBUG_MODULE)
Kanigeri, Hariddfa9752010-05-24 02:01:51 +0000422
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300423ssize_t omap_iommu_dump_ctx(struct omap_iommu *obj, char *buf, ssize_t bytes)
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200424{
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200425 if (!obj || !buf)
426 return -EINVAL;
427
Omar Ramirez Lunaebf7cda2012-11-19 19:05:51 -0600428 pm_runtime_get_sync(obj->dev);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200429
Hiroshi DOYU14e0e672009-08-28 10:54:41 -0700430 bytes = arch_iommu->dump_ctx(obj, buf, bytes);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200431
Omar Ramirez Lunaebf7cda2012-11-19 19:05:51 -0600432 pm_runtime_put_sync(obj->dev);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200433
434 return bytes;
435}
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300436EXPORT_SYMBOL_GPL(omap_iommu_dump_ctx);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200437
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300438static int
439__dump_tlb_entries(struct omap_iommu *obj, struct cr_regs *crs, int num)
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200440{
441 int i;
Hiroshi DOYU37c28362010-04-27 05:37:12 +0000442 struct iotlb_lock saved;
443 struct cr_regs tmp;
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200444 struct cr_regs *p = crs;
445
Omar Ramirez Lunaebf7cda2012-11-19 19:05:51 -0600446 pm_runtime_get_sync(obj->dev);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200447 iotlb_lock_get(obj, &saved);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200448
Hiroshi DOYU37c28362010-04-27 05:37:12 +0000449 for_each_iotlb_cr(obj, num, i, tmp) {
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200450 if (!iotlb_cr_valid(&tmp))
451 continue;
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200452 *p++ = tmp;
453 }
Hiroshi DOYU37c28362010-04-27 05:37:12 +0000454
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200455 iotlb_lock_set(obj, &saved);
Omar Ramirez Lunaebf7cda2012-11-19 19:05:51 -0600456 pm_runtime_put_sync(obj->dev);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200457
458 return p - crs;
459}
460
461/**
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300462 * omap_dump_tlb_entries - dump cr arrays to given buffer
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200463 * @obj: target iommu
464 * @buf: output buffer
465 **/
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300466size_t omap_dump_tlb_entries(struct omap_iommu *obj, char *buf, ssize_t bytes)
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200467{
Hiroshi DOYU14e0e672009-08-28 10:54:41 -0700468 int i, num;
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200469 struct cr_regs *cr;
470 char *p = buf;
471
Hiroshi DOYU14e0e672009-08-28 10:54:41 -0700472 num = bytes / sizeof(*cr);
473 num = min(obj->nr_tlb_entries, num);
474
475 cr = kcalloc(num, sizeof(*cr), GFP_KERNEL);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200476 if (!cr)
477 return 0;
478
Hiroshi DOYU14e0e672009-08-28 10:54:41 -0700479 num = __dump_tlb_entries(obj, cr, num);
480 for (i = 0; i < num; i++)
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200481 p += iotlb_dump_cr(obj, cr + i, p);
482 kfree(cr);
483
484 return p - buf;
485}
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300486EXPORT_SYMBOL_GPL(omap_dump_tlb_entries);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200487
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300488int omap_foreach_iommu_device(void *data, int (*fn)(struct device *, void *))
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200489{
490 return driver_for_each_device(&omap_iommu_driver.driver,
491 NULL, data, fn);
492}
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300493EXPORT_SYMBOL_GPL(omap_foreach_iommu_device);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200494
495#endif /* CONFIG_OMAP_IOMMU_DEBUG_MODULE */
496
497/*
498 * H/W pagetable operations
499 */
500static void flush_iopgd_range(u32 *first, u32 *last)
501{
502 /* FIXME: L2 cache should be taken care of if it exists */
503 do {
504 asm("mcr p15, 0, %0, c7, c10, 1 @ flush_pgd"
505 : : "r" (first));
506 first += L1_CACHE_BYTES / sizeof(*first);
507 } while (first <= last);
508}
509
510static void flush_iopte_range(u32 *first, u32 *last)
511{
512 /* FIXME: L2 cache should be taken care of if it exists */
513 do {
514 asm("mcr p15, 0, %0, c7, c10, 1 @ flush_pte"
515 : : "r" (first));
516 first += L1_CACHE_BYTES / sizeof(*first);
517 } while (first <= last);
518}
519
520static void iopte_free(u32 *iopte)
521{
522 /* Note: freed iopte's must be clean ready for re-use */
523 kmem_cache_free(iopte_cachep, iopte);
524}
525
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300526static u32 *iopte_alloc(struct omap_iommu *obj, u32 *iopgd, u32 da)
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200527{
528 u32 *iopte;
529
530 /* a table has already existed */
531 if (*iopgd)
532 goto pte_ready;
533
534 /*
535 * do the allocation outside the page table lock
536 */
537 spin_unlock(&obj->page_table_lock);
538 iopte = kmem_cache_zalloc(iopte_cachep, GFP_KERNEL);
539 spin_lock(&obj->page_table_lock);
540
541 if (!*iopgd) {
542 if (!iopte)
543 return ERR_PTR(-ENOMEM);
544
545 *iopgd = virt_to_phys(iopte) | IOPGD_TABLE;
546 flush_iopgd_range(iopgd, iopgd);
547
548 dev_vdbg(obj->dev, "%s: a new pte:%p\n", __func__, iopte);
549 } else {
550 /* We raced, free the reduniovant table */
551 iopte_free(iopte);
552 }
553
554pte_ready:
555 iopte = iopte_offset(iopgd, da);
556
557 dev_vdbg(obj->dev,
558 "%s: da:%08x pgd:%p *pgd:%08x pte:%p *pte:%08x\n",
559 __func__, da, iopgd, *iopgd, iopte, *iopte);
560
561 return iopte;
562}
563
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300564static int iopgd_alloc_section(struct omap_iommu *obj, u32 da, u32 pa, u32 prot)
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200565{
566 u32 *iopgd = iopgd_offset(obj, da);
567
Hiroshi DOYU4abb7612010-05-06 18:24:04 +0300568 if ((da | pa) & ~IOSECTION_MASK) {
569 dev_err(obj->dev, "%s: %08x:%08x should aligned on %08lx\n",
570 __func__, da, pa, IOSECTION_SIZE);
571 return -EINVAL;
572 }
573
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200574 *iopgd = (pa & IOSECTION_MASK) | prot | IOPGD_SECTION;
575 flush_iopgd_range(iopgd, iopgd);
576 return 0;
577}
578
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300579static int iopgd_alloc_super(struct omap_iommu *obj, u32 da, u32 pa, u32 prot)
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200580{
581 u32 *iopgd = iopgd_offset(obj, da);
582 int i;
583
Hiroshi DOYU4abb7612010-05-06 18:24:04 +0300584 if ((da | pa) & ~IOSUPER_MASK) {
585 dev_err(obj->dev, "%s: %08x:%08x should aligned on %08lx\n",
586 __func__, da, pa, IOSUPER_SIZE);
587 return -EINVAL;
588 }
589
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200590 for (i = 0; i < 16; i++)
591 *(iopgd + i) = (pa & IOSUPER_MASK) | prot | IOPGD_SUPER;
592 flush_iopgd_range(iopgd, iopgd + 15);
593 return 0;
594}
595
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300596static int iopte_alloc_page(struct omap_iommu *obj, u32 da, u32 pa, u32 prot)
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200597{
598 u32 *iopgd = iopgd_offset(obj, da);
599 u32 *iopte = iopte_alloc(obj, iopgd, da);
600
601 if (IS_ERR(iopte))
602 return PTR_ERR(iopte);
603
604 *iopte = (pa & IOPAGE_MASK) | prot | IOPTE_SMALL;
605 flush_iopte_range(iopte, iopte);
606
607 dev_vdbg(obj->dev, "%s: da:%08x pa:%08x pte:%p *pte:%08x\n",
608 __func__, da, pa, iopte, *iopte);
609
610 return 0;
611}
612
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300613static int iopte_alloc_large(struct omap_iommu *obj, u32 da, u32 pa, u32 prot)
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200614{
615 u32 *iopgd = iopgd_offset(obj, da);
616 u32 *iopte = iopte_alloc(obj, iopgd, da);
617 int i;
618
Hiroshi DOYU4abb7612010-05-06 18:24:04 +0300619 if ((da | pa) & ~IOLARGE_MASK) {
620 dev_err(obj->dev, "%s: %08x:%08x should aligned on %08lx\n",
621 __func__, da, pa, IOLARGE_SIZE);
622 return -EINVAL;
623 }
624
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200625 if (IS_ERR(iopte))
626 return PTR_ERR(iopte);
627
628 for (i = 0; i < 16; i++)
629 *(iopte + i) = (pa & IOLARGE_MASK) | prot | IOPTE_LARGE;
630 flush_iopte_range(iopte, iopte + 15);
631 return 0;
632}
633
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300634static int
635iopgtable_store_entry_core(struct omap_iommu *obj, struct iotlb_entry *e)
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200636{
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300637 int (*fn)(struct omap_iommu *, u32, u32, u32);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200638 u32 prot;
639 int err;
640
641 if (!obj || !e)
642 return -EINVAL;
643
644 switch (e->pgsz) {
645 case MMU_CAM_PGSZ_16M:
646 fn = iopgd_alloc_super;
647 break;
648 case MMU_CAM_PGSZ_1M:
649 fn = iopgd_alloc_section;
650 break;
651 case MMU_CAM_PGSZ_64K:
652 fn = iopte_alloc_large;
653 break;
654 case MMU_CAM_PGSZ_4K:
655 fn = iopte_alloc_page;
656 break;
657 default:
658 fn = NULL;
659 BUG();
660 break;
661 }
662
663 prot = get_iopte_attr(e);
664
665 spin_lock(&obj->page_table_lock);
666 err = fn(obj, e->da, e->pa, prot);
667 spin_unlock(&obj->page_table_lock);
668
669 return err;
670}
671
672/**
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300673 * omap_iopgtable_store_entry - Make an iommu pte entry
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200674 * @obj: target iommu
675 * @e: an iommu tlb entry info
676 **/
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300677int omap_iopgtable_store_entry(struct omap_iommu *obj, struct iotlb_entry *e)
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200678{
679 int err;
680
681 flush_iotlb_page(obj, e->da);
682 err = iopgtable_store_entry_core(obj, e);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200683 if (!err)
Ohad Ben-Cohen5da14a42011-08-16 15:19:10 +0300684 prefetch_iotlb_entry(obj, e);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200685 return err;
686}
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300687EXPORT_SYMBOL_GPL(omap_iopgtable_store_entry);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200688
689/**
690 * iopgtable_lookup_entry - Lookup an iommu pte entry
691 * @obj: target iommu
692 * @da: iommu device virtual address
693 * @ppgd: iommu pgd entry pointer to be returned
694 * @ppte: iommu pte entry pointer to be returned
695 **/
Ohad Ben-Cohene1f23812011-08-16 14:58:14 +0300696static void
697iopgtable_lookup_entry(struct omap_iommu *obj, u32 da, u32 **ppgd, u32 **ppte)
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200698{
699 u32 *iopgd, *iopte = NULL;
700
701 iopgd = iopgd_offset(obj, da);
702 if (!*iopgd)
703 goto out;
704
Hiroshi DOYUa1a54452010-05-13 09:45:35 +0300705 if (iopgd_is_table(*iopgd))
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200706 iopte = iopte_offset(iopgd, da);
707out:
708 *ppgd = iopgd;
709 *ppte = iopte;
710}
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200711
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300712static size_t iopgtable_clear_entry_core(struct omap_iommu *obj, u32 da)
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200713{
714 size_t bytes;
715 u32 *iopgd = iopgd_offset(obj, da);
716 int nent = 1;
717
718 if (!*iopgd)
719 return 0;
720
Hiroshi DOYUa1a54452010-05-13 09:45:35 +0300721 if (iopgd_is_table(*iopgd)) {
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200722 int i;
723 u32 *iopte = iopte_offset(iopgd, da);
724
725 bytes = IOPTE_SIZE;
726 if (*iopte & IOPTE_LARGE) {
727 nent *= 16;
728 /* rewind to the 1st entry */
Hiroshi DOYUc127c7d2010-02-15 10:03:32 -0800729 iopte = iopte_offset(iopgd, (da & IOLARGE_MASK));
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200730 }
731 bytes *= nent;
732 memset(iopte, 0, nent * sizeof(*iopte));
733 flush_iopte_range(iopte, iopte + (nent - 1) * sizeof(*iopte));
734
735 /*
736 * do table walk to check if this table is necessary or not
737 */
738 iopte = iopte_offset(iopgd, 0);
739 for (i = 0; i < PTRS_PER_IOPTE; i++)
740 if (iopte[i])
741 goto out;
742
743 iopte_free(iopte);
744 nent = 1; /* for the next L1 entry */
745 } else {
746 bytes = IOPGD_SIZE;
Hiroshi DOYUdcc730d2009-10-22 14:46:32 -0700747 if ((*iopgd & IOPGD_SUPER) == IOPGD_SUPER) {
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200748 nent *= 16;
749 /* rewind to the 1st entry */
Hiroshi DOYU8d33ea52010-02-15 10:03:32 -0800750 iopgd = iopgd_offset(obj, (da & IOSUPER_MASK));
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200751 }
752 bytes *= nent;
753 }
754 memset(iopgd, 0, nent * sizeof(*iopgd));
755 flush_iopgd_range(iopgd, iopgd + (nent - 1) * sizeof(*iopgd));
756out:
757 return bytes;
758}
759
760/**
761 * iopgtable_clear_entry - Remove an iommu pte entry
762 * @obj: target iommu
763 * @da: iommu device virtual address
764 **/
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300765static size_t iopgtable_clear_entry(struct omap_iommu *obj, u32 da)
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200766{
767 size_t bytes;
768
769 spin_lock(&obj->page_table_lock);
770
771 bytes = iopgtable_clear_entry_core(obj, da);
772 flush_iotlb_page(obj, da);
773
774 spin_unlock(&obj->page_table_lock);
775
776 return bytes;
777}
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200778
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300779static void iopgtable_clear_entry_all(struct omap_iommu *obj)
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200780{
781 int i;
782
783 spin_lock(&obj->page_table_lock);
784
785 for (i = 0; i < PTRS_PER_IOPGD; i++) {
786 u32 da;
787 u32 *iopgd;
788
789 da = i << IOPGD_SHIFT;
790 iopgd = iopgd_offset(obj, da);
791
792 if (!*iopgd)
793 continue;
794
Hiroshi DOYUa1a54452010-05-13 09:45:35 +0300795 if (iopgd_is_table(*iopgd))
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200796 iopte_free(iopte_offset(iopgd, 0));
797
798 *iopgd = 0;
799 flush_iopgd_range(iopgd, iopgd);
800 }
801
802 flush_iotlb_all(obj);
803
804 spin_unlock(&obj->page_table_lock);
805}
806
807/*
808 * Device IOMMU generic operations
809 */
810static irqreturn_t iommu_fault_handler(int irq, void *data)
811{
David Cohend594f1f2011-02-16 19:35:51 +0000812 u32 da, errs;
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200813 u32 *iopgd, *iopte;
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300814 struct omap_iommu *obj = data;
Ohad Ben-Cohene7f10f02011-09-13 15:26:29 -0400815 struct iommu_domain *domain = obj->domain;
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200816
817 if (!obj->refcount)
818 return IRQ_NONE;
819
David Cohend594f1f2011-02-16 19:35:51 +0000820 errs = iommu_report_fault(obj, &da);
Laurent Pinchartc56b2dd2011-05-10 16:56:46 +0200821 if (errs == 0)
822 return IRQ_HANDLED;
David Cohend594f1f2011-02-16 19:35:51 +0000823
824 /* Fault callback or TLB/PTE Dynamic loading */
Ohad Ben-Cohene7f10f02011-09-13 15:26:29 -0400825 if (!report_iommu_fault(domain, obj->dev, da, 0))
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200826 return IRQ_HANDLED;
827
Hiroshi DOYU37b29812010-05-24 02:01:52 +0000828 iommu_disable(obj);
829
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200830 iopgd = iopgd_offset(obj, da);
831
Hiroshi DOYUa1a54452010-05-13 09:45:35 +0300832 if (!iopgd_is_table(*iopgd)) {
Suman Annab6c2e092013-05-30 18:10:59 -0500833 dev_err(obj->dev, "%s: errs:0x%08x da:0x%08x pgd:0x%p *pgd:px%08x\n",
834 obj->name, errs, da, iopgd, *iopgd);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200835 return IRQ_NONE;
836 }
837
838 iopte = iopte_offset(iopgd, da);
839
Suman Annab6c2e092013-05-30 18:10:59 -0500840 dev_err(obj->dev, "%s: errs:0x%08x da:0x%08x pgd:0x%p *pgd:0x%08x pte:0x%p *pte:0x%08x\n",
841 obj->name, errs, da, iopgd, *iopgd, iopte, *iopte);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200842
843 return IRQ_NONE;
844}
845
846static int device_match_by_alias(struct device *dev, void *data)
847{
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300848 struct omap_iommu *obj = to_iommu(dev);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200849 const char *name = data;
850
851 pr_debug("%s: %s %s\n", __func__, obj->name, name);
852
853 return strcmp(obj->name, name) == 0;
854}
855
856/**
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +0300857 * omap_iommu_attach() - attach iommu device to an iommu domain
Ohad Ben-Cohenfabdbca2011-10-11 00:18:33 +0200858 * @name: name of target omap iommu device
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +0300859 * @iopgd: page table
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200860 **/
Ohad Ben-Cohenfabdbca2011-10-11 00:18:33 +0200861static struct omap_iommu *omap_iommu_attach(const char *name, u32 *iopgd)
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200862{
Suman Anna7ee08b9e2014-02-28 14:42:33 -0600863 int err;
Ohad Ben-Cohenfabdbca2011-10-11 00:18:33 +0200864 struct device *dev;
865 struct omap_iommu *obj;
866
867 dev = driver_find_device(&omap_iommu_driver.driver, NULL,
868 (void *)name,
869 device_match_by_alias);
870 if (!dev)
Suman Anna7ee08b9e2014-02-28 14:42:33 -0600871 return ERR_PTR(-ENODEV);
Ohad Ben-Cohenfabdbca2011-10-11 00:18:33 +0200872
873 obj = to_iommu(dev);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200874
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +0300875 spin_lock(&obj->iommu_lock);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200876
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +0300877 /* an iommu device can only be attached once */
878 if (++obj->refcount > 1) {
879 dev_err(dev, "%s: already attached!\n", obj->name);
880 err = -EBUSY;
881 goto err_enable;
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200882 }
883
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +0300884 obj->iopgd = iopgd;
885 err = iommu_enable(obj);
886 if (err)
887 goto err_enable;
888 flush_iotlb_all(obj);
889
Suman Anna7ee08b9e2014-02-28 14:42:33 -0600890 if (!try_module_get(obj->owner)) {
891 err = -ENODEV;
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200892 goto err_module;
Suman Anna7ee08b9e2014-02-28 14:42:33 -0600893 }
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200894
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +0300895 spin_unlock(&obj->iommu_lock);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200896
897 dev_dbg(obj->dev, "%s: %s\n", __func__, obj->name);
898 return obj;
899
900err_module:
901 if (obj->refcount == 1)
902 iommu_disable(obj);
903err_enable:
904 obj->refcount--;
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +0300905 spin_unlock(&obj->iommu_lock);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200906 return ERR_PTR(err);
907}
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200908
909/**
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +0300910 * omap_iommu_detach - release iommu device
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200911 * @obj: target iommu
912 **/
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300913static void omap_iommu_detach(struct omap_iommu *obj)
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200914{
Roel Kluinacf9d462010-01-08 10:29:05 -0800915 if (!obj || IS_ERR(obj))
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200916 return;
917
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +0300918 spin_lock(&obj->iommu_lock);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200919
920 if (--obj->refcount == 0)
921 iommu_disable(obj);
922
923 module_put(obj->owner);
924
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +0300925 obj->iopgd = NULL;
926
927 spin_unlock(&obj->iommu_lock);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200928
929 dev_dbg(obj->dev, "%s: %s\n", __func__, obj->name);
930}
David Cohend594f1f2011-02-16 19:35:51 +0000931
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200932/*
933 * OMAP Device MMU(IOMMU) detection
934 */
Greg Kroah-Hartmand34d6512012-12-21 15:05:21 -0800935static int omap_iommu_probe(struct platform_device *pdev)
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200936{
937 int err = -ENODEV;
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200938 int irq;
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300939 struct omap_iommu *obj;
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200940 struct resource *res;
941 struct iommu_platform_data *pdata = pdev->dev.platform_data;
Florian Vaussard3c927482014-02-28 14:42:36 -0600942 struct device_node *of = pdev->dev.of_node;
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200943
Suman Annaf129b3d2014-02-28 14:42:32 -0600944 obj = devm_kzalloc(&pdev->dev, sizeof(*obj) + MMU_REG_SIZE, GFP_KERNEL);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200945 if (!obj)
946 return -ENOMEM;
947
Florian Vaussard3c927482014-02-28 14:42:36 -0600948 if (of) {
949 obj->name = dev_name(&pdev->dev);
950 obj->nr_tlb_entries = 32;
951 err = of_property_read_u32(of, "ti,#tlb-entries",
952 &obj->nr_tlb_entries);
953 if (err && err != -EINVAL)
954 return err;
955 if (obj->nr_tlb_entries != 32 && obj->nr_tlb_entries != 8)
956 return -EINVAL;
957 /*
958 * da_start and da_end are needed for omap-iovmm, so hardcode
959 * these values as used by OMAP3 ISP - the only user for
960 * omap-iovmm
961 */
962 obj->da_start = 0;
963 obj->da_end = 0xfffff000;
Suman Annab148d5f2014-02-28 14:42:37 -0600964 if (of_find_property(of, "ti,iommu-bus-err-back", NULL))
965 obj->has_bus_err_back = MMU_GP_REG_BUS_ERR_BACK_EN;
Florian Vaussard3c927482014-02-28 14:42:36 -0600966 } else {
967 obj->nr_tlb_entries = pdata->nr_tlb_entries;
968 obj->name = pdata->name;
969 obj->da_start = pdata->da_start;
970 obj->da_end = pdata->da_end;
971 }
972 if (obj->da_end <= obj->da_start)
973 return -EINVAL;
974
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200975 obj->dev = &pdev->dev;
976 obj->ctx = (void *)obj + sizeof(*obj);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200977
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +0300978 spin_lock_init(&obj->iommu_lock);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200979 mutex_init(&obj->mmap_lock);
980 spin_lock_init(&obj->page_table_lock);
981 INIT_LIST_HEAD(&obj->mmap);
982
983 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Suman Annaf129b3d2014-02-28 14:42:32 -0600984 obj->regbase = devm_ioremap_resource(obj->dev, res);
985 if (IS_ERR(obj->regbase))
986 return PTR_ERR(obj->regbase);
Aaro Koskinenda4a0f72011-03-14 12:28:32 +0000987
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200988 irq = platform_get_irq(pdev, 0);
Suman Annaf129b3d2014-02-28 14:42:32 -0600989 if (irq < 0)
990 return -ENODEV;
991
992 err = devm_request_irq(obj->dev, irq, iommu_fault_handler, IRQF_SHARED,
993 dev_name(obj->dev), obj);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200994 if (err < 0)
Suman Annaf129b3d2014-02-28 14:42:32 -0600995 return err;
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200996 platform_set_drvdata(pdev, obj);
997
Omar Ramirez Lunaebf7cda2012-11-19 19:05:51 -0600998 pm_runtime_irq_safe(obj->dev);
999 pm_runtime_enable(obj->dev);
1000
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +02001001 dev_info(&pdev->dev, "%s registered\n", obj->name);
1002 return 0;
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +02001003}
1004
Greg Kroah-Hartmand34d6512012-12-21 15:05:21 -08001005static int omap_iommu_remove(struct platform_device *pdev)
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +02001006{
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +03001007 struct omap_iommu *obj = platform_get_drvdata(pdev);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +02001008
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +02001009 iopgtable_clear_entry_all(obj);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +02001010
Omar Ramirez Lunaebf7cda2012-11-19 19:05:51 -06001011 pm_runtime_disable(obj->dev);
1012
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +02001013 dev_info(&pdev->dev, "%s removed\n", obj->name);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +02001014 return 0;
1015}
1016
Florian Vaussard3c927482014-02-28 14:42:36 -06001017static struct of_device_id omap_iommu_of_match[] = {
1018 { .compatible = "ti,omap2-iommu" },
1019 { .compatible = "ti,omap4-iommu" },
1020 { .compatible = "ti,dra7-iommu" },
1021 {},
1022};
1023MODULE_DEVICE_TABLE(of, omap_iommu_of_match);
1024
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +02001025static struct platform_driver omap_iommu_driver = {
1026 .probe = omap_iommu_probe,
Greg Kroah-Hartmand34d6512012-12-21 15:05:21 -08001027 .remove = omap_iommu_remove,
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +02001028 .driver = {
1029 .name = "omap-iommu",
Florian Vaussard3c927482014-02-28 14:42:36 -06001030 .of_match_table = of_match_ptr(omap_iommu_of_match),
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +02001031 },
1032};
1033
1034static void iopte_cachep_ctor(void *iopte)
1035{
1036 clean_dcache_area(iopte, IOPTE_TABLE_SIZE);
1037}
1038
Tony Lindgrened1c7de2012-11-02 12:24:06 -07001039static u32 iotlb_init_entry(struct iotlb_entry *e, u32 da, u32 pa,
1040 u32 flags)
1041{
1042 memset(e, 0, sizeof(*e));
1043
1044 e->da = da;
1045 e->pa = pa;
1046 e->valid = 1;
1047 /* FIXME: add OMAP1 support */
1048 e->pgsz = flags & MMU_CAM_PGSZ_MASK;
1049 e->endian = flags & MMU_RAM_ENDIAN_MASK;
1050 e->elsz = flags & MMU_RAM_ELSZ_MASK;
1051 e->mixed = flags & MMU_RAM_MIXED_MASK;
1052
1053 return iopgsz_to_bytes(e->pgsz);
1054}
1055
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +03001056static int omap_iommu_map(struct iommu_domain *domain, unsigned long da,
Ohad Ben-Cohen50090652011-11-10 11:32:25 +02001057 phys_addr_t pa, size_t bytes, int prot)
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +03001058{
1059 struct omap_iommu_domain *omap_domain = domain->priv;
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +03001060 struct omap_iommu *oiommu = omap_domain->iommu_dev;
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +03001061 struct device *dev = oiommu->dev;
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +03001062 struct iotlb_entry e;
1063 int omap_pgsz;
1064 u32 ret, flags;
1065
1066 /* we only support mapping a single iommu page for now */
1067 omap_pgsz = bytes_to_iopgsz(bytes);
1068 if (omap_pgsz < 0) {
1069 dev_err(dev, "invalid size to map: %d\n", bytes);
1070 return -EINVAL;
1071 }
1072
1073 dev_dbg(dev, "mapping da 0x%lx to pa 0x%x size 0x%x\n", da, pa, bytes);
1074
1075 flags = omap_pgsz | prot;
1076
1077 iotlb_init_entry(&e, da, pa, flags);
1078
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +03001079 ret = omap_iopgtable_store_entry(oiommu, &e);
Ohad Ben-Cohenb4550d42011-09-02 13:32:31 -04001080 if (ret)
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +03001081 dev_err(dev, "omap_iopgtable_store_entry failed: %d\n", ret);
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +03001082
Ohad Ben-Cohenb4550d42011-09-02 13:32:31 -04001083 return ret;
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +03001084}
1085
Ohad Ben-Cohen50090652011-11-10 11:32:25 +02001086static size_t omap_iommu_unmap(struct iommu_domain *domain, unsigned long da,
1087 size_t size)
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +03001088{
1089 struct omap_iommu_domain *omap_domain = domain->priv;
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +03001090 struct omap_iommu *oiommu = omap_domain->iommu_dev;
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +03001091 struct device *dev = oiommu->dev;
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +03001092
Ohad Ben-Cohen50090652011-11-10 11:32:25 +02001093 dev_dbg(dev, "unmapping da 0x%lx size %u\n", da, size);
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +03001094
Ohad Ben-Cohen50090652011-11-10 11:32:25 +02001095 return iopgtable_clear_entry(oiommu, da);
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +03001096}
1097
1098static int
1099omap_iommu_attach_dev(struct iommu_domain *domain, struct device *dev)
1100{
1101 struct omap_iommu_domain *omap_domain = domain->priv;
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +03001102 struct omap_iommu *oiommu;
Ohad Ben-Cohenfabdbca2011-10-11 00:18:33 +02001103 struct omap_iommu_arch_data *arch_data = dev->archdata.iommu;
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +03001104 int ret = 0;
1105
1106 spin_lock(&omap_domain->lock);
1107
1108 /* only a single device is supported per domain for now */
1109 if (omap_domain->iommu_dev) {
1110 dev_err(dev, "iommu domain is already attached\n");
1111 ret = -EBUSY;
1112 goto out;
1113 }
1114
1115 /* get a handle to and enable the omap iommu */
Ohad Ben-Cohenfabdbca2011-10-11 00:18:33 +02001116 oiommu = omap_iommu_attach(arch_data->name, omap_domain->pgtable);
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +03001117 if (IS_ERR(oiommu)) {
1118 ret = PTR_ERR(oiommu);
1119 dev_err(dev, "can't get omap iommu: %d\n", ret);
1120 goto out;
1121 }
1122
Ohad Ben-Cohenfabdbca2011-10-11 00:18:33 +02001123 omap_domain->iommu_dev = arch_data->iommu_dev = oiommu;
Omar Ramirez Luna803b5272012-04-18 13:09:41 -05001124 omap_domain->dev = dev;
Ohad Ben-Cohene7f10f02011-09-13 15:26:29 -04001125 oiommu->domain = domain;
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +03001126
1127out:
1128 spin_unlock(&omap_domain->lock);
1129 return ret;
1130}
1131
Omar Ramirez Luna803b5272012-04-18 13:09:41 -05001132static void _omap_iommu_detach_dev(struct omap_iommu_domain *omap_domain,
1133 struct device *dev)
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +03001134{
Ohad Ben-Cohenfabdbca2011-10-11 00:18:33 +02001135 struct omap_iommu *oiommu = dev_to_omap_iommu(dev);
Omar Ramirez Luna803b5272012-04-18 13:09:41 -05001136 struct omap_iommu_arch_data *arch_data = dev->archdata.iommu;
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +03001137
1138 /* only a single device is supported per domain for now */
1139 if (omap_domain->iommu_dev != oiommu) {
1140 dev_err(dev, "invalid iommu device\n");
Omar Ramirez Luna803b5272012-04-18 13:09:41 -05001141 return;
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +03001142 }
1143
1144 iopgtable_clear_entry_all(oiommu);
1145
1146 omap_iommu_detach(oiommu);
1147
Ohad Ben-Cohenfabdbca2011-10-11 00:18:33 +02001148 omap_domain->iommu_dev = arch_data->iommu_dev = NULL;
Omar Ramirez Luna803b5272012-04-18 13:09:41 -05001149 omap_domain->dev = NULL;
1150}
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +03001151
Omar Ramirez Luna803b5272012-04-18 13:09:41 -05001152static void omap_iommu_detach_dev(struct iommu_domain *domain,
1153 struct device *dev)
1154{
1155 struct omap_iommu_domain *omap_domain = domain->priv;
1156
1157 spin_lock(&omap_domain->lock);
1158 _omap_iommu_detach_dev(omap_domain, dev);
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +03001159 spin_unlock(&omap_domain->lock);
1160}
1161
1162static int omap_iommu_domain_init(struct iommu_domain *domain)
1163{
1164 struct omap_iommu_domain *omap_domain;
1165
1166 omap_domain = kzalloc(sizeof(*omap_domain), GFP_KERNEL);
1167 if (!omap_domain) {
1168 pr_err("kzalloc failed\n");
1169 goto out;
1170 }
1171
1172 omap_domain->pgtable = kzalloc(IOPGD_TABLE_SIZE, GFP_KERNEL);
1173 if (!omap_domain->pgtable) {
1174 pr_err("kzalloc failed\n");
1175 goto fail_nomem;
1176 }
1177
1178 /*
1179 * should never fail, but please keep this around to ensure
1180 * we keep the hardware happy
1181 */
1182 BUG_ON(!IS_ALIGNED((long)omap_domain->pgtable, IOPGD_TABLE_SIZE));
1183
1184 clean_dcache_area(omap_domain->pgtable, IOPGD_TABLE_SIZE);
1185 spin_lock_init(&omap_domain->lock);
1186
1187 domain->priv = omap_domain;
1188
Joerg Roedel2c6edb02012-01-26 19:40:55 +01001189 domain->geometry.aperture_start = 0;
1190 domain->geometry.aperture_end = (1ULL << 32) - 1;
1191 domain->geometry.force_aperture = true;
1192
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +03001193 return 0;
1194
1195fail_nomem:
1196 kfree(omap_domain);
1197out:
1198 return -ENOMEM;
1199}
1200
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +03001201static void omap_iommu_domain_destroy(struct iommu_domain *domain)
1202{
1203 struct omap_iommu_domain *omap_domain = domain->priv;
1204
1205 domain->priv = NULL;
1206
Omar Ramirez Luna803b5272012-04-18 13:09:41 -05001207 /*
1208 * An iommu device is still attached
1209 * (currently, only one device can be attached) ?
1210 */
1211 if (omap_domain->iommu_dev)
1212 _omap_iommu_detach_dev(omap_domain, omap_domain->dev);
1213
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +03001214 kfree(omap_domain->pgtable);
1215 kfree(omap_domain);
1216}
1217
1218static phys_addr_t omap_iommu_iova_to_phys(struct iommu_domain *domain,
Varun Sethibb5547ac2013-03-29 01:23:58 +05301219 dma_addr_t da)
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +03001220{
1221 struct omap_iommu_domain *omap_domain = domain->priv;
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +03001222 struct omap_iommu *oiommu = omap_domain->iommu_dev;
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +03001223 struct device *dev = oiommu->dev;
1224 u32 *pgd, *pte;
1225 phys_addr_t ret = 0;
1226
1227 iopgtable_lookup_entry(oiommu, da, &pgd, &pte);
1228
1229 if (pte) {
1230 if (iopte_is_small(*pte))
1231 ret = omap_iommu_translate(*pte, da, IOPTE_MASK);
1232 else if (iopte_is_large(*pte))
1233 ret = omap_iommu_translate(*pte, da, IOLARGE_MASK);
1234 else
Suman Anna2abfcfb2013-05-30 18:10:38 -05001235 dev_err(dev, "bogus pte 0x%x, da 0x%llx", *pte,
1236 (unsigned long long)da);
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +03001237 } else {
1238 if (iopgd_is_section(*pgd))
1239 ret = omap_iommu_translate(*pgd, da, IOSECTION_MASK);
1240 else if (iopgd_is_super(*pgd))
1241 ret = omap_iommu_translate(*pgd, da, IOSUPER_MASK);
1242 else
Suman Anna2abfcfb2013-05-30 18:10:38 -05001243 dev_err(dev, "bogus pgd 0x%x, da 0x%llx", *pgd,
1244 (unsigned long long)da);
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +03001245 }
1246
1247 return ret;
1248}
1249
1250static int omap_iommu_domain_has_cap(struct iommu_domain *domain,
1251 unsigned long cap)
1252{
1253 return 0;
1254}
1255
1256static struct iommu_ops omap_iommu_ops = {
1257 .domain_init = omap_iommu_domain_init,
1258 .domain_destroy = omap_iommu_domain_destroy,
1259 .attach_dev = omap_iommu_attach_dev,
1260 .detach_dev = omap_iommu_detach_dev,
1261 .map = omap_iommu_map,
1262 .unmap = omap_iommu_unmap,
1263 .iova_to_phys = omap_iommu_iova_to_phys,
1264 .domain_has_cap = omap_iommu_domain_has_cap,
Ohad Ben-Cohen66bc8cf2011-11-10 11:32:27 +02001265 .pgsize_bitmap = OMAP_IOMMU_PGSIZES,
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +03001266};
1267
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +02001268static int __init omap_iommu_init(void)
1269{
1270 struct kmem_cache *p;
1271 const unsigned long flags = SLAB_HWCACHE_ALIGN;
1272 size_t align = 1 << 10; /* L2 pagetable alignement */
1273
1274 p = kmem_cache_create("iopte_cache", IOPTE_TABLE_SIZE, align, flags,
1275 iopte_cachep_ctor);
1276 if (!p)
1277 return -ENOMEM;
1278 iopte_cachep = p;
1279
Joerg Roedela65bc642011-09-06 17:56:07 +02001280 bus_set_iommu(&platform_bus_type, &omap_iommu_ops);
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +03001281
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +02001282 return platform_driver_register(&omap_iommu_driver);
1283}
Ohad Ben-Cohen435792d2012-02-26 12:14:14 +02001284/* must be ready before omap3isp is probed */
1285subsys_initcall(omap_iommu_init);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +02001286
1287static void __exit omap_iommu_exit(void)
1288{
1289 kmem_cache_destroy(iopte_cachep);
1290
1291 platform_driver_unregister(&omap_iommu_driver);
1292}
1293module_exit(omap_iommu_exit);
1294
1295MODULE_DESCRIPTION("omap iommu: tlb and pagetable primitives");
1296MODULE_ALIAS("platform:omap-iommu");
1297MODULE_AUTHOR("Hiroshi DOYU, Paul Mundt and Toshihiro Kobayashi");
1298MODULE_LICENSE("GPL v2");