| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 1 | /* | 
 | 2 |  * omap iommu: tlb and pagetable primitives | 
 | 3 |  * | 
| Hiroshi DOYU | c127c7d | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 4 |  * Copyright (C) 2008-2010 Nokia Corporation | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 5 |  * | 
 | 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 Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 16 | #include <linux/slab.h> | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 17 | #include <linux/interrupt.h> | 
 | 18 | #include <linux/ioport.h> | 
 | 19 | #include <linux/clk.h> | 
 | 20 | #include <linux/platform_device.h> | 
| Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 21 | #include <linux/iommu.h> | 
 | 22 | #include <linux/mutex.h> | 
 | 23 | #include <linux/spinlock.h> | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 24 |  | 
 | 25 | #include <asm/cacheflush.h> | 
 | 26 |  | 
| Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 27 | #include <plat/iommu.h> | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 28 |  | 
| Ohad Ben-Cohen | fcf3a6e | 2011-08-15 23:21:41 +0300 | [diff] [blame] | 29 | #include <plat/iopgtable.h> | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 30 |  | 
| Hiroshi DOYU | 37c2836 | 2010-04-27 05:37:12 +0000 | [diff] [blame] | 31 | #define for_each_iotlb_cr(obj, n, __i, cr)				\ | 
 | 32 | 	for (__i = 0;							\ | 
 | 33 | 	     (__i < (n)) && (cr = __iotlb_read_cr((obj), __i), true);	\ | 
 | 34 | 	     __i++) | 
 | 35 |  | 
| Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 36 | /** | 
 | 37 |  * struct omap_iommu_domain - omap iommu domain | 
 | 38 |  * @pgtable:	the page table | 
 | 39 |  * @iommu_dev:	an omap iommu device attached to this domain. only a single | 
 | 40 |  *		iommu device can be attached for now. | 
 | 41 |  * @lock:	domain lock, should be taken when attaching/detaching | 
 | 42 |  */ | 
 | 43 | struct omap_iommu_domain { | 
 | 44 | 	u32 *pgtable; | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 45 | 	struct omap_iommu *iommu_dev; | 
| Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 46 | 	spinlock_t lock; | 
 | 47 | }; | 
 | 48 |  | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 49 | /* accommodate the difference between omap1 and omap2/3 */ | 
 | 50 | static const struct iommu_functions *arch_iommu; | 
 | 51 |  | 
 | 52 | static struct platform_driver omap_iommu_driver; | 
 | 53 | static struct kmem_cache *iopte_cachep; | 
 | 54 |  | 
 | 55 | /** | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 56 |  * omap_install_iommu_arch - Install archtecure specific iommu functions | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 57 |  * @ops:	a pointer to architecture specific iommu functions | 
 | 58 |  * | 
 | 59 |  * There are several kind of iommu algorithm(tlb, pagetable) among | 
 | 60 |  * omap series. This interface installs such an iommu algorighm. | 
 | 61 |  **/ | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 62 | int omap_install_iommu_arch(const struct iommu_functions *ops) | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 63 | { | 
 | 64 | 	if (arch_iommu) | 
 | 65 | 		return -EBUSY; | 
 | 66 |  | 
 | 67 | 	arch_iommu = ops; | 
 | 68 | 	return 0; | 
 | 69 | } | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 70 | EXPORT_SYMBOL_GPL(omap_install_iommu_arch); | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 71 |  | 
 | 72 | /** | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 73 |  * omap_uninstall_iommu_arch - Uninstall archtecure specific iommu functions | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 74 |  * @ops:	a pointer to architecture specific iommu functions | 
 | 75 |  * | 
 | 76 |  * This interface uninstalls the iommu algorighm installed previously. | 
 | 77 |  **/ | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 78 | void omap_uninstall_iommu_arch(const struct iommu_functions *ops) | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 79 | { | 
 | 80 | 	if (arch_iommu != ops) | 
 | 81 | 		pr_err("%s: not your arch\n", __func__); | 
 | 82 |  | 
 | 83 | 	arch_iommu = NULL; | 
 | 84 | } | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 85 | EXPORT_SYMBOL_GPL(omap_uninstall_iommu_arch); | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 86 |  | 
 | 87 | /** | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 88 |  * omap_iommu_save_ctx - Save registers for pm off-mode support | 
| Ohad Ben-Cohen | fabdbca | 2011-10-11 00:18:33 +0200 | [diff] [blame^] | 89 |  * @dev:	client device | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 90 |  **/ | 
| Ohad Ben-Cohen | fabdbca | 2011-10-11 00:18:33 +0200 | [diff] [blame^] | 91 | void omap_iommu_save_ctx(struct device *dev) | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 92 | { | 
| Ohad Ben-Cohen | fabdbca | 2011-10-11 00:18:33 +0200 | [diff] [blame^] | 93 | 	struct omap_iommu *obj = dev_to_omap_iommu(dev); | 
 | 94 |  | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 95 | 	arch_iommu->save_ctx(obj); | 
 | 96 | } | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 97 | EXPORT_SYMBOL_GPL(omap_iommu_save_ctx); | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 98 |  | 
 | 99 | /** | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 100 |  * omap_iommu_restore_ctx - Restore registers for pm off-mode support | 
| Ohad Ben-Cohen | fabdbca | 2011-10-11 00:18:33 +0200 | [diff] [blame^] | 101 |  * @dev:	client device | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 102 |  **/ | 
| Ohad Ben-Cohen | fabdbca | 2011-10-11 00:18:33 +0200 | [diff] [blame^] | 103 | void omap_iommu_restore_ctx(struct device *dev) | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 104 | { | 
| Ohad Ben-Cohen | fabdbca | 2011-10-11 00:18:33 +0200 | [diff] [blame^] | 105 | 	struct omap_iommu *obj = dev_to_omap_iommu(dev); | 
 | 106 |  | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 107 | 	arch_iommu->restore_ctx(obj); | 
 | 108 | } | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 109 | EXPORT_SYMBOL_GPL(omap_iommu_restore_ctx); | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 110 |  | 
 | 111 | /** | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 112 |  * omap_iommu_arch_version - Return running iommu arch version | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 113 |  **/ | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 114 | u32 omap_iommu_arch_version(void) | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 115 | { | 
 | 116 | 	return arch_iommu->version; | 
 | 117 | } | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 118 | EXPORT_SYMBOL_GPL(omap_iommu_arch_version); | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 119 |  | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 120 | static int iommu_enable(struct omap_iommu *obj) | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 121 | { | 
 | 122 | 	int err; | 
 | 123 |  | 
 | 124 | 	if (!obj) | 
 | 125 | 		return -EINVAL; | 
 | 126 |  | 
| Martin Hostettler | ef4815a | 2011-02-24 12:51:31 -0800 | [diff] [blame] | 127 | 	if (!arch_iommu) | 
 | 128 | 		return -ENODEV; | 
 | 129 |  | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 130 | 	clk_enable(obj->clk); | 
 | 131 |  | 
 | 132 | 	err = arch_iommu->enable(obj); | 
 | 133 |  | 
 | 134 | 	clk_disable(obj->clk); | 
 | 135 | 	return err; | 
 | 136 | } | 
 | 137 |  | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 138 | static void iommu_disable(struct omap_iommu *obj) | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 139 | { | 
 | 140 | 	if (!obj) | 
 | 141 | 		return; | 
 | 142 |  | 
 | 143 | 	clk_enable(obj->clk); | 
 | 144 |  | 
 | 145 | 	arch_iommu->disable(obj); | 
 | 146 |  | 
 | 147 | 	clk_disable(obj->clk); | 
 | 148 | } | 
 | 149 |  | 
 | 150 | /* | 
 | 151 |  *	TLB operations | 
 | 152 |  */ | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 153 | void omap_iotlb_cr_to_e(struct cr_regs *cr, struct iotlb_entry *e) | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 154 | { | 
 | 155 | 	BUG_ON(!cr || !e); | 
 | 156 |  | 
 | 157 | 	arch_iommu->cr_to_e(cr, e); | 
 | 158 | } | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 159 | EXPORT_SYMBOL_GPL(omap_iotlb_cr_to_e); | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 160 |  | 
 | 161 | static inline int iotlb_cr_valid(struct cr_regs *cr) | 
 | 162 | { | 
 | 163 | 	if (!cr) | 
 | 164 | 		return -EINVAL; | 
 | 165 |  | 
 | 166 | 	return arch_iommu->cr_valid(cr); | 
 | 167 | } | 
 | 168 |  | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 169 | static inline struct cr_regs *iotlb_alloc_cr(struct omap_iommu *obj, | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 170 | 					     struct iotlb_entry *e) | 
 | 171 | { | 
 | 172 | 	if (!e) | 
 | 173 | 		return NULL; | 
 | 174 |  | 
 | 175 | 	return arch_iommu->alloc_cr(obj, e); | 
 | 176 | } | 
 | 177 |  | 
