Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | #ifndef _ASM_DMA_MAPPING_H |
2 | #define _ASM_DMA_MAPPING_H | |
3 | ||
4 | #include <asm/scatterlist.h> | |
5 | #include <asm/cache.h> | |
f8ac0425 | 6 | #include <asm-generic/dma-coherent.h> |
1da177e4 | 7 | |
48e1fd5a | 8 | #include <dma-coherence.h> |
1da177e4 | 9 | |
48e1fd5a | 10 | extern struct dma_map_ops *mips_dma_map_ops; |
1da177e4 | 11 | |
48e1fd5a DD |
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 | } | |
1da177e4 | 19 | |
48e1fd5a DD |
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; | |
1da177e4 | 24 | |
48e1fd5a DD |
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) | |
4f29c057 | 33 | { |
48e1fd5a DD |
34 | struct dma_map_ops *ops = get_dma_ops(dev); |
35 | return ops->dma_supported(dev, mask); | |
4f29c057 AN |
36 | } |
37 | ||
48e1fd5a DD |
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 | } | |
1da177e4 LT |
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 | ||
d3fa72e4 | 55 | extern void dma_cache_sync(struct device *dev, void *vaddr, size_t size, |
1da177e4 LT |
56 | enum dma_data_direction direction); |
57 | ||
48e1fd5a DD |
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 | ||
1da177e4 | 88 | #endif /* _ASM_DMA_MAPPING_H */ |