WIP FPC-III support
[linux/fpc-iii.git] / arch / arm / include / asm / dma-mapping.h
blob77082246a5e121ead21b8cd69c80e1202f2bd4f6
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef ASMARM_DMA_MAPPING_H
3 #define ASMARM_DMA_MAPPING_H
5 #ifdef __KERNEL__
7 #include <linux/mm_types.h>
8 #include <linux/scatterlist.h>
10 #include <xen/xen.h>
11 #include <asm/xen/hypervisor.h>
13 extern const struct dma_map_ops arm_dma_ops;
14 extern const struct dma_map_ops arm_coherent_dma_ops;
16 static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus)
18 if (IS_ENABLED(CONFIG_MMU) && !IS_ENABLED(CONFIG_ARM_LPAE))
19 return &arm_dma_ops;
20 return NULL;
23 /**
24 * arm_dma_alloc - allocate consistent memory for DMA
25 * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
26 * @size: required memory size
27 * @handle: bus-specific DMA address
28 * @attrs: optinal attributes that specific mapping properties
30 * Allocate some memory for a device for performing DMA. This function
31 * allocates pages, and will return the CPU-viewed address, and sets @handle
32 * to be the device-viewed address.
34 extern void *arm_dma_alloc(struct device *dev, size_t size, dma_addr_t *handle,
35 gfp_t gfp, unsigned long attrs);
37 /**
38 * arm_dma_free - free memory allocated by arm_dma_alloc
39 * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
40 * @size: size of memory originally requested in dma_alloc_coherent
41 * @cpu_addr: CPU-view address returned from dma_alloc_coherent
42 * @handle: device-view address returned from dma_alloc_coherent
43 * @attrs: optinal attributes that specific mapping properties
45 * Free (and unmap) a DMA buffer previously allocated by
46 * arm_dma_alloc().
48 * References to memory and mappings associated with cpu_addr/handle
49 * during and after this call executing are illegal.
51 extern void arm_dma_free(struct device *dev, size_t size, void *cpu_addr,
52 dma_addr_t handle, unsigned long attrs);
54 /**
55 * arm_dma_mmap - map a coherent DMA allocation into user space
56 * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
57 * @vma: vm_area_struct describing requested user mapping
58 * @cpu_addr: kernel CPU-view address returned from dma_alloc_coherent
59 * @handle: device-view address returned from dma_alloc_coherent
60 * @size: size of memory originally requested in dma_alloc_coherent
61 * @attrs: optinal attributes that specific mapping properties
63 * Map a coherent DMA buffer previously allocated by dma_alloc_coherent
64 * into user space. The coherent DMA buffer must not be freed by the
65 * driver until the user space mapping has been released.
67 extern int arm_dma_mmap(struct device *dev, struct vm_area_struct *vma,
68 void *cpu_addr, dma_addr_t dma_addr, size_t size,
69 unsigned long attrs);
72 * For SA-1111, IXP425, and ADI systems the dma-mapping functions are "magic"
73 * and utilize bounce buffers as needed to work around limited DMA windows.
75 * On the SA-1111, a bug limits DMA to only certain regions of RAM.
76 * On the IXP425, the PCI inbound window is 64MB (256MB total RAM)
77 * On some ADI engineering systems, PCI inbound window is 32MB (12MB total RAM)
79 * The following are helper functions used by the dmabounce subystem
83 /**
84 * dmabounce_register_dev
86 * @dev: valid struct device pointer
87 * @small_buf_size: size of buffers to use with small buffer pool
88 * @large_buf_size: size of buffers to use with large buffer pool (can be 0)
89 * @needs_bounce_fn: called to determine whether buffer needs bouncing
91 * This function should be called by low-level platform code to register
92 * a device as requireing DMA buffer bouncing. The function will allocate
93 * appropriate DMA pools for the device.
95 extern int dmabounce_register_dev(struct device *, unsigned long,
96 unsigned long, int (*)(struct device *, dma_addr_t, size_t));
98 /**
99 * dmabounce_unregister_dev
101 * @dev: valid struct device pointer
103 * This function should be called by low-level platform code when device
104 * that was previously registered with dmabounce_register_dev is removed
105 * from the system.
108 extern void dmabounce_unregister_dev(struct device *);
113 * The scatter list versions of the above methods.
115 extern int arm_dma_map_sg(struct device *, struct scatterlist *, int,
116 enum dma_data_direction, unsigned long attrs);
117 extern void arm_dma_unmap_sg(struct device *, struct scatterlist *, int,
118 enum dma_data_direction, unsigned long attrs);
119 extern void arm_dma_sync_sg_for_cpu(struct device *, struct scatterlist *, int,
120 enum dma_data_direction);
121 extern void arm_dma_sync_sg_for_device(struct device *, struct scatterlist *, int,
122 enum dma_data_direction);
123 extern int arm_dma_get_sgtable(struct device *dev, struct sg_table *sgt,
124 void *cpu_addr, dma_addr_t dma_addr, size_t size,
125 unsigned long attrs);
127 #endif /* __KERNEL__ */
128 #endif