1 #ifndef _LINUX_DMA_MAPPING_H
2 #define _LINUX_DMA_MAPPING_H
4 #include <linux/sizes.h>
5 #include <linux/string.h>
6 #include <linux/device.h>
8 #include <linux/dma-debug.h>
9 #include <linux/dma-direction.h>
10 #include <linux/scatterlist.h>
11 #include <linux/kmemcheck.h>
12 #include <linux/bug.h>
15 * List of possible attributes associated with a DMA mapping. The semantics
16 * of each attribute should be defined in Documentation/DMA-attributes.txt.
18 * DMA_ATTR_WRITE_BARRIER: DMA to a memory region with this attribute
19 * forces all pending DMA writes to complete.
21 #define DMA_ATTR_WRITE_BARRIER (1UL << 0)
23 * DMA_ATTR_WEAK_ORDERING: Specifies that reads and writes to the mapping
24 * may be weakly ordered, that is that reads and writes may pass each other.
26 #define DMA_ATTR_WEAK_ORDERING (1UL << 1)
28 * DMA_ATTR_WRITE_COMBINE: Specifies that writes to the mapping may be
29 * buffered to improve performance.
31 #define DMA_ATTR_WRITE_COMBINE (1UL << 2)
33 * DMA_ATTR_NON_CONSISTENT: Lets the platform to choose to return either
34 * consistent or non-consistent memory as it sees fit.
36 #define DMA_ATTR_NON_CONSISTENT (1UL << 3)
38 * DMA_ATTR_NO_KERNEL_MAPPING: Lets the platform to avoid creating a kernel
39 * virtual mapping for the allocated buffer.
41 #define DMA_ATTR_NO_KERNEL_MAPPING (1UL << 4)
43 * DMA_ATTR_SKIP_CPU_SYNC: Allows platform code to skip synchronization of
44 * the CPU cache for the given buffer assuming that it has been already
45 * transferred to 'device' domain.
47 #define DMA_ATTR_SKIP_CPU_SYNC (1UL << 5)
49 * DMA_ATTR_FORCE_CONTIGUOUS: Forces contiguous allocation of the buffer
52 #define DMA_ATTR_FORCE_CONTIGUOUS (1UL << 6)
54 * DMA_ATTR_ALLOC_SINGLE_PAGES: This is a hint to the DMA-mapping subsystem
55 * that it's probably not worth the time to try to allocate memory to in a way
56 * that gives better TLB efficiency.
58 #define DMA_ATTR_ALLOC_SINGLE_PAGES (1UL << 7)
60 * DMA_ATTR_NO_WARN: This tells the DMA-mapping subsystem to suppress
61 * allocation failure reports (similarly to __GFP_NOWARN).
63 #define DMA_ATTR_NO_WARN (1UL << 8)
66 * A dma_addr_t can hold any valid DMA or bus address for the platform.
67 * It can be given to a device to use as a DMA source or target. A CPU cannot
68 * reference a dma_addr_t directly because there may be translation between
69 * its physical address space and the bus address space.
72 void* (*alloc)(struct device *dev, size_t size,
73 dma_addr_t *dma_handle, gfp_t gfp,
75 void (*free)(struct device *dev, size_t size,
76 void *vaddr, dma_addr_t dma_handle,
78 int (*mmap)(struct device *, struct vm_area_struct *,
79 void *, dma_addr_t, size_t,
82 int (*get_sgtable)(struct device *dev, struct sg_table *sgt, void *,
83 dma_addr_t, size_t, unsigned long attrs);
85 dma_addr_t (*map_page)(struct device *dev, struct page *page,
86 unsigned long offset, size_t size,
87 enum dma_data_direction dir,
89 void (*unmap_page)(struct device *dev, dma_addr_t dma_handle,
90 size_t size, enum dma_data_direction dir,
93 * map_sg returns 0 on error and a value > 0 on success.
94 * It should never return a value < 0.
96 int (*map_sg)(struct device *dev, struct scatterlist *sg,
97 int nents, enum dma_data_direction dir,
99 void (*unmap_sg)(struct device *dev,
100 struct scatterlist *sg, int nents,
101 enum dma_data_direction dir,
102 unsigned long attrs);
103 dma_addr_t (*map_resource)(struct device *dev, phys_addr_t phys_addr,
104 size_t size, enum dma_data_direction dir,
105 unsigned long attrs);
106 void (*unmap_resource)(struct device *dev, dma_addr_t dma_handle,
107 size_t size, enum dma_data_direction dir,
108 unsigned long attrs);
109 void (*sync_single_for_cpu)(struct device *dev,
110 dma_addr_t dma_handle, size_t size,
111 enum dma_data_direction dir);
112 void (*sync_single_for_device)(struct device *dev,
113 dma_addr_t dma_handle, size_t size,
114 enum dma_data_direction dir);
115 void (*sync_sg_for_cpu)(struct device *dev,
116 struct scatterlist *sg, int nents,
117 enum dma_data_direction dir);
118 void (*sync_sg_for_device)(struct device *dev,
119 struct scatterlist *sg, int nents,
120 enum dma_data_direction dir);
121 int (*mapping_error)(struct device *dev, dma_addr_t dma_addr);
122 int (*dma_supported)(struct device *dev, u64 mask);
123 int (*set_dma_mask)(struct device *dev, u64 mask);
124 #ifdef ARCH_HAS_DMA_GET_REQUIRED_MASK
125 u64 (*get_required_mask)(struct device *dev);
130 extern const struct dma_map_ops dma_noop_ops;
132 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
134 #define DMA_MASK_NONE 0x0ULL
136 static inline int valid_dma_direction(int dma_direction)
138 return ((dma_direction == DMA_BIDIRECTIONAL) ||
139 (dma_direction == DMA_TO_DEVICE) ||
140 (dma_direction == DMA_FROM_DEVICE));
143 static inline int is_device_dma_capable(struct device *dev)
145 return dev->dma_mask != NULL && *dev->dma_mask != DMA_MASK_NONE;
148 #ifdef CONFIG_HAVE_GENERIC_DMA_COHERENT
150 * These three functions are only for dma allocator.
151 * Don't use them in device drivers.
153 int dma_alloc_from_coherent(struct device *dev, ssize_t size,
154 dma_addr_t *dma_handle, void **ret);
155 int dma_release_from_coherent(struct device *dev, int order, void *vaddr);
157 int dma_mmap_from_coherent(struct device *dev, struct vm_area_struct *vma,
158 void *cpu_addr, size_t size, int *ret);
160 #define dma_alloc_from_coherent(dev, size, handle, ret) (0)
161 #define dma_release_from_coherent(dev, order, vaddr) (0)
162 #define dma_mmap_from_coherent(dev, vma, vaddr, order, ret) (0)
163 #endif /* CONFIG_HAVE_GENERIC_DMA_COHERENT */
165 #ifdef CONFIG_HAS_DMA
166 #include <asm/dma-mapping.h>
167 static inline void set_dma_ops(struct device *dev,
168 const struct dma_map_ops *dma_ops)
170 dev->dma_ops = dma_ops;
174 * Define the dma api to allow compilation but not linking of
175 * dma dependent code. Code that depends on the dma-mapping
176 * API needs to set 'depends on HAS_DMA' in its Kconfig
178 extern const struct dma_map_ops bad_dma_ops;
179 static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
185 static inline dma_addr_t dma_map_single_attrs(struct device *dev, void *ptr,
187 enum dma_data_direction dir,
190 const struct dma_map_ops *ops = get_dma_ops(dev);
193 kmemcheck_mark_initialized(ptr, size);
194 BUG_ON(!valid_dma_direction(dir));
195 addr = ops->map_page(dev, virt_to_page(ptr),
196 offset_in_page(ptr), size,
198 debug_dma_map_page(dev, virt_to_page(ptr),
199 offset_in_page(ptr), size,
204 static inline void dma_unmap_single_attrs(struct device *dev, dma_addr_t addr,
206 enum dma_data_direction dir,
209 const struct dma_map_ops *ops = get_dma_ops(dev);
211 BUG_ON(!valid_dma_direction(dir));
213 ops->unmap_page(dev, addr, size, dir, attrs);
214 debug_dma_unmap_page(dev, addr, size, dir, true);
218 * dma_maps_sg_attrs returns 0 on error and > 0 on success.
219 * It should never return a value < 0.
221 static inline int dma_map_sg_attrs(struct device *dev, struct scatterlist *sg,
222 int nents, enum dma_data_direction dir,
225 const struct dma_map_ops *ops = get_dma_ops(dev);
227 struct scatterlist *s;
229 for_each_sg(sg, s, nents, i)
230 kmemcheck_mark_initialized(sg_virt(s), s->length);
231 BUG_ON(!valid_dma_direction(dir));
232 ents = ops->map_sg(dev, sg, nents, dir, attrs);
234 debug_dma_map_sg(dev, sg, nents, ents, dir);
239 static inline void dma_unmap_sg_attrs(struct device *dev, struct scatterlist *sg,
240 int nents, enum dma_data_direction dir,
243 const struct dma_map_ops *ops = get_dma_ops(dev);
245 BUG_ON(!valid_dma_direction(dir));
246 debug_dma_unmap_sg(dev, sg, nents, dir);
248 ops->unmap_sg(dev, sg, nents, dir, attrs);
251 static inline dma_addr_t dma_map_page_attrs(struct device *dev,
253 size_t offset, size_t size,
254 enum dma_data_direction dir,
257 const struct dma_map_ops *ops = get_dma_ops(dev);
260 kmemcheck_mark_initialized(page_address(page) + offset, size);
261 BUG_ON(!valid_dma_direction(dir));
262 addr = ops->map_page(dev, page, offset, size, dir, attrs);
263 debug_dma_map_page(dev, page, offset, size, dir, addr, false);
268 static inline void dma_unmap_page_attrs(struct device *dev,
269 dma_addr_t addr, size_t size,
270 enum dma_data_direction dir,
273 const struct dma_map_ops *ops = get_dma_ops(dev);
275 BUG_ON(!valid_dma_direction(dir));
277 ops->unmap_page(dev, addr, size, dir, attrs);
278 debug_dma_unmap_page(dev, addr, size, dir, false);
281 static inline dma_addr_t dma_map_resource(struct device *dev,
282 phys_addr_t phys_addr,
284 enum dma_data_direction dir,
287 const struct dma_map_ops *ops = get_dma_ops(dev);
290 BUG_ON(!valid_dma_direction(dir));
292 /* Don't allow RAM to be mapped */
293 BUG_ON(pfn_valid(PHYS_PFN(phys_addr)));
296 if (ops->map_resource)
297 addr = ops->map_resource(dev, phys_addr, size, dir, attrs);
299 debug_dma_map_resource(dev, phys_addr, size, dir, addr);
304 static inline void dma_unmap_resource(struct device *dev, dma_addr_t addr,
305 size_t size, enum dma_data_direction dir,
308 const struct dma_map_ops *ops = get_dma_ops(dev);
310 BUG_ON(!valid_dma_direction(dir));
311 if (ops->unmap_resource)
312 ops->unmap_resource(dev, addr, size, dir, attrs);
313 debug_dma_unmap_resource(dev, addr, size, dir);
316 static inline void dma_sync_single_for_cpu(struct device *dev, dma_addr_t addr,
318 enum dma_data_direction dir)
320 const struct dma_map_ops *ops = get_dma_ops(dev);
322 BUG_ON(!valid_dma_direction(dir));
323 if (ops->sync_single_for_cpu)
324 ops->sync_single_for_cpu(dev, addr, size, dir);
325 debug_dma_sync_single_for_cpu(dev, addr, size, dir);
328 static inline void dma_sync_single_for_device(struct device *dev,
329 dma_addr_t addr, size_t size,
330 enum dma_data_direction dir)
332 const struct dma_map_ops *ops = get_dma_ops(dev);
334 BUG_ON(!valid_dma_direction(dir));
335 if (ops->sync_single_for_device)
336 ops->sync_single_for_device(dev, addr, size, dir);
337 debug_dma_sync_single_for_device(dev, addr, size, dir);
340 static inline void dma_sync_single_range_for_cpu(struct device *dev,
342 unsigned long offset,
344 enum dma_data_direction dir)
346 const struct dma_map_ops *ops = get_dma_ops(dev);
348 BUG_ON(!valid_dma_direction(dir));
349 if (ops->sync_single_for_cpu)
350 ops->sync_single_for_cpu(dev, addr + offset, size, dir);
351 debug_dma_sync_single_range_for_cpu(dev, addr, offset, size, dir);
354 static inline void dma_sync_single_range_for_device(struct device *dev,
356 unsigned long offset,
358 enum dma_data_direction dir)
360 const struct dma_map_ops *ops = get_dma_ops(dev);
362 BUG_ON(!valid_dma_direction(dir));
363 if (ops->sync_single_for_device)
364 ops->sync_single_for_device(dev, addr + offset, size, dir);
365 debug_dma_sync_single_range_for_device(dev, addr, offset, size, dir);
369 dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
370 int nelems, enum dma_data_direction dir)
372 const struct dma_map_ops *ops = get_dma_ops(dev);
374 BUG_ON(!valid_dma_direction(dir));
375 if (ops->sync_sg_for_cpu)
376 ops->sync_sg_for_cpu(dev, sg, nelems, dir);
377 debug_dma_sync_sg_for_cpu(dev, sg, nelems, dir);
381 dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
382 int nelems, enum dma_data_direction dir)
384 const struct dma_map_ops *ops = get_dma_ops(dev);
386 BUG_ON(!valid_dma_direction(dir));
387 if (ops->sync_sg_for_device)
388 ops->sync_sg_for_device(dev, sg, nelems, dir);
389 debug_dma_sync_sg_for_device(dev, sg, nelems, dir);
393 #define dma_map_single(d, a, s, r) dma_map_single_attrs(d, a, s, r, 0)
394 #define dma_unmap_single(d, a, s, r) dma_unmap_single_attrs(d, a, s, r, 0)
395 #define dma_map_sg(d, s, n, r) dma_map_sg_attrs(d, s, n, r, 0)
396 #define dma_unmap_sg(d, s, n, r) dma_unmap_sg_attrs(d, s, n, r, 0)
397 #define dma_map_page(d, p, o, s, r) dma_map_page_attrs(d, p, o, s, r, 0)
398 #define dma_unmap_page(d, a, s, r) dma_unmap_page_attrs(d, a, s, r, 0)
400 extern int dma_common_mmap(struct device *dev, struct vm_area_struct *vma,
401 void *cpu_addr, dma_addr_t dma_addr, size_t size);
403 void *dma_common_contiguous_remap(struct page *page, size_t size,
404 unsigned long vm_flags,
405 pgprot_t prot, const void *caller);
407 void *dma_common_pages_remap(struct page **pages, size_t size,
408 unsigned long vm_flags, pgprot_t prot,
410 void dma_common_free_remap(void *cpu_addr, size_t size, unsigned long vm_flags);
413 * dma_mmap_attrs - map a coherent DMA allocation into user space
414 * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
415 * @vma: vm_area_struct describing requested user mapping
416 * @cpu_addr: kernel CPU-view address returned from dma_alloc_attrs
417 * @handle: device-view address returned from dma_alloc_attrs
418 * @size: size of memory originally requested in dma_alloc_attrs
419 * @attrs: attributes of mapping properties requested in dma_alloc_attrs
421 * Map a coherent DMA buffer previously allocated by dma_alloc_attrs
422 * into user space. The coherent DMA buffer must not be freed by the
423 * driver until the user space mapping has been released.
426 dma_mmap_attrs(struct device *dev, struct vm_area_struct *vma, void *cpu_addr,
427 dma_addr_t dma_addr, size_t size, unsigned long attrs)
429 const struct dma_map_ops *ops = get_dma_ops(dev);
432 return ops->mmap(dev, vma, cpu_addr, dma_addr, size, attrs);
433 return dma_common_mmap(dev, vma, cpu_addr, dma_addr, size);
436 #define dma_mmap_coherent(d, v, c, h, s) dma_mmap_attrs(d, v, c, h, s, 0)
439 dma_common_get_sgtable(struct device *dev, struct sg_table *sgt,
440 void *cpu_addr, dma_addr_t dma_addr, size_t size);
443 dma_get_sgtable_attrs(struct device *dev, struct sg_table *sgt, void *cpu_addr,
444 dma_addr_t dma_addr, size_t size,
447 const struct dma_map_ops *ops = get_dma_ops(dev);
449 if (ops->get_sgtable)
450 return ops->get_sgtable(dev, sgt, cpu_addr, dma_addr, size,
452 return dma_common_get_sgtable(dev, sgt, cpu_addr, dma_addr, size);
455 #define dma_get_sgtable(d, t, v, h, s) dma_get_sgtable_attrs(d, t, v, h, s, 0)
457 #ifndef arch_dma_alloc_attrs
458 #define arch_dma_alloc_attrs(dev, flag) (true)
461 static inline void *dma_alloc_attrs(struct device *dev, size_t size,
462 dma_addr_t *dma_handle, gfp_t flag,
465 const struct dma_map_ops *ops = get_dma_ops(dev);
470 if (dma_alloc_from_coherent(dev, size, dma_handle, &cpu_addr))
473 if (!arch_dma_alloc_attrs(&dev, &flag))
478 cpu_addr = ops->alloc(dev, size, dma_handle, flag, attrs);
479 debug_dma_alloc_coherent(dev, size, *dma_handle, cpu_addr);
483 static inline void dma_free_attrs(struct device *dev, size_t size,
484 void *cpu_addr, dma_addr_t dma_handle,
487 const struct dma_map_ops *ops = get_dma_ops(dev);
490 WARN_ON(irqs_disabled());
492 if (dma_release_from_coherent(dev, get_order(size), cpu_addr))
495 if (!ops->free || !cpu_addr)
498 debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);
499 ops->free(dev, size, cpu_addr, dma_handle, attrs);
502 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
503 dma_addr_t *dma_handle, gfp_t flag)
505 return dma_alloc_attrs(dev, size, dma_handle, flag, 0);
508 static inline void dma_free_coherent(struct device *dev, size_t size,
509 void *cpu_addr, dma_addr_t dma_handle)
511 return dma_free_attrs(dev, size, cpu_addr, dma_handle, 0);
514 static inline void *dma_alloc_noncoherent(struct device *dev, size_t size,
515 dma_addr_t *dma_handle, gfp_t gfp)
517 return dma_alloc_attrs(dev, size, dma_handle, gfp,
518 DMA_ATTR_NON_CONSISTENT);
521 static inline void dma_free_noncoherent(struct device *dev, size_t size,
522 void *cpu_addr, dma_addr_t dma_handle)
524 dma_free_attrs(dev, size, cpu_addr, dma_handle,
525 DMA_ATTR_NON_CONSISTENT);
528 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
530 debug_dma_mapping_error(dev, dma_addr);
532 if (get_dma_ops(dev)->mapping_error)
533 return get_dma_ops(dev)->mapping_error(dev, dma_addr);
535 #ifdef DMA_ERROR_CODE
536 return dma_addr == DMA_ERROR_CODE;
542 #ifndef HAVE_ARCH_DMA_SUPPORTED
543 static inline int dma_supported(struct device *dev, u64 mask)
545 const struct dma_map_ops *ops = get_dma_ops(dev);
549 if (!ops->dma_supported)
551 return ops->dma_supported(dev, mask);
555 #ifndef HAVE_ARCH_DMA_SET_MASK
556 static inline int dma_set_mask(struct device *dev, u64 mask)
558 const struct dma_map_ops *ops = get_dma_ops(dev);
560 if (ops->set_dma_mask)
561 return ops->set_dma_mask(dev, mask);
563 if (!dev->dma_mask || !dma_supported(dev, mask))
565 *dev->dma_mask = mask;
570 static inline u64 dma_get_mask(struct device *dev)
572 if (dev && dev->dma_mask && *dev->dma_mask)
573 return *dev->dma_mask;
574 return DMA_BIT_MASK(32);
577 #ifdef CONFIG_ARCH_HAS_DMA_SET_COHERENT_MASK
578 int dma_set_coherent_mask(struct device *dev, u64 mask);
580 static inline int dma_set_coherent_mask(struct device *dev, u64 mask)
582 if (!dma_supported(dev, mask))
584 dev->coherent_dma_mask = mask;
590 * Set both the DMA mask and the coherent DMA mask to the same thing.
591 * Note that we don't check the return value from dma_set_coherent_mask()
592 * as the DMA API guarantees that the coherent DMA mask can be set to
593 * the same or smaller than the streaming DMA mask.
595 static inline int dma_set_mask_and_coherent(struct device *dev, u64 mask)
597 int rc = dma_set_mask(dev, mask);
599 dma_set_coherent_mask(dev, mask);
604 * Similar to the above, except it deals with the case where the device
605 * does not have dev->dma_mask appropriately setup.
607 static inline int dma_coerce_mask_and_coherent(struct device *dev, u64 mask)
609 dev->dma_mask = &dev->coherent_dma_mask;
610 return dma_set_mask_and_coherent(dev, mask);
613 extern u64 dma_get_required_mask(struct device *dev);
615 #ifndef arch_setup_dma_ops
616 static inline void arch_setup_dma_ops(struct device *dev, u64 dma_base,
617 u64 size, const struct iommu_ops *iommu,
621 #ifndef arch_teardown_dma_ops
622 static inline void arch_teardown_dma_ops(struct device *dev) { }
625 static inline unsigned int dma_get_max_seg_size(struct device *dev)
627 if (dev->dma_parms && dev->dma_parms->max_segment_size)
628 return dev->dma_parms->max_segment_size;
632 static inline unsigned int dma_set_max_seg_size(struct device *dev,
635 if (dev->dma_parms) {
636 dev->dma_parms->max_segment_size = size;
642 static inline unsigned long dma_get_seg_boundary(struct device *dev)
644 if (dev->dma_parms && dev->dma_parms->segment_boundary_mask)
645 return dev->dma_parms->segment_boundary_mask;
646 return DMA_BIT_MASK(32);
649 static inline int dma_set_seg_boundary(struct device *dev, unsigned long mask)
651 if (dev->dma_parms) {
652 dev->dma_parms->segment_boundary_mask = mask;
659 static inline unsigned long dma_max_pfn(struct device *dev)
661 return *dev->dma_mask >> PAGE_SHIFT;
665 static inline void *dma_zalloc_coherent(struct device *dev, size_t size,
666 dma_addr_t *dma_handle, gfp_t flag)
668 void *ret = dma_alloc_coherent(dev, size, dma_handle,
673 #ifdef CONFIG_HAS_DMA
674 static inline int dma_get_cache_alignment(void)
676 #ifdef ARCH_DMA_MINALIGN
677 return ARCH_DMA_MINALIGN;
683 /* flags for the coherent memory api */
684 #define DMA_MEMORY_MAP 0x01
685 #define DMA_MEMORY_IO 0x02
686 #define DMA_MEMORY_INCLUDES_CHILDREN 0x04
687 #define DMA_MEMORY_EXCLUSIVE 0x08
689 #ifdef CONFIG_HAVE_GENERIC_DMA_COHERENT
690 int dma_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr,
691 dma_addr_t device_addr, size_t size, int flags);
692 void dma_release_declared_memory(struct device *dev);
693 void *dma_mark_declared_memory_occupied(struct device *dev,
694 dma_addr_t device_addr, size_t size);
697 dma_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr,
698 dma_addr_t device_addr, size_t size, int flags)
704 dma_release_declared_memory(struct device *dev)
709 dma_mark_declared_memory_occupied(struct device *dev,
710 dma_addr_t device_addr, size_t size)
712 return ERR_PTR(-EBUSY);
714 #endif /* CONFIG_HAVE_GENERIC_DMA_COHERENT */
719 extern void *dmam_alloc_coherent(struct device *dev, size_t size,
720 dma_addr_t *dma_handle, gfp_t gfp);
721 extern void dmam_free_coherent(struct device *dev, size_t size, void *vaddr,
722 dma_addr_t dma_handle);
723 extern void *dmam_alloc_noncoherent(struct device *dev, size_t size,
724 dma_addr_t *dma_handle, gfp_t gfp);
725 extern void dmam_free_noncoherent(struct device *dev, size_t size, void *vaddr,
726 dma_addr_t dma_handle);
727 #ifdef CONFIG_HAVE_GENERIC_DMA_COHERENT
728 extern int dmam_declare_coherent_memory(struct device *dev,
729 phys_addr_t phys_addr,
730 dma_addr_t device_addr, size_t size,
732 extern void dmam_release_declared_memory(struct device *dev);
733 #else /* CONFIG_HAVE_GENERIC_DMA_COHERENT */
734 static inline int dmam_declare_coherent_memory(struct device *dev,
735 phys_addr_t phys_addr, dma_addr_t device_addr,
736 size_t size, gfp_t gfp)
741 static inline void dmam_release_declared_memory(struct device *dev)
744 #endif /* CONFIG_HAVE_GENERIC_DMA_COHERENT */
746 static inline void *dma_alloc_wc(struct device *dev, size_t size,
747 dma_addr_t *dma_addr, gfp_t gfp)
749 return dma_alloc_attrs(dev, size, dma_addr, gfp,
750 DMA_ATTR_WRITE_COMBINE);
752 #ifndef dma_alloc_writecombine
753 #define dma_alloc_writecombine dma_alloc_wc
756 static inline void dma_free_wc(struct device *dev, size_t size,
757 void *cpu_addr, dma_addr_t dma_addr)
759 return dma_free_attrs(dev, size, cpu_addr, dma_addr,
760 DMA_ATTR_WRITE_COMBINE);
762 #ifndef dma_free_writecombine
763 #define dma_free_writecombine dma_free_wc
766 static inline int dma_mmap_wc(struct device *dev,
767 struct vm_area_struct *vma,
768 void *cpu_addr, dma_addr_t dma_addr,
771 return dma_mmap_attrs(dev, vma, cpu_addr, dma_addr, size,
772 DMA_ATTR_WRITE_COMBINE);
774 #ifndef dma_mmap_writecombine
775 #define dma_mmap_writecombine dma_mmap_wc
778 #if defined(CONFIG_NEED_DMA_MAP_STATE) || defined(CONFIG_DMA_API_DEBUG)
779 #define DEFINE_DMA_UNMAP_ADDR(ADDR_NAME) dma_addr_t ADDR_NAME
780 #define DEFINE_DMA_UNMAP_LEN(LEN_NAME) __u32 LEN_NAME
781 #define dma_unmap_addr(PTR, ADDR_NAME) ((PTR)->ADDR_NAME)
782 #define dma_unmap_addr_set(PTR, ADDR_NAME, VAL) (((PTR)->ADDR_NAME) = (VAL))
783 #define dma_unmap_len(PTR, LEN_NAME) ((PTR)->LEN_NAME)
784 #define dma_unmap_len_set(PTR, LEN_NAME, VAL) (((PTR)->LEN_NAME) = (VAL))
786 #define DEFINE_DMA_UNMAP_ADDR(ADDR_NAME)
787 #define DEFINE_DMA_UNMAP_LEN(LEN_NAME)
788 #define dma_unmap_addr(PTR, ADDR_NAME) (0)
789 #define dma_unmap_addr_set(PTR, ADDR_NAME, VAL) do { } while (0)
790 #define dma_unmap_len(PTR, LEN_NAME) (0)
791 #define dma_unmap_len_set(PTR, LEN_NAME, VAL) do { } while (0)