| Ohad Ben-Cohen | e1f2381 | 2011-08-16 14:58:14 +0300 | [diff] [blame] | 178 | static u32 iotlb_cr_to_virt(struct cr_regs *cr) | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 179 | { | 
 | 180 | 	return arch_iommu->cr_to_virt(cr); | 
 | 181 | } | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 182 |  | 
 | 183 | static u32 get_iopte_attr(struct iotlb_entry *e) | 
 | 184 | { | 
 | 185 | 	return arch_iommu->get_pte_attr(e); | 
 | 186 | } | 
 | 187 |  | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 188 | static u32 iommu_report_fault(struct omap_iommu *obj, u32 *da) | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 189 | { | 
 | 190 | 	return arch_iommu->fault_isr(obj, da); | 
 | 191 | } | 
 | 192 |  | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 193 | static void iotlb_lock_get(struct omap_iommu *obj, struct iotlb_lock *l) | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 194 | { | 
 | 195 | 	u32 val; | 
 | 196 |  | 
 | 197 | 	val = iommu_read_reg(obj, MMU_LOCK); | 
 | 198 |  | 
 | 199 | 	l->base = MMU_LOCK_BASE(val); | 
 | 200 | 	l->vict = MMU_LOCK_VICT(val); | 
 | 201 |  | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 202 | } | 
 | 203 |  | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 204 | static void iotlb_lock_set(struct omap_iommu *obj, struct iotlb_lock *l) | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 205 | { | 
 | 206 | 	u32 val; | 
 | 207 |  | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 208 | 	val = (l->base << MMU_LOCK_BASE_SHIFT); | 
 | 209 | 	val |= (l->vict << MMU_LOCK_VICT_SHIFT); | 
 | 210 |  | 
 | 211 | 	iommu_write_reg(obj, val, MMU_LOCK); | 
 | 212 | } | 
 | 213 |  | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 214 | static void iotlb_read_cr(struct omap_iommu *obj, struct cr_regs *cr) | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 215 | { | 
 | 216 | 	arch_iommu->tlb_read_cr(obj, cr); | 
 | 217 | } | 
 | 218 |  | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 219 | static void iotlb_load_cr(struct omap_iommu *obj, struct cr_regs *cr) | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 220 | { | 
 | 221 | 	arch_iommu->tlb_load_cr(obj, cr); | 
 | 222 |  | 
 | 223 | 	iommu_write_reg(obj, 1, MMU_FLUSH_ENTRY); | 
 | 224 | 	iommu_write_reg(obj, 1, MMU_LD_TLB); | 
 | 225 | } | 
 | 226 |  | 
 | 227 | /** | 
 | 228 |  * iotlb_dump_cr - Dump an iommu tlb entry into buf | 
 | 229 |  * @obj:	target iommu | 
 | 230 |  * @cr:		contents of cam and ram register | 
 | 231 |  * @buf:	output buffer | 
 | 232 |  **/ | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 233 | static inline ssize_t iotlb_dump_cr(struct omap_iommu *obj, struct cr_regs *cr, | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 234 | 				    char *buf) | 
 | 235 | { | 
 | 236 | 	BUG_ON(!cr || !buf); | 
 | 237 |  | 
 | 238 | 	return arch_iommu->dump_cr(obj, cr, buf); | 
 | 239 | } | 
 | 240 |  | 
| Hiroshi DOYU | 37c2836 | 2010-04-27 05:37:12 +0000 | [diff] [blame] | 241 | /* only used in iotlb iteration for-loop */ | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 242 | static struct cr_regs __iotlb_read_cr(struct omap_iommu *obj, int n) | 
| Hiroshi DOYU | 37c2836 | 2010-04-27 05:37:12 +0000 | [diff] [blame] | 243 | { | 
 | 244 | 	struct cr_regs cr; | 
 | 245 | 	struct iotlb_lock l; | 
 | 246 |  | 
 | 247 | 	iotlb_lock_get(obj, &l); | 
 | 248 | 	l.vict = n; | 
 | 249 | 	iotlb_lock_set(obj, &l); | 
 | 250 | 	iotlb_read_cr(obj, &cr); | 
 | 251 |  | 
 | 252 | 	return cr; | 
 | 253 | } | 
 | 254 |  | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 255 | /** | 
 | 256 |  * load_iotlb_entry - Set an iommu tlb entry | 
 | 257 |  * @obj:	target iommu | 
 | 258 |  * @e:		an iommu tlb entry info | 
 | 259 |  **/ | 
| Ohad Ben-Cohen | 5da14a4 | 2011-08-16 15:19:10 +0300 | [diff] [blame] | 260 | #ifdef PREFETCH_IOTLB | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 261 | static int load_iotlb_entry(struct omap_iommu *obj, struct iotlb_entry *e) | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 262 | { | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 263 | 	int err = 0; | 
 | 264 | 	struct iotlb_lock l; | 
 | 265 | 	struct cr_regs *cr; | 
 | 266 |  | 
 | 267 | 	if (!obj || !obj->nr_tlb_entries || !e) | 
 | 268 | 		return -EINVAL; | 
 | 269 |  | 
 | 270 | 	clk_enable(obj->clk); | 
 | 271 |  | 
| Kanigeri, Hari | be6d802 | 2010-04-22 23:26:11 +0000 | [diff] [blame] | 272 | 	iotlb_lock_get(obj, &l); | 
 | 273 | 	if (l.base == obj->nr_tlb_entries) { | 
 | 274 | 		dev_warn(obj->dev, "%s: preserve entries full\n", __func__); | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 275 | 		err = -EBUSY; | 
 | 276 | 		goto out; | 
 | 277 | 	} | 
| Kanigeri, Hari | be6d802 | 2010-04-22 23:26:11 +0000 | [diff] [blame] | 278 | 	if (!e->prsvd) { | 
| Hiroshi DOYU | 37c2836 | 2010-04-27 05:37:12 +0000 | [diff] [blame] | 279 | 		int i; | 
 | 280 | 		struct cr_regs tmp; | 
| Kanigeri, Hari | be6d802 | 2010-04-22 23:26:11 +0000 | [diff] [blame] | 281 |  | 
| Hiroshi DOYU | 37c2836 | 2010-04-27 05:37:12 +0000 | [diff] [blame] | 282 | 		for_each_iotlb_cr(obj, obj->nr_tlb_entries, i, tmp) | 
| Kanigeri, Hari | be6d802 | 2010-04-22 23:26:11 +0000 | [diff] [blame] | 283 | 			if (!iotlb_cr_valid(&tmp)) | 
 | 284 | 				break; | 
| Hiroshi DOYU | 37c2836 | 2010-04-27 05:37:12 +0000 | [diff] [blame] | 285 |  | 
| Kanigeri, Hari | be6d802 | 2010-04-22 23:26:11 +0000 | [diff] [blame] | 286 | 		if (i == obj->nr_tlb_entries) { | 
 | 287 | 			dev_dbg(obj->dev, "%s: full: no entry\n", __func__); | 
 | 288 | 			err = -EBUSY; | 
 | 289 | 			goto out; | 
 | 290 | 		} | 
| Hiroshi DOYU | 37c2836 | 2010-04-27 05:37:12 +0000 | [diff] [blame] | 291 |  | 
 | 292 | 		iotlb_lock_get(obj, &l); | 
| Kanigeri, Hari | be6d802 | 2010-04-22 23:26:11 +0000 | [diff] [blame] | 293 | 	} else { | 
 | 294 | 		l.vict = l.base; | 
 | 295 | 		iotlb_lock_set(obj, &l); | 
 | 296 | 	} | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 297 |  | 
 | 298 | 	cr = iotlb_alloc_cr(obj, e); | 
 | 299 | 	if (IS_ERR(cr)) { | 
 | 300 | 		clk_disable(obj->clk); | 
 | 301 | 		return PTR_ERR(cr); | 
 | 302 | 	} | 
 | 303 |  | 
 | 304 | 	iotlb_load_cr(obj, cr); | 
 | 305 | 	kfree(cr); | 
 | 306 |  | 
| Kanigeri, Hari | be6d802 | 2010-04-22 23:26:11 +0000 | [diff] [blame] | 307 | 	if (e->prsvd) | 
 | 308 | 		l.base++; | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 309 | 	/* increment victim for next tlb load */ | 
 | 310 | 	if (++l.vict == obj->nr_tlb_entries) | 
| Kanigeri, Hari | be6d802 | 2010-04-22 23:26:11 +0000 | [diff] [blame] | 311 | 		l.vict = l.base; | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 312 | 	iotlb_lock_set(obj, &l); | 
 | 313 | out: | 
 | 314 | 	clk_disable(obj->clk); | 
 | 315 | 	return err; | 
 | 316 | } | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 317 |  | 
| Ohad Ben-Cohen | 5da14a4 | 2011-08-16 15:19:10 +0300 | [diff] [blame] | 318 | #else /* !PREFETCH_IOTLB */ | 
 | 319 |  | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 320 | static int load_iotlb_entry(struct omap_iommu *obj, struct iotlb_entry *e) | 
