MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / include / asm-arm / dma-mapping.h
blobb8750631dd09dc54567c819c88e42f6333d2bc25
1 #ifndef ASMARM_DMA_MAPPING_H
2 #define ASMARM_DMA_MAPPING_H
4 #ifdef __KERNEL__
6 #include <linux/config.h>
7 #include <linux/mm.h> /* need struct page */
9 #include <asm/scatterlist.h>
12 * DMA-consistent mapping functions. These allocate/free a region of
13 * uncached, unwrite-buffered mapped memory space for use with DMA
14 * devices. This is the "generic" version. The PCI specific version
15 * is in pci.h
17 extern void consistent_sync(void *kaddr, size_t size, int rw);
20 * Return whether the given device DMA address mask can be supported
21 * properly. For example, if your device can only drive the low 24-bits
22 * during bus mastering, then you would pass 0x00ffffff as the mask
23 * to this function.
25 static inline int dma_supported(struct device *dev, u64 mask)
27 return dev->dma_mask && *dev->dma_mask != 0;
30 static inline int dma_set_mask(struct device *dev, u64 dma_mask)
32 if (!dev->dma_mask || !dma_supported(dev, dma_mask))
33 return -EIO;
35 *dev->dma_mask = dma_mask;
37 return 0;
40 static inline int dma_get_cache_alignment(void)
42 return 32;
45 static inline int dma_is_consistent(dma_addr_t handle)
47 return 0;
51 * DMA errors are defined by all-bits-set in the DMA address.
53 static inline int dma_mapping_error(dma_addr_t dma_addr)
55 return dma_addr == ~0;
58 /**
59 * dma_alloc_coherent - allocate consistent memory for DMA
60 * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
61 * @size: required memory size
62 * @handle: bus-specific DMA address
64 * Allocate some uncached, unbuffered memory for a device for
65 * performing DMA. This function allocates pages, and will
66 * return the CPU-viewed address, and sets @handle to be the
67 * device-viewed address.
69 extern void *
70 dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *handle, int gfp);
72 /**
73 * dma_free_coherent - free memory allocated by dma_alloc_coherent
74 * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
75 * @size: size of memory originally requested in dma_alloc_coherent
76 * @cpu_addr: CPU-view address returned from dma_alloc_coherent
77 * @handle: device-view address returned from dma_alloc_coherent
79 * Free (and unmap) a DMA buffer previously allocated by
80 * dma_alloc_coherent().
82 * References to memory and mappings associated with cpu_addr/handle
83 * during and after this call executing are illegal.
85 extern void
86 dma_free_coherent(struct device *dev, size_t size, void *cpu_addr,
87 dma_addr_t handle);
89 /**
90 * dma_alloc_writecombine - allocate writecombining memory for DMA
91 * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
92 * @size: required memory size
93 * @handle: bus-specific DMA address
95 * Allocate some uncached, buffered memory for a device for
96 * performing DMA. This function allocates pages, and will
97 * return the CPU-viewed address, and sets @handle to be the
98 * device-viewed address.
100 extern void *
101 dma_alloc_writecombine(struct device *dev, size_t size, dma_addr_t *handle, int gfp);
103 #define dma_free_writecombine(dev,size,cpu_addr,handle) \
104 dma_free_coherent(dev,size,cpu_addr,handle)
108 * dma_map_single - map a single buffer for streaming DMA
109 * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
110 * @cpu_addr: CPU direct mapped address of buffer
111 * @size: size of buffer to map
112 * @dir: DMA transfer direction
114 * Ensure that any data held in the cache is appropriately discarded
115 * or written back.
117 * The device owns this memory once this call has completed. The CPU
118 * can regain ownership by calling dma_unmap_single() or
119 * dma_sync_single_for_cpu().
121 #ifndef CONFIG_DMABOUNCE
122 static inline dma_addr_t
123 dma_map_single(struct device *dev, void *cpu_addr, size_t size,
124 enum dma_data_direction dir)
126 consistent_sync(cpu_addr, size, dir);
127 return virt_to_dma(dev, (unsigned long)cpu_addr);
129 #else
130 extern dma_addr_t dma_map_single(struct device *,void *, size_t, enum dma_data_direction);
131 #endif
134 * dma_map_page - map a portion of a page for streaming DMA
135 * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
136 * @page: page that buffer resides in
137 * @offset: offset into page for start of buffer
138 * @size: size of buffer to map
139 * @dir: DMA transfer direction
141 * Ensure that any data held in the cache is appropriately discarded
142 * or written back.
144 * The device owns this memory once this call has completed. The CPU
145 * can regain ownership by calling dma_unmap_page() or
146 * dma_sync_single_for_cpu().
148 static inline dma_addr_t
149 dma_map_page(struct device *dev, struct page *page,
150 unsigned long offset, size_t size,
151 enum dma_data_direction dir)
153 return dma_map_single(dev, page_address(page) + offset, size, (int)dir);
157 * dma_unmap_single - unmap a single buffer previously mapped
158 * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
159 * @handle: DMA address of buffer
160 * @size: size of buffer to map
161 * @dir: DMA transfer direction
163 * Unmap a single streaming mode DMA translation. The handle and size
164 * must match what was provided in the previous dma_map_single() call.
165 * All other usages are undefined.
167 * After this call, reads by the CPU to the buffer are guaranteed to see
168 * whatever the device wrote there.
170 #ifndef CONFIG_DMABOUNCE
171 static inline void
172 dma_unmap_single(struct device *dev, dma_addr_t handle, size_t size,
173 enum dma_data_direction dir)
175 /* nothing to do */
177 #else
178 extern void dma_unmap_single(struct device *, dma_addr_t, size_t, enum dma_data_direction);
179 #endif
182 * dma_unmap_page - unmap a buffer previously mapped through dma_map_page()
183 * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
184 * @handle: DMA address of buffer
185 * @size: size of buffer to map
186 * @dir: DMA transfer direction
188 * Unmap a single streaming mode DMA translation. The handle and size
189 * must match what was provided in the previous dma_map_single() call.
190 * All other usages are undefined.
192 * After this call, reads by the CPU to the buffer are guaranteed to see
193 * whatever the device wrote there.
195 static inline void
196 dma_unmap_page(struct device *dev, dma_addr_t handle, size_t size,
197 enum dma_data_direction dir)
199 dma_unmap_single(dev, handle, size, (int)dir);
203 * dma_map_sg - map a set of SG buffers for streaming mode DMA
204 * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
205 * @sg: list of buffers
206 * @nents: number of buffers to map
207 * @dir: DMA transfer direction
209 * Map a set of buffers described by scatterlist in streaming
210 * mode for DMA. This is the scatter-gather version of the
211 * above dma_map_single interface. Here the scatter gather list
212 * elements are each tagged with the appropriate dma address
213 * and length. They are obtained via sg_dma_{address,length}(SG).
215 * NOTE: An implementation may be able to use a smaller number of
216 * DMA address/length pairs than there are SG table elements.
217 * (for example via virtual mapping capabilities)
218 * The routine returns the number of addr/length pairs actually
219 * used, at most nents.
221 * Device ownership issues as mentioned above for dma_map_single are
222 * the same here.
224 #ifndef CONFIG_DMABOUNCE
225 static inline int
226 dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
227 enum dma_data_direction dir)
229 int i;
231 for (i = 0; i < nents; i++, sg++) {
232 char *virt;
234 sg->dma_address = page_to_dma(dev, sg->page) + sg->offset;
235 virt = page_address(sg->page) + sg->offset;
236 consistent_sync(virt, sg->length, dir);
239 return nents;
241 #else
242 extern int dma_map_sg(struct device *, struct scatterlist *, int, enum dma_data_direction);
243 #endif
246 * dma_unmap_sg - unmap a set of SG buffers mapped by dma_map_sg
247 * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
248 * @sg: list of buffers
249 * @nents: number of buffers to map
250 * @dir: DMA transfer direction
252 * Unmap a set of streaming mode DMA translations.
253 * Again, CPU read rules concerning calls here are the same as for
254 * dma_unmap_single() above.
256 #ifndef CONFIG_DMABOUNCE
257 static inline void
258 dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nents,
259 enum dma_data_direction dir)
262 /* nothing to do */
264 #else
265 extern void dma_unmap_sg(struct device *, struct scatterlist *, int, enum dma_data_direction);
266 #endif
270 * dma_sync_single_for_cpu
271 * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
272 * @handle: DMA address of buffer
273 * @size: size of buffer to map
274 * @dir: DMA transfer direction
276 * Make physical memory consistent for a single streaming mode DMA
277 * translation after a transfer.
279 * If you perform a dma_map_single() but wish to interrogate the
280 * buffer using the cpu, yet do not wish to teardown the PCI dma
281 * mapping, you must call this function before doing so. At the
282 * next point you give the PCI dma address back to the card, you
283 * must first the perform a dma_sync_for_device, and then the
284 * device again owns the buffer.
286 #ifndef CONFIG_DMABOUNCE
287 static inline void
288 dma_sync_single_for_cpu(struct device *dev, dma_addr_t handle, size_t size,
289 enum dma_data_direction dir)
291 consistent_sync((void *)dma_to_virt(dev, handle), size, dir);
294 static inline void
295 dma_sync_single_for_device(struct device *dev, dma_addr_t handle, size_t size,
296 enum dma_data_direction dir)
298 consistent_sync((void *)dma_to_virt(dev, handle), size, dir);
300 #else
301 extern void dma_sync_single_for_cpu(struct device*, dma_addr_t, size_t, enum dma_data_direction);
302 extern void dma_sync_single_for_device(struct device*, dma_addr_t, size_t, enum dma_data_direction);
303 #endif
307 * dma_sync_sg_for_cpu
308 * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
309 * @sg: list of buffers
310 * @nents: number of buffers to map
311 * @dir: DMA transfer direction
313 * Make physical memory consistent for a set of streaming
314 * mode DMA translations after a transfer.
316 * The same as dma_sync_single_for_* but for a scatter-gather list,
317 * same rules and usage.
319 #ifndef CONFIG_DMABOUNCE
320 static inline void
321 dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, int nents,
322 enum dma_data_direction dir)
324 int i;
326 for (i = 0; i < nents; i++, sg++) {
327 char *virt = page_address(sg->page) + sg->offset;
328 consistent_sync(virt, sg->length, dir);
332 static inline void
333 dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, int nents,
334 enum dma_data_direction dir)
336 int i;
338 for (i = 0; i < nents; i++, sg++) {
339 char *virt = page_address(sg->page) + sg->offset;
340 consistent_sync(virt, sg->length, dir);
343 #else
344 extern void dma_sync_sg_for_cpu(struct device*, struct scatterlist*, int, enum dma_data_direction);
345 extern void dma_sync_sg_for_device(struct device*, struct scatterlist*, int, enum dma_data_direction);
346 #endif
348 #ifdef CONFIG_DMABOUNCE
350 * For SA-1111, IXP425, and ADI systems the dma-mapping functions are "magic"
351 * and utilize bounce buffers as needed to work around limited DMA windows.
353 * On the SA-1111, a bug limits DMA to only certain regions of RAM.
354 * On the IXP425, the PCI inbound window is 64MB (256MB total RAM)
355 * On some ADI engineering sytems, PCI inbound window is 32MB (12MB total RAM)
357 * The following are helper functions used by the dmabounce subystem
362 * dmabounce_register_dev
364 * @dev: valid struct device pointer
365 * @small_buf_size: size of buffers to use with small buffer pool
366 * @large_buf_size: size of buffers to use with large buffer pool (can be 0)
368 * This function should be called by low-level platform code to register
369 * a device as requireing DMA buffer bouncing. The function will allocate
370 * appropriate DMA pools for the device.
373 extern int dmabounce_register_dev(struct device *, unsigned long, unsigned long);
376 * dmabounce_unregister_dev
378 * @dev: valid struct device pointer
380 * This function should be called by low-level platform code when device
381 * that was previously registered with dmabounce_register_dev is removed
382 * from the system.
385 extern void dmabounce_unregister_dev(struct device *);
388 * dma_needs_bounce
390 * @dev: valid struct device pointer
391 * @dma_handle: dma_handle of unbounced buffer
392 * @size: size of region being mapped
394 * Platforms that utilize the dmabounce mechanism must implement
395 * this function.
397 * The dmabounce routines call this function whenever a dma-mapping
398 * is requested to determine whether a given buffer needs to be bounced
399 * or not. The function must return 0 if the the buffer is OK for
400 * DMA access and 1 if the buffer needs to be bounced.
403 extern int dma_needs_bounce(struct device*, dma_addr_t, size_t);
404 #endif /* CONFIG_DMABOUNCE */
406 #endif /* __KERNEL__ */
407 #endif