1 #ifndef ___ASM_SPARC_DMA_MAPPING_H
2 #define ___ASM_SPARC_DMA_MAPPING_H
4 #include <linux/scatterlist.h>
6 #include <linux/dma-debug.h>
8 #define DMA_ERROR_CODE (~(dma_addr_t)0x0)
10 int dma_supported(struct device *dev, u64 mask);
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)
15 static inline void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
16 enum dma_data_direction dir)
18 /* Since dma_{alloc,free}_noncoherent() allocated coherent memory, this
19 * routine can be a nop.
23 extern struct dma_map_ops *dma_ops;
24 extern struct dma_map_ops *leon_dma_ops;
25 extern struct dma_map_ops pci32_dma_ops;
27 extern struct bus_type pci_bus_type;
29 static inline struct dma_map_ops *get_dma_ops(struct device *dev)
31 #ifdef CONFIG_SPARC_LEON
32 if (sparc_cpu_model == sparc_leon)
35 #if defined(CONFIG_SPARC32) && defined(CONFIG_PCI)
36 if (dev->bus == &pci_bus_type)
37 return &pci32_dma_ops;
42 #include <asm-generic/dma-mapping-common.h>
44 #define dma_alloc_coherent(d,s,h,f) dma_alloc_attrs(d,s,h,f,NULL)
46 static inline void *dma_alloc_attrs(struct device *dev, size_t size,
47 dma_addr_t *dma_handle, gfp_t flag,
48 struct dma_attrs *attrs)
50 struct dma_map_ops *ops = get_dma_ops(dev);
53 cpu_addr = ops->alloc(dev, size, dma_handle, flag, attrs);
54 debug_dma_alloc_coherent(dev, size, *dma_handle, cpu_addr);
58 #define dma_free_coherent(d,s,c,h) dma_free_attrs(d,s,c,h,NULL)
60 static inline void dma_free_attrs(struct device *dev, size_t size,
61 void *cpu_addr, dma_addr_t dma_handle,
62 struct dma_attrs *attrs)
64 struct dma_map_ops *ops = get_dma_ops(dev);
66 debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);
67 ops->free(dev, size, cpu_addr, dma_handle, attrs);
70 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
72 debug_dma_mapping_error(dev, dma_addr);
73 return (dma_addr == DMA_ERROR_CODE);
76 static inline int dma_set_mask(struct device *dev, u64 mask)
79 if (dev->bus == &pci_bus_type) {
80 if (!dev->dma_mask || !dma_supported(dev, mask))
82 *dev->dma_mask = mask;