Skip to content

Commit

Permalink
drivers: dma-coherent: use MEMREMAP_WC for DMA_MEMORY_MAP
Browse files Browse the repository at this point in the history
When the DMA_MEMORY_MAP flag is used, memory which can be accessed
directly should be returned, so use memremap(..., MEMREMAP_WC) to
provide a writecombine mapping.

Signed-off-by: Brian Starkey <brian.starkey@arm.com>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Brian Starkey authored and Linus Torvalds committed Mar 22, 2016
1 parent c907e0e commit 6b03ae0
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions drivers/base/dma-coherent.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Coherent per-device memory handling.
* Borrowed from i386
*/
#include <linux/io.h>
#include <linux/slab.h>
#include <linux/kernel.h>
#include <linux/module.h>
Expand Down Expand Up @@ -31,7 +32,10 @@ static bool dma_init_coherent_memory(
if (!size)
goto out;

mem_base = ioremap(phys_addr, size);
if (flags & DMA_MEMORY_MAP)
mem_base = memremap(phys_addr, size, MEMREMAP_WC);
else
mem_base = ioremap(phys_addr, size);
if (!mem_base)
goto out;

Expand All @@ -54,16 +58,24 @@ static bool dma_init_coherent_memory(

out:
kfree(dma_mem);
if (mem_base)
iounmap(mem_base);
if (mem_base) {
if (flags & DMA_MEMORY_MAP)
memunmap(mem_base);
else
iounmap(mem_base);
}
return false;
}

static void dma_release_coherent_memory(struct dma_coherent_mem *mem)
{
if (!mem)
return;
iounmap(mem->virt_base);

if (mem->flags & DMA_MEMORY_MAP)
memunmap(mem->virt_base);
else
iounmap(mem->virt_base);
kfree(mem->bitmap);
kfree(mem);
}
Expand Down

0 comments on commit 6b03ae0

Please sign in to comment.