| Ohad Ben-Cohen | 5da14a4 | 2011-08-16 15:19:10 +0300 | [diff] [blame] | 321 | { | 
 | 322 | 	return 0; | 
 | 323 | } | 
 | 324 |  | 
 | 325 | #endif /* !PREFETCH_IOTLB */ | 
 | 326 |  | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 327 | static int prefetch_iotlb_entry(struct omap_iommu *obj, struct iotlb_entry *e) | 
| Ohad Ben-Cohen | 5da14a4 | 2011-08-16 15:19:10 +0300 | [diff] [blame] | 328 | { | 
 | 329 | 	return load_iotlb_entry(obj, e); | 
 | 330 | } | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 331 |  | 
 | 332 | /** | 
 | 333 |  * flush_iotlb_page - Clear an iommu tlb entry | 
 | 334 |  * @obj:	target iommu | 
 | 335 |  * @da:		iommu device virtual address | 
 | 336 |  * | 
 | 337 |  * Clear an iommu tlb entry which includes 'da' address. | 
 | 338 |  **/ | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 339 | static void flush_iotlb_page(struct omap_iommu *obj, u32 da) | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 340 | { | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 341 | 	int i; | 
| Hiroshi DOYU | 37c2836 | 2010-04-27 05:37:12 +0000 | [diff] [blame] | 342 | 	struct cr_regs cr; | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 343 |  | 
 | 344 | 	clk_enable(obj->clk); | 
 | 345 |  | 
| Hiroshi DOYU | 37c2836 | 2010-04-27 05:37:12 +0000 | [diff] [blame] | 346 | 	for_each_iotlb_cr(obj, obj->nr_tlb_entries, i, cr) { | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 347 | 		u32 start; | 
 | 348 | 		size_t bytes; | 
 | 349 |  | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 350 | 		if (!iotlb_cr_valid(&cr)) | 
 | 351 | 			continue; | 
 | 352 |  | 
 | 353 | 		start = iotlb_cr_to_virt(&cr); | 
 | 354 | 		bytes = iopgsz_to_bytes(cr.cam & 3); | 
 | 355 |  | 
 | 356 | 		if ((start <= da) && (da < start + bytes)) { | 
 | 357 | 			dev_dbg(obj->dev, "%s: %08x<=%08x(%x)\n", | 
 | 358 | 				__func__, start, da, bytes); | 
| Hari Kanigeri | 0fa035e | 2010-08-20 13:50:18 +0000 | [diff] [blame] | 359 | 			iotlb_load_cr(obj, &cr); | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 360 | 			iommu_write_reg(obj, 1, MMU_FLUSH_ENTRY); | 
 | 361 | 		} | 
 | 362 | 	} | 
 | 363 | 	clk_disable(obj->clk); | 
 | 364 |  | 
 | 365 | 	if (i == obj->nr_tlb_entries) | 
 | 366 | 		dev_dbg(obj->dev, "%s: no page for %08x\n", __func__, da); | 
 | 367 | } | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 368 |  | 
 | 369 | /** | 
 | 370 |  * flush_iotlb_all - Clear all iommu tlb entries | 
 | 371 |  * @obj:	target iommu | 
 | 372 |  **/ | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 373 | static void flush_iotlb_all(struct omap_iommu *obj) | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 374 | { | 
 | 375 | 	struct iotlb_lock l; | 
 | 376 |  | 
 | 377 | 	clk_enable(obj->clk); | 
 | 378 |  | 
 | 379 | 	l.base = 0; | 
 | 380 | 	l.vict = 0; | 
 | 381 | 	iotlb_lock_set(obj, &l); | 
 | 382 |  | 
 | 383 | 	iommu_write_reg(obj, 1, MMU_GFLUSH); | 
 | 384 |  | 
 | 385 | 	clk_disable(obj->clk); | 
 | 386 | } | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 387 |  | 
