1 #ifndef _ASM_DMA_MAPPING_H
2 #define _ASM_DMA_MAPPING_H
3 
4 #include <asm/scatterlist.h>
5 #include <asm/cache.h>
6 
7 void *dma_alloc_noncoherent(struct device *dev, size_t size,
8 			   dma_addr_t *dma_handle, gfp_t flag);
9 
10 void dma_free_noncoherent(struct device *dev, size_t size,
11 			 void *vaddr, dma_addr_t dma_handle);
12 
13 void *dma_alloc_coherent(struct device *dev, size_t size,
14 			   dma_addr_t *dma_handle, gfp_t flag);
15 
16 void dma_free_coherent(struct device *dev, size_t size,
17 			 void *vaddr, dma_addr_t dma_handle);
18 
19 extern dma_addr_t dma_map_single(struct device *dev, void *ptr, size_t size,
20 	enum dma_data_direction direction);
21 extern void dma_unmap_single(struct device *dev, dma_addr_t dma_addr,
22 	size_t size, enum dma_data_direction direction);
23 extern int dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
24 	enum dma_data_direction direction);
25 extern dma_addr_t dma_map_page(struct device *dev, struct page *page,
26 	unsigned long offset, size_t size, enum dma_data_direction direction);
27 
28 static inline void dma_unmap_page(struct device *dev, dma_addr_t dma_address,
29 	size_t size, enum dma_data_direction direction)
30 {
31 	dma_unmap_single(dev, dma_address, size, direction);
32 }
33 
34 extern void dma_unmap_sg(struct device *dev, struct scatterlist *sg,
35 	int nhwentries, enum dma_data_direction direction);
36 extern void dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle,
37 	size_t size, enum dma_data_direction direction);
38 extern void dma_sync_single_for_device(struct device *dev,
39 	dma_addr_t dma_handle, size_t size, enum dma_data_direction direction);
40 extern void dma_sync_single_range_for_cpu(struct device *dev,
41 	dma_addr_t dma_handle, unsigned long offset, size_t size,
42 	enum dma_data_direction direction);
43 extern void dma_sync_single_range_for_device(struct device *dev,
44 	dma_addr_t dma_handle, unsigned long offset, size_t size,
45 	enum dma_data_direction direction);
46 extern void dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
47 	int nelems, enum dma_data_direction direction);
48 extern void dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
49 	int nelems, enum dma_data_direction direction);
50 extern int dma_mapping_error(struct device *dev, dma_addr_t dma_addr);
51 extern int dma_supported(struct device *dev, u64 mask);
52 
53 static inline int
54 dma_set_mask(struct device *dev, u64 mask)
55 {
56 	if(!dev->dma_mask || !dma_supported(dev, mask))
57 		return -EIO;
58 
59 	*dev->dma_mask = mask;
60 
61 	return 0;
62 }
63 
64 static inline int
65 dma_get_cache_alignment(void)
66 {
67 	/* XXX Largest on any MIPS */
68 	return 128;
69 }
70 
71 extern int dma_is_consistent(struct device *dev, dma_addr_t dma_addr);
72 
73 extern void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
74 	       enum dma_data_direction direction);
75 
76 #if 0
77 #define ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY
78 
79 extern int dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr,
80 	dma_addr_t device_addr, size_t size, int flags);
81 extern void dma_release_declared_memory(struct device *dev);
82 extern void * dma_mark_declared_memory_occupied(struct device *dev,
83 	dma_addr_t device_addr, size_t size);
84 #endif
85 
86 #endif /* _ASM_DMA_MAPPING_H */
87