Linux 4.2.2
[linux/fpc-iii.git] / arch / xtensa / include / asm / dma-mapping.h
blob1f5f6dc097365ab4f4be0a00a481859dc29e4256
1 /*
2 * include/asm-xtensa/dma-mapping.h
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details.
8 * Copyright (C) 2003 - 2005 Tensilica Inc.
9 */
11 #ifndef _XTENSA_DMA_MAPPING_H
12 #define _XTENSA_DMA_MAPPING_H
14 #include <asm/cache.h>
15 #include <asm/io.h>
16 #include <linux/mm.h>
17 #include <linux/scatterlist.h>
19 #define DMA_ERROR_CODE (~(dma_addr_t)0x0)
22 * DMA-consistent mapping functions.
25 extern void *consistent_alloc(int, size_t, dma_addr_t, unsigned long);
26 extern void consistent_free(void*, size_t, dma_addr_t);
27 extern void consistent_sync(void*, size_t, int);
29 #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
30 #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
32 void *dma_alloc_coherent(struct device *dev, size_t size,
33 dma_addr_t *dma_handle, gfp_t flag);
35 void dma_free_coherent(struct device *dev, size_t size,
36 void *vaddr, dma_addr_t dma_handle);
38 static inline dma_addr_t
39 dma_map_single(struct device *dev, void *ptr, size_t size,
40 enum dma_data_direction direction)
42 BUG_ON(direction == DMA_NONE);
43 consistent_sync(ptr, size, direction);
44 return virt_to_phys(ptr);
47 static inline void
48 dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
49 enum dma_data_direction direction)
51 BUG_ON(direction == DMA_NONE);
54 static inline int
55 dma_map_sg(struct device *dev, struct scatterlist *sglist, int nents,
56 enum dma_data_direction direction)
58 int i;
59 struct scatterlist *sg;
61 BUG_ON(direction == DMA_NONE);
63 for_each_sg(sglist, sg, nents, i) {
64 BUG_ON(!sg_page(sg));
66 sg->dma_address = sg_phys(sg);
67 consistent_sync(sg_virt(sg), sg->length, direction);
70 return nents;
73 static inline dma_addr_t
74 dma_map_page(struct device *dev, struct page *page, unsigned long offset,
75 size_t size, enum dma_data_direction direction)
77 BUG_ON(direction == DMA_NONE);
78 return (dma_addr_t)(page_to_pfn(page)) * PAGE_SIZE + offset;
81 static inline void
82 dma_unmap_page(struct device *dev, dma_addr_t dma_address, size_t size,
83 enum dma_data_direction direction)
85 BUG_ON(direction == DMA_NONE);
89 static inline void
90 dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nhwentries,
91 enum dma_data_direction direction)
93 BUG_ON(direction == DMA_NONE);
96 static inline void
97 dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle, size_t size,
98 enum dma_data_direction direction)
100 consistent_sync((void *)bus_to_virt(dma_handle), size, direction);
103 static inline void
104 dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle,
105 size_t size, enum dma_data_direction direction)
107 consistent_sync((void *)bus_to_virt(dma_handle), size, direction);
110 static inline void
111 dma_sync_single_range_for_cpu(struct device *dev, dma_addr_t dma_handle,
112 unsigned long offset, size_t size,
113 enum dma_data_direction direction)
116 consistent_sync((void *)bus_to_virt(dma_handle)+offset,size,direction);
119 static inline void
120 dma_sync_single_range_for_device(struct device *dev, dma_addr_t dma_handle,
121 unsigned long offset, size_t size,
122 enum dma_data_direction direction)
125 consistent_sync((void *)bus_to_virt(dma_handle)+offset,size,direction);
127 static inline void
128 dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sglist, int nelems,
129 enum dma_data_direction dir)
131 int i;
132 struct scatterlist *sg;
134 for_each_sg(sglist, sg, nelems, i)
135 consistent_sync(sg_virt(sg), sg->length, dir);
138 static inline void
139 dma_sync_sg_for_device(struct device *dev, struct scatterlist *sglist,
140 int nelems, enum dma_data_direction dir)
142 int i;
143 struct scatterlist *sg;
145 for_each_sg(sglist, sg, nelems, i)
146 consistent_sync(sg_virt(sg), sg->length, dir);
148 static inline int
149 dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
151 return 0;
154 static inline int
155 dma_supported(struct device *dev, u64 mask)
157 return 1;
160 static inline int
161 dma_set_mask(struct device *dev, u64 mask)
163 if(!dev->dma_mask || !dma_supported(dev, mask))
164 return -EIO;
166 *dev->dma_mask = mask;
168 return 0;
171 static inline void
172 dma_cache_sync(struct device *dev, void *vaddr, size_t size,
173 enum dma_data_direction direction)
175 consistent_sync(vaddr, size, direction);
178 /* Not supported for now */
179 static inline int dma_mmap_coherent(struct device *dev,
180 struct vm_area_struct *vma, void *cpu_addr,
181 dma_addr_t dma_addr, size_t size)
183 return -EINVAL;
186 static inline int dma_get_sgtable(struct device *dev, struct sg_table *sgt,
187 void *cpu_addr, dma_addr_t dma_addr,
188 size_t size)
190 return -EINVAL;
193 static inline void *dma_alloc_attrs(struct device *dev, size_t size,
194 dma_addr_t *dma_handle, gfp_t flag,
195 struct dma_attrs *attrs)
197 return NULL;
200 static inline void dma_free_attrs(struct device *dev, size_t size,
201 void *vaddr, dma_addr_t dma_handle,
202 struct dma_attrs *attrs)
206 #endif /* _XTENSA_DMA_MAPPING_H */