| Arnd Bergmann | e4efd94 | 2011-10-02 14:34:05 -0400 | [diff] [blame] | 388 | #if defined(CONFIG_OMAP_IOMMU_DEBUG) || defined(CONFIG_OMAP_IOMMU_DEBUG_MODULE) | 
| Kanigeri, Hari | ddfa975 | 2010-05-24 02:01:51 +0000 | [diff] [blame] | 389 |  | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 390 | ssize_t omap_iommu_dump_ctx(struct omap_iommu *obj, char *buf, ssize_t bytes) | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 391 | { | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 392 | 	if (!obj || !buf) | 
 | 393 | 		return -EINVAL; | 
 | 394 |  | 
 | 395 | 	clk_enable(obj->clk); | 
 | 396 |  | 
| Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 397 | 	bytes = arch_iommu->dump_ctx(obj, buf, bytes); | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 398 |  | 
 | 399 | 	clk_disable(obj->clk); | 
 | 400 |  | 
 | 401 | 	return bytes; | 
 | 402 | } | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 403 | EXPORT_SYMBOL_GPL(omap_iommu_dump_ctx); | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 404 |  | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 405 | static int | 
 | 406 | __dump_tlb_entries(struct omap_iommu *obj, struct cr_regs *crs, int num) | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 407 | { | 
 | 408 | 	int i; | 
| Hiroshi DOYU | 37c2836 | 2010-04-27 05:37:12 +0000 | [diff] [blame] | 409 | 	struct iotlb_lock saved; | 
 | 410 | 	struct cr_regs tmp; | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 411 | 	struct cr_regs *p = crs; | 
 | 412 |  | 
 | 413 | 	clk_enable(obj->clk); | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 414 | 	iotlb_lock_get(obj, &saved); | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 415 |  | 
| Hiroshi DOYU | 37c2836 | 2010-04-27 05:37:12 +0000 | [diff] [blame] | 416 | 	for_each_iotlb_cr(obj, num, i, tmp) { | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 417 | 		if (!iotlb_cr_valid(&tmp)) | 
 | 418 | 			continue; | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 419 | 		*p++ = tmp; | 
 | 420 | 	} | 
| Hiroshi DOYU | 37c2836 | 2010-04-27 05:37:12 +0000 | [diff] [blame] | 421 |  | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 422 | 	iotlb_lock_set(obj, &saved); | 
 | 423 | 	clk_disable(obj->clk); | 
 | 424 |  | 
 | 425 | 	return  p - crs; | 
 | 426 | } | 
 | 427 |  | 
 | 428 | /** | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 429 |  * omap_dump_tlb_entries - dump cr arrays to given buffer | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 430 |  * @obj:	target iommu | 
 | 431 |  * @buf:	output buffer | 
 | 432 |  **/ | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 433 | size_t omap_dump_tlb_entries(struct omap_iommu *obj, char *buf, ssize_t bytes) | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 434 | { | 
| Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 435 | 	int i, num; | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 436 | 	struct cr_regs *cr; | 
 | 437 | 	char *p = buf; | 
 | 438 |  | 
| Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 439 | 	num = bytes / sizeof(*cr); | 
 | 440 | 	num = min(obj->nr_tlb_entries, num); | 
 | 441 |  | 
 | 442 | 	cr = kcalloc(num, sizeof(*cr), GFP_KERNEL); | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 443 | 	if (!cr) | 
 | 444 | 		return 0; | 
 | 445 |  | 
| Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 446 | 	num = __dump_tlb_entries(obj, cr, num); | 
 | 447 | 	for (i = 0; i < num; i++) | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 448 | 		p += iotlb_dump_cr(obj, cr + i, p); | 
 | 449 | 	kfree(cr); | 
 | 450 |  | 
 | 451 | 	return p - buf; | 
 | 452 | } | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 453 | EXPORT_SYMBOL_GPL(omap_dump_tlb_entries); | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 454 |  | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 455 | int omap_foreach_iommu_device(void *data, int (*fn)(struct device *, void *)) | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 456 | { | 
 | 457 | 	return driver_for_each_device(&omap_iommu_driver.driver, | 
 | 458 | 				      NULL, data, fn); | 
 | 459 | } | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 460 | EXPORT_SYMBOL_GPL(omap_foreach_iommu_device); | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 461 |  | 
 | 462 | #endif /* CONFIG_OMAP_IOMMU_DEBUG_MODULE */ | 
 | 463 |  | 
 | 464 | /* | 
 | 465 |  *	H/W pagetable operations | 
 | 466 |  */ | 
 | 467 | static void flush_iopgd_range(u32 *first, u32 *last) | 
 | 468 | { | 
 | 469 | 	/* FIXME: L2 cache should be taken care of if it exists */ | 
 | 470 | 	do { | 
 | 471 | 		asm("mcr	p15, 0, %0, c7, c10, 1 @ flush_pgd" | 
 | 472 | 		    : : "r" (first)); | 
 | 473 | 		first += L1_CACHE_BYTES / sizeof(*first); | 
 | 474 | 	} while (first <= last); | 
 | 475 | } | 
 | 476 |  | 
 | 477 | static void flush_iopte_range(u32 *first, u32 *last) | 
 | 478 | { | 
 | 479 | 	/* FIXME: L2 cache should be taken care of if it exists */ | 
 | 480 | 	do { | 
 | 481 | 		asm("mcr	p15, 0, %0, c7, c10, 1 @ flush_pte" | 
 | 482 | 		    : : "r" (first)); | 
 | 483 | 		first += L1_CACHE_BYTES / sizeof(*first); | 
 | 484 | 	} while (first <= last); | 
 | 485 | } | 
 | 486 |  | 
 | 487 | static void iopte_free(u32 *iopte) | 
 | 488 | { | 
 | 489 | 	/* Note: freed iopte's must be clean ready for re-use */ | 
 | 490 | 	kmem_cache_free(iopte_cachep, iopte); | 
 | 491 | } | 
 | 492 |  | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 493 | static u32 *iopte_alloc(struct omap_iommu *obj, u32 *iopgd, u32 da) | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 494 | { | 
 | 495 | 	u32 *iopte; | 
 | 496 |  | 
 | 497 | 	/* a table has already existed */ | 
 | 498 | 	if (*iopgd) | 
 | 499 | 		goto pte_ready; | 
 | 500 |  | 
 | 501 | 	/* | 
 | 502 | 	 * do the allocation outside the page table lock | 
 | 503 | 	 */ | 
 | 504 | 	spin_unlock(&obj->page_table_lock); | 
 | 505 | 	iopte = kmem_cache_zalloc(iopte_cachep, GFP_KERNEL); | 
 | 506 | 	spin_lock(&obj->page_table_lock); | 
 | 507 |  | 
 | 508 | 	if (!*iopgd) { | 
 | 509 | 		if (!iopte) | 
 | 510 | 			return ERR_PTR(-ENOMEM); | 
 | 511 |  | 
 | 512 | 		*iopgd = virt_to_phys(iopte) | IOPGD_TABLE; | 
 | 513 | 		flush_iopgd_range(iopgd, iopgd); | 
 | 514 |  | 
 | 515 | 		dev_vdbg(obj->dev, "%s: a new pte:%p\n", __func__, iopte); | 
 | 516 | 	} else { | 
 | 517 | 		/* We raced, free the reduniovant table */ | 
 | 518 | 		iopte_free(iopte); | 
 | 519 | 	} | 
 | 520 |  | 
 | 521 | pte_ready: | 
 | 522 | 	iopte = iopte_offset(iopgd, da); | 
 | 523 |  | 
 | 524 | 	dev_vdbg(obj->dev, | 
 | 525 | 		 "%s: da:%08x pgd:%p *pgd:%08x pte:%p *pte:%08x\n", | 
 | 526 | 		 __func__, da, iopgd, *iopgd, iopte, *iopte); | 
 | 527 |  | 
 | 528 | 	return iopte; | 
 | 529 | } | 
 | 530 |  | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 531 | static int iopgd_alloc_section(struct omap_iommu *obj, u32 da, u32 pa, u32 prot) | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 532 | { | 
 | 533 | 	u32 *iopgd = iopgd_offset(obj, da); | 
 | 534 |  | 
| Hiroshi DOYU | 4abb761 | 2010-05-06 18:24:04 +0300 | [diff] [blame] | 535 | 	if ((da | pa) & ~IOSECTION_MASK) { | 
 | 536 | 		dev_err(obj->dev, "%s: %08x:%08x should aligned on %08lx\n", | 
 | 537 | 			__func__, da, pa, IOSECTION_SIZE); | 
 | 538 | 		return -EINVAL; | 
 | 539 | 	} | 
 | 540 |  | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 541 | 	*iopgd = (pa & IOSECTION_MASK) | prot | IOPGD_SECTION; | 
 | 542 | 	flush_iopgd_range(iopgd, iopgd); | 
 | 543 | 	return 0; | 
 | 544 | } | 
 | 545 |  | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 546 | static int iopgd_alloc_super(struct omap_iommu *obj, u32 da, u32 pa, u32 prot) | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 547 | { | 
 | 548 | 	u32 *iopgd = iopgd_offset(obj, da); | 
 | 549 | 	int i; | 
 | 550 |  | 
| Hiroshi DOYU | 4abb761 | 2010-05-06 18:24:04 +0300 | [diff] [blame] | 551 | 	if ((da | pa) & ~IOSUPER_MASK) { | 
 | 552 | 		dev_err(obj->dev, "%s: %08x:%08x should aligned on %08lx\n", | 
 | 553 | 			__func__, da, pa, IOSUPER_SIZE); | 
 | 554 | 		return -EINVAL; | 
 | 555 | 	} | 
 | 556 |  | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 557 | 	for (i = 0; i < 16; i++) | 
 | 558 | 		*(iopgd + i) = (pa & IOSUPER_MASK) | prot | IOPGD_SUPER; | 
 | 559 | 	flush_iopgd_range(iopgd, iopgd + 15); | 
 | 560 | 	return 0; | 
 | 561 | } | 
 | 562 |  | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 563 | static int iopte_alloc_page(struct omap_iommu *obj, u32 da, u32 pa, u32 prot) | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 564 | { | 
 | 565 | 	u32 *iopgd = iopgd_offset(obj, da); | 
 | 566 | 	u32 *iopte = iopte_alloc(obj, iopgd, da); | 
 | 567 |  | 
 | 568 | 	if (IS_ERR(iopte)) | 
 | 569 | 		return PTR_ERR(iopte); | 
 | 570 |  | 
 | 571 | 	*iopte = (pa & IOPAGE_MASK) | prot | IOPTE_SMALL; | 
 | 572 | 	flush_iopte_range(iopte, iopte); | 
 | 573 |  | 
 | 574 | 	dev_vdbg(obj->dev, "%s: da:%08x pa:%08x pte:%p *pte:%08x\n", | 
 | 575 | 		 __func__, da, pa, iopte, *iopte); | 
 | 576 |  | 
 | 577 | 	return 0; | 
 | 578 | } | 
 | 579 |  | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 580 | static int iopte_alloc_large(struct omap_iommu *obj, u32 da, u32 pa, u32 prot) | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 581 | { | 
 | 582 | 	u32 *iopgd = iopgd_offset(obj, da); | 
 | 583 | 	u32 *iopte = iopte_alloc(obj, iopgd, da); | 
 | 584 | 	int i; | 
 | 585 |  | 
| Hiroshi DOYU | 4abb761 | 2010-05-06 18:24:04 +0300 | [diff] [blame] | 586 | 	if ((da | pa) & ~IOLARGE_MASK) { | 
 | 587 | 		dev_err(obj->dev, "%s: %08x:%08x should aligned on %08lx\n", | 
 | 588 | 			__func__, da, pa, IOLARGE_SIZE); | 
 | 589 | 		return -EINVAL; | 
 | 590 | 	} | 
 | 591 |  | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 592 | 	if (IS_ERR(iopte)) | 
 | 593 | 		return PTR_ERR(iopte); | 
 | 594 |  | 
 | 595 | 	for (i = 0; i < 16; i++) | 
 | 596 | 		*(iopte + i) = (pa & IOLARGE_MASK) | prot | IOPTE_LARGE; | 
 | 597 | 	flush_iopte_range(iopte, iopte + 15); | 
 | 598 | 	return 0; | 
 | 599 | } | 
 | 600 |  | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 601 | static int | 
 | 602 | iopgtable_store_entry_core(struct omap_iommu *obj, struct iotlb_entry *e) | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 603 | { | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 604 | 	int (*fn)(struct omap_iommu *, u32, u32, u32); | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 605 | 	u32 prot; | 
 | 606 | 	int err; | 
 | 607 |  | 
 | 608 | 	if (!obj || !e) | 
 | 609 | 		return -EINVAL; | 
 | 610 |  | 
 | 611 | 	switch (e->pgsz) { | 
 | 612 | 	case MMU_CAM_PGSZ_16M: | 
 | 613 | 		fn = iopgd_alloc_super; | 
 | 614 | 		break; | 
 | 615 | 	case MMU_CAM_PGSZ_1M: | 
 | 616 | 		fn = iopgd_alloc_section; | 
 | 617 | 		break; | 
 | 618 | 	case MMU_CAM_PGSZ_64K: | 
 | 619 | 		fn = iopte_alloc_large; | 
 | 620 | 		break; | 
 | 621 | 	case MMU_CAM_PGSZ_4K: | 
 | 622 | 		fn = iopte_alloc_page; | 
 | 623 | 		break; | 
 | 624 | 	default: | 
 | 625 | 		fn = NULL; | 
 | 626 | 		BUG(); | 
 | 627 | 		break; | 
 | 628 | 	} | 
 | 629 |  | 
 | 630 | 	prot = get_iopte_attr(e); | 
 | 631 |  | 
 | 632 | 	spin_lock(&obj->page_table_lock); | 
 | 633 | 	err = fn(obj, e->da, e->pa, prot); | 
 | 634 | 	spin_unlock(&obj->page_table_lock); | 
 | 635 |  | 
 | 636 | 	return err; | 
 | 637 | } | 
 | 638 |  | 
 | 639 | /** | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 640 |  * omap_iopgtable_store_entry - Make an iommu pte entry | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 641 |  * @obj:	target iommu | 
 | 642 |  * @e:		an iommu tlb entry info | 
 | 643 |  **/ | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 644 | int omap_iopgtable_store_entry(struct omap_iommu *obj, struct iotlb_entry *e) | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 645 | { | 
 | 646 | 	int err; | 
 | 647 |  | 
 | 648 | 	flush_iotlb_page(obj, e->da); | 
 | 649 | 	err = iopgtable_store_entry_core(obj, e); | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 650 | 	if (!err) | 
| Ohad Ben-Cohen | 5da14a4 | 2011-08-16 15:19:10 +0300 | [diff] [blame] | 651 | 		prefetch_iotlb_entry(obj, e); | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 652 | 	return err; | 
 | 653 | } | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 654 | EXPORT_SYMBOL_GPL(omap_iopgtable_store_entry); | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 655 |  | 
 | 656 | /** | 
 | 657 |  * iopgtable_lookup_entry - Lookup an iommu pte entry | 
 | 658 |  * @obj:	target iommu | 
 | 659 |  * @da:		iommu device virtual address | 
 | 660 |  * @ppgd:	iommu pgd entry pointer to be returned | 
 | 661 |  * @ppte:	iommu pte entry pointer to be returned | 
 | 662 |  **/ | 
