dma-mapping.h revision 4565f0170dfc849b3629c27d769db800467baa62
1#ifndef ___ASM_SPARC_DMA_MAPPING_H 2#define ___ASM_SPARC_DMA_MAPPING_H 3 4#include <linux/scatterlist.h> 5#include <linux/mm.h> 6#include <linux/dma-debug.h> 7 8#define DMA_ERROR_CODE (~(dma_addr_t)0x0) 9 10extern int dma_supported(struct device *dev, u64 mask); 11 12#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f) 13#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h) 14#define dma_is_consistent(d, h) (1) 15 16extern struct dma_map_ops *dma_ops, pci32_dma_ops; 17extern struct bus_type pci_bus_type; 18 19static inline struct dma_map_ops *get_dma_ops(struct device *dev) 20{ 21#if defined(CONFIG_SPARC32) && defined(CONFIG_PCI) 22 if (dev->bus == &pci_bus_type) 23 return &pci32_dma_ops; 24#endif 25 return dma_ops; 26} 27 28#include <asm-generic/dma-mapping-common.h> 29 30static inline void *dma_alloc_coherent(struct device *dev, size_t size, 31 dma_addr_t *dma_handle, gfp_t flag) 32{ 33 struct dma_map_ops *ops = get_dma_ops(dev); 34 void *cpu_addr; 35 36 cpu_addr = ops->alloc_coherent(dev, size, dma_handle, flag); 37 debug_dma_alloc_coherent(dev, size, *dma_handle, cpu_addr); 38 return cpu_addr; 39} 40 41static inline void dma_free_coherent(struct device *dev, size_t size, 42 void *cpu_addr, dma_addr_t dma_handle) 43{ 44 struct dma_map_ops *ops = get_dma_ops(dev); 45 46 debug_dma_free_coherent(dev, size, cpu_addr, dma_handle); 47 ops->free_coherent(dev, size, cpu_addr, dma_handle); 48} 49 50static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr) 51{ 52 return (dma_addr == DMA_ERROR_CODE); 53} 54 55static inline int dma_set_mask(struct device *dev, u64 mask) 56{ 57#ifdef CONFIG_PCI 58 if (dev->bus == &pci_bus_type) { 59 if (!dev->dma_mask || !dma_supported(dev, mask)) 60 return -EINVAL; 61 *dev->dma_mask = mask; 62 return 0; 63 } 64#endif 65 return -EINVAL; 66} 67 68#endif 69