iommu.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. /*
  2. * Copyright (C) 2001 Mike Corrigan & Dave Engebretsen, IBM Corporation
  3. *
  4. * Rewrite, cleanup, new allocation schemes, virtual merging:
  5. * Copyright (C) 2004 Olof Johansson, IBM Corporation
  6. * and Ben. Herrenschmidt, IBM Corporation
  7. *
  8. * Dynamic DMA mapping support, bus-independent parts.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. */
  24. #include <linux/init.h>
  25. #include <linux/types.h>
  26. #include <linux/slab.h>
  27. #include <linux/mm.h>
  28. #include <linux/spinlock.h>
  29. #include <linux/string.h>
  30. #include <linux/dma-mapping.h>
  31. #include <linux/bitops.h>
  32. #include <asm/io.h>
  33. #include <asm/prom.h>
  34. #include <asm/iommu.h>
  35. #include <asm/pci-bridge.h>
  36. #include <asm/machdep.h>
  37. #include <asm/kdump.h>
  38. #define DBG(...)
  39. #ifdef CONFIG_IOMMU_VMERGE
  40. static int novmerge = 0;
  41. #else
  42. static int novmerge = 1;
  43. #endif
  44. static int protect4gb = 1;
  45. static inline unsigned long iommu_num_pages(unsigned long vaddr,
  46. unsigned long slen)
  47. {
  48. unsigned long npages;
  49. npages = IOMMU_PAGE_ALIGN(vaddr + slen) - (vaddr & IOMMU_PAGE_MASK);
  50. npages >>= IOMMU_PAGE_SHIFT;
  51. return npages;
  52. }
  53. static int __init setup_protect4gb(char *str)
  54. {
  55. if (strcmp(str, "on") == 0)
  56. protect4gb = 1;
  57. else if (strcmp(str, "off") == 0)
  58. protect4gb = 0;
  59. return 1;
  60. }
  61. static int __init setup_iommu(char *str)
  62. {
  63. if (!strcmp(str, "novmerge"))
  64. novmerge = 1;
  65. else if (!strcmp(str, "vmerge"))
  66. novmerge = 0;
  67. return 1;
  68. }
  69. __setup("protect4gb=", setup_protect4gb);
  70. __setup("iommu=", setup_iommu);
  71. static unsigned long iommu_range_alloc(struct iommu_table *tbl,
  72. unsigned long npages,
  73. unsigned long *handle,
  74. unsigned long mask,
  75. unsigned int align_order)
  76. {
  77. unsigned long n, end, i, start;
  78. unsigned long limit;
  79. int largealloc = npages > 15;
  80. int pass = 0;
  81. unsigned long align_mask;
  82. align_mask = 0xffffffffffffffffl >> (64 - align_order);
  83. /* This allocator was derived from x86_64's bit string search */
  84. /* Sanity check */
  85. if (unlikely(npages == 0)) {
  86. if (printk_ratelimit())
  87. WARN_ON(1);
  88. return DMA_ERROR_CODE;
  89. }
  90. if (handle && *handle)
  91. start = *handle;
  92. else
  93. start = largealloc ? tbl->it_largehint : tbl->it_hint;
  94. /* Use only half of the table for small allocs (15 pages or less) */
  95. limit = largealloc ? tbl->it_size : tbl->it_halfpoint;
  96. if (largealloc && start < tbl->it_halfpoint)
  97. start = tbl->it_halfpoint;
  98. /* The case below can happen if we have a small segment appended
  99. * to a large, or when the previous alloc was at the very end of
  100. * the available space. If so, go back to the initial start.
  101. */
  102. if (start >= limit)
  103. start = largealloc ? tbl->it_largehint : tbl->it_hint;
  104. again:
  105. if (limit + tbl->it_offset > mask) {
  106. limit = mask - tbl->it_offset + 1;
  107. /* If we're constrained on address range, first try
  108. * at the masked hint to avoid O(n) search complexity,
  109. * but on second pass, start at 0.
  110. */
  111. if ((start & mask) >= limit || pass > 0)
  112. start = 0;
  113. else
  114. start &= mask;
  115. }
  116. n = find_next_zero_bit(tbl->it_map, limit, start);
  117. /* Align allocation */
  118. n = (n + align_mask) & ~align_mask;
  119. end = n + npages;
  120. if (unlikely(end >= limit)) {
  121. if (likely(pass < 2)) {
  122. /* First failure, just rescan the half of the table.
  123. * Second failure, rescan the other half of the table.
  124. */
  125. start = (largealloc ^ pass) ? tbl->it_halfpoint : 0;
  126. limit = pass ? tbl->it_size : limit;
  127. pass++;
  128. goto again;
  129. } else {
  130. /* Third failure, give up */
  131. return DMA_ERROR_CODE;
  132. }
  133. }
  134. for (i = n; i < end; i++)
  135. if (test_bit(i, tbl->it_map)) {
  136. start = i+1;
  137. goto again;
  138. }
  139. for (i = n; i < end; i++)
  140. __set_bit(i, tbl->it_map);
  141. /* Bump the hint to a new block for small allocs. */
  142. if (largealloc) {
  143. /* Don't bump to new block to avoid fragmentation */
  144. tbl->it_largehint = end;
  145. } else {
  146. /* Overflow will be taken care of at the next allocation */
  147. tbl->it_hint = (end + tbl->it_blocksize - 1) &
  148. ~(tbl->it_blocksize - 1);
  149. }
  150. /* Update handle for SG allocations */
  151. if (handle)
  152. *handle = end;
  153. return n;
  154. }
  155. static dma_addr_t iommu_alloc(struct iommu_table *tbl, void *page,
  156. unsigned int npages, enum dma_data_direction direction,
  157. unsigned long mask, unsigned int align_order)
  158. {
  159. unsigned long entry, flags;
  160. dma_addr_t ret = DMA_ERROR_CODE;
  161. spin_lock_irqsave(&(tbl->it_lock), flags);
  162. entry = iommu_range_alloc(tbl, npages, NULL, mask, align_order);
  163. if (unlikely(entry == DMA_ERROR_CODE)) {
  164. spin_unlock_irqrestore(&(tbl->it_lock), flags);
  165. return DMA_ERROR_CODE;
  166. }
  167. entry += tbl->it_offset; /* Offset into real TCE table */
  168. ret = entry << IOMMU_PAGE_SHIFT; /* Set the return dma address */
  169. /* Put the TCEs in the HW table */
  170. ppc_md.tce_build(tbl, entry, npages, (unsigned long)page & IOMMU_PAGE_MASK,
  171. direction);
  172. /* Flush/invalidate TLB caches if necessary */
  173. if (ppc_md.tce_flush)
  174. ppc_md.tce_flush(tbl);
  175. spin_unlock_irqrestore(&(tbl->it_lock), flags);
  176. /* Make sure updates are seen by hardware */
  177. mb();
  178. return ret;
  179. }
  180. static void __iommu_free(struct iommu_table *tbl, dma_addr_t dma_addr,
  181. unsigned int npages)
  182. {
  183. unsigned long entry, free_entry;
  184. unsigned long i;
  185. entry = dma_addr >> IOMMU_PAGE_SHIFT;
  186. free_entry = entry - tbl->it_offset;
  187. if (((free_entry + npages) > tbl->it_size) ||
  188. (entry < tbl->it_offset)) {
  189. if (printk_ratelimit()) {
  190. printk(KERN_INFO "iommu_free: invalid entry\n");
  191. printk(KERN_INFO "\tentry = 0x%lx\n", entry);
  192. printk(KERN_INFO "\tdma_addr = 0x%lx\n", (u64)dma_addr);
  193. printk(KERN_INFO "\tTable = 0x%lx\n", (u64)tbl);
  194. printk(KERN_INFO "\tbus# = 0x%lx\n", (u64)tbl->it_busno);
  195. printk(KERN_INFO "\tsize = 0x%lx\n", (u64)tbl->it_size);
  196. printk(KERN_INFO "\tstartOff = 0x%lx\n", (u64)tbl->it_offset);
  197. printk(KERN_INFO "\tindex = 0x%lx\n", (u64)tbl->it_index);
  198. WARN_ON(1);
  199. }
  200. return;
  201. }
  202. ppc_md.tce_free(tbl, entry, npages);
  203. for (i = 0; i < npages; i++)
  204. __clear_bit(free_entry+i, tbl->it_map);
  205. }
  206. static void iommu_free(struct iommu_table *tbl, dma_addr_t dma_addr,
  207. unsigned int npages)
  208. {
  209. unsigned long flags;
  210. spin_lock_irqsave(&(tbl->it_lock), flags);
  211. __iommu_free(tbl, dma_addr, npages);
  212. /* Make sure TLB cache is flushed if the HW needs it. We do
  213. * not do an mb() here on purpose, it is not needed on any of
  214. * the current platforms.
  215. */
  216. if (ppc_md.tce_flush)
  217. ppc_md.tce_flush(tbl);
  218. spin_unlock_irqrestore(&(tbl->it_lock), flags);
  219. }
  220. int iommu_map_sg(struct iommu_table *tbl, struct scatterlist *sglist,
  221. int nelems, unsigned long mask,
  222. enum dma_data_direction direction)
  223. {
  224. dma_addr_t dma_next = 0, dma_addr;
  225. unsigned long flags;
  226. struct scatterlist *s, *outs, *segstart;
  227. int outcount, incount;
  228. unsigned long handle;
  229. BUG_ON(direction == DMA_NONE);
  230. if ((nelems == 0) || !tbl)
  231. return 0;
  232. outs = s = segstart = &sglist[0];
  233. outcount = 1;
  234. incount = nelems;
  235. handle = 0;
  236. /* Init first segment length for backout at failure */
  237. outs->dma_length = 0;
  238. DBG("sg mapping %d elements:\n", nelems);
  239. spin_lock_irqsave(&(tbl->it_lock), flags);
  240. for (s = outs; nelems; nelems--, s++) {
  241. unsigned long vaddr, npages, entry, slen;
  242. slen = s->length;
  243. /* Sanity check */
  244. if (slen == 0) {
  245. dma_next = 0;
  246. continue;
  247. }
  248. /* Allocate iommu entries for that segment */
  249. vaddr = (unsigned long)page_address(s->page) + s->offset;
  250. npages = iommu_num_pages(vaddr, slen);
  251. entry = iommu_range_alloc(tbl, npages, &handle, mask >> IOMMU_PAGE_SHIFT, 0);
  252. DBG(" - vaddr: %lx, size: %lx\n", vaddr, slen);
  253. /* Handle failure */
  254. if (unlikely(entry == DMA_ERROR_CODE)) {
  255. if (printk_ratelimit())
  256. printk(KERN_INFO "iommu_alloc failed, tbl %p vaddr %lx"
  257. " npages %lx\n", tbl, vaddr, npages);
  258. goto failure;
  259. }
  260. /* Convert entry to a dma_addr_t */
  261. entry += tbl->it_offset;
  262. dma_addr = entry << IOMMU_PAGE_SHIFT;
  263. dma_addr |= (s->offset & ~IOMMU_PAGE_MASK);
  264. DBG(" - %lu pages, entry: %lx, dma_addr: %lx\n",
  265. npages, entry, dma_addr);
  266. /* Insert into HW table */
  267. ppc_md.tce_build(tbl, entry, npages, vaddr & IOMMU_PAGE_MASK, direction);
  268. /* If we are in an open segment, try merging */
  269. if (segstart != s) {
  270. DBG(" - trying merge...\n");
  271. /* We cannot merge if:
  272. * - allocated dma_addr isn't contiguous to previous allocation
  273. */
  274. if (novmerge || (dma_addr != dma_next)) {
  275. /* Can't merge: create a new segment */
  276. segstart = s;
  277. outcount++; outs++;
  278. DBG(" can't merge, new segment.\n");
  279. } else {
  280. outs->dma_length += s->length;
  281. DBG(" merged, new len: %ux\n", outs->dma_length);
  282. }
  283. }
  284. if (segstart == s) {
  285. /* This is a new segment, fill entries */
  286. DBG(" - filling new segment.\n");
  287. outs->dma_address = dma_addr;
  288. outs->dma_length = slen;
  289. }
  290. /* Calculate next page pointer for contiguous check */
  291. dma_next = dma_addr + slen;
  292. DBG(" - dma next is: %lx\n", dma_next);
  293. }
  294. /* Flush/invalidate TLB caches if necessary */
  295. if (ppc_md.tce_flush)
  296. ppc_md.tce_flush(tbl);
  297. spin_unlock_irqrestore(&(tbl->it_lock), flags);
  298. DBG("mapped %d elements:\n", outcount);
  299. /* For the sake of iommu_unmap_sg, we clear out the length in the
  300. * next entry of the sglist if we didn't fill the list completely
  301. */
  302. if (outcount < incount) {
  303. outs++;
  304. outs->dma_address = DMA_ERROR_CODE;
  305. outs->dma_length = 0;
  306. }
  307. /* Make sure updates are seen by hardware */
  308. mb();
  309. return outcount;
  310. failure:
  311. for (s = &sglist[0]; s <= outs; s++) {
  312. if (s->dma_length != 0) {
  313. unsigned long vaddr, npages;
  314. vaddr = s->dma_address & IOMMU_PAGE_MASK;
  315. npages = iommu_num_pages(s->dma_address, s->dma_length);
  316. __iommu_free(tbl, vaddr, npages);
  317. s->dma_address = DMA_ERROR_CODE;
  318. s->dma_length = 0;
  319. }
  320. }
  321. spin_unlock_irqrestore(&(tbl->it_lock), flags);
  322. return 0;
  323. }
  324. void iommu_unmap_sg(struct iommu_table *tbl, struct scatterlist *sglist,
  325. int nelems, enum dma_data_direction direction)
  326. {
  327. unsigned long flags;
  328. BUG_ON(direction == DMA_NONE);
  329. if (!tbl)
  330. return;
  331. spin_lock_irqsave(&(tbl->it_lock), flags);
  332. while (nelems--) {
  333. unsigned int npages;
  334. dma_addr_t dma_handle = sglist->dma_address;
  335. if (sglist->dma_length == 0)
  336. break;
  337. npages = iommu_num_pages(dma_handle,sglist->dma_length);
  338. __iommu_free(tbl, dma_handle, npages);
  339. sglist++;
  340. }
  341. /* Flush/invalidate TLBs if necessary. As for iommu_free(), we
  342. * do not do an mb() here, the affected platforms do not need it
  343. * when freeing.
  344. */
  345. if (ppc_md.tce_flush)
  346. ppc_md.tce_flush(tbl);
  347. spin_unlock_irqrestore(&(tbl->it_lock), flags);
  348. }
  349. /*
  350. * Build a iommu_table structure. This contains a bit map which
  351. * is used to manage allocation of the tce space.
  352. */
  353. struct iommu_table *iommu_init_table(struct iommu_table *tbl, int nid)
  354. {
  355. unsigned long sz;
  356. unsigned long start_index, end_index;
  357. unsigned long entries_per_4g;
  358. unsigned long index;
  359. static int welcomed = 0;
  360. struct page *page;
  361. /* Set aside 1/4 of the table for large allocations. */
  362. tbl->it_halfpoint = tbl->it_size * 3 / 4;
  363. /* number of bytes needed for the bitmap */
  364. sz = (tbl->it_size + 7) >> 3;
  365. page = alloc_pages_node(nid, GFP_ATOMIC, get_order(sz));
  366. if (!page)
  367. panic("iommu_init_table: Can't allocate %ld bytes\n", sz);
  368. tbl->it_map = page_address(page);
  369. memset(tbl->it_map, 0, sz);
  370. tbl->it_hint = 0;
  371. tbl->it_largehint = tbl->it_halfpoint;
  372. spin_lock_init(&tbl->it_lock);
  373. #ifdef CONFIG_CRASH_DUMP
  374. if (ppc_md.tce_get) {
  375. unsigned long tceval;
  376. unsigned long tcecount = 0;
  377. /*
  378. * Reserve the existing mappings left by the first kernel.
  379. */
  380. for (index = 0; index < tbl->it_size; index++) {
  381. tceval = ppc_md.tce_get(tbl, index + tbl->it_offset);
  382. /*
  383. * Freed TCE entry contains 0x7fffffffffffffff on JS20
  384. */
  385. if (tceval && (tceval != 0x7fffffffffffffffUL)) {
  386. __set_bit(index, tbl->it_map);
  387. tcecount++;
  388. }
  389. }
  390. if ((tbl->it_size - tcecount) < KDUMP_MIN_TCE_ENTRIES) {
  391. printk(KERN_WARNING "TCE table is full; ");
  392. printk(KERN_WARNING "freeing %d entries for the kdump boot\n",
  393. KDUMP_MIN_TCE_ENTRIES);
  394. for (index = tbl->it_size - KDUMP_MIN_TCE_ENTRIES;
  395. index < tbl->it_size; index++)
  396. __clear_bit(index, tbl->it_map);
  397. }
  398. }
  399. #else
  400. /* Clear the hardware table in case firmware left allocations in it */
  401. ppc_md.tce_free(tbl, tbl->it_offset, tbl->it_size);
  402. #endif
  403. /*
  404. * DMA cannot cross 4 GB boundary. Mark last entry of each 4
  405. * GB chunk as reserved.
  406. */
  407. if (protect4gb) {
  408. entries_per_4g = 0x100000000l >> IOMMU_PAGE_SHIFT;
  409. /* Mark the last bit before a 4GB boundary as used */
  410. start_index = tbl->it_offset | (entries_per_4g - 1);
  411. start_index -= tbl->it_offset;
  412. end_index = tbl->it_size;
  413. for (index = start_index; index < end_index - 1; index += entries_per_4g)
  414. __set_bit(index, tbl->it_map);
  415. }
  416. if (!welcomed) {
  417. printk(KERN_INFO "IOMMU table initialized, virtual merging %s\n",
  418. novmerge ? "disabled" : "enabled");
  419. welcomed = 1;
  420. }
  421. return tbl;
  422. }
  423. void iommu_free_table(struct device_node *dn)
  424. {
  425. struct pci_dn *pdn = dn->data;
  426. struct iommu_table *tbl = pdn->iommu_table;
  427. unsigned long bitmap_sz, i;
  428. unsigned int order;
  429. if (!tbl || !tbl->it_map) {
  430. printk(KERN_ERR "%s: expected TCE map for %s\n", __FUNCTION__,
  431. dn->full_name);
  432. return;
  433. }
  434. /* verify that table contains no entries */
  435. /* it_size is in entries, and we're examining 64 at a time */
  436. for (i = 0; i < (tbl->it_size/64); i++) {
  437. if (tbl->it_map[i] != 0) {
  438. printk(KERN_WARNING "%s: Unexpected TCEs for %s\n",
  439. __FUNCTION__, dn->full_name);
  440. break;
  441. }
  442. }
  443. /* calculate bitmap size in bytes */
  444. bitmap_sz = (tbl->it_size + 7) / 8;
  445. /* free bitmap */
  446. order = get_order(bitmap_sz);
  447. free_pages((unsigned long) tbl->it_map, order);
  448. /* free table */
  449. kfree(tbl);
  450. }
  451. /* Creates TCEs for a user provided buffer. The user buffer must be
  452. * contiguous real kernel storage (not vmalloc). The address of the buffer
  453. * passed here is the kernel (virtual) address of the buffer. The buffer
  454. * need not be page aligned, the dma_addr_t returned will point to the same
  455. * byte within the page as vaddr.
  456. */
  457. dma_addr_t iommu_map_single(struct iommu_table *tbl, void *vaddr,
  458. size_t size, unsigned long mask,
  459. enum dma_data_direction direction)
  460. {
  461. dma_addr_t dma_handle = DMA_ERROR_CODE;
  462. unsigned long uaddr;
  463. unsigned int npages;
  464. BUG_ON(direction == DMA_NONE);
  465. uaddr = (unsigned long)vaddr;
  466. npages = iommu_num_pages(uaddr, size);
  467. if (tbl) {
  468. dma_handle = iommu_alloc(tbl, vaddr, npages, direction,
  469. mask >> IOMMU_PAGE_SHIFT, 0);
  470. if (dma_handle == DMA_ERROR_CODE) {
  471. if (printk_ratelimit()) {
  472. printk(KERN_INFO "iommu_alloc failed, "
  473. "tbl %p vaddr %p npages %d\n",
  474. tbl, vaddr, npages);
  475. }
  476. } else
  477. dma_handle |= (uaddr & ~IOMMU_PAGE_MASK);
  478. }
  479. return dma_handle;
  480. }
  481. void iommu_unmap_single(struct iommu_table *tbl, dma_addr_t dma_handle,
  482. size_t size, enum dma_data_direction direction)
  483. {
  484. unsigned int npages;
  485. BUG_ON(direction == DMA_NONE);
  486. if (tbl) {
  487. npages = iommu_num_pages(dma_handle, size);
  488. iommu_free(tbl, dma_handle, npages);
  489. }
  490. }
  491. /* Allocates a contiguous real buffer and creates mappings over it.
  492. * Returns the virtual address of the buffer and sets dma_handle
  493. * to the dma address (mapping) of the first page.
  494. */
  495. void *iommu_alloc_coherent(struct iommu_table *tbl, size_t size,
  496. dma_addr_t *dma_handle, unsigned long mask, gfp_t flag, int node)
  497. {
  498. void *ret = NULL;
  499. dma_addr_t mapping;
  500. unsigned int order;
  501. unsigned int nio_pages, io_order;
  502. struct page *page;
  503. size = PAGE_ALIGN(size);
  504. order = get_order(size);
  505. /*
  506. * Client asked for way too much space. This is checked later
  507. * anyway. It is easier to debug here for the drivers than in
  508. * the tce tables.
  509. */
  510. if (order >= IOMAP_MAX_ORDER) {
  511. printk("iommu_alloc_consistent size too large: 0x%lx\n", size);
  512. return NULL;
  513. }
  514. if (!tbl)
  515. return NULL;
  516. /* Alloc enough pages (and possibly more) */
  517. page = alloc_pages_node(node, flag, order);
  518. if (!page)
  519. return NULL;
  520. ret = page_address(page);
  521. memset(ret, 0, size);
  522. /* Set up tces to cover the allocated range */
  523. nio_pages = size >> IOMMU_PAGE_SHIFT;
  524. io_order = get_iommu_order(size);
  525. mapping = iommu_alloc(tbl, ret, nio_pages, DMA_BIDIRECTIONAL,
  526. mask >> IOMMU_PAGE_SHIFT, io_order);
  527. if (mapping == DMA_ERROR_CODE) {
  528. free_pages((unsigned long)ret, order);
  529. return NULL;
  530. }
  531. *dma_handle = mapping;
  532. return ret;
  533. }
  534. void iommu_free_coherent(struct iommu_table *tbl, size_t size,
  535. void *vaddr, dma_addr_t dma_handle)
  536. {
  537. if (tbl) {
  538. unsigned int nio_pages;
  539. size = PAGE_ALIGN(size);
  540. nio_pages = size >> IOMMU_PAGE_SHIFT;
  541. iommu_free(tbl, dma_handle, nio_pages);
  542. size = PAGE_ALIGN(size);
  543. free_pages((unsigned long)vaddr, get_order(size));
  544. }
  545. }