blob: 664ba53dc32a79fed9b7ed433e88a8b3a56e5d45 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _ASM_DMA_MAPPING_H
2#define _ASM_DMA_MAPPING_H
3
4#include <asm/scatterlist.h>
5#include <asm/cache.h>
Yoichi Yuasaf8ac04252009-06-04 00:16:04 +09006#include <asm-generic/dma-coherent.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007
8void *dma_alloc_noncoherent(struct device *dev, size_t size,
Al Viro185a8ff2005-10-21 03:21:23 -04009 dma_addr_t *dma_handle, gfp_t flag);
Linus Torvalds1da177e2005-04-16 15:20:36 -070010
11void dma_free_noncoherent(struct device *dev, size_t size,
12 void *vaddr, dma_addr_t dma_handle);
13
14void *dma_alloc_coherent(struct device *dev, size_t size,
Al Viro185a8ff2005-10-21 03:21:23 -040015 dma_addr_t *dma_handle, gfp_t flag);
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
17void dma_free_coherent(struct device *dev, size_t size,
18 void *vaddr, dma_addr_t dma_handle);
19
20extern dma_addr_t dma_map_single(struct device *dev, void *ptr, size_t size,
21 enum dma_data_direction direction);
22extern void dma_unmap_single(struct device *dev, dma_addr_t dma_addr,
23 size_t size, enum dma_data_direction direction);
24extern int dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
25 enum dma_data_direction direction);
26extern dma_addr_t dma_map_page(struct device *dev, struct page *page,
27 unsigned long offset, size_t size, enum dma_data_direction direction);
Atsushi Nemoto4f29c052009-01-23 00:42:11 +090028
29static inline void dma_unmap_page(struct device *dev, dma_addr_t dma_address,
30 size_t size, enum dma_data_direction direction)
31{
32 dma_unmap_single(dev, dma_address, size, direction);
33}
34
Linus Torvalds1da177e2005-04-16 15:20:36 -070035extern void dma_unmap_sg(struct device *dev, struct scatterlist *sg,
36 int nhwentries, enum dma_data_direction direction);
37extern void dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle,
38 size_t size, enum dma_data_direction direction);
39extern void dma_sync_single_for_device(struct device *dev,
40 dma_addr_t dma_handle, size_t size, enum dma_data_direction direction);
41extern void dma_sync_single_range_for_cpu(struct device *dev,
42 dma_addr_t dma_handle, unsigned long offset, size_t size,
43 enum dma_data_direction direction);
44extern void dma_sync_single_range_for_device(struct device *dev,
45 dma_addr_t dma_handle, unsigned long offset, size_t size,
46 enum dma_data_direction direction);
47extern void dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
48 int nelems, enum dma_data_direction direction);
49extern void dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
50 int nelems, enum dma_data_direction direction);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -070051extern int dma_mapping_error(struct device *dev, dma_addr_t dma_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070052extern int dma_supported(struct device *dev, u64 mask);
53
54static inline int
55dma_set_mask(struct device *dev, u64 mask)
56{
57 if(!dev->dma_mask || !dma_supported(dev, mask))
58 return -EIO;
59
60 *dev->dma_mask = mask;
61
62 return 0;
63}
64
65static inline int
66dma_get_cache_alignment(void)
67{
68 /* XXX Largest on any MIPS */
69 return 128;
70}
71
Ralf Baechlef67637e2006-12-06 20:38:54 -080072extern int dma_is_consistent(struct device *dev, dma_addr_t dma_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
Ralf Baechled3fa72e2006-12-06 20:38:56 -080074extern void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 enum dma_data_direction direction);
76
Linus Torvalds1da177e2005-04-16 15:20:36 -070077#endif /* _ASM_DMA_MAPPING_H */