• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef _ASM_DMA_MAPPING_H
2 #define _ASM_DMA_MAPPING_H
3 
4 #include <asm/scatterlist.h>
5 #include <asm/dma-coherence.h>
6 #include <asm/cache.h>
7 #include <asm-generic/dma-coherent.h>
8 
9 #ifndef CONFIG_SGI_IP27 /* Kludge to fix 2.6.39 build for IP27 */
10 #include <dma-coherence.h>
11 #endif
12 
13 extern struct dma_map_ops *mips_dma_map_ops;
14 
get_dma_ops(struct device * dev)15 static inline struct dma_map_ops *get_dma_ops(struct device *dev)
16 {
17 	if (dev && dev->archdata.dma_ops)
18 		return dev->archdata.dma_ops;
19 	else
20 		return mips_dma_map_ops;
21 }
22 
dma_capable(struct device * dev,dma_addr_t addr,size_t size)23 static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
24 {
25 	if (!dev->dma_mask)
26 		return false;
27 
28 	return addr + size <= *dev->dma_mask;
29 }
30 
dma_mark_clean(void * addr,size_t size)31 static inline void dma_mark_clean(void *addr, size_t size) {}
32 
33 #include <asm-generic/dma-mapping-common.h>
34 
dma_supported(struct device * dev,u64 mask)35 static inline int dma_supported(struct device *dev, u64 mask)
36 {
37 	struct dma_map_ops *ops = get_dma_ops(dev);
38 	return ops->dma_supported(dev, mask);
39 }
40 
dma_mapping_error(struct device * dev,u64 mask)41 static inline int dma_mapping_error(struct device *dev, u64 mask)
42 {
43 	struct dma_map_ops *ops = get_dma_ops(dev);
44 
45 	debug_dma_mapping_error(dev, mask);
46 	return ops->mapping_error(dev, mask);
47 }
48 
49 static inline int
dma_set_mask(struct device * dev,u64 mask)50 dma_set_mask(struct device *dev, u64 mask)
51 {
52 	struct dma_map_ops *ops = get_dma_ops(dev);
53 
54 	if(!dev->dma_mask || !dma_supported(dev, mask))
55 		return -EIO;
56 
57 	if (ops->set_dma_mask)
58 		return ops->set_dma_mask(dev, mask);
59 
60 	*dev->dma_mask = mask;
61 
62 	return 0;
63 }
64 
65 extern void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
66 	       enum dma_data_direction direction);
67 
68 #define dma_alloc_coherent(d,s,h,f)	dma_alloc_attrs(d,s,h,f,NULL)
69 
dma_alloc_attrs(struct device * dev,size_t size,dma_addr_t * dma_handle,gfp_t gfp,struct dma_attrs * attrs)70 static inline void *dma_alloc_attrs(struct device *dev, size_t size,
71 				    dma_addr_t *dma_handle, gfp_t gfp,
72 				    struct dma_attrs *attrs)
73 {
74 	void *ret;
75 	struct dma_map_ops *ops = get_dma_ops(dev);
76 
77 	ret = ops->alloc(dev, size, dma_handle, gfp, attrs);
78 
79 	debug_dma_alloc_coherent(dev, size, *dma_handle, ret);
80 
81 	return ret;
82 }
83 
84 #define dma_free_coherent(d,s,c,h) dma_free_attrs(d,s,c,h,NULL)
85 
dma_free_attrs(struct device * dev,size_t size,void * vaddr,dma_addr_t dma_handle,struct dma_attrs * attrs)86 static inline void dma_free_attrs(struct device *dev, size_t size,
87 				  void *vaddr, dma_addr_t dma_handle,
88 				  struct dma_attrs *attrs)
89 {
90 	struct dma_map_ops *ops = get_dma_ops(dev);
91 
92 	ops->free(dev, size, vaddr, dma_handle, attrs);
93 
94 	debug_dma_free_coherent(dev, size, vaddr, dma_handle);
95 }
96 
97 
98 void *dma_alloc_noncoherent(struct device *dev, size_t size,
99 			   dma_addr_t *dma_handle, gfp_t flag);
100 
101 void dma_free_noncoherent(struct device *dev, size_t size,
102 			 void *vaddr, dma_addr_t dma_handle);
103 
104 #endif /* _ASM_DMA_MAPPING_H */
105