Adding support for MOXA ART SoC. Testing port of linux-2.6.32.60-moxart.
[linux-3.6.7-moxart.git] / arch / sh / include / asm / dma-mapping.h
blob8bd965e00a159c2ae6f45af71b8804da23f84c98
1 #ifndef __ASM_SH_DMA_MAPPING_H
2 #define __ASM_SH_DMA_MAPPING_H
4 extern struct dma_map_ops *dma_ops;
5 extern void no_iommu_init(void);
7 static inline struct dma_map_ops *get_dma_ops(struct device *dev)
9 return dma_ops;
12 #include <asm-generic/dma-coherent.h>
13 #include <asm-generic/dma-mapping-common.h>
15 static inline int dma_supported(struct device *dev, u64 mask)
17 struct dma_map_ops *ops = get_dma_ops(dev);
19 if (ops->dma_supported)
20 return ops->dma_supported(dev, mask);
22 return 1;
25 static inline int dma_set_mask(struct device *dev, u64 mask)
27 struct dma_map_ops *ops = get_dma_ops(dev);
29 if (!dev->dma_mask || !dma_supported(dev, mask))
30 return -EIO;
31 if (ops->set_dma_mask)
32 return ops->set_dma_mask(dev, mask);
34 *dev->dma_mask = mask;
36 return 0;
39 void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
40 enum dma_data_direction dir);
42 #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
43 #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
45 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
47 struct dma_map_ops *ops = get_dma_ops(dev);
49 if (ops->mapping_error)
50 return ops->mapping_error(dev, dma_addr);
52 return dma_addr == 0;
55 #define dma_alloc_coherent(d,s,h,f) dma_alloc_attrs(d,s,h,f,NULL)
57 static inline void *dma_alloc_attrs(struct device *dev, size_t size,
58 dma_addr_t *dma_handle, gfp_t gfp,
59 struct dma_attrs *attrs)
61 struct dma_map_ops *ops = get_dma_ops(dev);
62 void *memory;
64 if (dma_alloc_from_coherent(dev, size, dma_handle, &memory))
65 return memory;
66 if (!ops->alloc)
67 return NULL;
69 memory = ops->alloc(dev, size, dma_handle, gfp, attrs);
70 debug_dma_alloc_coherent(dev, size, *dma_handle, memory);
72 return memory;
75 #define dma_free_coherent(d,s,c,h) dma_free_attrs(d,s,c,h,NULL)
77 static inline void dma_free_attrs(struct device *dev, size_t size,
78 void *vaddr, dma_addr_t dma_handle,
79 struct dma_attrs *attrs)
81 struct dma_map_ops *ops = get_dma_ops(dev);
83 if (dma_release_from_coherent(dev, get_order(size), vaddr))
84 return;
86 debug_dma_free_coherent(dev, size, vaddr, dma_handle);
87 if (ops->free)
88 ops->free(dev, size, vaddr, dma_handle, attrs);
91 /* arch/sh/mm/consistent.c */
92 extern void *dma_generic_alloc_coherent(struct device *dev, size_t size,
93 dma_addr_t *dma_addr, gfp_t flag,
94 struct dma_attrs *attrs);
95 extern void dma_generic_free_coherent(struct device *dev, size_t size,
96 void *vaddr, dma_addr_t dma_handle,
97 struct dma_attrs *attrs);
99 #endif /* __ASM_SH_DMA_MAPPING_H */