Skip to content

Commit 21caf3a

Browse files
LorenzoNavaRussell King
authored andcommitted
ARM: 8398/1: arm DMA: Fix allocation from CMA for coherent DMA
This patch allows the use of CMA for DMA coherent memory allocation. At the moment if the input parameter "is_coherent" is set to true the allocation is not made using the CMA, which I think is not the desired behaviour. The patch covers the allocation and free of memory for coherent DMA. Signed-off-by: Lorenzo Nava <lorenx4@gmail.com> Reviewed-by: Catalin Marinas <catalin.marinas@arm.com> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
1 parent 1234e3f commit 21caf3a

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

arch/arm/mm/dma-mapping.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -649,14 +649,18 @@ static void *__dma_alloc(struct device *dev, size_t size, dma_addr_t *handle,
649649
size = PAGE_ALIGN(size);
650650
want_vaddr = !dma_get_attr(DMA_ATTR_NO_KERNEL_MAPPING, attrs);
651651

652-
if (is_coherent || nommu())
652+
if (nommu())
653+
addr = __alloc_simple_buffer(dev, size, gfp, &page);
654+
else if (dev_get_cma_area(dev) && (gfp & __GFP_WAIT))
655+
addr = __alloc_from_contiguous(dev, size, prot, &page,
656+
caller, want_vaddr);
657+
else if (is_coherent)
653658
addr = __alloc_simple_buffer(dev, size, gfp, &page);
654659
else if (!(gfp & __GFP_WAIT))
655660
addr = __alloc_from_pool(size, &page);
656-
else if (!dev_get_cma_area(dev))
657-
addr = __alloc_remap_buffer(dev, size, gfp, prot, &page, caller, want_vaddr);
658661
else
659-
addr = __alloc_from_contiguous(dev, size, prot, &page, caller, want_vaddr);
662+
addr = __alloc_remap_buffer(dev, size, gfp, prot, &page,
663+
caller, want_vaddr);
660664

661665
if (page)
662666
*handle = pfn_to_dma(dev, page_to_pfn(page));
@@ -684,13 +688,12 @@ void *arm_dma_alloc(struct device *dev, size_t size, dma_addr_t *handle,
684688
static void *arm_coherent_dma_alloc(struct device *dev, size_t size,
685689
dma_addr_t *handle, gfp_t gfp, struct dma_attrs *attrs)
686690
{
687-
pgprot_t prot = __get_dma_pgprot(attrs, PAGE_KERNEL);
688691
void *memory;
689692

690693
if (dma_alloc_from_coherent(dev, size, handle, &memory))
691694
return memory;
692695

693-
return __dma_alloc(dev, size, handle, gfp, prot, true,
696+
return __dma_alloc(dev, size, handle, gfp, PAGE_KERNEL, true,
694697
attrs, __builtin_return_address(0));
695698
}
696699

@@ -754,12 +757,12 @@ static void __arm_dma_free(struct device *dev, size_t size, void *cpu_addr,
754757

755758
size = PAGE_ALIGN(size);
756759

757-
if (is_coherent || nommu()) {
760+
if (nommu()) {
758761
__dma_free_buffer(page, size);
759-
} else if (__free_from_pool(cpu_addr, size)) {
762+
} else if (!is_coherent && __free_from_pool(cpu_addr, size)) {
760763
return;
761764
} else if (!dev_get_cma_area(dev)) {
762-
if (want_vaddr)
765+
if (want_vaddr && !is_coherent)
763766
__dma_free_remap(cpu_addr, size);
764767
__dma_free_buffer(page, size);
765768
} else {

0 commit comments

Comments
 (0)