common non-cache coherent direct dma mapping ops v2
Subsystems (12)
Hi all,
this series continues consolidating the dma-mapping code, with a focus on architectures that do not (always) provide cache coherence for DMA. Three architectures (arm, mips and powerpc) are still left to be converted later due to complexity of their dma ops selection.
The dma-noncoherent ops calls the dma-direct ops for the actual translation of streaming mappins and allow the architecture to provide any cache flushing required for cpu to device and/or device to cpu ownership transfers. The dma coherent allocator is for now still left entirely to architecture supplied implementations due the amount of variations. Hopefully we can do some consolidation for them later on as well.
A lot of architectures are currently doing very questionable things in their dma mapping routines, which are documented in the changelogs for each patch. Please review them very careful and correct me on incorrect assumptions.
Because this series sits on top of three previously submitted series a git tree might be useful to actually test it. It is provided here:
git://git.infradead.org/users/hch/misc.git generic-dma-noncoherent.2
Gitweb:
http://git.infradead.org/users/hch/misc.git/shortlog/refs/heads/generic-dma-noncoherent.2
Changes since v1:
- dropped the already merged generic, arc and c6x patches (with the map_single offset fix from Alexey Brodkin)
- split various changes into smaller patches
- dropped the arm-nommu changes for now
- fixed a typo
Changes since RFC:
- fix a typo accidentally disabling the device to cpu transfer sync
- fixed a few compile failures
PATCH 1/25 hexagon: remove the sync_single_for_cpu DMA operation
hexagon does all the required cache maintainance at dma map time, and none at unmap time. It thus has to implement sync_single_for_device to match the map cace for buffer reuse, but there is no point in doing another invalidation in the sync_single_cpu_case, which in terms of cache maintainance is equivalent to the unmap case.
--- arch/hexagon/kernel/dma.c | 8 -------- 1 file changed, 8 deletions(-)
arch/hexagon/kernel/dma.c +0 -8
@@ -181,13 +181,6 @@ static dma_addr_t hexagon_map_page(struct device *dev, struct page *page,return bus; } -static void hexagon_sync_single_for_cpu (struct device *dev, -dma_addr_t dma_handle,size_t size, -enum dma_data_direction dir) -{ -dma_sync (dma_addr_to_virt (dma_handle), size, dir); -} -static void hexagon_sync_single_for_device (struct device *dev,dma_addr_t dma_handle,size_t size,enum dma_data_direction dir)
@@ -205,7 +198,6 @@ const struct dma_map_ops hexagon_dma_ops = { .free = hexagon_free_coherent, .map_sg = hexagon_map_sg, .map_page = hexagon_map_page, - .sync_single_for_cpu = hexagon_sync_single_for_cpu, .sync_single_for_device = hexagon_sync_single_for_device, .mapping_error = hexagon_mapping_error, };
Signature · 1 line
2.17.0
PATCH 2/25 hexagon: implement the sync_sg_for_device DMA operation
In reply to Christoph HellwigThis methods needs to provide the equivalent of sync_single_for_device for each S/G list element, but was missing.
--- arch/hexagon/kernel/dma.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
arch/hexagon/kernel/dma.c +13 -0
@@ -188,6 +188,18 @@ static void hexagon_sync_single_for_device(struct device *dev,dma_sync (dma_addr_to_virt (dma_handle), size, dir); } +static void hexagon_sync_sg_for_device (struct device *dev, +struct scatterlist *sgl,int nents,enum dma_data_direction dir) +{ +struct scatterlist *sg; +int i; + +for_each_sg (sgl, sg, nents, i) +hexagon_sync_single_for_device (dev,sg_dma_address (sg), + sg->length, dir); +} + +static int hexagon_mapping_error (struct device *dev,dma_addr_t dma_addr) {return dma_addr ==HEXAGON_MAPPING_ERROR ;
@@ -199,6 +211,7 @@ const struct dma_map_ops hexagon_dma_ops = { .map_sg = hexagon_map_sg, .map_page = hexagon_map_page, .sync_single_for_device = hexagon_sync_single_for_device, + .sync_sg_for_device = hexagon_sync_sg_for_device, .mapping_error = hexagon_mapping_error, };
Signature · 1 line
2.17.0
PATCH 3/25 hexagon: use generic dma_noncoherent_ops
In reply to Christoph HellwigSwitch to the generic noncoherent direct mapping implementation.
--- arch/hexagon/Kconfig | 2 + arch/hexagon/include/asm/Kbuild | 1 + arch/hexagon/include/asm/dma-mapping.h | 40 ------- arch/hexagon/kernel/dma.c | 148 ++----------------------- 4 files changed, 11 insertions(+), 180 deletions(-) delete mode 100644 arch/hexagon/include/asm/dma-mapping.h
arch/hexagon/Kconfig +2 -0
@@ -4,6 +4,7 @@ comment "Linux Kernel Configuration for Hexagon" config HEXAGON def_bool y + select ARCH_HAS_SYNC_DMA_FOR_DEVICE select HAVE_OPROFILE # Other pending projects/to-do items. # select HAVE_REGS_AND_STACK_ACCESS_API
@@ -28,6 +29,7 @@ config HEXAGON select GENERIC_CLOCKEVENTS_BROADCAST select MODULES_USE_ELF_RELA select GENERIC_CPU_DEVICES + select DMA_NONCOHERENT_OPS ---help--- Qualcomm Hexagon is a processor architecture designed for high performance and low power across a wide variety of applications.
arch/hexagon/include/asm/Kbuild +1 -0
@@ -5,6 +5,7 @@ generic-y += bugs.h generic-y += current.h generic-y += device.h generic-y += div64.h +generic-y += dma-mapping.h generic-y += emergency-restart.h generic-y += extable.h generic-y += fb.h
arch/hexagon/include/asm/dma-mapping.h deleted +0 -40
@@ -1,40 +0,0 @@ -/* -* DMA operations for the Hexagon architecture -* -* Copyright (c) 2010-2011, The Linux Foundation. All rights reserved. -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License version 2 and -* only version 2 as published by the Free Software Foundation. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -* 02110-1301, USA. -*/ - -#ifndef _ASM_DMA_MAPPING_H -#define _ASM_DMA_MAPPING_H - -#include <linux/types.h> -#include <linux/cache.h> -#include <linux/mm.h> -#include <linux/scatterlist.h> -#include <linux/dma-debug.h> -#include <asm/io.h> - -struct device ; - -extern const struct dma_map_ops *dma_ops; - -static inline const struct dma_map_ops *get_arch_dma_ops (struct bus_type *bus) -{ -return dma_ops; -} - -#endif
arch/hexagon/kernel/dma.c +8 -140
179 lines not on this page · raw message
Signature · 1 line
2.17.0
PATCH 4/25 m68k: use generic dma_noncoherent_ops
In reply to Christoph HellwigSwitch to the generic noncoherent direct mapping implementation.
--- arch/m68k/Kconfig | 2 + arch/m68k/include/asm/Kbuild | 1 + arch/m68k/include/asm/dma-mapping.h | 12 ----- arch/m68k/kernel/dma.c | 68 ++++------------------------- 4 files changed, 11 insertions(+), 72 deletions(-) delete mode 100644 arch/m68k/include/asm/dma-mapping.h
arch/m68k/Kconfig +2 -0
@@ -2,6 +2,7 @@ config M68K bool default y + select ARCH_HAS_SYNC_DMA_FOR_DEVICE if HAS_DMA select ARCH_MIGHT_HAVE_PC_PARPORT if ISA select ARCH_NO_COHERENT_DMA_MMAP if !MMU select HAVE_IDE
@@ -24,6 +25,7 @@ config M68K select MODULES_USE_ELF_RELA select OLD_SIGSUSPEND3 select OLD_SIGACTION + select DMA_NONCOHERENT_OPS if HAS_DMA config CPU_BIG_ENDIAN def_bool y
arch/m68k/include/asm/Kbuild +1 -0
@@ -1,5 +1,6 @@ generic-y += barrier.h generic-y += device.h +generic-y += dma-mapping.h generic-y += emergency-restart.h generic-y += exec.h generic-y += extable.h
arch/m68k/include/asm/dma-mapping.h deleted +0 -12
@@ -1,12 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef _M68K_DMA_MAPPING_H -#define _M68K_DMA_MAPPING_H - -extern const struct dma_map_ops m68k_dma_ops; - -static inline const struct dma_map_ops *get_arch_dma_ops (struct bus_type *bus) -{ -return &m68k_dma_ops; -} - -#endif /* _M68K_DMA_MAPPING_H */
arch/m68k/kernel/dma.c +8 -60
107 lines not on this page · raw message
Signature · 1 line
2.17.0
PATCH 5/25 microblaze: use generic dma_noncoherent_ops
In reply to Christoph HellwigSwitch to the generic noncoherent direct mapping implementation.
This removes the direction-based optimizations in sync_{single,sg}_for_{cpu,device} which were marked untestested and do not match the usually very well tested {un,}map_{single,sg} implementations.
--- arch/microblaze/Kconfig | 4 + arch/microblaze/include/asm/Kbuild | 1 + arch/microblaze/include/asm/dma-mapping.h | 28 ----- arch/microblaze/include/asm/pgtable.h | 2 - arch/microblaze/kernel/dma.c | 144 ++-------------------- arch/microblaze/mm/consistent.c | 9 +- 6 files changed, 22 insertions(+), 166 deletions(-) delete mode 100644 arch/microblaze/include/asm/dma-mapping.h
arch/microblaze/Kconfig +4 -0
@@ -1,6 +1,8 @@ config MICROBLAZE def_bool y select ARCH_HAS_GCOV_PROFILE_ALL + select ARCH_HAS_SYNC_DMA_FOR_CPU + select ARCH_HAS_SYNC_DMA_FOR_DEVICE select ARCH_MIGHT_HAVE_PC_PARPORT select ARCH_NO_COHERENT_DMA_MMAP if !MMU select ARCH_WANT_IPC_PARSE_VERSION
@@ -8,6 +10,8 @@ config MICROBLAZE select TIMER_OF select CLONE_BACKWARDS3 select COMMON_CLK + select DMA_NONCOHERENT_OPS + select DMA_NONCOHERENT_MMAP select GENERIC_ATOMIC64 select GENERIC_CLOCKEVENTS select GENERIC_CPU_DEVICES
arch/microblaze/include/asm/Kbuild +1 -0
@@ -4,6 +4,7 @@ generic-y += bug.h generic-y += bugs.h generic-y += device.h generic-y += div64.h +generic-y += dma-mapping.h generic-y += emergency-restart.h generic-y += exec.h generic-y += extable.h
arch/microblaze/include/asm/dma-mapping.h deleted +0 -28
@@ -1,28 +0,0 @@ -/* -* Implements the generic device dma API for microblaze and the pci -* -* Copyright (C) 2009-2010 Michal Simek <[email protected]> -* Copyright (C) 2009-2010 PetaLogix -* -* This file is subject to the terms and conditions of the GNU General -* Public License. See the file COPYING in the main directory of this -* archive for more details. -* -* This file is base on powerpc and x86 dma-mapping.h versions -* Copyright (C) 2004 IBM -*/ - -#ifndef _ASM_MICROBLAZE_DMA_MAPPING_H -#define _ASM_MICROBLAZE_DMA_MAPPING_H - -/* -* Available generic sets of operations -*/ -extern const struct dma_map_ops dma_nommu_ops; - -static inline const struct dma_map_ops *get_arch_dma_ops (struct bus_type *bus) -{ -return &dma_nommu_ops; -} - -#endif /* _ASM_MICROBLAZE_DMA_MAPPING_H */
arch/microblaze/include/asm/pgtable.h +0 -2
@@ -553,8 +553,6 @@ void __init *early_get_page(void);extern unsigned long ioremap_bot, ioremap_base; -void *consistent_alloc (gfp_t gfp,size_t size,dma_addr_t *dma_handle); -void consistent_free (size_t size,void *vaddr);void consistent_sync (void *vaddr,size_t size,int direction);void consistent_sync_page (struct page *page,unsigned long offset,size_t size,int direction);
arch/microblaze/kernel/dma.c +12 -132
171 lines not on this page · raw message
arch/microblaze/mm/consistent.c +5 -4
@@ -33,6 +33,7 @@#include <linux/pci.h> #include <linux/interrupt.h> #include <linux/gfp.h> +#include <linux/dma-noncoherent.h> #include <asm/pgalloc.h> #include <linux/io.h>
@@ -59,7 +60,8 @@* uncached region. This will no doubt cause big problems if memory allocated * here is not also freed properly. -- JW */ -void *consistent_alloc (gfp_t gfp,size_t size,dma_addr_t *dma_handle) +void *arch_dma_alloc (struct device *dev,size_t size,dma_addr_t *dma_handle, +gfp_t gfp,unsigned long attrs) {unsigned long order, vaddr;void *ret;
@@ -154,7 +156,6 @@ void *consistent_alloc(gfp_t gfp, size_t size, dma_addr_t *dma_handle)return ret; } -EXPORT_SYMBOL (consistent_alloc);#ifdef CONFIG_MMU static pte_t *consistent_virt_to_pte (void *vaddr)
@@ -178,7 +179,8 @@ unsigned long consistent_virt_to_pfn(void *vaddr)/* * free page(s) as defined by the above mapping. */ -void consistent_free (size_t size,void *vaddr) +void arch_dma_free (struct device *dev,size_t size,void *vaddr, +dma_addr_t dma_addr,unsigned long attrs) {struct page *page;
@@ -218,7 +220,6 @@ void consistent_free(size_t size, void *vaddr)flush_tlb_all ();#endif } -EXPORT_SYMBOL (consistent_free);/* * make an area consistent.
Signature · 1 line
2.17.0
PATCH 6/25 microblaze: remove the consistent_sync and consistent_sync_page
In reply to Christoph HellwigBoth unused.
--- arch/microblaze/include/asm/pgtable.h | 3 -- arch/microblaze/mm/consistent.c | 45 --------------------------- 2 files changed, 48 deletions(-)
arch/microblaze/include/asm/pgtable.h +0 -3
@@ -553,9 +553,6 @@ void __init *early_get_page(void);extern unsigned long ioremap_bot, ioremap_base; -void consistent_sync (void *vaddr,size_t size,int direction); -void consistent_sync_page (struct page *page,unsigned long offset, -size_t size,int direction);unsigned long consistent_virt_to_pfn (void *vaddr);void setup_memory (void );
arch/microblaze/mm/consistent.c +0 -45
48 lines not on this page · raw message
Signature · 1 line
2.17.0
PATCH 7/25 nds32: remove the broken kmap code in nds32_dma_map_sg
In reply to Christoph Hellwignds32_dma_map_sg is the only of the various DMA operations that tries to deal with highmem (the single page variants and SG sync routines are missing, SG unmap is entirely unimplemented), and it does so without taking into account S/G list items that are bigger than a page, which are legal and can happen frequently.
Remove this code for now - if highmem support on nds32 becomes a real thing it needs to be added back as a loop over pages in the newly consolidated code that deals with all operations.
--- arch/nds32/kernel/dma.c | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-)
arch/nds32/kernel/dma.c +3 -18
@@ -393,24 +393,9 @@ static int nds32_dma_map_sg(struct device *dev, struct scatterlist *sg,int i;for (i =0 ; i < nents; i++, sg++) { -void *virt; -unsigned long pfn; -struct page *page =sg_page (sg); - - sg->dma_address =sg_phys (sg); - pfn =page_to_pfn (page) + sg->offset /PAGE_SIZE ; - page =pfn_to_page (pfn); -if (PageHighMem (page)) { - virt =kmap_atomic (page); -consistent_sync (virt, sg->length, dir,FOR_CPU ); -kunmap_atomic (virt); - }else { -if (sg->offset >PAGE_SIZE ) -panic ("sg->offset:%08x > PAGE_SIZE\n" , - sg->offset); - virt =page_address (page) + sg->offset; -consistent_sync (virt, sg->length, dir,FOR_CPU ); - } +char *virt = +page_address ((struct page *)sg->page_link) + sg->offset; +consistent_sync (virt, sg->length, dir,FOR_CPU ); }return nents; }
Signature · 1 line
2.17.0
PATCH 8/25 nds32: consolidate DMA cache maintainance routines
In reply to Christoph HellwigMake sure all other DMA methods call nds32_dma_sync_single_for_{device,cpu} to perform cache maintaince, and remove the consisteny_sync helper that implemented both with entirely separate code based off an argument.
--- arch/nds32/kernel/dma.c | 140 +++++++++++++++++----------------------- 1 file changed, 61 insertions(+), 79 deletions(-)
arch/nds32/kernel/dma.c +61 -79
@@ -22,11 +22,6 @@static pte_t *consistent_pte;static DEFINE_RAW_SPINLOCK (consistent_lock); -enum master_type { -FOR_CPU =0 , -FOR_DEVICE =1 , -}; -/* * VM region handling support. *
@@ -333,15 +328,53 @@ static int __init consistent_init(void) }core_initcall (consistent_init); -static void consistent_sync (void *vaddr,size_t size,int direction,int master_type); + +static void +nds32_dma_sync_single_for_device (struct device *dev,dma_addr_t handle, +size_t size,enum dma_data_direction dir) +{ +unsigned long start = (unsigned long )phys_to_virt (handle); + +switch (dir) { +case DMA_FROM_DEVICE : +break ; +case DMA_TO_DEVICE : +case DMA_BIDIRECTIONAL : +cpu_dma_wb_range (start, start + size); +break ; +default : +BUG (); + } +} + +static void +nds32_dma_sync_single_for_cpu (struct device *dev,dma_addr_t handle, +size_t size,enum dma_data_direction dir) +{ +unsigned long start = (unsigned long )phys_to_virt (handle); + +switch (dir) { +case DMA_TO_DEVICE : +break ; +case DMA_FROM_DEVICE : +case DMA_BIDIRECTIONAL : +cpu_dma_inval_range (start, start + size); +break ; +default : +BUG (); + } +} +static dma_addr_t nds32_dma_map_page (struct device *dev,struct page *page,unsigned long offset,size_t size,enum dma_data_direction dir,unsigned long attrs) { +dma_addr_t dma_addr =page_to_phys (page) + offset; +if (!(attrs &DMA_ATTR_SKIP_CPU_SYNC )) -consistent_sync ((void *)(page_address (page) + offset), size, dir,FOR_DEVICE ); -return page_to_phys (page) + offset; +nds32_dma_sync_single_for_device (dev, handle, size, dir); +return dma_addr; } static void nds32_dma_unmap_page(struct device *dev, dma_addr_t handle,
@@ -349,75 +382,19 @@ static void nds32_dma_unmap_page(struct device *dev, dma_addr_t handle, unsigned long attrs) {if (!(attrs &DMA_ATTR_SKIP_CPU_SYNC )) -consistent_sync (phys_to_virt (handle), size, dir,FOR_CPU ); +nds32_dma_sync_single_for_cpu (dev, handle, size, dir); } -/* -* Make an area consistent for devices. -*/ -static void consistent_sync (void *vaddr,size_t size,int direction,int master_type) -{ -unsigned long start = (unsigned long )vaddr; -unsigned long end = start + size; - -if (master_type ==FOR_CPU ) { -switch (direction) { -case DMA_TO_DEVICE : -break ; -case DMA_FROM_DEVICE : -case DMA_BIDIRECTIONAL : -cpu_dma_inval_range (start, end); -break ; -default : -BUG (); - } - }else { -/* FOR_DEVICE */ -switch (direction) { -case DMA_FROM_DEVICE : -break ; -case DMA_TO_DEVICE : -case DMA_BIDIRECTIONAL : -cpu_dma_wb_range (start, end); -break ; -default : -BUG (); - } - } -} - -static int nds32_dma_map_sg (struct device *dev,struct scatterlist *sg, -int nents,enum dma_data_direction dir, -unsigned long attrs) +static void +nds32_dma_sync_sg_for_device (struct device *dev,struct scatterlist *sg, +int nents,enum dma_data_direction dir) {int i;for (i =0 ; i < nents; i++, sg++) { -char *virt = -page_address ((struct page *)sg->page_link) + sg->offset; -consistent_sync (virt, sg->length, dir,FOR_CPU ); +nds32_dma_sync_single_for_device (dev,sg_dma_address (sg), + sg->length, dir); } -return nents; -} - -static void nds32_dma_unmap_sg (struct device *dev,struct scatterlist *sg, -int nhwentries,enum dma_data_direction dir, -unsigned long attrs) -{ -} - -static void -nds32_dma_sync_single_for_cpu (struct device *dev,dma_addr_t handle, -size_t size,enum dma_data_direction dir) -{ -consistent_sync ((void *)phys_to_virt (handle), size, dir,FOR_CPU ); -} - -static void -nds32_dma_sync_single_for_device (struct device *dev,dma_addr_t handle, -size_t size,enum dma_data_direction dir) -{ -consistent_sync ((void *)phys_to_virt (handle), size, dir,FOR_DEVICE ); } static void
@@ -427,23 +404,28 @@ nds32_dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, int nents,int i;for (i =0 ; i < nents; i++, sg++) { -char *virt = -page_address ((struct page *)sg->page_link) + sg->offset; -consistent_sync (virt, sg->length, dir,FOR_CPU ); +nds32_dma_sync_single_for_cpu (dev,sg_dma_address (sg), + sg->length, dir); } } -static void -nds32_dma_sync_sg_for_device (struct device *dev,struct scatterlist *sg, -int nents,enum dma_data_direction dir) +static int nds32_dma_map_sg (struct device *dev,struct scatterlist *sg, +int nents,enum dma_data_direction dir, +unsigned long attrs) {int i;for (i =0 ; i < nents; i++, sg++) { -char *virt = -page_address ((struct page *)sg->page_link) + sg->offset; -consistent_sync (virt, sg->length, dir,FOR_DEVICE ); +nds32_dma_sync_single_for_device (dev,sg_dma_address (sg), + sg->length, dir); } +return nents; +} + +static void nds32_dma_unmap_sg (struct device *dev,struct scatterlist *sg, +int nhwentries,enum dma_data_direction dir, +unsigned long attrs) +{ }struct dma_map_ops nds32_dma_ops = {
Signature · 1 line
2.17.0
PATCH 9/25 nds32: implement the unmap_sg DMA operation
In reply to Christoph HellwigThis matches the implementation of the more commonly used unmap_single routines and the sync_sg_for_cpu method which should provide equivalent cache maintainance.
--- arch/nds32/kernel/dma.c | 6 ++++++ 1 file changed, 6 insertions(+)
arch/nds32/kernel/dma.c +6 -0
@@ -426,6 +426,12 @@ static void nds32_dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nhwentries, enum dma_data_direction dir, unsigned long attrs) { + int i; + +for (i =0 ; i < nhwentries; i++, sg++) { +nds32_dma_sync_single_for_cpu (dev,sg_dma_address (sg), + sg->length, dir); + } } struct dma_map_ops nds32_dma_ops = {
Signature · 1 line
2.17.0
PATCH 10/25 nds32: use generic dma_noncoherent_ops
In reply to Christoph HellwigSwitch to the generic noncoherent direct mapping implementation.
--- arch/nds32/Kconfig | 3 + arch/nds32/include/asm/Kbuild | 1 + arch/nds32/include/asm/dma-mapping.h | 14 ---- arch/nds32/kernel/dma.c | 113 +++------------------------ 4 files changed, 15 insertions(+), 116 deletions(-) delete mode 100644 arch/nds32/include/asm/dma-mapping.h
arch/nds32/Kconfig +3 -0
@@ -5,10 +5,13 @@ config NDS32 def_bool y + select ARCH_HAS_SYNC_DMA_FOR_CPU + select ARCH_HAS_SYNC_DMA_FOR_DEVICE select ARCH_WANT_FRAME_POINTERS if FTRACE select CLKSRC_MMIO select CLONE_BACKWARDS select COMMON_CLK + select DMA_NONCOHERENT_OPS select GENERIC_ATOMIC64 select GENERIC_CPU_DEVICES select GENERIC_CLOCKEVENTS
arch/nds32/include/asm/Kbuild +1 -0
@@ -13,6 +13,7 @@ generic-y += cputime.h generic-y += device.h generic-y += div64.h generic-y += dma.h +generic-y += dma-mapping.h generic-y += emergency-restart.h generic-y += errno.h generic-y += exec.h
arch/nds32/include/asm/dma-mapping.h deleted +0 -14
@@ -1,14 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -// Copyright (C) 2005-2017 Andes Technology Corporation - -#ifndef ASMNDS32_DMA_MAPPING_H -#define ASMNDS32_DMA_MAPPING_H - -extern struct dma_map_ops nds32_dma_ops; - -static inline struct dma_map_ops *get_arch_dma_ops (struct bus_type *bus) -{ -return &nds32_dma_ops; -} - -#endif
arch/nds32/kernel/dma.c +11 -102
155 lines not on this page · raw message
Signature · 1 line
2.17.0
PATCH 11/25 nios2: use generic dma_noncoherent_ops
In reply to Christoph HellwigSwitch to the generic noncoherent direct mapping implementation.
--- arch/nios2/Kconfig | 3 + arch/nios2/include/asm/Kbuild | 1 + arch/nios2/include/asm/dma-mapping.h | 20 ---- arch/nios2/mm/dma-mapping.c | 139 +++------------------------ 4 files changed, 17 insertions(+), 146 deletions(-) delete mode 100644 arch/nios2/include/asm/dma-mapping.h
arch/nios2/Kconfig +3 -0
@@ -1,6 +1,9 @@ # SPDX-License-Identifier: GPL-2.0 config NIOS2 def_bool y + select ARCH_HAS_SYNC_DMA_FOR_CPU + select ARCH_HAS_SYNC_DMA_FOR_DEVICE + select DMA_NONCOHERENT_OPS select TIMER_OF select GENERIC_ATOMIC64 select GENERIC_CLOCKEVENTS
arch/nios2/include/asm/Kbuild +1 -0
@@ -8,6 +8,7 @@ generic-y += current.h generic-y += device.h generic-y += div64.h generic-y += dma.h +generic-y += dma-mapping.h generic-y += emergency-restart.h generic-y += exec.h generic-y += extable.h
arch/nios2/include/asm/dma-mapping.h deleted +0 -20
@@ -1,20 +0,0 @@ -/* -* Copyright (C) 2011 Tobias Klauser <[email protected]> -* Copyright (C) 2009 Wind River Systems Inc -* -* This file is subject to the terms and conditions of the GNU General -* Public License. See the file COPYING in the main directory of this -* archive for more details. -*/ - -#ifndef _ASM_NIOS2_DMA_MAPPING_H -#define _ASM_NIOS2_DMA_MAPPING_H - -extern const struct dma_map_ops nios2_dma_ops; - -static inline const struct dma_map_ops *get_arch_dma_ops (struct bus_type *bus) -{ -return &nios2_dma_ops; -} - -#endif /* _ASM_NIOS2_DMA_MAPPING_H */
arch/nios2/mm/dma-mapping.c +13 -126
174 lines not on this page · raw message
Signature · 1 line
2.17.0
PATCH 12/25 openrisc: remove the sync_single_for_cpu DMA operation
In reply to Christoph Hellwigopenrisc does all the required cache maintainance at dma map time, and none at unmap time. It thus has to implement sync_single_for_device to match the map cace for buffer reuse, but there is no point in doing another invalidation in the sync_single_cpu_case, which in terms of cache maintainance is equivalent to the unmap case.
--- arch/openrisc/kernel/dma.c | 15 --------------- 1 file changed, 15 deletions(-)
arch/openrisc/kernel/dma.c +0 -15
@@ -208,20 +208,6 @@ or1k_unmap_sg(struct device *dev, struct scatterlist *sg, } } -static void -or1k_sync_single_for_cpu (struct device *dev, -dma_addr_t dma_handle,size_t size, -enum dma_data_direction dir) -{ -unsigned long cl; -dma_addr_t addr = dma_handle; -struct cpuinfo_or1k *cpuinfo = &cpuinfo_or1k[smp_processor_id ()]; - -/* Invalidate the dcache for the requested range */ -for (cl = addr; cl < addr + size; cl += cpuinfo->dcache_block_size) -mtspr (SPR_DCBIR , cl); -} - static void or1k_sync_single_for_device(struct device *dev, dma_addr_t dma_handle, size_t size,
@@ -243,7 +229,6 @@ const struct dma_map_ops or1k_dma_map_ops = { .unmap_page = or1k_unmap_page, .map_sg = or1k_map_sg, .unmap_sg = or1k_unmap_sg, - .sync_single_for_cpu = or1k_sync_single_for_cpu, .sync_single_for_device = or1k_sync_single_for_device, };EXPORT_SYMBOL (or1k_dma_map_ops);
Signature · 1 line
2.17.0
PATCH 13/25 openrisc: remove the no-op unmap_page and unmap_sg DMA operations
In reply to Christoph Hellwig--- arch/openrisc/kernel/dma.c | 23 ----------------------- 1 file changed, 23 deletions(-)
arch/openrisc/kernel/dma.c +0 -23
@@ -171,14 +171,6 @@ or1k_map_page(struct device *dev, struct page *page,return addr; } -static void -or1k_unmap_page (struct device *dev,dma_addr_t dma_handle, -size_t size,enum dma_data_direction dir, -unsigned long attrs) -{ -/* Nothing special to do here... */ -} - static int or1k_map_sg(struct device *dev, struct scatterlist *sg, int nents, enum dma_data_direction dir,
@@ -195,19 +187,6 @@ or1k_map_sg(struct device *dev, struct scatterlist *sg,return nents; } -static void -or1k_unmap_sg (struct device *dev,struct scatterlist *sg, -int nents,enum dma_data_direction dir, -unsigned long attrs) -{ -struct scatterlist *s; -int i; - -for_each_sg (sg, s, nents, i) { -or1k_unmap_page (dev,sg_dma_address (s),sg_dma_len (s), dir,0 ); - } -} - static void or1k_sync_single_for_device(struct device *dev, dma_addr_t dma_handle, size_t size,
@@ -226,9 +205,7 @@ const struct dma_map_ops or1k_dma_map_ops = { .alloc = or1k_dma_alloc, .free = or1k_dma_free, .map_page = or1k_map_page, - .unmap_page = or1k_unmap_page, .map_sg = or1k_map_sg, - .unmap_sg = or1k_unmap_sg, .sync_single_for_device = or1k_sync_single_for_device, };EXPORT_SYMBOL (or1k_dma_map_ops);
Signature · 1 line
2.17.0
PATCH 14/25 openrisc: fix cache maintainance the the sync_single_for_device DMA operation
In reply to Christoph HellwigThe cache maintaince in the sync_single_for_device operation should be equivalent to the map_page operation to facilitate reusing buffers. Fix the openrisc implementation by moving the cache maintaince performed in map_page into the sync_single method, and calling that from map_page.
--- arch/openrisc/kernel/dma.c | 42 +++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 23 deletions(-)
arch/openrisc/kernel/dma.c +19 -23
@@ -133,19 +133,15 @@ or1k_dma_free(struct device *dev, size_t size, void *vaddr,free_pages_exact (vaddr, size); } -static dma_addr_t -or1k_map_page (struct device *dev,struct page *page, -unsigned long offset,size_t size, -enum dma_data_direction dir, -unsigned long attrs) +static void +or1k_sync_single_for_device (struct device *dev, +dma_addr_t dma_handle,size_t size, +enum dma_data_direction dir) {unsigned long cl; -dma_addr_t addr =page_to_phys (page) + offset; +dma_addr_t addr = dma_handle;struct cpuinfo_or1k *cpuinfo = &cpuinfo_or1k[smp_processor_id ()]; -if (attrs &DMA_ATTR_SKIP_CPU_SYNC ) -return addr; -switch (dir) {case DMA_TO_DEVICE :/* Flush the dcache for the requested range */
@@ -168,6 +164,20 @@ or1k_map_page(struct device *dev, struct page *page,break ; } +} + +static dma_addr_t +or1k_map_page (struct device *dev,struct page *page, +unsigned long offset,size_t size, +enum dma_data_direction dir, +unsigned long attrs) +{ +unsigned long cl; +dma_addr_t addr =page_to_phys (page) + offset; +struct cpuinfo_or1k *cpuinfo = &cpuinfo_or1k[smp_processor_id ()]; + +if (!(attrs &DMA_ATTR_SKIP_CPU_SYNC )) +or1k_sync_single_for_device (dev, addr, size, dir);return addr; }
@@ -187,20 +197,6 @@ or1k_map_sg(struct device *dev, struct scatterlist *sg,return nents; } -static void -or1k_sync_single_for_device (struct device *dev, -dma_addr_t dma_handle,size_t size, -enum dma_data_direction dir) -{ -unsigned long cl; -dma_addr_t addr = dma_handle; -struct cpuinfo_or1k *cpuinfo = &cpuinfo_or1k[smp_processor_id ()]; - -/* Flush the dcache for the requested range */ -for (cl = addr; cl < addr + size; cl += cpuinfo->dcache_block_size) -mtspr (SPR_DCBFR , cl); -} -const struct dma_map_ops or1k_dma_map_ops = { .alloc = or1k_dma_alloc, .free = or1k_dma_free,
Signature · 1 line
2.17.0
PATCH 15/25 openrisc: use generic dma_noncoherent_ops
In reply to Christoph HellwigSwitch to the generic noncoherent direct mapping implementation.
--- arch/openrisc/Kconfig | 2 + arch/openrisc/include/asm/Kbuild | 1 + arch/openrisc/include/asm/dma-mapping.h | 35 ------------- arch/openrisc/kernel/dma.c | 65 ++++--------------------- 4 files changed, 12 insertions(+), 91 deletions(-) delete mode 100644 arch/openrisc/include/asm/dma-mapping.h
arch/openrisc/Kconfig +2 -0
@@ -6,6 +6,8 @@ config OPENRISC def_bool y + select ARCH_HAS_SYNC_DMA_FOR_DEVICE + select DMA_NONCOHERENT_OPS select OF select OF_EARLY_FLATTREE select IRQ_DOMAIN
arch/openrisc/include/asm/Kbuild +1 -0
@@ -6,6 +6,7 @@ generic-y += current.h generic-y += device.h generic-y += div64.h generic-y += dma.h +generic-y += dma-mapping.h generic-y += emergency-restart.h generic-y += exec.h generic-y += extable.h
arch/openrisc/include/asm/dma-mapping.h deleted +0 -35
@@ -1,35 +0,0 @@ -/* -* OpenRISC Linux -* -* Linux architectural port borrowing liberally from similar works of -* others. All original copyrights apply as per the original source -* declaration. -* -* OpenRISC implementation: -* Copyright (C) 2010-2011 Jonas Bonn <[email protected]> -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -*/ - -#ifndef __ASM_OPENRISC_DMA_MAPPING_H -#define __ASM_OPENRISC_DMA_MAPPING_H - -/* -* See Documentation/DMA-API-HOWTO.txt and -* Documentation/DMA-API.txt for documentation. -*/ - -#include <linux/dma-debug.h> -#include <linux/dma-mapping.h> - -extern const struct dma_map_ops or1k_dma_map_ops; - -static inline const struct dma_map_ops *get_arch_dma_ops (struct bus_type *bus) -{ -return &or1k_dma_map_ops; -} - -#endif /* __ASM_OPENRISC_DMA_MAPPING_H */
arch/openrisc/kernel/dma.c +9 -56
95 lines not on this page · raw message
Signature · 1 line
2.17.0
PATCH 16/25 sh: simplify get_arch_dma_ops
In reply to Christoph HellwigRemove the indirection through the dma_ops variable, and just return nommu_dma_ops directly from get_arch_dma_ops.
--- arch/sh/include/asm/dma-mapping.h | 5 ++--- arch/sh/kernel/dma-nommu.c | 8 +------- arch/sh/mm/consistent.c | 3 --- arch/sh/mm/init.c | 10 ---------- 4 files changed, 3 insertions(+), 23 deletions(-)
arch/sh/include/asm/dma-mapping.h +2 -3
@@ -2,12 +2,11 @@#ifndef __ASM_SH_DMA_MAPPING_H#define __ASM_SH_DMA_MAPPING_H -extern const struct dma_map_ops *dma_ops; -extern void no_iommu_init (void ); +extern const struct dma_map_ops nommu_dma_ops;static inline const struct dma_map_ops *get_arch_dma_ops (struct bus_type *bus) { -return dma_ops; +return &nommu_dma_ops; } extern void *dma_generic_alloc_coherent(struct device *dev, size_t size,
arch/sh/kernel/dma-nommu.c +1 -7
@@ -79,10 +79,4 @@ const struct dma_map_ops nommu_dma_ops = { .sync_sg_for_device = nommu_sync_sg_for_device,#endif }; - -void __init no_iommu_init (void ) -{ -if (dma_ops) -return ; - dma_ops = &nommu_dma_ops; -} +EXPORT_SYMBOL (nommu_dma_ops);
arch/sh/mm/consistent.c +0 -3
@@ -20,9 +20,6 @@#include <asm/cacheflush.h> #include <asm/addrspace.h> -const struct dma_map_ops *dma_ops; -EXPORT_SYMBOL (dma_ops); -void *dma_generic_alloc_coherent (struct device *dev,size_t size,dma_addr_t *dma_handle,gfp_t gfp,unsigned long attrs)
arch/sh/mm/init.c +0 -10
@@ -395,22 +395,12 @@ void __init paging_init(void)free_area_init_nodes (max_zone_pfns); } -/* -* Early initialization for any I/O MMUs we might have. -*/ -static void __init iommu_init (void ) -{ -no_iommu_init (); -} -unsigned int mem_init_done =0 ;void __init mem_init (void ) {pg_data_t *pgdat; -iommu_init (); - high_memory =NULL ;for_each_online_pgdat (pgdat) high_memory = max_t(void *, high_memory,
Signature · 1 line
2.17.0
PATCH 17/25 sh: introduce a sh_cacheop_vaddr helper
In reply to Christoph HellwigAnd use it in the maple bus code to avoid a dma API dependency.
--- arch/sh/include/asm/cacheflush.h | 7 +++++++ arch/sh/mm/consistent.c | 6 +----- drivers/sh/maple/maple.c | 7 ++++--- 3 files changed, 12 insertions(+), 8 deletions(-)
arch/sh/include/asm/cacheflush.h +7 -0
@@ -101,5 +101,12 @@ void kunmap_coherent(void *kvaddr);void cpu_cache_init (void ); +static inline void *sh_cacheop_vaddr (void *vaddr) +{ +if (__in_29bit_mode ()) + vaddr = (void *)CAC_ADDR ((unsigned long )vaddr); +return vaddr; +} +#endif /* __KERNEL__ */ #endif /* __ASM_SH_CACHEFLUSH_H */
arch/sh/mm/consistent.c +1 -5
@@ -69,10 +69,7 @@ void dma_generic_free_coherent(struct device *dev, size_t size,void sh_sync_dma_for_device (void *vaddr,size_t size,enum dma_data_direction direction) { -void *addr; - - addr =__in_29bit_mode () ? - (void *)CAC_ADDR ((unsigned long )vaddr) : vaddr; +void *addr =sh_cacheop_vaddr (vaddr);switch (direction) {case DMA_FROM_DEVICE :/* invalidate only */
@@ -88,7 +85,6 @@ void sh_sync_dma_for_device(void *vaddr, size_t size,BUG (); } } -EXPORT_SYMBOL (sh_sync_dma_for_device);static int __init memchunk_setup (char *str) {
drivers/sh/maple/maple.c +4 -3
@@ -300,8 +300,8 @@ static void maple_send(void)mutex_unlock (&maple_wlist_lock);if (maple_packets >0 ) {for (i =0 ; i < (1 <<MAPLE_DMA_PAGES ); i++) -sh_sync_dma_for_device (maple_sendbuf + i *PAGE_SIZE , -PAGE_SIZE ,DMA_BIDIRECTIONAL ); +__flush_purge_region (maple_sendbuf + i *PAGE_SIZE , +PAGE_SIZE ); } finish:
@@ -642,7 +642,8 @@ static void maple_dma_handler(struct work_struct *work)list_for_each_entry_safe (mq, nmq, &maple_sentq, list) { mdev = mq->dev; recvbuf = mq->recvbuf->buf; -sh_sync_dma_for_device (recvbuf,0x400 ,DMA_FROM_DEVICE ); +__flush_invalidate_region (sh_cacheop_vaddr (recvbuf), +0x400 ); code = recvbuf[0 ];kfree (mq->sendbuf);list_del_init (&mq->list);
Signature · 1 line
2.17.0
PATCH 18/25 sh: use dma_direct_ops for the CONFIG_DMA_COHERENT case
In reply to Christoph HellwigThis is a slight change in behavior as we avoid the detour through the virtual mapping for the coherent allocator, but if this CPU really is coherent that should be the right thing to do.
--- arch/sh/Kconfig | 1 + arch/sh/include/asm/dma-mapping.h | 4 ++++ arch/sh/kernel/Makefile | 4 ++-- arch/sh/kernel/dma-nommu.c | 4 ---- 4 files changed, 7 insertions(+), 6 deletions(-)
arch/sh/Kconfig +1 -0
@@ -157,6 +157,7 @@ config SWAP_IO_SPACE bool config DMA_COHERENT + select DMA_DIRECT_OPS bool config DMA_NONCOHERENT
arch/sh/include/asm/dma-mapping.h +4 -0
@@ -6,7 +6,11 @@ extern const struct dma_map_ops nommu_dma_ops;static inline const struct dma_map_ops *get_arch_dma_ops (struct bus_type *bus) { +#ifdef CONFIG_DMA_NONCOHERENT return &nommu_dma_ops; +#else +return &dma_direct_ops; +#endif } extern void *dma_generic_alloc_coherent(struct device *dev, size_t size,
arch/sh/kernel/Makefile +2 -2
@@ -12,7 +12,7 @@ endif CFLAGS_REMOVE_return_address.o = -pg -obj-y := debugtraps.o dma-nommu.o dumpstack.o \ +obj-y := debugtraps.o dumpstack.o \ idle.o io.o irq.o irq_$(BITS).o kdebugfs.o \ machvec.o nmi_debug.o process.o \ process_$(BITS).o ptrace.o ptrace_$(BITS).o \
@@ -45,7 +45,7 @@ obj-$(CONFIG_DUMP_CODE) += disassemble.o obj-$(CONFIG_HIBERNATION) += swsusp.o obj-$(CONFIG_DWARF_UNWINDER) += dwarf.o obj-$(CONFIG_PERF_EVENTS) += perf_event.o perf_callchain.o - +obj-$(CONFIG_DMA_NONCOHERENT) += dma-nommu.o obj-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o ccflags-y := -Werror
arch/sh/kernel/dma-nommu.c +0 -4
@@ -51,7 +51,6 @@ static int nommu_map_sg(struct device *dev, struct scatterlist *sg,return nents; } -#ifdef CONFIG_DMA_NONCOHERENT static void nommu_sync_single_for_device (struct device *dev,dma_addr_t addr,size_t size,enum dma_data_direction dir) {
@@ -67,16 +66,13 @@ static void nommu_sync_sg_for_device(struct device *dev, struct scatterlist *sg,for_each_sg (sg, s, nelems, i)sh_sync_dma_for_device (sg_virt (s), s->length, dir); } -#endif const struct dma_map_ops nommu_dma_ops = { .alloc = dma_generic_alloc_coherent, .free = dma_generic_free_coherent, .map_page = nommu_map_page, .map_sg = nommu_map_sg, -#ifdef CONFIG_DMA_NONCOHERENT .sync_single_for_device = nommu_sync_single_for_device, .sync_sg_for_device = nommu_sync_sg_for_device, -#endif };EXPORT_SYMBOL (nommu_dma_ops);
Signature · 1 line
2.17.0
PATCH 19/25 sh: split arch/sh/mm/consistent.c
In reply to Christoph HellwigHalf of the file just contains platform device memory setup code which is required for all builds, and half contains helpers for dma coherent allocation, which is only needed if CONFIG_DMA_NONCOHERENT is enabled.
--- arch/sh/kernel/Makefile | 2 +- arch/sh/kernel/dma-coherent.c | 80 +++++++++++++++++++++++++++++++++++ arch/sh/mm/consistent.c | 75 -------------------------------- 3 files changed, 81 insertions(+), 76 deletions(-) create mode 100644 arch/sh/kernel/dma-coherent.c
arch/sh/kernel/Makefile +1 -1
@@ -45,7 +45,7 @@ obj-$(CONFIG_DUMP_CODE) += disassemble.o obj-$(CONFIG_HIBERNATION) += swsusp.o obj-$(CONFIG_DWARF_UNWINDER) += dwarf.o obj-$(CONFIG_PERF_EVENTS) += perf_event.o perf_callchain.o -obj-$(CONFIG_DMA_NONCOHERENT) += dma-nommu.o +obj-$(CONFIG_DMA_NONCOHERENT) += dma-nommu.o dma-coherent.o obj-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o ccflags-y := -Werror
arch/sh/kernel/dma-coherent.c new file +80 -0
80 lines not on this page · raw message
arch/sh/mm/consistent.c +0 -75
88 lines not on this page · raw message
Signature · 1 line
2.17.0
PATCH 20/25 sh: use generic dma_noncoherent_ops
In reply to Christoph HellwigSwitch to the generic noncoherent direct mapping implementation.
--- arch/sh/Kconfig | 3 +- arch/sh/include/asm/Kbuild | 1 + arch/sh/include/asm/dma-mapping.h | 26 ----------- arch/sh/kernel/Makefile | 2 +- arch/sh/kernel/dma-coherent.c | 23 +++++---- arch/sh/kernel/dma-nommu.c | 78 ------------------------------- 6 files changed, 15 insertions(+), 118 deletions(-) delete mode 100644 arch/sh/include/asm/dma-mapping.h delete mode 100644 arch/sh/kernel/dma-nommu.c
arch/sh/Kconfig +2 -1
@@ -49,7 +49,6 @@ config SUPERH select HAVE_ARCH_AUDITSYSCALL select HAVE_FUTEX_CMPXCHG if FUTEX select HAVE_NMI - select NEED_DMA_MAP_STATE select NEED_SG_DMA_LENGTH help
@@ -162,6 +161,8 @@ config DMA_COHERENT config DMA_NONCOHERENT def_bool !DMA_COHERENT + select ARCH_HAS_SYNC_DMA_FOR_DEVICE + select DMA_NONCOHERENT_OPS config PGTABLE_LEVELS default 3 if X2TLB
arch/sh/include/asm/Kbuild +1 -0
@@ -1,6 +1,7 @@ generic-y += current.h generic-y += delay.h generic-y += div64.h +generic-y += dma-mapping.h generic-y += emergency-restart.h generic-y += exec.h generic-y += irq_regs.h
arch/sh/include/asm/dma-mapping.h deleted +0 -26
@@ -1,26 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef __ASM_SH_DMA_MAPPING_H -#define __ASM_SH_DMA_MAPPING_H - -extern const struct dma_map_ops nommu_dma_ops; - -static inline const struct dma_map_ops *get_arch_dma_ops (struct bus_type *bus) -{ -#ifdef CONFIG_DMA_NONCOHERENT -return &nommu_dma_ops; -#else -return &dma_direct_ops; -#endif -} - -extern void *dma_generic_alloc_coherent (struct device *dev,size_t size, -dma_addr_t *dma_addr,gfp_t flag, -unsigned long attrs); -extern void dma_generic_free_coherent (struct device *dev,size_t size, -void *vaddr,dma_addr_t dma_handle, -unsigned long attrs); - -void sh_sync_dma_for_device (void *vaddr,size_t size, -enum dma_data_direction dir); - -#endif /* __ASM_SH_DMA_MAPPING_H */
arch/sh/kernel/Makefile +1 -1
@@ -45,7 +45,7 @@ obj-$(CONFIG_DUMP_CODE) += disassemble.o obj-$(CONFIG_HIBERNATION) += swsusp.o obj-$(CONFIG_DWARF_UNWINDER) += dwarf.o obj-$(CONFIG_PERF_EVENTS) += perf_event.o perf_callchain.o -obj-$(CONFIG_DMA_NONCOHERENT) += dma-nommu.o dma-coherent.o +obj-$(CONFIG_DMA_NONCOHERENT) += dma-coherent.o obj-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o ccflags-y := -Werror
arch/sh/kernel/dma-coherent.c +11 -12
@@ -7,14 +7,13 @@*/ #include <linux/mm.h> #include <linux/init.h> -#include <linux/dma-mapping.h> +#include <linux/dma-noncoherent.h> #include <linux/module.h> #include <asm/cacheflush.h> #include <asm/addrspace.h> -void *dma_generic_alloc_coherent (struct device *dev,size_t size, -dma_addr_t *dma_handle,gfp_t gfp, -unsigned long attrs) +void *arch_dma_alloc (struct device *dev,size_t size,dma_addr_t *dma_handle, +gfp_t gfp,unsigned long attrs) {void *ret, *ret_nocache;int order =get_order (size);
@@ -29,7 +28,8 @@ void *dma_generic_alloc_coherent(struct device *dev, size_t size,* Pages from the page allocator may have data present in * cache. So flush the cache before using uncached memory. */ -sh_sync_dma_for_device (ret, size,DMA_BIDIRECTIONAL ); +arch_sync_dma_for_device (dev,virt_to_phys (ret), size, +DMA_BIDIRECTIONAL ); ret_nocache = (void __force *)ioremap_nocache (virt_to_phys (ret), size);if (!ret_nocache) {
@@ -44,9 +44,8 @@ void *dma_generic_alloc_coherent(struct device *dev, size_t size,return ret_nocache; } -void dma_generic_free_coherent (struct device *dev,size_t size, -void *vaddr,dma_addr_t dma_handle, -unsigned long attrs) +void arch_dma_free (struct device *dev,size_t size,void *vaddr, +dma_addr_t dma_handle,unsigned long attrs) {int order =get_order (size);unsigned long pfn = (dma_handle >>PAGE_SHIFT ) + dev->dma_pfn_offset;
@@ -58,12 +57,12 @@ void dma_generic_free_coherent(struct device *dev, size_t size,iounmap (vaddr); } -void sh_sync_dma_for_device (void *vaddr,size_t size, -enum dma_data_direction direction) +void arch_sync_dma_for_device (struct device *dev,phys_addr_t paddr, +size_t size,enum dma_data_direction dir) { -void *addr =sh_cacheop_vaddr (vaddr); +void *addr =sh_cacheop_vaddr (phys_to_virt (paddr)); -switch (direction) { +switch (dir) {case DMA_FROM_DEVICE :/* invalidate only */ __flush_invalidate_region (addr, size);break ;
arch/sh/kernel/dma-nommu.c deleted +0 -78
78 lines not on this page · raw message
Signature · 1 line
2.17.0
PATCH 21/25 xtensa: use generic dma_noncoherent_ops
In reply to Christoph HellwigSwitch to the generic noncoherent direct mapping implementation.
--- arch/xtensa/Kconfig | 3 + arch/xtensa/include/asm/Kbuild | 1 + arch/xtensa/include/asm/dma-mapping.h | 26 ------ arch/xtensa/kernel/pci-dma.c | 130 +++----------------------- 4 files changed, 19 insertions(+), 141 deletions(-) delete mode 100644 arch/xtensa/include/asm/dma-mapping.h
arch/xtensa/Kconfig +3 -0
@@ -5,11 +5,14 @@ config ZONE_DMA config XTENSA def_bool y select ARCH_NO_COHERENT_DMA_MMAP if !MMU + select ARCH_HAS_SYNC_DMA_FOR_CPU + select ARCH_HAS_SYNC_DMA_FOR_DEVICE select ARCH_WANT_FRAME_POINTERS select ARCH_WANT_IPC_PARSE_VERSION select BUILDTIME_EXTABLE_SORT select CLONE_BACKWARDS select COMMON_CLK + select DMA_NONCOHERENT_OPS select GENERIC_ATOMIC64 select GENERIC_CLOCKEVENTS select GENERIC_IRQ_SHOW
arch/xtensa/include/asm/Kbuild +1 -0
@@ -2,6 +2,7 @@ generic-y += bug.h generic-y += device.h generic-y += div64.h generic-y += dma-contiguous.h +generic-y += dma-mapping.h generic-y += emergency-restart.h generic-y += exec.h generic-y += extable.h
arch/xtensa/include/asm/dma-mapping.h deleted +0 -26
@@ -1,26 +0,0 @@ -/* -* This file is subject to the terms and conditions of the GNU General Public -* License. See the file "COPYING" in the main directory of this archive -* for more details. -* -* Copyright (C) 2003 - 2005 Tensilica Inc. -* Copyright (C) 2015 Cadence Design Systems Inc. -*/ - -#ifndef _XTENSA_DMA_MAPPING_H -#define _XTENSA_DMA_MAPPING_H - -#include <asm/cache.h> -#include <asm/io.h> - -#include <linux/mm.h> -#include <linux/scatterlist.h> - -extern const struct dma_map_ops xtensa_dma_map_ops; - -static inline const struct dma_map_ops *get_arch_dma_ops (struct bus_type *bus) -{ -return &xtensa_dma_map_ops; -} - -#endif /* _XTENSA_DMA_MAPPING_H */
arch/xtensa/kernel/pci-dma.c +15 -115
190 lines not on this page · raw message
Signature · 1 line
2.17.0
PATCH 22/25 sparc: use generic dma_noncoherent_ops
In reply to Christoph HellwigSwitch to the generic noncoherent direct mapping implementation.
This removes the previous sync_single_for_device implementation, which looks bogus given that no syncing is happening in the similar but more important map_single case.
--- arch/sparc/Kconfig | 2 + arch/sparc/include/asm/dma-mapping.h | 5 +- arch/sparc/kernel/ioport.c | 151 ++------------------------- 3 files changed, 14 insertions(+), 144 deletions(-)
arch/sparc/Kconfig +2 -0
@@ -48,6 +48,8 @@ config SPARC config SPARC32 def_bool !64BIT + select ARCH_HAS_SYNC_DMA_FOR_CPU + select DMA_NONCOHERENT_OPS select GENERIC_ATOMIC64 select CLZ_TAB select HAVE_UID16
arch/sparc/include/asm/dma-mapping.h +2 -3
@@ -7,7 +7,6 @@#include <linux/dma-debug.h> extern const struct dma_map_ops *dma_ops; -extern const struct dma_map_ops pci32_dma_ops;extern struct bus_type pci_bus_type;
@@ -15,11 +14,11 @@ static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus) {#ifdef CONFIG_SPARC_LEON if (sparc_cpu_model == sparc_leon) -return &pci32_dma_ops; +return &dma_noncoherent_ops;#endif #if defined(CONFIG_SPARC32 ) && defined(CONFIG_PCI )if (bus == &pci_bus_type) -return &pci32_dma_ops; +return &dma_noncoherent_ops;#endif return dma_ops; }
arch/sparc/kernel/ioport.c +10 -141
179 lines not on this page · raw message
Signature · 1 line
2.17.0
PATCH 23/25 parisc: merge pcx_dma_ops and pcxl_dma_ops
In reply to Christoph HellwigThe only difference is that pcxl supports dma coherent allocations, while pcx only supports non-consistent allocations and otherwise fails.
But dma_alloc* is not in the fast path, and merging these two allows an easy migration path to the generic dma-noncoherent implementation, so do it.
--- arch/parisc/include/asm/dma-mapping.h | 3 +- arch/parisc/kernel/pci-dma.c | 80 ++++++++++++--------------- arch/parisc/kernel/setup.c | 8 +-- arch/parisc/mm/init.c | 11 +--- 4 files changed, 43 insertions(+), 59 deletions(-)
arch/parisc/include/asm/dma-mapping.h +1 -2
@@ -22,8 +22,7 @@*/ #ifdef CONFIG_PA11 -extern const struct dma_map_ops pcxl_dma_ops; -extern const struct dma_map_ops pcx_dma_ops; +extern const struct dma_map_ops pa11_dma_ops;#endif extern const struct dma_map_ops *hppa_dma_ops;
arch/parisc/kernel/pci-dma.c +36 -44
105 lines not on this page · raw message
arch/parisc/kernel/setup.c +3 -5
@@ -97,14 +97,12 @@ void __init dma_ops_init(void)panic ("PA-RISC Linux currently only supports machines that conform to\n" "the PA-RISC 1.1 or 2.0 architecture specification.\n" ); -case pcxs: -case pcxt: - hppa_dma_ops = &pcx_dma_ops; -break ;case pcxl2:pa7300lc_init ();case pcxl:/* falls through */ - hppa_dma_ops = &pcxl_dma_ops; +case pcxs: +case pcxt: + hppa_dma_ops = &pa11_dma_ops;break ;default :break ;
arch/parisc/mm/init.c +3 -8
@@ -19,7 +19,6 @@#include <linux/gfp.h> #include <linux/delay.h> #include <linux/init.h> -#include <linux/pci.h> /* for hppa_dma_ops and pcxl_dma_ops */ #include <linux/initrd.h> #include <linux/swap.h> #include <linux/unistd.h>
@@ -616,17 +615,13 @@ void __init mem_init(void)free_all_bootmem ();#ifdef CONFIG_PA11 -if (hppa_dma_ops == &pcxl_dma_ops) { +if (boot_cpu_data.cpu_type == pcxl2 || boot_cpu_data.cpu_type == pcxl) { pcxl_dma_start = (unsigned long )SET_MAP_OFFSET (MAP_START ); parisc_vmalloc_start =SET_MAP_OFFSET (pcxl_dma_start +PCXL_DMA_MAP_SIZE ); - }else { - pcxl_dma_start =0 ; - parisc_vmalloc_start =SET_MAP_OFFSET (MAP_START ); - } -#else - parisc_vmalloc_start =SET_MAP_OFFSET (MAP_START ); + } else#endif + parisc_vmalloc_start =SET_MAP_OFFSET (MAP_START );mem_init_print_info (NULL );
Signature · 1 line
2.17.0
PATCH 24/25 parisc: always use flush_kernel_dcache_range for DMA cache maintainance
In reply to Christoph HellwigCurrent the S/G list based DMA ops use flush_kernel_vmap_range which contains a few UP optimizations, while the rest of the DMA operations uses flush_kernel_dcache_range. The single vs sg operations are supposed to have the same effect, so they should use the same routines. Use the more conservation version for now, but if people more familiar with parisc think the vmap version is generally fine for DMA we should switch all interfaces over to it.
--- arch/parisc/kernel/pci-dma.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/parisc/kernel/pci-dma.c +3 -3
@@ -550,7 +550,7 @@ static void pa11_dma_unmap_sg(struct device *dev, struct scatterlist *sglist,/* once we do combining we'll need to use phys_to_virt(sg_dma_address(sglist)) */ for_each_sg (sglist, sg, nents, i) -flush_kernel_vmap_range (sg_virt (sg), sg->length); +flush_kernel_dcache_range (sg_virt (sg), sg->length); } static void pa11_dma_sync_single_for_cpu(struct device *dev,
@@ -581,7 +581,7 @@ static void pa11_dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sgl/* once we do combining we'll need to use phys_to_virt(sg_dma_address(sglist)) */ for_each_sg (sglist, sg, nents, i) -flush_kernel_vmap_range (sg_virt (sg), sg->length); +flush_kernel_dcache_range (sg_virt (sg), sg->length); }static void pa11_dma_sync_sg_for_device (struct device *dev,struct scatterlist *sglist,int nents,enum dma_data_direction direction)
@@ -592,7 +592,7 @@ static void pa11_dma_sync_sg_for_device(struct device *dev, struct scatterlist */* once we do combining we'll need to use phys_to_virt(sg_dma_address(sglist)) */ for_each_sg (sglist, sg, nents, i) -flush_kernel_vmap_range (sg_virt (sg), sg->length); +flush_kernel_dcache_range (sg_virt (sg), sg->length); } static void pa11_dma_cache_sync(struct device *dev, void *vaddr, size_t size,
Signature · 1 line
2.17.0
PATCH 25/25 parisc: use generic dma_noncoherent_ops
In reply to Christoph HellwigSwitch to the generic noncoherent direct mapping implementation.
Fix sync_single_for_cpu to do skip the cache flush unless the transfer is to the device to match the more tested unmap_single path which should have the same cache coherency implications.
--- arch/parisc/Kconfig | 4 + arch/parisc/include/asm/dma-mapping.h | 4 - arch/parisc/kernel/pci-dma.c | 145 ++------------------------ arch/parisc/kernel/setup.c | 2 +- 4 files changed, 16 insertions(+), 139 deletions(-)
arch/parisc/Kconfig +4 -0
@@ -188,6 +188,10 @@ config PA20 config PA11 def_bool y depends on PA7000 || PA7100LC || PA7200 || PA7300LC + select ARCH_HAS_SYNC_DMA_FOR_CPU + select ARCH_HAS_SYNC_DMA_FOR_DEVICE + select DMA_NONCOHERENT_OPS + select DMA_NONCOHERENT_CACHE_SYNC config PREFETCH def_bool y
arch/parisc/include/asm/dma-mapping.h +0 -4
@@ -21,10 +21,6 @@** flush/purge and allocate "regular" cacheable pages for everything. */ -#ifdef CONFIG_PA11 -extern const struct dma_map_ops pa11_dma_ops; -#endif -extern const struct dma_map_ops *hppa_dma_ops;static inline const struct dma_map_ops *get_arch_dma_ops (struct bus_type *bus)
arch/parisc/kernel/pci-dma.c +11 -134
180 lines not on this page · raw message
arch/parisc/kernel/setup.c +1 -1
@@ -102,7 +102,7 @@ void __init dma_ops_init(void)case pcxl:/* falls through */ case pcxs:case pcxt: - hppa_dma_ops = &pa11_dma_ops; + hppa_dma_ops = &dma_noncoherent_ops;break ;default :break ;
Signature · 1 line
2.17.0