Skip to content

Commit 6b03ae0

Browse files
Brian Starkeytorvalds
authored andcommitted
drivers: dma-coherent: use MEMREMAP_WC for DMA_MEMORY_MAP
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>
1 parent c907e0e commit 6b03ae0

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

drivers/base/dma-coherent.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Coherent per-device memory handling.
33
* Borrowed from i386
44
*/
5+
#include <linux/io.h>
56
#include <linux/slab.h>
67
#include <linux/kernel.h>
78
#include <linux/module.h>
@@ -31,7 +32,10 @@ static bool dma_init_coherent_memory(
3132
if (!size)
3233
goto out;
3334

34-
mem_base = ioremap(phys_addr, size);
35+
if (flags & DMA_MEMORY_MAP)
36+
mem_base = memremap(phys_addr, size, MEMREMAP_WC);
37+
else
38+
mem_base = ioremap(phys_addr, size);
3539
if (!mem_base)
3640
goto out;
3741

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

5559
out:
5660
kfree(dma_mem);
57-
if (mem_base)
58-
iounmap(mem_base);
61+
if (mem_base) {
62+
if (flags & DMA_MEMORY_MAP)
63+
memunmap(mem_base);
64+
else
65+
iounmap(mem_base);
66+
}
5967
return false;
6068
}
6169

6270
static void dma_release_coherent_memory(struct dma_coherent_mem *mem)
6371
{
6472
if (!mem)
6573
return;
66-
iounmap(mem->virt_base);
74+
75+
if (mem->flags & DMA_MEMORY_MAP)
76+
memunmap(mem->virt_base);
77+
else
78+
iounmap(mem->virt_base);
6779
kfree(mem->bitmap);
6880
kfree(mem);
6981
}

0 commit comments

Comments
 (0)