blob: 2d71a916d50cb755d8e15f2abfaff126e5140319 [file] [log] [blame]
Liam Mark4d4fbba2017-02-08 10:30:49 -08001/* Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -07002 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13#include <linux/dma-contiguous.h>
14#include <linux/dma-mapping.h>
15#include <linux/dma-mapping-fast.h>
16#include <linux/io-pgtable-fast.h>
Patrick Dalyde1c64d2017-09-12 16:30:12 -070017#include <linux/pci.h>
Patrick Daly7bcb5462016-08-03 17:27:36 -070018#include <linux/vmalloc.h>
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -070019#include <asm/cacheflush.h>
20#include <asm/dma-iommu.h>
Charan Teja Reddy29f61402017-02-09 20:44:29 +053021#include <linux/slab.h>
22#include <linux/vmalloc.h>
Patrick Daly1323e412017-10-05 21:16:25 -070023#include <trace/events/iommu.h>
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -070024
Patrick Daly23301482017-10-12 16:18:25 -070025#include <soc/qcom/secure_buffer.h>
26#include <linux/arm-smmu-errata.h>
27
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -070028/* some redundant definitions... :( TODO: move to io-pgtable-fast.h */
29#define FAST_PAGE_SHIFT 12
30#define FAST_PAGE_SIZE (1UL << FAST_PAGE_SHIFT)
31#define FAST_PAGE_MASK (~(PAGE_SIZE - 1))
32#define FAST_PTE_ADDR_MASK ((av8l_fast_iopte)0xfffffffff000)
Liam Mark83a9f86e2017-02-08 09:37:17 -080033#define FAST_MAIR_ATTR_IDX_CACHE 1
34#define FAST_PTE_ATTRINDX_SHIFT 2
35#define FAST_PTE_ATTRINDX_MASK 0x7
36#define FAST_PTE_SH_SHIFT 8
37#define FAST_PTE_SH_MASK (((av8l_fast_iopte)0x3) << FAST_PTE_SH_SHIFT)
38#define FAST_PTE_SH_OS (((av8l_fast_iopte)2) << FAST_PTE_SH_SHIFT)
39#define FAST_PTE_SH_IS (((av8l_fast_iopte)3) << FAST_PTE_SH_SHIFT)
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -070040
Mitchel Humpherys425d03d2016-06-23 13:25:12 -070041static pgprot_t __get_dma_pgprot(unsigned long attrs, pgprot_t prot,
42 bool coherent)
43{
44 if (attrs & DMA_ATTR_STRONGLY_ORDERED)
45 return pgprot_noncached(prot);
46 else if (!coherent || (attrs & DMA_ATTR_WRITE_COMBINE))
47 return pgprot_writecombine(prot);
48 return prot;
49}
50
51static int __get_iommu_pgprot(unsigned long attrs, int prot,
52 bool coherent)
53{
54 if (!(attrs & DMA_ATTR_EXEC_MAPPING))
55 prot |= IOMMU_NOEXEC;
56 if ((attrs & DMA_ATTR_STRONGLY_ORDERED))
57 prot |= IOMMU_MMIO;
58 if (coherent)
59 prot |= IOMMU_CACHE;
60
61 return prot;
62}
63
Mitchel Humpherys9de66db2016-06-07 11:09:44 -070064static void fast_dmac_clean_range(struct dma_fast_smmu_mapping *mapping,
65 void *start, void *end)
66{
67 if (!mapping->is_smmu_pt_coherent)
68 dmac_clean_range(start, end);
69}
70
Liam Mark83a9f86e2017-02-08 09:37:17 -080071static bool __fast_is_pte_coherent(av8l_fast_iopte *ptep)
72{
73 int attr_idx = (*ptep & (FAST_PTE_ATTRINDX_MASK <<
74 FAST_PTE_ATTRINDX_SHIFT)) >>
75 FAST_PTE_ATTRINDX_SHIFT;
76
77 if ((attr_idx == FAST_MAIR_ATTR_IDX_CACHE) &&
78 (((*ptep & FAST_PTE_SH_MASK) == FAST_PTE_SH_IS) ||
79 (*ptep & FAST_PTE_SH_MASK) == FAST_PTE_SH_OS))
80 return true;
81
82 return false;
83}
84
85static bool is_dma_coherent(struct device *dev, unsigned long attrs)
86{
87 bool is_coherent;
88
89 if (attrs & DMA_ATTR_FORCE_COHERENT)
90 is_coherent = true;
91 else if (attrs & DMA_ATTR_FORCE_NON_COHERENT)
92 is_coherent = false;
93 else if (is_device_dma_coherent(dev))
94 is_coherent = true;
95 else
96 is_coherent = false;
97
98 return is_coherent;
99}
100
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700101/*
102 * Checks if the allocated range (ending at @end) covered the upcoming
103 * stale bit. We don't need to know exactly where the range starts since
104 * we already know where the candidate search range started. If, starting
105 * from the beginning of the candidate search range, we had to step over
106 * (or landed directly on top of) the upcoming stale bit, then we return
107 * true.
108 *
109 * Due to wrapping, there are two scenarios we'll need to check: (1) if the
110 * range [search_start, upcoming_stale] spans 0 (i.e. search_start >
111 * upcoming_stale), and, (2) if the range: [search_start, upcoming_stale]
112 * does *not* span 0 (i.e. search_start <= upcoming_stale). And for each
113 * of those two scenarios we need to handle three cases: (1) the bit was
114 * found before wrapping or
115 */
116static bool __bit_covered_stale(unsigned long upcoming_stale,
117 unsigned long search_start,
118 unsigned long end)
119{
120 if (search_start > upcoming_stale) {
121 if (end >= search_start) {
122 /*
123 * We started searching above upcoming_stale and we
124 * didn't wrap, so we couldn't have crossed
125 * upcoming_stale.
126 */
127 return false;
128 }
129 /*
130 * We wrapped. Did we cross (or land on top of)
131 * upcoming_stale?
132 */
133 return end >= upcoming_stale;
134 }
135
136 if (search_start <= upcoming_stale) {
137 if (end >= search_start) {
138 /*
139 * We didn't wrap. Did we cross (or land on top
140 * of) upcoming_stale?
141 */
142 return end >= upcoming_stale;
143 }
144 /*
145 * We wrapped. So we must have crossed upcoming_stale
146 * (since we started searching below it).
147 */
148 return true;
149 }
150
151 /* we should have covered all logical combinations... */
152 WARN_ON(1);
153 return true;
154}
155
156static dma_addr_t __fast_smmu_alloc_iova(struct dma_fast_smmu_mapping *mapping,
Mitchel Humpherys5c704e02015-12-21 15:06:34 -0800157 unsigned long attrs,
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700158 size_t size)
159{
Patrick Daly23301482017-10-12 16:18:25 -0700160 unsigned long bit, prev_search_start, nbits;
161 unsigned long align;
162 unsigned long guard_len;
163 dma_addr_t iova;
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700164
Patrick Daly23301482017-10-12 16:18:25 -0700165 if (mapping->min_iova_align)
166 guard_len = ALIGN(size, mapping->min_iova_align) - size;
167 else
168 guard_len = 0;
169
170 nbits = (size + guard_len) >> FAST_PAGE_SHIFT;
171 align = (1 << get_order(size + guard_len)) - 1;
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700172 bit = bitmap_find_next_zero_area(
173 mapping->bitmap, mapping->num_4k_pages, mapping->next_start,
174 nbits, align);
175 if (unlikely(bit > mapping->num_4k_pages)) {
176 /* try wrapping */
177 mapping->next_start = 0; /* TODO: SHOULD I REALLY DO THIS?!? */
178 bit = bitmap_find_next_zero_area(
179 mapping->bitmap, mapping->num_4k_pages, 0, nbits,
180 align);
181 if (unlikely(bit > mapping->num_4k_pages))
182 return DMA_ERROR_CODE;
183 }
184
185 bitmap_set(mapping->bitmap, bit, nbits);
186 prev_search_start = mapping->next_start;
187 mapping->next_start = bit + nbits;
188 if (unlikely(mapping->next_start >= mapping->num_4k_pages))
189 mapping->next_start = 0;
190
191 /*
192 * If we just re-allocated a VA whose TLB hasn't been invalidated
193 * since it was last used and unmapped, we need to invalidate it
194 * here. We actually invalidate the entire TLB so that we don't
195 * have to invalidate the TLB again until we wrap back around.
196 */
197 if (mapping->have_stale_tlbs &&
198 __bit_covered_stale(mapping->upcoming_stale_bit,
199 prev_search_start,
200 bit + nbits - 1)) {
Mitchel Humpherys5c704e02015-12-21 15:06:34 -0800201 bool skip_sync = (attrs & DMA_ATTR_SKIP_CPU_SYNC);
202
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700203 iommu_tlbiall(mapping->domain);
204 mapping->have_stale_tlbs = false;
Mitchel Humpherys5c704e02015-12-21 15:06:34 -0800205 av8l_fast_clear_stale_ptes(mapping->pgtbl_pmds, skip_sync);
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700206 }
207
Patrick Daly23301482017-10-12 16:18:25 -0700208 iova = (bit << FAST_PAGE_SHIFT) + mapping->base;
209 if (guard_len &&
210 iommu_map(mapping->domain, iova + size,
211 page_to_phys(mapping->guard_page),
212 guard_len, ARM_SMMU_GUARD_PROT)) {
213
214 bitmap_clear(mapping->bitmap, bit, nbits);
215 return DMA_ERROR_CODE;
216 }
217 return iova;
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700218}
219
220/*
221 * Checks whether the candidate bit will be allocated sooner than the
222 * current upcoming stale bit. We can say candidate will be upcoming
223 * sooner than the current upcoming stale bit if it lies between the
224 * starting bit of the next search range and the upcoming stale bit
225 * (allowing for wrap-around).
226 *
227 * Stated differently, we're checking the relative ordering of three
228 * unsigned numbers. So we need to check all 6 (i.e. 3!) permutations,
229 * namely:
230 *
231 * 0 |---A---B---C---| TOP (Case 1)
232 * 0 |---A---C---B---| TOP (Case 2)
233 * 0 |---B---A---C---| TOP (Case 3)
234 * 0 |---B---C---A---| TOP (Case 4)
235 * 0 |---C---A---B---| TOP (Case 5)
236 * 0 |---C---B---A---| TOP (Case 6)
237 *
238 * Note that since we're allowing numbers to wrap, the following three
239 * scenarios are all equivalent for Case 1:
240 *
241 * 0 |---A---B---C---| TOP
242 * 0 |---C---A---B---| TOP (C has wrapped. This is Case 5.)
243 * 0 |---B---C---A---| TOP (C and B have wrapped. This is Case 4.)
244 *
245 * In any of these cases, if we start searching from A, we will find B
246 * before we find C.
247 *
248 * We can also find two equivalent cases for Case 2:
249 *
250 * 0 |---A---C---B---| TOP
251 * 0 |---B---A---C---| TOP (B has wrapped. This is Case 3.)
252 * 0 |---C---B---A---| TOP (B and C have wrapped. This is Case 6.)
253 *
254 * In any of these cases, if we start searching from A, we will find C
255 * before we find B.
256 */
257static bool __bit_is_sooner(unsigned long candidate,
258 struct dma_fast_smmu_mapping *mapping)
259{
260 unsigned long A = mapping->next_start;
261 unsigned long B = candidate;
262 unsigned long C = mapping->upcoming_stale_bit;
263
264 if ((A < B && B < C) || /* Case 1 */
265 (C < A && A < B) || /* Case 5 */
266 (B < C && C < A)) /* Case 4 */
267 return true;
268
269 if ((A < C && C < B) || /* Case 2 */
270 (B < A && A < C) || /* Case 3 */
271 (C < B && B < A)) /* Case 6 */
272 return false;
273
274 /*
275 * For simplicity, we've been ignoring the possibility of any of
276 * our three numbers being equal. Handle those cases here (they
277 * shouldn't happen very often, (I think?)).
278 */
279
280 /*
281 * If candidate is the next bit to be searched then it's definitely
282 * sooner.
283 */
284 if (A == B)
285 return true;
286
287 /*
288 * If candidate is the next upcoming stale bit we'll return false
289 * to avoid doing `upcoming = candidate' in the caller (which would
290 * be useless since they're already equal)
291 */
292 if (B == C)
293 return false;
294
295 /*
296 * If next start is the upcoming stale bit then candidate can't
297 * possibly be sooner. The "soonest" bit is already selected.
298 */
299 if (A == C)
300 return false;
301
302 /* We should have covered all logical combinations. */
303 WARN(1, "Well, that's awkward. A=%ld, B=%ld, C=%ld\n", A, B, C);
304 return true;
305}
306
307static void __fast_smmu_free_iova(struct dma_fast_smmu_mapping *mapping,
308 dma_addr_t iova, size_t size)
309{
310 unsigned long start_bit = (iova - mapping->base) >> FAST_PAGE_SHIFT;
Patrick Daly23301482017-10-12 16:18:25 -0700311 unsigned long nbits;
312 unsigned long guard_len;
313
314 if (mapping->min_iova_align)
315 guard_len = ALIGN(size, mapping->min_iova_align) - size;
316 else
317 guard_len = 0;
318 nbits = (size + guard_len) >> FAST_PAGE_SHIFT;
319
320 iommu_unmap(mapping->domain, iova + size, guard_len);
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700321
322 /*
323 * We don't invalidate TLBs on unmap. We invalidate TLBs on map
324 * when we're about to re-allocate a VA that was previously
325 * unmapped but hasn't yet been invalidated. So we need to keep
326 * track of which bit is the closest to being re-allocated here.
327 */
328 if (__bit_is_sooner(start_bit, mapping))
329 mapping->upcoming_stale_bit = start_bit;
330
331 bitmap_clear(mapping->bitmap, start_bit, nbits);
332 mapping->have_stale_tlbs = true;
333}
334
335
336static void __fast_dma_page_cpu_to_dev(struct page *page, unsigned long off,
337 size_t size, enum dma_data_direction dir)
338{
339 __dma_map_area(page_address(page) + off, size, dir);
340}
341
342static void __fast_dma_page_dev_to_cpu(struct page *page, unsigned long off,
343 size_t size, enum dma_data_direction dir)
344{
345 __dma_unmap_area(page_address(page) + off, size, dir);
346
347 /* TODO: WHAT IS THIS? */
348 /*
349 * Mark the D-cache clean for this page to avoid extra flushing.
350 */
351 if (dir != DMA_TO_DEVICE && off == 0 && size >= PAGE_SIZE)
352 set_bit(PG_dcache_clean, &page->flags);
353}
354
355static int __fast_dma_direction_to_prot(enum dma_data_direction dir)
356{
357 switch (dir) {
358 case DMA_BIDIRECTIONAL:
359 return IOMMU_READ | IOMMU_WRITE;
360 case DMA_TO_DEVICE:
361 return IOMMU_READ;
362 case DMA_FROM_DEVICE:
363 return IOMMU_WRITE;
364 default:
365 return 0;
366 }
367}
368
369static dma_addr_t fast_smmu_map_page(struct device *dev, struct page *page,
370 unsigned long offset, size_t size,
371 enum dma_data_direction dir,
372 unsigned long attrs)
373{
374 struct dma_fast_smmu_mapping *mapping = dev->archdata.mapping->fast;
375 dma_addr_t iova;
376 unsigned long flags;
377 av8l_fast_iopte *pmd;
378 phys_addr_t phys_plus_off = page_to_phys(page) + offset;
379 phys_addr_t phys_to_map = round_down(phys_plus_off, FAST_PAGE_SIZE);
380 unsigned long offset_from_phys_to_map = phys_plus_off & ~FAST_PAGE_MASK;
381 size_t len = ALIGN(size + offset_from_phys_to_map, FAST_PAGE_SIZE);
382 int nptes = len >> FAST_PAGE_SHIFT;
383 bool skip_sync = (attrs & DMA_ATTR_SKIP_CPU_SYNC);
384 int prot = __fast_dma_direction_to_prot(dir);
Liam Mark83a9f86e2017-02-08 09:37:17 -0800385 bool is_coherent = is_dma_coherent(dev, attrs);
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700386
Mitchel Humpherys425d03d2016-06-23 13:25:12 -0700387 prot = __get_iommu_pgprot(attrs, prot, is_coherent);
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700388
Mitchel Humpherys425d03d2016-06-23 13:25:12 -0700389 if (!skip_sync && !is_coherent)
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700390 __fast_dma_page_cpu_to_dev(phys_to_page(phys_to_map),
391 offset_from_phys_to_map, size, dir);
392
393 spin_lock_irqsave(&mapping->lock, flags);
394
Mitchel Humpherys5c704e02015-12-21 15:06:34 -0800395 iova = __fast_smmu_alloc_iova(mapping, attrs, len);
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700396
397 if (unlikely(iova == DMA_ERROR_CODE))
398 goto fail;
399
400 pmd = iopte_pmd_offset(mapping->pgtbl_pmds, iova);
401
402 if (unlikely(av8l_fast_map_public(pmd, phys_to_map, len, prot)))
403 goto fail_free_iova;
404
Mitchel Humpherys9de66db2016-06-07 11:09:44 -0700405 fast_dmac_clean_range(mapping, pmd, pmd + nptes);
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700406
407 spin_unlock_irqrestore(&mapping->lock, flags);
Patrick Daly1323e412017-10-05 21:16:25 -0700408
409 trace_map(mapping->domain, iova, phys_to_map, len, prot);
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700410 return iova + offset_from_phys_to_map;
411
412fail_free_iova:
413 __fast_smmu_free_iova(mapping, iova, size);
414fail:
415 spin_unlock_irqrestore(&mapping->lock, flags);
416 return DMA_ERROR_CODE;
417}
418
419static void fast_smmu_unmap_page(struct device *dev, dma_addr_t iova,
420 size_t size, enum dma_data_direction dir,
421 unsigned long attrs)
422{
423 struct dma_fast_smmu_mapping *mapping = dev->archdata.mapping->fast;
424 unsigned long flags;
425 av8l_fast_iopte *pmd = iopte_pmd_offset(mapping->pgtbl_pmds, iova);
426 unsigned long offset = iova & ~FAST_PAGE_MASK;
427 size_t len = ALIGN(size + offset, FAST_PAGE_SIZE);
428 int nptes = len >> FAST_PAGE_SHIFT;
429 struct page *page = phys_to_page((*pmd & FAST_PTE_ADDR_MASK));
430 bool skip_sync = (attrs & DMA_ATTR_SKIP_CPU_SYNC);
Liam Mark83a9f86e2017-02-08 09:37:17 -0800431 bool is_coherent = is_dma_coherent(dev, attrs);
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700432
Mitchel Humpherys425d03d2016-06-23 13:25:12 -0700433 if (!skip_sync && !is_coherent)
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700434 __fast_dma_page_dev_to_cpu(page, offset, size, dir);
435
436 spin_lock_irqsave(&mapping->lock, flags);
437 av8l_fast_unmap_public(pmd, len);
Mitchel Humpherys9de66db2016-06-07 11:09:44 -0700438 fast_dmac_clean_range(mapping, pmd, pmd + nptes);
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700439 __fast_smmu_free_iova(mapping, iova, len);
440 spin_unlock_irqrestore(&mapping->lock, flags);
Patrick Daly1323e412017-10-05 21:16:25 -0700441
442 trace_unmap(mapping->domain, iova - offset, len, len);
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700443}
444
Liam Mark78d7fb52016-12-01 13:05:31 -0800445static void fast_smmu_sync_single_for_cpu(struct device *dev,
446 dma_addr_t iova, size_t size, enum dma_data_direction dir)
447{
448 struct dma_fast_smmu_mapping *mapping = dev->archdata.mapping->fast;
449 av8l_fast_iopte *pmd = iopte_pmd_offset(mapping->pgtbl_pmds, iova);
450 unsigned long offset = iova & ~FAST_PAGE_MASK;
451 struct page *page = phys_to_page((*pmd & FAST_PTE_ADDR_MASK));
452
Liam Mark83a9f86e2017-02-08 09:37:17 -0800453 if (!__fast_is_pte_coherent(pmd))
Liam Mark78d7fb52016-12-01 13:05:31 -0800454 __fast_dma_page_dev_to_cpu(page, offset, size, dir);
455}
456
457static void fast_smmu_sync_single_for_device(struct device *dev,
458 dma_addr_t iova, size_t size, enum dma_data_direction dir)
459{
460 struct dma_fast_smmu_mapping *mapping = dev->archdata.mapping->fast;
461 av8l_fast_iopte *pmd = iopte_pmd_offset(mapping->pgtbl_pmds, iova);
462 unsigned long offset = iova & ~FAST_PAGE_MASK;
463 struct page *page = phys_to_page((*pmd & FAST_PTE_ADDR_MASK));
464
Liam Mark83a9f86e2017-02-08 09:37:17 -0800465 if (!__fast_is_pte_coherent(pmd))
Liam Mark78d7fb52016-12-01 13:05:31 -0800466 __fast_dma_page_cpu_to_dev(page, offset, size, dir);
467}
468
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700469static int fast_smmu_map_sg(struct device *dev, struct scatterlist *sg,
470 int nents, enum dma_data_direction dir,
471 unsigned long attrs)
472{
Patrick Daly36c547a2017-09-06 19:13:02 -0700473 /* 0 indicates error */
474 return 0;
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700475}
476
477static void fast_smmu_unmap_sg(struct device *dev,
478 struct scatterlist *sg, int nents,
479 enum dma_data_direction dir,
480 unsigned long attrs)
481{
482 WARN_ON_ONCE(1);
483}
484
Liam Mark78d7fb52016-12-01 13:05:31 -0800485static void fast_smmu_sync_sg_for_cpu(struct device *dev,
486 struct scatterlist *sg, int nents, enum dma_data_direction dir)
487{
488 WARN_ON_ONCE(1);
489}
490
491static void fast_smmu_sync_sg_for_device(struct device *dev,
492 struct scatterlist *sg, int nents, enum dma_data_direction dir)
493{
494 WARN_ON_ONCE(1);
495}
496
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700497static void __fast_smmu_free_pages(struct page **pages, int count)
498{
499 int i;
500
501 for (i = 0; i < count; i++)
502 __free_page(pages[i]);
503 kvfree(pages);
504}
505
506static struct page **__fast_smmu_alloc_pages(unsigned int count, gfp_t gfp)
507{
508 struct page **pages;
509 unsigned int i = 0, array_size = count * sizeof(*pages);
510
511 if (array_size <= PAGE_SIZE)
512 pages = kzalloc(array_size, GFP_KERNEL);
513 else
514 pages = vzalloc(array_size);
515 if (!pages)
516 return NULL;
517
518 /* IOMMU can map any pages, so himem can also be used here */
519 gfp |= __GFP_NOWARN | __GFP_HIGHMEM;
520
521 for (i = 0; i < count; ++i) {
522 struct page *page = alloc_page(gfp);
523
524 if (!page) {
525 __fast_smmu_free_pages(pages, i);
526 return NULL;
527 }
528 pages[i] = page;
529 }
530 return pages;
531}
532
533static void *fast_smmu_alloc(struct device *dev, size_t size,
534 dma_addr_t *handle, gfp_t gfp,
535 unsigned long attrs)
536{
537 struct dma_fast_smmu_mapping *mapping = dev->archdata.mapping->fast;
538 struct sg_table sgt;
539 dma_addr_t dma_addr, iova_iter;
540 void *addr;
541 av8l_fast_iopte *ptep;
542 unsigned long flags;
543 struct sg_mapping_iter miter;
544 unsigned int count = ALIGN(size, SZ_4K) >> PAGE_SHIFT;
545 int prot = IOMMU_READ | IOMMU_WRITE; /* TODO: extract from attrs */
Liam Mark83a9f86e2017-02-08 09:37:17 -0800546 bool is_coherent = is_dma_coherent(dev, attrs);
Mitchel Humpherys425d03d2016-06-23 13:25:12 -0700547 pgprot_t remap_prot = __get_dma_pgprot(attrs, PAGE_KERNEL, is_coherent);
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700548 struct page **pages;
549
Mitchel Humpherys425d03d2016-06-23 13:25:12 -0700550 prot = __get_iommu_pgprot(attrs, prot, is_coherent);
551
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700552 *handle = DMA_ERROR_CODE;
553
554 pages = __fast_smmu_alloc_pages(count, gfp);
555 if (!pages) {
556 dev_err(dev, "no pages\n");
557 return NULL;
558 }
559
560 size = ALIGN(size, SZ_4K);
561 if (sg_alloc_table_from_pages(&sgt, pages, count, 0, size, gfp)) {
562 dev_err(dev, "no sg tablen\n");
563 goto out_free_pages;
564 }
565
Mitchel Humpherys425d03d2016-06-23 13:25:12 -0700566 if (!is_coherent) {
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700567 /*
568 * The CPU-centric flushing implied by SG_MITER_TO_SG isn't
569 * sufficient here, so skip it by using the "wrong" direction.
570 */
571 sg_miter_start(&miter, sgt.sgl, sgt.orig_nents,
572 SG_MITER_FROM_SG);
573 while (sg_miter_next(&miter))
Kyle Yan65be4a52016-10-31 15:05:00 -0700574 __dma_flush_area(miter.addr, miter.length);
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700575 sg_miter_stop(&miter);
576 }
577
578 spin_lock_irqsave(&mapping->lock, flags);
Mitchel Humpherys5c704e02015-12-21 15:06:34 -0800579 dma_addr = __fast_smmu_alloc_iova(mapping, attrs, size);
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700580 if (dma_addr == DMA_ERROR_CODE) {
581 dev_err(dev, "no iova\n");
582 spin_unlock_irqrestore(&mapping->lock, flags);
583 goto out_free_sg;
584 }
585 iova_iter = dma_addr;
586 sg_miter_start(&miter, sgt.sgl, sgt.orig_nents,
587 SG_MITER_FROM_SG | SG_MITER_ATOMIC);
588 while (sg_miter_next(&miter)) {
589 int nptes = miter.length >> FAST_PAGE_SHIFT;
590
591 ptep = iopte_pmd_offset(mapping->pgtbl_pmds, iova_iter);
592 if (unlikely(av8l_fast_map_public(
593 ptep, page_to_phys(miter.page),
594 miter.length, prot))) {
595 dev_err(dev, "no map public\n");
596 /* TODO: unwind previously successful mappings */
597 goto out_free_iova;
598 }
Mitchel Humpherys9de66db2016-06-07 11:09:44 -0700599 fast_dmac_clean_range(mapping, ptep, ptep + nptes);
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700600 iova_iter += miter.length;
601 }
602 sg_miter_stop(&miter);
603 spin_unlock_irqrestore(&mapping->lock, flags);
604
605 addr = dma_common_pages_remap(pages, size, VM_USERMAP, remap_prot,
606 __builtin_return_address(0));
607 if (!addr) {
608 dev_err(dev, "no common pages\n");
609 goto out_unmap;
610 }
611
612 *handle = dma_addr;
613 sg_free_table(&sgt);
614 return addr;
615
616out_unmap:
617 /* need to take the lock again for page tables and iova */
618 spin_lock_irqsave(&mapping->lock, flags);
619 ptep = iopte_pmd_offset(mapping->pgtbl_pmds, dma_addr);
620 av8l_fast_unmap_public(ptep, size);
Mitchel Humpherys9de66db2016-06-07 11:09:44 -0700621 fast_dmac_clean_range(mapping, ptep, ptep + count);
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700622out_free_iova:
623 __fast_smmu_free_iova(mapping, dma_addr, size);
624 spin_unlock_irqrestore(&mapping->lock, flags);
625out_free_sg:
626 sg_free_table(&sgt);
627out_free_pages:
628 __fast_smmu_free_pages(pages, count);
629 return NULL;
630}
631
632static void fast_smmu_free(struct device *dev, size_t size,
633 void *vaddr, dma_addr_t dma_handle,
634 unsigned long attrs)
635{
636 struct dma_fast_smmu_mapping *mapping = dev->archdata.mapping->fast;
637 struct vm_struct *area;
638 struct page **pages;
639 size_t count = ALIGN(size, SZ_4K) >> FAST_PAGE_SHIFT;
640 av8l_fast_iopte *ptep;
641 unsigned long flags;
642
643 size = ALIGN(size, SZ_4K);
644
645 area = find_vm_area(vaddr);
646 if (WARN_ON_ONCE(!area))
647 return;
648
649 pages = area->pages;
650 dma_common_free_remap(vaddr, size, VM_USERMAP, false);
651 ptep = iopte_pmd_offset(mapping->pgtbl_pmds, dma_handle);
652 spin_lock_irqsave(&mapping->lock, flags);
653 av8l_fast_unmap_public(ptep, size);
Mitchel Humpherys9de66db2016-06-07 11:09:44 -0700654 fast_dmac_clean_range(mapping, ptep, ptep + count);
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700655 __fast_smmu_free_iova(mapping, dma_handle, size);
656 spin_unlock_irqrestore(&mapping->lock, flags);
657 __fast_smmu_free_pages(pages, count);
658}
659
Patrick Daly7bcb5462016-08-03 17:27:36 -0700660static int fast_smmu_mmap_attrs(struct device *dev, struct vm_area_struct *vma,
661 void *cpu_addr, dma_addr_t dma_addr,
662 size_t size, unsigned long attrs)
663{
664 struct vm_struct *area;
665 unsigned long uaddr = vma->vm_start;
666 struct page **pages;
667 int i, nr_pages, ret = 0;
Liam Mark83a9f86e2017-02-08 09:37:17 -0800668 bool coherent = is_dma_coherent(dev, attrs);
Patrick Daly7bcb5462016-08-03 17:27:36 -0700669
Mitchel Humpherys425d03d2016-06-23 13:25:12 -0700670 vma->vm_page_prot = __get_dma_pgprot(attrs, vma->vm_page_prot,
671 coherent);
Patrick Daly7bcb5462016-08-03 17:27:36 -0700672 area = find_vm_area(cpu_addr);
673 if (!area)
674 return -EINVAL;
675
676 pages = area->pages;
677 nr_pages = PAGE_ALIGN(size) >> PAGE_SHIFT;
678 for (i = vma->vm_pgoff; i < nr_pages && uaddr < vma->vm_end; i++) {
679 ret = vm_insert_page(vma, uaddr, pages[i]);
680 if (ret)
681 break;
682 uaddr += PAGE_SIZE;
683 }
684
685 return ret;
686}
687
Patrick Daly9c79f382017-06-12 18:15:25 -0700688static int fast_smmu_get_sgtable(struct device *dev, struct sg_table *sgt,
689 void *cpu_addr, dma_addr_t dma_addr,
690 size_t size, unsigned long attrs)
691{
692 unsigned int n_pages = PAGE_ALIGN(size) >> PAGE_SHIFT;
693 struct vm_struct *area;
694
695 area = find_vm_area(cpu_addr);
696 if (!area || !area->pages)
697 return -EINVAL;
698
699 return sg_alloc_table_from_pages(sgt, area->pages, n_pages, 0, size,
700 GFP_KERNEL);
701}
702
Patrick Daly199fa672017-05-04 15:30:16 -0700703static dma_addr_t fast_smmu_dma_map_resource(
704 struct device *dev, phys_addr_t phys_addr,
705 size_t size, enum dma_data_direction dir,
706 unsigned long attrs)
707{
708 struct dma_fast_smmu_mapping *mapping = dev->archdata.mapping->fast;
709 size_t offset = phys_addr & ~FAST_PAGE_MASK;
710 size_t len = round_up(size + offset, FAST_PAGE_SIZE);
711 dma_addr_t dma_addr;
712 int prot;
713 unsigned long flags;
714
715 spin_lock_irqsave(&mapping->lock, flags);
716 dma_addr = __fast_smmu_alloc_iova(mapping, attrs, len);
717 spin_unlock_irqrestore(&mapping->lock, flags);
718
719 if (dma_addr == DMA_ERROR_CODE)
720 return dma_addr;
721
722 prot = __fast_dma_direction_to_prot(dir);
723 prot |= IOMMU_MMIO;
724
725 if (iommu_map(mapping->domain, dma_addr, phys_addr - offset,
726 len, prot)) {
727 spin_lock_irqsave(&mapping->lock, flags);
728 __fast_smmu_free_iova(mapping, dma_addr, len);
729 spin_unlock_irqrestore(&mapping->lock, flags);
730 return DMA_ERROR_CODE;
731 }
732 return dma_addr + offset;
733}
734
735static void fast_smmu_dma_unmap_resource(
736 struct device *dev, dma_addr_t addr,
737 size_t size, enum dma_data_direction dir,
738 unsigned long attrs)
739{
740 struct dma_fast_smmu_mapping *mapping = dev->archdata.mapping->fast;
741 size_t offset = addr & ~FAST_PAGE_MASK;
742 size_t len = round_up(size + offset, FAST_PAGE_SIZE);
743 unsigned long flags;
744
745 iommu_unmap(mapping->domain, addr - offset, len);
746 spin_lock_irqsave(&mapping->lock, flags);
747 __fast_smmu_free_iova(mapping, addr, len);
748 spin_unlock_irqrestore(&mapping->lock, flags);
749}
750
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700751static int fast_smmu_mapping_error(struct device *dev,
752 dma_addr_t dma_addr)
753{
754 return dma_addr == DMA_ERROR_CODE;
755}
756
Mitchel Humpherys5c704e02015-12-21 15:06:34 -0800757static void __fast_smmu_mapped_over_stale(struct dma_fast_smmu_mapping *fast,
758 void *data)
759{
760 av8l_fast_iopte *ptep = data;
761 dma_addr_t iova;
762 unsigned long bitmap_idx;
763
764 bitmap_idx = (unsigned long)(ptep - fast->pgtbl_pmds);
765 iova = bitmap_idx << FAST_PAGE_SHIFT;
766 dev_err(fast->dev, "Mapped over stale tlb at %pa\n", &iova);
767 dev_err(fast->dev, "bitmap (failure at idx %lu):\n", bitmap_idx);
768 dev_err(fast->dev, "ptep: %p pmds: %p diff: %lu\n", ptep,
Charan Teja Reddy29f61402017-02-09 20:44:29 +0530769 fast->pgtbl_pmds, bitmap_idx);
Mitchel Humpherys5c704e02015-12-21 15:06:34 -0800770 print_hex_dump(KERN_ERR, "bmap: ", DUMP_PREFIX_ADDRESS,
771 32, 8, fast->bitmap, fast->bitmap_size, false);
772}
773
774static int fast_smmu_notify(struct notifier_block *self,
775 unsigned long action, void *data)
776{
777 struct dma_fast_smmu_mapping *fast = container_of(
778 self, struct dma_fast_smmu_mapping, notifier);
779
780 switch (action) {
781 case MAPPED_OVER_STALE_TLB:
782 __fast_smmu_mapped_over_stale(fast, data);
783 return NOTIFY_OK;
784 default:
785 WARN(1, "Unhandled notifier action");
786 return NOTIFY_DONE;
787 }
788}
789
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700790static const struct dma_map_ops fast_smmu_dma_ops = {
791 .alloc = fast_smmu_alloc,
792 .free = fast_smmu_free,
Patrick Daly7bcb5462016-08-03 17:27:36 -0700793 .mmap = fast_smmu_mmap_attrs,
Patrick Daly9c79f382017-06-12 18:15:25 -0700794 .get_sgtable = fast_smmu_get_sgtable,
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700795 .map_page = fast_smmu_map_page,
796 .unmap_page = fast_smmu_unmap_page,
Liam Mark78d7fb52016-12-01 13:05:31 -0800797 .sync_single_for_cpu = fast_smmu_sync_single_for_cpu,
798 .sync_single_for_device = fast_smmu_sync_single_for_device,
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700799 .map_sg = fast_smmu_map_sg,
800 .unmap_sg = fast_smmu_unmap_sg,
Liam Mark78d7fb52016-12-01 13:05:31 -0800801 .sync_sg_for_cpu = fast_smmu_sync_sg_for_cpu,
802 .sync_sg_for_device = fast_smmu_sync_sg_for_device,
Patrick Daly199fa672017-05-04 15:30:16 -0700803 .map_resource = fast_smmu_dma_map_resource,
804 .unmap_resource = fast_smmu_dma_unmap_resource,
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700805 .mapping_error = fast_smmu_mapping_error,
806};
807
808/**
809 * __fast_smmu_create_mapping_sized
810 * @base: bottom of the VA range
811 * @size: size of the VA range in bytes
812 *
813 * Creates a mapping structure which holds information about used/unused IO
814 * address ranges, which is required to perform mapping with IOMMU aware
815 * functions. The only VA range supported is [0, 4GB).
816 *
817 * The client device need to be attached to the mapping with
818 * fast_smmu_attach_device function.
819 */
820static struct dma_fast_smmu_mapping *__fast_smmu_create_mapping_sized(
Charan Teja Reddy29f61402017-02-09 20:44:29 +0530821 dma_addr_t base, u64 size)
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700822{
823 struct dma_fast_smmu_mapping *fast;
824
825 fast = kzalloc(sizeof(struct dma_fast_smmu_mapping), GFP_KERNEL);
826 if (!fast)
827 goto err;
828
829 fast->base = base;
830 fast->size = size;
831 fast->num_4k_pages = size >> FAST_PAGE_SHIFT;
832 fast->bitmap_size = BITS_TO_LONGS(fast->num_4k_pages) * sizeof(long);
833
Liam Mark4d4fbba2017-02-08 10:30:49 -0800834 fast->bitmap = kzalloc(fast->bitmap_size, GFP_KERNEL | __GFP_NOWARN |
835 __GFP_NORETRY);
836 if (!fast->bitmap)
837 fast->bitmap = vzalloc(fast->bitmap_size);
838
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700839 if (!fast->bitmap)
840 goto err2;
841
842 spin_lock_init(&fast->lock);
843
844 return fast;
845err2:
846 kfree(fast);
847err:
848 return ERR_PTR(-ENOMEM);
849}
850
Patrick Dalybc8b1cb2017-05-04 17:10:10 -0700851/*
852 * Based off of similar code from dma-iommu.c, but modified to use a different
853 * iova allocator
854 */
855static void fast_smmu_reserve_pci_windows(struct device *dev,
856 struct dma_fast_smmu_mapping *mapping)
857{
858 struct pci_host_bridge *bridge;
859 struct resource_entry *window;
860 phys_addr_t start, end;
861 struct pci_dev *pci_dev;
862 unsigned long flags;
863
864 if (!dev_is_pci(dev))
865 return;
866
867 pci_dev = to_pci_dev(dev);
868 bridge = pci_find_host_bridge(pci_dev->bus);
869
870 spin_lock_irqsave(&mapping->lock, flags);
871 resource_list_for_each_entry(window, &bridge->windows) {
872 if (resource_type(window->res) != IORESOURCE_MEM &&
873 resource_type(window->res) != IORESOURCE_IO)
874 continue;
875
876 start = round_down(window->res->start - window->offset,
877 FAST_PAGE_SIZE);
878 end = round_up(window->res->end - window->offset,
879 FAST_PAGE_SIZE);
880 start = max_t(unsigned long, mapping->base, start);
881 end = min_t(unsigned long, mapping->base + mapping->size, end);
882 if (start >= end)
883 continue;
884
885 dev_dbg(dev, "iova allocator reserved 0x%pa-0x%pa\n",
886 &start, &end);
887
888 start = (start - mapping->base) >> FAST_PAGE_SHIFT;
889 end = (end - mapping->base) >> FAST_PAGE_SHIFT;
890 bitmap_set(mapping->bitmap, start, end - start);
891 }
892 spin_unlock_irqrestore(&mapping->lock, flags);
893}
894
Patrick Daly23301482017-10-12 16:18:25 -0700895static int fast_smmu_errata_init(struct dma_iommu_mapping *mapping)
896{
897 struct dma_fast_smmu_mapping *fast = mapping->fast;
898 int vmid = VMID_HLOS;
899 int min_iova_align = 0;
900
901 iommu_domain_get_attr(mapping->domain,
Patrick Daly83174c12017-10-26 12:31:15 -0700902 DOMAIN_ATTR_MMU500_ERRATA_MIN_ALIGN,
Patrick Daly23301482017-10-12 16:18:25 -0700903 &min_iova_align);
904 iommu_domain_get_attr(mapping->domain, DOMAIN_ATTR_SECURE_VMID, &vmid);
905 if (vmid >= VMID_LAST || vmid < 0)
906 vmid = VMID_HLOS;
907
908 if (min_iova_align) {
909 fast->min_iova_align = ARM_SMMU_MIN_IOVA_ALIGN;
910 fast->guard_page = arm_smmu_errata_get_guard_page(vmid);
911 if (!fast->guard_page)
912 return -ENOMEM;
913 }
914 return 0;
915}
916
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700917/**
Patrick Daly1748f082017-09-05 21:32:52 -0700918 * fast_smmu_init_mapping
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700919 * @dev: valid struct device pointer
920 * @mapping: io address space mapping structure (returned from
Patrick Daly1748f082017-09-05 21:32:52 -0700921 * arm_iommu_create_mapping)
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700922 *
Patrick Daly1748f082017-09-05 21:32:52 -0700923 * Called the first time a device is attached to this mapping.
924 * Not for dma client use.
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700925 */
Patrick Daly1748f082017-09-05 21:32:52 -0700926int fast_smmu_init_mapping(struct device *dev,
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700927 struct dma_iommu_mapping *mapping)
928{
Patrick Daly0df84ac2017-10-11 17:32:41 -0700929 int err;
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700930 struct iommu_domain *domain = mapping->domain;
931 struct iommu_pgtbl_info info;
Charan Teja Reddy29f61402017-02-09 20:44:29 +0530932 u64 size = (u64)mapping->bits << PAGE_SHIFT;
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700933
Patrick Daly1748f082017-09-05 21:32:52 -0700934 if (mapping->base + size > (SZ_1G * 4ULL)) {
935 dev_err(dev, "Iova end address too large\n");
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700936 return -EINVAL;
Patrick Daly1748f082017-09-05 21:32:52 -0700937 }
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700938
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700939 mapping->fast = __fast_smmu_create_mapping_sized(mapping->base, size);
940 if (IS_ERR(mapping->fast))
941 return -ENOMEM;
942 mapping->fast->domain = domain;
943 mapping->fast->dev = dev;
944
Patrick Daly23301482017-10-12 16:18:25 -0700945 if (fast_smmu_errata_init(mapping))
946 goto release_mapping;
947
Patrick Dalybc8b1cb2017-05-04 17:10:10 -0700948 fast_smmu_reserve_pci_windows(dev, mapping->fast);
949
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700950 if (iommu_domain_get_attr(domain, DOMAIN_ATTR_PGTBL_INFO,
951 &info)) {
952 dev_err(dev, "Couldn't get page table info\n");
Patrick Daly1748f082017-09-05 21:32:52 -0700953 err = -EINVAL;
Patrick Daly121a9a12017-10-11 17:43:29 -0700954 goto release_mapping;
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700955 }
956 mapping->fast->pgtbl_pmds = info.pmds;
957
Mitchel Humpherys9de66db2016-06-07 11:09:44 -0700958 if (iommu_domain_get_attr(domain, DOMAIN_ATTR_PAGE_TABLE_IS_COHERENT,
Patrick Daly1748f082017-09-05 21:32:52 -0700959 &mapping->fast->is_smmu_pt_coherent)) {
960 err = -EINVAL;
Patrick Daly121a9a12017-10-11 17:43:29 -0700961 goto release_mapping;
Patrick Daly1748f082017-09-05 21:32:52 -0700962 }
Mitchel Humpherys9de66db2016-06-07 11:09:44 -0700963
Mitchel Humpherys5c704e02015-12-21 15:06:34 -0800964 mapping->fast->notifier.notifier_call = fast_smmu_notify;
965 av8l_register_notify(&mapping->fast->notifier);
966
Patrick Daly1748f082017-09-05 21:32:52 -0700967 mapping->ops = &fast_smmu_dma_ops;
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700968 return 0;
Patrick Daly1748f082017-09-05 21:32:52 -0700969
Patrick Daly1748f082017-09-05 21:32:52 -0700970release_mapping:
971 kfree(mapping->fast->bitmap);
972 kfree(mapping->fast);
973 return err;
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700974}
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700975
976/**
Patrick Daly1748f082017-09-05 21:32:52 -0700977 * fast_smmu_release_mapping
978 * @kref: dma_iommu_mapping->kref
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700979 *
Patrick Daly1748f082017-09-05 21:32:52 -0700980 * Cleans up the given iommu mapping.
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700981 */
Patrick Daly1748f082017-09-05 21:32:52 -0700982void fast_smmu_release_mapping(struct kref *kref)
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700983{
Patrick Daly1748f082017-09-05 21:32:52 -0700984 struct dma_iommu_mapping *mapping =
985 container_of(kref, struct dma_iommu_mapping, kref);
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700986
Liam Mark4d4fbba2017-02-08 10:30:49 -0800987 kvfree(mapping->fast->bitmap);
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700988 kfree(mapping->fast);
Patrick Daly1748f082017-09-05 21:32:52 -0700989 iommu_domain_free(mapping->domain);
990 kfree(mapping);
Mitchel Humpherys0e43f0a2015-10-08 15:03:09 -0700991}