Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 1 | /* |
| 2 | * omap iommu: simple virtual address space management |
| 3 | * |
| 4 | * Copyright (C) 2008-2009 Nokia Corporation |
| 5 | * |
| 6 | * Written by Hiroshi DOYU <Hiroshi.DOYU@nokia.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/err.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 14 | #include <linux/slab.h> |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 15 | #include <linux/vmalloc.h> |
| 16 | #include <linux/device.h> |
| 17 | #include <linux/scatterlist.h> |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 18 | #include <linux/iommu.h> |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 19 | |
| 20 | #include <asm/cacheflush.h> |
| 21 | #include <asm/mach/map.h> |
| 22 | |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 23 | #include <plat/iommu.h> |
| 24 | #include <plat/iovmm.h> |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 25 | |
Ohad Ben-Cohen | fcf3a6e | 2011-08-15 23:21:41 +0300 | [diff] [blame] | 26 | #include <plat/iopgtable.h> |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 27 | |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 28 | static struct kmem_cache *iovm_area_cachep; |
| 29 | |
| 30 | /* return total bytes of sg buffers */ |
| 31 | static size_t sgtable_len(const struct sg_table *sgt) |
| 32 | { |
| 33 | unsigned int i, total = 0; |
| 34 | struct scatterlist *sg; |
| 35 | |
| 36 | if (!sgt) |
| 37 | return 0; |
| 38 | |
| 39 | for_each_sg(sgt->sgl, sg, sgt->nents, i) { |
| 40 | size_t bytes; |
| 41 | |
Ohad Ben-Cohen | 66cf402 | 2011-06-08 09:06:11 +0300 | [diff] [blame] | 42 | bytes = sg->length; |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 43 | |
| 44 | if (!iopgsz_ok(bytes)) { |
| 45 | pr_err("%s: sg[%d] not iommu pagesize(%x)\n", |
| 46 | __func__, i, bytes); |
| 47 | return 0; |
| 48 | } |
| 49 | |
| 50 | total += bytes; |
| 51 | } |
| 52 | |
| 53 | return total; |
| 54 | } |
| 55 | #define sgtable_ok(x) (!!sgtable_len(x)) |
| 56 | |
Guzman Lugo, Fernando | ad10812 | 2010-12-15 00:54:01 +0000 | [diff] [blame] | 57 | static unsigned max_alignment(u32 addr) |
| 58 | { |
| 59 | int i; |
| 60 | unsigned pagesize[] = { SZ_16M, SZ_1M, SZ_64K, SZ_4K, }; |
| 61 | for (i = 0; i < ARRAY_SIZE(pagesize) && addr & (pagesize[i] - 1); i++) |
| 62 | ; |
| 63 | return (i < ARRAY_SIZE(pagesize)) ? pagesize[i] : 0; |
| 64 | } |
| 65 | |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 66 | /* |
| 67 | * calculate the optimal number sg elements from total bytes based on |
| 68 | * iommu superpages |
| 69 | */ |
Guzman Lugo, Fernando | ad10812 | 2010-12-15 00:54:01 +0000 | [diff] [blame] | 70 | static unsigned sgtable_nents(size_t bytes, u32 da, u32 pa) |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 71 | { |
Guzman Lugo, Fernando | ad10812 | 2010-12-15 00:54:01 +0000 | [diff] [blame] | 72 | unsigned nr_entries = 0, ent_sz; |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 73 | |
| 74 | if (!IS_ALIGNED(bytes, PAGE_SIZE)) { |
| 75 | pr_err("%s: wrong size %08x\n", __func__, bytes); |
| 76 | return 0; |
| 77 | } |
| 78 | |
Guzman Lugo, Fernando | ad10812 | 2010-12-15 00:54:01 +0000 | [diff] [blame] | 79 | while (bytes) { |
| 80 | ent_sz = max_alignment(da | pa); |
| 81 | ent_sz = min_t(unsigned, ent_sz, iopgsz_max(bytes)); |
| 82 | nr_entries++; |
| 83 | da += ent_sz; |
| 84 | pa += ent_sz; |
| 85 | bytes -= ent_sz; |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 86 | } |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 87 | |
| 88 | return nr_entries; |
| 89 | } |
| 90 | |
| 91 | /* allocate and initialize sg_table header(a kind of 'superblock') */ |
Guzman Lugo, Fernando | ad10812 | 2010-12-15 00:54:01 +0000 | [diff] [blame] | 92 | static struct sg_table *sgtable_alloc(const size_t bytes, u32 flags, |
| 93 | u32 da, u32 pa) |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 94 | { |
| 95 | unsigned int nr_entries; |
| 96 | int err; |
| 97 | struct sg_table *sgt; |
| 98 | |
| 99 | if (!bytes) |
| 100 | return ERR_PTR(-EINVAL); |
| 101 | |
| 102 | if (!IS_ALIGNED(bytes, PAGE_SIZE)) |
| 103 | return ERR_PTR(-EINVAL); |
| 104 | |
Guzman Lugo, Fernando | ad10812 | 2010-12-15 00:54:01 +0000 | [diff] [blame] | 105 | if (flags & IOVMF_LINEAR) { |
| 106 | nr_entries = sgtable_nents(bytes, da, pa); |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 107 | if (!nr_entries) |
| 108 | return ERR_PTR(-EINVAL); |
| 109 | } else |
| 110 | nr_entries = bytes / PAGE_SIZE; |
| 111 | |
| 112 | sgt = kzalloc(sizeof(*sgt), GFP_KERNEL); |
| 113 | if (!sgt) |
| 114 | return ERR_PTR(-ENOMEM); |
| 115 | |
| 116 | err = sg_alloc_table(sgt, nr_entries, GFP_KERNEL); |
Satish | 7f1225b | 2010-06-09 13:21:27 +0300 | [diff] [blame] | 117 | if (err) { |
| 118 | kfree(sgt); |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 119 | return ERR_PTR(err); |
Satish | 7f1225b | 2010-06-09 13:21:27 +0300 | [diff] [blame] | 120 | } |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 121 | |
| 122 | pr_debug("%s: sgt:%p(%d entries)\n", __func__, sgt, nr_entries); |
| 123 | |
| 124 | return sgt; |
| 125 | } |
| 126 | |
| 127 | /* free sg_table header(a kind of superblock) */ |
| 128 | static void sgtable_free(struct sg_table *sgt) |
| 129 | { |
| 130 | if (!sgt) |
| 131 | return; |
| 132 | |
| 133 | sg_free_table(sgt); |
| 134 | kfree(sgt); |
| 135 | |
| 136 | pr_debug("%s: sgt:%p\n", __func__, sgt); |
| 137 | } |
| 138 | |
| 139 | /* map 'sglist' to a contiguous mpu virtual area and return 'va' */ |
| 140 | static void *vmap_sg(const struct sg_table *sgt) |
| 141 | { |
| 142 | u32 va; |
| 143 | size_t total; |
| 144 | unsigned int i; |
| 145 | struct scatterlist *sg; |
| 146 | struct vm_struct *new; |
| 147 | const struct mem_type *mtype; |
| 148 | |
| 149 | mtype = get_mem_type(MT_DEVICE); |
| 150 | if (!mtype) |
| 151 | return ERR_PTR(-EINVAL); |
| 152 | |
| 153 | total = sgtable_len(sgt); |
| 154 | if (!total) |
| 155 | return ERR_PTR(-EINVAL); |
| 156 | |
| 157 | new = __get_vm_area(total, VM_IOREMAP, VMALLOC_START, VMALLOC_END); |
| 158 | if (!new) |
| 159 | return ERR_PTR(-ENOMEM); |
| 160 | va = (u32)new->addr; |
| 161 | |
| 162 | for_each_sg(sgt->sgl, sg, sgt->nents, i) { |
| 163 | size_t bytes; |
| 164 | u32 pa; |
| 165 | int err; |
| 166 | |
| 167 | pa = sg_phys(sg); |
Ohad Ben-Cohen | 66cf402 | 2011-06-08 09:06:11 +0300 | [diff] [blame] | 168 | bytes = sg->length; |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 169 | |
| 170 | BUG_ON(bytes != PAGE_SIZE); |
| 171 | |
| 172 | err = ioremap_page(va, pa, mtype); |
| 173 | if (err) |
| 174 | goto err_out; |
| 175 | |
| 176 | va += bytes; |
| 177 | } |
| 178 | |
Sanjeev Premi | 6716bd0 | 2009-09-24 16:23:12 -0700 | [diff] [blame] | 179 | flush_cache_vmap((unsigned long)new->addr, |
| 180 | (unsigned long)(new->addr + total)); |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 181 | return new->addr; |
| 182 | |
| 183 | err_out: |
| 184 | WARN_ON(1); /* FIXME: cleanup some mpu mappings */ |
| 185 | vunmap(new->addr); |
| 186 | return ERR_PTR(-EAGAIN); |
| 187 | } |
| 188 | |
| 189 | static inline void vunmap_sg(const void *va) |
| 190 | { |
| 191 | vunmap(va); |
| 192 | } |
| 193 | |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame^] | 194 | static struct iovm_struct *__find_iovm_area(struct omap_iommu *obj, |
| 195 | const u32 da) |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 196 | { |
| 197 | struct iovm_struct *tmp; |
| 198 | |
| 199 | list_for_each_entry(tmp, &obj->mmap, list) { |
| 200 | if ((da >= tmp->da_start) && (da < tmp->da_end)) { |
| 201 | size_t len; |
| 202 | |
| 203 | len = tmp->da_end - tmp->da_start; |
| 204 | |
| 205 | dev_dbg(obj->dev, "%s: %08x-%08x-%08x(%x) %08x\n", |
| 206 | __func__, tmp->da_start, da, tmp->da_end, len, |
| 207 | tmp->flags); |
| 208 | |
| 209 | return tmp; |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | return NULL; |
| 214 | } |
| 215 | |
| 216 | /** |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame^] | 217 | * omap_find_iovm_area - find iovma which includes @da |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 218 | * @da: iommu device virtual address |
| 219 | * |
| 220 | * Find the existing iovma starting at @da |
| 221 | */ |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame^] | 222 | struct iovm_struct *omap_find_iovm_area(struct omap_iommu *obj, u32 da) |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 223 | { |
| 224 | struct iovm_struct *area; |
| 225 | |
| 226 | mutex_lock(&obj->mmap_lock); |
| 227 | area = __find_iovm_area(obj, da); |
| 228 | mutex_unlock(&obj->mmap_lock); |
| 229 | |
| 230 | return area; |
| 231 | } |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame^] | 232 | EXPORT_SYMBOL_GPL(omap_find_iovm_area); |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 233 | |
| 234 | /* |
| 235 | * This finds the hole(area) which fits the requested address and len |
| 236 | * in iovmas mmap, and returns the new allocated iovma. |
| 237 | */ |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame^] | 238 | static struct iovm_struct *alloc_iovm_area(struct omap_iommu *obj, u32 da, |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 239 | size_t bytes, u32 flags) |
| 240 | { |
| 241 | struct iovm_struct *new, *tmp; |
Michael Jones | 4359d38 | 2011-03-09 09:17:32 +0000 | [diff] [blame] | 242 | u32 start, prev_end, alignment; |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 243 | |
| 244 | if (!obj || !bytes) |
| 245 | return ERR_PTR(-EINVAL); |
| 246 | |
| 247 | start = da; |
Michael Jones | 4359d38 | 2011-03-09 09:17:32 +0000 | [diff] [blame] | 248 | alignment = PAGE_SIZE; |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 249 | |
David Cohen | d038aee | 2011-03-09 09:17:33 +0000 | [diff] [blame] | 250 | if (~flags & IOVMF_DA_FIXED) { |
Michael Jones | 4359d38 | 2011-03-09 09:17:32 +0000 | [diff] [blame] | 251 | /* Don't map address 0 */ |
| 252 | start = obj->da_start ? obj->da_start : alignment; |
Guzman Lugo, Fernando | c7f4ab2 | 2010-12-15 00:54:03 +0000 | [diff] [blame] | 253 | |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 254 | if (flags & IOVMF_LINEAR) |
Michael Jones | 4359d38 | 2011-03-09 09:17:32 +0000 | [diff] [blame] | 255 | alignment = iopgsz_max(bytes); |
| 256 | start = roundup(start, alignment); |
Guzman Lugo, Fernando | c7f4ab2 | 2010-12-15 00:54:03 +0000 | [diff] [blame] | 257 | } else if (start < obj->da_start || start > obj->da_end || |
| 258 | obj->da_end - start < bytes) { |
| 259 | return ERR_PTR(-EINVAL); |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | tmp = NULL; |
| 263 | if (list_empty(&obj->mmap)) |
| 264 | goto found; |
| 265 | |
| 266 | prev_end = 0; |
| 267 | list_for_each_entry(tmp, &obj->mmap, list) { |
| 268 | |
Guzman Lugo, Fernando | ba6e1f4 | 2010-12-15 00:54:00 +0000 | [diff] [blame] | 269 | if (prev_end > start) |
Hiroshi DOYU | e0a42e4 | 2010-05-06 17:09:25 +0300 | [diff] [blame] | 270 | break; |
| 271 | |
Guzman Lugo, Fernando | c7f4ab2 | 2010-12-15 00:54:03 +0000 | [diff] [blame] | 272 | if (tmp->da_start > start && (tmp->da_start - start) >= bytes) |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 273 | goto found; |
| 274 | |
David Cohen | d038aee | 2011-03-09 09:17:33 +0000 | [diff] [blame] | 275 | if (tmp->da_end >= start && ~flags & IOVMF_DA_FIXED) |
Michael Jones | 4359d38 | 2011-03-09 09:17:32 +0000 | [diff] [blame] | 276 | start = roundup(tmp->da_end + 1, alignment); |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 277 | |
| 278 | prev_end = tmp->da_end; |
| 279 | } |
| 280 | |
Guzman Lugo, Fernando | c7f4ab2 | 2010-12-15 00:54:03 +0000 | [diff] [blame] | 281 | if ((start >= prev_end) && (obj->da_end - start >= bytes)) |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 282 | goto found; |
| 283 | |
| 284 | dev_dbg(obj->dev, "%s: no space to fit %08x(%x) flags: %08x\n", |
| 285 | __func__, da, bytes, flags); |
| 286 | |
| 287 | return ERR_PTR(-EINVAL); |
| 288 | |
| 289 | found: |
| 290 | new = kmem_cache_zalloc(iovm_area_cachep, GFP_KERNEL); |
| 291 | if (!new) |
| 292 | return ERR_PTR(-ENOMEM); |
| 293 | |
| 294 | new->iommu = obj; |
| 295 | new->da_start = start; |
| 296 | new->da_end = start + bytes; |
| 297 | new->flags = flags; |
| 298 | |
| 299 | /* |
| 300 | * keep ascending order of iovmas |
| 301 | */ |
| 302 | if (tmp) |
| 303 | list_add_tail(&new->list, &tmp->list); |
| 304 | else |
| 305 | list_add(&new->list, &obj->mmap); |
| 306 | |
| 307 | dev_dbg(obj->dev, "%s: found %08x-%08x-%08x(%x) %08x\n", |
| 308 | __func__, new->da_start, start, new->da_end, bytes, flags); |
| 309 | |
| 310 | return new; |
| 311 | } |
| 312 | |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame^] | 313 | static void free_iovm_area(struct omap_iommu *obj, struct iovm_struct *area) |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 314 | { |
| 315 | size_t bytes; |
| 316 | |
| 317 | BUG_ON(!obj || !area); |
| 318 | |
| 319 | bytes = area->da_end - area->da_start; |
| 320 | |
| 321 | dev_dbg(obj->dev, "%s: %08x-%08x(%x) %08x\n", |
| 322 | __func__, area->da_start, area->da_end, bytes, area->flags); |
| 323 | |
| 324 | list_del(&area->list); |
| 325 | kmem_cache_free(iovm_area_cachep, area); |
| 326 | } |
| 327 | |
| 328 | /** |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame^] | 329 | * omap_da_to_va - convert (d) to (v) |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 330 | * @obj: objective iommu |
| 331 | * @da: iommu device virtual address |
| 332 | * @va: mpu virtual address |
| 333 | * |
| 334 | * Returns mpu virtual addr which corresponds to a given device virtual addr |
| 335 | */ |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame^] | 336 | void *omap_da_to_va(struct omap_iommu *obj, u32 da) |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 337 | { |
| 338 | void *va = NULL; |
| 339 | struct iovm_struct *area; |
| 340 | |
| 341 | mutex_lock(&obj->mmap_lock); |
| 342 | |
| 343 | area = __find_iovm_area(obj, da); |
| 344 | if (!area) { |
| 345 | dev_dbg(obj->dev, "%s: no da area(%08x)\n", __func__, da); |
| 346 | goto out; |
| 347 | } |
| 348 | va = area->va; |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 349 | out: |
Daniel Walker | 2654890 | 2009-10-05 13:31:45 -0700 | [diff] [blame] | 350 | mutex_unlock(&obj->mmap_lock); |
| 351 | |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 352 | return va; |
| 353 | } |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame^] | 354 | EXPORT_SYMBOL_GPL(omap_da_to_va); |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 355 | |
| 356 | static void sgtable_fill_vmalloc(struct sg_table *sgt, void *_va) |
| 357 | { |
| 358 | unsigned int i; |
| 359 | struct scatterlist *sg; |
| 360 | void *va = _va; |
| 361 | void *va_end; |
| 362 | |
| 363 | for_each_sg(sgt->sgl, sg, sgt->nents, i) { |
| 364 | struct page *pg; |
| 365 | const size_t bytes = PAGE_SIZE; |
| 366 | |
| 367 | /* |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame^] | 368 | * iommu 'superpage' isn't supported with 'omap_iommu_vmalloc()' |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 369 | */ |
| 370 | pg = vmalloc_to_page(va); |
| 371 | BUG_ON(!pg); |
| 372 | sg_set_page(sg, pg, bytes, 0); |
| 373 | |
| 374 | va += bytes; |
| 375 | } |
| 376 | |
| 377 | va_end = _va + PAGE_SIZE * i; |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | static inline void sgtable_drain_vmalloc(struct sg_table *sgt) |
| 381 | { |
| 382 | /* |
| 383 | * Actually this is not necessary at all, just exists for |
Hiroshi DOYU | ba6a1179 | 2009-10-05 13:31:45 -0700 | [diff] [blame] | 384 | * consistency of the code readability. |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 385 | */ |
| 386 | BUG_ON(!sgt); |
| 387 | } |
| 388 | |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 389 | /* create 'da' <-> 'pa' mapping from 'sgt' */ |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 390 | static int map_iovm_area(struct iommu_domain *domain, struct iovm_struct *new, |
| 391 | const struct sg_table *sgt, u32 flags) |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 392 | { |
| 393 | int err; |
| 394 | unsigned int i, j; |
| 395 | struct scatterlist *sg; |
| 396 | u32 da = new->da_start; |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 397 | int order; |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 398 | |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 399 | if (!domain || !sgt) |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 400 | return -EINVAL; |
| 401 | |
| 402 | BUG_ON(!sgtable_ok(sgt)); |
| 403 | |
| 404 | for_each_sg(sgt->sgl, sg, sgt->nents, i) { |
| 405 | u32 pa; |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 406 | size_t bytes; |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 407 | |
| 408 | pa = sg_phys(sg); |
Ohad Ben-Cohen | 66cf402 | 2011-06-08 09:06:11 +0300 | [diff] [blame] | 409 | bytes = sg->length; |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 410 | |
| 411 | flags &= ~IOVMF_PGSZ_MASK; |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 412 | |
| 413 | if (bytes_to_iopgsz(bytes) < 0) |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 414 | goto err_out; |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 415 | |
| 416 | order = get_order(bytes); |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 417 | |
| 418 | pr_debug("%s: [%d] %08x %08x(%x)\n", __func__, |
| 419 | i, da, pa, bytes); |
| 420 | |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 421 | err = iommu_map(domain, da, pa, order, flags); |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 422 | if (err) |
| 423 | goto err_out; |
| 424 | |
| 425 | da += bytes; |
| 426 | } |
| 427 | return 0; |
| 428 | |
| 429 | err_out: |
| 430 | da = new->da_start; |
| 431 | |
| 432 | for_each_sg(sgt->sgl, sg, i, j) { |
| 433 | size_t bytes; |
| 434 | |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 435 | bytes = sg->length; |
| 436 | order = get_order(bytes); |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 437 | |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 438 | /* ignore failures.. we're already handling one */ |
| 439 | iommu_unmap(domain, da, order); |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 440 | |
| 441 | da += bytes; |
| 442 | } |
| 443 | return err; |
| 444 | } |
| 445 | |
| 446 | /* release 'da' <-> 'pa' mapping */ |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame^] | 447 | static void unmap_iovm_area(struct iommu_domain *domain, struct omap_iommu *obj, |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 448 | struct iovm_struct *area) |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 449 | { |
| 450 | u32 start; |
| 451 | size_t total = area->da_end - area->da_start; |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 452 | const struct sg_table *sgt = area->sgt; |
| 453 | struct scatterlist *sg; |
| 454 | int i, err; |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 455 | |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 456 | BUG_ON(!sgtable_ok(sgt)); |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 457 | BUG_ON((!total) || !IS_ALIGNED(total, PAGE_SIZE)); |
| 458 | |
| 459 | start = area->da_start; |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 460 | for_each_sg(sgt->sgl, sg, sgt->nents, i) { |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 461 | size_t bytes; |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 462 | int order; |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 463 | |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 464 | bytes = sg->length; |
| 465 | order = get_order(bytes); |
| 466 | |
| 467 | err = iommu_unmap(domain, start, order); |
| 468 | if (err) |
| 469 | break; |
| 470 | |
| 471 | dev_dbg(obj->dev, "%s: unmap %08x(%x) %08x\n", |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 472 | __func__, start, bytes, area->flags); |
| 473 | |
| 474 | BUG_ON(!IS_ALIGNED(bytes, PAGE_SIZE)); |
| 475 | |
| 476 | total -= bytes; |
| 477 | start += bytes; |
| 478 | } |
| 479 | BUG_ON(total); |
| 480 | } |
| 481 | |
| 482 | /* template function for all unmapping */ |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 483 | static struct sg_table *unmap_vm_area(struct iommu_domain *domain, |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame^] | 484 | struct omap_iommu *obj, const u32 da, |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 485 | void (*fn)(const void *), u32 flags) |
| 486 | { |
| 487 | struct sg_table *sgt = NULL; |
| 488 | struct iovm_struct *area; |
| 489 | |
| 490 | if (!IS_ALIGNED(da, PAGE_SIZE)) { |
| 491 | dev_err(obj->dev, "%s: alignment err(%08x)\n", __func__, da); |
| 492 | return NULL; |
| 493 | } |
| 494 | |
| 495 | mutex_lock(&obj->mmap_lock); |
| 496 | |
| 497 | area = __find_iovm_area(obj, da); |
| 498 | if (!area) { |
| 499 | dev_dbg(obj->dev, "%s: no da area(%08x)\n", __func__, da); |
| 500 | goto out; |
| 501 | } |
| 502 | |
| 503 | if ((area->flags & flags) != flags) { |
| 504 | dev_err(obj->dev, "%s: wrong flags(%08x)\n", __func__, |
| 505 | area->flags); |
| 506 | goto out; |
| 507 | } |
| 508 | sgt = (struct sg_table *)area->sgt; |
| 509 | |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 510 | unmap_iovm_area(domain, obj, area); |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 511 | |
| 512 | fn(area->va); |
| 513 | |
| 514 | dev_dbg(obj->dev, "%s: %08x-%08x-%08x(%x) %08x\n", __func__, |
| 515 | area->da_start, da, area->da_end, |
| 516 | area->da_end - area->da_start, area->flags); |
| 517 | |
| 518 | free_iovm_area(obj, area); |
| 519 | out: |
| 520 | mutex_unlock(&obj->mmap_lock); |
| 521 | |
| 522 | return sgt; |
| 523 | } |
| 524 | |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame^] | 525 | static u32 map_iommu_region(struct iommu_domain *domain, struct omap_iommu *obj, |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 526 | u32 da, const struct sg_table *sgt, void *va, |
| 527 | size_t bytes, u32 flags) |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 528 | { |
| 529 | int err = -ENOMEM; |
| 530 | struct iovm_struct *new; |
| 531 | |
| 532 | mutex_lock(&obj->mmap_lock); |
| 533 | |
| 534 | new = alloc_iovm_area(obj, da, bytes, flags); |
| 535 | if (IS_ERR(new)) { |
| 536 | err = PTR_ERR(new); |
| 537 | goto err_alloc_iovma; |
| 538 | } |
| 539 | new->va = va; |
| 540 | new->sgt = sgt; |
| 541 | |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 542 | if (map_iovm_area(domain, new, sgt, new->flags)) |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 543 | goto err_map; |
| 544 | |
| 545 | mutex_unlock(&obj->mmap_lock); |
| 546 | |
| 547 | dev_dbg(obj->dev, "%s: da:%08x(%x) flags:%08x va:%p\n", |
| 548 | __func__, new->da_start, bytes, new->flags, va); |
| 549 | |
| 550 | return new->da_start; |
| 551 | |
| 552 | err_map: |
| 553 | free_iovm_area(obj, new); |
| 554 | err_alloc_iovma: |
| 555 | mutex_unlock(&obj->mmap_lock); |
| 556 | return err; |
| 557 | } |
| 558 | |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame^] | 559 | static inline u32 |
| 560 | __iommu_vmap(struct iommu_domain *domain, struct omap_iommu *obj, |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 561 | u32 da, const struct sg_table *sgt, |
| 562 | void *va, size_t bytes, u32 flags) |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 563 | { |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 564 | return map_iommu_region(domain, obj, da, sgt, va, bytes, flags); |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | /** |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame^] | 568 | * omap_iommu_vmap - (d)-(p)-(v) address mapper |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 569 | * @obj: objective iommu |
| 570 | * @sgt: address of scatter gather table |
| 571 | * @flags: iovma and page property |
| 572 | * |
| 573 | * Creates 1-n-1 mapping with given @sgt and returns @da. |
| 574 | * All @sgt element must be io page size aligned. |
| 575 | */ |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame^] | 576 | u32 omap_iommu_vmap(struct iommu_domain *domain, struct omap_iommu *obj, u32 da, |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 577 | const struct sg_table *sgt, u32 flags) |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 578 | { |
| 579 | size_t bytes; |
Hiroshi DOYU | 935e473 | 2009-11-22 10:11:02 -0800 | [diff] [blame] | 580 | void *va = NULL; |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 581 | |
| 582 | if (!obj || !obj->dev || !sgt) |
| 583 | return -EINVAL; |
| 584 | |
| 585 | bytes = sgtable_len(sgt); |
| 586 | if (!bytes) |
| 587 | return -EINVAL; |
| 588 | bytes = PAGE_ALIGN(bytes); |
| 589 | |
Hiroshi DOYU | 935e473 | 2009-11-22 10:11:02 -0800 | [diff] [blame] | 590 | if (flags & IOVMF_MMIO) { |
| 591 | va = vmap_sg(sgt); |
| 592 | if (IS_ERR(va)) |
| 593 | return PTR_ERR(va); |
| 594 | } |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 595 | |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 596 | flags |= IOVMF_DISCONT; |
| 597 | flags |= IOVMF_MMIO; |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 598 | |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 599 | da = __iommu_vmap(domain, obj, da, sgt, va, bytes, flags); |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 600 | if (IS_ERR_VALUE(da)) |
| 601 | vunmap_sg(va); |
| 602 | |
| 603 | return da; |
| 604 | } |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame^] | 605 | EXPORT_SYMBOL_GPL(omap_iommu_vmap); |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 606 | |
| 607 | /** |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame^] | 608 | * omap_iommu_vunmap - release virtual mapping obtained by 'omap_iommu_vmap()' |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 609 | * @obj: objective iommu |
| 610 | * @da: iommu device virtual address |
| 611 | * |
| 612 | * Free the iommu virtually contiguous memory area starting at |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame^] | 613 | * @da, which was returned by 'omap_iommu_vmap()'. |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 614 | */ |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 615 | struct sg_table * |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame^] | 616 | omap_iommu_vunmap(struct iommu_domain *domain, struct omap_iommu *obj, u32 da) |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 617 | { |
| 618 | struct sg_table *sgt; |
| 619 | /* |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame^] | 620 | * 'sgt' is allocated before 'omap_iommu_vmalloc()' is called. |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 621 | * Just returns 'sgt' to the caller to free |
| 622 | */ |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 623 | sgt = unmap_vm_area(domain, obj, da, vunmap_sg, |
| 624 | IOVMF_DISCONT | IOVMF_MMIO); |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 625 | if (!sgt) |
| 626 | dev_dbg(obj->dev, "%s: No sgt\n", __func__); |
| 627 | return sgt; |
| 628 | } |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame^] | 629 | EXPORT_SYMBOL_GPL(omap_iommu_vunmap); |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 630 | |
| 631 | /** |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame^] | 632 | * omap_iommu_vmalloc - (d)-(p)-(v) address allocator and mapper |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 633 | * @obj: objective iommu |
| 634 | * @da: contiguous iommu virtual memory |
| 635 | * @bytes: allocation size |
| 636 | * @flags: iovma and page property |
| 637 | * |
| 638 | * Allocate @bytes linearly and creates 1-n-1 mapping and returns |
David Cohen | d038aee | 2011-03-09 09:17:33 +0000 | [diff] [blame] | 639 | * @da again, which might be adjusted if 'IOVMF_DA_FIXED' is not set. |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 640 | */ |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame^] | 641 | u32 |
| 642 | omap_iommu_vmalloc(struct iommu_domain *domain, struct omap_iommu *obj, u32 da, |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 643 | size_t bytes, u32 flags) |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 644 | { |
| 645 | void *va; |
| 646 | struct sg_table *sgt; |
| 647 | |
| 648 | if (!obj || !obj->dev || !bytes) |
| 649 | return -EINVAL; |
| 650 | |
| 651 | bytes = PAGE_ALIGN(bytes); |
| 652 | |
| 653 | va = vmalloc(bytes); |
| 654 | if (!va) |
| 655 | return -ENOMEM; |
| 656 | |
Guzman Lugo, Fernando | ad10812 | 2010-12-15 00:54:01 +0000 | [diff] [blame] | 657 | flags |= IOVMF_DISCONT; |
| 658 | flags |= IOVMF_ALLOC; |
Guzman Lugo, Fernando | ad10812 | 2010-12-15 00:54:01 +0000 | [diff] [blame] | 659 | |
| 660 | sgt = sgtable_alloc(bytes, flags, da, 0); |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 661 | if (IS_ERR(sgt)) { |
| 662 | da = PTR_ERR(sgt); |
| 663 | goto err_sgt_alloc; |
| 664 | } |
| 665 | sgtable_fill_vmalloc(sgt, va); |
| 666 | |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 667 | da = __iommu_vmap(domain, obj, da, sgt, va, bytes, flags); |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 668 | if (IS_ERR_VALUE(da)) |
| 669 | goto err_iommu_vmap; |
| 670 | |
| 671 | return da; |
| 672 | |
| 673 | err_iommu_vmap: |
| 674 | sgtable_drain_vmalloc(sgt); |
| 675 | sgtable_free(sgt); |
| 676 | err_sgt_alloc: |
| 677 | vfree(va); |
| 678 | return da; |
| 679 | } |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame^] | 680 | EXPORT_SYMBOL_GPL(omap_iommu_vmalloc); |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 681 | |
| 682 | /** |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame^] | 683 | * omap_iommu_vfree - release memory allocated by 'omap_iommu_vmalloc()' |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 684 | * @obj: objective iommu |
| 685 | * @da: iommu device virtual address |
| 686 | * |
| 687 | * Frees the iommu virtually continuous memory area starting at |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame^] | 688 | * @da, as obtained from 'omap_iommu_vmalloc()'. |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 689 | */ |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame^] | 690 | void omap_iommu_vfree(struct iommu_domain *domain, struct omap_iommu *obj, |
| 691 | const u32 da) |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 692 | { |
| 693 | struct sg_table *sgt; |
| 694 | |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 695 | sgt = unmap_vm_area(domain, obj, da, vfree, |
| 696 | IOVMF_DISCONT | IOVMF_ALLOC); |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 697 | if (!sgt) |
| 698 | dev_dbg(obj->dev, "%s: No sgt\n", __func__); |
| 699 | sgtable_free(sgt); |
| 700 | } |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame^] | 701 | EXPORT_SYMBOL_GPL(omap_iommu_vfree); |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 702 | |
Hiroshi DOYU | 69d3a84 | 2009-01-28 21:32:08 +0200 | [diff] [blame] | 703 | static int __init iovmm_init(void) |
| 704 | { |
| 705 | const unsigned long flags = SLAB_HWCACHE_ALIGN; |
| 706 | struct kmem_cache *p; |
| 707 | |
| 708 | p = kmem_cache_create("iovm_area_cache", sizeof(struct iovm_struct), 0, |
| 709 | flags, NULL); |
| 710 | if (!p) |
| 711 | return -ENOMEM; |
| 712 | iovm_area_cachep = p; |
| 713 | |
| 714 | return 0; |
| 715 | } |
| 716 | module_init(iovmm_init); |
| 717 | |
| 718 | static void __exit iovmm_exit(void) |
| 719 | { |
| 720 | kmem_cache_destroy(iovm_area_cachep); |
| 721 | } |
| 722 | module_exit(iovmm_exit); |
| 723 | |
| 724 | MODULE_DESCRIPTION("omap iommu: simple virtual address space management"); |
| 725 | MODULE_AUTHOR("Hiroshi DOYU <Hiroshi.DOYU@nokia.com>"); |
| 726 | MODULE_LICENSE("GPL v2"); |