Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

MIPS: Add DMA declare coherent memory support

The ohci-sm501 driver requires dma_declare_coherent_memory(). It is used
by the driver's local memory allocation with dma_alloc_coherent().

Tested on TANBAC TB0287(VR4131 + SM501).

[Ralf: Fixed reject in dma-default.c and removed the entire #if 0'ed block
in dma-mapping.h instead of just the #if 0.]

Signed-off-by: Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>

authored by

Yoichi Yuasa and committed by
Ralf Baechle
f8ac0425 da0bac33

+9 -10
+1
arch/mips/Kconfig
··· 1 1 config MIPS 2 2 bool 3 3 default y 4 + select HAVE_GENERIC_DMA_COHERENT 4 5 select HAVE_IDE 5 6 select HAVE_OPROFILE 6 7 select HAVE_ARCH_KGDB
+1 -10
arch/mips/include/asm/dma-mapping.h
··· 3 3 4 4 #include <asm/scatterlist.h> 5 5 #include <asm/cache.h> 6 + #include <asm-generic/dma-coherent.h> 6 7 7 8 void *dma_alloc_noncoherent(struct device *dev, size_t size, 8 9 dma_addr_t *dma_handle, gfp_t flag); ··· 73 72 74 73 extern void dma_cache_sync(struct device *dev, void *vaddr, size_t size, 75 74 enum dma_data_direction direction); 76 - 77 - #if 0 78 - #define ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY 79 - 80 - extern int dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr, 81 - dma_addr_t device_addr, size_t size, int flags); 82 - extern void dma_release_declared_memory(struct device *dev); 83 - extern void * dma_mark_declared_memory_occupied(struct device *dev, 84 - dma_addr_t device_addr, size_t size); 85 - #endif 86 75 87 76 #endif /* _ASM_DMA_MAPPING_H */
+7
arch/mips/mm/dma-default.c
··· 90 90 { 91 91 void *ret; 92 92 93 + if (dma_alloc_from_coherent(dev, size, dma_handle, &ret)) 94 + return ret; 95 + 93 96 gfp = massage_gfp_flags(dev, gfp); 94 97 95 98 ret = (void *) __get_free_pages(gfp, get_order(size)); ··· 125 122 dma_addr_t dma_handle) 126 123 { 127 124 unsigned long addr = (unsigned long) vaddr; 125 + int order = get_order(size); 126 + 127 + if (dma_release_from_coherent(dev, order, vaddr)) 128 + return; 128 129 129 130 plat_unmap_dma_mem(dev, dma_handle, size, DMA_BIDIRECTIONAL); 130 131