diff options
author | Marek Szyprowski <m.szyprowski@samsung.com> | 2012-05-16 12:31:23 -0400 |
---|---|---|
committer | Marek Szyprowski <m.szyprowski@samsung.com> | 2012-05-21 09:06:22 -0400 |
commit | f99d60341238fe73fc514129cd9ae4e44e1b2c47 (patch) | |
tree | 4e3214b9cdfbcddd9243f14161c77956eb3f5791 /arch/arm/mm | |
parent | 51fde3499b531d4cf278f4d2eaa6c45b2865b16b (diff) |
ARM: dma-mapping: use alloc, mmap, free from dma_ops
This patch converts dma_alloc/free/mmap_{coherent,writecombine}
functions to use generic alloc/free/mmap methods from dma_map_ops
structure. A new DMA_ATTR_WRITE_COMBINE DMA attribute have been
introduced to implement writecombine methods.
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Acked-by: Kyungmin Park <kyungmin.park@samsung.com>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Tested-By: Subash Patel <subash.ramaswamy@linaro.org>
Diffstat (limited to 'arch/arm/mm')
-rw-r--r-- | arch/arm/mm/dma-mapping.c | 60 |
1 files changed, 24 insertions, 36 deletions
diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index dddb406d0763..2501866a904c 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c | |||
@@ -113,6 +113,9 @@ static void arm_dma_sync_single_for_device(struct device *dev, | |||
113 | static int arm_dma_set_mask(struct device *dev, u64 dma_mask); | 113 | static int arm_dma_set_mask(struct device *dev, u64 dma_mask); |
114 | 114 | ||
115 | struct dma_map_ops arm_dma_ops = { | 115 | struct dma_map_ops arm_dma_ops = { |
116 | .alloc = arm_dma_alloc, | ||
117 | .free = arm_dma_free, | ||
118 | .mmap = arm_dma_mmap, | ||
116 | .map_page = arm_dma_map_page, | 119 | .map_page = arm_dma_map_page, |
117 | .unmap_page = arm_dma_unmap_page, | 120 | .unmap_page = arm_dma_unmap_page, |
118 | .map_sg = arm_dma_map_sg, | 121 | .map_sg = arm_dma_map_sg, |
@@ -415,10 +418,19 @@ static void __dma_free_remap(void *cpu_addr, size_t size) | |||
415 | arm_vmregion_free(&consistent_head, c); | 418 | arm_vmregion_free(&consistent_head, c); |
416 | } | 419 | } |
417 | 420 | ||
421 | static inline pgprot_t __get_dma_pgprot(struct dma_attrs *attrs, pgprot_t prot) | ||
422 | { | ||
423 | prot = dma_get_attr(DMA_ATTR_WRITE_COMBINE, attrs) ? | ||
424 | pgprot_writecombine(prot) : | ||
425 | pgprot_dmacoherent(prot); | ||
426 | return prot; | ||
427 | } | ||
428 | |||
418 | #else /* !CONFIG_MMU */ | 429 | #else /* !CONFIG_MMU */ |
419 | 430 | ||
420 | #define __dma_alloc_remap(page, size, gfp, prot, c) page_address(page) | 431 | #define __dma_alloc_remap(page, size, gfp, prot, c) page_address(page) |
421 | #define __dma_free_remap(addr, size) do { } while (0) | 432 | #define __dma_free_remap(addr, size) do { } while (0) |
433 | #define __get_dma_pgprot(attrs, prot) __pgprot(0) | ||
422 | 434 | ||
423 | #endif /* CONFIG_MMU */ | 435 | #endif /* CONFIG_MMU */ |
424 | 436 | ||
@@ -462,41 +474,33 @@ __dma_alloc(struct device *dev, size_t size, dma_addr_t *handle, gfp_t gfp, | |||
462 | * Allocate DMA-coherent memory space and return both the kernel remapped | 474 | * Allocate DMA-coherent memory space and return both the kernel remapped |
463 | * virtual and bus address for that space. | 475 | * virtual and bus address for that space. |
464 | */ | 476 | */ |
465 | void * | 477 | void *arm_dma_alloc(struct device *dev, size_t size, dma_addr_t *handle, |
466 | dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *handle, gfp_t gfp) | 478 | gfp_t gfp, struct dma_attrs *attrs) |
467 | { | 479 | { |
480 | pgprot_t prot = __get_dma_pgprot(attrs, pgprot_kernel); | ||
468 | void *memory; | 481 | void *memory; |
469 | 482 | ||
470 | if (dma_alloc_from_coherent(dev, size, handle, &memory)) | 483 | if (dma_alloc_from_coherent(dev, size, handle, &memory)) |
471 | return memory; | 484 | return memory; |
472 | 485 | ||
473 | return __dma_alloc(dev, size, handle, gfp, | 486 | return __dma_alloc(dev, size, handle, gfp, prot, |
474 | pgprot_dmacoherent(pgprot_kernel), | ||
475 | __builtin_return_address(0)); | 487 | __builtin_return_address(0)); |
476 | } | 488 | } |
477 | EXPORT_SYMBOL(dma_alloc_coherent); | ||
478 | 489 | ||
479 | /* | 490 | /* |
480 | * Allocate a writecombining region, in much the same way as | 491 | * Create userspace mapping for the DMA-coherent memory. |
481 | * dma_alloc_coherent above. | ||
482 | */ | 492 | */ |
483 | void * | 493 | int arm_dma_mmap(struct device *dev, struct vm_area_struct *vma, |
484 | dma_alloc_writecombine(struct device *dev, size_t size, dma_addr_t *handle, gfp_t gfp) | 494 | void *cpu_addr, dma_addr_t dma_addr, size_t size, |
485 | { | 495 | struct dma_attrs *attrs) |
486 | return __dma_alloc(dev, size, handle, gfp, | ||
487 | pgprot_writecombine(pgprot_kernel), | ||
488 | __builtin_return_address(0)); | ||
489 | } | ||
490 | EXPORT_SYMBOL(dma_alloc_writecombine); | ||
491 | |||
492 | static int dma_mmap(struct device *dev, struct vm_area_struct *vma, | ||
493 | void *cpu_addr, dma_addr_t dma_addr, size_t size) | ||
494 | { | 496 | { |
495 | int ret = -ENXIO; | 497 | int ret = -ENXIO; |
496 | #ifdef CONFIG_MMU | 498 | #ifdef CONFIG_MMU |
497 | unsigned long user_size, kern_size; | 499 | unsigned long user_size, kern_size; |
498 | struct arm_vmregion *c; | 500 | struct arm_vmregion *c; |
499 | 501 | ||
502 | vma->vm_page_prot = __get_dma_pgprot(attrs, vma->vm_page_prot); | ||
503 | |||
500 | if (dma_mmap_from_coherent(dev, vma, cpu_addr, size, &ret)) | 504 | if (dma_mmap_from_coherent(dev, vma, cpu_addr, size, &ret)) |
501 | return ret; | 505 | return ret; |
502 | 506 | ||
@@ -521,27 +525,12 @@ static int dma_mmap(struct device *dev, struct vm_area_struct *vma, | |||
521 | return ret; | 525 | return ret; |
522 | } | 526 | } |
523 | 527 | ||
524 | int dma_mmap_coherent(struct device *dev, struct vm_area_struct *vma, | ||
525 | void *cpu_addr, dma_addr_t dma_addr, size_t size) | ||
526 | { | ||
527 | vma->vm_page_prot = pgprot_dmacoherent(vma->vm_page_prot); | ||
528 | return dma_mmap(dev, vma, cpu_addr, dma_addr, size); | ||
529 | } | ||
530 | EXPORT_SYMBOL(dma_mmap_coherent); | ||
531 | |||
532 | int dma_mmap_writecombine(struct device *dev, struct vm_area_struct *vma, | ||
533 | void *cpu_addr, dma_addr_t dma_addr, size_t size) | ||
534 | { | ||
535 | vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot); | ||
536 | return dma_mmap(dev, vma, cpu_addr, dma_addr, size); | ||
537 | } | ||
538 | EXPORT_SYMBOL(dma_mmap_writecombine); | ||
539 | |||
540 | /* | 528 | /* |
541 | * free a page as defined by the above mapping. | 529 | * free a page as defined by the above mapping. |
542 | * Must not be called with IRQs disabled. | 530 | * Must not be called with IRQs disabled. |
543 | */ | 531 | */ |
544 | void dma_free_coherent(struct device *dev, size_t size, void *cpu_addr, dma_addr_t handle) | 532 | void arm_dma_free(struct device *dev, size_t size, void *cpu_addr, |
533 | dma_addr_t handle, struct dma_attrs *attrs) | ||
545 | { | 534 | { |
546 | WARN_ON(irqs_disabled()); | 535 | WARN_ON(irqs_disabled()); |
547 | 536 | ||
@@ -555,7 +544,6 @@ void dma_free_coherent(struct device *dev, size_t size, void *cpu_addr, dma_addr | |||
555 | 544 | ||
556 | __dma_free_buffer(pfn_to_page(dma_to_pfn(dev, handle)), size); | 545 | __dma_free_buffer(pfn_to_page(dma_to_pfn(dev, handle)), size); |
557 | } | 546 | } |
558 | EXPORT_SYMBOL(dma_free_coherent); | ||
559 | 547 | ||
560 | static void dma_cache_maint_page(struct page *page, unsigned long offset, | 548 | static void dma_cache_maint_page(struct page *page, unsigned long offset, |
561 | size_t size, enum dma_data_direction dir, | 549 | size_t size, enum dma_data_direction dir, |