| Ohad Ben-Cohen | e1f2381 | 2011-08-16 14:58:14 +0300 | [diff] [blame] | 663 | static void | 
 | 664 | iopgtable_lookup_entry(struct omap_iommu *obj, u32 da, u32 **ppgd, u32 **ppte) | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 665 | { | 
 | 666 | 	u32 *iopgd, *iopte = NULL; | 
 | 667 |  | 
 | 668 | 	iopgd = iopgd_offset(obj, da); | 
 | 669 | 	if (!*iopgd) | 
 | 670 | 		goto out; | 
 | 671 |  | 
| Hiroshi DOYU | a1a5445 | 2010-05-13 09:45:35 +0300 | [diff] [blame] | 672 | 	if (iopgd_is_table(*iopgd)) | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 673 | 		iopte = iopte_offset(iopgd, da); | 
 | 674 | out: | 
 | 675 | 	*ppgd = iopgd; | 
 | 676 | 	*ppte = iopte; | 
 | 677 | } | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 678 |  | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 679 | static size_t iopgtable_clear_entry_core(struct omap_iommu *obj, u32 da) | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 680 | { | 
 | 681 | 	size_t bytes; | 
 | 682 | 	u32 *iopgd = iopgd_offset(obj, da); | 
 | 683 | 	int nent = 1; | 
 | 684 |  | 
 | 685 | 	if (!*iopgd) | 
 | 686 | 		return 0; | 
 | 687 |  | 
| Hiroshi DOYU | a1a5445 | 2010-05-13 09:45:35 +0300 | [diff] [blame] | 688 | 	if (iopgd_is_table(*iopgd)) { | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 689 | 		int i; | 
 | 690 | 		u32 *iopte = iopte_offset(iopgd, da); | 
 | 691 |  | 
 | 692 | 		bytes = IOPTE_SIZE; | 
 | 693 | 		if (*iopte & IOPTE_LARGE) { | 
 | 694 | 			nent *= 16; | 
 | 695 | 			/* rewind to the 1st entry */ | 
| Hiroshi DOYU | c127c7d | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 696 | 			iopte = iopte_offset(iopgd, (da & IOLARGE_MASK)); | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 697 | 		} | 
 | 698 | 		bytes *= nent; | 
 | 699 | 		memset(iopte, 0, nent * sizeof(*iopte)); | 
 | 700 | 		flush_iopte_range(iopte, iopte + (nent - 1) * sizeof(*iopte)); | 
 | 701 |  | 
 | 702 | 		/* | 
 | 703 | 		 * do table walk to check if this table is necessary or not | 
 | 704 | 		 */ | 
 | 705 | 		iopte = iopte_offset(iopgd, 0); | 
 | 706 | 		for (i = 0; i < PTRS_PER_IOPTE; i++) | 
 | 707 | 			if (iopte[i]) | 
 | 708 | 				goto out; | 
 | 709 |  | 
 | 710 | 		iopte_free(iopte); | 
 | 711 | 		nent = 1; /* for the next L1 entry */ | 
 | 712 | 	} else { | 
 | 713 | 		bytes = IOPGD_SIZE; | 
| Hiroshi DOYU | dcc730d | 2009-10-22 14:46:32 -0700 | [diff] [blame] | 714 | 		if ((*iopgd & IOPGD_SUPER) == IOPGD_SUPER) { | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 715 | 			nent *= 16; | 
 | 716 | 			/* rewind to the 1st entry */ | 
| Hiroshi DOYU | 8d33ea5 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 717 | 			iopgd = iopgd_offset(obj, (da & IOSUPER_MASK)); | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 718 | 		} | 
 | 719 | 		bytes *= nent; | 
 | 720 | 	} | 
 | 721 | 	memset(iopgd, 0, nent * sizeof(*iopgd)); | 
 | 722 | 	flush_iopgd_range(iopgd, iopgd + (nent - 1) * sizeof(*iopgd)); | 
 | 723 | out: | 
 | 724 | 	return bytes; | 
 | 725 | } | 
 | 726 |  | 
 | 727 | /** | 
 | 728 |  * iopgtable_clear_entry - Remove an iommu pte entry | 
 | 729 |  * @obj:	target iommu | 
 | 730 |  * @da:		iommu device virtual address | 
 | 731 |  **/ | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 732 | static size_t iopgtable_clear_entry(struct omap_iommu *obj, u32 da) | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 733 | { | 
 | 734 | 	size_t bytes; | 
 | 735 |  | 
 | 736 | 	spin_lock(&obj->page_table_lock); | 
 | 737 |  | 
 | 738 | 	bytes = iopgtable_clear_entry_core(obj, da); | 
 | 739 | 	flush_iotlb_page(obj, da); | 
 | 740 |  | 
 | 741 | 	spin_unlock(&obj->page_table_lock); | 
 | 742 |  | 
 | 743 | 	return bytes; | 
 | 744 | } | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 745 |  | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 746 | static void iopgtable_clear_entry_all(struct omap_iommu *obj) | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 747 | { | 
 | 748 | 	int i; | 
 | 749 |  | 
 | 750 | 	spin_lock(&obj->page_table_lock); | 
 | 751 |  | 
 | 752 | 	for (i = 0; i < PTRS_PER_IOPGD; i++) { | 
 | 753 | 		u32 da; | 
 | 754 | 		u32 *iopgd; | 
 | 755 |  | 
 | 756 | 		da = i << IOPGD_SHIFT; | 
 | 757 | 		iopgd = iopgd_offset(obj, da); | 
 | 758 |  | 
 | 759 | 		if (!*iopgd) | 
 | 760 | 			continue; | 
 | 761 |  | 
| Hiroshi DOYU | a1a5445 | 2010-05-13 09:45:35 +0300 | [diff] [blame] | 762 | 		if (iopgd_is_table(*iopgd)) | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 763 | 			iopte_free(iopte_offset(iopgd, 0)); | 
 | 764 |  | 
 | 765 | 		*iopgd = 0; | 
 | 766 | 		flush_iopgd_range(iopgd, iopgd); | 
 | 767 | 	} | 
 | 768 |  | 
 | 769 | 	flush_iotlb_all(obj); | 
 | 770 |  | 
 | 771 | 	spin_unlock(&obj->page_table_lock); | 
 | 772 | } | 
 | 773 |  | 
 | 774 | /* | 
 | 775 |  *	Device IOMMU generic operations | 
 | 776 |  */ | 
 | 777 | static irqreturn_t iommu_fault_handler(int irq, void *data) | 
 | 778 | { | 
| David Cohen | d594f1f | 2011-02-16 19:35:51 +0000 | [diff] [blame] | 779 | 	u32 da, errs; | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 780 | 	u32 *iopgd, *iopte; | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 781 | 	struct omap_iommu *obj = data; | 
| Ohad Ben-Cohen | e7f10f0 | 2011-09-13 15:26:29 -0400 | [diff] [blame] | 782 | 	struct iommu_domain *domain = obj->domain; | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 783 |  | 
 | 784 | 	if (!obj->refcount) | 
 | 785 | 		return IRQ_NONE; | 
 | 786 |  | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 787 | 	clk_enable(obj->clk); | 
| David Cohen | d594f1f | 2011-02-16 19:35:51 +0000 | [diff] [blame] | 788 | 	errs = iommu_report_fault(obj, &da); | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 789 | 	clk_disable(obj->clk); | 
| Laurent Pinchart | c56b2dd | 2011-05-10 16:56:46 +0200 | [diff] [blame] | 790 | 	if (errs == 0) | 
 | 791 | 		return IRQ_HANDLED; | 
| David Cohen | d594f1f | 2011-02-16 19:35:51 +0000 | [diff] [blame] | 792 |  | 
 | 793 | 	/* Fault callback or TLB/PTE Dynamic loading */ | 
| Ohad Ben-Cohen | e7f10f0 | 2011-09-13 15:26:29 -0400 | [diff] [blame] | 794 | 	if (!report_iommu_fault(domain, obj->dev, da, 0)) | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 795 | 		return IRQ_HANDLED; | 
 | 796 |  | 
| Hiroshi DOYU | 37b2981 | 2010-05-24 02:01:52 +0000 | [diff] [blame] | 797 | 	iommu_disable(obj); | 
 | 798 |  | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 799 | 	iopgd = iopgd_offset(obj, da); | 
 | 800 |  | 
| Hiroshi DOYU | a1a5445 | 2010-05-13 09:45:35 +0300 | [diff] [blame] | 801 | 	if (!iopgd_is_table(*iopgd)) { | 
| David Cohen | d594f1f | 2011-02-16 19:35:51 +0000 | [diff] [blame] | 802 | 		dev_err(obj->dev, "%s: errs:0x%08x da:0x%08x pgd:0x%p " | 
 | 803 | 			"*pgd:px%08x\n", obj->name, errs, da, iopgd, *iopgd); | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 804 | 		return IRQ_NONE; | 
 | 805 | 	} | 
 | 806 |  | 
 | 807 | 	iopte = iopte_offset(iopgd, da); | 
 | 808 |  | 
| David Cohen | d594f1f | 2011-02-16 19:35:51 +0000 | [diff] [blame] | 809 | 	dev_err(obj->dev, "%s: errs:0x%08x da:0x%08x pgd:0x%p *pgd:0x%08x " | 
 | 810 | 		"pte:0x%p *pte:0x%08x\n", obj->name, errs, da, iopgd, *iopgd, | 
 | 811 | 		iopte, *iopte); | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 812 |  | 
 | 813 | 	return IRQ_NONE; | 
 | 814 | } | 
 | 815 |  | 
 | 816 | static int device_match_by_alias(struct device *dev, void *data) | 
 | 817 | { | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 818 | 	struct omap_iommu *obj = to_iommu(dev); | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 819 | 	const char *name = data; | 
 | 820 |  | 
 | 821 | 	pr_debug("%s: %s %s\n", __func__, obj->name, name); | 
 | 822 |  | 
 | 823 | 	return strcmp(obj->name, name) == 0; | 
 | 824 | } | 
 | 825 |  | 
 | 826 | /** | 
| Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 827 |  * omap_iommu_attach() - attach iommu device to an iommu domain | 
| Ohad Ben-Cohen | fabdbca | 2011-10-11 00:18:33 +0200 | [diff] [blame^] | 828 |  * @name:	name of target omap iommu device | 
| Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 829 |  * @iopgd:	page table | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 830 |  **/ | 
| Ohad Ben-Cohen | fabdbca | 2011-10-11 00:18:33 +0200 | [diff] [blame^] | 831 | static struct omap_iommu *omap_iommu_attach(const char *name, u32 *iopgd) | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 832 | { | 
 | 833 | 	int err = -ENOMEM; | 
| Ohad Ben-Cohen | fabdbca | 2011-10-11 00:18:33 +0200 | [diff] [blame^] | 834 | 	struct device *dev; | 
 | 835 | 	struct omap_iommu *obj; | 
 | 836 |  | 
 | 837 | 	dev = driver_find_device(&omap_iommu_driver.driver, NULL, | 
 | 838 | 				(void *)name, | 
 | 839 | 				device_match_by_alias); | 
 | 840 | 	if (!dev) | 
 | 841 | 		return NULL; | 
 | 842 |  | 
 | 843 | 	obj = to_iommu(dev); | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 844 |  | 
| Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 845 | 	spin_lock(&obj->iommu_lock); | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 846 |  | 
| Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 847 | 	/* an iommu device can only be attached once */ | 
 | 848 | 	if (++obj->refcount > 1) { | 
 | 849 | 		dev_err(dev, "%s: already attached!\n", obj->name); | 
 | 850 | 		err = -EBUSY; | 
 | 851 | 		goto err_enable; | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 852 | 	} | 
 | 853 |  | 
| Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 854 | 	obj->iopgd = iopgd; | 
 | 855 | 	err = iommu_enable(obj); | 
 | 856 | 	if (err) | 
 | 857 | 		goto err_enable; | 
 | 858 | 	flush_iotlb_all(obj); | 
 | 859 |  | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 860 | 	if (!try_module_get(obj->owner)) | 
 | 861 | 		goto err_module; | 
 | 862 |  | 
| Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 863 | 	spin_unlock(&obj->iommu_lock); | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 864 |  | 
 | 865 | 	dev_dbg(obj->dev, "%s: %s\n", __func__, obj->name); | 
 | 866 | 	return obj; | 
 | 867 |  | 
 | 868 | err_module: | 
 | 869 | 	if (obj->refcount == 1) | 
 | 870 | 		iommu_disable(obj); | 
 | 871 | err_enable: | 
 | 872 | 	obj->refcount--; | 
| Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 873 | 	spin_unlock(&obj->iommu_lock); | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 874 | 	return ERR_PTR(err); | 
 | 875 | } | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 876 |  | 
 | 877 | /** | 
| Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 878 |  * omap_iommu_detach - release iommu device | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 879 |  * @obj:	target iommu | 
 | 880 |  **/ | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 881 | static void omap_iommu_detach(struct omap_iommu *obj) | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 882 | { | 
| Roel Kluin | acf9d46 | 2010-01-08 10:29:05 -0800 | [diff] [blame] | 883 | 	if (!obj || IS_ERR(obj)) | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 884 | 		return; | 
 | 885 |  | 
| Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 886 | 	spin_lock(&obj->iommu_lock); | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 887 |  | 
 | 888 | 	if (--obj->refcount == 0) | 
 | 889 | 		iommu_disable(obj); | 
 | 890 |  | 
 | 891 | 	module_put(obj->owner); | 
 | 892 |  | 
| Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 893 | 	obj->iopgd = NULL; | 
 | 894 |  | 
 | 895 | 	spin_unlock(&obj->iommu_lock); | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 896 |  | 
 | 897 | 	dev_dbg(obj->dev, "%s: %s\n", __func__, obj->name); | 
 | 898 | } | 
