55
66#include <linux/mm_types.h>
77#include <linux/scatterlist.h>
8+ #include <linux/dma-attrs.h>
89#include <linux/dma-debug.h>
910
1011#include <asm-generic/dma-coherent.h>
@@ -110,68 +111,115 @@ static inline void dma_free_noncoherent(struct device *dev, size_t size,
110111extern int dma_supported (struct device * dev , u64 mask );
111112
112113/**
113- * dma_alloc_coherent - allocate consistent memory for DMA
114+ * arm_dma_alloc - allocate consistent memory for DMA
114115 * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
115116 * @size: required memory size
116117 * @handle: bus-specific DMA address
118+ * @attrs: optinal attributes that specific mapping properties
117119 *
118- * Allocate some uncached, unbuffered memory for a device for
119- * performing DMA. This function allocates pages, and will
120- * return the CPU-viewed address, and sets @handle to be the
121- * device-viewed address.
120+ * Allocate some memory for a device for performing DMA. This function
121+ * allocates pages, and will return the CPU-viewed address, and sets @handle
122+ * to be the device-viewed address.
122123 */
123- extern void * dma_alloc_coherent (struct device * , size_t , dma_addr_t * , gfp_t );
124+ extern void * arm_dma_alloc (struct device * dev , size_t size , dma_addr_t * handle ,
125+ gfp_t gfp , struct dma_attrs * attrs );
126+
127+ #define dma_alloc_coherent (d , s , h , f ) dma_alloc_attrs(d, s, h, f, NULL)
128+
129+ static inline void * dma_alloc_attrs (struct device * dev , size_t size ,
130+ dma_addr_t * dma_handle , gfp_t flag ,
131+ struct dma_attrs * attrs )
132+ {
133+ struct dma_map_ops * ops = get_dma_ops (dev );
134+ void * cpu_addr ;
135+ BUG_ON (!ops );
136+
137+ cpu_addr = ops -> alloc (dev , size , dma_handle , flag , attrs );
138+ debug_dma_alloc_coherent (dev , size , * dma_handle , cpu_addr );
139+ return cpu_addr ;
140+ }
124141
125142/**
126- * dma_free_coherent - free memory allocated by dma_alloc_coherent
143+ * arm_dma_free - free memory allocated by arm_dma_alloc
127144 * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
128145 * @size: size of memory originally requested in dma_alloc_coherent
129146 * @cpu_addr: CPU-view address returned from dma_alloc_coherent
130147 * @handle: device-view address returned from dma_alloc_coherent
148+ * @attrs: optinal attributes that specific mapping properties
131149 *
132150 * Free (and unmap) a DMA buffer previously allocated by
133- * dma_alloc_coherent ().
151+ * arm_dma_alloc ().
134152 *
135153 * References to memory and mappings associated with cpu_addr/handle
136154 * during and after this call executing are illegal.
137155 */
138- extern void dma_free_coherent (struct device * , size_t , void * , dma_addr_t );
156+ extern void arm_dma_free (struct device * dev , size_t size , void * cpu_addr ,
157+ dma_addr_t handle , struct dma_attrs * attrs );
158+
159+ #define dma_free_coherent (d , s , c , h ) dma_free_attrs(d, s, c, h, NULL)
160+
161+ static inline void dma_free_attrs (struct device * dev , size_t size ,
162+ void * cpu_addr , dma_addr_t dma_handle ,
163+ struct dma_attrs * attrs )
164+ {
165+ struct dma_map_ops * ops = get_dma_ops (dev );
166+ BUG_ON (!ops );
167+
168+ debug_dma_free_coherent (dev , size , cpu_addr , dma_handle );
169+ ops -> free (dev , size , cpu_addr , dma_handle , attrs );
170+ }
139171
140172/**
141- * dma_mmap_coherent - map a coherent DMA allocation into user space
173+ * arm_dma_mmap - map a coherent DMA allocation into user space
142174 * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
143175 * @vma: vm_area_struct describing requested user mapping
144176 * @cpu_addr: kernel CPU-view address returned from dma_alloc_coherent
145177 * @handle: device-view address returned from dma_alloc_coherent
146178 * @size: size of memory originally requested in dma_alloc_coherent
179+ * @attrs: optinal attributes that specific mapping properties
147180 *
148181 * Map a coherent DMA buffer previously allocated by dma_alloc_coherent
149182 * into user space. The coherent DMA buffer must not be freed by the
150183 * driver until the user space mapping has been released.
151184 */
152- int dma_mmap_coherent (struct device * , struct vm_area_struct * ,
153- void * , dma_addr_t , size_t );
185+ extern int arm_dma_mmap (struct device * dev , struct vm_area_struct * vma ,
186+ void * cpu_addr , dma_addr_t dma_addr , size_t size ,
187+ struct dma_attrs * attrs );
154188
189+ #define dma_mmap_coherent (d , v , c , h , s ) dma_mmap_attrs(d, v, c, h, s, NULL)
155190
156- /**
157- * dma_alloc_writecombine - allocate writecombining memory for DMA
158- * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
159- * @size: required memory size
160- * @handle: bus-specific DMA address
161- *
162- * Allocate some uncached, buffered memory for a device for
163- * performing DMA. This function allocates pages, and will
164- * return the CPU-viewed address, and sets @handle to be the
165- * device-viewed address.
166- */
167- extern void * dma_alloc_writecombine (struct device * , size_t , dma_addr_t * ,
168- gfp_t );
191+ static inline int dma_mmap_attrs (struct device * dev , struct vm_area_struct * vma ,
192+ void * cpu_addr , dma_addr_t dma_addr ,
193+ size_t size , struct dma_attrs * attrs )
194+ {
195+ struct dma_map_ops * ops = get_dma_ops (dev );
196+ BUG_ON (!ops );
197+ return ops -> mmap (dev , vma , cpu_addr , dma_addr , size , attrs );
198+ }
169199
170- #define dma_free_writecombine (dev ,size ,cpu_addr ,handle ) \
171- dma_free_coherent(dev,size,cpu_addr,handle)
200+ static inline void * dma_alloc_writecombine (struct device * dev , size_t size ,
201+ dma_addr_t * dma_handle , gfp_t flag )
202+ {
203+ DEFINE_DMA_ATTRS (attrs );
204+ dma_set_attr (DMA_ATTR_WRITE_COMBINE , & attrs );
205+ return dma_alloc_attrs (dev , size , dma_handle , flag , & attrs );
206+ }
172207
173- int dma_mmap_writecombine (struct device * , struct vm_area_struct * ,
174- void * , dma_addr_t , size_t );
208+ static inline void dma_free_writecombine (struct device * dev , size_t size ,
209+ void * cpu_addr , dma_addr_t dma_handle )
210+ {
211+ DEFINE_DMA_ATTRS (attrs );
212+ dma_set_attr (DMA_ATTR_WRITE_COMBINE , & attrs );
213+ return dma_free_attrs (dev , size , cpu_addr , dma_handle , & attrs );
214+ }
215+
216+ static inline int dma_mmap_writecombine (struct device * dev , struct vm_area_struct * vma ,
217+ void * cpu_addr , dma_addr_t dma_addr , size_t size )
218+ {
219+ DEFINE_DMA_ATTRS (attrs );
220+ dma_set_attr (DMA_ATTR_WRITE_COMBINE , & attrs );
221+ return dma_mmap_attrs (dev , vma , cpu_addr , dma_addr , size , & attrs );
222+ }
175223
176224/*
177225 * This can be called during boot to increase the size of the consistent
@@ -180,7 +228,6 @@ int dma_mmap_writecombine(struct device *, struct vm_area_struct *,
180228 */
181229extern void __init init_consistent_dma_size (unsigned long size );
182230
183-
184231/*
185232 * For SA-1111, IXP425, and ADI systems the dma-mapping functions are "magic"
186233 * and utilize bounce buffers as needed to work around limited DMA windows.
0 commit comments