aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/arm/common/dmabounce.c48
-rw-r--r--arch/arm/include/asm/dma-mapping.h104
2 files changed, 64 insertions, 88 deletions
diff --git a/arch/arm/common/dmabounce.c b/arch/arm/common/dmabounce.c
index d4b0c608fdee..22aec95c9863 100644
--- a/arch/arm/common/dmabounce.c
+++ b/arch/arm/common/dmabounce.c
@@ -154,9 +154,7 @@ alloc_safe_buffer(struct dmabounce_device_info *device_info, void *ptr,
154#endif 154#endif
155 155
156 write_lock_irqsave(&device_info->lock, flags); 156 write_lock_irqsave(&device_info->lock, flags);
157
158 list_add(&buf->node, &device_info->safe_buffers); 157 list_add(&buf->node, &device_info->safe_buffers);
159
160 write_unlock_irqrestore(&device_info->lock, flags); 158 write_unlock_irqrestore(&device_info->lock, flags);
161 159
162 return buf; 160 return buf;
@@ -220,8 +218,7 @@ static struct safe_buffer *find_safe_buffer_dev(struct device *dev,
220 return find_safe_buffer(dev->archdata.dmabounce, dma_addr); 218 return find_safe_buffer(dev->archdata.dmabounce, dma_addr);
221} 219}
222 220
223static inline dma_addr_t 221static inline dma_addr_t map_single(struct device *dev, void *ptr, size_t size,
224map_single(struct device *dev, void *ptr, size_t size,
225 enum dma_data_direction dir) 222 enum dma_data_direction dir)
226{ 223{
227 struct dmabounce_device_info *device_info = dev->archdata.dmabounce; 224 struct dmabounce_device_info *device_info = dev->archdata.dmabounce;
@@ -285,9 +282,8 @@ map_single(struct device *dev, void *ptr, size_t size,
285 return dma_addr; 282 return dma_addr;
286} 283}
287 284
288static inline void 285static inline void unmap_single(struct device *dev, dma_addr_t dma_addr,
289unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size, 286 size_t size, enum dma_data_direction dir)
290 enum dma_data_direction dir)
291{ 287{
292 struct safe_buffer *buf = find_safe_buffer_dev(dev, dma_addr, "unmap"); 288 struct safe_buffer *buf = find_safe_buffer_dev(dev, dma_addr, "unmap");
293 289
@@ -332,25 +328,20 @@ unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
332 * substitute the safe buffer for the unsafe one. 328 * substitute the safe buffer for the unsafe one.
333 * (basically move the buffer from an unsafe area to a safe one) 329 * (basically move the buffer from an unsafe area to a safe one)
334 */ 330 */
335dma_addr_t 331dma_addr_t dma_map_single(struct device *dev, void *ptr, size_t size,
336dma_map_single(struct device *dev, void *ptr, size_t size,
337 enum dma_data_direction dir) 332 enum dma_data_direction dir)
338{ 333{
339 dma_addr_t dma_addr;
340
341 dev_dbg(dev, "%s(ptr=%p,size=%d,dir=%x)\n", 334 dev_dbg(dev, "%s(ptr=%p,size=%d,dir=%x)\n",
342 __func__, ptr, size, dir); 335 __func__, ptr, size, dir);
343 336
344 BUG_ON(dir == DMA_NONE); 337 BUG_ON(dir == DMA_NONE);
345 338
346 dma_addr = map_single(dev, ptr, size, dir); 339 return map_single(dev, ptr, size, dir);
347
348 return dma_addr;
349} 340}
341EXPORT_SYMBOL(dma_map_single);
350 342
351dma_addr_t dma_map_page(struct device *dev, struct page *page, 343dma_addr_t dma_map_page(struct device *dev, struct page *page,
352 unsigned long offset, size_t size, 344 unsigned long offset, size_t size, enum dma_data_direction dir)
353 enum dma_data_direction dir)
354{ 345{
355 dev_dbg(dev, "%s(page=%p,off=%#lx,size=%zx,dir=%x)\n", 346 dev_dbg(dev, "%s(page=%p,off=%#lx,size=%zx,dir=%x)\n",
356 __func__, page, offset, size, dir); 347 __func__, page, offset, size, dir);
@@ -368,9 +359,8 @@ EXPORT_SYMBOL(dma_map_page);
368 * should be) 359 * should be)
369 */ 360 */
370 361
371void 362void dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
372dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size, 363 enum dma_data_direction dir)
373 enum dma_data_direction dir)
374{ 364{
375 dev_dbg(dev, "%s(ptr=%p,size=%d,dir=%x)\n", 365 dev_dbg(dev, "%s(ptr=%p,size=%d,dir=%x)\n",
376 __func__, (void *) dma_addr, size, dir); 366 __func__, (void *) dma_addr, size, dir);
@@ -379,6 +369,7 @@ dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
379 369
380 unmap_single(dev, dma_addr, size, dir); 370 unmap_single(dev, dma_addr, size, dir);
381} 371}
372EXPORT_SYMBOL(dma_unmap_single);
382 373
383int dmabounce_sync_for_cpu(struct device *dev, dma_addr_t addr, 374int dmabounce_sync_for_cpu(struct device *dev, dma_addr_t addr,
384 unsigned long off, size_t sz, enum dma_data_direction dir) 375 unsigned long off, size_t sz, enum dma_data_direction dir)
@@ -434,9 +425,8 @@ int dmabounce_sync_for_device(struct device *dev, dma_addr_t addr,
434} 425}
435EXPORT_SYMBOL(dmabounce_sync_for_device); 426EXPORT_SYMBOL(dmabounce_sync_for_device);
436 427
437static int 428static int dmabounce_init_pool(struct dmabounce_pool *pool, struct device *dev,
438dmabounce_init_pool(struct dmabounce_pool *pool, struct device *dev, const char *name, 429 const char *name, unsigned long size)
439 unsigned long size)
440{ 430{
441 pool->size = size; 431 pool->size = size;
442 DO_STATS(pool->allocs = 0); 432 DO_STATS(pool->allocs = 0);
@@ -447,9 +437,8 @@ dmabounce_init_pool(struct dmabounce_pool *pool, struct device *dev, const char
447 return pool->pool ? 0 : -ENOMEM; 437 return pool->pool ? 0 : -ENOMEM;
448} 438}
449 439
450int 440int dmabounce_register_dev(struct device *dev, unsigned long small_buffer_size,
451dmabounce_register_dev(struct device *dev, unsigned long small_buffer_size, 441 unsigned long large_buffer_size)
452 unsigned long large_buffer_size)
453{ 442{
454 struct dmabounce_device_info *device_info; 443 struct dmabounce_device_info *device_info;
455 int ret; 444 int ret;
@@ -505,9 +494,9 @@ dmabounce_register_dev(struct device *dev, unsigned long small_buffer_size,
505 kfree(device_info); 494 kfree(device_info);
506 return ret; 495 return ret;
507} 496}
497EXPORT_SYMBOL(dmabounce_register_dev);
508 498
509void 499void dmabounce_unregister_dev(struct device *dev)
510dmabounce_unregister_dev(struct device *dev)
511{ 500{
512 struct dmabounce_device_info *device_info = dev->archdata.dmabounce; 501 struct dmabounce_device_info *device_info = dev->archdata.dmabounce;
513 502
@@ -540,11 +529,6 @@ dmabounce_unregister_dev(struct device *dev)
540 529
541 dev_info(dev, "dmabounce: device unregistered\n"); 530 dev_info(dev, "dmabounce: device unregistered\n");
542} 531}
543
544
545EXPORT_SYMBOL(dma_map_single);
546EXPORT_SYMBOL(dma_unmap_single);
547EXPORT_SYMBOL(dmabounce_register_dev);
548EXPORT_SYMBOL(dmabounce_unregister_dev); 532EXPORT_SYMBOL(dmabounce_unregister_dev);
549 533
550MODULE_AUTHOR("Christopher Hoover <ch@hpl.hp.com>, Deepak Saxena <dsaxena@plexity.net>"); 534MODULE_AUTHOR("Christopher Hoover <ch@hpl.hp.com>, Deepak Saxena <dsaxena@plexity.net>");
diff --git a/arch/arm/include/asm/dma-mapping.h b/arch/arm/include/asm/dma-mapping.h
index 1204dc958c43..1532b7a6079d 100644
--- a/arch/arm/include/asm/dma-mapping.h
+++ b/arch/arm/include/asm/dma-mapping.h
@@ -104,15 +104,14 @@ static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
104 * Dummy noncoherent implementation. We don't provide a dma_cache_sync 104 * Dummy noncoherent implementation. We don't provide a dma_cache_sync
105 * function so drivers using this API are highlighted with build warnings. 105 * function so drivers using this API are highlighted with build warnings.
106 */ 106 */
107static inline void * 107static inline void *dma_alloc_noncoherent(struct device *dev, size_t size,
108dma_alloc_noncoherent(struct device *dev, size_t size, dma_addr_t *handle, gfp_t gfp) 108 dma_addr_t *handle, gfp_t gfp)
109{ 109{
110 return NULL; 110 return NULL;
111} 111}
112 112
113static inline void 113static inline void dma_free_noncoherent(struct device *dev, size_t size,
114dma_free_noncoherent(struct device *dev, size_t size, void *cpu_addr, 114 void *cpu_addr, dma_addr_t handle)
115 dma_addr_t handle)
116{ 115{
117} 116}
118 117
@@ -127,8 +126,7 @@ dma_free_noncoherent(struct device *dev, size_t size, void *cpu_addr,
127 * return the CPU-viewed address, and sets @handle to be the 126 * return the CPU-viewed address, and sets @handle to be the
128 * device-viewed address. 127 * device-viewed address.
129 */ 128 */
130extern void * 129extern void *dma_alloc_coherent(struct device *, size_t, dma_addr_t *, gfp_t);
131dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *handle, gfp_t gfp);
132 130
133/** 131/**
134 * dma_free_coherent - free memory allocated by dma_alloc_coherent 132 * dma_free_coherent - free memory allocated by dma_alloc_coherent
@@ -143,9 +141,7 @@ dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *handle, gfp_t gf
143 * References to memory and mappings associated with cpu_addr/handle 141 * References to memory and mappings associated with cpu_addr/handle
144 * during and after this call executing are illegal. 142 * during and after this call executing are illegal.
145 */ 143 */
146extern void 144extern void dma_free_coherent(struct device *, size_t, void *, dma_addr_t);
147dma_free_coherent(struct device *dev, size_t size, void *cpu_addr,
148 dma_addr_t handle);
149 145
150/** 146/**
151 * dma_mmap_coherent - map a coherent DMA allocation into user space 147 * dma_mmap_coherent - map a coherent DMA allocation into user space
@@ -159,8 +155,8 @@ dma_free_coherent(struct device *dev, size_t size, void *cpu_addr,
159 * into user space. The coherent DMA buffer must not be freed by the 155 * into user space. The coherent DMA buffer must not be freed by the
160 * driver until the user space mapping has been released. 156 * driver until the user space mapping has been released.
161 */ 157 */
162int dma_mmap_coherent(struct device *dev, struct vm_area_struct *vma, 158int dma_mmap_coherent(struct device *, struct vm_area_struct *,
163 void *cpu_addr, dma_addr_t handle, size_t size); 159 void *, dma_addr_t, size_t);
164 160
165 161
166/** 162/**
@@ -174,14 +170,14 @@ int dma_mmap_coherent(struct device *dev, struct vm_area_struct *vma,
174 * return the CPU-viewed address, and sets @handle to be the 170 * return the CPU-viewed address, and sets @handle to be the
175 * device-viewed address. 171 * device-viewed address.
176 */ 172 */
177extern void * 173extern void *dma_alloc_writecombine(struct device *, size_t, dma_addr_t *,
178dma_alloc_writecombine(struct device *dev, size_t size, dma_addr_t *handle, gfp_t gfp); 174 gfp_t);
179 175
180#define dma_free_writecombine(dev,size,cpu_addr,handle) \ 176#define dma_free_writecombine(dev,size,cpu_addr,handle) \
181 dma_free_coherent(dev,size,cpu_addr,handle) 177 dma_free_coherent(dev,size,cpu_addr,handle)
182 178
183int dma_mmap_writecombine(struct device *dev, struct vm_area_struct *vma, 179int dma_mmap_writecombine(struct device *, struct vm_area_struct *,
184 void *cpu_addr, dma_addr_t handle, size_t size); 180 void *, dma_addr_t, size_t);
185 181
186 182
187#ifdef CONFIG_DMABOUNCE 183#ifdef CONFIG_DMABOUNCE
@@ -209,7 +205,8 @@ int dma_mmap_writecombine(struct device *dev, struct vm_area_struct *vma,
209 * appropriate DMA pools for the device. 205 * appropriate DMA pools for the device.
210 * 206 *
211 */ 207 */
212extern int dmabounce_register_dev(struct device *, unsigned long, unsigned long); 208extern int dmabounce_register_dev(struct device *, unsigned long,
209 unsigned long);
213 210
214/** 211/**
215 * dmabounce_unregister_dev 212 * dmabounce_unregister_dev
@@ -244,19 +241,20 @@ extern int dma_needs_bounce(struct device*, dma_addr_t, size_t);
244/* 241/*
245 * The DMA API, implemented by dmabounce.c. See below for descriptions. 242 * The DMA API, implemented by dmabounce.c. See below for descriptions.
246 */ 243 */
247extern dma_addr_t dma_map_single(struct device *,void *, size_t, enum dma_data_direction); 244extern dma_addr_t dma_map_single(struct device *, void *, size_t,
248extern dma_addr_t dma_map_page(struct device *dev, struct page *page, 245 enum dma_data_direction);
249 unsigned long offset, size_t size, 246extern dma_addr_t dma_map_page(struct device *, struct page *,
250 enum dma_data_direction dir); 247 unsigned long, size_t, enum dma_data_direction);
251extern void dma_unmap_single(struct device *, dma_addr_t, size_t, enum dma_data_direction); 248extern void dma_unmap_single(struct device *, dma_addr_t, size_t,
249 enum dma_data_direction);
252 250
253/* 251/*
254 * Private functions 252 * Private functions
255 */ 253 */
256int dmabounce_sync_for_cpu(struct device *, dma_addr_t, unsigned long, 254int dmabounce_sync_for_cpu(struct device *, dma_addr_t, unsigned long,
257 size_t, enum dma_data_direction); 255 size_t, enum dma_data_direction);
258int dmabounce_sync_for_device(struct device *, dma_addr_t, unsigned long, 256int dmabounce_sync_for_device(struct device *, dma_addr_t, unsigned long,
259 size_t, enum dma_data_direction); 257 size_t, enum dma_data_direction);
260#else 258#else
261#define dmabounce_sync_for_cpu(dev,dma,off,sz,dir) (1) 259#define dmabounce_sync_for_cpu(dev,dma,off,sz,dir) (1)
262#define dmabounce_sync_for_device(dev,dma,off,sz,dir) (1) 260#define dmabounce_sync_for_device(dev,dma,off,sz,dir) (1)
@@ -276,9 +274,8 @@ int dmabounce_sync_for_device(struct device *, dma_addr_t, unsigned long,
276 * can regain ownership by calling dma_unmap_single() or 274 * can regain ownership by calling dma_unmap_single() or
277 * dma_sync_single_for_cpu(). 275 * dma_sync_single_for_cpu().
278 */ 276 */
279static inline dma_addr_t 277static inline dma_addr_t dma_map_single(struct device *dev, void *cpu_addr,
280dma_map_single(struct device *dev, void *cpu_addr, size_t size, 278 size_t size, enum dma_data_direction dir)
281 enum dma_data_direction dir)
282{ 279{
283 if (!arch_is_coherent()) 280 if (!arch_is_coherent())
284 dma_cache_maint(cpu_addr, size, dir); 281 dma_cache_maint(cpu_addr, size, dir);
@@ -286,7 +283,6 @@ dma_map_single(struct device *dev, void *cpu_addr, size_t size,
286 return virt_to_dma(dev, cpu_addr); 283 return virt_to_dma(dev, cpu_addr);
287} 284}
288 285
289
290/** 286/**
291 * dma_map_page - map a portion of a page for streaming DMA 287 * dma_map_page - map a portion of a page for streaming DMA
292 * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices 288 * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
@@ -302,10 +298,8 @@ dma_map_single(struct device *dev, void *cpu_addr, size_t size,
302 * can regain ownership by calling dma_unmap_page() or 298 * can regain ownership by calling dma_unmap_page() or
303 * dma_sync_single_for_cpu(). 299 * dma_sync_single_for_cpu().
304 */ 300 */
305static inline dma_addr_t 301static inline dma_addr_t dma_map_page(struct device *dev, struct page *page,
306dma_map_page(struct device *dev, struct page *page, 302 unsigned long offset, size_t size, enum dma_data_direction dir)
307 unsigned long offset, size_t size,
308 enum dma_data_direction dir)
309{ 303{
310 if (!arch_is_coherent()) 304 if (!arch_is_coherent())
311 dma_cache_maint(page_address(page) + offset, size, dir); 305 dma_cache_maint(page_address(page) + offset, size, dir);
@@ -327,9 +321,8 @@ dma_map_page(struct device *dev, struct page *page,
327 * After this call, reads by the CPU to the buffer are guaranteed to see 321 * After this call, reads by the CPU to the buffer are guaranteed to see
328 * whatever the device wrote there. 322 * whatever the device wrote there.
329 */ 323 */
330static inline void 324static inline void dma_unmap_single(struct device *dev, dma_addr_t handle,
331dma_unmap_single(struct device *dev, dma_addr_t handle, size_t size, 325 size_t size, enum dma_data_direction dir)
332 enum dma_data_direction dir)
333{ 326{
334 /* nothing to do */ 327 /* nothing to do */
335} 328}
@@ -349,9 +342,8 @@ dma_unmap_single(struct device *dev, dma_addr_t handle, size_t size,
349 * After this call, reads by the CPU to the buffer are guaranteed to see 342 * After this call, reads by the CPU to the buffer are guaranteed to see
350 * whatever the device wrote there. 343 * whatever the device wrote there.
351 */ 344 */
352static inline void 345static inline void dma_unmap_page(struct device *dev, dma_addr_t handle,
353dma_unmap_page(struct device *dev, dma_addr_t handle, size_t size, 346 size_t size, enum dma_data_direction dir)
354 enum dma_data_direction dir)
355{ 347{
356 dma_unmap_single(dev, handle, size, dir); 348 dma_unmap_single(dev, handle, size, dir);
357} 349}
@@ -374,10 +366,9 @@ dma_unmap_page(struct device *dev, dma_addr_t handle, size_t size,
374 * must first the perform a dma_sync_for_device, and then the 366 * must first the perform a dma_sync_for_device, and then the
375 * device again owns the buffer. 367 * device again owns the buffer.
376 */ 368 */
377static inline void 369static inline void dma_sync_single_range_for_cpu(struct device *dev,
378dma_sync_single_range_for_cpu(struct device *dev, dma_addr_t handle, 370 dma_addr_t handle, unsigned long offset, size_t size,
379 unsigned long offset, size_t size, 371 enum dma_data_direction dir)
380 enum dma_data_direction dir)
381{ 372{
382 if (!dmabounce_sync_for_cpu(dev, handle, offset, size, dir)) 373 if (!dmabounce_sync_for_cpu(dev, handle, offset, size, dir))
383 return; 374 return;
@@ -386,10 +377,9 @@ dma_sync_single_range_for_cpu(struct device *dev, dma_addr_t handle,
386 dma_cache_maint(dma_to_virt(dev, handle) + offset, size, dir); 377 dma_cache_maint(dma_to_virt(dev, handle) + offset, size, dir);
387} 378}
388 379
389static inline void 380static inline void dma_sync_single_range_for_device(struct device *dev,
390dma_sync_single_range_for_device(struct device *dev, dma_addr_t handle, 381 dma_addr_t handle, unsigned long offset, size_t size,
391 unsigned long offset, size_t size, 382 enum dma_data_direction dir)
392 enum dma_data_direction dir)
393{ 383{
394 if (!dmabounce_sync_for_device(dev, handle, offset, size, dir)) 384 if (!dmabounce_sync_for_device(dev, handle, offset, size, dir))
395 return; 385 return;
@@ -398,16 +388,14 @@ dma_sync_single_range_for_device(struct device *dev, dma_addr_t handle,
398 dma_cache_maint(dma_to_virt(dev, handle) + offset, size, dir); 388 dma_cache_maint(dma_to_virt(dev, handle) + offset, size, dir);
399} 389}
400 390
401static inline void 391static inline void dma_sync_single_for_cpu(struct device *dev,
402dma_sync_single_for_cpu(struct device *dev, dma_addr_t handle, size_t size, 392 dma_addr_t handle, size_t size, enum dma_data_direction dir)
403 enum dma_data_direction dir)
404{ 393{
405 dma_sync_single_range_for_cpu(dev, handle, 0, size, dir); 394 dma_sync_single_range_for_cpu(dev, handle, 0, size, dir);
406} 395}
407 396
408static inline void 397static inline void dma_sync_single_for_device(struct device *dev,
409dma_sync_single_for_device(struct device *dev, dma_addr_t handle, size_t size, 398 dma_addr_t handle, size_t size, enum dma_data_direction dir)
410 enum dma_data_direction dir)
411{ 399{
412 dma_sync_single_range_for_device(dev, handle, 0, size, dir); 400 dma_sync_single_range_for_device(dev, handle, 0, size, dir);
413} 401}
@@ -415,10 +403,14 @@ dma_sync_single_for_device(struct device *dev, dma_addr_t handle, size_t size,
415/* 403/*
416 * The scatter list versions of the above methods. 404 * The scatter list versions of the above methods.
417 */ 405 */
418extern int dma_map_sg(struct device *, struct scatterlist *, int, enum dma_data_direction); 406extern int dma_map_sg(struct device *, struct scatterlist *, int,
419extern void dma_unmap_sg(struct device *, struct scatterlist *, int, enum dma_data_direction); 407 enum dma_data_direction);
420extern void dma_sync_sg_for_cpu(struct device*, struct scatterlist*, int, enum dma_data_direction); 408extern void dma_unmap_sg(struct device *, struct scatterlist *, int,
421extern void dma_sync_sg_for_device(struct device*, struct scatterlist*, int, enum dma_data_direction); 409 enum dma_data_direction);
410extern void dma_sync_sg_for_cpu(struct device *, struct scatterlist *, int,
411 enum dma_data_direction);
412extern void dma_sync_sg_for_device(struct device *, struct scatterlist *, int,
413 enum dma_data_direction);
422 414
423 415
424#endif /* __KERNEL__ */ 416#endif /* __KERNEL__ */