fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / arch / i386 / kernel / swiotlb.c
1 /*
2  * Dynamic DMA mapping support.
3  *
4  * This implementation is a fallback for platforms that do not support
5  * I/O TLBs (aka DMA address translation hardware).
6  * Copyright (C) 2000 Asit Mallick <Asit.K.Mallick@intel.com>
7  * Copyright (C) 2000 Goutham Rao <goutham.rao@intel.com>
8  * Copyright (C) 2000, 2003 Hewlett-Packard Co
9  *      David Mosberger-Tang <davidm@hpl.hp.com>
10  * Copyright (C) 2005 Keir Fraser <keir@xensource.com>
11  */
12
13 #include <linux/cache.h>
14 #include <linux/mm.h>
15 #include <linux/module.h>
16 #include <linux/pci.h>
17 #include <linux/spinlock.h>
18 #include <linux/string.h>
19 #include <linux/types.h>
20 #include <linux/ctype.h>
21 #include <linux/init.h>
22 #include <linux/bootmem.h>
23 #include <linux/highmem.h>
24 #include <asm/io.h>
25 #include <asm/pci.h>
26 #include <asm/dma.h>
27 #include <asm/uaccess.h>
28 #include <xen/interface/memory.h>
29 #include <asm-i386/mach-xen/asm/swiotlb.h>
30
31 int swiotlb;
32 EXPORT_SYMBOL(swiotlb);
33
34 #define OFFSET(val,align) ((unsigned long)((val) & ( (align) - 1)))
35
36 #define SG_ENT_PHYS_ADDRESS(sg) (page_to_bus((sg)->page) + (sg)->offset)
37
38 /*
39  * Maximum allowable number of contiguous slabs to map,
40  * must be a power of 2.  What is the appropriate value ?
41  * The complexity of {map,unmap}_single is linearly dependent on this value.
42  */
43 #define IO_TLB_SEGSIZE  128
44
45 /*
46  * log of the size of each IO TLB slab.  The number of slabs is command line
47  * controllable.
48  */
49 #define IO_TLB_SHIFT 11
50
51 int swiotlb_force;
52 static char *iotlb_virt_start;
53 static unsigned long iotlb_nslabs;
54
55 /*
56  * Used to do a quick range check in swiotlb_unmap_single and
57  * swiotlb_sync_single_*, to see if the memory was in fact allocated by this
58  * API.
59  */
60 static unsigned long iotlb_pfn_start, iotlb_pfn_end;
61
62 /* Does the given dma address reside within the swiotlb aperture? */
63 static inline int in_swiotlb_aperture(dma_addr_t dev_addr)
64 {
65         unsigned long pfn = mfn_to_local_pfn(dev_addr >> PAGE_SHIFT);
66         return (pfn_valid(pfn)
67                 && (pfn >= iotlb_pfn_start)
68                 && (pfn < iotlb_pfn_end));
69 }
70
71 /*
72  * When the IOMMU overflows we return a fallback buffer. This sets the size.
73  */
74 static unsigned long io_tlb_overflow = 32*1024;
75
76 void *io_tlb_overflow_buffer;
77
78 /*
79  * This is a free list describing the number of free entries available from
80  * each index
81  */
82 static unsigned int *io_tlb_list;
83 static unsigned int io_tlb_index;
84
85 /*
86  * We need to save away the original address corresponding to a mapped entry
87  * for the sync operations.
88  */
89 static struct phys_addr {
90         struct page *page;
91         unsigned int offset;
92 } *io_tlb_orig_addr;
93
94 /*
95  * Protect the above data structures in the map and unmap calls
96  */
97 static DEFINE_SPINLOCK(io_tlb_lock);
98
99 static int __init
100 setup_io_tlb_npages(char *str)
101 {
102         /* Unlike ia64, the size is aperture in megabytes, not 'slabs'! */
103         if (isdigit(*str)) {
104                 iotlb_nslabs = simple_strtoul(str, &str, 0) <<
105                         (20 - IO_TLB_SHIFT);
106                 iotlb_nslabs = ALIGN(iotlb_nslabs, IO_TLB_SEGSIZE);
107                 /* Round up to power of two (xen_create_contiguous_region). */
108                 while (iotlb_nslabs & (iotlb_nslabs-1))
109                         iotlb_nslabs += iotlb_nslabs & ~(iotlb_nslabs-1);
110         }
111         if (*str == ',')
112                 ++str;
113         /*
114          * NB. 'force' enables the swiotlb, but doesn't force its use for
115          * every DMA like it does on native Linux. 'off' forcibly disables
116          * use of the swiotlb.
117          */
118         if (!strcmp(str, "force"))
119                 swiotlb_force = 1;
120         else if (!strcmp(str, "off"))
121                 swiotlb_force = -1;
122         return 1;
123 }
124 __setup("swiotlb=", setup_io_tlb_npages);
125 /* make io_tlb_overflow tunable too? */
126
127 /*
128  * Statically reserve bounce buffer space and initialize bounce buffer data
129  * structures for the software IO TLB used to implement the PCI DMA API.
130  */
131 void
132 swiotlb_init_with_default_size (size_t default_size)
133 {
134         unsigned long i, bytes;
135
136         if (!iotlb_nslabs) {
137                 iotlb_nslabs = (default_size >> IO_TLB_SHIFT);
138                 iotlb_nslabs = ALIGN(iotlb_nslabs, IO_TLB_SEGSIZE);
139                 /* Round up to power of two (xen_create_contiguous_region). */
140                 while (iotlb_nslabs & (iotlb_nslabs-1))
141                         iotlb_nslabs += iotlb_nslabs & ~(iotlb_nslabs-1);
142         }
143
144         bytes = iotlb_nslabs * (1UL << IO_TLB_SHIFT);
145
146         /*
147          * Get IO TLB memory from the low pages
148          */
149         iotlb_virt_start = alloc_bootmem_low_pages(bytes);
150         if (!iotlb_virt_start)
151                 panic("Cannot allocate SWIOTLB buffer!\n"
152                       "Use dom0_mem Xen boot parameter to reserve\n"
153                       "some DMA memory (e.g., dom0_mem=-128M).\n");
154
155         for (i = 0; i < iotlb_nslabs; i += IO_TLB_SEGSIZE) {
156                 int rc = xen_create_contiguous_region(
157                         (unsigned long)iotlb_virt_start + (i << IO_TLB_SHIFT),
158                         get_order(IO_TLB_SEGSIZE << IO_TLB_SHIFT),
159                         IO_TLB_DMA_BITS);
160                 BUG_ON(rc);
161         }
162
163         /*
164          * Allocate and initialize the free list array.  This array is used
165          * to find contiguous free memory regions of size up to IO_TLB_SEGSIZE.
166          */
167         io_tlb_list = alloc_bootmem(iotlb_nslabs * sizeof(int));
168         for (i = 0; i < iotlb_nslabs; i++)
169                 io_tlb_list[i] = IO_TLB_SEGSIZE - OFFSET(i, IO_TLB_SEGSIZE);
170         io_tlb_index = 0;
171         io_tlb_orig_addr = alloc_bootmem(
172                 iotlb_nslabs * sizeof(*io_tlb_orig_addr));
173
174         /*
175          * Get the overflow emergency buffer
176          */
177         io_tlb_overflow_buffer = alloc_bootmem_low(io_tlb_overflow);
178
179         iotlb_pfn_start = __pa(iotlb_virt_start) >> PAGE_SHIFT;
180         iotlb_pfn_end   = iotlb_pfn_start + (bytes >> PAGE_SHIFT);
181
182         printk(KERN_INFO "Software IO TLB enabled: \n"
183                " Aperture:     %lu megabytes\n"
184                " Kernel range: 0x%016lx - 0x%016lx\n",
185                bytes >> 20,
186                (unsigned long)iotlb_virt_start,
187                (unsigned long)iotlb_virt_start + bytes);
188 }
189
190 void
191 swiotlb_init(void)
192 {
193         long ram_end;
194         size_t defsz = 64 * (1 << 20); /* 64MB default size */
195
196         if (swiotlb_force == 1) {
197                 swiotlb = 1;
198         } else if ((swiotlb_force != -1) &&
199                    is_running_on_xen() &&
200                    is_initial_xendomain()) {
201                 /* Domain 0 always has a swiotlb. */
202                 ram_end = HYPERVISOR_memory_op(XENMEM_maximum_ram_page, NULL);
203                 if (ram_end <= 0x7ffff)
204                         defsz = 2 * (1 << 20); /* 2MB on <2GB on systems. */
205                 swiotlb = 1;
206         }
207
208         if (swiotlb)
209                 swiotlb_init_with_default_size(defsz);
210         else
211                 printk(KERN_INFO "Software IO TLB disabled\n");
212 }
213
214 /*
215  * We use __copy_to_user_inatomic to transfer to the host buffer because the
216  * buffer may be mapped read-only (e.g, in blkback driver) but lower-level
217  * drivers map the buffer for DMA_BIDIRECTIONAL access. This causes an
218  * unnecessary copy from the aperture to the host buffer, and a page fault.
219  */
220 static void
221 __sync_single(struct phys_addr buffer, char *dma_addr, size_t size, int dir)
222 {
223         if (PageHighMem(buffer.page)) {
224                 size_t len, bytes;
225                 char *dev, *host, *kmp;
226                 len = size;
227                 while (len != 0) {
228                         if (((bytes = len) + buffer.offset) > PAGE_SIZE)
229                                 bytes = PAGE_SIZE - buffer.offset;
230                         kmp  = kmap_atomic(buffer.page, KM_SWIOTLB);
231                         dev  = dma_addr + size - len;
232                         host = kmp + buffer.offset;
233                         if (dir == DMA_FROM_DEVICE) {
234                                 if (__copy_to_user_inatomic(host, dev, bytes))
235                                         /* inaccessible */;
236                         } else
237                                 memcpy(dev, host, bytes);
238                         kunmap_atomic(kmp, KM_SWIOTLB);
239                         len -= bytes;
240                         buffer.page++;
241                         buffer.offset = 0;
242                 }
243         } else {
244                 char *host = (char *)phys_to_virt(
245                         page_to_pseudophys(buffer.page)) + buffer.offset;
246                 if (dir == DMA_FROM_DEVICE) {
247                         if (__copy_to_user_inatomic(host, dma_addr, size))
248                                 /* inaccessible */;
249                 } else if (dir == DMA_TO_DEVICE)
250                         memcpy(dma_addr, host, size);
251         }
252 }
253
254 /*
255  * Allocates bounce buffer and returns its kernel virtual address.
256  */
257 static void *
258 map_single(struct device *hwdev, struct phys_addr buffer, size_t size, int dir)
259 {
260         unsigned long flags;
261         char *dma_addr;
262         unsigned int nslots, stride, index, wrap;
263         int i;
264
265         /*
266          * For mappings greater than a page, we limit the stride (and
267          * hence alignment) to a page size.
268          */
269         nslots = ALIGN(size, 1 << IO_TLB_SHIFT) >> IO_TLB_SHIFT;
270         if (size > PAGE_SIZE)
271                 stride = (1 << (PAGE_SHIFT - IO_TLB_SHIFT));
272         else
273                 stride = 1;
274
275         BUG_ON(!nslots);
276
277         /*
278          * Find suitable number of IO TLB entries size that will fit this
279          * request and allocate a buffer from that IO TLB pool.
280          */
281         spin_lock_irqsave(&io_tlb_lock, flags);
282         {
283                 wrap = index = ALIGN(io_tlb_index, stride);
284
285                 if (index >= iotlb_nslabs)
286                         wrap = index = 0;
287
288                 do {
289                         /*
290                          * If we find a slot that indicates we have 'nslots'
291                          * number of contiguous buffers, we allocate the
292                          * buffers from that slot and mark the entries as '0'
293                          * indicating unavailable.
294                          */
295                         if (io_tlb_list[index] >= nslots) {
296                                 int count = 0;
297
298                                 for (i = index; i < (int)(index + nslots); i++)
299                                         io_tlb_list[i] = 0;
300                                 for (i = index - 1;
301                                      (OFFSET(i, IO_TLB_SEGSIZE) !=
302                                       IO_TLB_SEGSIZE -1) && io_tlb_list[i];
303                                      i--)
304                                         io_tlb_list[i] = ++count;
305                                 dma_addr = iotlb_virt_start +
306                                         (index << IO_TLB_SHIFT);
307
308                                 /*
309                                  * Update the indices to avoid searching in
310                                  * the next round.
311                                  */
312                                 io_tlb_index = 
313                                         ((index + nslots) < iotlb_nslabs
314                                          ? (index + nslots) : 0);
315
316                                 goto found;
317                         }
318                         index += stride;
319                         if (index >= iotlb_nslabs)
320                                 index = 0;
321                 } while (index != wrap);
322
323                 spin_unlock_irqrestore(&io_tlb_lock, flags);
324                 return NULL;
325         }
326   found:
327         spin_unlock_irqrestore(&io_tlb_lock, flags);
328
329         /*
330          * Save away the mapping from the original address to the DMA address.
331          * This is needed when we sync the memory.  Then we sync the buffer if
332          * needed.
333          */
334         io_tlb_orig_addr[index] = buffer;
335         if ((dir == DMA_TO_DEVICE) || (dir == DMA_BIDIRECTIONAL))
336                 __sync_single(buffer, dma_addr, size, DMA_TO_DEVICE);
337
338         return dma_addr;
339 }
340
341 /*
342  * dma_addr is the kernel virtual address of the bounce buffer to unmap.
343  */
344 static void
345 unmap_single(struct device *hwdev, char *dma_addr, size_t size, int dir)
346 {
347         unsigned long flags;
348         int i, count, nslots = ALIGN(size, 1 << IO_TLB_SHIFT) >> IO_TLB_SHIFT;
349         int index = (dma_addr - iotlb_virt_start) >> IO_TLB_SHIFT;
350         struct phys_addr buffer = io_tlb_orig_addr[index];
351
352         /*
353          * First, sync the memory before unmapping the entry
354          */
355         if ((dir == DMA_FROM_DEVICE) || (dir == DMA_BIDIRECTIONAL))
356                 __sync_single(buffer, dma_addr, size, DMA_FROM_DEVICE);
357
358         /*
359          * Return the buffer to the free list by setting the corresponding
360          * entries to indicate the number of contigous entries available.
361          * While returning the entries to the free list, we merge the entries
362          * with slots below and above the pool being returned.
363          */
364         spin_lock_irqsave(&io_tlb_lock, flags);
365         {
366                 count = ((index + nslots) < ALIGN(index + 1, IO_TLB_SEGSIZE) ?
367                          io_tlb_list[index + nslots] : 0);
368                 /*
369                  * Step 1: return the slots to the free list, merging the
370                  * slots with superceeding slots
371                  */
372                 for (i = index + nslots - 1; i >= index; i--)
373                         io_tlb_list[i] = ++count;
374                 /*
375                  * Step 2: merge the returned slots with the preceding slots,
376                  * if available (non zero)
377                  */
378                 for (i = index - 1;
379                      (OFFSET(i, IO_TLB_SEGSIZE) !=
380                       IO_TLB_SEGSIZE -1) && io_tlb_list[i];
381                      i--)
382                         io_tlb_list[i] = ++count;
383         }
384         spin_unlock_irqrestore(&io_tlb_lock, flags);
385 }
386
387 static void
388 sync_single(struct device *hwdev, char *dma_addr, size_t size, int dir)
389 {
390         int index = (dma_addr - iotlb_virt_start) >> IO_TLB_SHIFT;
391         struct phys_addr buffer = io_tlb_orig_addr[index];
392         BUG_ON((dir != DMA_FROM_DEVICE) && (dir != DMA_TO_DEVICE));
393         __sync_single(buffer, dma_addr, size, dir);
394 }
395
396 static void
397 swiotlb_full(struct device *dev, size_t size, int dir, int do_panic)
398 {
399         /*
400          * Ran out of IOMMU space for this operation. This is very bad.
401          * Unfortunately the drivers cannot handle this operation properly.
402          * unless they check for pci_dma_mapping_error (most don't)
403          * When the mapping is small enough return a static buffer to limit
404          * the damage, or panic when the transfer is too big.
405          */
406         printk(KERN_ERR "PCI-DMA: Out of SW-IOMMU space for %lu bytes at "
407                "device %s\n", (unsigned long)size, dev ? dev->bus_id : "?");
408
409         if (size > io_tlb_overflow && do_panic) {
410                 if (dir == PCI_DMA_FROMDEVICE || dir == PCI_DMA_BIDIRECTIONAL)
411                         panic("PCI-DMA: Memory would be corrupted\n");
412                 if (dir == PCI_DMA_TODEVICE || dir == PCI_DMA_BIDIRECTIONAL)
413                         panic("PCI-DMA: Random memory would be DMAed\n");
414         }
415 }
416
417 /*
418  * Map a single buffer of the indicated size for DMA in streaming mode.  The
419  * PCI address to use is returned.
420  *
421  * Once the device is given the dma address, the device owns this memory until
422  * either swiotlb_unmap_single or swiotlb_dma_sync_single is performed.
423  */
424 dma_addr_t
425 swiotlb_map_single(struct device *hwdev, void *ptr, size_t size, int dir)
426 {
427         dma_addr_t dev_addr = virt_to_bus(ptr);
428         void *map;
429         struct phys_addr buffer;
430
431         BUG_ON(dir == DMA_NONE);
432
433         /*
434          * If the pointer passed in happens to be in the device's DMA window,
435          * we can safely return the device addr and not worry about bounce
436          * buffering it.
437          */
438         if (!range_straddles_page_boundary(ptr, size) &&
439             !address_needs_mapping(hwdev, dev_addr))
440                 return dev_addr;
441
442         /*
443          * Oh well, have to allocate and map a bounce buffer.
444          */
445         buffer.page   = virt_to_page(ptr);
446         buffer.offset = (unsigned long)ptr & ~PAGE_MASK;
447         map = map_single(hwdev, buffer, size, dir);
448         if (!map) {
449                 swiotlb_full(hwdev, size, dir, 1);
450                 map = io_tlb_overflow_buffer;
451         }
452
453         dev_addr = virt_to_bus(map);
454         return dev_addr;
455 }
456
457 /*
458  * Unmap a single streaming mode DMA translation.  The dma_addr and size must
459  * match what was provided for in a previous swiotlb_map_single call.  All
460  * other usages are undefined.
461  *
462  * After this call, reads by the cpu to the buffer are guaranteed to see
463  * whatever the device wrote there.
464  */
465 void
466 swiotlb_unmap_single(struct device *hwdev, dma_addr_t dev_addr, size_t size,
467                      int dir)
468 {
469         BUG_ON(dir == DMA_NONE);
470         if (in_swiotlb_aperture(dev_addr))
471                 unmap_single(hwdev, bus_to_virt(dev_addr), size, dir);
472 }
473
474 /*
475  * Make physical memory consistent for a single streaming mode DMA translation
476  * after a transfer.
477  *
478  * If you perform a swiotlb_map_single() but wish to interrogate the buffer
479  * using the cpu, yet do not wish to teardown the PCI dma mapping, you must
480  * call this function before doing so.  At the next point you give the PCI dma
481  * address back to the card, you must first perform a
482  * swiotlb_dma_sync_for_device, and then the device again owns the buffer
483  */
484 void
485 swiotlb_sync_single_for_cpu(struct device *hwdev, dma_addr_t dev_addr,
486                             size_t size, int dir)
487 {
488         BUG_ON(dir == DMA_NONE);
489         if (in_swiotlb_aperture(dev_addr))
490                 sync_single(hwdev, bus_to_virt(dev_addr), size, dir);
491 }
492
493 void
494 swiotlb_sync_single_for_device(struct device *hwdev, dma_addr_t dev_addr,
495                                size_t size, int dir)
496 {
497         BUG_ON(dir == DMA_NONE);
498         if (in_swiotlb_aperture(dev_addr))
499                 sync_single(hwdev, bus_to_virt(dev_addr), size, dir);
500 }
501
502 /*
503  * Map a set of buffers described by scatterlist in streaming mode for DMA.
504  * This is the scatter-gather version of the above swiotlb_map_single
505  * interface.  Here the scatter gather list elements are each tagged with the
506  * appropriate dma address and length.  They are obtained via
507  * sg_dma_{address,length}(SG).
508  *
509  * NOTE: An implementation may be able to use a smaller number of
510  *       DMA address/length pairs than there are SG table elements.
511  *       (for example via virtual mapping capabilities)
512  *       The routine returns the number of addr/length pairs actually
513  *       used, at most nents.
514  *
515  * Device ownership issues as mentioned above for swiotlb_map_single are the
516  * same here.
517  */
518 int
519 swiotlb_map_sg(struct device *hwdev, struct scatterlist *sg, int nelems,
520                int dir)
521 {
522         struct phys_addr buffer;
523         dma_addr_t dev_addr;
524         char *map;
525         int i;
526
527         BUG_ON(dir == DMA_NONE);
528
529         for (i = 0; i < nelems; i++, sg++) {
530                 dev_addr = SG_ENT_PHYS_ADDRESS(sg);
531                 if (address_needs_mapping(hwdev, dev_addr)) {
532                         buffer.page   = sg->page;
533                         buffer.offset = sg->offset;
534                         map = map_single(hwdev, buffer, sg->length, dir);
535                         if (!map) {
536                                 /* Don't panic here, we expect map_sg users
537                                    to do proper error handling. */
538                                 swiotlb_full(hwdev, sg->length, dir, 0);
539                                 swiotlb_unmap_sg(hwdev, sg - i, i, dir);
540                                 sg[0].dma_length = 0;
541                                 return 0;
542                         }
543                         sg->dma_address = (dma_addr_t)virt_to_bus(map);
544                 } else
545                         sg->dma_address = dev_addr;
546                 sg->dma_length = sg->length;
547         }
548         return nelems;
549 }
550
551 /*
552  * Unmap a set of streaming mode DMA translations.  Again, cpu read rules
553  * concerning calls here are the same as for swiotlb_unmap_single() above.
554  */
555 void
556 swiotlb_unmap_sg(struct device *hwdev, struct scatterlist *sg, int nelems,
557                  int dir)
558 {
559         int i;
560
561         BUG_ON(dir == DMA_NONE);
562
563         for (i = 0; i < nelems; i++, sg++)
564                 if (sg->dma_address != SG_ENT_PHYS_ADDRESS(sg))
565                         unmap_single(hwdev, 
566                                      (void *)bus_to_virt(sg->dma_address),
567                                      sg->dma_length, dir);
568 }
569
570 /*
571  * Make physical memory consistent for a set of streaming mode DMA translations
572  * after a transfer.
573  *
574  * The same as swiotlb_sync_single_* but for a scatter-gather list, same rules
575  * and usage.
576  */
577 void
578 swiotlb_sync_sg_for_cpu(struct device *hwdev, struct scatterlist *sg,
579                         int nelems, int dir)
580 {
581         int i;
582
583         BUG_ON(dir == DMA_NONE);
584
585         for (i = 0; i < nelems; i++, sg++)
586                 if (sg->dma_address != SG_ENT_PHYS_ADDRESS(sg))
587                         sync_single(hwdev,
588                                     (void *)bus_to_virt(sg->dma_address),
589                                     sg->dma_length, dir);
590 }
591
592 void
593 swiotlb_sync_sg_for_device(struct device *hwdev, struct scatterlist *sg,
594                            int nelems, int dir)
595 {
596         int i;
597
598         BUG_ON(dir == DMA_NONE);
599
600         for (i = 0; i < nelems; i++, sg++)
601                 if (sg->dma_address != SG_ENT_PHYS_ADDRESS(sg))
602                         sync_single(hwdev,
603                                     (void *)bus_to_virt(sg->dma_address),
604                                     sg->dma_length, dir);
605 }
606
607 dma_addr_t
608 swiotlb_map_page(struct device *hwdev, struct page *page,
609                  unsigned long offset, size_t size,
610                  enum dma_data_direction direction)
611 {
612         struct phys_addr buffer;
613         dma_addr_t dev_addr;
614         char *map;
615
616         dev_addr = page_to_bus(page) + offset;
617         if (address_needs_mapping(hwdev, dev_addr)) {
618                 buffer.page   = page;
619                 buffer.offset = offset;
620                 map = map_single(hwdev, buffer, size, direction);
621                 if (!map) {
622                         swiotlb_full(hwdev, size, direction, 1);
623                         map = io_tlb_overflow_buffer;
624                 }
625                 dev_addr = (dma_addr_t)virt_to_bus(map);
626         }
627
628         return dev_addr;
629 }
630
631 void
632 swiotlb_unmap_page(struct device *hwdev, dma_addr_t dma_address,
633                    size_t size, enum dma_data_direction direction)
634 {
635         BUG_ON(!valid_dma_direction(direction));
636         if (in_swiotlb_aperture(dma_address))
637                 unmap_single(hwdev, bus_to_virt(dma_address), size, direction);
638 }
639
640 int
641 swiotlb_dma_mapping_error(dma_addr_t dma_addr)
642 {
643         return (dma_addr == virt_to_bus(io_tlb_overflow_buffer));
644 }
645
646 /*
647  * Return whether the given PCI device DMA address mask can be supported
648  * properly.  For example, if your device can only drive the low 24-bits
649  * during PCI bus mastering, then you would pass 0x00ffffff as the mask to
650  * this function.
651  */
652 int
653 swiotlb_dma_supported (struct device *hwdev, u64 mask)
654 {
655         return (mask >= ((1UL << IO_TLB_DMA_BITS) - 1));
656 }
657
658 EXPORT_SYMBOL(swiotlb_init);
659 EXPORT_SYMBOL(swiotlb_map_single);
660 EXPORT_SYMBOL(swiotlb_unmap_single);
661 EXPORT_SYMBOL(swiotlb_map_sg);
662 EXPORT_SYMBOL(swiotlb_unmap_sg);
663 EXPORT_SYMBOL(swiotlb_sync_single_for_cpu);
664 EXPORT_SYMBOL(swiotlb_sync_single_for_device);
665 EXPORT_SYMBOL(swiotlb_sync_sg_for_cpu);
666 EXPORT_SYMBOL(swiotlb_sync_sg_for_device);
667 EXPORT_SYMBOL(swiotlb_map_page);
668 EXPORT_SYMBOL(swiotlb_unmap_page);
669 EXPORT_SYMBOL(swiotlb_dma_mapping_error);
670 EXPORT_SYMBOL(swiotlb_dma_supported);