| David Cohen | d594f1f | 2011-02-16 19:35:51 +0000 | [diff] [blame] | 899 |  | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 900 | /* | 
 | 901 |  *	OMAP Device MMU(IOMMU) detection | 
 | 902 |  */ | 
 | 903 | static int __devinit omap_iommu_probe(struct platform_device *pdev) | 
 | 904 | { | 
 | 905 | 	int err = -ENODEV; | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 906 | 	int irq; | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 907 | 	struct omap_iommu *obj; | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 908 | 	struct resource *res; | 
 | 909 | 	struct iommu_platform_data *pdata = pdev->dev.platform_data; | 
 | 910 |  | 
 | 911 | 	if (pdev->num_resources != 2) | 
 | 912 | 		return -EINVAL; | 
 | 913 |  | 
 | 914 | 	obj = kzalloc(sizeof(*obj) + MMU_REG_SIZE, GFP_KERNEL); | 
 | 915 | 	if (!obj) | 
 | 916 | 		return -ENOMEM; | 
 | 917 |  | 
 | 918 | 	obj->clk = clk_get(&pdev->dev, pdata->clk_name); | 
 | 919 | 	if (IS_ERR(obj->clk)) | 
 | 920 | 		goto err_clk; | 
 | 921 |  | 
 | 922 | 	obj->nr_tlb_entries = pdata->nr_tlb_entries; | 
 | 923 | 	obj->name = pdata->name; | 
 | 924 | 	obj->dev = &pdev->dev; | 
 | 925 | 	obj->ctx = (void *)obj + sizeof(*obj); | 
| Guzman Lugo, Fernando | c7f4ab2 | 2010-12-15 00:54:03 +0000 | [diff] [blame] | 926 | 	obj->da_start = pdata->da_start; | 
 | 927 | 	obj->da_end = pdata->da_end; | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 928 |  | 
| Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 929 | 	spin_lock_init(&obj->iommu_lock); | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 930 | 	mutex_init(&obj->mmap_lock); | 
 | 931 | 	spin_lock_init(&obj->page_table_lock); | 
 | 932 | 	INIT_LIST_HEAD(&obj->mmap); | 
 | 933 |  | 
 | 934 | 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 
 | 935 | 	if (!res) { | 
 | 936 | 		err = -ENODEV; | 
 | 937 | 		goto err_mem; | 
 | 938 | 	} | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 939 |  | 
 | 940 | 	res = request_mem_region(res->start, resource_size(res), | 
 | 941 | 				 dev_name(&pdev->dev)); | 
 | 942 | 	if (!res) { | 
 | 943 | 		err = -EIO; | 
 | 944 | 		goto err_mem; | 
 | 945 | 	} | 
 | 946 |  | 
| Aaro Koskinen | da4a0f7 | 2011-03-14 12:28:32 +0000 | [diff] [blame] | 947 | 	obj->regbase = ioremap(res->start, resource_size(res)); | 
 | 948 | 	if (!obj->regbase) { | 
 | 949 | 		err = -ENOMEM; | 
 | 950 | 		goto err_ioremap; | 
 | 951 | 	} | 
 | 952 |  | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 953 | 	irq = platform_get_irq(pdev, 0); | 
 | 954 | 	if (irq < 0) { | 
 | 955 | 		err = -ENODEV; | 
 | 956 | 		goto err_irq; | 
 | 957 | 	} | 
 | 958 | 	err = request_irq(irq, iommu_fault_handler, IRQF_SHARED, | 
 | 959 | 			  dev_name(&pdev->dev), obj); | 
 | 960 | 	if (err < 0) | 
 | 961 | 		goto err_irq; | 
 | 962 | 	platform_set_drvdata(pdev, obj); | 
 | 963 |  | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 964 | 	dev_info(&pdev->dev, "%s registered\n", obj->name); | 
 | 965 | 	return 0; | 
 | 966 |  | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 967 | err_irq: | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 968 | 	iounmap(obj->regbase); | 
| Aaro Koskinen | da4a0f7 | 2011-03-14 12:28:32 +0000 | [diff] [blame] | 969 | err_ioremap: | 
 | 970 | 	release_mem_region(res->start, resource_size(res)); | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 971 | err_mem: | 
 | 972 | 	clk_put(obj->clk); | 
 | 973 | err_clk: | 
 | 974 | 	kfree(obj); | 
 | 975 | 	return err; | 
 | 976 | } | 
 | 977 |  | 
 | 978 | static int __devexit omap_iommu_remove(struct platform_device *pdev) | 
 | 979 | { | 
 | 980 | 	int irq; | 
 | 981 | 	struct resource *res; | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 982 | 	struct omap_iommu *obj = platform_get_drvdata(pdev); | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 983 |  | 
 | 984 | 	platform_set_drvdata(pdev, NULL); | 
 | 985 |  | 
 | 986 | 	iopgtable_clear_entry_all(obj); | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 987 |  | 
 | 988 | 	irq = platform_get_irq(pdev, 0); | 
 | 989 | 	free_irq(irq, obj); | 
 | 990 | 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 
 | 991 | 	release_mem_region(res->start, resource_size(res)); | 
 | 992 | 	iounmap(obj->regbase); | 
 | 993 |  | 
 | 994 | 	clk_put(obj->clk); | 
 | 995 | 	dev_info(&pdev->dev, "%s removed\n", obj->name); | 
 | 996 | 	kfree(obj); | 
 | 997 | 	return 0; | 
 | 998 | } | 
 | 999 |  | 
 | 1000 | static struct platform_driver omap_iommu_driver = { | 
 | 1001 | 	.probe	= omap_iommu_probe, | 
 | 1002 | 	.remove	= __devexit_p(omap_iommu_remove), | 
 | 1003 | 	.driver	= { | 
 | 1004 | 		.name	= "omap-iommu", | 
 | 1005 | 	}, | 
 | 1006 | }; | 
 | 1007 |  | 
 | 1008 | static void iopte_cachep_ctor(void *iopte) | 
 | 1009 | { | 
 | 1010 | 	clean_dcache_area(iopte, IOPTE_TABLE_SIZE); | 
 | 1011 | } | 
 | 1012 |  | 
| Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1013 | static int omap_iommu_map(struct iommu_domain *domain, unsigned long da, | 
 | 1014 | 			 phys_addr_t pa, int order, int prot) | 
 | 1015 | { | 
 | 1016 | 	struct omap_iommu_domain *omap_domain = domain->priv; | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 1017 | 	struct omap_iommu *oiommu = omap_domain->iommu_dev; | 
| Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1018 | 	struct device *dev = oiommu->dev; | 
 | 1019 | 	size_t bytes = PAGE_SIZE << order; | 
 | 1020 | 	struct iotlb_entry e; | 
 | 1021 | 	int omap_pgsz; | 
 | 1022 | 	u32 ret, flags; | 
 | 1023 |  | 
 | 1024 | 	/* we only support mapping a single iommu page for now */ | 
 | 1025 | 	omap_pgsz = bytes_to_iopgsz(bytes); | 
 | 1026 | 	if (omap_pgsz < 0) { | 
 | 1027 | 		dev_err(dev, "invalid size to map: %d\n", bytes); | 
 | 1028 | 		return -EINVAL; | 
 | 1029 | 	} | 
 | 1030 |  | 
 | 1031 | 	dev_dbg(dev, "mapping da 0x%lx to pa 0x%x size 0x%x\n", da, pa, bytes); | 
 | 1032 |  | 
 | 1033 | 	flags = omap_pgsz | prot; | 
 | 1034 |  | 
 | 1035 | 	iotlb_init_entry(&e, da, pa, flags); | 
 | 1036 |  | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 1037 | 	ret = omap_iopgtable_store_entry(oiommu, &e); | 
| Ohad Ben-Cohen | b4550d4 | 2011-09-02 13:32:31 -0400 | [diff] [blame] | 1038 | 	if (ret) | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 1039 | 		dev_err(dev, "omap_iopgtable_store_entry failed: %d\n", ret); | 
| Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1040 |  | 
| Ohad Ben-Cohen | b4550d4 | 2011-09-02 13:32:31 -0400 | [diff] [blame] | 1041 | 	return ret; | 
| Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1042 | } | 
 | 1043 |  | 
 | 1044 | static int omap_iommu_unmap(struct iommu_domain *domain, unsigned long da, | 
 | 1045 | 			    int order) | 
 | 1046 | { | 
 | 1047 | 	struct omap_iommu_domain *omap_domain = domain->priv; | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 1048 | 	struct omap_iommu *oiommu = omap_domain->iommu_dev; | 
| Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1049 | 	struct device *dev = oiommu->dev; | 
| Ohad Ben-Cohen | 5e1b612 | 2011-09-02 13:32:33 -0400 | [diff] [blame] | 1050 | 	size_t unmap_size; | 
| Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1051 |  | 
| Ohad Ben-Cohen | 5e1b612 | 2011-09-02 13:32:33 -0400 | [diff] [blame] | 1052 | 	dev_dbg(dev, "unmapping da 0x%lx order %d\n", da, order); | 
| Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1053 |  | 
| Ohad Ben-Cohen | 5e1b612 | 2011-09-02 13:32:33 -0400 | [diff] [blame] | 1054 | 	unmap_size = iopgtable_clear_entry(oiommu, da); | 
| Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1055 |  | 
| Ohad Ben-Cohen | 5e1b612 | 2011-09-02 13:32:33 -0400 | [diff] [blame] | 1056 | 	return unmap_size ? get_order(unmap_size) : -EINVAL; | 
| Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1057 | } | 
 | 1058 |  | 
 | 1059 | static int | 
 | 1060 | omap_iommu_attach_dev(struct iommu_domain *domain, struct device *dev) | 
 | 1061 | { | 
 | 1062 | 	struct omap_iommu_domain *omap_domain = domain->priv; | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 1063 | 	struct omap_iommu *oiommu; | 
| Ohad Ben-Cohen | fabdbca | 2011-10-11 00:18:33 +0200 | [diff] [blame^] | 1064 | 	struct omap_iommu_arch_data *arch_data = dev->archdata.iommu; | 
| Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1065 | 	int ret = 0; | 
 | 1066 |  | 
 | 1067 | 	spin_lock(&omap_domain->lock); | 
 | 1068 |  | 
 | 1069 | 	/* only a single device is supported per domain for now */ | 
 | 1070 | 	if (omap_domain->iommu_dev) { | 
 | 1071 | 		dev_err(dev, "iommu domain is already attached\n"); | 
 | 1072 | 		ret = -EBUSY; | 
 | 1073 | 		goto out; | 
 | 1074 | 	} | 
 | 1075 |  | 
 | 1076 | 	/* get a handle to and enable the omap iommu */ | 
| Ohad Ben-Cohen | fabdbca | 2011-10-11 00:18:33 +0200 | [diff] [blame^] | 1077 | 	oiommu = omap_iommu_attach(arch_data->name, omap_domain->pgtable); | 
| Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1078 | 	if (IS_ERR(oiommu)) { | 
 | 1079 | 		ret = PTR_ERR(oiommu); | 
 | 1080 | 		dev_err(dev, "can't get omap iommu: %d\n", ret); | 
 | 1081 | 		goto out; | 
 | 1082 | 	} | 
 | 1083 |  | 
| Ohad Ben-Cohen | fabdbca | 2011-10-11 00:18:33 +0200 | [diff] [blame^] | 1084 | 	omap_domain->iommu_dev = arch_data->iommu_dev = oiommu; | 
| Ohad Ben-Cohen | e7f10f0 | 2011-09-13 15:26:29 -0400 | [diff] [blame] | 1085 | 	oiommu->domain = domain; | 
| Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1086 |  | 
 | 1087 | out: | 
 | 1088 | 	spin_unlock(&omap_domain->lock); | 
 | 1089 | 	return ret; | 
 | 1090 | } | 
 | 1091 |  | 
 | 1092 | static void omap_iommu_detach_dev(struct iommu_domain *domain, | 
 | 1093 | 				 struct device *dev) | 
 | 1094 | { | 
 | 1095 | 	struct omap_iommu_domain *omap_domain = domain->priv; | 
| Ohad Ben-Cohen | fabdbca | 2011-10-11 00:18:33 +0200 | [diff] [blame^] | 1096 | 	struct omap_iommu_arch_data *arch_data = dev->archdata.iommu; | 
 | 1097 | 	struct omap_iommu *oiommu = dev_to_omap_iommu(dev); | 
| Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1098 |  | 
 | 1099 | 	spin_lock(&omap_domain->lock); | 
 | 1100 |  | 
 | 1101 | 	/* only a single device is supported per domain for now */ | 
 | 1102 | 	if (omap_domain->iommu_dev != oiommu) { | 
 | 1103 | 		dev_err(dev, "invalid iommu device\n"); | 
 | 1104 | 		goto out; | 
 | 1105 | 	} | 
 | 1106 |  | 
 | 1107 | 	iopgtable_clear_entry_all(oiommu); | 
 | 1108 |  | 
 | 1109 | 	omap_iommu_detach(oiommu); | 
 | 1110 |  | 
| Ohad Ben-Cohen | fabdbca | 2011-10-11 00:18:33 +0200 | [diff] [blame^] | 1111 | 	omap_domain->iommu_dev = arch_data->iommu_dev = NULL; | 
| Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1112 |  | 
 | 1113 | out: | 
 | 1114 | 	spin_unlock(&omap_domain->lock); | 
 | 1115 | } | 
 | 1116 |  | 
 | 1117 | static int omap_iommu_domain_init(struct iommu_domain *domain) | 
 | 1118 | { | 
 | 1119 | 	struct omap_iommu_domain *omap_domain; | 
 | 1120 |  | 
 | 1121 | 	omap_domain = kzalloc(sizeof(*omap_domain), GFP_KERNEL); | 
 | 1122 | 	if (!omap_domain) { | 
 | 1123 | 		pr_err("kzalloc failed\n"); | 
 | 1124 | 		goto out; | 
 | 1125 | 	} | 
 | 1126 |  | 
 | 1127 | 	omap_domain->pgtable = kzalloc(IOPGD_TABLE_SIZE, GFP_KERNEL); | 
 | 1128 | 	if (!omap_domain->pgtable) { | 
 | 1129 | 		pr_err("kzalloc failed\n"); | 
 | 1130 | 		goto fail_nomem; | 
 | 1131 | 	} | 
 | 1132 |  | 
 | 1133 | 	/* | 
 | 1134 | 	 * should never fail, but please keep this around to ensure | 
 | 1135 | 	 * we keep the hardware happy | 
 | 1136 | 	 */ | 
 | 1137 | 	BUG_ON(!IS_ALIGNED((long)omap_domain->pgtable, IOPGD_TABLE_SIZE)); | 
 | 1138 |  | 
 | 1139 | 	clean_dcache_area(omap_domain->pgtable, IOPGD_TABLE_SIZE); | 
 | 1140 | 	spin_lock_init(&omap_domain->lock); | 
 | 1141 |  | 
 | 1142 | 	domain->priv = omap_domain; | 
 | 1143 |  | 
 | 1144 | 	return 0; | 
 | 1145 |  | 
 | 1146 | fail_nomem: | 
 | 1147 | 	kfree(omap_domain); | 
 | 1148 | out: | 
 | 1149 | 	return -ENOMEM; | 
 | 1150 | } | 
 | 1151 |  | 
 | 1152 | /* assume device was already detached */ | 
 | 1153 | static void omap_iommu_domain_destroy(struct iommu_domain *domain) | 
 | 1154 | { | 
 | 1155 | 	struct omap_iommu_domain *omap_domain = domain->priv; | 
 | 1156 |  | 
 | 1157 | 	domain->priv = NULL; | 
 | 1158 |  | 
 | 1159 | 	kfree(omap_domain->pgtable); | 
 | 1160 | 	kfree(omap_domain); | 
 | 1161 | } | 
 | 1162 |  | 
 | 1163 | static phys_addr_t omap_iommu_iova_to_phys(struct iommu_domain *domain, | 
 | 1164 | 					  unsigned long da) | 
 | 1165 | { | 
 | 1166 | 	struct omap_iommu_domain *omap_domain = domain->priv; | 
| Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 1167 | 	struct omap_iommu *oiommu = omap_domain->iommu_dev; | 
| Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1168 | 	struct device *dev = oiommu->dev; | 
 | 1169 | 	u32 *pgd, *pte; | 
 | 1170 | 	phys_addr_t ret = 0; | 
 | 1171 |  | 
 | 1172 | 	iopgtable_lookup_entry(oiommu, da, &pgd, &pte); | 
 | 1173 |  | 
 | 1174 | 	if (pte) { | 
 | 1175 | 		if (iopte_is_small(*pte)) | 
 | 1176 | 			ret = omap_iommu_translate(*pte, da, IOPTE_MASK); | 
 | 1177 | 		else if (iopte_is_large(*pte)) | 
 | 1178 | 			ret = omap_iommu_translate(*pte, da, IOLARGE_MASK); | 
 | 1179 | 		else | 
 | 1180 | 			dev_err(dev, "bogus pte 0x%x", *pte); | 
 | 1181 | 	} else { | 
 | 1182 | 		if (iopgd_is_section(*pgd)) | 
 | 1183 | 			ret = omap_iommu_translate(*pgd, da, IOSECTION_MASK); | 
 | 1184 | 		else if (iopgd_is_super(*pgd)) | 
 | 1185 | 			ret = omap_iommu_translate(*pgd, da, IOSUPER_MASK); | 
 | 1186 | 		else | 
 | 1187 | 			dev_err(dev, "bogus pgd 0x%x", *pgd); | 
 | 1188 | 	} | 
 | 1189 |  | 
 | 1190 | 	return ret; | 
 | 1191 | } | 
 | 1192 |  | 
 | 1193 | static int omap_iommu_domain_has_cap(struct iommu_domain *domain, | 
 | 1194 | 				    unsigned long cap) | 
 | 1195 | { | 
 | 1196 | 	return 0; | 
 | 1197 | } | 
 | 1198 |  | 
 | 1199 | static struct iommu_ops omap_iommu_ops = { | 
 | 1200 | 	.domain_init	= omap_iommu_domain_init, | 
 | 1201 | 	.domain_destroy	= omap_iommu_domain_destroy, | 
 | 1202 | 	.attach_dev	= omap_iommu_attach_dev, | 
 | 1203 | 	.detach_dev	= omap_iommu_detach_dev, | 
 | 1204 | 	.map		= omap_iommu_map, | 
 | 1205 | 	.unmap		= omap_iommu_unmap, | 
 | 1206 | 	.iova_to_phys	= omap_iommu_iova_to_phys, | 
 | 1207 | 	.domain_has_cap	= omap_iommu_domain_has_cap, | 
 | 1208 | }; | 
 | 1209 |  | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 1210 | static int __init omap_iommu_init(void) | 
 | 1211 | { | 
 | 1212 | 	struct kmem_cache *p; | 
 | 1213 | 	const unsigned long flags = SLAB_HWCACHE_ALIGN; | 
 | 1214 | 	size_t align = 1 << 10; /* L2 pagetable alignement */ | 
 | 1215 |  | 
 | 1216 | 	p = kmem_cache_create("iopte_cache", IOPTE_TABLE_SIZE, align, flags, | 
 | 1217 | 			      iopte_cachep_ctor); | 
 | 1218 | 	if (!p) | 
 | 1219 | 		return -ENOMEM; | 
 | 1220 | 	iopte_cachep = p; | 
 | 1221 |  | 
| Joerg Roedel | a65bc64 | 2011-09-06 17:56:07 +0200 | [diff] [blame] | 1222 | 	bus_set_iommu(&platform_bus_type, &omap_iommu_ops); | 
| Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1223 |  | 
| Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 1224 | 	return platform_driver_register(&omap_iommu_driver); | 
 | 1225 | } | 
 | 1226 | module_init(omap_iommu_init); | 
 | 1227 |  | 
 | 1228 | static void __exit omap_iommu_exit(void) | 
 | 1229 | { | 
 | 1230 | 	kmem_cache_destroy(iopte_cachep); | 
 | 1231 |  | 
 | 1232 | 	platform_driver_unregister(&omap_iommu_driver); | 
 | 1233 | } | 
 | 1234 | module_exit(omap_iommu_exit); | 
 | 1235 |  | 
 | 1236 | MODULE_DESCRIPTION("omap iommu: tlb and pagetable primitives"); | 
 | 1237 | MODULE_ALIAS("platform:omap-iommu"); | 
 | 1238 | MODULE_AUTHOR("Hiroshi DOYU, Paul Mundt and Toshihiro Kobayashi"); | 
 | 1239 | MODULE_LICENSE("GPL v2"); |