From c22c0dbd7d3bb7ce47779b757d567d2e7746744b Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 14 Feb 2020 16:40:17 +0900 Subject: dma-mapping: fix the prototype of dma_map_single() Make dma_map_single() return the dma address, and remove the pointless volatile. Signed-off-by: Masahiro Yamada --- arch/arm/include/asm/dma-mapping.h | 5 +++-- arch/nds32/include/asm/dma-mapping.h | 5 +++-- arch/riscv/include/asm/dma-mapping.h | 5 +++-- arch/x86/include/asm/dma-mapping.h | 5 +++-- 4 files changed, 12 insertions(+), 8 deletions(-) (limited to 'arch') diff --git a/arch/arm/include/asm/dma-mapping.h b/arch/arm/include/asm/dma-mapping.h index d20703739f..d0895a2096 100644 --- a/arch/arm/include/asm/dma-mapping.h +++ b/arch/arm/include/asm/dma-mapping.h @@ -11,6 +11,7 @@ #include #include #include +#include #include #define dma_mapping_error(x, y) 0 @@ -26,8 +27,8 @@ static inline void dma_free_coherent(void *addr) free(addr); } -static inline unsigned long dma_map_single(volatile void *vaddr, size_t len, - enum dma_data_direction dir) +static inline dma_addr_t dma_map_single(void *vaddr, size_t len, + enum dma_data_direction dir) { unsigned long addr = (unsigned long)vaddr; diff --git a/arch/nds32/include/asm/dma-mapping.h b/arch/nds32/include/asm/dma-mapping.h index c8876ceadd..9387dec347 100644 --- a/arch/nds32/include/asm/dma-mapping.h +++ b/arch/nds32/include/asm/dma-mapping.h @@ -10,6 +10,7 @@ #include #include #include +#include #include static void *dma_alloc_coherent(size_t len, unsigned long *handle) @@ -18,8 +19,8 @@ static void *dma_alloc_coherent(size_t len, unsigned long *handle) return (void *)*handle; } -static inline unsigned long dma_map_single(volatile void *vaddr, size_t len, - enum dma_data_direction dir) +static inline dma_addr_t dma_map_single(void *vaddr, size_t len, + enum dma_data_direction dir) { unsigned long addr = (unsigned long)vaddr; diff --git a/arch/riscv/include/asm/dma-mapping.h b/arch/riscv/include/asm/dma-mapping.h index 6cc3946959..eac56f8fbd 100644 --- a/arch/riscv/include/asm/dma-mapping.h +++ b/arch/riscv/include/asm/dma-mapping.h @@ -10,6 +10,7 @@ #define __ASM_RISCV_DMA_MAPPING_H #include +#include #include #include #include @@ -28,8 +29,8 @@ static inline void dma_free_coherent(void *addr) free(addr); } -static inline unsigned long dma_map_single(volatile void *vaddr, size_t len, - enum dma_data_direction dir) +static inline dma_addr_t dma_map_single(void *vaddr, size_t len, + enum dma_data_direction dir) { unsigned long addr = (unsigned long)vaddr; diff --git a/arch/x86/include/asm/dma-mapping.h b/arch/x86/include/asm/dma-mapping.h index 900b99b8a6..7e205e3313 100644 --- a/arch/x86/include/asm/dma-mapping.h +++ b/arch/x86/include/asm/dma-mapping.h @@ -11,6 +11,7 @@ #include #include #include +#include #include #define dma_mapping_error(x, y) 0 @@ -26,8 +27,8 @@ static inline void dma_free_coherent(void *addr) free(addr); } -static inline unsigned long dma_map_single(volatile void *vaddr, size_t len, - enum dma_data_direction dir) +static inline dma_addr_t dma_map_single(void *vaddr, size_t len, + enum dma_data_direction dir) { unsigned long addr = (unsigned long)vaddr; -- cgit From 950c5968672a22a65790534234d1106bd1303652 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 14 Feb 2020 16:40:18 +0900 Subject: dma-mapping: fix the prototype of dma_unmap_single() dma_unmap_single() takes the dma address, not virtual address. Signed-off-by: Masahiro Yamada --- arch/arm/include/asm/dma-mapping.h | 4 +--- arch/nds32/include/asm/dma-mapping.h | 4 +--- arch/riscv/include/asm/dma-mapping.h | 4 +--- arch/x86/include/asm/dma-mapping.h | 4 +--- 4 files changed, 4 insertions(+), 12 deletions(-) (limited to 'arch') diff --git a/arch/arm/include/asm/dma-mapping.h b/arch/arm/include/asm/dma-mapping.h index d0895a2096..efdbed7280 100644 --- a/arch/arm/include/asm/dma-mapping.h +++ b/arch/arm/include/asm/dma-mapping.h @@ -42,11 +42,9 @@ static inline dma_addr_t dma_map_single(void *vaddr, size_t len, return addr; } -static inline void dma_unmap_single(volatile void *vaddr, size_t len, +static inline void dma_unmap_single(dma_addr_t addr, size_t len, enum dma_data_direction dir) { - unsigned long addr = (unsigned long)vaddr; - len = ALIGN(len, ARCH_DMA_MINALIGN); if (dir != DMA_TO_DEVICE) diff --git a/arch/nds32/include/asm/dma-mapping.h b/arch/nds32/include/asm/dma-mapping.h index 9387dec347..784f489db5 100644 --- a/arch/nds32/include/asm/dma-mapping.h +++ b/arch/nds32/include/asm/dma-mapping.h @@ -34,11 +34,9 @@ static inline dma_addr_t dma_map_single(void *vaddr, size_t len, return addr; } -static inline void dma_unmap_single(volatile void *vaddr, size_t len, +static inline void dma_unmap_single(dma_addr_t addr, size_t len, enum dma_data_direction dir) { - unsigned long addr = (unsigned long)vaddr; - len = ALIGN(len, ARCH_DMA_MINALIGN); if (dir != DMA_TO_DEVICE) diff --git a/arch/riscv/include/asm/dma-mapping.h b/arch/riscv/include/asm/dma-mapping.h index eac56f8fbd..1ac4a4fed5 100644 --- a/arch/riscv/include/asm/dma-mapping.h +++ b/arch/riscv/include/asm/dma-mapping.h @@ -44,11 +44,9 @@ static inline dma_addr_t dma_map_single(void *vaddr, size_t len, return addr; } -static inline void dma_unmap_single(volatile void *vaddr, size_t len, +static inline void dma_unmap_single(dma_addr_t addr, size_t len, enum dma_data_direction dir) { - unsigned long addr = (unsigned long)vaddr; - len = ALIGN(len, ARCH_DMA_MINALIGN); if (dir != DMA_TO_DEVICE) diff --git a/arch/x86/include/asm/dma-mapping.h b/arch/x86/include/asm/dma-mapping.h index 7e205e3313..37704da5dd 100644 --- a/arch/x86/include/asm/dma-mapping.h +++ b/arch/x86/include/asm/dma-mapping.h @@ -42,11 +42,9 @@ static inline dma_addr_t dma_map_single(void *vaddr, size_t len, return addr; } -static inline void dma_unmap_single(volatile void *vaddr, size_t len, +static inline void dma_unmap_single(dma_addr_t addr, size_t len, enum dma_data_direction dir) { - unsigned long addr = (unsigned long)vaddr; - len = ALIGN(len, ARCH_DMA_MINALIGN); if (dir != DMA_TO_DEVICE) -- cgit From 9d86b89c590832c9bcb1c69d5ccdecdf731f97ae Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 14 Feb 2020 16:40:19 +0900 Subject: dma-mapping: move dma_map_(un)single() to The implementation of dma_map_single() and dma_unmap_single() is exactly the same for all the architectures that support them. Factor them out to , and make all drivers to include instead of . If we need to differentiate them for some architectures, we can move the generic definitions to . Add some comments to the helpers. The concept is quite similar to the DMA-API of Linux kernel. Drivers are agnostic about what is going on behind the scene. Just call dma_map_single() before the DMA, and dma_unmap_single() after it. Signed-off-by: Masahiro Yamada --- arch/arm/include/asm/dma-mapping.h | 26 -------------------------- arch/nds32/include/asm/dma-mapping.h | 24 ------------------------ arch/riscv/include/asm/dma-mapping.h | 26 -------------------------- arch/x86/include/asm/dma-mapping.h | 26 -------------------------- 4 files changed, 102 deletions(-) (limited to 'arch') diff --git a/arch/arm/include/asm/dma-mapping.h b/arch/arm/include/asm/dma-mapping.h index efdbed7280..8bb3fa2e0e 100644 --- a/arch/arm/include/asm/dma-mapping.h +++ b/arch/arm/include/asm/dma-mapping.h @@ -14,8 +14,6 @@ #include #include -#define dma_mapping_error(x, y) 0 - static inline void *dma_alloc_coherent(size_t len, unsigned long *handle) { *handle = (unsigned long)memalign(ARCH_DMA_MINALIGN, ROUND(len, ARCH_DMA_MINALIGN)); @@ -27,28 +25,4 @@ static inline void dma_free_coherent(void *addr) free(addr); } -static inline dma_addr_t dma_map_single(void *vaddr, size_t len, - enum dma_data_direction dir) -{ - unsigned long addr = (unsigned long)vaddr; - - len = ALIGN(len, ARCH_DMA_MINALIGN); - - if (dir == DMA_FROM_DEVICE) - invalidate_dcache_range(addr, addr + len); - else - flush_dcache_range(addr, addr + len); - - return addr; -} - -static inline void dma_unmap_single(dma_addr_t addr, size_t len, - enum dma_data_direction dir) -{ - len = ALIGN(len, ARCH_DMA_MINALIGN); - - if (dir != DMA_TO_DEVICE) - invalidate_dcache_range(addr, addr + len); -} - #endif /* __ASM_ARM_DMA_MAPPING_H */ diff --git a/arch/nds32/include/asm/dma-mapping.h b/arch/nds32/include/asm/dma-mapping.h index 784f489db5..f8668f1fe5 100644 --- a/arch/nds32/include/asm/dma-mapping.h +++ b/arch/nds32/include/asm/dma-mapping.h @@ -19,28 +19,4 @@ static void *dma_alloc_coherent(size_t len, unsigned long *handle) return (void *)*handle; } -static inline dma_addr_t dma_map_single(void *vaddr, size_t len, - enum dma_data_direction dir) -{ - unsigned long addr = (unsigned long)vaddr; - - len = ALIGN(len, ARCH_DMA_MINALIGN); - - if (dir == DMA_FROM_DEVICE) - invalidate_dcache_range(addr, addr + len); - else - flush_dcache_range(addr, addr + len); - - return addr; -} - -static inline void dma_unmap_single(dma_addr_t addr, size_t len, - enum dma_data_direction dir) -{ - len = ALIGN(len, ARCH_DMA_MINALIGN); - - if (dir != DMA_TO_DEVICE) - invalidate_dcache_range(addr, addr + len); -} - #endif /* __ASM_NDS_DMA_MAPPING_H */ diff --git a/arch/riscv/include/asm/dma-mapping.h b/arch/riscv/include/asm/dma-mapping.h index 1ac4a4fed5..6ecadab41c 100644 --- a/arch/riscv/include/asm/dma-mapping.h +++ b/arch/riscv/include/asm/dma-mapping.h @@ -16,8 +16,6 @@ #include #include -#define dma_mapping_error(x, y) 0 - static inline void *dma_alloc_coherent(size_t len, unsigned long *handle) { *handle = (unsigned long)memalign(ARCH_DMA_MINALIGN, len); @@ -29,28 +27,4 @@ static inline void dma_free_coherent(void *addr) free(addr); } -static inline dma_addr_t dma_map_single(void *vaddr, size_t len, - enum dma_data_direction dir) -{ - unsigned long addr = (unsigned long)vaddr; - - len = ALIGN(len, ARCH_DMA_MINALIGN); - - if (dir == DMA_FROM_DEVICE) - invalidate_dcache_range(addr, addr + len); - else - flush_dcache_range(addr, addr + len); - - return addr; -} - -static inline void dma_unmap_single(dma_addr_t addr, size_t len, - enum dma_data_direction dir) -{ - len = ALIGN(len, ARCH_DMA_MINALIGN); - - if (dir != DMA_TO_DEVICE) - invalidate_dcache_range(addr, addr + len); -} - #endif /* __ASM_RISCV_DMA_MAPPING_H */ diff --git a/arch/x86/include/asm/dma-mapping.h b/arch/x86/include/asm/dma-mapping.h index 37704da5dd..8be1003e6b 100644 --- a/arch/x86/include/asm/dma-mapping.h +++ b/arch/x86/include/asm/dma-mapping.h @@ -14,8 +14,6 @@ #include #include -#define dma_mapping_error(x, y) 0 - static inline void *dma_alloc_coherent(size_t len, unsigned long *handle) { *handle = (unsigned long)memalign(ARCH_DMA_MINALIGN, len); @@ -27,28 +25,4 @@ static inline void dma_free_coherent(void *addr) free(addr); } -static inline dma_addr_t dma_map_single(void *vaddr, size_t len, - enum dma_data_direction dir) -{ - unsigned long addr = (unsigned long)vaddr; - - len = ALIGN(len, ARCH_DMA_MINALIGN); - - if (dir == DMA_FROM_DEVICE) - invalidate_dcache_range(addr, addr + len); - else - flush_dcache_range(addr, addr + len); - - return addr; -} - -static inline void dma_unmap_single(dma_addr_t addr, size_t len, - enum dma_data_direction dir) -{ - len = ALIGN(len, ARCH_DMA_MINALIGN); - - if (dir != DMA_TO_DEVICE) - invalidate_dcache_range(addr, addr + len); -} - #endif /* __ASM_X86_DMA_MAPPING_H */ -- cgit From 057516308a0a1892a54f16bce0577c9dcccc4857 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 20 Feb 2020 14:15:37 +0900 Subject: dma-mapping: add for all architectures To avoid "asm/dma-mapping.h: No such file or directory" error, we need something. Signed-off-by: Masahiro Yamada --- arch/arc/include/asm/dma-mapping.h | 1 + arch/m68k/include/asm/dma-mapping.h | 1 + arch/microblaze/include/asm/dma-mapping.h | 1 + arch/mips/include/asm/dma-mapping.h | 1 + arch/powerpc/include/asm/dma-mapping.h | 1 + arch/sandbox/include/asm/dma-mapping.h | 1 + arch/sh/include/asm/dma-mapping.h | 1 + arch/xtensa/include/asm/dma-mapping.h | 1 + 8 files changed, 8 insertions(+) create mode 100644 arch/arc/include/asm/dma-mapping.h create mode 100644 arch/m68k/include/asm/dma-mapping.h create mode 100644 arch/microblaze/include/asm/dma-mapping.h create mode 100644 arch/mips/include/asm/dma-mapping.h create mode 100644 arch/powerpc/include/asm/dma-mapping.h create mode 100644 arch/sandbox/include/asm/dma-mapping.h create mode 100644 arch/sh/include/asm/dma-mapping.h create mode 100644 arch/xtensa/include/asm/dma-mapping.h (limited to 'arch') diff --git a/arch/arc/include/asm/dma-mapping.h b/arch/arc/include/asm/dma-mapping.h new file mode 100644 index 0000000000..853b0877b3 --- /dev/null +++ b/arch/arc/include/asm/dma-mapping.h @@ -0,0 +1 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ diff --git a/arch/m68k/include/asm/dma-mapping.h b/arch/m68k/include/asm/dma-mapping.h new file mode 100644 index 0000000000..853b0877b3 --- /dev/null +++ b/arch/m68k/include/asm/dma-mapping.h @@ -0,0 +1 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ diff --git a/arch/microblaze/include/asm/dma-mapping.h b/arch/microblaze/include/asm/dma-mapping.h new file mode 100644 index 0000000000..853b0877b3 --- /dev/null +++ b/arch/microblaze/include/asm/dma-mapping.h @@ -0,0 +1 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ diff --git a/arch/mips/include/asm/dma-mapping.h b/arch/mips/include/asm/dma-mapping.h new file mode 100644 index 0000000000..853b0877b3 --- /dev/null +++ b/arch/mips/include/asm/dma-mapping.h @@ -0,0 +1 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ diff --git a/arch/powerpc/include/asm/dma-mapping.h b/arch/powerpc/include/asm/dma-mapping.h new file mode 100644 index 0000000000..853b0877b3 --- /dev/null +++ b/arch/powerpc/include/asm/dma-mapping.h @@ -0,0 +1 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ diff --git a/arch/sandbox/include/asm/dma-mapping.h b/arch/sandbox/include/asm/dma-mapping.h new file mode 100644 index 0000000000..853b0877b3 --- /dev/null +++ b/arch/sandbox/include/asm/dma-mapping.h @@ -0,0 +1 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ diff --git a/arch/sh/include/asm/dma-mapping.h b/arch/sh/include/asm/dma-mapping.h new file mode 100644 index 0000000000..853b0877b3 --- /dev/null +++ b/arch/sh/include/asm/dma-mapping.h @@ -0,0 +1 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ diff --git a/arch/xtensa/include/asm/dma-mapping.h b/arch/xtensa/include/asm/dma-mapping.h new file mode 100644 index 0000000000..853b0877b3 --- /dev/null +++ b/arch/xtensa/include/asm/dma-mapping.h @@ -0,0 +1 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ -- cgit