omap-iovmm.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  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. #include <linux/err.h>
  13. #include <linux/slab.h>
  14. #include <linux/vmalloc.h>
  15. #include <linux/device.h>
  16. #include <linux/scatterlist.h>
  17. #include <linux/iommu.h>
  18. #include <asm/cacheflush.h>
  19. #include <asm/mach/map.h>
  20. #include <plat/iommu.h>
  21. #include <plat/iovmm.h>
  22. #include <plat/iopgtable.h>
  23. static struct kmem_cache *iovm_area_cachep;
  24. /* return the offset of the first scatterlist entry in a sg table */
  25. static unsigned int sgtable_offset(const struct sg_table *sgt)
  26. {
  27. if (!sgt || !sgt->nents)
  28. return 0;
  29. return sgt->sgl->offset;
  30. }
  31. /* return total bytes of sg buffers */
  32. static size_t sgtable_len(const struct sg_table *sgt)
  33. {
  34. unsigned int i, total = 0;
  35. struct scatterlist *sg;
  36. if (!sgt)
  37. return 0;
  38. for_each_sg(sgt->sgl, sg, sgt->nents, i) {
  39. size_t bytes;
  40. bytes = sg->length + sg->offset;
  41. if (!iopgsz_ok(bytes)) {
  42. pr_err("%s: sg[%d] not iommu pagesize(%u %u)\n",
  43. __func__, i, bytes, sg->offset);
  44. return 0;
  45. }
  46. if (i && sg->offset) {
  47. pr_err("%s: sg[%d] offset not allowed in internal "
  48. "entries\n", __func__, i);
  49. return 0;
  50. }
  51. total += bytes;
  52. }
  53. return total;
  54. }
  55. #define sgtable_ok(x) (!!sgtable_len(x))
  56. static unsigned max_alignment(u32 addr)
  57. {
  58. int i;
  59. unsigned pagesize[] = { SZ_16M, SZ_1M, SZ_64K, SZ_4K, };
  60. for (i = 0; i < ARRAY_SIZE(pagesize) && addr & (pagesize[i] - 1); i++)
  61. ;
  62. return (i < ARRAY_SIZE(pagesize)) ? pagesize[i] : 0;
  63. }
  64. /*
  65. * calculate the optimal number sg elements from total bytes based on
  66. * iommu superpages
  67. */
  68. static unsigned sgtable_nents(size_t bytes, u32 da, u32 pa)
  69. {
  70. unsigned nr_entries = 0, ent_sz;
  71. if (!IS_ALIGNED(bytes, PAGE_SIZE)) {
  72. pr_err("%s: wrong size %08x\n", __func__, bytes);
  73. return 0;
  74. }
  75. while (bytes) {
  76. ent_sz = max_alignment(da | pa);
  77. ent_sz = min_t(unsigned, ent_sz, iopgsz_max(bytes));
  78. nr_entries++;
  79. da += ent_sz;
  80. pa += ent_sz;
  81. bytes -= ent_sz;
  82. }
  83. return nr_entries;
  84. }
  85. /* allocate and initialize sg_table header(a kind of 'superblock') */
  86. static struct sg_table *sgtable_alloc(const size_t bytes, u32 flags,
  87. u32 da, u32 pa)
  88. {
  89. unsigned int nr_entries;
  90. int err;
  91. struct sg_table *sgt;
  92. if (!bytes)
  93. return ERR_PTR(-EINVAL);
  94. if (!IS_ALIGNED(bytes, PAGE_SIZE))
  95. return ERR_PTR(-EINVAL);
  96. if (flags & IOVMF_LINEAR) {
  97. nr_entries = sgtable_nents(bytes, da, pa);
  98. if (!nr_entries)
  99. return ERR_PTR(-EINVAL);
  100. } else
  101. nr_entries = bytes / PAGE_SIZE;
  102. sgt = kzalloc(sizeof(*sgt), GFP_KERNEL);
  103. if (!sgt)
  104. return ERR_PTR(-ENOMEM);
  105. err = sg_alloc_table(sgt, nr_entries, GFP_KERNEL);
  106. if (err) {
  107. kfree(sgt);
  108. return ERR_PTR(err);
  109. }
  110. pr_debug("%s: sgt:%p(%d entries)\n", __func__, sgt, nr_entries);
  111. return sgt;
  112. }
  113. /* free sg_table header(a kind of superblock) */
  114. static void sgtable_free(struct sg_table *sgt)
  115. {
  116. if (!sgt)
  117. return;
  118. sg_free_table(sgt);
  119. kfree(sgt);
  120. pr_debug("%s: sgt:%p\n", __func__, sgt);
  121. }
  122. /* map 'sglist' to a contiguous mpu virtual area and return 'va' */
  123. static void *vmap_sg(const struct sg_table *sgt)
  124. {
  125. u32 va;
  126. size_t total;
  127. unsigned int i;
  128. struct scatterlist *sg;
  129. struct vm_struct *new;
  130. const struct mem_type *mtype;
  131. mtype = get_mem_type(MT_DEVICE);
  132. if (!mtype)
  133. return ERR_PTR(-EINVAL);
  134. total = sgtable_len(sgt);
  135. if (!total)
  136. return ERR_PTR(-EINVAL);
  137. new = __get_vm_area(total, VM_IOREMAP, VMALLOC_START, VMALLOC_END);
  138. if (!new)
  139. return ERR_PTR(-ENOMEM);
  140. va = (u32)new->addr;
  141. for_each_sg(sgt->sgl, sg, sgt->nents, i) {
  142. size_t bytes;
  143. u32 pa;
  144. int err;
  145. pa = sg_phys(sg) - sg->offset;
  146. bytes = sg->length + sg->offset;
  147. BUG_ON(bytes != PAGE_SIZE);
  148. err = ioremap_page(va, pa, mtype);
  149. if (err)
  150. goto err_out;
  151. va += bytes;
  152. }
  153. flush_cache_vmap((unsigned long)new->addr,
  154. (unsigned long)(new->addr + total));
  155. return new->addr;
  156. err_out:
  157. WARN_ON(1); /* FIXME: cleanup some mpu mappings */
  158. vunmap(new->addr);
  159. return ERR_PTR(-EAGAIN);
  160. }
  161. static inline void vunmap_sg(const void *va)
  162. {
  163. vunmap(va);
  164. }
  165. static struct iovm_struct *__find_iovm_area(struct omap_iommu *obj,
  166. const u32 da)
  167. {
  168. struct iovm_struct *tmp;
  169. list_for_each_entry(tmp, &obj->mmap, list) {
  170. if ((da >= tmp->da_start) && (da < tmp->da_end)) {
  171. size_t len;
  172. len = tmp->da_end - tmp->da_start;
  173. dev_dbg(obj->dev, "%s: %08x-%08x-%08x(%x) %08x\n",
  174. __func__, tmp->da_start, da, tmp->da_end, len,
  175. tmp->flags);
  176. return tmp;
  177. }
  178. }
  179. return NULL;
  180. }
  181. /**
  182. * omap_find_iovm_area - find iovma which includes @da
  183. * @da: iommu device virtual address
  184. *
  185. * Find the existing iovma starting at @da
  186. */
  187. struct iovm_struct *omap_find_iovm_area(struct omap_iommu *obj, u32 da)
  188. {
  189. struct iovm_struct *area;
  190. mutex_lock(&obj->mmap_lock);
  191. area = __find_iovm_area(obj, da);
  192. mutex_unlock(&obj->mmap_lock);
  193. return area;
  194. }
  195. EXPORT_SYMBOL_GPL(omap_find_iovm_area);
  196. /*
  197. * This finds the hole(area) which fits the requested address and len
  198. * in iovmas mmap, and returns the new allocated iovma.
  199. */
  200. static struct iovm_struct *alloc_iovm_area(struct omap_iommu *obj, u32 da,
  201. size_t bytes, u32 flags)
  202. {
  203. struct iovm_struct *new, *tmp;
  204. u32 start, prev_end, alignment;
  205. if (!obj || !bytes)
  206. return ERR_PTR(-EINVAL);
  207. start = da;
  208. alignment = PAGE_SIZE;
  209. if (~flags & IOVMF_DA_FIXED) {
  210. /* Don't map address 0 */
  211. start = obj->da_start ? obj->da_start : alignment;
  212. if (flags & IOVMF_LINEAR)
  213. alignment = iopgsz_max(bytes);
  214. start = roundup(start, alignment);
  215. } else if (start < obj->da_start || start > obj->da_end ||
  216. obj->da_end - start < bytes) {
  217. return ERR_PTR(-EINVAL);
  218. }
  219. tmp = NULL;
  220. if (list_empty(&obj->mmap))
  221. goto found;
  222. prev_end = 0;
  223. list_for_each_entry(tmp, &obj->mmap, list) {
  224. if (prev_end > start)
  225. break;
  226. if (tmp->da_start > start && (tmp->da_start - start) >= bytes)
  227. goto found;
  228. if (tmp->da_end >= start && ~flags & IOVMF_DA_FIXED)
  229. start = roundup(tmp->da_end + 1, alignment);
  230. prev_end = tmp->da_end;
  231. }
  232. if ((start >= prev_end) && (obj->da_end - start >= bytes))
  233. goto found;
  234. dev_dbg(obj->dev, "%s: no space to fit %08x(%x) flags: %08x\n",
  235. __func__, da, bytes, flags);
  236. return ERR_PTR(-EINVAL);
  237. found:
  238. new = kmem_cache_zalloc(iovm_area_cachep, GFP_KERNEL);
  239. if (!new)
  240. return ERR_PTR(-ENOMEM);
  241. new->iommu = obj;
  242. new->da_start = start;
  243. new->da_end = start + bytes;
  244. new->flags = flags;
  245. /*
  246. * keep ascending order of iovmas
  247. */
  248. if (tmp)
  249. list_add_tail(&new->list, &tmp->list);
  250. else
  251. list_add(&new->list, &obj->mmap);
  252. dev_dbg(obj->dev, "%s: found %08x-%08x-%08x(%x) %08x\n",
  253. __func__, new->da_start, start, new->da_end, bytes, flags);
  254. return new;
  255. }
  256. static void free_iovm_area(struct omap_iommu *obj, struct iovm_struct *area)
  257. {
  258. size_t bytes;
  259. BUG_ON(!obj || !area);
  260. bytes = area->da_end - area->da_start;
  261. dev_dbg(obj->dev, "%s: %08x-%08x(%x) %08x\n",
  262. __func__, area->da_start, area->da_end, bytes, area->flags);
  263. list_del(&area->list);
  264. kmem_cache_free(iovm_area_cachep, area);
  265. }
  266. /**
  267. * omap_da_to_va - convert (d) to (v)
  268. * @obj: objective iommu
  269. * @da: iommu device virtual address
  270. * @va: mpu virtual address
  271. *
  272. * Returns mpu virtual addr which corresponds to a given device virtual addr
  273. */
  274. void *omap_da_to_va(struct omap_iommu *obj, u32 da)
  275. {
  276. void *va = NULL;
  277. struct iovm_struct *area;
  278. mutex_lock(&obj->mmap_lock);
  279. area = __find_iovm_area(obj, da);
  280. if (!area) {
  281. dev_dbg(obj->dev, "%s: no da area(%08x)\n", __func__, da);
  282. goto out;
  283. }
  284. va = area->va;
  285. out:
  286. mutex_unlock(&obj->mmap_lock);
  287. return va;
  288. }
  289. EXPORT_SYMBOL_GPL(omap_da_to_va);
  290. static void sgtable_fill_vmalloc(struct sg_table *sgt, void *_va)
  291. {
  292. unsigned int i;
  293. struct scatterlist *sg;
  294. void *va = _va;
  295. void *va_end;
  296. for_each_sg(sgt->sgl, sg, sgt->nents, i) {
  297. struct page *pg;
  298. const size_t bytes = PAGE_SIZE;
  299. /*
  300. * iommu 'superpage' isn't supported with 'omap_iommu_vmalloc()'
  301. */
  302. pg = vmalloc_to_page(va);
  303. BUG_ON(!pg);
  304. sg_set_page(sg, pg, bytes, 0);
  305. va += bytes;
  306. }
  307. va_end = _va + PAGE_SIZE * i;
  308. }
  309. static inline void sgtable_drain_vmalloc(struct sg_table *sgt)
  310. {
  311. /*
  312. * Actually this is not necessary at all, just exists for
  313. * consistency of the code readability.
  314. */
  315. BUG_ON(!sgt);
  316. }
  317. /* create 'da' <-> 'pa' mapping from 'sgt' */
  318. static int map_iovm_area(struct iommu_domain *domain, struct iovm_struct *new,
  319. const struct sg_table *sgt, u32 flags)
  320. {
  321. int err;
  322. unsigned int i, j;
  323. struct scatterlist *sg;
  324. u32 da = new->da_start;
  325. int order;
  326. if (!domain || !sgt)
  327. return -EINVAL;
  328. BUG_ON(!sgtable_ok(sgt));
  329. for_each_sg(sgt->sgl, sg, sgt->nents, i) {
  330. u32 pa;
  331. size_t bytes;
  332. pa = sg_phys(sg) - sg->offset;
  333. bytes = sg->length + sg->offset;
  334. flags &= ~IOVMF_PGSZ_MASK;
  335. if (bytes_to_iopgsz(bytes) < 0)
  336. goto err_out;
  337. order = get_order(bytes);
  338. pr_debug("%s: [%d] %08x %08x(%x)\n", __func__,
  339. i, da, pa, bytes);
  340. err = iommu_map(domain, da, pa, order, flags);
  341. if (err)
  342. goto err_out;
  343. da += bytes;
  344. }
  345. return 0;
  346. err_out:
  347. da = new->da_start;
  348. for_each_sg(sgt->sgl, sg, i, j) {
  349. size_t bytes;
  350. bytes = sg->length + sg->offset;
  351. order = get_order(bytes);
  352. /* ignore failures.. we're already handling one */
  353. iommu_unmap(domain, da, order);
  354. da += bytes;
  355. }
  356. return err;
  357. }
  358. /* release 'da' <-> 'pa' mapping */
  359. static void unmap_iovm_area(struct iommu_domain *domain, struct omap_iommu *obj,
  360. struct iovm_struct *area)
  361. {
  362. u32 start;
  363. size_t total = area->da_end - area->da_start;
  364. const struct sg_table *sgt = area->sgt;
  365. struct scatterlist *sg;
  366. int i, err;
  367. BUG_ON(!sgtable_ok(sgt));
  368. BUG_ON((!total) || !IS_ALIGNED(total, PAGE_SIZE));
  369. start = area->da_start;
  370. for_each_sg(sgt->sgl, sg, sgt->nents, i) {
  371. size_t bytes;
  372. int order;
  373. bytes = sg->length + sg->offset;
  374. order = get_order(bytes);
  375. err = iommu_unmap(domain, start, order);
  376. if (err < 0)
  377. break;
  378. dev_dbg(obj->dev, "%s: unmap %08x(%x) %08x\n",
  379. __func__, start, bytes, area->flags);
  380. BUG_ON(!IS_ALIGNED(bytes, PAGE_SIZE));
  381. total -= bytes;
  382. start += bytes;
  383. }
  384. BUG_ON(total);
  385. }
  386. /* template function for all unmapping */
  387. static struct sg_table *unmap_vm_area(struct iommu_domain *domain,
  388. struct omap_iommu *obj, const u32 da,
  389. void (*fn)(const void *), u32 flags)
  390. {
  391. struct sg_table *sgt = NULL;
  392. struct iovm_struct *area;
  393. if (!IS_ALIGNED(da, PAGE_SIZE)) {
  394. dev_err(obj->dev, "%s: alignment err(%08x)\n", __func__, da);
  395. return NULL;
  396. }
  397. mutex_lock(&obj->mmap_lock);
  398. area = __find_iovm_area(obj, da);
  399. if (!area) {
  400. dev_dbg(obj->dev, "%s: no da area(%08x)\n", __func__, da);
  401. goto out;
  402. }
  403. if ((area->flags & flags) != flags) {
  404. dev_err(obj->dev, "%s: wrong flags(%08x)\n", __func__,
  405. area->flags);
  406. goto out;
  407. }
  408. sgt = (struct sg_table *)area->sgt;
  409. unmap_iovm_area(domain, obj, area);
  410. fn(area->va);
  411. dev_dbg(obj->dev, "%s: %08x-%08x-%08x(%x) %08x\n", __func__,
  412. area->da_start, da, area->da_end,
  413. area->da_end - area->da_start, area->flags);
  414. free_iovm_area(obj, area);
  415. out:
  416. mutex_unlock(&obj->mmap_lock);
  417. return sgt;
  418. }
  419. static u32 map_iommu_region(struct iommu_domain *domain, struct omap_iommu *obj,
  420. u32 da, const struct sg_table *sgt, void *va,
  421. size_t bytes, u32 flags)
  422. {
  423. int err = -ENOMEM;
  424. struct iovm_struct *new;
  425. mutex_lock(&obj->mmap_lock);
  426. new = alloc_iovm_area(obj, da, bytes, flags);
  427. if (IS_ERR(new)) {
  428. err = PTR_ERR(new);
  429. goto err_alloc_iovma;
  430. }
  431. new->va = va;
  432. new->sgt = sgt;
  433. if (map_iovm_area(domain, new, sgt, new->flags))
  434. goto err_map;
  435. mutex_unlock(&obj->mmap_lock);
  436. dev_dbg(obj->dev, "%s: da:%08x(%x) flags:%08x va:%p\n",
  437. __func__, new->da_start, bytes, new->flags, va);
  438. return new->da_start;
  439. err_map:
  440. free_iovm_area(obj, new);
  441. err_alloc_iovma:
  442. mutex_unlock(&obj->mmap_lock);
  443. return err;
  444. }
  445. static inline u32
  446. __iommu_vmap(struct iommu_domain *domain, struct omap_iommu *obj,
  447. u32 da, const struct sg_table *sgt,
  448. void *va, size_t bytes, u32 flags)
  449. {
  450. return map_iommu_region(domain, obj, da, sgt, va, bytes, flags);
  451. }
  452. /**
  453. * omap_iommu_vmap - (d)-(p)-(v) address mapper
  454. * @obj: objective iommu
  455. * @sgt: address of scatter gather table
  456. * @flags: iovma and page property
  457. *
  458. * Creates 1-n-1 mapping with given @sgt and returns @da.
  459. * All @sgt element must be io page size aligned.
  460. */
  461. u32 omap_iommu_vmap(struct iommu_domain *domain, struct omap_iommu *obj, u32 da,
  462. const struct sg_table *sgt, u32 flags)
  463. {
  464. size_t bytes;
  465. void *va = NULL;
  466. if (!obj || !obj->dev || !sgt)
  467. return -EINVAL;
  468. bytes = sgtable_len(sgt);
  469. if (!bytes)
  470. return -EINVAL;
  471. bytes = PAGE_ALIGN(bytes);
  472. if (flags & IOVMF_MMIO) {
  473. va = vmap_sg(sgt);
  474. if (IS_ERR(va))
  475. return PTR_ERR(va);
  476. }
  477. flags |= IOVMF_DISCONT;
  478. flags |= IOVMF_MMIO;
  479. da = __iommu_vmap(domain, obj, da, sgt, va, bytes, flags);
  480. if (IS_ERR_VALUE(da))
  481. vunmap_sg(va);
  482. return da + sgtable_offset(sgt);
  483. }
  484. EXPORT_SYMBOL_GPL(omap_iommu_vmap);
  485. /**
  486. * omap_iommu_vunmap - release virtual mapping obtained by 'omap_iommu_vmap()'
  487. * @obj: objective iommu
  488. * @da: iommu device virtual address
  489. *
  490. * Free the iommu virtually contiguous memory area starting at
  491. * @da, which was returned by 'omap_iommu_vmap()'.
  492. */
  493. struct sg_table *
  494. omap_iommu_vunmap(struct iommu_domain *domain, struct omap_iommu *obj, u32 da)
  495. {
  496. struct sg_table *sgt;
  497. /*
  498. * 'sgt' is allocated before 'omap_iommu_vmalloc()' is called.
  499. * Just returns 'sgt' to the caller to free
  500. */
  501. da &= PAGE_MASK;
  502. sgt = unmap_vm_area(domain, obj, da, vunmap_sg,
  503. IOVMF_DISCONT | IOVMF_MMIO);
  504. if (!sgt)
  505. dev_dbg(obj->dev, "%s: No sgt\n", __func__);
  506. return sgt;
  507. }
  508. EXPORT_SYMBOL_GPL(omap_iommu_vunmap);
  509. /**
  510. * omap_iommu_vmalloc - (d)-(p)-(v) address allocator and mapper
  511. * @obj: objective iommu
  512. * @da: contiguous iommu virtual memory
  513. * @bytes: allocation size
  514. * @flags: iovma and page property
  515. *
  516. * Allocate @bytes linearly and creates 1-n-1 mapping and returns
  517. * @da again, which might be adjusted if 'IOVMF_DA_FIXED' is not set.
  518. */
  519. u32
  520. omap_iommu_vmalloc(struct iommu_domain *domain, struct omap_iommu *obj, u32 da,
  521. size_t bytes, u32 flags)
  522. {
  523. void *va;
  524. struct sg_table *sgt;
  525. if (!obj || !obj->dev || !bytes)
  526. return -EINVAL;
  527. bytes = PAGE_ALIGN(bytes);
  528. va = vmalloc(bytes);
  529. if (!va)
  530. return -ENOMEM;
  531. flags |= IOVMF_DISCONT;
  532. flags |= IOVMF_ALLOC;
  533. sgt = sgtable_alloc(bytes, flags, da, 0);
  534. if (IS_ERR(sgt)) {
  535. da = PTR_ERR(sgt);
  536. goto err_sgt_alloc;
  537. }
  538. sgtable_fill_vmalloc(sgt, va);
  539. da = __iommu_vmap(domain, obj, da, sgt, va, bytes, flags);
  540. if (IS_ERR_VALUE(da))
  541. goto err_iommu_vmap;
  542. return da;
  543. err_iommu_vmap:
  544. sgtable_drain_vmalloc(sgt);
  545. sgtable_free(sgt);
  546. err_sgt_alloc:
  547. vfree(va);
  548. return da;
  549. }
  550. EXPORT_SYMBOL_GPL(omap_iommu_vmalloc);
  551. /**
  552. * omap_iommu_vfree - release memory allocated by 'omap_iommu_vmalloc()'
  553. * @obj: objective iommu
  554. * @da: iommu device virtual address
  555. *
  556. * Frees the iommu virtually continuous memory area starting at
  557. * @da, as obtained from 'omap_iommu_vmalloc()'.
  558. */
  559. void omap_iommu_vfree(struct iommu_domain *domain, struct omap_iommu *obj,
  560. const u32 da)
  561. {
  562. struct sg_table *sgt;
  563. sgt = unmap_vm_area(domain, obj, da, vfree,
  564. IOVMF_DISCONT | IOVMF_ALLOC);
  565. if (!sgt)
  566. dev_dbg(obj->dev, "%s: No sgt\n", __func__);
  567. sgtable_free(sgt);
  568. }
  569. EXPORT_SYMBOL_GPL(omap_iommu_vfree);
  570. static int __init iovmm_init(void)
  571. {
  572. const unsigned long flags = SLAB_HWCACHE_ALIGN;
  573. struct kmem_cache *p;
  574. p = kmem_cache_create("iovm_area_cache", sizeof(struct iovm_struct), 0,
  575. flags, NULL);
  576. if (!p)
  577. return -ENOMEM;
  578. iovm_area_cachep = p;
  579. return 0;
  580. }
  581. module_init(iovmm_init);
  582. static void __exit iovmm_exit(void)
  583. {
  584. kmem_cache_destroy(iovm_area_cachep);
  585. }
  586. module_exit(iovmm_exit);
  587. MODULE_DESCRIPTION("omap iommu: simple virtual address space management");
  588. MODULE_AUTHOR("Hiroshi DOYU <Hiroshi.DOYU@nokia.com>");
  589. MODULE_LICENSE("GPL v2");