dma-mapping: move the remap helpers to a separate file
Subsystems (4)
PATCH 1/1 dma-mapping: move the remap helpers to a separate file
The dma remap code only really makes sense for not cache coherent architectures, and currently is only used by arm, arm64 and xtensa. Split it out into a separate file with a separate Kconfig symbol.
[Laura: you wrote this code back then, do you have a sensible
copyright statement to add, given that the mapping.c statement obviously does not match your code that was written much later]
--- arch/arm/Kconfig | 1 + arch/arm64/Kconfig | 1 + arch/xtensa/Kconfig | 1 + kernel/dma/Kconfig | 4 +++ kernel/dma/Makefile | 2 +- kernel/dma/mapping.c | 84 ------------------------------------------- kernel/dma/remap.c | 85 ++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 93 insertions(+), 85 deletions(-) create mode 100644 kernel/dma/remap.c
arch/arm/Kconfig +1 -0
@@ -30,6 +30,7 @@ config ARM select CPU_PM if (SUSPEND || CPU_IDLE) select DCACHE_WORD_ACCESS if HAVE_EFFICIENT_UNALIGNED_ACCESS select DMA_DIRECT_OPS if !MMU + select DMA_REMAP if MMU select EDAC_SUPPORT select EDAC_ATOMIC_SCRUB select GENERIC_ALLOCATOR
arch/arm64/Kconfig +1 -0
@@ -77,6 +77,7 @@ config ARM64 select CPU_PM if (SUSPEND || CPU_IDLE) select DCACHE_WORD_ACCESS select DMA_DIRECT_OPS + select DMA_REMAP select EDAC_SUPPORT select FRAME_POINTER select GENERIC_ALLOCATOR
arch/xtensa/Kconfig +1 -0
@@ -10,6 +10,7 @@ config XTENSA select CLONE_BACKWARDS select COMMON_CLK select DMA_DIRECT_OPS + select DMA_REMAP if MMU select GENERIC_ATOMIC64 select GENERIC_CLOCKEVENTS select GENERIC_IRQ_SHOW
kernel/dma/Kconfig +4 -0
@@ -51,3 +51,7 @@ config SWIOTLB bool select DMA_DIRECT_OPS select NEED_DMA_MAP_STATE + +config DMA_REMAP + depends on MMU + bool
kernel/dma/Makefile +1 -1
@@ -7,4 +7,4 @@ obj-$(CONFIG_DMA_DIRECT_OPS) += direct.o obj-$(CONFIG_DMA_VIRT_OPS) += virt.o obj-$(CONFIG_DMA_API_DEBUG) += debug.o obj-$(CONFIG_SWIOTLB) += swiotlb.o - +obj-$(CONFIG_DMA_REMAP) += remap.o
kernel/dma/mapping.c +0 -84
87 lines not on this page · raw message
kernel/dma/remap.c new file +85 -0
85 lines not on this page · raw message
Signature · 1 line
2.19.1
Quoted 8 lines · Christoph Hellwig
The dma remap code only really makes sense for not cache coherent architectures, and currently is only used by arm, arm64 and xtensa. Split it out into a separate file with a separate
Kconfigsymbol.[Laura: you wrote this code back then, do you have a sensible
copyright statement to add, given that themapping.cstatement obviously does not match your code that was written much later]
Hmmmmm, that was written and committed via my codeaurora.org e-mail address. Probably best to use "Copyright (c) 2014, The Linux Foundation" since that was the standard. If you want,
Thanks,
Laura
Quoted 254 lines
Signed-off-by Christoph Hellwig <[email protected]>--- arch/arm/Kconfig | 1 + arch/arm64/Kconfig | 1 + arch/xtensa/Kconfig | 1 + kernel/dma/Kconfig | 4 +++ kernel/dma/Makefile | 2 +- kernel/dma/mapping.c | 84 ------------------------------------------- kernel/dma/remap.c | 85 ++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 93 insertions(+), 85 deletions(-)create mode 100644
kernel/dma/remap.carch/arm/Kconfig +1
-0@@ -30,6 +30,7 @@ config ARM select CPU_PM if (SUSPEND || CPU_IDLE) select DCACHE_WORD_ACCESS if HAVE_EFFICIENT_UNALIGNED_ACCESS select DMA_DIRECT_OPS if !MMU + select DMA_REMAP if MMU select EDAC_SUPPORT select EDAC_ATOMIC_SCRUB select GENERIC_ALLOCATORarch/arm64/Kconfig +1
-0@@ -77,6 +77,7 @@ config ARM64 select CPU_PM if (SUSPEND || CPU_IDLE) select DCACHE_WORD_ACCESS select DMA_DIRECT_OPS + select DMA_REMAP select EDAC_SUPPORT select FRAME_POINTER select GENERIC_ALLOCATORarch/xtensa/Kconfig +1
-0@@ -10,6 +10,7 @@ config XTENSA select CLONE_BACKWARDS select COMMON_CLK select DMA_DIRECT_OPS + select DMA_REMAP if MMU select GENERIC_ATOMIC64 select GENERIC_CLOCKEVENTS select GENERIC_IRQ_SHOWkernel/dma/Kconfig +4
-0@@ -51,3 +51,7 @@ config SWIOTLB bool select DMA_DIRECT_OPS select NEED_DMA_MAP_STATE + +config DMA_REMAP + depends on MMU + boolkernel/dma/Makefile +1
-1@@ -7,4 +7,4 @@ obj-$(CONFIG_DMA_DIRECT_OPS) += direct.o obj-$(CONFIG_DMA_VIRT_OPS) += virt.o obj-$(CONFIG_DMA_API_DEBUG) += debug.o obj-$(CONFIG_SWIOTLB) += swiotlb.o - +obj-$(CONFIG_DMA_REMAP) += remap.okernel/dma/mapping.c +0
-84@@ -262,87 +262,3 @@ int dma_common_mmap(struct device *dev, struct vm_area_struct *vma,#endif /* !CONFIG_ARCH_NO_COHERENT_DMA_MMAP */ }EXPORT_SYMBOL (dma_common_mmap); - -#ifdef CONFIG_MMU -static struct vm_struct *__dma_common_pages_remap (struct page **pages, -size_t size,unsigned long vm_flags,pgprot_t prot, -const void *caller) -{ -struct vm_struct *area; - - area =get_vm_area_caller (size, vm_flags, caller); -if (!area) -return NULL ; - -if (map_vm_area (area, prot, pages)) { -vunmap (area->addr); -return NULL ; - } - -return area; -} - -/* -* remaps an array of PAGE_SIZE pages into another vm_area -* Cannot be used in non-sleeping contexts -*/ -void *dma_common_pages_remap (struct page **pages,size_t size, -unsigned long vm_flags,pgprot_t prot, -const void *caller) -{ -struct vm_struct *area; - - area =__dma_common_pages_remap (pages, size, vm_flags, prot, caller); -if (!area) -return NULL ; - - area->pages = pages; - -return area->addr; -} - -/* -* remaps an allocated contiguous region into another vm_area. -* Cannot be used in non-sleeping contexts -*/ - -void *dma_common_contiguous_remap (struct page *page,size_t size, -unsigned long vm_flags, -pgprot_t prot,const void *caller) -{ -int i; -struct page **pages; -struct vm_struct *area; - - pages =kmalloc (sizeof (struct page *) <<get_order (size),GFP_KERNEL ); -if (!pages) -return NULL ; - -for (i =0 ; i < (size >>PAGE_SHIFT ); i++) - pages[i] =nth_page (page, i); - - area =__dma_common_pages_remap (pages, size, vm_flags, prot, caller); - -kfree (pages); - -if (!area) -return NULL ; -return area->addr; -} - -/* -* unmaps a range previously mapped by dma_common_*_remap -*/ -void dma_common_free_remap (void *cpu_addr,size_t size,unsigned long vm_flags) -{ -struct vm_struct *area =find_vm_area (cpu_addr); - -if (!area || (area->flags & vm_flags) != vm_flags) { -WARN (1 ,"trying to free invalid coherent area: %p\n" , cpu_addr); -return ; - } - -unmap_kernel_range ((unsigned long )cpu_addr,PAGE_ALIGN (size)); -vunmap (cpu_addr); -} -#endif kernel/dma/remap.c new file +85
-0@@ -0,0 +1,85 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <linux/dma-mapping.h> +#include <linux/slab.h> +#include <linux/vmalloc.h> + +static struct vm_struct *__dma_common_pages_remap (struct page **pages, +size_t size,unsigned long vm_flags,pgprot_t prot, +const void *caller) +{ +struct vm_struct *area; + + area =get_vm_area_caller (size, vm_flags, caller); +if (!area) +return NULL ; + +if (map_vm_area (area, prot, pages)) { +vunmap (area->addr); +return NULL ; + } + +return area; +} + +/* +* remaps an array of PAGE_SIZE pages into another vm_area +* Cannot be used in non-sleeping contexts +*/ +void *dma_common_pages_remap (struct page **pages,size_t size, +unsigned long vm_flags,pgprot_t prot, +const void *caller) +{ +struct vm_struct *area; + + area =__dma_common_pages_remap (pages, size, vm_flags, prot, caller); +if (!area) +return NULL ; + + area->pages = pages; + +return area->addr; +} + +/* +* Remaps an allocated contiguous region into another vm_area. +* Cannot be used in non-sleeping contexts +*/ +void *dma_common_contiguous_remap (struct page *page,size_t size, +unsigned long vm_flags, +pgprot_t prot,const void *caller) +{ +int i; +struct page **pages; +struct vm_struct *area; + + pages =kmalloc (sizeof (struct page *) <<get_order (size),GFP_KERNEL ); +if (!pages) +return NULL ; + +for (i =0 ; i < (size >>PAGE_SHIFT ); i++) + pages[i] =nth_page (page, i); + + area =__dma_common_pages_remap (pages, size, vm_flags, prot, caller); + +kfree (pages); + +if (!area) +return NULL ; +return area->addr; +} + +/* +* Unmaps a range previously mapped by dma_common_*_remap +*/ +void dma_common_free_remap (void *cpu_addr,size_t size,unsigned long vm_flags) +{ +struct vm_struct *area =find_vm_area (cpu_addr); + +if (!area || (area->flags & vm_flags) != vm_flags) { +WARN (1 ,"trying to free invalid coherent area: %p\n" , cpu_addr); +return ; + } + +unmap_kernel_range ((unsigned long )cpu_addr,PAGE_ALIGN (size)); +vunmap (cpu_addr); +}
Quoted 9 lines · Laura Abbott
Quoted 8 lines
The dma remap code only really makes sense for not cache coherent architectures, and currently is only used by arm, arm64 and xtensa. Split it out into a separate file with a separate
Kconfigsymbol.[Laura: you wrote this code back then, do you have a sensible
copyright statement to add, given that themapping.cstatement obviously does not match your code that was written much later]
Quoted 5 lines
Hmmmmm, that was written and committed via my codeaurora.org e-mail address. Probably best to use "Copyright (c) 2014, The Linux Foundation" since that was the standard. If you want,
Acked-by Laura Abbott <[email protected]>
Thanks!