drivers: dma-coherent: use MEMREMAP_WC for DMA_MEMORY_MAP
authorBrian Starkey <brian.starkey@arm.com>
Tue, 22 Mar 2016 21:28:03 +0000 (14:28 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 22 Mar 2016 22:36:02 +0000 (15:36 -0700)
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>
drivers/base/dma-coherent.c

index 87b8083748885592c8da34f2defa4a1b46be0be5..25bb398ec7a13d40fffbdea6b3cb5352639e4b0c 100644 (file)
@@ -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>
@@ -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;
 
@@ -54,8 +58,12 @@ 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;
 }
 
@@ -63,7 +71,11 @@ 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);
 }