Merge branch 'imx-for-2.6.38' of git://git.pengutronix.de/git/ukl/linux-2.6 into...
[pandora-kernel.git] / arch / mips / include / asm / dma-mapping.h
1 #ifndef _ASM_DMA_MAPPING_H
2 #define _ASM_DMA_MAPPING_H
3
4 #include <asm/scatterlist.h>
5 #include <asm/cache.h>
6 #include <asm-generic/dma-coherent.h>
7
8 #include <dma-coherence.h>
9
10 extern struct dma_map_ops *mips_dma_map_ops;
11
12 static inline struct dma_map_ops *get_dma_ops(struct device *dev)
13 {
14         if (dev && dev->archdata.dma_ops)
15                 return dev->archdata.dma_ops;
16         else
17                 return mips_dma_map_ops;
18 }
19
20 static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
21 {
22         if (!dev->dma_mask)
23                 return 0;
24
25         return addr + size <= *dev->dma_mask;
26 }
27
28 static inline void dma_mark_clean(void *addr, size_t size) {}
29
30 #include <asm-generic/dma-mapping-common.h>
31
32 static inline int dma_supported(struct device *dev, u64 mask)
33 {
34         struct dma_map_ops *ops = get_dma_ops(dev);
35         return ops->dma_supported(dev, mask);
36 }
37
38 static inline int dma_mapping_error(struct device *dev, u64 mask)
39 {
40         struct dma_map_ops *ops = get_dma_ops(dev);
41         return ops->mapping_error(dev, mask);
42 }
43
44 static inline int
45 dma_set_mask(struct device *dev, u64 mask)
46 {
47         if(!dev->dma_mask || !dma_supported(dev, mask))
48                 return -EIO;
49
50         *dev->dma_mask = mask;
51
52         return 0;
53 }
54
55 extern void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
56                enum dma_data_direction direction);
57
58 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
59                                        dma_addr_t *dma_handle, gfp_t gfp)
60 {
61         void *ret;
62         struct dma_map_ops *ops = get_dma_ops(dev);
63
64         ret = ops->alloc_coherent(dev, size, dma_handle, gfp);
65
66         debug_dma_alloc_coherent(dev, size, *dma_handle, ret);
67
68         return ret;
69 }
70
71 static inline void dma_free_coherent(struct device *dev, size_t size,
72                                      void *vaddr, dma_addr_t dma_handle)
73 {
74         struct dma_map_ops *ops = get_dma_ops(dev);
75
76         ops->free_coherent(dev, size, vaddr, dma_handle);
77
78         debug_dma_free_coherent(dev, size, vaddr, dma_handle);
79 }
80
81
82 void *dma_alloc_noncoherent(struct device *dev, size_t size,
83                            dma_addr_t *dma_handle, gfp_t flag);
84
85 void dma_free_noncoherent(struct device *dev, size_t size,
86                          void *vaddr, dma_addr_t dma_handle);
87
88 #endif /* _ASM_DMA_MAPPING_H */