From 0b06cd5ca5801698b7fd9fa94d2b419d02dd126e Mon Sep 17 00:00:00 2001 From: Patrick Daly Date: Wed, 17 Feb 2016 15:58:22 -0800 Subject: [PATCH] arm: dma: Allow CMA pages to not have a kernel mapping Currently, there are use cases where not having any kernel mapping is required; if the CMA memory needs to be used as a pool which can have both cached and uncached mappings we need to remove the mapping to avoid the multiple mapping problem. Extend the dma APIs to use the DMA_ATTR_NO_KERNEL_MAPPING with CMA. This doesn't end up saving any virtual address space but the mapping will still not be present. Change-Id: I64d21250abbe615c43e2b5b1272ee2b6d106705a Signed-off-by: Laura Abbott Signed-off-by: Patrick Daly Signed-off-by: Vijayanand Jitta Signed-off-by: Charan Teja Reddy Signed-off-by: Qingqing Zhou --- arch/arm/mm/dma-mapping.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index 5443a6c72a63..66a46e9d0126 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -484,12 +484,26 @@ static int __dma_update_pte(pte_t *pte, unsigned long addr, void *data) return 0; } -static void __dma_remap(struct page *page, size_t size, pgprot_t prot) +static int __dma_clear_pte(pte_t *pte, unsigned long addr, void *data) +{ + pte_clear(&init_mm, addr, pte); + return 0; +} + +static void __dma_remap(struct page *page, size_t size, pgprot_t prot, + bool want_vaddr) { unsigned long start = (unsigned long) page_address(page); unsigned end = start + size; + int (*func)(pte_t *pte, unsigned long addr, void *data); - apply_to_page_range(&init_mm, start, size, __dma_update_pte, &prot); + if (!want_vaddr) + func = __dma_clear_pte; + else + func = __dma_update_pte; + + apply_to_page_range(&init_mm, start, size, func, &prot); + mb(); /*Ensure pte's are updated */ flush_tlb_kernel_range(start, end); } @@ -572,9 +586,6 @@ static void *__alloc_from_contiguous(struct device *dev, size_t size, __dma_clear_buffer(page, size, coherent_flag); - if (!want_vaddr) - goto out; - if (PageHighMem(page)) { ptr = dma_common_contiguous_remap(page, size, prot, caller); if (!ptr) { @@ -582,11 +593,10 @@ static void *__alloc_from_contiguous(struct device *dev, size_t size, return NULL; } } else { - __dma_remap(page, size, prot); + __dma_remap(page, size, prot, want_vaddr); ptr = page_address(page); } - out: *ret_page = page; return ptr; } @@ -594,12 +604,10 @@ static void *__alloc_from_contiguous(struct device *dev, size_t size, static void __free_from_contiguous(struct device *dev, struct page *page, void *cpu_addr, size_t size, bool want_vaddr) { - if (want_vaddr) { - if (PageHighMem(page)) - dma_common_free_remap(cpu_addr, size); - else - __dma_remap(page, size, PAGE_KERNEL); - } + if (PageHighMem(page)) + dma_common_free_remap(cpu_addr, size); + else + __dma_remap(page, size, PAGE_KERNEL, true); dma_release_from_contiguous(dev, page, size >> PAGE_SHIFT); }