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
8 * Copyright (C) 2003 - 2005 Tensilica Inc.
11 #ifndef _XTENSA_DMA_MAPPING_H
12 #define _XTENSA_DMA_MAPPING_H
14 #include <asm/cache.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
);
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
);
55 dma_map_sg(struct device
*dev
, struct scatterlist
*sglist
, int nents
,
56 enum dma_data_direction direction
)
59 struct scatterlist
*sg
;
61 BUG_ON(direction
== DMA_NONE
);
63 for_each_sg(sglist
, sg
, nents
, i
) {
66 sg
->dma_address
= sg_phys(sg
);
67 consistent_sync(sg_virt(sg
), sg
->length
, direction
);
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
;
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
);
90 dma_unmap_sg(struct device
*dev
, struct scatterlist
*sg
, int nhwentries
,
91 enum dma_data_direction direction
)
93 BUG_ON(direction
== DMA_NONE
);
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
);
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
);
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
);
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
);
128 dma_sync_sg_for_cpu(struct device
*dev
, struct scatterlist
*sglist
, int nelems
,
129 enum dma_data_direction dir
)
132 struct scatterlist
*sg
;
134 for_each_sg(sglist
, sg
, nelems
, i
)
135 consistent_sync(sg_virt(sg
), sg
->length
, dir
);
139 dma_sync_sg_for_device(struct device
*dev
, struct scatterlist
*sglist
,
140 int nelems
, enum dma_data_direction dir
)
143 struct scatterlist
*sg
;
145 for_each_sg(sglist
, sg
, nelems
, i
)
146 consistent_sync(sg_virt(sg
), sg
->length
, dir
);
149 dma_mapping_error(struct device
*dev
, dma_addr_t dma_addr
)
155 dma_supported(struct device
*dev
, u64 mask
)
161 dma_set_mask(struct device
*dev
, u64 mask
)
163 if(!dev
->dma_mask
|| !dma_supported(dev
, mask
))
166 *dev
->dma_mask
= mask
;
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
)
186 static inline int dma_get_sgtable(struct device
*dev
, struct sg_table
*sgt
,
187 void *cpu_addr
, dma_addr_t dma_addr
,
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
)
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 */