Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is subject to the terms and conditions of the GNU General Public |
| 3 | * License. See the file "COPYING" in the main directory of this archive |
| 4 | * for more details. |
| 5 | * |
| 6 | * Copyright (C) 2000 Ani Joshi <ajoshi@unixbox.com> |
Ralf Baechle | 9a88cbb | 2006-11-16 02:56:12 +0000 | [diff] [blame] | 7 | * Copyright (C) 2000, 2001, 06 Ralf Baechle <ralf@linux-mips.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * swiped from i386, and cloned for MIPS by Geert, polished by Ralf. |
| 9 | */ |
Ralf Baechle | 9a88cbb | 2006-11-16 02:56:12 +0000 | [diff] [blame] | 10 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/types.h> |
Ralf Baechle | 9a88cbb | 2006-11-16 02:56:12 +0000 | [diff] [blame] | 12 | #include <linux/dma-mapping.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/mm.h> |
| 14 | #include <linux/module.h> |
Jens Axboe | 4fcc47a | 2007-10-23 12:32:34 +0200 | [diff] [blame] | 15 | #include <linux/scatterlist.h> |
Ralf Baechle | 6e86b0b | 2007-10-29 19:35:33 +0000 | [diff] [blame] | 16 | #include <linux/string.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
| 18 | #include <asm/cache.h> |
| 19 | #include <asm/io.h> |
| 20 | |
Ralf Baechle | 9a88cbb | 2006-11-16 02:56:12 +0000 | [diff] [blame] | 21 | #include <dma-coherence.h> |
| 22 | |
Kevin Cernekee | 3807ef3f6 | 2009-04-23 17:25:12 -0700 | [diff] [blame] | 23 | static inline unsigned long dma_addr_to_virt(struct device *dev, |
| 24 | dma_addr_t dma_addr) |
Franck Bui-Huu | c9d0696 | 2007-03-19 17:36:42 +0100 | [diff] [blame] | 25 | { |
Kevin Cernekee | 3807ef3f6 | 2009-04-23 17:25:12 -0700 | [diff] [blame] | 26 | unsigned long addr = plat_dma_addr_to_phys(dev, dma_addr); |
Franck Bui-Huu | c9d0696 | 2007-03-19 17:36:42 +0100 | [diff] [blame] | 27 | |
| 28 | return (unsigned long)phys_to_virt(addr); |
| 29 | } |
| 30 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | /* |
| 32 | * Warning on the terminology - Linux calls an uncached area coherent; |
| 33 | * MIPS terminology calls memory areas with hardware maintained coherency |
| 34 | * coherent. |
| 35 | */ |
| 36 | |
Ralf Baechle | 9a88cbb | 2006-11-16 02:56:12 +0000 | [diff] [blame] | 37 | static inline int cpu_is_noncoherent_r10000(struct device *dev) |
| 38 | { |
| 39 | return !plat_device_is_coherent(dev) && |
Ralf Baechle | 10cc352 | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 40 | (current_cpu_type() == CPU_R10000 || |
| 41 | current_cpu_type() == CPU_R12000); |
Ralf Baechle | 9a88cbb | 2006-11-16 02:56:12 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Ralf Baechle | cce335a | 2007-11-03 02:05:43 +0000 | [diff] [blame] | 44 | static gfp_t massage_gfp_flags(const struct device *dev, gfp_t gfp) |
| 45 | { |
| 46 | /* ignore region specifiers */ |
| 47 | gfp &= ~(__GFP_DMA | __GFP_DMA32 | __GFP_HIGHMEM); |
| 48 | |
Thomas Bogendoerfer | 3201671 | 2007-12-30 12:45:40 +0100 | [diff] [blame] | 49 | #ifdef CONFIG_ZONE_DMA |
Ralf Baechle | cce335a | 2007-11-03 02:05:43 +0000 | [diff] [blame] | 50 | if (dev == NULL) |
| 51 | gfp |= __GFP_DMA; |
| 52 | else if (dev->coherent_dma_mask < DMA_BIT_MASK(24)) |
| 53 | gfp |= __GFP_DMA; |
| 54 | else |
| 55 | #endif |
| 56 | #ifdef CONFIG_ZONE_DMA32 |
| 57 | if (dev->coherent_dma_mask < DMA_BIT_MASK(32)) |
| 58 | gfp |= __GFP_DMA32; |
| 59 | else |
| 60 | #endif |
| 61 | ; |
| 62 | |
| 63 | /* Don't invoke OOM killer */ |
| 64 | gfp |= __GFP_NORETRY; |
| 65 | |
| 66 | return gfp; |
| 67 | } |
| 68 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | void *dma_alloc_noncoherent(struct device *dev, size_t size, |
Al Viro | 185a8ff | 2005-10-21 03:21:23 -0400 | [diff] [blame] | 70 | dma_addr_t * dma_handle, gfp_t gfp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | { |
| 72 | void *ret; |
Ralf Baechle | 9a88cbb | 2006-11-16 02:56:12 +0000 | [diff] [blame] | 73 | |
Ralf Baechle | cce335a | 2007-11-03 02:05:43 +0000 | [diff] [blame] | 74 | gfp = massage_gfp_flags(dev, gfp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | ret = (void *) __get_free_pages(gfp, get_order(size)); |
| 77 | |
| 78 | if (ret != NULL) { |
| 79 | memset(ret, 0, size); |
Ralf Baechle | 9a88cbb | 2006-11-16 02:56:12 +0000 | [diff] [blame] | 80 | *dma_handle = plat_map_dma_mem(dev, ret, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | return ret; |
| 84 | } |
| 85 | |
| 86 | EXPORT_SYMBOL(dma_alloc_noncoherent); |
| 87 | |
| 88 | void *dma_alloc_coherent(struct device *dev, size_t size, |
Al Viro | 185a8ff | 2005-10-21 03:21:23 -0400 | [diff] [blame] | 89 | dma_addr_t * dma_handle, gfp_t gfp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | { |
| 91 | void *ret; |
| 92 | |
Yoichi Yuasa | f8ac042 | 2009-06-04 00:16:04 +0900 | [diff] [blame] | 93 | if (dma_alloc_from_coherent(dev, size, dma_handle, &ret)) |
| 94 | return ret; |
| 95 | |
Ralf Baechle | cce335a | 2007-11-03 02:05:43 +0000 | [diff] [blame] | 96 | gfp = massage_gfp_flags(dev, gfp); |
Ralf Baechle | 9a88cbb | 2006-11-16 02:56:12 +0000 | [diff] [blame] | 97 | |
Ralf Baechle | 9a88cbb | 2006-11-16 02:56:12 +0000 | [diff] [blame] | 98 | ret = (void *) __get_free_pages(gfp, get_order(size)); |
| 99 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | if (ret) { |
Ralf Baechle | 9a88cbb | 2006-11-16 02:56:12 +0000 | [diff] [blame] | 101 | memset(ret, 0, size); |
| 102 | *dma_handle = plat_map_dma_mem(dev, ret, size); |
| 103 | |
| 104 | if (!plat_device_is_coherent(dev)) { |
| 105 | dma_cache_wback_inv((unsigned long) ret, size); |
| 106 | ret = UNCAC_ADDR(ret); |
| 107 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | return ret; |
| 111 | } |
| 112 | |
| 113 | EXPORT_SYMBOL(dma_alloc_coherent); |
| 114 | |
| 115 | void dma_free_noncoherent(struct device *dev, size_t size, void *vaddr, |
| 116 | dma_addr_t dma_handle) |
| 117 | { |
Kevin Cernekee | d3f634b | 2009-04-23 17:03:43 -0700 | [diff] [blame] | 118 | plat_unmap_dma_mem(dev, dma_handle, size, DMA_BIDIRECTIONAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | free_pages((unsigned long) vaddr, get_order(size)); |
| 120 | } |
| 121 | |
| 122 | EXPORT_SYMBOL(dma_free_noncoherent); |
| 123 | |
| 124 | void dma_free_coherent(struct device *dev, size_t size, void *vaddr, |
| 125 | dma_addr_t dma_handle) |
| 126 | { |
| 127 | unsigned long addr = (unsigned long) vaddr; |
Yoichi Yuasa | f8ac042 | 2009-06-04 00:16:04 +0900 | [diff] [blame] | 128 | int order = get_order(size); |
| 129 | |
| 130 | if (dma_release_from_coherent(dev, order, vaddr)) |
| 131 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | |
Kevin Cernekee | d3f634b | 2009-04-23 17:03:43 -0700 | [diff] [blame] | 133 | plat_unmap_dma_mem(dev, dma_handle, size, DMA_BIDIRECTIONAL); |
David Daney | 11531ac | 2008-12-10 18:14:45 -0800 | [diff] [blame] | 134 | |
Ralf Baechle | 9a88cbb | 2006-11-16 02:56:12 +0000 | [diff] [blame] | 135 | if (!plat_device_is_coherent(dev)) |
| 136 | addr = CAC_ADDR(addr); |
| 137 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | free_pages(addr, get_order(size)); |
| 139 | } |
| 140 | |
| 141 | EXPORT_SYMBOL(dma_free_coherent); |
| 142 | |
| 143 | static inline void __dma_sync(unsigned long addr, size_t size, |
| 144 | enum dma_data_direction direction) |
| 145 | { |
| 146 | switch (direction) { |
| 147 | case DMA_TO_DEVICE: |
| 148 | dma_cache_wback(addr, size); |
| 149 | break; |
| 150 | |
| 151 | case DMA_FROM_DEVICE: |
| 152 | dma_cache_inv(addr, size); |
| 153 | break; |
| 154 | |
| 155 | case DMA_BIDIRECTIONAL: |
| 156 | dma_cache_wback_inv(addr, size); |
| 157 | break; |
| 158 | |
| 159 | default: |
| 160 | BUG(); |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | dma_addr_t dma_map_single(struct device *dev, void *ptr, size_t size, |
| 165 | enum dma_data_direction direction) |
| 166 | { |
| 167 | unsigned long addr = (unsigned long) ptr; |
| 168 | |
Ralf Baechle | 9a88cbb | 2006-11-16 02:56:12 +0000 | [diff] [blame] | 169 | if (!plat_device_is_coherent(dev)) |
| 170 | __dma_sync(addr, size, direction); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | |
Ralf Baechle | 9a88cbb | 2006-11-16 02:56:12 +0000 | [diff] [blame] | 172 | return plat_map_dma_mem(dev, ptr, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | EXPORT_SYMBOL(dma_map_single); |
| 176 | |
| 177 | void dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size, |
| 178 | enum dma_data_direction direction) |
| 179 | { |
Ralf Baechle | 9a88cbb | 2006-11-16 02:56:12 +0000 | [diff] [blame] | 180 | if (cpu_is_noncoherent_r10000(dev)) |
Kevin Cernekee | 3807ef3f6 | 2009-04-23 17:25:12 -0700 | [diff] [blame] | 181 | __dma_sync(dma_addr_to_virt(dev, dma_addr), size, |
Ralf Baechle | 9a88cbb | 2006-11-16 02:56:12 +0000 | [diff] [blame] | 182 | direction); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | |
Kevin Cernekee | d3f634b | 2009-04-23 17:03:43 -0700 | [diff] [blame] | 184 | plat_unmap_dma_mem(dev, dma_addr, size, direction); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | EXPORT_SYMBOL(dma_unmap_single); |
| 188 | |
| 189 | int dma_map_sg(struct device *dev, struct scatterlist *sg, int nents, |
| 190 | enum dma_data_direction direction) |
| 191 | { |
| 192 | int i; |
| 193 | |
| 194 | BUG_ON(direction == DMA_NONE); |
| 195 | |
| 196 | for (i = 0; i < nents; i++, sg++) { |
| 197 | unsigned long addr; |
Ralf Baechle | 42a3b4f | 2005-09-03 15:56:17 -0700 | [diff] [blame] | 198 | |
Jens Axboe | 58b053e | 2007-10-22 20:02:46 +0200 | [diff] [blame] | 199 | addr = (unsigned long) sg_virt(sg); |
Ralf Baechle | 9a88cbb | 2006-11-16 02:56:12 +0000 | [diff] [blame] | 200 | if (!plat_device_is_coherent(dev) && addr) |
Jens Axboe | 58b053e | 2007-10-22 20:02:46 +0200 | [diff] [blame] | 201 | __dma_sync(addr, sg->length, direction); |
Thomas Bogendoerfer | fbd5604 | 2007-05-18 14:32:36 +0200 | [diff] [blame] | 202 | sg->dma_address = plat_map_dma_mem(dev, |
Jens Axboe | 58b053e | 2007-10-22 20:02:46 +0200 | [diff] [blame] | 203 | (void *)addr, sg->length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | return nents; |
| 207 | } |
| 208 | |
| 209 | EXPORT_SYMBOL(dma_map_sg); |
| 210 | |
| 211 | dma_addr_t dma_map_page(struct device *dev, struct page *page, |
| 212 | unsigned long offset, size_t size, enum dma_data_direction direction) |
| 213 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | BUG_ON(direction == DMA_NONE); |
| 215 | |
Ralf Baechle | 9a88cbb | 2006-11-16 02:56:12 +0000 | [diff] [blame] | 216 | if (!plat_device_is_coherent(dev)) { |
| 217 | unsigned long addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | |
Ralf Baechle | 9a88cbb | 2006-11-16 02:56:12 +0000 | [diff] [blame] | 219 | addr = (unsigned long) page_address(page) + offset; |
Atsushi Nemoto | 4f29c05 | 2009-01-23 00:42:11 +0900 | [diff] [blame] | 220 | __dma_sync(addr, size, direction); |
Ralf Baechle | 9a88cbb | 2006-11-16 02:56:12 +0000 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | return plat_map_dma_mem_page(dev, page) + offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | EXPORT_SYMBOL(dma_map_page); |
| 227 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | void dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nhwentries, |
| 229 | enum dma_data_direction direction) |
| 230 | { |
| 231 | unsigned long addr; |
| 232 | int i; |
| 233 | |
| 234 | BUG_ON(direction == DMA_NONE); |
| 235 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | for (i = 0; i < nhwentries; i++, sg++) { |
Ralf Baechle | 9a88cbb | 2006-11-16 02:56:12 +0000 | [diff] [blame] | 237 | if (!plat_device_is_coherent(dev) && |
| 238 | direction != DMA_TO_DEVICE) { |
Jens Axboe | 58b053e | 2007-10-22 20:02:46 +0200 | [diff] [blame] | 239 | addr = (unsigned long) sg_virt(sg); |
Ralf Baechle | 9a88cbb | 2006-11-16 02:56:12 +0000 | [diff] [blame] | 240 | if (addr) |
Jens Axboe | 58b053e | 2007-10-22 20:02:46 +0200 | [diff] [blame] | 241 | __dma_sync(addr, sg->length, direction); |
Ralf Baechle | 9a88cbb | 2006-11-16 02:56:12 +0000 | [diff] [blame] | 242 | } |
Kevin Cernekee | d3f634b | 2009-04-23 17:03:43 -0700 | [diff] [blame] | 243 | plat_unmap_dma_mem(dev, sg->dma_address, sg->length, direction); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | } |
| 245 | } |
| 246 | |
| 247 | EXPORT_SYMBOL(dma_unmap_sg); |
| 248 | |
| 249 | void dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle, |
| 250 | size_t size, enum dma_data_direction direction) |
| 251 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | BUG_ON(direction == DMA_NONE); |
Ralf Baechle | 42a3b4f | 2005-09-03 15:56:17 -0700 | [diff] [blame] | 253 | |
Ralf Baechle | 9a88cbb | 2006-11-16 02:56:12 +0000 | [diff] [blame] | 254 | if (cpu_is_noncoherent_r10000(dev)) { |
| 255 | unsigned long addr; |
| 256 | |
Kevin Cernekee | 3807ef3f6 | 2009-04-23 17:25:12 -0700 | [diff] [blame] | 257 | addr = dma_addr_to_virt(dev, dma_handle); |
Ralf Baechle | 9a88cbb | 2006-11-16 02:56:12 +0000 | [diff] [blame] | 258 | __dma_sync(addr, size, direction); |
| 259 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | EXPORT_SYMBOL(dma_sync_single_for_cpu); |
| 263 | |
| 264 | void dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle, |
| 265 | size_t size, enum dma_data_direction direction) |
| 266 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | BUG_ON(direction == DMA_NONE); |
| 268 | |
David Daney | 843aef4 | 2008-12-11 15:33:36 -0800 | [diff] [blame] | 269 | plat_extra_sync_for_device(dev); |
Thomas Bogendoerfer | 9b43fb6 | 2007-02-23 19:58:48 +0100 | [diff] [blame] | 270 | if (!plat_device_is_coherent(dev)) { |
Ralf Baechle | 9a88cbb | 2006-11-16 02:56:12 +0000 | [diff] [blame] | 271 | unsigned long addr; |
| 272 | |
Kevin Cernekee | 3807ef3f6 | 2009-04-23 17:25:12 -0700 | [diff] [blame] | 273 | addr = dma_addr_to_virt(dev, dma_handle); |
Ralf Baechle | 9a88cbb | 2006-11-16 02:56:12 +0000 | [diff] [blame] | 274 | __dma_sync(addr, size, direction); |
| 275 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | EXPORT_SYMBOL(dma_sync_single_for_device); |
| 279 | |
| 280 | void dma_sync_single_range_for_cpu(struct device *dev, dma_addr_t dma_handle, |
| 281 | unsigned long offset, size_t size, enum dma_data_direction direction) |
| 282 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | BUG_ON(direction == DMA_NONE); |
| 284 | |
Ralf Baechle | 9a88cbb | 2006-11-16 02:56:12 +0000 | [diff] [blame] | 285 | if (cpu_is_noncoherent_r10000(dev)) { |
| 286 | unsigned long addr; |
| 287 | |
Kevin Cernekee | 3807ef3f6 | 2009-04-23 17:25:12 -0700 | [diff] [blame] | 288 | addr = dma_addr_to_virt(dev, dma_handle); |
Ralf Baechle | 9a88cbb | 2006-11-16 02:56:12 +0000 | [diff] [blame] | 289 | __dma_sync(addr + offset, size, direction); |
| 290 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | EXPORT_SYMBOL(dma_sync_single_range_for_cpu); |
| 294 | |
| 295 | void dma_sync_single_range_for_device(struct device *dev, dma_addr_t dma_handle, |
| 296 | unsigned long offset, size_t size, enum dma_data_direction direction) |
| 297 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | BUG_ON(direction == DMA_NONE); |
| 299 | |
David Daney | 843aef4 | 2008-12-11 15:33:36 -0800 | [diff] [blame] | 300 | plat_extra_sync_for_device(dev); |
Thomas Bogendoerfer | 9b43fb6 | 2007-02-23 19:58:48 +0100 | [diff] [blame] | 301 | if (!plat_device_is_coherent(dev)) { |
Ralf Baechle | 9a88cbb | 2006-11-16 02:56:12 +0000 | [diff] [blame] | 302 | unsigned long addr; |
| 303 | |
Kevin Cernekee | 3807ef3f6 | 2009-04-23 17:25:12 -0700 | [diff] [blame] | 304 | addr = dma_addr_to_virt(dev, dma_handle); |
Ralf Baechle | 9a88cbb | 2006-11-16 02:56:12 +0000 | [diff] [blame] | 305 | __dma_sync(addr + offset, size, direction); |
| 306 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | EXPORT_SYMBOL(dma_sync_single_range_for_device); |
| 310 | |
| 311 | void dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, int nelems, |
| 312 | enum dma_data_direction direction) |
| 313 | { |
| 314 | int i; |
Ralf Baechle | 42a3b4f | 2005-09-03 15:56:17 -0700 | [diff] [blame] | 315 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | BUG_ON(direction == DMA_NONE); |
Ralf Baechle | 42a3b4f | 2005-09-03 15:56:17 -0700 | [diff] [blame] | 317 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | /* Make sure that gcc doesn't leave the empty loop body. */ |
Ralf Baechle | 9a88cbb | 2006-11-16 02:56:12 +0000 | [diff] [blame] | 319 | for (i = 0; i < nelems; i++, sg++) { |
Ralf Baechle | 5b648a9 | 2007-03-02 11:42:11 +0000 | [diff] [blame] | 320 | if (cpu_is_noncoherent_r10000(dev)) |
Jens Axboe | 58b053e | 2007-10-22 20:02:46 +0200 | [diff] [blame] | 321 | __dma_sync((unsigned long)page_address(sg_page(sg)), |
Ralf Baechle | 9a88cbb | 2006-11-16 02:56:12 +0000 | [diff] [blame] | 322 | sg->length, direction); |
Ralf Baechle | 9a88cbb | 2006-11-16 02:56:12 +0000 | [diff] [blame] | 323 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | EXPORT_SYMBOL(dma_sync_sg_for_cpu); |
| 327 | |
| 328 | void dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, int nelems, |
| 329 | enum dma_data_direction direction) |
| 330 | { |
| 331 | int i; |
| 332 | |
| 333 | BUG_ON(direction == DMA_NONE); |
| 334 | |
| 335 | /* Make sure that gcc doesn't leave the empty loop body. */ |
Ralf Baechle | 9a88cbb | 2006-11-16 02:56:12 +0000 | [diff] [blame] | 336 | for (i = 0; i < nelems; i++, sg++) { |
| 337 | if (!plat_device_is_coherent(dev)) |
Jens Axboe | 58b053e | 2007-10-22 20:02:46 +0200 | [diff] [blame] | 338 | __dma_sync((unsigned long)page_address(sg_page(sg)), |
Ralf Baechle | 9a88cbb | 2006-11-16 02:56:12 +0000 | [diff] [blame] | 339 | sg->length, direction); |
Ralf Baechle | 9a88cbb | 2006-11-16 02:56:12 +0000 | [diff] [blame] | 340 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | EXPORT_SYMBOL(dma_sync_sg_for_device); |
| 344 | |
FUJITA Tomonori | 8d8bb39 | 2008-07-25 19:44:49 -0700 | [diff] [blame] | 345 | int dma_mapping_error(struct device *dev, dma_addr_t dma_addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | { |
David Daney | 843aef4 | 2008-12-11 15:33:36 -0800 | [diff] [blame] | 347 | return plat_dma_mapping_error(dev, dma_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | EXPORT_SYMBOL(dma_mapping_error); |
| 351 | |
| 352 | int dma_supported(struct device *dev, u64 mask) |
| 353 | { |
David Daney | 843aef4 | 2008-12-11 15:33:36 -0800 | [diff] [blame] | 354 | return plat_dma_supported(dev, mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | EXPORT_SYMBOL(dma_supported); |
| 358 | |
Ralf Baechle | f67637e | 2006-12-06 20:38:54 -0800 | [diff] [blame] | 359 | int dma_is_consistent(struct device *dev, dma_addr_t dma_addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | { |
Ralf Baechle | 9a88cbb | 2006-11-16 02:56:12 +0000 | [diff] [blame] | 361 | return plat_device_is_coherent(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | EXPORT_SYMBOL(dma_is_consistent); |
| 365 | |
Ralf Baechle | d3fa72e | 2006-12-06 20:38:56 -0800 | [diff] [blame] | 366 | void dma_cache_sync(struct device *dev, void *vaddr, size_t size, |
Ralf Baechle | 9a88cbb | 2006-11-16 02:56:12 +0000 | [diff] [blame] | 367 | enum dma_data_direction direction) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | { |
Ralf Baechle | 9a88cbb | 2006-11-16 02:56:12 +0000 | [diff] [blame] | 369 | BUG_ON(direction == DMA_NONE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | |
David Daney | 843aef4 | 2008-12-11 15:33:36 -0800 | [diff] [blame] | 371 | plat_extra_sync_for_device(dev); |
Ralf Baechle | 9a88cbb | 2006-11-16 02:56:12 +0000 | [diff] [blame] | 372 | if (!plat_device_is_coherent(dev)) |
Thomas Bogendoerfer | c7c6b39 | 2007-11-27 19:31:33 +0100 | [diff] [blame] | 373 | __dma_sync((unsigned long)vaddr, size, direction); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | EXPORT_SYMBOL(dma_cache_sync); |