Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Dynamic DMA mapping support. |
| 3 | * |
Jan Beulich | 563aaf0 | 2007-02-05 18:51:25 -0800 | [diff] [blame] | 4 | * This implementation is a fallback for platforms that do not support |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | * |
| 11 | * 03/05/07 davidm Switch from PCI-DMA to generic device DMA API. |
| 12 | * 00/12/13 davidm Rename to swiotlb.c and add mark_clean() to avoid |
| 13 | * unnecessary i-cache flushing. |
John W. Linville | 569c8bf | 2005-09-29 14:45:24 -0700 | [diff] [blame] | 14 | * 04/07/.. ak Better overflow handling. Assorted fixes. |
| 15 | * 05/09/10 linville Add support for syncing ranges, support syncing for |
| 16 | * DMA_BIDIRECTIONAL mappings, miscellaneous cleanup. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | */ |
| 18 | |
| 19 | #include <linux/cache.h> |
Tony Luck | 17e5ad6 | 2005-09-29 15:52:13 -0700 | [diff] [blame] | 20 | #include <linux/dma-mapping.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/mm.h> |
| 22 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/spinlock.h> |
Jeremy Fitzhardinge | 8c5df16 | 2008-12-16 12:17:26 -0800 | [diff] [blame] | 24 | #include <linux/swiotlb.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <linux/string.h> |
Ian Campbell | 0016fde | 2008-12-16 12:17:27 -0800 | [diff] [blame] | 26 | #include <linux/swiotlb.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <linux/types.h> |
| 28 | #include <linux/ctype.h> |
| 29 | |
| 30 | #include <asm/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <asm/dma.h> |
Tony Luck | 17e5ad6 | 2005-09-29 15:52:13 -0700 | [diff] [blame] | 32 | #include <asm/scatterlist.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
| 34 | #include <linux/init.h> |
| 35 | #include <linux/bootmem.h> |
FUJITA Tomonori | a852250 | 2008-04-29 00:59:36 -0700 | [diff] [blame] | 36 | #include <linux/iommu-helper.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
| 38 | #define OFFSET(val,align) ((unsigned long) \ |
| 39 | ( (val) & ( (align) - 1))) |
| 40 | |
Jens Axboe | f9527f1 | 2007-10-22 19:44:53 +0200 | [diff] [blame] | 41 | #define SG_ENT_VIRT_ADDRESS(sg) (sg_virt((sg))) |
Jan Beulich | 93fbff6 | 2007-02-05 18:49:45 -0800 | [diff] [blame] | 42 | #define SG_ENT_PHYS_ADDRESS(sg) virt_to_bus(SG_ENT_VIRT_ADDRESS(sg)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
Alex Williamson | 0b9afed | 2005-09-06 11:20:49 -0600 | [diff] [blame] | 44 | #define SLABS_PER_PAGE (1 << (PAGE_SHIFT - IO_TLB_SHIFT)) |
| 45 | |
| 46 | /* |
| 47 | * Minimum IO TLB size to bother booting with. Systems with mainly |
| 48 | * 64bit capable cards will only lightly use the swiotlb. If we can't |
| 49 | * allocate a contiguous 1MB, we're probably in trouble anyway. |
| 50 | */ |
| 51 | #define IO_TLB_MIN_SLABS ((1<<20) >> IO_TLB_SHIFT) |
| 52 | |
John W. Linville | de69e0f | 2005-09-29 14:44:57 -0700 | [diff] [blame] | 53 | /* |
| 54 | * Enumeration for sync targets |
| 55 | */ |
| 56 | enum dma_sync_target { |
| 57 | SYNC_FOR_CPU = 0, |
| 58 | SYNC_FOR_DEVICE = 1, |
| 59 | }; |
| 60 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | int swiotlb_force; |
| 62 | |
| 63 | /* |
| 64 | * Used to do a quick range check in swiotlb_unmap_single and |
| 65 | * swiotlb_sync_single_*, to see if the memory was in fact allocated by this |
| 66 | * API. |
| 67 | */ |
| 68 | static char *io_tlb_start, *io_tlb_end; |
| 69 | |
| 70 | /* |
| 71 | * The number of IO TLB blocks (in groups of 64) betweeen io_tlb_start and |
| 72 | * io_tlb_end. This is command line adjustable via setup_io_tlb_npages. |
| 73 | */ |
| 74 | static unsigned long io_tlb_nslabs; |
| 75 | |
| 76 | /* |
| 77 | * When the IOMMU overflows we return a fallback buffer. This sets the size. |
| 78 | */ |
| 79 | static unsigned long io_tlb_overflow = 32*1024; |
| 80 | |
| 81 | void *io_tlb_overflow_buffer; |
| 82 | |
| 83 | /* |
| 84 | * This is a free list describing the number of free entries available from |
| 85 | * each index |
| 86 | */ |
| 87 | static unsigned int *io_tlb_list; |
| 88 | static unsigned int io_tlb_index; |
| 89 | |
| 90 | /* |
| 91 | * We need to save away the original address corresponding to a mapped entry |
| 92 | * for the sync operations. |
| 93 | */ |
Tony Luck | 25667d6 | 2007-03-06 13:31:45 -0800 | [diff] [blame] | 94 | static unsigned char **io_tlb_orig_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
| 96 | /* |
| 97 | * Protect the above data structures in the map and unmap calls |
| 98 | */ |
| 99 | static DEFINE_SPINLOCK(io_tlb_lock); |
| 100 | |
| 101 | static int __init |
| 102 | setup_io_tlb_npages(char *str) |
| 103 | { |
| 104 | if (isdigit(*str)) { |
Alex Williamson | e8579e7 | 2005-08-04 13:06:00 -0700 | [diff] [blame] | 105 | io_tlb_nslabs = simple_strtoul(str, &str, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | /* avoid tail segment of size < IO_TLB_SEGSIZE */ |
| 107 | io_tlb_nslabs = ALIGN(io_tlb_nslabs, IO_TLB_SEGSIZE); |
| 108 | } |
| 109 | if (*str == ',') |
| 110 | ++str; |
| 111 | if (!strcmp(str, "force")) |
| 112 | swiotlb_force = 1; |
| 113 | return 1; |
| 114 | } |
| 115 | __setup("swiotlb=", setup_io_tlb_npages); |
| 116 | /* make io_tlb_overflow tunable too? */ |
| 117 | |
Jeremy Fitzhardinge | 8c5df16 | 2008-12-16 12:17:26 -0800 | [diff] [blame] | 118 | void * __weak swiotlb_alloc_boot(size_t size, unsigned long nslabs) |
| 119 | { |
| 120 | return alloc_bootmem_low_pages(size); |
| 121 | } |
| 122 | |
| 123 | void * __weak swiotlb_alloc(unsigned order, unsigned long nslabs) |
| 124 | { |
| 125 | return (void *)__get_free_pages(GFP_DMA | __GFP_NOWARN, order); |
| 126 | } |
| 127 | |
Ian Campbell | e08e1f7 | 2008-12-16 12:17:30 -0800 | [diff] [blame] | 128 | dma_addr_t __weak swiotlb_phys_to_bus(phys_addr_t paddr) |
| 129 | { |
| 130 | return paddr; |
| 131 | } |
| 132 | |
| 133 | phys_addr_t __weak swiotlb_bus_to_phys(dma_addr_t baddr) |
| 134 | { |
| 135 | return baddr; |
| 136 | } |
| 137 | |
| 138 | static dma_addr_t swiotlb_virt_to_bus(volatile void *address) |
| 139 | { |
| 140 | return swiotlb_phys_to_bus(virt_to_phys(address)); |
| 141 | } |
| 142 | |
| 143 | static void *swiotlb_bus_to_virt(dma_addr_t address) |
| 144 | { |
| 145 | return phys_to_virt(swiotlb_bus_to_phys(address)); |
| 146 | } |
| 147 | |
Ian Campbell | b81ea27 | 2008-12-16 12:17:31 -0800 | [diff] [blame^] | 148 | int __weak swiotlb_arch_range_needs_mapping(void *ptr, size_t size) |
| 149 | { |
| 150 | return 0; |
| 151 | } |
| 152 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | /* |
| 154 | * Statically reserve bounce buffer space and initialize bounce buffer data |
Tony Luck | 17e5ad6 | 2005-09-29 15:52:13 -0700 | [diff] [blame] | 155 | * structures for the software IO TLB used to implement the DMA API. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | */ |
Jan Beulich | 563aaf0 | 2007-02-05 18:51:25 -0800 | [diff] [blame] | 157 | void __init |
| 158 | swiotlb_init_with_default_size(size_t default_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | { |
Jan Beulich | 563aaf0 | 2007-02-05 18:51:25 -0800 | [diff] [blame] | 160 | unsigned long i, bytes; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
| 162 | if (!io_tlb_nslabs) { |
Alex Williamson | e8579e7 | 2005-08-04 13:06:00 -0700 | [diff] [blame] | 163 | io_tlb_nslabs = (default_size >> IO_TLB_SHIFT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | io_tlb_nslabs = ALIGN(io_tlb_nslabs, IO_TLB_SEGSIZE); |
| 165 | } |
| 166 | |
Jan Beulich | 563aaf0 | 2007-02-05 18:51:25 -0800 | [diff] [blame] | 167 | bytes = io_tlb_nslabs << IO_TLB_SHIFT; |
| 168 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | /* |
| 170 | * Get IO TLB memory from the low pages |
| 171 | */ |
Jeremy Fitzhardinge | 8c5df16 | 2008-12-16 12:17:26 -0800 | [diff] [blame] | 172 | io_tlb_start = swiotlb_alloc_boot(bytes, io_tlb_nslabs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | if (!io_tlb_start) |
| 174 | panic("Cannot allocate SWIOTLB buffer"); |
Jan Beulich | 563aaf0 | 2007-02-05 18:51:25 -0800 | [diff] [blame] | 175 | io_tlb_end = io_tlb_start + bytes; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | |
| 177 | /* |
| 178 | * Allocate and initialize the free list array. This array is used |
| 179 | * to find contiguous free memory regions of size up to IO_TLB_SEGSIZE |
| 180 | * between io_tlb_start and io_tlb_end. |
| 181 | */ |
| 182 | io_tlb_list = alloc_bootmem(io_tlb_nslabs * sizeof(int)); |
Tony Luck | 25667d6 | 2007-03-06 13:31:45 -0800 | [diff] [blame] | 183 | for (i = 0; i < io_tlb_nslabs; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | io_tlb_list[i] = IO_TLB_SEGSIZE - OFFSET(i, IO_TLB_SEGSIZE); |
| 185 | io_tlb_index = 0; |
Tony Luck | 25667d6 | 2007-03-06 13:31:45 -0800 | [diff] [blame] | 186 | io_tlb_orig_addr = alloc_bootmem(io_tlb_nslabs * sizeof(char *)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | |
| 188 | /* |
| 189 | * Get the overflow emergency buffer |
| 190 | */ |
| 191 | io_tlb_overflow_buffer = alloc_bootmem_low(io_tlb_overflow); |
Jan Beulich | 563aaf0 | 2007-02-05 18:51:25 -0800 | [diff] [blame] | 192 | if (!io_tlb_overflow_buffer) |
| 193 | panic("Cannot allocate SWIOTLB overflow buffer!\n"); |
| 194 | |
Tony Luck | 25667d6 | 2007-03-06 13:31:45 -0800 | [diff] [blame] | 195 | printk(KERN_INFO "Placing software IO TLB between 0x%lx - 0x%lx\n", |
Ian Campbell | e08e1f7 | 2008-12-16 12:17:30 -0800 | [diff] [blame] | 196 | swiotlb_virt_to_bus(io_tlb_start), swiotlb_virt_to_bus(io_tlb_end)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | } |
| 198 | |
Jan Beulich | 563aaf0 | 2007-02-05 18:51:25 -0800 | [diff] [blame] | 199 | void __init |
| 200 | swiotlb_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | { |
Tony Luck | 25667d6 | 2007-03-06 13:31:45 -0800 | [diff] [blame] | 202 | swiotlb_init_with_default_size(64 * (1<<20)); /* default to 64MB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | } |
| 204 | |
Alex Williamson | 0b9afed | 2005-09-06 11:20:49 -0600 | [diff] [blame] | 205 | /* |
| 206 | * Systems with larger DMA zones (those that don't support ISA) can |
| 207 | * initialize the swiotlb later using the slab allocator if needed. |
| 208 | * This should be just like above, but with some error catching. |
| 209 | */ |
| 210 | int |
Jan Beulich | 563aaf0 | 2007-02-05 18:51:25 -0800 | [diff] [blame] | 211 | swiotlb_late_init_with_default_size(size_t default_size) |
Alex Williamson | 0b9afed | 2005-09-06 11:20:49 -0600 | [diff] [blame] | 212 | { |
Jan Beulich | 563aaf0 | 2007-02-05 18:51:25 -0800 | [diff] [blame] | 213 | unsigned long i, bytes, req_nslabs = io_tlb_nslabs; |
Alex Williamson | 0b9afed | 2005-09-06 11:20:49 -0600 | [diff] [blame] | 214 | unsigned int order; |
| 215 | |
| 216 | if (!io_tlb_nslabs) { |
| 217 | io_tlb_nslabs = (default_size >> IO_TLB_SHIFT); |
| 218 | io_tlb_nslabs = ALIGN(io_tlb_nslabs, IO_TLB_SEGSIZE); |
| 219 | } |
| 220 | |
| 221 | /* |
| 222 | * Get IO TLB memory from the low pages |
| 223 | */ |
Jan Beulich | 563aaf0 | 2007-02-05 18:51:25 -0800 | [diff] [blame] | 224 | order = get_order(io_tlb_nslabs << IO_TLB_SHIFT); |
Alex Williamson | 0b9afed | 2005-09-06 11:20:49 -0600 | [diff] [blame] | 225 | io_tlb_nslabs = SLABS_PER_PAGE << order; |
Jan Beulich | 563aaf0 | 2007-02-05 18:51:25 -0800 | [diff] [blame] | 226 | bytes = io_tlb_nslabs << IO_TLB_SHIFT; |
Alex Williamson | 0b9afed | 2005-09-06 11:20:49 -0600 | [diff] [blame] | 227 | |
| 228 | while ((SLABS_PER_PAGE << order) > IO_TLB_MIN_SLABS) { |
Jeremy Fitzhardinge | 8c5df16 | 2008-12-16 12:17:26 -0800 | [diff] [blame] | 229 | io_tlb_start = swiotlb_alloc(order, io_tlb_nslabs); |
Alex Williamson | 0b9afed | 2005-09-06 11:20:49 -0600 | [diff] [blame] | 230 | if (io_tlb_start) |
| 231 | break; |
| 232 | order--; |
| 233 | } |
| 234 | |
| 235 | if (!io_tlb_start) |
| 236 | goto cleanup1; |
| 237 | |
Jan Beulich | 563aaf0 | 2007-02-05 18:51:25 -0800 | [diff] [blame] | 238 | if (order != get_order(bytes)) { |
Alex Williamson | 0b9afed | 2005-09-06 11:20:49 -0600 | [diff] [blame] | 239 | printk(KERN_WARNING "Warning: only able to allocate %ld MB " |
| 240 | "for software IO TLB\n", (PAGE_SIZE << order) >> 20); |
| 241 | io_tlb_nslabs = SLABS_PER_PAGE << order; |
Jan Beulich | 563aaf0 | 2007-02-05 18:51:25 -0800 | [diff] [blame] | 242 | bytes = io_tlb_nslabs << IO_TLB_SHIFT; |
Alex Williamson | 0b9afed | 2005-09-06 11:20:49 -0600 | [diff] [blame] | 243 | } |
Jan Beulich | 563aaf0 | 2007-02-05 18:51:25 -0800 | [diff] [blame] | 244 | io_tlb_end = io_tlb_start + bytes; |
| 245 | memset(io_tlb_start, 0, bytes); |
Alex Williamson | 0b9afed | 2005-09-06 11:20:49 -0600 | [diff] [blame] | 246 | |
| 247 | /* |
| 248 | * Allocate and initialize the free list array. This array is used |
| 249 | * to find contiguous free memory regions of size up to IO_TLB_SEGSIZE |
| 250 | * between io_tlb_start and io_tlb_end. |
| 251 | */ |
| 252 | io_tlb_list = (unsigned int *)__get_free_pages(GFP_KERNEL, |
| 253 | get_order(io_tlb_nslabs * sizeof(int))); |
| 254 | if (!io_tlb_list) |
| 255 | goto cleanup2; |
| 256 | |
| 257 | for (i = 0; i < io_tlb_nslabs; i++) |
| 258 | io_tlb_list[i] = IO_TLB_SEGSIZE - OFFSET(i, IO_TLB_SEGSIZE); |
| 259 | io_tlb_index = 0; |
| 260 | |
Tony Luck | 25667d6 | 2007-03-06 13:31:45 -0800 | [diff] [blame] | 261 | io_tlb_orig_addr = (unsigned char **)__get_free_pages(GFP_KERNEL, |
| 262 | get_order(io_tlb_nslabs * sizeof(char *))); |
Alex Williamson | 0b9afed | 2005-09-06 11:20:49 -0600 | [diff] [blame] | 263 | if (!io_tlb_orig_addr) |
| 264 | goto cleanup3; |
| 265 | |
Tony Luck | 25667d6 | 2007-03-06 13:31:45 -0800 | [diff] [blame] | 266 | memset(io_tlb_orig_addr, 0, io_tlb_nslabs * sizeof(char *)); |
Alex Williamson | 0b9afed | 2005-09-06 11:20:49 -0600 | [diff] [blame] | 267 | |
| 268 | /* |
| 269 | * Get the overflow emergency buffer |
| 270 | */ |
| 271 | io_tlb_overflow_buffer = (void *)__get_free_pages(GFP_DMA, |
| 272 | get_order(io_tlb_overflow)); |
| 273 | if (!io_tlb_overflow_buffer) |
| 274 | goto cleanup4; |
| 275 | |
Tony Luck | 25667d6 | 2007-03-06 13:31:45 -0800 | [diff] [blame] | 276 | printk(KERN_INFO "Placing %luMB software IO TLB between 0x%lx - " |
| 277 | "0x%lx\n", bytes >> 20, |
Ian Campbell | e08e1f7 | 2008-12-16 12:17:30 -0800 | [diff] [blame] | 278 | swiotlb_virt_to_bus(io_tlb_start), swiotlb_virt_to_bus(io_tlb_end)); |
Alex Williamson | 0b9afed | 2005-09-06 11:20:49 -0600 | [diff] [blame] | 279 | |
| 280 | return 0; |
| 281 | |
| 282 | cleanup4: |
Tony Luck | 25667d6 | 2007-03-06 13:31:45 -0800 | [diff] [blame] | 283 | free_pages((unsigned long)io_tlb_orig_addr, get_order(io_tlb_nslabs * |
| 284 | sizeof(char *))); |
Alex Williamson | 0b9afed | 2005-09-06 11:20:49 -0600 | [diff] [blame] | 285 | io_tlb_orig_addr = NULL; |
| 286 | cleanup3: |
Tony Luck | 25667d6 | 2007-03-06 13:31:45 -0800 | [diff] [blame] | 287 | free_pages((unsigned long)io_tlb_list, get_order(io_tlb_nslabs * |
| 288 | sizeof(int))); |
Alex Williamson | 0b9afed | 2005-09-06 11:20:49 -0600 | [diff] [blame] | 289 | io_tlb_list = NULL; |
Alex Williamson | 0b9afed | 2005-09-06 11:20:49 -0600 | [diff] [blame] | 290 | cleanup2: |
Jan Beulich | 563aaf0 | 2007-02-05 18:51:25 -0800 | [diff] [blame] | 291 | io_tlb_end = NULL; |
Alex Williamson | 0b9afed | 2005-09-06 11:20:49 -0600 | [diff] [blame] | 292 | free_pages((unsigned long)io_tlb_start, order); |
| 293 | io_tlb_start = NULL; |
| 294 | cleanup1: |
| 295 | io_tlb_nslabs = req_nslabs; |
| 296 | return -ENOMEM; |
| 297 | } |
| 298 | |
Andrew Morton | be6b026 | 2007-02-12 00:52:17 -0800 | [diff] [blame] | 299 | static int |
FUJITA Tomonori | 2797982 | 2008-09-10 01:06:49 +0900 | [diff] [blame] | 300 | address_needs_mapping(struct device *hwdev, dma_addr_t addr, size_t size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | { |
FUJITA Tomonori | 07a2c01 | 2008-09-19 02:02:05 +0900 | [diff] [blame] | 302 | return !is_buffer_dma_capable(dma_get_mask(hwdev), addr, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | } |
| 304 | |
Ian Campbell | b81ea27 | 2008-12-16 12:17:31 -0800 | [diff] [blame^] | 305 | static inline int range_needs_mapping(void *ptr, size_t size) |
| 306 | { |
| 307 | return swiotlb_force || swiotlb_arch_range_needs_mapping(ptr, size); |
| 308 | } |
| 309 | |
FUJITA Tomonori | 640aebf | 2008-09-08 18:53:50 +0900 | [diff] [blame] | 310 | static int is_swiotlb_buffer(char *addr) |
| 311 | { |
| 312 | return addr >= io_tlb_start && addr < io_tlb_end; |
| 313 | } |
| 314 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | /* |
| 316 | * Allocates bounce buffer and returns its kernel virtual address. |
| 317 | */ |
| 318 | static void * |
Tony Luck | 25667d6 | 2007-03-06 13:31:45 -0800 | [diff] [blame] | 319 | map_single(struct device *hwdev, char *buffer, size_t size, int dir) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | { |
| 321 | unsigned long flags; |
| 322 | char *dma_addr; |
| 323 | unsigned int nslots, stride, index, wrap; |
| 324 | int i; |
FUJITA Tomonori | 681cc5c | 2008-02-04 22:28:16 -0800 | [diff] [blame] | 325 | unsigned long start_dma_addr; |
| 326 | unsigned long mask; |
| 327 | unsigned long offset_slots; |
| 328 | unsigned long max_slots; |
| 329 | |
| 330 | mask = dma_get_seg_boundary(hwdev); |
Ian Campbell | e08e1f7 | 2008-12-16 12:17:30 -0800 | [diff] [blame] | 331 | start_dma_addr = swiotlb_virt_to_bus(io_tlb_start) & mask; |
FUJITA Tomonori | 681cc5c | 2008-02-04 22:28:16 -0800 | [diff] [blame] | 332 | |
| 333 | offset_slots = ALIGN(start_dma_addr, 1 << IO_TLB_SHIFT) >> IO_TLB_SHIFT; |
Ian Campbell | a5ddde4a | 2008-12-16 12:17:29 -0800 | [diff] [blame] | 334 | |
| 335 | /* |
| 336 | * Carefully handle integer overflow which can occur when mask == ~0UL. |
| 337 | */ |
Jan Beulich | b15a3891 | 2008-03-13 09:13:30 +0000 | [diff] [blame] | 338 | max_slots = mask + 1 |
| 339 | ? ALIGN(mask + 1, 1 << IO_TLB_SHIFT) >> IO_TLB_SHIFT |
| 340 | : 1UL << (BITS_PER_LONG - IO_TLB_SHIFT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | |
| 342 | /* |
| 343 | * For mappings greater than a page, we limit the stride (and |
| 344 | * hence alignment) to a page size. |
| 345 | */ |
| 346 | nslots = ALIGN(size, 1 << IO_TLB_SHIFT) >> IO_TLB_SHIFT; |
| 347 | if (size > PAGE_SIZE) |
| 348 | stride = (1 << (PAGE_SHIFT - IO_TLB_SHIFT)); |
| 349 | else |
| 350 | stride = 1; |
| 351 | |
Eric Sesterhenn | 3481454 | 2006-03-24 18:47:11 +0100 | [diff] [blame] | 352 | BUG_ON(!nslots); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | |
| 354 | /* |
| 355 | * Find suitable number of IO TLB entries size that will fit this |
| 356 | * request and allocate a buffer from that IO TLB pool. |
| 357 | */ |
| 358 | spin_lock_irqsave(&io_tlb_lock, flags); |
Andrew Morton | a7133a1 | 2008-04-29 00:59:36 -0700 | [diff] [blame] | 359 | index = ALIGN(io_tlb_index, stride); |
| 360 | if (index >= io_tlb_nslabs) |
| 361 | index = 0; |
| 362 | wrap = index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | |
Andrew Morton | a7133a1 | 2008-04-29 00:59:36 -0700 | [diff] [blame] | 364 | do { |
FUJITA Tomonori | a852250 | 2008-04-29 00:59:36 -0700 | [diff] [blame] | 365 | while (iommu_is_span_boundary(index, nslots, offset_slots, |
| 366 | max_slots)) { |
Jan Beulich | b15a3891 | 2008-03-13 09:13:30 +0000 | [diff] [blame] | 367 | index += stride; |
| 368 | if (index >= io_tlb_nslabs) |
| 369 | index = 0; |
Andrew Morton | a7133a1 | 2008-04-29 00:59:36 -0700 | [diff] [blame] | 370 | if (index == wrap) |
| 371 | goto not_found; |
| 372 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | |
Andrew Morton | a7133a1 | 2008-04-29 00:59:36 -0700 | [diff] [blame] | 374 | /* |
| 375 | * If we find a slot that indicates we have 'nslots' number of |
| 376 | * contiguous buffers, we allocate the buffers from that slot |
| 377 | * and mark the entries as '0' indicating unavailable. |
| 378 | */ |
| 379 | if (io_tlb_list[index] >= nslots) { |
| 380 | int count = 0; |
| 381 | |
| 382 | for (i = index; i < (int) (index + nslots); i++) |
| 383 | io_tlb_list[i] = 0; |
| 384 | for (i = index - 1; (OFFSET(i, IO_TLB_SEGSIZE) != IO_TLB_SEGSIZE - 1) && io_tlb_list[i]; i--) |
| 385 | io_tlb_list[i] = ++count; |
| 386 | dma_addr = io_tlb_start + (index << IO_TLB_SHIFT); |
| 387 | |
| 388 | /* |
| 389 | * Update the indices to avoid searching in the next |
| 390 | * round. |
| 391 | */ |
| 392 | io_tlb_index = ((index + nslots) < io_tlb_nslabs |
| 393 | ? (index + nslots) : 0); |
| 394 | |
| 395 | goto found; |
| 396 | } |
| 397 | index += stride; |
| 398 | if (index >= io_tlb_nslabs) |
| 399 | index = 0; |
| 400 | } while (index != wrap); |
| 401 | |
| 402 | not_found: |
| 403 | spin_unlock_irqrestore(&io_tlb_lock, flags); |
| 404 | return NULL; |
| 405 | found: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | spin_unlock_irqrestore(&io_tlb_lock, flags); |
| 407 | |
| 408 | /* |
| 409 | * Save away the mapping from the original address to the DMA address. |
| 410 | * This is needed when we sync the memory. Then we sync the buffer if |
| 411 | * needed. |
| 412 | */ |
Keir Fraser | df336d1 | 2007-07-21 04:37:24 -0700 | [diff] [blame] | 413 | for (i = 0; i < nslots; i++) |
| 414 | io_tlb_orig_addr[index+i] = buffer + (i << IO_TLB_SHIFT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | if (dir == DMA_TO_DEVICE || dir == DMA_BIDIRECTIONAL) |
Tony Luck | 25667d6 | 2007-03-06 13:31:45 -0800 | [diff] [blame] | 416 | memcpy(dma_addr, buffer, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | |
| 418 | return dma_addr; |
| 419 | } |
| 420 | |
| 421 | /* |
| 422 | * dma_addr is the kernel virtual address of the bounce buffer to unmap. |
| 423 | */ |
| 424 | static void |
| 425 | unmap_single(struct device *hwdev, char *dma_addr, size_t size, int dir) |
| 426 | { |
| 427 | unsigned long flags; |
| 428 | int i, count, nslots = ALIGN(size, 1 << IO_TLB_SHIFT) >> IO_TLB_SHIFT; |
| 429 | int index = (dma_addr - io_tlb_start) >> IO_TLB_SHIFT; |
Tony Luck | 25667d6 | 2007-03-06 13:31:45 -0800 | [diff] [blame] | 430 | char *buffer = io_tlb_orig_addr[index]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | |
| 432 | /* |
| 433 | * First, sync the memory before unmapping the entry |
| 434 | */ |
Tony Luck | 25667d6 | 2007-03-06 13:31:45 -0800 | [diff] [blame] | 435 | if (buffer && ((dir == DMA_FROM_DEVICE) || (dir == DMA_BIDIRECTIONAL))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | /* |
| 437 | * bounce... copy the data back into the original buffer * and |
| 438 | * delete the bounce buffer. |
| 439 | */ |
Tony Luck | 25667d6 | 2007-03-06 13:31:45 -0800 | [diff] [blame] | 440 | memcpy(buffer, dma_addr, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | |
| 442 | /* |
| 443 | * Return the buffer to the free list by setting the corresponding |
| 444 | * entries to indicate the number of contigous entries available. |
| 445 | * While returning the entries to the free list, we merge the entries |
| 446 | * with slots below and above the pool being returned. |
| 447 | */ |
| 448 | spin_lock_irqsave(&io_tlb_lock, flags); |
| 449 | { |
| 450 | count = ((index + nslots) < ALIGN(index + 1, IO_TLB_SEGSIZE) ? |
| 451 | io_tlb_list[index + nslots] : 0); |
| 452 | /* |
| 453 | * Step 1: return the slots to the free list, merging the |
| 454 | * slots with superceeding slots |
| 455 | */ |
| 456 | for (i = index + nslots - 1; i >= index; i--) |
| 457 | io_tlb_list[i] = ++count; |
| 458 | /* |
| 459 | * Step 2: merge the returned slots with the preceding slots, |
| 460 | * if available (non zero) |
| 461 | */ |
| 462 | for (i = index - 1; (OFFSET(i, IO_TLB_SEGSIZE) != IO_TLB_SEGSIZE -1) && io_tlb_list[i]; i--) |
| 463 | io_tlb_list[i] = ++count; |
| 464 | } |
| 465 | spin_unlock_irqrestore(&io_tlb_lock, flags); |
| 466 | } |
| 467 | |
| 468 | static void |
John W. Linville | de69e0f | 2005-09-29 14:44:57 -0700 | [diff] [blame] | 469 | sync_single(struct device *hwdev, char *dma_addr, size_t size, |
| 470 | int dir, int target) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | { |
| 472 | int index = (dma_addr - io_tlb_start) >> IO_TLB_SHIFT; |
Tony Luck | 25667d6 | 2007-03-06 13:31:45 -0800 | [diff] [blame] | 473 | char *buffer = io_tlb_orig_addr[index]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | |
Keir Fraser | df336d1 | 2007-07-21 04:37:24 -0700 | [diff] [blame] | 475 | buffer += ((unsigned long)dma_addr & ((1 << IO_TLB_SHIFT) - 1)); |
| 476 | |
John W. Linville | de69e0f | 2005-09-29 14:44:57 -0700 | [diff] [blame] | 477 | switch (target) { |
| 478 | case SYNC_FOR_CPU: |
| 479 | if (likely(dir == DMA_FROM_DEVICE || dir == DMA_BIDIRECTIONAL)) |
Tony Luck | 25667d6 | 2007-03-06 13:31:45 -0800 | [diff] [blame] | 480 | memcpy(buffer, dma_addr, size); |
Eric Sesterhenn | 3481454 | 2006-03-24 18:47:11 +0100 | [diff] [blame] | 481 | else |
| 482 | BUG_ON(dir != DMA_TO_DEVICE); |
John W. Linville | de69e0f | 2005-09-29 14:44:57 -0700 | [diff] [blame] | 483 | break; |
| 484 | case SYNC_FOR_DEVICE: |
| 485 | if (likely(dir == DMA_TO_DEVICE || dir == DMA_BIDIRECTIONAL)) |
Tony Luck | 25667d6 | 2007-03-06 13:31:45 -0800 | [diff] [blame] | 486 | memcpy(dma_addr, buffer, size); |
Eric Sesterhenn | 3481454 | 2006-03-24 18:47:11 +0100 | [diff] [blame] | 487 | else |
| 488 | BUG_ON(dir != DMA_FROM_DEVICE); |
John W. Linville | de69e0f | 2005-09-29 14:44:57 -0700 | [diff] [blame] | 489 | break; |
| 490 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | BUG(); |
John W. Linville | de69e0f | 2005-09-29 14:44:57 -0700 | [diff] [blame] | 492 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | void * |
| 496 | swiotlb_alloc_coherent(struct device *hwdev, size_t size, |
Al Viro | 06a5449 | 2005-10-21 03:21:03 -0400 | [diff] [blame] | 497 | dma_addr_t *dma_handle, gfp_t flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | { |
Jan Beulich | 563aaf0 | 2007-02-05 18:51:25 -0800 | [diff] [blame] | 499 | dma_addr_t dev_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | void *ret; |
| 501 | int order = get_order(size); |
FUJITA Tomonori | 1e74f30 | 2008-11-17 16:24:34 +0900 | [diff] [blame] | 502 | u64 dma_mask = DMA_32BIT_MASK; |
| 503 | |
| 504 | if (hwdev && hwdev->coherent_dma_mask) |
| 505 | dma_mask = hwdev->coherent_dma_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | |
Tony Luck | 25667d6 | 2007-03-06 13:31:45 -0800 | [diff] [blame] | 507 | ret = (void *)__get_free_pages(flags, order); |
Ian Campbell | e08e1f7 | 2008-12-16 12:17:30 -0800 | [diff] [blame] | 508 | if (ret && !is_buffer_dma_capable(dma_mask, swiotlb_virt_to_bus(ret), size)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | /* |
| 510 | * The allocated memory isn't reachable by the device. |
| 511 | * Fall back on swiotlb_map_single(). |
| 512 | */ |
| 513 | free_pages((unsigned long) ret, order); |
| 514 | ret = NULL; |
| 515 | } |
| 516 | if (!ret) { |
| 517 | /* |
| 518 | * We are either out of memory or the device can't DMA |
| 519 | * to GFP_DMA memory; fall back on |
| 520 | * swiotlb_map_single(), which will grab memory from |
| 521 | * the lowest available address range. |
| 522 | */ |
FUJITA Tomonori | 9dfda12 | 2008-09-08 18:53:48 +0900 | [diff] [blame] | 523 | ret = map_single(hwdev, NULL, size, DMA_FROM_DEVICE); |
| 524 | if (!ret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | memset(ret, 0, size); |
Ian Campbell | e08e1f7 | 2008-12-16 12:17:30 -0800 | [diff] [blame] | 529 | dev_addr = swiotlb_virt_to_bus(ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | |
| 531 | /* Confirm address can be DMA'd by device */ |
FUJITA Tomonori | 1e74f30 | 2008-11-17 16:24:34 +0900 | [diff] [blame] | 532 | if (!is_buffer_dma_capable(dma_mask, dev_addr, size)) { |
Jan Beulich | 563aaf0 | 2007-02-05 18:51:25 -0800 | [diff] [blame] | 533 | printk("hwdev DMA mask = 0x%016Lx, dev_addr = 0x%016Lx\n", |
FUJITA Tomonori | 1e74f30 | 2008-11-17 16:24:34 +0900 | [diff] [blame] | 534 | (unsigned long long)dma_mask, |
Jan Beulich | 563aaf0 | 2007-02-05 18:51:25 -0800 | [diff] [blame] | 535 | (unsigned long long)dev_addr); |
FUJITA Tomonori | a2b89b5 | 2008-10-23 18:42:03 +0900 | [diff] [blame] | 536 | |
| 537 | /* DMA_TO_DEVICE to avoid memcpy in unmap_single */ |
| 538 | unmap_single(hwdev, ret, size, DMA_TO_DEVICE); |
| 539 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | } |
| 541 | *dma_handle = dev_addr; |
| 542 | return ret; |
| 543 | } |
| 544 | |
| 545 | void |
| 546 | swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr, |
| 547 | dma_addr_t dma_handle) |
| 548 | { |
David Brownell | aa24886 | 2007-08-10 13:10:27 -0700 | [diff] [blame] | 549 | WARN_ON(irqs_disabled()); |
FUJITA Tomonori | 640aebf | 2008-09-08 18:53:50 +0900 | [diff] [blame] | 550 | if (!is_swiotlb_buffer(vaddr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | free_pages((unsigned long) vaddr, get_order(size)); |
| 552 | else |
| 553 | /* DMA_TO_DEVICE to avoid memcpy in unmap_single */ |
FUJITA Tomonori | 21f6c4d | 2008-09-08 18:53:49 +0900 | [diff] [blame] | 554 | unmap_single(hwdev, vaddr, size, DMA_TO_DEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | static void |
| 558 | swiotlb_full(struct device *dev, size_t size, int dir, int do_panic) |
| 559 | { |
| 560 | /* |
| 561 | * Ran out of IOMMU space for this operation. This is very bad. |
| 562 | * Unfortunately the drivers cannot handle this operation properly. |
Tony Luck | 17e5ad6 | 2005-09-29 15:52:13 -0700 | [diff] [blame] | 563 | * unless they check for dma_mapping_error (most don't) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | * When the mapping is small enough return a static buffer to limit |
| 565 | * the damage, or panic when the transfer is too big. |
| 566 | */ |
Jan Beulich | 563aaf0 | 2007-02-05 18:51:25 -0800 | [diff] [blame] | 567 | printk(KERN_ERR "DMA: Out of SW-IOMMU space for %zu bytes at " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | "device %s\n", size, dev ? dev->bus_id : "?"); |
| 569 | |
| 570 | if (size > io_tlb_overflow && do_panic) { |
Tony Luck | 17e5ad6 | 2005-09-29 15:52:13 -0700 | [diff] [blame] | 571 | if (dir == DMA_FROM_DEVICE || dir == DMA_BIDIRECTIONAL) |
| 572 | panic("DMA: Memory would be corrupted\n"); |
| 573 | if (dir == DMA_TO_DEVICE || dir == DMA_BIDIRECTIONAL) |
| 574 | panic("DMA: Random memory would be DMAed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | } |
| 576 | } |
| 577 | |
| 578 | /* |
| 579 | * Map a single buffer of the indicated size for DMA in streaming mode. The |
Tony Luck | 17e5ad6 | 2005-09-29 15:52:13 -0700 | [diff] [blame] | 580 | * physical address to use is returned. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | * |
| 582 | * Once the device is given the dma address, the device owns this memory until |
| 583 | * either swiotlb_unmap_single or swiotlb_dma_sync_single is performed. |
| 584 | */ |
| 585 | dma_addr_t |
Arthur Kepner | 309df0c | 2008-04-29 01:00:32 -0700 | [diff] [blame] | 586 | swiotlb_map_single_attrs(struct device *hwdev, void *ptr, size_t size, |
| 587 | int dir, struct dma_attrs *attrs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | { |
Ian Campbell | e08e1f7 | 2008-12-16 12:17:30 -0800 | [diff] [blame] | 589 | dma_addr_t dev_addr = swiotlb_virt_to_bus(ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | void *map; |
| 591 | |
Eric Sesterhenn | 3481454 | 2006-03-24 18:47:11 +0100 | [diff] [blame] | 592 | BUG_ON(dir == DMA_NONE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | /* |
| 594 | * If the pointer passed in happens to be in the device's DMA window, |
| 595 | * we can safely return the device addr and not worry about bounce |
| 596 | * buffering it. |
| 597 | */ |
Ian Campbell | b81ea27 | 2008-12-16 12:17:31 -0800 | [diff] [blame^] | 598 | if (!address_needs_mapping(hwdev, dev_addr, size) && |
| 599 | !range_needs_mapping(ptr, size)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | return dev_addr; |
| 601 | |
| 602 | /* |
| 603 | * Oh well, have to allocate and map a bounce buffer. |
| 604 | */ |
Tony Luck | 25667d6 | 2007-03-06 13:31:45 -0800 | [diff] [blame] | 605 | map = map_single(hwdev, ptr, size, dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | if (!map) { |
| 607 | swiotlb_full(hwdev, size, dir, 1); |
| 608 | map = io_tlb_overflow_buffer; |
| 609 | } |
| 610 | |
Ian Campbell | e08e1f7 | 2008-12-16 12:17:30 -0800 | [diff] [blame] | 611 | dev_addr = swiotlb_virt_to_bus(map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | |
| 613 | /* |
| 614 | * Ensure that the address returned is DMA'ble |
| 615 | */ |
FUJITA Tomonori | 2797982 | 2008-09-10 01:06:49 +0900 | [diff] [blame] | 616 | if (address_needs_mapping(hwdev, dev_addr, size)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | panic("map_single: bounce buffer is not DMA'ble"); |
| 618 | |
| 619 | return dev_addr; |
| 620 | } |
Arthur Kepner | 309df0c | 2008-04-29 01:00:32 -0700 | [diff] [blame] | 621 | EXPORT_SYMBOL(swiotlb_map_single_attrs); |
| 622 | |
| 623 | dma_addr_t |
| 624 | swiotlb_map_single(struct device *hwdev, void *ptr, size_t size, int dir) |
| 625 | { |
| 626 | return swiotlb_map_single_attrs(hwdev, ptr, size, dir, NULL); |
| 627 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | |
| 629 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | * Unmap a single streaming mode DMA translation. The dma_addr and size must |
| 631 | * match what was provided for in a previous swiotlb_map_single call. All |
| 632 | * other usages are undefined. |
| 633 | * |
| 634 | * After this call, reads by the cpu to the buffer are guaranteed to see |
| 635 | * whatever the device wrote there. |
| 636 | */ |
| 637 | void |
Arthur Kepner | 309df0c | 2008-04-29 01:00:32 -0700 | [diff] [blame] | 638 | swiotlb_unmap_single_attrs(struct device *hwdev, dma_addr_t dev_addr, |
| 639 | size_t size, int dir, struct dma_attrs *attrs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | { |
Ian Campbell | e08e1f7 | 2008-12-16 12:17:30 -0800 | [diff] [blame] | 641 | char *dma_addr = swiotlb_bus_to_virt(dev_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | |
Eric Sesterhenn | 3481454 | 2006-03-24 18:47:11 +0100 | [diff] [blame] | 643 | BUG_ON(dir == DMA_NONE); |
FUJITA Tomonori | 640aebf | 2008-09-08 18:53:50 +0900 | [diff] [blame] | 644 | if (is_swiotlb_buffer(dma_addr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | unmap_single(hwdev, dma_addr, size, dir); |
| 646 | else if (dir == DMA_FROM_DEVICE) |
Jan Beulich | cde14bb | 2007-02-05 18:46:40 -0800 | [diff] [blame] | 647 | dma_mark_clean(dma_addr, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | } |
Arthur Kepner | 309df0c | 2008-04-29 01:00:32 -0700 | [diff] [blame] | 649 | EXPORT_SYMBOL(swiotlb_unmap_single_attrs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | |
Arthur Kepner | 309df0c | 2008-04-29 01:00:32 -0700 | [diff] [blame] | 651 | void |
| 652 | swiotlb_unmap_single(struct device *hwdev, dma_addr_t dev_addr, size_t size, |
| 653 | int dir) |
| 654 | { |
| 655 | return swiotlb_unmap_single_attrs(hwdev, dev_addr, size, dir, NULL); |
| 656 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | /* |
| 658 | * Make physical memory consistent for a single streaming mode DMA translation |
| 659 | * after a transfer. |
| 660 | * |
| 661 | * If you perform a swiotlb_map_single() but wish to interrogate the buffer |
Tony Luck | 17e5ad6 | 2005-09-29 15:52:13 -0700 | [diff] [blame] | 662 | * using the cpu, yet do not wish to teardown the dma mapping, you must |
| 663 | * call this function before doing so. At the next point you give the dma |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | * address back to the card, you must first perform a |
| 665 | * swiotlb_dma_sync_for_device, and then the device again owns the buffer |
| 666 | */ |
Andrew Morton | be6b026 | 2007-02-12 00:52:17 -0800 | [diff] [blame] | 667 | static void |
John W. Linville | 8270f3f | 2005-09-29 14:43:32 -0700 | [diff] [blame] | 668 | swiotlb_sync_single(struct device *hwdev, dma_addr_t dev_addr, |
John W. Linville | de69e0f | 2005-09-29 14:44:57 -0700 | [diff] [blame] | 669 | size_t size, int dir, int target) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | { |
Ian Campbell | e08e1f7 | 2008-12-16 12:17:30 -0800 | [diff] [blame] | 671 | char *dma_addr = swiotlb_bus_to_virt(dev_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | |
Eric Sesterhenn | 3481454 | 2006-03-24 18:47:11 +0100 | [diff] [blame] | 673 | BUG_ON(dir == DMA_NONE); |
FUJITA Tomonori | 640aebf | 2008-09-08 18:53:50 +0900 | [diff] [blame] | 674 | if (is_swiotlb_buffer(dma_addr)) |
John W. Linville | de69e0f | 2005-09-29 14:44:57 -0700 | [diff] [blame] | 675 | sync_single(hwdev, dma_addr, size, dir, target); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | else if (dir == DMA_FROM_DEVICE) |
Jan Beulich | cde14bb | 2007-02-05 18:46:40 -0800 | [diff] [blame] | 677 | dma_mark_clean(dma_addr, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | void |
John W. Linville | 8270f3f | 2005-09-29 14:43:32 -0700 | [diff] [blame] | 681 | swiotlb_sync_single_for_cpu(struct device *hwdev, dma_addr_t dev_addr, |
| 682 | size_t size, int dir) |
| 683 | { |
John W. Linville | de69e0f | 2005-09-29 14:44:57 -0700 | [diff] [blame] | 684 | swiotlb_sync_single(hwdev, dev_addr, size, dir, SYNC_FOR_CPU); |
John W. Linville | 8270f3f | 2005-09-29 14:43:32 -0700 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | swiotlb_sync_single_for_device(struct device *hwdev, dma_addr_t dev_addr, |
| 689 | size_t size, int dir) |
| 690 | { |
John W. Linville | de69e0f | 2005-09-29 14:44:57 -0700 | [diff] [blame] | 691 | swiotlb_sync_single(hwdev, dev_addr, size, dir, SYNC_FOR_DEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | /* |
John W. Linville | 878a97c | 2005-09-29 14:44:23 -0700 | [diff] [blame] | 695 | * Same as above, but for a sub-range of the mapping. |
| 696 | */ |
Andrew Morton | be6b026 | 2007-02-12 00:52:17 -0800 | [diff] [blame] | 697 | static void |
John W. Linville | 878a97c | 2005-09-29 14:44:23 -0700 | [diff] [blame] | 698 | swiotlb_sync_single_range(struct device *hwdev, dma_addr_t dev_addr, |
John W. Linville | de69e0f | 2005-09-29 14:44:57 -0700 | [diff] [blame] | 699 | unsigned long offset, size_t size, |
| 700 | int dir, int target) |
John W. Linville | 878a97c | 2005-09-29 14:44:23 -0700 | [diff] [blame] | 701 | { |
Ian Campbell | e08e1f7 | 2008-12-16 12:17:30 -0800 | [diff] [blame] | 702 | char *dma_addr = swiotlb_bus_to_virt(dev_addr) + offset; |
John W. Linville | 878a97c | 2005-09-29 14:44:23 -0700 | [diff] [blame] | 703 | |
Eric Sesterhenn | 3481454 | 2006-03-24 18:47:11 +0100 | [diff] [blame] | 704 | BUG_ON(dir == DMA_NONE); |
FUJITA Tomonori | 640aebf | 2008-09-08 18:53:50 +0900 | [diff] [blame] | 705 | if (is_swiotlb_buffer(dma_addr)) |
John W. Linville | de69e0f | 2005-09-29 14:44:57 -0700 | [diff] [blame] | 706 | sync_single(hwdev, dma_addr, size, dir, target); |
John W. Linville | 878a97c | 2005-09-29 14:44:23 -0700 | [diff] [blame] | 707 | else if (dir == DMA_FROM_DEVICE) |
Jan Beulich | cde14bb | 2007-02-05 18:46:40 -0800 | [diff] [blame] | 708 | dma_mark_clean(dma_addr, size); |
John W. Linville | 878a97c | 2005-09-29 14:44:23 -0700 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | void |
| 712 | swiotlb_sync_single_range_for_cpu(struct device *hwdev, dma_addr_t dev_addr, |
| 713 | unsigned long offset, size_t size, int dir) |
| 714 | { |
John W. Linville | de69e0f | 2005-09-29 14:44:57 -0700 | [diff] [blame] | 715 | swiotlb_sync_single_range(hwdev, dev_addr, offset, size, dir, |
| 716 | SYNC_FOR_CPU); |
John W. Linville | 878a97c | 2005-09-29 14:44:23 -0700 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | void |
| 720 | swiotlb_sync_single_range_for_device(struct device *hwdev, dma_addr_t dev_addr, |
| 721 | unsigned long offset, size_t size, int dir) |
| 722 | { |
John W. Linville | de69e0f | 2005-09-29 14:44:57 -0700 | [diff] [blame] | 723 | swiotlb_sync_single_range(hwdev, dev_addr, offset, size, dir, |
| 724 | SYNC_FOR_DEVICE); |
John W. Linville | 878a97c | 2005-09-29 14:44:23 -0700 | [diff] [blame] | 725 | } |
| 726 | |
Arthur Kepner | 309df0c | 2008-04-29 01:00:32 -0700 | [diff] [blame] | 727 | void swiotlb_unmap_sg_attrs(struct device *, struct scatterlist *, int, int, |
| 728 | struct dma_attrs *); |
John W. Linville | 878a97c | 2005-09-29 14:44:23 -0700 | [diff] [blame] | 729 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | * Map a set of buffers described by scatterlist in streaming mode for DMA. |
| 731 | * This is the scatter-gather version of the above swiotlb_map_single |
| 732 | * interface. Here the scatter gather list elements are each tagged with the |
| 733 | * appropriate dma address and length. They are obtained via |
| 734 | * sg_dma_{address,length}(SG). |
| 735 | * |
| 736 | * NOTE: An implementation may be able to use a smaller number of |
| 737 | * DMA address/length pairs than there are SG table elements. |
| 738 | * (for example via virtual mapping capabilities) |
| 739 | * The routine returns the number of addr/length pairs actually |
| 740 | * used, at most nents. |
| 741 | * |
| 742 | * Device ownership issues as mentioned above for swiotlb_map_single are the |
| 743 | * same here. |
| 744 | */ |
| 745 | int |
Arthur Kepner | 309df0c | 2008-04-29 01:00:32 -0700 | [diff] [blame] | 746 | swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl, int nelems, |
| 747 | int dir, struct dma_attrs *attrs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | { |
Jens Axboe | dbfd49f | 2007-05-11 14:56:18 +0200 | [diff] [blame] | 749 | struct scatterlist *sg; |
Tony Luck | 25667d6 | 2007-03-06 13:31:45 -0800 | [diff] [blame] | 750 | void *addr; |
Jan Beulich | 563aaf0 | 2007-02-05 18:51:25 -0800 | [diff] [blame] | 751 | dma_addr_t dev_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | int i; |
| 753 | |
Eric Sesterhenn | 3481454 | 2006-03-24 18:47:11 +0100 | [diff] [blame] | 754 | BUG_ON(dir == DMA_NONE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | |
Jens Axboe | dbfd49f | 2007-05-11 14:56:18 +0200 | [diff] [blame] | 756 | for_each_sg(sgl, sg, nelems, i) { |
Tony Luck | 25667d6 | 2007-03-06 13:31:45 -0800 | [diff] [blame] | 757 | addr = SG_ENT_VIRT_ADDRESS(sg); |
Ian Campbell | e08e1f7 | 2008-12-16 12:17:30 -0800 | [diff] [blame] | 758 | dev_addr = swiotlb_virt_to_bus(addr); |
Ian Campbell | b81ea27 | 2008-12-16 12:17:31 -0800 | [diff] [blame^] | 759 | if (range_needs_mapping(sg_virt(sg), sg->length) || |
FUJITA Tomonori | 2797982 | 2008-09-10 01:06:49 +0900 | [diff] [blame] | 760 | address_needs_mapping(hwdev, dev_addr, sg->length)) { |
Tony Luck | 25667d6 | 2007-03-06 13:31:45 -0800 | [diff] [blame] | 761 | void *map = map_single(hwdev, addr, sg->length, dir); |
Andi Kleen | 7e87023 | 2005-12-20 14:45:19 +0100 | [diff] [blame] | 762 | if (!map) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | /* Don't panic here, we expect map_sg users |
| 764 | to do proper error handling. */ |
| 765 | swiotlb_full(hwdev, sg->length, dir, 0); |
Arthur Kepner | 309df0c | 2008-04-29 01:00:32 -0700 | [diff] [blame] | 766 | swiotlb_unmap_sg_attrs(hwdev, sgl, i, dir, |
| 767 | attrs); |
Jens Axboe | dbfd49f | 2007-05-11 14:56:18 +0200 | [diff] [blame] | 768 | sgl[0].dma_length = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | return 0; |
| 770 | } |
Ian Campbell | e08e1f7 | 2008-12-16 12:17:30 -0800 | [diff] [blame] | 771 | sg->dma_address = swiotlb_virt_to_bus(map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | } else |
| 773 | sg->dma_address = dev_addr; |
| 774 | sg->dma_length = sg->length; |
| 775 | } |
| 776 | return nelems; |
| 777 | } |
Arthur Kepner | 309df0c | 2008-04-29 01:00:32 -0700 | [diff] [blame] | 778 | EXPORT_SYMBOL(swiotlb_map_sg_attrs); |
| 779 | |
| 780 | int |
| 781 | swiotlb_map_sg(struct device *hwdev, struct scatterlist *sgl, int nelems, |
| 782 | int dir) |
| 783 | { |
| 784 | return swiotlb_map_sg_attrs(hwdev, sgl, nelems, dir, NULL); |
| 785 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | |
| 787 | /* |
| 788 | * Unmap a set of streaming mode DMA translations. Again, cpu read rules |
| 789 | * concerning calls here are the same as for swiotlb_unmap_single() above. |
| 790 | */ |
| 791 | void |
Arthur Kepner | 309df0c | 2008-04-29 01:00:32 -0700 | [diff] [blame] | 792 | swiotlb_unmap_sg_attrs(struct device *hwdev, struct scatterlist *sgl, |
| 793 | int nelems, int dir, struct dma_attrs *attrs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | { |
Jens Axboe | dbfd49f | 2007-05-11 14:56:18 +0200 | [diff] [blame] | 795 | struct scatterlist *sg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | int i; |
| 797 | |
Eric Sesterhenn | 3481454 | 2006-03-24 18:47:11 +0100 | [diff] [blame] | 798 | BUG_ON(dir == DMA_NONE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | |
Jens Axboe | dbfd49f | 2007-05-11 14:56:18 +0200 | [diff] [blame] | 800 | for_each_sg(sgl, sg, nelems, i) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | if (sg->dma_address != SG_ENT_PHYS_ADDRESS(sg)) |
Ian Campbell | e08e1f7 | 2008-12-16 12:17:30 -0800 | [diff] [blame] | 802 | unmap_single(hwdev, swiotlb_bus_to_virt(sg->dma_address), |
Jan Beulich | 93fbff6 | 2007-02-05 18:49:45 -0800 | [diff] [blame] | 803 | sg->dma_length, dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | else if (dir == DMA_FROM_DEVICE) |
Jan Beulich | cde14bb | 2007-02-05 18:46:40 -0800 | [diff] [blame] | 805 | dma_mark_clean(SG_ENT_VIRT_ADDRESS(sg), sg->dma_length); |
Jens Axboe | dbfd49f | 2007-05-11 14:56:18 +0200 | [diff] [blame] | 806 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | } |
Arthur Kepner | 309df0c | 2008-04-29 01:00:32 -0700 | [diff] [blame] | 808 | EXPORT_SYMBOL(swiotlb_unmap_sg_attrs); |
| 809 | |
| 810 | void |
| 811 | swiotlb_unmap_sg(struct device *hwdev, struct scatterlist *sgl, int nelems, |
| 812 | int dir) |
| 813 | { |
| 814 | return swiotlb_unmap_sg_attrs(hwdev, sgl, nelems, dir, NULL); |
| 815 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | |
| 817 | /* |
| 818 | * Make physical memory consistent for a set of streaming mode DMA translations |
| 819 | * after a transfer. |
| 820 | * |
| 821 | * The same as swiotlb_sync_single_* but for a scatter-gather list, same rules |
| 822 | * and usage. |
| 823 | */ |
Andrew Morton | be6b026 | 2007-02-12 00:52:17 -0800 | [diff] [blame] | 824 | static void |
Jens Axboe | dbfd49f | 2007-05-11 14:56:18 +0200 | [diff] [blame] | 825 | swiotlb_sync_sg(struct device *hwdev, struct scatterlist *sgl, |
John W. Linville | de69e0f | 2005-09-29 14:44:57 -0700 | [diff] [blame] | 826 | int nelems, int dir, int target) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | { |
Jens Axboe | dbfd49f | 2007-05-11 14:56:18 +0200 | [diff] [blame] | 828 | struct scatterlist *sg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | int i; |
| 830 | |
Eric Sesterhenn | 3481454 | 2006-03-24 18:47:11 +0100 | [diff] [blame] | 831 | BUG_ON(dir == DMA_NONE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | |
Jens Axboe | dbfd49f | 2007-05-11 14:56:18 +0200 | [diff] [blame] | 833 | for_each_sg(sgl, sg, nelems, i) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | if (sg->dma_address != SG_ENT_PHYS_ADDRESS(sg)) |
Ian Campbell | e08e1f7 | 2008-12-16 12:17:30 -0800 | [diff] [blame] | 835 | sync_single(hwdev, swiotlb_bus_to_virt(sg->dma_address), |
John W. Linville | de69e0f | 2005-09-29 14:44:57 -0700 | [diff] [blame] | 836 | sg->dma_length, dir, target); |
Jan Beulich | cde14bb | 2007-02-05 18:46:40 -0800 | [diff] [blame] | 837 | else if (dir == DMA_FROM_DEVICE) |
| 838 | dma_mark_clean(SG_ENT_VIRT_ADDRESS(sg), sg->dma_length); |
Jens Axboe | dbfd49f | 2007-05-11 14:56:18 +0200 | [diff] [blame] | 839 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | } |
| 841 | |
| 842 | void |
John W. Linville | 8270f3f | 2005-09-29 14:43:32 -0700 | [diff] [blame] | 843 | swiotlb_sync_sg_for_cpu(struct device *hwdev, struct scatterlist *sg, |
| 844 | int nelems, int dir) |
| 845 | { |
John W. Linville | de69e0f | 2005-09-29 14:44:57 -0700 | [diff] [blame] | 846 | swiotlb_sync_sg(hwdev, sg, nelems, dir, SYNC_FOR_CPU); |
John W. Linville | 8270f3f | 2005-09-29 14:43:32 -0700 | [diff] [blame] | 847 | } |
| 848 | |
| 849 | void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | swiotlb_sync_sg_for_device(struct device *hwdev, struct scatterlist *sg, |
| 851 | int nelems, int dir) |
| 852 | { |
John W. Linville | de69e0f | 2005-09-29 14:44:57 -0700 | [diff] [blame] | 853 | swiotlb_sync_sg(hwdev, sg, nelems, dir, SYNC_FOR_DEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | } |
| 855 | |
| 856 | int |
FUJITA Tomonori | 8d8bb39 | 2008-07-25 19:44:49 -0700 | [diff] [blame] | 857 | swiotlb_dma_mapping_error(struct device *hwdev, dma_addr_t dma_addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | { |
Ian Campbell | e08e1f7 | 2008-12-16 12:17:30 -0800 | [diff] [blame] | 859 | return (dma_addr == swiotlb_virt_to_bus(io_tlb_overflow_buffer)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | } |
| 861 | |
| 862 | /* |
Tony Luck | 17e5ad6 | 2005-09-29 15:52:13 -0700 | [diff] [blame] | 863 | * Return whether the given device DMA address mask can be supported |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | * properly. For example, if your device can only drive the low 24-bits |
Tony Luck | 17e5ad6 | 2005-09-29 15:52:13 -0700 | [diff] [blame] | 865 | * during bus mastering, then you would pass 0x00ffffff as the mask to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | * this function. |
| 867 | */ |
| 868 | int |
Jan Beulich | 563aaf0 | 2007-02-05 18:51:25 -0800 | [diff] [blame] | 869 | swiotlb_dma_supported(struct device *hwdev, u64 mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | { |
Ian Campbell | e08e1f7 | 2008-12-16 12:17:30 -0800 | [diff] [blame] | 871 | return swiotlb_virt_to_bus(io_tlb_end - 1) <= mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | } |
| 873 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | EXPORT_SYMBOL(swiotlb_map_single); |
| 875 | EXPORT_SYMBOL(swiotlb_unmap_single); |
| 876 | EXPORT_SYMBOL(swiotlb_map_sg); |
| 877 | EXPORT_SYMBOL(swiotlb_unmap_sg); |
| 878 | EXPORT_SYMBOL(swiotlb_sync_single_for_cpu); |
| 879 | EXPORT_SYMBOL(swiotlb_sync_single_for_device); |
John W. Linville | 878a97c | 2005-09-29 14:44:23 -0700 | [diff] [blame] | 880 | EXPORT_SYMBOL_GPL(swiotlb_sync_single_range_for_cpu); |
| 881 | EXPORT_SYMBOL_GPL(swiotlb_sync_single_range_for_device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | EXPORT_SYMBOL(swiotlb_sync_sg_for_cpu); |
| 883 | EXPORT_SYMBOL(swiotlb_sync_sg_for_device); |
| 884 | EXPORT_SYMBOL(swiotlb_dma_mapping_error); |
Tony Luck | 25667d6 | 2007-03-06 13:31:45 -0800 | [diff] [blame] | 885 | EXPORT_SYMBOL(swiotlb_alloc_coherent); |
| 886 | EXPORT_SYMBOL(swiotlb_free_coherent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | EXPORT_SYMBOL(swiotlb_dma_supported); |