refactor dma_cache_sync
Subsystems (16)
The dma_cache_sync routines is used to flush caches for memory returned by dma_alloc_attrs with the DMA_ATTR_NON_CONSISTENT flag (or previously from dma_alloc_noncoherent), but the requirements for it seems to be frequently misunderstood. dma_cache_sync is documented to be a no-op for allocations that do not have the DMA_ATTR_NON_CONSISTENT flag set, and yet a lot of architectures implement it in some way despite not implementing DMA_ATTR_NON_CONSISTENT.
This series removes a few abuses of dma_cache_sync for non-DMA API purposes, then changes all remaining architectures that do not implement DMA_ATTR_NON_CONSISTENT to implement dma_cache_sync as a no-op, and then adds the struct dma_map_ops indirection we use for all other DMA mapping operations to dma_cache_sync as well, thus removing all but two implementations of the function.
PATCH 1/12 floppy: consolidate the dummy fd_cacheflush definition
Only mips defines this helper, so remove all the other arch definitions.
--- arch/alpha/include/asm/floppy.h | 2 -- arch/powerpc/include/asm/floppy.h | 2 -- arch/sparc/include/asm/floppy_32.h | 1 - arch/sparc/include/asm/floppy_64.h | 1 - drivers/block/floppy.c | 4 ++++ 5 files changed, 4 insertions(+), 6 deletions(-)
arch/alpha/include/asm/floppy.h +0 -2
@@ -24,7 +24,6 @@#define fd_set_dma_count (count) set_dma_count(FLOPPY_DMA,count)#define fd_enable_irq () enable_irq(FLOPPY_IRQ)#define fd_disable_irq () disable_irq(FLOPPY_IRQ) -#define fd_cacheflush (addr,size)/* nothing */ #define fd_request_irq () request_irq(FLOPPY_IRQ, floppy_interrupt,\ 0, "floppy", NULL)#define fd_free_irq () free_irq(FLOPPY_IRQ, NULL)
@@ -62,7 +61,6 @@ alpha_fd_dma_setup(char *addr, unsigned long size, int mode, int io) prev_dir = dir;fd_clear_dma_ff (); -fd_cacheflush (addr, size);fd_set_dma_mode (mode);set_dma_addr (FLOPPY_DMA , bus_addr);fd_set_dma_count (size);
arch/powerpc/include/asm/floppy.h +0 -2
@@ -25,7 +25,6 @@#define fd_get_dma_residue () fd_ops->_get_dma_residue(FLOPPY_DMA)#define fd_enable_irq () enable_irq(FLOPPY_IRQ)#define fd_disable_irq () disable_irq(FLOPPY_IRQ) -#define fd_cacheflush (addr,size)/* nothing */ #define fd_free_irq () free_irq(FLOPPY_IRQ, NULL);#include <linux/pci.h>
@@ -152,7 +151,6 @@ static int hard_dma_setup(char *addr, unsigned long size, int mode, int io) prev_dir = dir;fd_clear_dma_ff (); -fd_cacheflush (addr, size);fd_set_dma_mode (mode);set_dma_addr (FLOPPY_DMA , bus_addr);fd_set_dma_count (size);
arch/sparc/include/asm/floppy_32.h +0 -1
@@ -70,7 +70,6 @@ static struct sun_floppy_ops sun_fdops;#define fd_set_dma_count (count) sun_fd_set_dma_count(count)#define fd_enable_irq ()/* nothing... */ #define fd_disable_irq ()/* nothing... */ -#define fd_cacheflush (addr, size)/* nothing... */ #define fd_request_irq () sun_fd_request_irq()#define fd_free_irq ()/* nothing... */ #if 0 /* P3: added by Alain, these cause a MMU corruption. 19960524 XXX */
arch/sparc/include/asm/floppy_64.h +0 -1
@@ -72,7 +72,6 @@ static struct sun_floppy_ops sun_fdops;#define fd_set_dma_addr (addr) sun_fdops.fd_set_dma_addr(addr)#define fd_set_dma_count (count) sun_fdops.fd_set_dma_count(count)#define get_dma_residue (x) sun_fdops.get_dma_residue() -#define fd_cacheflush (addr, size)/* nothing... */ #define fd_request_irq () sun_fdops.fd_request_irq()#define fd_free_irq () sun_fdops.fd_free_irq()#define fd_eject (drive) sun_fdops.fd_eject(drive)
drivers/block/floppy.c +4 -0
@@ -275,6 +275,10 @@ static int set_next_request(void);#define fd_dma_mem_alloc (size) __get_dma_pages(GFP_KERNEL, get_order(size))#endif +#ifndef fd_cacheflush +#define fd_cacheflush (addr, size)/* nothing... */ +#endif +static inline void fallback_on_nodma_alloc (char **addr,size_t l) {#ifdef FLOPPY_CAN_FALLBACK_ON_NODMA
Signature · 1 line
2.11.0
PATCH 2/12 mips: don't use dma_cache_sync to implement fd_cacheflush
In reply to Christoph HellwigThe floppy drivers doesn't otherwise use the DMA API, so indirecting through it just for cache flushing in MIPS-specific code just call dma_cache_wback_inv directly.
--- arch/mips/include/asm/floppy.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/mips/include/asm/floppy.h +2 -2
@@ -10,11 +10,11 @@#ifndef _ASM_FLOPPY_H#define _ASM_FLOPPY_H -#include <linux/dma-mapping.h> +#include <asm/io.h> static inline void fd_cacheflush (char * addr,long size) { -dma_cache_sync (NULL , addr, size,DMA_BIDIRECTIONAL ); +dma_cache_wback_inv ((unsigned long )addr, size); }#define MAX_BUFFER_SECTORS 24
Signature · 1 line
2.11.0
PATCH 3/12 frv: make dma_cache_sync a no-op
In reply to Christoph Hellwigfrv does not implement DMA_ATTR_NON_CONSISTENT allocations, so it doesn't make any sense to do any work in dma_cache_sync given that it must be a no-op when dma_alloc_attrs returns coherent memory.
--- arch/frv/include/asm/dma-mapping.h | 1 - 1 file changed, 1 deletion(-)
arch/frv/include/asm/dma-mapping.h +0 -1
@@ -18,7 +18,6 @@ static inlinevoid dma_cache_sync (struct device *dev,void *vaddr,size_t size,enum dma_data_direction direction) { -flush_write_buffers (); }#endif /* _ASM_DMA_MAPPING_H */
Signature · 1 line
2.11.0
PATCH 4/12 x86: make dma_cache_sync a no-op
In reply to Christoph Hellwigx86 does not implement DMA_ATTR_NON_CONSISTENT allocations, so it doesn't make any sense to do any work in dma_cache_sync given that it must be a no-op when dma_alloc_attrs returns coherent memory.
--- arch/x86/include/asm/dma-mapping.h | 1 - 1 file changed, 1 deletion(-)
arch/x86/include/asm/dma-mapping.h +0 -1
@@ -70,7 +70,6 @@ static inline void dma_cache_sync(struct device *dev, void *vaddr, size_t size, enum dma_data_direction dir) { -flush_write_buffers (); } static inline unsigned long dma_alloc_coherent_mask(struct device *dev,
Signature · 1 line
2.11.0
PATCH 5/12 ia64: make dma_cache_sync a no-op
In reply to Christoph Hellwigia64 does not implement DMA_ATTR_NON_CONSISTENT allocations, so it doesn't make any sense to do any work in dma_cache_sync given that it must be a no-op when dma_alloc_attrs returns coherent memory.
--- arch/ia64/include/asm/dma-mapping.h | 5 ----- 1 file changed, 5 deletions(-)
arch/ia64/include/asm/dma-mapping.h +0 -5
@@ -48,11 +48,6 @@ static inline void dma_cache_sync (struct device *dev, void *vaddr, size_t size, enum dma_data_direction dir) { -/* -* IA-64 is cache-coherent, so this is mostly a no-op. However, we do need to -* ensure that dma_cache_sync() enforces order, hence the mb(). -*/ -mb (); } #endif /* _ASM_IA64_DMA_MAPPING_H */
Signature · 1 line
2.11.0
PATCH 6/12 microblaze: make dma_cache_sync a no-op
In reply to Christoph Hellwigmicroblaze does not implement DMA_ATTR_NON_CONSISTENT allocations, so it doesn't make any sense to do any work in dma_cache_sync given that it must be a no-op when dma_alloc_attrs returns coherent memory.
This also allows moving __dma_sync out of the microblaze asm/dma-mapping.h and thus greatly reduce the amount of includes there.
--- arch/microblaze/include/asm/dma-mapping.h | 34 ------------------------------- arch/microblaze/kernel/dma.c | 17 ++++++++++++++++ 2 files changed, 17 insertions(+), 34 deletions(-)
arch/microblaze/include/asm/dma-mapping.h +0 -34
@@ -16,22 +16,6 @@#define _ASM_MICROBLAZE_DMA_MAPPING_H/* -* See Documentation/DMA-API-HOWTO.txt and -* Documentation/DMA-API.txt for documentation. -*/ - -#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> -#include <asm/cacheflush.h> - -#define __dma_alloc_coherent (dev, gfp, size, handle) NULL -#define __dma_free_coherent (size, addr) ((void)0) - -/* * Available generic sets of operations */ extern const struct dma_map_ops dma_direct_ops;
@@ -41,27 +25,9 @@ static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus) return &dma_direct_ops; } -static inline void __dma_sync (unsigned long paddr, -size_t size,enum dma_data_direction direction) -{ -switch (direction) { -case DMA_TO_DEVICE : -case DMA_BIDIRECTIONAL : -flush_dcache_range (paddr, paddr + size); -break ; -case DMA_FROM_DEVICE : -invalidate_dcache_range (paddr, paddr + size); -break ; -default : -BUG (); - } -} -static inline void dma_cache_sync (struct device *dev,void *vaddr,size_t size,enum dma_data_direction direction) { -BUG_ON (direction =DMA_NONE ); -__dma_sync (virt_to_phys (vaddr), size, (int )direction); }#endif /* _ASM_MICROBLAZE_DMA_MAPPING_H */
arch/microblaze/kernel/dma.c +17 -0
@@ -12,6 +12,7 @@#include <linux/dma-debug.h> #include <linux/export.h> #include <linux/bug.h> +#include <asm/cacheflush.h> #define NOT_COHERENT_CACHE
@@ -51,6 +52,22 @@ static void dma_direct_free_coherent(struct device *dev, size_t size,#endif } +static inline void __dma_sync (unsigned long paddr, +size_t size,enum dma_data_direction direction) +{ +switch (direction) { +case DMA_TO_DEVICE : +case DMA_BIDIRECTIONAL : +flush_dcache_range (paddr, paddr + size); +break ; +case DMA_FROM_DEVICE : +invalidate_dcache_range (paddr, paddr + size); +break ; +default : +BUG (); + } +} +static int dma_direct_map_sg (struct device *dev,struct scatterlist *sgl,int nents,enum dma_data_direction direction,unsigned long attrs)
Signature · 1 line
2.11.0
PATCH 7/12 mn10300: make dma_cache_sync a no-op
In reply to Christoph Hellwigmn10300 does not implement DMA_ATTR_NON_CONSISTENT allocations, so it doesn't make any sense to do any work in dma_cache_sync given that it must be a no-op when dma_alloc_attrs returns coherent memory.
--- arch/mn10300/include/asm/dma-mapping.h | 4 ---- 1 file changed, 4 deletions(-)
arch/mn10300/include/asm/dma-mapping.h +0 -4
@@ -11,9 +11,6 @@#ifndef _ASM_DMA_MAPPING_H#define _ASM_DMA_MAPPING_H -#include <asm/cache.h> -#include <asm/io.h> -extern const struct dma_map_ops mn10300_dma_ops;static inline const struct dma_map_ops *get_arch_dma_ops (struct bus_type *bus)
@@ -25,7 +22,6 @@ static inlinevoid dma_cache_sync (void *vaddr,size_t size,enum dma_data_direction direction) { -mn10300_dcache_flush_inv (); }#endif
Signature · 1 line
2.11.0
PATCH 8/12 powerpc: make dma_cache_sync a no-op
In reply to Christoph Hellwigpowerpc does not implement DMA_ATTR_NON_CONSISTENT allocations, so it doesn't make any sense to do any work in dma_cache_sync given that it must be a no-op when dma_alloc_attrs returns coherent memory.
--- arch/powerpc/include/asm/dma-mapping.h | 2 -- 1 file changed, 2 deletions(-)
arch/powerpc/include/asm/dma-mapping.h +0 -2
@@ -144,8 +144,6 @@ static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)static inline void dma_cache_sync (struct device *dev,void *vaddr,size_t size,enum dma_data_direction direction) { -BUG_ON (direction =DMA_NONE ); -__dma_sync (vaddr, size, (int )direction); }#endif /* __KERNEL__ */
Signature · 1 line
2.11.0
PATCH 9/12 unicore32: make dma_cache_sync a no-op
In reply to Christoph Hellwigunicore32 does not implement DMA_ATTR_NON_CONSISTENT allocations, so it doesn't make any sense to do any work in dma_cache_sync given that it must be a no-op when dma_alloc_attrs returns coherent memory.
--- arch/unicore32/include/asm/cacheflush.h | 9 --------- arch/unicore32/include/asm/dma-mapping.h | 17 ----------------- arch/unicore32/mm/proc-syms.c | 3 --- 3 files changed, 29 deletions(-)
arch/unicore32/include/asm/cacheflush.h +0 -9
@@ -102,15 +102,6 @@ extern void __cpuc_flush_dcache_area(void *, size_t);extern void __cpuc_flush_kern_dcache_area (void *addr,size_t size);/* -* These are private to the dma-mapping API. Do not use directly. -* Their sole purpose is to ensure that data held in the cache -* is visible to DMA, or data written by DMA to system memory is -* visible to the CPU. -*/ -extern void __cpuc_dma_clean_range (unsigned long ,unsigned long ); -extern void __cpuc_dma_flush_range (unsigned long ,unsigned long ); - -/* * Copy user data from/to a page which is mapped into a different * processes address space. Really, we want to allow our "user * space" model to handle this.
arch/unicore32/include/asm/dma-mapping.h +0 -17
@@ -18,9 +18,6 @@#include <linux/scatterlist.h> #include <linux/swiotlb.h> -#include <asm/memory.h> -#include <asm/cacheflush.h> -extern const struct dma_map_ops swiotlb_dma_map_ops;static inline const struct dma_map_ops *get_arch_dma_ops (struct bus_type *bus)
@@ -51,20 +48,6 @@ static inline void dma_mark_clean(void *addr, size_t size) {}static inline void dma_cache_sync (struct device *dev,void *vaddr,size_t size,enum dma_data_direction direction) { -unsigned long start = (unsigned long )vaddr; -unsigned long end = start + size; - -switch (direction) { -case DMA_NONE : -BUG (); -case DMA_FROM_DEVICE : -case DMA_BIDIRECTIONAL :/* writeback and invalidate */ -__cpuc_dma_flush_range (start, end); -break ; -case DMA_TO_DEVICE :/* writeback only */ -__cpuc_dma_clean_range (start, end); -break ; - } }#endif /* __KERNEL__ */
arch/unicore32/mm/proc-syms.c +0 -3
@@ -20,6 +20,3 @@ EXPORT_SYMBOL(cpu_dcache_clean_area);EXPORT_SYMBOL (cpu_set_pte);EXPORT_SYMBOL (__cpuc_coherent_kern_range); - -EXPORT_SYMBOL (__cpuc_dma_flush_range); -EXPORT_SYMBOL (__cpuc_dma_clean_range);
Signature · 1 line
2.11.0
PATCH 10/12 xtensa: make dma_cache_sync a no-op
In reply to Christoph Hellwigxtensa does not implement DMA_ATTR_NON_CONSISTENT allocations, so it doesn't make any sense to do any work in dma_cache_sync given that it must be a no-op when dma_alloc_attrs returns coherent memory.
--- arch/xtensa/include/asm/dma-mapping.h | 6 ++++-- arch/xtensa/kernel/pci-dma.c | 23 ----------------------- 2 files changed, 4 insertions(+), 25 deletions(-)
arch/xtensa/include/asm/dma-mapping.h +4 -2
@@ -23,8 +23,10 @@ static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus)return &xtensa_dma_map_ops; } -void dma_cache_sync (struct device *dev,void *vaddr,size_t size, -enum dma_data_direction direction); +static inline void dma_cache_sync (struct device *dev,void *vaddr,size_t size, +enum dma_data_direction direction) +{ +}static inline dma_addr_t phys_to_dma (struct device *dev,phys_addr_t paddr) {
arch/xtensa/kernel/pci-dma.c +0 -23
@@ -26,29 +26,6 @@#include <asm/cacheflush.h> #include <asm/io.h> -void dma_cache_sync (struct device *dev,void *vaddr,size_t size, -enum dma_data_direction dir) -{ -switch (dir) { -case DMA_BIDIRECTIONAL : -__flush_invalidate_dcache_range ((unsigned long )vaddr, size); -break ; - -case DMA_FROM_DEVICE : -__invalidate_dcache_range ((unsigned long )vaddr, size); -break ; - -case DMA_TO_DEVICE : -__flush_dcache_range ((unsigned long )vaddr, size); -break ; - -case DMA_NONE : -BUG (); -break ; - } -} -EXPORT_SYMBOL (dma_cache_sync); -static void do_cache_op (dma_addr_t dma_handle,size_t size,void (*fn)(unsigned long ,unsigned long )) {
Signature · 1 line
2.11.0
PATCH 11/12 sh: make dma_cache_sync a no-op
In reply to Christoph Hellwigsh does not implement DMA_ATTR_NON_CONSISTENT allocations, so it doesn't make any sense to do any work in dma_cache_sync given that it must be a no-op when dma_alloc_attrs returns coherent memory.
On the other hand sh uses dma_cache_sync internally in the dma_ops implementation and for the maple bus that does not use the DMA API, so a the old functionality for dma_cache_sync is still provided under the name sh_sync_dma_for_device, and without the redundant dev argument. While at it two of the syncing dma_ops also go the proper _for_device postfix.
--- arch/sh/include/asm/dma-mapping.h | 9 +++++++-- arch/sh/kernel/dma-nommu.c | 17 +++++++++-------- arch/sh/mm/consistent.c | 6 +++--- drivers/sh/maple/maple.c | 5 ++--- 4 files changed, 21 insertions(+), 16 deletions(-)
arch/sh/include/asm/dma-mapping.h +7 -2
@@ -9,8 +9,10 @@ static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus)return dma_ops; } -void dma_cache_sync (struct device *dev,void *vaddr,size_t size, -enum dma_data_direction dir); +static inline void dma_cache_sync (struct device *dev,void *vaddr,size_t size, +enum dma_data_direction dir) +{ +}/* arch/sh/mm/consistent.c */ extern void *dma_generic_alloc_coherent(struct device *dev, size_t size,
@@ -20,4 +22,7 @@ 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/dma-nommu.c +9 -8
@@ -9,6 +9,7 @@*/ #include <linux/dma-mapping.h> #include <linux/io.h> +#include <asm/cacheflush.h> static dma_addr_t nommu_map_page(struct device *dev, struct page *page, unsigned long offset, size_t size,
@@ -20,7 +21,7 @@ static dma_addr_t nommu_map_page(struct device *dev, struct page *page,WARN_ON (size =0 );if (!(attrs &DMA_ATTR_SKIP_CPU_SYNC )) -dma_cache_sync (dev,page_address (page) + offset, size, dir); +sh_sync_dma_for_device (page_address (page) + offset, size, dir);return addr; }
@@ -38,7 +39,7 @@ static int nommu_map_sg(struct device *dev, struct scatterlist *sg,BUG_ON (!sg_page (s));if (!(attrs &DMA_ATTR_SKIP_CPU_SYNC )) -dma_cache_sync (dev,sg_virt (s), s->length, dir); +sh_sync_dma_for_device (sg_virt (s), s->length, dir); s->dma_address =sg_phys (s); s->dma_length = s->length;
@@ -48,20 +49,20 @@ static int nommu_map_sg(struct device *dev, struct scatterlist *sg, }#ifdef CONFIG_DMA_NONCOHERENT -static void nommu_sync_single (struct device *dev,dma_addr_t addr, +static void nommu_sync_single_for_device (struct device *dev,dma_addr_t addr,size_t size,enum dma_data_direction dir) { -dma_cache_sync (dev,phys_to_virt (addr), size, dir); +sh_sync_dma_for_device (phys_to_virt (addr), size, dir); } -static void nommu_sync_sg (struct device *dev,struct scatterlist *sg, +static void nommu_sync_sg_for_device (struct device *dev,struct scatterlist *sg,int nelems,enum dma_data_direction dir) {struct scatterlist *s;int i;for_each_sg (sg, s, nelems, i) -dma_cache_sync (dev,sg_virt (s), s->length, dir); +sh_sync_dma_for_device (sg_virt (s), s->length, dir); }#endif
@@ -71,8 +72,8 @@ const struct dma_map_ops nommu_dma_ops = { .map_page = nommu_map_page, .map_sg = nommu_map_sg, #ifdef CONFIG_DMA_NONCOHERENT - .sync_single_for_device = nommu_sync_single, - .sync_sg_for_device = nommu_sync_sg, + .sync_single_for_device = nommu_sync_single_for_device, + .sync_sg_for_device = nommu_sync_sg_for_device, #endif .is_phys = 1, };
arch/sh/mm/consistent.c +3 -3
@@ -49,7 +49,7 @@ 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. */ -dma_cache_sync (dev, ret, size,DMA_BIDIRECTIONAL ); +sh_sync_dma_for_device (ret, size,DMA_BIDIRECTIONAL ); ret_nocache = (void __force *)ioremap_nocache (virt_to_phys (ret), size);if (!ret_nocache) {
@@ -78,7 +78,7 @@ void dma_generic_free_coherent(struct device *dev, size_t size,iounmap (vaddr); } -void dma_cache_sync (struct device *dev,void *vaddr,size_t size, +void sh_sync_dma_for_device (void *vaddr,size_t size,enum dma_data_direction direction) {void *addr;
@@ -100,7 +100,7 @@ void dma_cache_sync(struct device *dev, void *vaddr, size_t size,BUG (); } } -EXPORT_SYMBOL (dma_cache_sync); +EXPORT_SYMBOL (sh_sync_dma_for_device);static int __init memchunk_setup (char *str) {
drivers/sh/maple/maple.c +2 -3
@@ -300,7 +300,7 @@ static void maple_send(void)mutex_unlock (&maple_wlist_lock);if (maple_packets >0 ) {for (i =0 ; i < (1 <<MAPLE_DMA_PAGES ); i++) -dma_cache_sync (0 , maple_sendbuf + i *PAGE_SIZE , +sh_sync_dma_for_device (maple_sendbuf + i *PAGE_SIZE ,PAGE_SIZE ,DMA_BIDIRECTIONAL ); }
@@ -642,8 +642,7 @@ 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; -dma_cache_sync (&mdev->dev, recvbuf,0x400 , -DMA_FROM_DEVICE ); +sh_sync_dma_for_device (recvbuf,0x400 ,DMA_FROM_DEVICE ); code = recvbuf[0 ];kfree (mq->sendbuf);list_del_init (&mq->list);
Signature · 1 line
2.11.0
PATCH 12/12 dma-mapping: turn dma_cache_sync into a dma_map_ops method
In reply to Christoph HellwigAfter we removed all the dead wood it turns out only two architectures actually implement dma_cache_sync as a no-op: mips and parisc. Add a cache_sync method to struct dma_map_ops and implement it for the mips defualt DMA ops, and the parisc pa11 ops.
Note that arm, arc and openrisc support DMA_ATTR_NON_CONSISTENT, but never provided a functional dma_cache_sync implementations, which seems somewhat odd.
--- arch/alpha/include/asm/dma-mapping.h | 2 -- arch/cris/include/asm/dma-mapping.h | 6 ------ arch/frv/include/asm/dma-mapping.h | 6 ------ arch/hexagon/include/asm/dma-mapping.h | 3 --- arch/ia64/include/asm/dma-mapping.h | 6 ------ arch/m32r/include/asm/dma-mapping.h | 5 ----- arch/m68k/include/asm/dma-mapping.h | 6 ------ arch/metag/include/asm/dma-mapping.h | 10 ---------- arch/microblaze/include/asm/dma-mapping.h | 5 ----- arch/mips/include/asm/dma-mapping.h | 3 --- arch/mips/mm/dma-default.c | 7 +++---- arch/mn10300/include/asm/dma-mapping.h | 6 ------ arch/nios2/include/asm/dma-mapping.h | 9 --------- arch/parisc/include/asm/dma-mapping.h | 8 -------- arch/parisc/kernel/pci-dma.c | 8 ++++++++ arch/powerpc/include/asm/dma-mapping.h | 5 ----- arch/s390/include/asm/dma-mapping.h | 5 ----- arch/sh/include/asm/dma-mapping.h | 6 ------ arch/sparc/include/asm/dma-mapping.h | 8 -------- arch/tile/include/asm/dma-mapping.h | 9 --------- arch/unicore32/include/asm/dma-mapping.h | 5 ----- arch/x86/include/asm/dma-mapping.h | 6 ------ arch/xtensa/include/asm/dma-mapping.h | 5 ----- include/linux/dma-mapping.h | 13 +++++++++++++ 24 files changed, 24 insertions(+), 128 deletions(-)
arch/alpha/include/asm/dma-mapping.h +0 -2
@@ -8,6 +8,4 @@ static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus) return dma_ops; } -#define dma_cache_sync (dev, va, size, dir) ((void)0) -#endif /* _ALPHA_DMA_MAPPING_H */
arch/cris/include/asm/dma-mapping.h +0 -6
@@ -16,10 +16,4 @@ static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus) }#endif -static inline void -dma_cache_sync (struct device *dev,void *vaddr,size_t size, -enum dma_data_direction direction) -{ -} -#endif
arch/frv/include/asm/dma-mapping.h +0 -6
@@ -14,10 +14,4 @@ static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus) return &frv_dma_ops; } -static inline -void dma_cache_sync (struct device *dev,void *vaddr,size_t size, -enum dma_data_direction direction) -{ -} -#endif /* _ASM_DMA_MAPPING_H */
arch/hexagon/include/asm/dma-mapping.h +0 -3
@@ -37,9 +37,6 @@ static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus)return dma_ops; } -extern void dma_cache_sync (struct device *dev,void *vaddr,size_t size, -enum dma_data_direction direction); -static inline bool dma_capable (struct device *dev,dma_addr_t addr,size_t size) {if (!dev->dma_mask)
arch/ia64/include/asm/dma-mapping.h +0 -6
@@ -44,10 +44,4 @@ static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr) return daddr; } -static inline void -dma_cache_sync (struct device *dev,void *vaddr,size_t size, -enum dma_data_direction dir) -{ -} -#endif /* _ASM_IA64_DMA_MAPPING_H */
arch/m32r/include/asm/dma-mapping.h +0 -5
@@ -13,11 +13,6 @@ static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus)return &dma_noop_ops; } -static inline void dma_cache_sync (struct device *dev,void *vaddr,size_t size, -enum dma_data_direction direction) -{ -} -static inline bool dma_capable (struct device *dev,dma_addr_t addr,size_t size) {if (!dev->dma_mask)
arch/m68k/include/asm/dma-mapping.h +0 -6
@@ -8,10 +8,4 @@ static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus) return &m68k_dma_ops; } -static inline void dma_cache_sync (struct device *dev,void *vaddr,size_t size, -enum dma_data_direction dir) -{ -/* we use coherent allocation, so not much to do here. */ -} -#endif /* _M68K_DMA_MAPPING_H */
arch/metag/include/asm/dma-mapping.h +0 -10
@@ -8,14 +8,4 @@ static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus) return &metag_dma_ops; } -/* -* dma_alloc_attrs() always returns non-cacheable memory, so there's no need to -* do any flushing here. -*/ -static inline void -dma_cache_sync (struct device *dev,void *vaddr,size_t size, -enum dma_data_direction direction) -{ -} -#endif
arch/microblaze/include/asm/dma-mapping.h +0 -5
@@ -25,9 +25,4 @@ static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus) return &dma_direct_ops; } -static inline void dma_cache_sync (struct device *dev,void *vaddr,size_t size, -enum dma_data_direction direction) -{ -} -#endif /* _ASM_MICROBLAZE_DMA_MAPPING_H */
arch/mips/include/asm/dma-mapping.h +0 -3
@@ -26,9 +26,6 @@ static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)static inline void dma_mark_clean (void *addr,size_t size) {} -extern void dma_cache_sync (struct device *dev,void *vaddr,size_t size, -enum dma_data_direction direction); -#define arch_setup_dma_ops arch_setup_dma_ops static inline void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size, const struct iommu_ops *iommu,
arch/mips/mm/dma-default.c +3 -4
@@ -419,7 +419,7 @@ int mips_dma_supported(struct device *dev, u64 mask)return plat_dma_supported (dev, mask); } -void dma_cache_sync (struct device *dev,void *vaddr,size_t size, +static void mips_dma_cache_sync (struct device *dev,void *vaddr,size_t size,enum dma_data_direction direction) {BUG_ON (direction =DMA_NONE );
@@ -428,8 +428,6 @@ void dma_cache_sync(struct device *dev, void *vaddr, size_t size,__dma_sync_virtual (vaddr, size, direction); } -EXPORT_SYMBOL (dma_cache_sync); -static const struct dma_map_ops mips_default_dma_map_ops = { .alloc = mips_dma_alloc_coherent, .free = mips_dma_free_coherent,
@@ -443,7 +441,8 @@ static const struct dma_map_ops mips_default_dma_map_ops = { .sync_sg_for_cpu = mips_dma_sync_sg_for_cpu, .sync_sg_for_device = mips_dma_sync_sg_for_device, .mapping_error = mips_dma_mapping_error, - .dma_supported = mips_dma_supported + .dma_supported = mips_dma_supported, + .cache_sync = mips_dma_cache_sync, };const struct dma_map_ops *mips_dma_map_ops = &mips_default_dma_map_ops;
arch/mn10300/include/asm/dma-mapping.h +0 -6
@@ -18,10 +18,4 @@ static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus) return &mn10300_dma_ops; } -static inline -void dma_cache_sync (void *vaddr,size_t size, -enum dma_data_direction direction) -{ -} -#endif
arch/nios2/include/asm/dma-mapping.h +0 -9
@@ -17,13 +17,4 @@ static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus) return &nios2_dma_ops; } -/* -* dma_alloc_attrs() always returns non-cacheable memory, so there's no need to -* do any flushing here. -*/ -static inline void dma_cache_sync (struct device *dev,void *vaddr,size_t size, -enum dma_data_direction direction) -{ -} -#endif /* _ASM_NIOS2_DMA_MAPPING_H */
arch/parisc/include/asm/dma-mapping.h +0 -8
@@ -32,14 +32,6 @@ static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus)return hppa_dma_ops; } -static inline void -dma_cache_sync (struct device *dev,void *vaddr,size_t size, -enum dma_data_direction direction) -{ -if (hppa_dma_ops->sync_single_for_cpu) -flush_kernel_dcache_range ((unsigned long )vaddr, size); -} -static inline void *parisc_walk_tree (struct device *dev) {
arch/parisc/kernel/pci-dma.c +8 -0
@@ -572,6 +572,12 @@ static void pa11_dma_sync_sg_for_device(struct device *dev, struct scatterlist *flush_kernel_vmap_range (sg_virt (sg), sg->length); } +static void pa11_dma_cache_sync (struct device *dev,void *vaddr,size_t size, +enum dma_data_direction direction) +{ +flush_kernel_dcache_range ((unsigned long )vaddr, size); +} +const struct dma_map_ops pcxl_dma_ops = { .dma_supported = pa11_dma_supported, .alloc = pa11_dma_alloc,
@@ -584,6 +590,7 @@ const struct dma_map_ops pcxl_dma_ops = { .sync_single_for_device = pa11_dma_sync_single_for_device, .sync_sg_for_cpu = pa11_dma_sync_sg_for_cpu, .sync_sg_for_device = pa11_dma_sync_sg_for_device, + .cache_sync = pa11_dma_cache_sync, }; static void *pcx_dma_alloc(struct device *dev, size_t size,
@@ -620,4 +627,5 @@ const struct dma_map_ops pcx_dma_ops = { .sync_single_for_device = pa11_dma_sync_single_for_device, .sync_sg_for_cpu = pa11_dma_sync_sg_for_cpu, .sync_sg_for_device = pa11_dma_sync_sg_for_device, + .cache_sync = pa11_dma_cache_sync, };
arch/powerpc/include/asm/dma-mapping.h +0 -5
@@ -141,10 +141,5 @@ static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)#define ARCH_HAS_DMA_MMAP_COHERENT -static inline void dma_cache_sync (struct device *dev,void *vaddr,size_t size, -enum dma_data_direction direction) -{ -} -#endif /* __KERNEL__ */ #endif /* _ASM_DMA_MAPPING_H */
arch/s390/include/asm/dma-mapping.h +0 -5
@@ -15,11 +15,6 @@ static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus)return &dma_noop_ops; } -static inline void dma_cache_sync (struct device *dev,void *vaddr,size_t size, -enum dma_data_direction direction) -{ -} -static inline bool dma_capable (struct device *dev,dma_addr_t addr,size_t size) {if (!dev->dma_mask)
arch/sh/include/asm/dma-mapping.h +0 -6
@@ -9,12 +9,6 @@ static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus)return dma_ops; } -static inline void dma_cache_sync (struct device *dev,void *vaddr,size_t size, -enum dma_data_direction dir) -{ -} - -/* arch/sh/mm/consistent.c */ extern void *dma_generic_alloc_coherent (struct device *dev,size_t size,dma_addr_t *dma_addr,gfp_t flag,unsigned long attrs);
arch/sparc/include/asm/dma-mapping.h +0 -8
@@ -5,14 +5,6 @@#include <linux/mm.h> #include <linux/dma-debug.h> -static inline void dma_cache_sync (struct device *dev,void *vaddr,size_t size, -enum dma_data_direction dir) -{ -/* Since dma_{alloc,free}_noncoherent() allocated coherent memory, this -* routine can be a nop. -*/ -} -extern const struct dma_map_ops *dma_ops;extern const struct dma_map_ops pci32_dma_ops;
arch/tile/include/asm/dma-mapping.h +0 -9
@@ -67,13 +67,4 @@ static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)#define HAVE_ARCH_DMA_SET_MASK 1int dma_set_mask (struct device *dev,u64 mask); -/* -* dma_alloc_attrs() always returns non-cacheable memory, so there's no need to -* do any flushing here. -*/ -static inline void dma_cache_sync (struct device *dev,void *vaddr,size_t size, -enum dma_data_direction direction) -{ -} -#endif /* _ASM_TILE_DMA_MAPPING_H */
arch/unicore32/include/asm/dma-mapping.h +0 -5
@@ -45,10 +45,5 @@ static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)static inline void dma_mark_clean (void *addr,size_t size) {} -static inline void dma_cache_sync (struct device *dev,void *vaddr, -size_t size,enum dma_data_direction direction) -{ -} -#endif /* __KERNEL__ */ #endif
arch/x86/include/asm/dma-mapping.h +0 -6
@@ -66,12 +66,6 @@ static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr) }#endif /* CONFIG_X86_DMA_REMAP */ -static inline void -dma_cache_sync (struct device *dev,void *vaddr,size_t size, -enum dma_data_direction dir) -{ -} -static inline unsigned long dma_alloc_coherent_mask (struct device *dev,gfp_t gfp) {
arch/xtensa/include/asm/dma-mapping.h +0 -5
@@ -23,11 +23,6 @@ static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus)return &xtensa_dma_map_ops; } -static inline void dma_cache_sync (struct device *dev,void *vaddr,size_t size, -enum dma_data_direction direction) -{ -} -static inline dma_addr_t phys_to_dma (struct device *dev,phys_addr_t paddr) {return (dma_addr_t )paddr;
include/linux/dma-mapping.h +13 -0
@@ -125,6 +125,8 @@ struct dma_map_ops {void (*sync_sg_for_device)(struct device *dev,struct scatterlist *sg,int nents,enum dma_data_direction dir); +void (*cache_sync)(struct device *dev,void *vaddr,size_t size, +enum dma_data_direction direction);int (*mapping_error)(struct device *dev,dma_addr_t dma_addr);int (*dma_supported)(struct device *dev,u64 mask);#ifdef ARCH_HAS_DMA_GET_REQUIRED_MASK
@@ -435,6 +437,17 @@ dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,#define dma_map_page (d, p, o, s, r) dma_map_page_attrs(d, p, o, s, r, 0)#define dma_unmap_page (d, a, s, r) dma_unmap_page_attrs(d, a, s, r, 0) +static inline void +dma_cache_sync (struct device *dev,void *vaddr,size_t size, +enum dma_data_direction dir) +{ +const struct dma_map_ops *ops =get_dma_ops (dev); + +BUG_ON (!valid_dma_direction (dir)); +if (ops->cache_sync) + ops->cache_sync (dev, vaddr, size, dir); +} +extern int dma_common_mmap (struct device *dev,struct vm_area_struct *vma,void *cpu_addr,dma_addr_t dma_addr,size_t size);
Signature · 1 line
2.11.0
Geert Uytterhoeven
maintainerRe: [PATCH 12/12] dma-mapping: turn dma_cache_sync into a dma_map_ops method
Hi Christoph,
Quoted 2 lines · Christoph Hellwig
After we removed all the dead wood it turns out only two architectures actually implement
dma_cache_syncas a no-op: mips and parisc. Add
s/no-op/real op/
Quoted 2 lines
a
cache_syncmethod to structdma_map_opsand implement it for the mips defualt DMA ops, and the parisc pa11 ops.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Re: [PATCH 04/12] x86: make dma_cache_sync a no-op
In reply to Christoph HellwigQuoted 5 lines · Christoph Hellwig
x86 does not implement
DMA_ATTR_NON_CONSISTENTallocations, so it doesn't make any sense to do any work indma_cache_syncgiven that it must be a no-op whendma_alloc_attrsreturns coherent memory.Signed-off-by Christoph Hellwig <[email protected]
Quoted 20 lines
--- arch/x86/include/asm/dma-mapping.h | 1 - 1 file changed, 1 deletion(-)arch/x86/include/asm/dma-mapping.h +0
-1@@ -70,7 +70,6 @@ static inline void dma_cache_sync(struct device *dev, void *vaddr, size_t size, enum dma_data_direction dir) { -flush_write_buffers (); } static inline unsigned long dma_alloc_coherent_mask(struct device *dev,Signature · 1 line
2.11.0