aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/linux/dma-mapping.h255
1 files changed, 164 insertions, 91 deletions
diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
index 937c2a949fca..cef2127e1d70 100644
--- a/include/linux/dma-mapping.h
+++ b/include/linux/dma-mapping.h
@@ -194,33 +194,6 @@ static inline int dma_mmap_from_global_coherent(struct vm_area_struct *vma,
194} 194}
195#endif /* CONFIG_HAVE_GENERIC_DMA_COHERENT */ 195#endif /* CONFIG_HAVE_GENERIC_DMA_COHERENT */
196 196
197#ifdef CONFIG_HAS_DMA
198#include <asm/dma-mapping.h>
199static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
200{
201 if (dev && dev->dma_ops)
202 return dev->dma_ops;
203 return get_arch_dma_ops(dev ? dev->bus : NULL);
204}
205
206static inline void set_dma_ops(struct device *dev,
207 const struct dma_map_ops *dma_ops)
208{
209 dev->dma_ops = dma_ops;
210}
211#else
212/*
213 * Define the dma api to allow compilation of dma dependent code.
214 * Code that depends on the dma-mapping API needs to set 'depends on HAS_DMA'
215 * in its Kconfig, unless it already depends on <something> || COMPILE_TEST,
216 * where <something> guarantuees the availability of the dma-mapping API.
217 */
218static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
219{
220 return NULL;
221}
222#endif
223
224static inline bool dma_is_direct(const struct dma_map_ops *ops) 197static inline bool dma_is_direct(const struct dma_map_ops *ops)
225{ 198{
226 return likely(!ops); 199 return likely(!ops);
@@ -284,6 +257,22 @@ static inline void dma_direct_sync_sg_for_cpu(struct device *dev,
284} 257}
285#endif 258#endif
286 259
260#ifdef CONFIG_HAS_DMA
261#include <asm/dma-mapping.h>
262
263static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
264{
265 if (dev && dev->dma_ops)
266 return dev->dma_ops;
267 return get_arch_dma_ops(dev ? dev->bus : NULL);
268}
269
270static inline void set_dma_ops(struct device *dev,
271 const struct dma_map_ops *dma_ops)
272{
273 dev->dma_ops = dma_ops;
274}
275
287static inline dma_addr_t dma_map_page_attrs(struct device *dev, 276static inline dma_addr_t dma_map_page_attrs(struct device *dev,
288 struct page *page, size_t offset, size_t size, 277 struct page *page, size_t offset, size_t size,
289 enum dma_data_direction dir, unsigned long attrs) 278 enum dma_data_direction dir, unsigned long attrs)
@@ -399,13 +388,6 @@ static inline void dma_sync_single_for_cpu(struct device *dev, dma_addr_t addr,
399 debug_dma_sync_single_for_cpu(dev, addr, size, dir); 388 debug_dma_sync_single_for_cpu(dev, addr, size, dir);
400} 389}
401 390
402static inline void dma_sync_single_range_for_cpu(struct device *dev,
403 dma_addr_t addr, unsigned long offset, size_t size,
404 enum dma_data_direction dir)
405{
406 return dma_sync_single_for_cpu(dev, addr + offset, size, dir);
407}
408
409static inline void dma_sync_single_for_device(struct device *dev, 391static inline void dma_sync_single_for_device(struct device *dev,
410 dma_addr_t addr, size_t size, 392 dma_addr_t addr, size_t size,
411 enum dma_data_direction dir) 393 enum dma_data_direction dir)
@@ -420,13 +402,6 @@ static inline void dma_sync_single_for_device(struct device *dev,
420 debug_dma_sync_single_for_device(dev, addr, size, dir); 402 debug_dma_sync_single_for_device(dev, addr, size, dir);
421} 403}
422 404
423static inline void dma_sync_single_range_for_device(struct device *dev,
424 dma_addr_t addr, unsigned long offset, size_t size,
425 enum dma_data_direction dir)
426{
427 return dma_sync_single_for_device(dev, addr + offset, size, dir);
428}
429
430static inline void 405static inline void
431dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, 406dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
432 int nelems, enum dma_data_direction dir) 407 int nelems, enum dma_data_direction dir)
@@ -456,6 +431,138 @@ dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
456 431
457} 432}
458 433
434static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
435{
436 debug_dma_mapping_error(dev, dma_addr);
437
438 if (dma_addr == DMA_MAPPING_ERROR)
439 return -ENOMEM;
440 return 0;
441}
442
443void *dma_alloc_attrs(struct device *dev, size_t size, dma_addr_t *dma_handle,
444 gfp_t flag, unsigned long attrs);
445void dma_free_attrs(struct device *dev, size_t size, void *cpu_addr,
446 dma_addr_t dma_handle, unsigned long attrs);
447void *dmam_alloc_attrs(struct device *dev, size_t size, dma_addr_t *dma_handle,
448 gfp_t gfp, unsigned long attrs);
449void dmam_free_coherent(struct device *dev, size_t size, void *vaddr,
450 dma_addr_t dma_handle);
451void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
452 enum dma_data_direction dir);
453int dma_get_sgtable_attrs(struct device *dev, struct sg_table *sgt,
454 void *cpu_addr, dma_addr_t dma_addr, size_t size,
455 unsigned long attrs);
456int dma_mmap_attrs(struct device *dev, struct vm_area_struct *vma,
457 void *cpu_addr, dma_addr_t dma_addr, size_t size,
458 unsigned long attrs);
459int dma_supported(struct device *dev, u64 mask);
460int dma_set_mask(struct device *dev, u64 mask);
461int dma_set_coherent_mask(struct device *dev, u64 mask);
462u64 dma_get_required_mask(struct device *dev);
463#else /* CONFIG_HAS_DMA */
464static inline dma_addr_t dma_map_page_attrs(struct device *dev,
465 struct page *page, size_t offset, size_t size,
466 enum dma_data_direction dir, unsigned long attrs)
467{
468 return DMA_MAPPING_ERROR;
469}
470static inline void dma_unmap_page_attrs(struct device *dev, dma_addr_t addr,
471 size_t size, enum dma_data_direction dir, unsigned long attrs)
472{
473}
474static inline int dma_map_sg_attrs(struct device *dev, struct scatterlist *sg,
475 int nents, enum dma_data_direction dir, unsigned long attrs)
476{
477 return 0;
478}
479static inline void dma_unmap_sg_attrs(struct device *dev,
480 struct scatterlist *sg, int nents, enum dma_data_direction dir,
481 unsigned long attrs)
482{
483}
484static inline dma_addr_t dma_map_resource(struct device *dev,
485 phys_addr_t phys_addr, size_t size, enum dma_data_direction dir,
486 unsigned long attrs)
487{
488 return DMA_MAPPING_ERROR;
489}
490static inline void dma_unmap_resource(struct device *dev, dma_addr_t addr,
491 size_t size, enum dma_data_direction dir, unsigned long attrs)
492{
493}
494static inline void dma_sync_single_for_cpu(struct device *dev, dma_addr_t addr,
495 size_t size, enum dma_data_direction dir)
496{
497}
498static inline void dma_sync_single_for_device(struct device *dev,
499 dma_addr_t addr, size_t size, enum dma_data_direction dir)
500{
501}
502static inline void dma_sync_sg_for_cpu(struct device *dev,
503 struct scatterlist *sg, int nelems, enum dma_data_direction dir)
504{
505}
506static inline void dma_sync_sg_for_device(struct device *dev,
507 struct scatterlist *sg, int nelems, enum dma_data_direction dir)
508{
509}
510static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
511{
512 return -ENOMEM;
513}
514static inline void *dma_alloc_attrs(struct device *dev, size_t size,
515 dma_addr_t *dma_handle, gfp_t flag, unsigned long attrs)
516{
517 return NULL;
518}
519static void dma_free_attrs(struct device *dev, size_t size, void *cpu_addr,
520 dma_addr_t dma_handle, unsigned long attrs)
521{
522}
523static inline void *dmam_alloc_attrs(struct device *dev, size_t size,
524 dma_addr_t *dma_handle, gfp_t gfp, unsigned long attrs)
525{
526 return NULL;
527}
528static inline void dmam_free_coherent(struct device *dev, size_t size,
529 void *vaddr, dma_addr_t dma_handle)
530{
531}
532static inline void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
533 enum dma_data_direction dir)
534{
535}
536static inline int dma_get_sgtable_attrs(struct device *dev,
537 struct sg_table *sgt, void *cpu_addr, dma_addr_t dma_addr,
538 size_t size, unsigned long attrs)
539{
540 return -ENXIO;
541}
542static inline int dma_mmap_attrs(struct device *dev, struct vm_area_struct *vma,
543 void *cpu_addr, dma_addr_t dma_addr, size_t size,
544 unsigned long attrs)
545{
546 return -ENXIO;
547}
548static inline int dma_supported(struct device *dev, u64 mask)
549{
550 return 0;
551}
552static inline int dma_set_mask(struct device *dev, u64 mask)
553{
554 return -EIO;
555}
556static inline int dma_set_coherent_mask(struct device *dev, u64 mask)
557{
558 return -EIO;
559}
560static inline u64 dma_get_required_mask(struct device *dev)
561{
562 return 0;
563}
564#endif /* CONFIG_HAS_DMA */
565
459static inline dma_addr_t dma_map_single_attrs(struct device *dev, void *ptr, 566static inline dma_addr_t dma_map_single_attrs(struct device *dev, void *ptr,
460 size_t size, enum dma_data_direction dir, unsigned long attrs) 567 size_t size, enum dma_data_direction dir, unsigned long attrs)
461{ 568{
@@ -470,15 +577,28 @@ static inline void dma_unmap_single_attrs(struct device *dev, dma_addr_t addr,
470 return dma_unmap_page_attrs(dev, addr, size, dir, attrs); 577 return dma_unmap_page_attrs(dev, addr, size, dir, attrs);
471} 578}
472 579
580static inline void dma_sync_single_range_for_cpu(struct device *dev,
581 dma_addr_t addr, unsigned long offset, size_t size,
582 enum dma_data_direction dir)
583{
584 return dma_sync_single_for_cpu(dev, addr + offset, size, dir);
585}
586
587static inline void dma_sync_single_range_for_device(struct device *dev,
588 dma_addr_t addr, unsigned long offset, size_t size,
589 enum dma_data_direction dir)
590{
591 return dma_sync_single_for_device(dev, addr + offset, size, dir);
592}
593
473#define dma_map_single(d, a, s, r) dma_map_single_attrs(d, a, s, r, 0) 594#define dma_map_single(d, a, s, r) dma_map_single_attrs(d, a, s, r, 0)
474#define dma_unmap_single(d, a, s, r) dma_unmap_single_attrs(d, a, s, r, 0) 595#define dma_unmap_single(d, a, s, r) dma_unmap_single_attrs(d, a, s, r, 0)
475#define dma_map_sg(d, s, n, r) dma_map_sg_attrs(d, s, n, r, 0) 596#define dma_map_sg(d, s, n, r) dma_map_sg_attrs(d, s, n, r, 0)
476#define dma_unmap_sg(d, s, n, r) dma_unmap_sg_attrs(d, s, n, r, 0) 597#define dma_unmap_sg(d, s, n, r) dma_unmap_sg_attrs(d, s, n, r, 0)
477#define dma_map_page(d, p, o, s, r) dma_map_page_attrs(d, p, o, s, r, 0) 598#define dma_map_page(d, p, o, s, r) dma_map_page_attrs(d, p, o, s, r, 0)
478#define dma_unmap_page(d, a, s, r) dma_unmap_page_attrs(d, a, s, r, 0) 599#define dma_unmap_page(d, a, s, r) dma_unmap_page_attrs(d, a, s, r, 0)
479 600#define dma_get_sgtable(d, t, v, h, s) dma_get_sgtable_attrs(d, t, v, h, s, 0)
480void dma_cache_sync(struct device *dev, void *vaddr, size_t size, 601#define dma_mmap_coherent(d, v, c, h, s) dma_mmap_attrs(d, v, c, h, s, 0)
481 enum dma_data_direction dir);
482 602
483extern int dma_common_mmap(struct device *dev, struct vm_area_struct *vma, 603extern int dma_common_mmap(struct device *dev, struct vm_area_struct *vma,
484 void *cpu_addr, dma_addr_t dma_addr, size_t size, 604 void *cpu_addr, dma_addr_t dma_addr, size_t size,
@@ -498,25 +618,10 @@ bool dma_in_atomic_pool(void *start, size_t size);
498void *dma_alloc_from_pool(size_t size, struct page **ret_page, gfp_t flags); 618void *dma_alloc_from_pool(size_t size, struct page **ret_page, gfp_t flags);
499bool dma_free_from_pool(void *start, size_t size); 619bool dma_free_from_pool(void *start, size_t size);
500 620
501int dma_mmap_attrs(struct device *dev, struct vm_area_struct *vma,
502 void *cpu_addr, dma_addr_t dma_addr, size_t size,
503 unsigned long attrs);
504#define dma_mmap_coherent(d, v, c, h, s) dma_mmap_attrs(d, v, c, h, s, 0)
505
506int 621int
507dma_common_get_sgtable(struct device *dev, struct sg_table *sgt, void *cpu_addr, 622dma_common_get_sgtable(struct device *dev, struct sg_table *sgt, void *cpu_addr,
508 dma_addr_t dma_addr, size_t size, unsigned long attrs); 623 dma_addr_t dma_addr, size_t size, unsigned long attrs);
509 624
510int dma_get_sgtable_attrs(struct device *dev, struct sg_table *sgt,
511 void *cpu_addr, dma_addr_t dma_addr, size_t size,
512 unsigned long attrs);
513#define dma_get_sgtable(d, t, v, h, s) dma_get_sgtable_attrs(d, t, v, h, s, 0)
514
515void *dma_alloc_attrs(struct device *dev, size_t size, dma_addr_t *dma_handle,
516 gfp_t flag, unsigned long attrs);
517void dma_free_attrs(struct device *dev, size_t size, void *cpu_addr,
518 dma_addr_t dma_handle, unsigned long attrs);
519
520static inline void *dma_alloc_coherent(struct device *dev, size_t size, 625static inline void *dma_alloc_coherent(struct device *dev, size_t size,
521 dma_addr_t *dma_handle, gfp_t gfp) 626 dma_addr_t *dma_handle, gfp_t gfp)
522{ 627{
@@ -531,18 +636,6 @@ static inline void dma_free_coherent(struct device *dev, size_t size,
531 return dma_free_attrs(dev, size, cpu_addr, dma_handle, 0); 636 return dma_free_attrs(dev, size, cpu_addr, dma_handle, 0);
532} 637}
533 638
534static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
535{
536 debug_dma_mapping_error(dev, dma_addr);
537
538 if (dma_addr == DMA_MAPPING_ERROR)
539 return -ENOMEM;
540 return 0;
541}
542
543int dma_supported(struct device *dev, u64 mask);
544int dma_set_mask(struct device *dev, u64 mask);
545int dma_set_coherent_mask(struct device *dev, u64 mask);
546 639
547static inline u64 dma_get_mask(struct device *dev) 640static inline u64 dma_get_mask(struct device *dev)
548{ 641{
@@ -575,8 +668,6 @@ static inline int dma_coerce_mask_and_coherent(struct device *dev, u64 mask)
575 return dma_set_mask_and_coherent(dev, mask); 668 return dma_set_mask_and_coherent(dev, mask);
576} 669}
577 670
578extern u64 dma_get_required_mask(struct device *dev);
579
580#ifndef arch_setup_dma_ops 671#ifndef arch_setup_dma_ops
581static inline void arch_setup_dma_ops(struct device *dev, u64 dma_base, 672static inline void arch_setup_dma_ops(struct device *dev, u64 dma_base,
582 u64 size, const struct iommu_ops *iommu, 673 u64 size, const struct iommu_ops *iommu,
@@ -673,24 +764,6 @@ dma_mark_declared_memory_occupied(struct device *dev,
673} 764}
674#endif /* CONFIG_HAVE_GENERIC_DMA_COHERENT */ 765#endif /* CONFIG_HAVE_GENERIC_DMA_COHERENT */
675 766
676/*
677 * Managed DMA API
678 */
679#ifdef CONFIG_HAS_DMA
680extern void *dmam_alloc_attrs(struct device *dev, size_t size,
681 dma_addr_t *dma_handle, gfp_t gfp,
682 unsigned long attrs);
683extern void dmam_free_coherent(struct device *dev, size_t size, void *vaddr,
684 dma_addr_t dma_handle);
685#else /* !CONFIG_HAS_DMA */
686static inline void *dmam_alloc_attrs(struct device *dev, size_t size,
687 dma_addr_t *dma_handle, gfp_t gfp,
688 unsigned long attrs)
689{ return NULL; }
690static inline void dmam_free_coherent(struct device *dev, size_t size,
691 void *vaddr, dma_addr_t dma_handle) { }
692#endif /* !CONFIG_HAS_DMA */
693
694static inline void *dmam_alloc_coherent(struct device *dev, size_t size, 767static inline void *dmam_alloc_coherent(struct device *dev, size_t size,
695 dma_addr_t *dma_handle, gfp_t gfp) 768 dma_addr_t *dma_handle, gfp_t gfp)
696{ 769{