1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3 * Copyright(c) 2004 - 2006 Intel Corporation. All rights reserved.
4 */
5 #ifndef LINUX_DMAENGINE_H
6 #define LINUX_DMAENGINE_H
7
8 #include <linux/device.h>
9 #include <linux/err.h>
10 #include <linux/uio.h>
11 #include <linux/bug.h>
12 #include <linux/scatterlist.h>
13 #include <linux/bitmap.h>
14 #include <linux/types.h>
15 #include <linux/android_kabi.h>
16 #include <asm/page.h>
17
18 /**
19 * typedef dma_cookie_t - an opaque DMA cookie
20 *
21 * if dma_cookie_t is >0 it's a DMA request cookie, <0 it's an error code
22 */
23 typedef s32 dma_cookie_t;
24 #define DMA_MIN_COOKIE 1
25
dma_submit_error(dma_cookie_t cookie)26 static inline int dma_submit_error(dma_cookie_t cookie)
27 {
28 return cookie < 0 ? cookie : 0;
29 }
30
31 /**
32 * enum dma_status - DMA transaction status
33 * @DMA_COMPLETE: transaction completed
34 * @DMA_IN_PROGRESS: transaction not yet processed
35 * @DMA_PAUSED: transaction is paused
36 * @DMA_ERROR: transaction failed
37 */
38 enum dma_status {
39 DMA_COMPLETE,
40 DMA_IN_PROGRESS,
41 DMA_PAUSED,
42 DMA_ERROR,
43 DMA_OUT_OF_ORDER,
44 };
45
46 /**
47 * enum dma_transaction_type - DMA transaction types/indexes
48 *
49 * Note: The DMA_ASYNC_TX capability is not to be set by drivers. It is
50 * automatically set as dma devices are registered.
51 */
52 enum dma_transaction_type {
53 DMA_MEMCPY,
54 DMA_XOR,
55 DMA_PQ,
56 DMA_XOR_VAL,
57 DMA_PQ_VAL,
58 DMA_MEMSET,
59 DMA_MEMSET_SG,
60 DMA_INTERRUPT,
61 DMA_PRIVATE,
62 DMA_ASYNC_TX,
63 DMA_SLAVE,
64 DMA_CYCLIC,
65 DMA_INTERLEAVE,
66 DMA_COMPLETION_NO_ORDER,
67 DMA_REPEAT,
68 DMA_LOAD_EOT,
69 /* last transaction type for creation of the capabilities mask */
70 DMA_TX_TYPE_END,
71 };
72
73 /**
74 * enum dma_transfer_direction - dma transfer mode and direction indicator
75 * @DMA_MEM_TO_MEM: Async/Memcpy mode
76 * @DMA_MEM_TO_DEV: Slave mode & From Memory to Device
77 * @DMA_DEV_TO_MEM: Slave mode & From Device to Memory
78 * @DMA_DEV_TO_DEV: Slave mode & From Device to Device
79 */
80 enum dma_transfer_direction {
81 DMA_MEM_TO_MEM,
82 DMA_MEM_TO_DEV,
83 DMA_DEV_TO_MEM,
84 DMA_DEV_TO_DEV,
85 DMA_TRANS_NONE,
86 };
87
88 /**
89 * Interleaved Transfer Request
90 * ----------------------------
91 * A chunk is collection of contiguous bytes to be transferred.
92 * The gap(in bytes) between two chunks is called inter-chunk-gap(ICG).
93 * ICGs may or may not change between chunks.
94 * A FRAME is the smallest series of contiguous {chunk,icg} pairs,
95 * that when repeated an integral number of times, specifies the transfer.
96 * A transfer template is specification of a Frame, the number of times
97 * it is to be repeated and other per-transfer attributes.
98 *
99 * Practically, a client driver would have ready a template for each
100 * type of transfer it is going to need during its lifetime and
101 * set only 'src_start' and 'dst_start' before submitting the requests.
102 *
103 *
104 * | Frame-1 | Frame-2 | ~ | Frame-'numf' |
105 * |====....==.===...=...|====....==.===...=...| ~ |====....==.===...=...|
106 *
107 * == Chunk size
108 * ... ICG
109 */
110
111 /**
112 * struct data_chunk - Element of scatter-gather list that makes a frame.
113 * @size: Number of bytes to read from source.
114 * size_dst := fn(op, size_src), so doesn't mean much for destination.
115 * @icg: Number of bytes to jump after last src/dst address of this
116 * chunk and before first src/dst address for next chunk.
117 * Ignored for dst(assumed 0), if dst_inc is true and dst_sgl is false.
118 * Ignored for src(assumed 0), if src_inc is true and src_sgl is false.
119 * @dst_icg: Number of bytes to jump after last dst address of this
120 * chunk and before the first dst address for next chunk.
121 * Ignored if dst_inc is true and dst_sgl is false.
122 * @src_icg: Number of bytes to jump after last src address of this
123 * chunk and before the first src address for next chunk.
124 * Ignored if src_inc is true and src_sgl is false.
125 */
126 struct data_chunk {
127 size_t size;
128 size_t icg;
129 size_t dst_icg;
130 size_t src_icg;
131 };
132
133 /**
134 * struct dma_interleaved_template - Template to convey DMAC the transfer pattern
135 * and attributes.
136 * @src_start: Bus address of source for the first chunk.
137 * @dst_start: Bus address of destination for the first chunk.
138 * @dir: Specifies the type of Source and Destination.
139 * @src_inc: If the source address increments after reading from it.
140 * @dst_inc: If the destination address increments after writing to it.
141 * @src_sgl: If the 'icg' of sgl[] applies to Source (scattered read).
142 * Otherwise, source is read contiguously (icg ignored).
143 * Ignored if src_inc is false.
144 * @dst_sgl: If the 'icg' of sgl[] applies to Destination (scattered write).
145 * Otherwise, destination is filled contiguously (icg ignored).
146 * Ignored if dst_inc is false.
147 * @numf: Number of frames in this template.
148 * @frame_size: Number of chunks in a frame i.e, size of sgl[].
149 * @sgl: Array of {chunk,icg} pairs that make up a frame.
150 */
151 struct dma_interleaved_template {
152 dma_addr_t src_start;
153 dma_addr_t dst_start;
154 enum dma_transfer_direction dir;
155 bool src_inc;
156 bool dst_inc;
157 bool src_sgl;
158 bool dst_sgl;
159 size_t numf;
160 size_t frame_size;
161 struct data_chunk sgl[];
162 };
163
164 /**
165 * struct dma_vec - DMA vector
166 * @addr: Bus address of the start of the vector
167 * @len: Length in bytes of the DMA vector
168 */
169 struct dma_vec {
170 dma_addr_t addr;
171 size_t len;
172 };
173
174 /**
175 * enum dma_ctrl_flags - DMA flags to augment operation preparation,
176 * control completion, and communicate status.
177 * @DMA_PREP_INTERRUPT - trigger an interrupt (callback) upon completion of
178 * this transaction
179 * @DMA_CTRL_ACK - if clear, the descriptor cannot be reused until the client
180 * acknowledges receipt, i.e. has a chance to establish any dependency
181 * chains
182 * @DMA_PREP_PQ_DISABLE_P - prevent generation of P while generating Q
183 * @DMA_PREP_PQ_DISABLE_Q - prevent generation of Q while generating P
184 * @DMA_PREP_CONTINUE - indicate to a driver that it is reusing buffers as
185 * sources that were the result of a previous operation, in the case of a PQ
186 * operation it continues the calculation with new sources
187 * @DMA_PREP_FENCE - tell the driver that subsequent operations depend
188 * on the result of this operation
189 * @DMA_CTRL_REUSE: client can reuse the descriptor and submit again till
190 * cleared or freed
191 * @DMA_PREP_CMD: tell the driver that the data passed to DMA API is command
192 * data and the descriptor should be in different format from normal
193 * data descriptors.
194 * @DMA_PREP_REPEAT: tell the driver that the transaction shall be automatically
195 * repeated when it ends until a transaction is issued on the same channel
196 * with the DMA_PREP_LOAD_EOT flag set. This flag is only applicable to
197 * interleaved transactions and is ignored for all other transaction types.
198 * @DMA_PREP_LOAD_EOT: tell the driver that the transaction shall replace any
199 * active repeated (as indicated by DMA_PREP_REPEAT) transaction when the
200 * repeated transaction ends. Not setting this flag when the previously queued
201 * transaction is marked with DMA_PREP_REPEAT will cause the new transaction
202 * to never be processed and stay in the issued queue forever. The flag is
203 * ignored if the previous transaction is not a repeated transaction.
204 */
205 enum dma_ctrl_flags {
206 DMA_PREP_INTERRUPT = (1 << 0),
207 DMA_CTRL_ACK = (1 << 1),
208 DMA_PREP_PQ_DISABLE_P = (1 << 2),
209 DMA_PREP_PQ_DISABLE_Q = (1 << 3),
210 DMA_PREP_CONTINUE = (1 << 4),
211 DMA_PREP_FENCE = (1 << 5),
212 DMA_CTRL_REUSE = (1 << 6),
213 DMA_PREP_CMD = (1 << 7),
214 DMA_PREP_REPEAT = (1 << 8),
215 DMA_PREP_LOAD_EOT = (1 << 9),
216 };
217
218 /**
219 * enum sum_check_bits - bit position of pq_check_flags
220 */
221 enum sum_check_bits {
222 SUM_CHECK_P = 0,
223 SUM_CHECK_Q = 1,
224 };
225
226 /**
227 * enum pq_check_flags - result of async_{xor,pq}_zero_sum operations
228 * @SUM_CHECK_P_RESULT - 1 if xor zero sum error, 0 otherwise
229 * @SUM_CHECK_Q_RESULT - 1 if reed-solomon zero sum error, 0 otherwise
230 */
231 enum sum_check_flags {
232 SUM_CHECK_P_RESULT = (1 << SUM_CHECK_P),
233 SUM_CHECK_Q_RESULT = (1 << SUM_CHECK_Q),
234 };
235
236
237 /**
238 * dma_cap_mask_t - capabilities bitmap modeled after cpumask_t.
239 * See linux/cpumask.h
240 */
241 typedef struct { DECLARE_BITMAP(bits, DMA_TX_TYPE_END); } dma_cap_mask_t;
242
243 /**
244 * enum dma_desc_metadata_mode - per descriptor metadata mode types supported
245 * @DESC_METADATA_CLIENT - the metadata buffer is allocated/provided by the
246 * client driver and it is attached (via the dmaengine_desc_attach_metadata()
247 * helper) to the descriptor.
248 *
249 * Client drivers interested to use this mode can follow:
250 * - DMA_MEM_TO_DEV / DEV_MEM_TO_MEM:
251 * 1. prepare the descriptor (dmaengine_prep_*)
252 * construct the metadata in the client's buffer
253 * 2. use dmaengine_desc_attach_metadata() to attach the buffer to the
254 * descriptor
255 * 3. submit the transfer
256 * - DMA_DEV_TO_MEM:
257 * 1. prepare the descriptor (dmaengine_prep_*)
258 * 2. use dmaengine_desc_attach_metadata() to attach the buffer to the
259 * descriptor
260 * 3. submit the transfer
261 * 4. when the transfer is completed, the metadata should be available in the
262 * attached buffer
263 *
264 * @DESC_METADATA_ENGINE - the metadata buffer is allocated/managed by the DMA
265 * driver. The client driver can ask for the pointer, maximum size and the
266 * currently used size of the metadata and can directly update or read it.
267 * dmaengine_desc_get_metadata_ptr() and dmaengine_desc_set_metadata_len() is
268 * provided as helper functions.
269 *
270 * Note: the metadata area for the descriptor is no longer valid after the
271 * transfer has been completed (valid up to the point when the completion
272 * callback returns if used).
273 *
274 * Client drivers interested to use this mode can follow:
275 * - DMA_MEM_TO_DEV / DEV_MEM_TO_MEM:
276 * 1. prepare the descriptor (dmaengine_prep_*)
277 * 2. use dmaengine_desc_get_metadata_ptr() to get the pointer to the engine's
278 * metadata area
279 * 3. update the metadata at the pointer
280 * 4. use dmaengine_desc_set_metadata_len() to tell the DMA engine the amount
281 * of data the client has placed into the metadata buffer
282 * 5. submit the transfer
283 * - DMA_DEV_TO_MEM:
284 * 1. prepare the descriptor (dmaengine_prep_*)
285 * 2. submit the transfer
286 * 3. on transfer completion, use dmaengine_desc_get_metadata_ptr() to get the
287 * pointer to the engine's metadata area
288 * 4. Read out the metadata from the pointer
289 *
290 * Note: the two mode is not compatible and clients must use one mode for a
291 * descriptor.
292 */
293 enum dma_desc_metadata_mode {
294 DESC_METADATA_NONE = 0,
295 DESC_METADATA_CLIENT = BIT(0),
296 DESC_METADATA_ENGINE = BIT(1),
297 };
298
299 /**
300 * struct dma_chan_percpu - the per-CPU part of struct dma_chan
301 * @memcpy_count: transaction counter
302 * @bytes_transferred: byte counter
303 */
304 struct dma_chan_percpu {
305 /* stats */
306 unsigned long memcpy_count;
307 unsigned long bytes_transferred;
308 };
309
310 /**
311 * struct dma_router - DMA router structure
312 * @dev: pointer to the DMA router device
313 * @route_free: function to be called when the route can be disconnected
314 */
315 struct dma_router {
316 struct device *dev;
317 void (*route_free)(struct device *dev, void *route_data);
318 };
319
320 /**
321 * struct dma_chan - devices supply DMA channels, clients use them
322 * @device: ptr to the dma device who supplies this channel, always !%NULL
323 * @slave: ptr to the device using this channel
324 * @cookie: last cookie value returned to client
325 * @completed_cookie: last completed cookie for this channel
326 * @chan_id: channel ID for sysfs
327 * @dev: class device for sysfs
328 * @name: backlink name for sysfs
329 * @dbg_client_name: slave name for debugfs in format:
330 * dev_name(requester's dev):channel name, for example: "2b00000.mcasp:tx"
331 * @device_node: used to add this to the device chan list
332 * @local: per-cpu pointer to a struct dma_chan_percpu
333 * @client_count: how many clients are using this channel
334 * @table_count: number of appearances in the mem-to-mem allocation table
335 * @router: pointer to the DMA router structure
336 * @route_data: channel specific data for the router
337 * @private: private data for certain client-channel associations
338 */
339 struct dma_chan {
340 struct dma_device *device;
341 struct device *slave;
342 dma_cookie_t cookie;
343 dma_cookie_t completed_cookie;
344
345 /* sysfs */
346 int chan_id;
347 struct dma_chan_dev *dev;
348 const char *name;
349 #ifdef CONFIG_DEBUG_FS
350 char *dbg_client_name;
351 #endif
352
353 struct list_head device_node;
354 struct dma_chan_percpu __percpu *local;
355 int client_count;
356 int table_count;
357
358 /* DMA router */
359 struct dma_router *router;
360 void *route_data;
361
362 void *private;
363 };
364
365 /**
366 * struct dma_chan_dev - relate sysfs device node to backing channel device
367 * @chan: driver channel device
368 * @device: sysfs device
369 * @dev_id: parent dma_device dev_id
370 * @chan_dma_dev: The channel is using custom/different dma-mapping
371 * compared to the parent dma_device
372 */
373 struct dma_chan_dev {
374 struct dma_chan *chan;
375 struct device device;
376 int dev_id;
377 bool chan_dma_dev;
378 };
379
380 /**
381 * enum dma_slave_buswidth - defines bus width of the DMA slave
382 * device, source or target buses
383 */
384 enum dma_slave_buswidth {
385 DMA_SLAVE_BUSWIDTH_UNDEFINED = 0,
386 DMA_SLAVE_BUSWIDTH_1_BYTE = 1,
387 DMA_SLAVE_BUSWIDTH_2_BYTES = 2,
388 DMA_SLAVE_BUSWIDTH_3_BYTES = 3,
389 DMA_SLAVE_BUSWIDTH_4_BYTES = 4,
390 DMA_SLAVE_BUSWIDTH_8_BYTES = 8,
391 DMA_SLAVE_BUSWIDTH_16_BYTES = 16,
392 DMA_SLAVE_BUSWIDTH_32_BYTES = 32,
393 DMA_SLAVE_BUSWIDTH_64_BYTES = 64,
394 DMA_SLAVE_BUSWIDTH_128_BYTES = 128,
395 };
396
397 /**
398 * struct dma_slave_config - dma slave channel runtime config
399 * @direction: whether the data shall go in or out on this slave
400 * channel, right now. DMA_MEM_TO_DEV and DMA_DEV_TO_MEM are
401 * legal values. DEPRECATED, drivers should use the direction argument
402 * to the device_prep_slave_sg and device_prep_dma_cyclic functions or
403 * the dir field in the dma_interleaved_template structure.
404 * @src_addr: this is the physical address where DMA slave data
405 * should be read (RX), if the source is memory this argument is
406 * ignored.
407 * @dst_addr: this is the physical address where DMA slave data
408 * should be written (TX), if the destination is memory this argument
409 * is ignored.
410 * @src_addr_width: this is the width in bytes of the source (RX)
411 * register where DMA data shall be read. If the source
412 * is memory this may be ignored depending on architecture.
413 * Legal values: 1, 2, 3, 4, 8, 16, 32, 64, 128.
414 * @dst_addr_width: same as src_addr_width but for destination
415 * target (TX) mutatis mutandis.
416 * @src_maxburst: the maximum number of words (note: words, as in
417 * units of the src_addr_width member, not bytes) that can be sent
418 * in one burst to the device. Typically something like half the
419 * FIFO depth on I/O peripherals so you don't overflow it. This
420 * may or may not be applicable on memory sources.
421 * @dst_maxburst: same as src_maxburst but for destination target
422 * mutatis mutandis.
423 * @src_port_window_size: The length of the register area in words the data need
424 * to be accessed on the device side. It is only used for devices which is using
425 * an area instead of a single register to receive the data. Typically the DMA
426 * loops in this area in order to transfer the data.
427 * @dst_port_window_size: same as src_port_window_size but for the destination
428 * port.
429 * @device_fc: Flow Controller Settings. Only valid for slave channels. Fill
430 * with 'true' if peripheral should be flow controller. Direction will be
431 * selected at Runtime.
432 * @peripheral_config: peripheral configuration for programming peripheral
433 * for dmaengine transfer
434 * @peripheral_size: peripheral configuration buffer size
435 *
436 * This struct is passed in as configuration data to a DMA engine
437 * in order to set up a certain channel for DMA transport at runtime.
438 * The DMA device/engine has to provide support for an additional
439 * callback in the dma_device structure, device_config and this struct
440 * will then be passed in as an argument to the function.
441 *
442 * The rationale for adding configuration information to this struct is as
443 * follows: if it is likely that more than one DMA slave controllers in
444 * the world will support the configuration option, then make it generic.
445 * If not: if it is fixed so that it be sent in static from the platform
446 * data, then prefer to do that.
447 */
448 struct dma_slave_config {
449 enum dma_transfer_direction direction;
450 phys_addr_t src_addr;
451 phys_addr_t dst_addr;
452 enum dma_slave_buswidth src_addr_width;
453 enum dma_slave_buswidth dst_addr_width;
454 u32 src_maxburst;
455 u32 dst_maxburst;
456 u32 src_port_window_size;
457 u32 dst_port_window_size;
458 bool device_fc;
459 void *peripheral_config;
460 size_t peripheral_size;
461 };
462
463 /**
464 * enum dma_residue_granularity - Granularity of the reported transfer residue
465 * @DMA_RESIDUE_GRANULARITY_DESCRIPTOR: Residue reporting is not support. The
466 * DMA channel is only able to tell whether a descriptor has been completed or
467 * not, which means residue reporting is not supported by this channel. The
468 * residue field of the dma_tx_state field will always be 0.
469 * @DMA_RESIDUE_GRANULARITY_SEGMENT: Residue is updated after each successfully
470 * completed segment of the transfer (For cyclic transfers this is after each
471 * period). This is typically implemented by having the hardware generate an
472 * interrupt after each transferred segment and then the drivers updates the
473 * outstanding residue by the size of the segment. Another possibility is if
474 * the hardware supports scatter-gather and the segment descriptor has a field
475 * which gets set after the segment has been completed. The driver then counts
476 * the number of segments without the flag set to compute the residue.
477 * @DMA_RESIDUE_GRANULARITY_BURST: Residue is updated after each transferred
478 * burst. This is typically only supported if the hardware has a progress
479 * register of some sort (E.g. a register with the current read/write address
480 * or a register with the amount of bursts/beats/bytes that have been
481 * transferred or still need to be transferred).
482 */
483 enum dma_residue_granularity {
484 DMA_RESIDUE_GRANULARITY_DESCRIPTOR = 0,
485 DMA_RESIDUE_GRANULARITY_SEGMENT = 1,
486 DMA_RESIDUE_GRANULARITY_BURST = 2,
487 };
488
489 /**
490 * struct dma_slave_caps - expose capabilities of a slave channel only
491 * @src_addr_widths: bit mask of src addr widths the channel supports.
492 * Width is specified in bytes, e.g. for a channel supporting
493 * a width of 4 the mask should have BIT(4) set.
494 * @dst_addr_widths: bit mask of dst addr widths the channel supports
495 * @directions: bit mask of slave directions the channel supports.
496 * Since the enum dma_transfer_direction is not defined as bit flag for
497 * each type, the dma controller should set BIT(<TYPE>) and same
498 * should be checked by controller as well
499 * @min_burst: min burst capability per-transfer
500 * @max_burst: max burst capability per-transfer
501 * @max_sg_burst: max number of SG list entries executed in a single burst
502 * DMA tansaction with no software intervention for reinitialization.
503 * Zero value means unlimited number of entries.
504 * @cmd_pause: true, if pause is supported (i.e. for reading residue or
505 * for resume later)
506 * @cmd_resume: true, if resume is supported
507 * @cmd_terminate: true, if terminate cmd is supported
508 * @residue_granularity: granularity of the reported transfer residue
509 * @descriptor_reuse: if a descriptor can be reused by client and
510 * resubmitted multiple times
511 */
512 struct dma_slave_caps {
513 u32 src_addr_widths;
514 u32 dst_addr_widths;
515 u32 directions;
516 u32 min_burst;
517 u32 max_burst;
518 u32 max_sg_burst;
519 bool cmd_pause;
520 bool cmd_resume;
521 bool cmd_terminate;
522 enum dma_residue_granularity residue_granularity;
523 bool descriptor_reuse;
524 };
525
dma_chan_name(struct dma_chan * chan)526 static inline const char *dma_chan_name(struct dma_chan *chan)
527 {
528 return dev_name(&chan->dev->device);
529 }
530
531 /**
532 * typedef dma_filter_fn - callback filter for dma_request_channel
533 * @chan: channel to be reviewed
534 * @filter_param: opaque parameter passed through dma_request_channel
535 *
536 * When this optional parameter is specified in a call to dma_request_channel a
537 * suitable channel is passed to this routine for further dispositioning before
538 * being returned. Where 'suitable' indicates a non-busy channel that
539 * satisfies the given capability mask. It returns 'true' to indicate that the
540 * channel is suitable.
541 */
542 typedef bool (*dma_filter_fn)(struct dma_chan *chan, void *filter_param);
543
544 typedef void (*dma_async_tx_callback)(void *dma_async_param);
545
546 enum dmaengine_tx_result {
547 DMA_TRANS_NOERROR = 0, /* SUCCESS */
548 DMA_TRANS_READ_FAILED, /* Source DMA read failed */
549 DMA_TRANS_WRITE_FAILED, /* Destination DMA write failed */
550 DMA_TRANS_ABORTED, /* Op never submitted / aborted */
551 };
552
553 struct dmaengine_result {
554 enum dmaengine_tx_result result;
555 u32 residue;
556 };
557
558 typedef void (*dma_async_tx_callback_result)(void *dma_async_param,
559 const struct dmaengine_result *result);
560
561 struct dmaengine_unmap_data {
562 #if IS_ENABLED(CONFIG_DMA_ENGINE_RAID)
563 u16 map_cnt;
564 #else
565 u8 map_cnt;
566 #endif
567 u8 to_cnt;
568 u8 from_cnt;
569 u8 bidi_cnt;
570 struct device *dev;
571 struct kref kref;
572 size_t len;
573 dma_addr_t addr[];
574 };
575
576 struct dma_async_tx_descriptor;
577
578 struct dma_descriptor_metadata_ops {
579 int (*attach)(struct dma_async_tx_descriptor *desc, void *data,
580 size_t len);
581
582 void *(*get_ptr)(struct dma_async_tx_descriptor *desc,
583 size_t *payload_len, size_t *max_len);
584 int (*set_len)(struct dma_async_tx_descriptor *desc,
585 size_t payload_len);
586 };
587
588 /**
589 * struct dma_async_tx_descriptor - async transaction descriptor
590 * ---dma generic offload fields---
591 * @cookie: tracking cookie for this transaction, set to -EBUSY if
592 * this tx is sitting on a dependency list
593 * @flags: flags to augment operation preparation, control completion, and
594 * communicate status
595 * @phys: physical address of the descriptor
596 * @chan: target channel for this operation
597 * @tx_submit: accept the descriptor, assign ordered cookie and mark the
598 * descriptor pending. To be pushed on .issue_pending() call
599 * @callback: routine to call after this operation is complete
600 * @callback_param: general parameter to pass to the callback routine
601 * @desc_metadata_mode: core managed metadata mode to protect mixed use of
602 * DESC_METADATA_CLIENT or DESC_METADATA_ENGINE. Otherwise
603 * DESC_METADATA_NONE
604 * @metadata_ops: DMA driver provided metadata mode ops, need to be set by the
605 * DMA driver if metadata mode is supported with the descriptor
606 * ---async_tx api specific fields---
607 * @next: at completion submit this descriptor
608 * @parent: pointer to the next level up in the dependency chain
609 * @lock: protect the parent and next pointers
610 */
611 struct dma_async_tx_descriptor {
612 dma_cookie_t cookie;
613 enum dma_ctrl_flags flags; /* not a 'long' to pack with cookie */
614 dma_addr_t phys;
615 struct dma_chan *chan;
616 dma_cookie_t (*tx_submit)(struct dma_async_tx_descriptor *tx);
617 int (*desc_free)(struct dma_async_tx_descriptor *tx);
618 dma_async_tx_callback callback;
619 dma_async_tx_callback_result callback_result;
620 void *callback_param;
621 struct dmaengine_unmap_data *unmap;
622 enum dma_desc_metadata_mode desc_metadata_mode;
623 struct dma_descriptor_metadata_ops *metadata_ops;
624 #ifdef CONFIG_ASYNC_TX_ENABLE_CHANNEL_SWITCH
625 struct dma_async_tx_descriptor *next;
626 struct dma_async_tx_descriptor *parent;
627 spinlock_t lock;
628 #endif
629
630 ANDROID_KABI_RESERVE(1);
631 ANDROID_KABI_RESERVE(2);
632 ANDROID_KABI_RESERVE(3);
633 ANDROID_KABI_RESERVE(4);
634 };
635
636 #ifdef CONFIG_DMA_ENGINE
dma_set_unmap(struct dma_async_tx_descriptor * tx,struct dmaengine_unmap_data * unmap)637 static inline void dma_set_unmap(struct dma_async_tx_descriptor *tx,
638 struct dmaengine_unmap_data *unmap)
639 {
640 kref_get(&unmap->kref);
641 tx->unmap = unmap;
642 }
643
644 struct dmaengine_unmap_data *
645 dmaengine_get_unmap_data(struct device *dev, int nr, gfp_t flags);
646 void dmaengine_unmap_put(struct dmaengine_unmap_data *unmap);
647 #else
dma_set_unmap(struct dma_async_tx_descriptor * tx,struct dmaengine_unmap_data * unmap)648 static inline void dma_set_unmap(struct dma_async_tx_descriptor *tx,
649 struct dmaengine_unmap_data *unmap)
650 {
651 }
652 static inline struct dmaengine_unmap_data *
dmaengine_get_unmap_data(struct device * dev,int nr,gfp_t flags)653 dmaengine_get_unmap_data(struct device *dev, int nr, gfp_t flags)
654 {
655 return NULL;
656 }
dmaengine_unmap_put(struct dmaengine_unmap_data * unmap)657 static inline void dmaengine_unmap_put(struct dmaengine_unmap_data *unmap)
658 {
659 }
660 #endif
661
dma_descriptor_unmap(struct dma_async_tx_descriptor * tx)662 static inline void dma_descriptor_unmap(struct dma_async_tx_descriptor *tx)
663 {
664 if (!tx->unmap)
665 return;
666
667 dmaengine_unmap_put(tx->unmap);
668 tx->unmap = NULL;
669 }
670
671 #ifndef CONFIG_ASYNC_TX_ENABLE_CHANNEL_SWITCH
txd_lock(struct dma_async_tx_descriptor * txd)672 static inline void txd_lock(struct dma_async_tx_descriptor *txd)
673 {
674 }
txd_unlock(struct dma_async_tx_descriptor * txd)675 static inline void txd_unlock(struct dma_async_tx_descriptor *txd)
676 {
677 }
txd_chain(struct dma_async_tx_descriptor * txd,struct dma_async_tx_descriptor * next)678 static inline void txd_chain(struct dma_async_tx_descriptor *txd, struct dma_async_tx_descriptor *next)
679 {
680 BUG();
681 }
txd_clear_parent(struct dma_async_tx_descriptor * txd)682 static inline void txd_clear_parent(struct dma_async_tx_descriptor *txd)
683 {
684 }
txd_clear_next(struct dma_async_tx_descriptor * txd)685 static inline void txd_clear_next(struct dma_async_tx_descriptor *txd)
686 {
687 }
txd_next(struct dma_async_tx_descriptor * txd)688 static inline struct dma_async_tx_descriptor *txd_next(struct dma_async_tx_descriptor *txd)
689 {
690 return NULL;
691 }
txd_parent(struct dma_async_tx_descriptor * txd)692 static inline struct dma_async_tx_descriptor *txd_parent(struct dma_async_tx_descriptor *txd)
693 {
694 return NULL;
695 }
696
697 #else
txd_lock(struct dma_async_tx_descriptor * txd)698 static inline void txd_lock(struct dma_async_tx_descriptor *txd)
699 {
700 spin_lock_bh(&txd->lock);
701 }
txd_unlock(struct dma_async_tx_descriptor * txd)702 static inline void txd_unlock(struct dma_async_tx_descriptor *txd)
703 {
704 spin_unlock_bh(&txd->lock);
705 }
txd_chain(struct dma_async_tx_descriptor * txd,struct dma_async_tx_descriptor * next)706 static inline void txd_chain(struct dma_async_tx_descriptor *txd, struct dma_async_tx_descriptor *next)
707 {
708 txd->next = next;
709 next->parent = txd;
710 }
txd_clear_parent(struct dma_async_tx_descriptor * txd)711 static inline void txd_clear_parent(struct dma_async_tx_descriptor *txd)
712 {
713 txd->parent = NULL;
714 }
txd_clear_next(struct dma_async_tx_descriptor * txd)715 static inline void txd_clear_next(struct dma_async_tx_descriptor *txd)
716 {
717 txd->next = NULL;
718 }
txd_parent(struct dma_async_tx_descriptor * txd)719 static inline struct dma_async_tx_descriptor *txd_parent(struct dma_async_tx_descriptor *txd)
720 {
721 return txd->parent;
722 }
txd_next(struct dma_async_tx_descriptor * txd)723 static inline struct dma_async_tx_descriptor *txd_next(struct dma_async_tx_descriptor *txd)
724 {
725 return txd->next;
726 }
727 #endif
728
729 /**
730 * struct dma_tx_state - filled in to report the status of
731 * a transfer.
732 * @last: last completed DMA cookie
733 * @used: last issued DMA cookie (i.e. the one in progress)
734 * @residue: the remaining number of bytes left to transmit
735 * on the selected transfer for states DMA_IN_PROGRESS and
736 * DMA_PAUSED if this is implemented in the driver, else 0
737 * @in_flight_bytes: amount of data in bytes cached by the DMA.
738 */
739 struct dma_tx_state {
740 dma_cookie_t last;
741 dma_cookie_t used;
742 u32 residue;
743 u32 in_flight_bytes;
744 };
745
746 /**
747 * enum dmaengine_alignment - defines alignment of the DMA async tx
748 * buffers
749 */
750 enum dmaengine_alignment {
751 DMAENGINE_ALIGN_1_BYTE = 0,
752 DMAENGINE_ALIGN_2_BYTES = 1,
753 DMAENGINE_ALIGN_4_BYTES = 2,
754 DMAENGINE_ALIGN_8_BYTES = 3,
755 DMAENGINE_ALIGN_16_BYTES = 4,
756 DMAENGINE_ALIGN_32_BYTES = 5,
757 DMAENGINE_ALIGN_64_BYTES = 6,
758 DMAENGINE_ALIGN_128_BYTES = 7,
759 DMAENGINE_ALIGN_256_BYTES = 8,
760 };
761
762 /**
763 * struct dma_slave_map - associates slave device and it's slave channel with
764 * parameter to be used by a filter function
765 * @devname: name of the device
766 * @slave: slave channel name
767 * @param: opaque parameter to pass to struct dma_filter.fn
768 */
769 struct dma_slave_map {
770 const char *devname;
771 const char *slave;
772 void *param;
773 };
774
775 /**
776 * struct dma_filter - information for slave device/channel to filter_fn/param
777 * mapping
778 * @fn: filter function callback
779 * @mapcnt: number of slave device/channel in the map
780 * @map: array of channel to filter mapping data
781 */
782 struct dma_filter {
783 dma_filter_fn fn;
784 int mapcnt;
785 const struct dma_slave_map *map;
786 };
787
788 /**
789 * struct dma_device - info on the entity supplying DMA services
790 * @ref: reference is taken and put every time a channel is allocated or freed
791 * @chancnt: how many DMA channels are supported
792 * @privatecnt: how many DMA channels are requested by dma_request_channel
793 * @channels: the list of struct dma_chan
794 * @global_node: list_head for global dma_device_list
795 * @filter: information for device/slave to filter function/param mapping
796 * @cap_mask: one or more dma_capability flags
797 * @desc_metadata_modes: supported metadata modes by the DMA device
798 * @max_xor: maximum number of xor sources, 0 if no capability
799 * @max_pq: maximum number of PQ sources and PQ-continue capability
800 * @copy_align: alignment shift for memcpy operations
801 * @xor_align: alignment shift for xor operations
802 * @pq_align: alignment shift for pq operations
803 * @fill_align: alignment shift for memset operations
804 * @dev_id: unique device ID
805 * @dev: struct device reference for dma mapping api
806 * @owner: owner module (automatically set based on the provided dev)
807 * @chan_ida: unique channel ID
808 * @src_addr_widths: bit mask of src addr widths the device supports
809 * Width is specified in bytes, e.g. for a device supporting
810 * a width of 4 the mask should have BIT(4) set.
811 * @dst_addr_widths: bit mask of dst addr widths the device supports
812 * @directions: bit mask of slave directions the device supports.
813 * Since the enum dma_transfer_direction is not defined as bit flag for
814 * each type, the dma controller should set BIT(<TYPE>) and same
815 * should be checked by controller as well
816 * @min_burst: min burst capability per-transfer
817 * @max_burst: max burst capability per-transfer
818 * @max_sg_burst: max number of SG list entries executed in a single burst
819 * DMA tansaction with no software intervention for reinitialization.
820 * Zero value means unlimited number of entries.
821 * @descriptor_reuse: a submitted transfer can be resubmitted after completion
822 * @residue_granularity: granularity of the transfer residue reported
823 * by tx_status
824 * @device_alloc_chan_resources: allocate resources and return the
825 * number of allocated descriptors
826 * @device_router_config: optional callback for DMA router configuration
827 * @device_free_chan_resources: release DMA channel's resources
828 * @device_prep_dma_memcpy: prepares a memcpy operation
829 * @device_prep_dma_xor: prepares a xor operation
830 * @device_prep_dma_xor_val: prepares a xor validation operation
831 * @device_prep_dma_pq: prepares a pq operation
832 * @device_prep_dma_pq_val: prepares a pqzero_sum operation
833 * @device_prep_dma_memset: prepares a memset operation
834 * @device_prep_dma_memset_sg: prepares a memset operation over a scatter list
835 * @device_prep_dma_interrupt: prepares an end of chain interrupt operation
836 * @device_prep_slave_sg: prepares a slave dma operation
837 * @device_prep_dma_cyclic: prepare a cyclic dma operation suitable for audio.
838 * The function takes a buffer of size buf_len. The callback function will
839 * be called after period_len bytes have been transferred.
840 * @device_prep_interleaved_dma: Transfer expression in a generic way.
841 * @device_prep_dma_imm_data: DMA's 8 byte immediate data to the dst address
842 * @device_caps: May be used to override the generic DMA slave capabilities
843 * with per-channel specific ones
844 * @device_config: Pushes a new configuration to a channel, return 0 or an error
845 * code
846 * @device_pause: Pauses any transfer happening on a channel. Returns
847 * 0 or an error code
848 * @device_resume: Resumes any transfer on a channel previously
849 * paused. Returns 0 or an error code
850 * @device_terminate_all: Aborts all transfers on a channel. Returns 0
851 * or an error code
852 * @device_synchronize: Synchronizes the termination of a transfers to the
853 * current context.
854 * @device_tx_status: poll for transaction completion, the optional
855 * txstate parameter can be supplied with a pointer to get a
856 * struct with auxiliary transfer status information, otherwise the call
857 * will just return a simple status code
858 * @device_issue_pending: push pending transactions to hardware
859 * @device_release: called sometime atfer dma_async_device_unregister() is
860 * called and there are no further references to this structure. This
861 * must be implemented to free resources however many existing drivers
862 * do not and are therefore not safe to unbind while in use.
863 * @dbg_summary_show: optional routine to show contents in debugfs; default code
864 * will be used when this is omitted, but custom code can show extra,
865 * controller specific information.
866 * @dbg_dev_root: the root folder in debugfs for this device
867 */
868 struct dma_device {
869 struct kref ref;
870 unsigned int chancnt;
871 unsigned int privatecnt;
872 struct list_head channels;
873 struct list_head global_node;
874 struct dma_filter filter;
875 dma_cap_mask_t cap_mask;
876 enum dma_desc_metadata_mode desc_metadata_modes;
877 unsigned short max_xor;
878 unsigned short max_pq;
879 enum dmaengine_alignment copy_align;
880 enum dmaengine_alignment xor_align;
881 enum dmaengine_alignment pq_align;
882 enum dmaengine_alignment fill_align;
883 #define DMA_HAS_PQ_CONTINUE (1 << 15)
884
885 int dev_id;
886 struct device *dev;
887 struct module *owner;
888 struct ida chan_ida;
889
890 u32 src_addr_widths;
891 u32 dst_addr_widths;
892 u32 directions;
893 u32 min_burst;
894 u32 max_burst;
895 u32 max_sg_burst;
896 bool descriptor_reuse;
897 enum dma_residue_granularity residue_granularity;
898
899 int (*device_alloc_chan_resources)(struct dma_chan *chan);
900 int (*device_router_config)(struct dma_chan *chan);
901 void (*device_free_chan_resources)(struct dma_chan *chan);
902
903 struct dma_async_tx_descriptor *(*device_prep_dma_memcpy)(
904 struct dma_chan *chan, dma_addr_t dst, dma_addr_t src,
905 size_t len, unsigned long flags);
906 struct dma_async_tx_descriptor *(*device_prep_dma_xor)(
907 struct dma_chan *chan, dma_addr_t dst, dma_addr_t *src,
908 unsigned int src_cnt, size_t len, unsigned long flags);
909 struct dma_async_tx_descriptor *(*device_prep_dma_xor_val)(
910 struct dma_chan *chan, dma_addr_t *src, unsigned int src_cnt,
911 size_t len, enum sum_check_flags *result, unsigned long flags);
912 struct dma_async_tx_descriptor *(*device_prep_dma_pq)(
913 struct dma_chan *chan, dma_addr_t *dst, dma_addr_t *src,
914 unsigned int src_cnt, const unsigned char *scf,
915 size_t len, unsigned long flags);
916 struct dma_async_tx_descriptor *(*device_prep_dma_pq_val)(
917 struct dma_chan *chan, dma_addr_t *pq, dma_addr_t *src,
918 unsigned int src_cnt, const unsigned char *scf, size_t len,
919 enum sum_check_flags *pqres, unsigned long flags);
920 struct dma_async_tx_descriptor *(*device_prep_dma_memset)(
921 struct dma_chan *chan, dma_addr_t dest, int value, size_t len,
922 unsigned long flags);
923 struct dma_async_tx_descriptor *(*device_prep_dma_memset_sg)(
924 struct dma_chan *chan, struct scatterlist *sg,
925 unsigned int nents, int value, unsigned long flags);
926 struct dma_async_tx_descriptor *(*device_prep_dma_interrupt)(
927 struct dma_chan *chan, unsigned long flags);
928
929 struct dma_async_tx_descriptor *(*device_prep_peripheral_dma_vec)(
930 struct dma_chan *chan, const struct dma_vec *vecs,
931 size_t nents, enum dma_transfer_direction direction,
932 unsigned long flags);
933 struct dma_async_tx_descriptor *(*device_prep_slave_sg)(
934 struct dma_chan *chan, struct scatterlist *sgl,
935 unsigned int sg_len, enum dma_transfer_direction direction,
936 unsigned long flags, void *context);
937 struct dma_async_tx_descriptor *(*device_prep_dma_cyclic)(
938 struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len,
939 size_t period_len, enum dma_transfer_direction direction,
940 unsigned long flags);
941 struct dma_async_tx_descriptor *(*device_prep_interleaved_dma)(
942 struct dma_chan *chan, struct dma_interleaved_template *xt,
943 unsigned long flags);
944 struct dma_async_tx_descriptor *(*device_prep_dma_imm_data)(
945 struct dma_chan *chan, dma_addr_t dst, u64 data,
946 unsigned long flags);
947
948 void (*device_caps)(struct dma_chan *chan, struct dma_slave_caps *caps);
949 int (*device_config)(struct dma_chan *chan, struct dma_slave_config *config);
950 int (*device_pause)(struct dma_chan *chan);
951 int (*device_resume)(struct dma_chan *chan);
952 int (*device_terminate_all)(struct dma_chan *chan);
953 void (*device_synchronize)(struct dma_chan *chan);
954
955 enum dma_status (*device_tx_status)(struct dma_chan *chan,
956 dma_cookie_t cookie,
957 struct dma_tx_state *txstate);
958 void (*device_issue_pending)(struct dma_chan *chan);
959 void (*device_release)(struct dma_device *dev);
960 /* debugfs support */
961 void (*dbg_summary_show)(struct seq_file *s, struct dma_device *dev);
962 struct dentry *dbg_dev_root;
963 };
964
dmaengine_slave_config(struct dma_chan * chan,struct dma_slave_config * config)965 static inline int dmaengine_slave_config(struct dma_chan *chan,
966 struct dma_slave_config *config)
967 {
968 if (chan->device->device_config)
969 return chan->device->device_config(chan, config);
970
971 return -ENOSYS;
972 }
973
is_slave_direction(enum dma_transfer_direction direction)974 static inline bool is_slave_direction(enum dma_transfer_direction direction)
975 {
976 return (direction == DMA_MEM_TO_DEV) || (direction == DMA_DEV_TO_MEM) ||
977 (direction == DMA_DEV_TO_DEV);
978 }
979
dmaengine_prep_slave_single(struct dma_chan * chan,dma_addr_t buf,size_t len,enum dma_transfer_direction dir,unsigned long flags)980 static inline struct dma_async_tx_descriptor *dmaengine_prep_slave_single(
981 struct dma_chan *chan, dma_addr_t buf, size_t len,
982 enum dma_transfer_direction dir, unsigned long flags)
983 {
984 struct scatterlist sg;
985 sg_init_table(&sg, 1);
986 sg_dma_address(&sg) = buf;
987 sg_dma_len(&sg) = len;
988
989 if (!chan || !chan->device || !chan->device->device_prep_slave_sg)
990 return NULL;
991
992 return chan->device->device_prep_slave_sg(chan, &sg, 1,
993 dir, flags, NULL);
994 }
995
996 /**
997 * dmaengine_prep_peripheral_dma_vec() - Prepare a DMA scatter-gather descriptor
998 * @chan: The channel to be used for this descriptor
999 * @vecs: The array of DMA vectors that should be transferred
1000 * @nents: The number of DMA vectors in the array
1001 * @dir: Specifies the direction of the data transfer
1002 * @flags: DMA engine flags
1003 */
dmaengine_prep_peripheral_dma_vec(struct dma_chan * chan,const struct dma_vec * vecs,size_t nents,enum dma_transfer_direction dir,unsigned long flags)1004 static inline struct dma_async_tx_descriptor *dmaengine_prep_peripheral_dma_vec(
1005 struct dma_chan *chan, const struct dma_vec *vecs, size_t nents,
1006 enum dma_transfer_direction dir, unsigned long flags)
1007 {
1008 if (!chan || !chan->device || !chan->device->device_prep_peripheral_dma_vec)
1009 return NULL;
1010
1011 return chan->device->device_prep_peripheral_dma_vec(chan, vecs, nents,
1012 dir, flags);
1013 }
1014
dmaengine_prep_slave_sg(struct dma_chan * chan,struct scatterlist * sgl,unsigned int sg_len,enum dma_transfer_direction dir,unsigned long flags)1015 static inline struct dma_async_tx_descriptor *dmaengine_prep_slave_sg(
1016 struct dma_chan *chan, struct scatterlist *sgl, unsigned int sg_len,
1017 enum dma_transfer_direction dir, unsigned long flags)
1018 {
1019 if (!chan || !chan->device || !chan->device->device_prep_slave_sg)
1020 return NULL;
1021
1022 return chan->device->device_prep_slave_sg(chan, sgl, sg_len,
1023 dir, flags, NULL);
1024 }
1025
1026 #ifdef CONFIG_RAPIDIO_DMA_ENGINE
1027 struct rio_dma_ext;
dmaengine_prep_rio_sg(struct dma_chan * chan,struct scatterlist * sgl,unsigned int sg_len,enum dma_transfer_direction dir,unsigned long flags,struct rio_dma_ext * rio_ext)1028 static inline struct dma_async_tx_descriptor *dmaengine_prep_rio_sg(
1029 struct dma_chan *chan, struct scatterlist *sgl, unsigned int sg_len,
1030 enum dma_transfer_direction dir, unsigned long flags,
1031 struct rio_dma_ext *rio_ext)
1032 {
1033 if (!chan || !chan->device || !chan->device->device_prep_slave_sg)
1034 return NULL;
1035
1036 return chan->device->device_prep_slave_sg(chan, sgl, sg_len,
1037 dir, flags, rio_ext);
1038 }
1039 #endif
1040
dmaengine_prep_dma_cyclic(struct dma_chan * chan,dma_addr_t buf_addr,size_t buf_len,size_t period_len,enum dma_transfer_direction dir,unsigned long flags)1041 static inline struct dma_async_tx_descriptor *dmaengine_prep_dma_cyclic(
1042 struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len,
1043 size_t period_len, enum dma_transfer_direction dir,
1044 unsigned long flags)
1045 {
1046 if (!chan || !chan->device || !chan->device->device_prep_dma_cyclic)
1047 return NULL;
1048
1049 return chan->device->device_prep_dma_cyclic(chan, buf_addr, buf_len,
1050 period_len, dir, flags);
1051 }
1052
dmaengine_prep_interleaved_dma(struct dma_chan * chan,struct dma_interleaved_template * xt,unsigned long flags)1053 static inline struct dma_async_tx_descriptor *dmaengine_prep_interleaved_dma(
1054 struct dma_chan *chan, struct dma_interleaved_template *xt,
1055 unsigned long flags)
1056 {
1057 if (!chan || !chan->device || !chan->device->device_prep_interleaved_dma)
1058 return NULL;
1059 if (flags & DMA_PREP_REPEAT &&
1060 !test_bit(DMA_REPEAT, chan->device->cap_mask.bits))
1061 return NULL;
1062
1063 return chan->device->device_prep_interleaved_dma(chan, xt, flags);
1064 }
1065
1066 /**
1067 * dmaengine_prep_dma_memset() - Prepare a DMA memset descriptor.
1068 * @chan: The channel to be used for this descriptor
1069 * @dest: Address of buffer to be set
1070 * @value: Treated as a single byte value that fills the destination buffer
1071 * @len: The total size of dest
1072 * @flags: DMA engine flags
1073 */
dmaengine_prep_dma_memset(struct dma_chan * chan,dma_addr_t dest,int value,size_t len,unsigned long flags)1074 static inline struct dma_async_tx_descriptor *dmaengine_prep_dma_memset(
1075 struct dma_chan *chan, dma_addr_t dest, int value, size_t len,
1076 unsigned long flags)
1077 {
1078 if (!chan || !chan->device || !chan->device->device_prep_dma_memset)
1079 return NULL;
1080
1081 return chan->device->device_prep_dma_memset(chan, dest, value,
1082 len, flags);
1083 }
1084
dmaengine_prep_dma_memcpy(struct dma_chan * chan,dma_addr_t dest,dma_addr_t src,size_t len,unsigned long flags)1085 static inline struct dma_async_tx_descriptor *dmaengine_prep_dma_memcpy(
1086 struct dma_chan *chan, dma_addr_t dest, dma_addr_t src,
1087 size_t len, unsigned long flags)
1088 {
1089 if (!chan || !chan->device || !chan->device->device_prep_dma_memcpy)
1090 return NULL;
1091
1092 return chan->device->device_prep_dma_memcpy(chan, dest, src,
1093 len, flags);
1094 }
1095
dmaengine_is_metadata_mode_supported(struct dma_chan * chan,enum dma_desc_metadata_mode mode)1096 static inline bool dmaengine_is_metadata_mode_supported(struct dma_chan *chan,
1097 enum dma_desc_metadata_mode mode)
1098 {
1099 if (!chan)
1100 return false;
1101
1102 return !!(chan->device->desc_metadata_modes & mode);
1103 }
1104
1105 #ifdef CONFIG_DMA_ENGINE
1106 int dmaengine_desc_attach_metadata(struct dma_async_tx_descriptor *desc,
1107 void *data, size_t len);
1108 void *dmaengine_desc_get_metadata_ptr(struct dma_async_tx_descriptor *desc,
1109 size_t *payload_len, size_t *max_len);
1110 int dmaengine_desc_set_metadata_len(struct dma_async_tx_descriptor *desc,
1111 size_t payload_len);
1112 #else /* CONFIG_DMA_ENGINE */
dmaengine_desc_attach_metadata(struct dma_async_tx_descriptor * desc,void * data,size_t len)1113 static inline int dmaengine_desc_attach_metadata(
1114 struct dma_async_tx_descriptor *desc, void *data, size_t len)
1115 {
1116 return -EINVAL;
1117 }
dmaengine_desc_get_metadata_ptr(struct dma_async_tx_descriptor * desc,size_t * payload_len,size_t * max_len)1118 static inline void *dmaengine_desc_get_metadata_ptr(
1119 struct dma_async_tx_descriptor *desc, size_t *payload_len,
1120 size_t *max_len)
1121 {
1122 return NULL;
1123 }
dmaengine_desc_set_metadata_len(struct dma_async_tx_descriptor * desc,size_t payload_len)1124 static inline int dmaengine_desc_set_metadata_len(
1125 struct dma_async_tx_descriptor *desc, size_t payload_len)
1126 {
1127 return -EINVAL;
1128 }
1129 #endif /* CONFIG_DMA_ENGINE */
1130
1131 /**
1132 * dmaengine_terminate_all() - Terminate all active DMA transfers
1133 * @chan: The channel for which to terminate the transfers
1134 *
1135 * This function is DEPRECATED use either dmaengine_terminate_sync() or
1136 * dmaengine_terminate_async() instead.
1137 */
dmaengine_terminate_all(struct dma_chan * chan)1138 static inline int dmaengine_terminate_all(struct dma_chan *chan)
1139 {
1140 if (chan->device->device_terminate_all)
1141 return chan->device->device_terminate_all(chan);
1142
1143 return -ENOSYS;
1144 }
1145
1146 /**
1147 * dmaengine_terminate_async() - Terminate all active DMA transfers
1148 * @chan: The channel for which to terminate the transfers
1149 *
1150 * Calling this function will terminate all active and pending descriptors
1151 * that have previously been submitted to the channel. It is not guaranteed
1152 * though that the transfer for the active descriptor has stopped when the
1153 * function returns. Furthermore it is possible the complete callback of a
1154 * submitted transfer is still running when this function returns.
1155 *
1156 * dmaengine_synchronize() needs to be called before it is safe to free
1157 * any memory that is accessed by previously submitted descriptors or before
1158 * freeing any resources accessed from within the completion callback of any
1159 * previously submitted descriptors.
1160 *
1161 * This function can be called from atomic context as well as from within a
1162 * complete callback of a descriptor submitted on the same channel.
1163 *
1164 * If none of the two conditions above apply consider using
1165 * dmaengine_terminate_sync() instead.
1166 */
dmaengine_terminate_async(struct dma_chan * chan)1167 static inline int dmaengine_terminate_async(struct dma_chan *chan)
1168 {
1169 if (chan->device->device_terminate_all)
1170 return chan->device->device_terminate_all(chan);
1171
1172 return -EINVAL;
1173 }
1174
1175 /**
1176 * dmaengine_synchronize() - Synchronize DMA channel termination
1177 * @chan: The channel to synchronize
1178 *
1179 * Synchronizes to the DMA channel termination to the current context. When this
1180 * function returns it is guaranteed that all transfers for previously issued
1181 * descriptors have stopped and it is safe to free the memory associated
1182 * with them. Furthermore it is guaranteed that all complete callback functions
1183 * for a previously submitted descriptor have finished running and it is safe to
1184 * free resources accessed from within the complete callbacks.
1185 *
1186 * The behavior of this function is undefined if dma_async_issue_pending() has
1187 * been called between dmaengine_terminate_async() and this function.
1188 *
1189 * This function must only be called from non-atomic context and must not be
1190 * called from within a complete callback of a descriptor submitted on the same
1191 * channel.
1192 */
dmaengine_synchronize(struct dma_chan * chan)1193 static inline void dmaengine_synchronize(struct dma_chan *chan)
1194 {
1195 might_sleep();
1196
1197 if (chan->device->device_synchronize)
1198 chan->device->device_synchronize(chan);
1199 }
1200
1201 /**
1202 * dmaengine_terminate_sync() - Terminate all active DMA transfers
1203 * @chan: The channel for which to terminate the transfers
1204 *
1205 * Calling this function will terminate all active and pending transfers
1206 * that have previously been submitted to the channel. It is similar to
1207 * dmaengine_terminate_async() but guarantees that the DMA transfer has actually
1208 * stopped and that all complete callbacks have finished running when the
1209 * function returns.
1210 *
1211 * This function must only be called from non-atomic context and must not be
1212 * called from within a complete callback of a descriptor submitted on the same
1213 * channel.
1214 */
dmaengine_terminate_sync(struct dma_chan * chan)1215 static inline int dmaengine_terminate_sync(struct dma_chan *chan)
1216 {
1217 int ret;
1218
1219 ret = dmaengine_terminate_async(chan);
1220 if (ret)
1221 return ret;
1222
1223 dmaengine_synchronize(chan);
1224
1225 return 0;
1226 }
1227
dmaengine_pause(struct dma_chan * chan)1228 static inline int dmaengine_pause(struct dma_chan *chan)
1229 {
1230 if (chan->device->device_pause)
1231 return chan->device->device_pause(chan);
1232
1233 return -ENOSYS;
1234 }
1235
dmaengine_resume(struct dma_chan * chan)1236 static inline int dmaengine_resume(struct dma_chan *chan)
1237 {
1238 if (chan->device->device_resume)
1239 return chan->device->device_resume(chan);
1240
1241 return -ENOSYS;
1242 }
1243
dmaengine_tx_status(struct dma_chan * chan,dma_cookie_t cookie,struct dma_tx_state * state)1244 static inline enum dma_status dmaengine_tx_status(struct dma_chan *chan,
1245 dma_cookie_t cookie, struct dma_tx_state *state)
1246 {
1247 return chan->device->device_tx_status(chan, cookie, state);
1248 }
1249
dmaengine_submit(struct dma_async_tx_descriptor * desc)1250 static inline dma_cookie_t dmaengine_submit(struct dma_async_tx_descriptor *desc)
1251 {
1252 return desc->tx_submit(desc);
1253 }
1254
dmaengine_check_align(enum dmaengine_alignment align,size_t off1,size_t off2,size_t len)1255 static inline bool dmaengine_check_align(enum dmaengine_alignment align,
1256 size_t off1, size_t off2, size_t len)
1257 {
1258 return !(((1 << align) - 1) & (off1 | off2 | len));
1259 }
1260
is_dma_copy_aligned(struct dma_device * dev,size_t off1,size_t off2,size_t len)1261 static inline bool is_dma_copy_aligned(struct dma_device *dev, size_t off1,
1262 size_t off2, size_t len)
1263 {
1264 return dmaengine_check_align(dev->copy_align, off1, off2, len);
1265 }
1266
is_dma_xor_aligned(struct dma_device * dev,size_t off1,size_t off2,size_t len)1267 static inline bool is_dma_xor_aligned(struct dma_device *dev, size_t off1,
1268 size_t off2, size_t len)
1269 {
1270 return dmaengine_check_align(dev->xor_align, off1, off2, len);
1271 }
1272
is_dma_pq_aligned(struct dma_device * dev,size_t off1,size_t off2,size_t len)1273 static inline bool is_dma_pq_aligned(struct dma_device *dev, size_t off1,
1274 size_t off2, size_t len)
1275 {
1276 return dmaengine_check_align(dev->pq_align, off1, off2, len);
1277 }
1278
is_dma_fill_aligned(struct dma_device * dev,size_t off1,size_t off2,size_t len)1279 static inline bool is_dma_fill_aligned(struct dma_device *dev, size_t off1,
1280 size_t off2, size_t len)
1281 {
1282 return dmaengine_check_align(dev->fill_align, off1, off2, len);
1283 }
1284
1285 static inline void
dma_set_maxpq(struct dma_device * dma,int maxpq,int has_pq_continue)1286 dma_set_maxpq(struct dma_device *dma, int maxpq, int has_pq_continue)
1287 {
1288 dma->max_pq = maxpq;
1289 if (has_pq_continue)
1290 dma->max_pq |= DMA_HAS_PQ_CONTINUE;
1291 }
1292
dmaf_continue(enum dma_ctrl_flags flags)1293 static inline bool dmaf_continue(enum dma_ctrl_flags flags)
1294 {
1295 return (flags & DMA_PREP_CONTINUE) == DMA_PREP_CONTINUE;
1296 }
1297
dmaf_p_disabled_continue(enum dma_ctrl_flags flags)1298 static inline bool dmaf_p_disabled_continue(enum dma_ctrl_flags flags)
1299 {
1300 enum dma_ctrl_flags mask = DMA_PREP_CONTINUE | DMA_PREP_PQ_DISABLE_P;
1301
1302 return (flags & mask) == mask;
1303 }
1304
dma_dev_has_pq_continue(struct dma_device * dma)1305 static inline bool dma_dev_has_pq_continue(struct dma_device *dma)
1306 {
1307 return (dma->max_pq & DMA_HAS_PQ_CONTINUE) == DMA_HAS_PQ_CONTINUE;
1308 }
1309
dma_dev_to_maxpq(struct dma_device * dma)1310 static inline unsigned short dma_dev_to_maxpq(struct dma_device *dma)
1311 {
1312 return dma->max_pq & ~DMA_HAS_PQ_CONTINUE;
1313 }
1314
1315 /* dma_maxpq - reduce maxpq in the face of continued operations
1316 * @dma - dma device with PQ capability
1317 * @flags - to check if DMA_PREP_CONTINUE and DMA_PREP_PQ_DISABLE_P are set
1318 *
1319 * When an engine does not support native continuation we need 3 extra
1320 * source slots to reuse P and Q with the following coefficients:
1321 * 1/ {00} * P : remove P from Q', but use it as a source for P'
1322 * 2/ {01} * Q : use Q to continue Q' calculation
1323 * 3/ {00} * Q : subtract Q from P' to cancel (2)
1324 *
1325 * In the case where P is disabled we only need 1 extra source:
1326 * 1/ {01} * Q : use Q to continue Q' calculation
1327 */
dma_maxpq(struct dma_device * dma,enum dma_ctrl_flags flags)1328 static inline int dma_maxpq(struct dma_device *dma, enum dma_ctrl_flags flags)
1329 {
1330 if (dma_dev_has_pq_continue(dma) || !dmaf_continue(flags))
1331 return dma_dev_to_maxpq(dma);
1332 if (dmaf_p_disabled_continue(flags))
1333 return dma_dev_to_maxpq(dma) - 1;
1334 if (dmaf_continue(flags))
1335 return dma_dev_to_maxpq(dma) - 3;
1336 BUG();
1337 }
1338
dmaengine_get_icg(bool inc,bool sgl,size_t icg,size_t dir_icg)1339 static inline size_t dmaengine_get_icg(bool inc, bool sgl, size_t icg,
1340 size_t dir_icg)
1341 {
1342 if (inc) {
1343 if (dir_icg)
1344 return dir_icg;
1345 if (sgl)
1346 return icg;
1347 }
1348
1349 return 0;
1350 }
1351
dmaengine_get_dst_icg(struct dma_interleaved_template * xt,struct data_chunk * chunk)1352 static inline size_t dmaengine_get_dst_icg(struct dma_interleaved_template *xt,
1353 struct data_chunk *chunk)
1354 {
1355 return dmaengine_get_icg(xt->dst_inc, xt->dst_sgl,
1356 chunk->icg, chunk->dst_icg);
1357 }
1358
dmaengine_get_src_icg(struct dma_interleaved_template * xt,struct data_chunk * chunk)1359 static inline size_t dmaengine_get_src_icg(struct dma_interleaved_template *xt,
1360 struct data_chunk *chunk)
1361 {
1362 return dmaengine_get_icg(xt->src_inc, xt->src_sgl,
1363 chunk->icg, chunk->src_icg);
1364 }
1365
1366 /* --- public DMA engine API --- */
1367
1368 #ifdef CONFIG_DMA_ENGINE
1369 void dmaengine_get(void);
1370 void dmaengine_put(void);
1371 #else
dmaengine_get(void)1372 static inline void dmaengine_get(void)
1373 {
1374 }
dmaengine_put(void)1375 static inline void dmaengine_put(void)
1376 {
1377 }
1378 #endif
1379
1380 #ifdef CONFIG_ASYNC_TX_DMA
1381 #define async_dmaengine_get() dmaengine_get()
1382 #define async_dmaengine_put() dmaengine_put()
1383 #ifndef CONFIG_ASYNC_TX_ENABLE_CHANNEL_SWITCH
1384 #define async_dma_find_channel(type) dma_find_channel(DMA_ASYNC_TX)
1385 #else
1386 #define async_dma_find_channel(type) dma_find_channel(type)
1387 #endif /* CONFIG_ASYNC_TX_ENABLE_CHANNEL_SWITCH */
1388 #else
async_dmaengine_get(void)1389 static inline void async_dmaengine_get(void)
1390 {
1391 }
async_dmaengine_put(void)1392 static inline void async_dmaengine_put(void)
1393 {
1394 }
1395 static inline struct dma_chan *
async_dma_find_channel(enum dma_transaction_type type)1396 async_dma_find_channel(enum dma_transaction_type type)
1397 {
1398 return NULL;
1399 }
1400 #endif /* CONFIG_ASYNC_TX_DMA */
1401 void dma_async_tx_descriptor_init(struct dma_async_tx_descriptor *tx,
1402 struct dma_chan *chan);
1403
async_tx_ack(struct dma_async_tx_descriptor * tx)1404 static inline void async_tx_ack(struct dma_async_tx_descriptor *tx)
1405 {
1406 tx->flags |= DMA_CTRL_ACK;
1407 }
1408
async_tx_clear_ack(struct dma_async_tx_descriptor * tx)1409 static inline void async_tx_clear_ack(struct dma_async_tx_descriptor *tx)
1410 {
1411 tx->flags &= ~DMA_CTRL_ACK;
1412 }
1413
async_tx_test_ack(struct dma_async_tx_descriptor * tx)1414 static inline bool async_tx_test_ack(struct dma_async_tx_descriptor *tx)
1415 {
1416 return (tx->flags & DMA_CTRL_ACK) == DMA_CTRL_ACK;
1417 }
1418
1419 #define dma_cap_set(tx, mask) __dma_cap_set((tx), &(mask))
1420 static inline void
__dma_cap_set(enum dma_transaction_type tx_type,dma_cap_mask_t * dstp)1421 __dma_cap_set(enum dma_transaction_type tx_type, dma_cap_mask_t *dstp)
1422 {
1423 set_bit(tx_type, dstp->bits);
1424 }
1425
1426 #define dma_cap_clear(tx, mask) __dma_cap_clear((tx), &(mask))
1427 static inline void
__dma_cap_clear(enum dma_transaction_type tx_type,dma_cap_mask_t * dstp)1428 __dma_cap_clear(enum dma_transaction_type tx_type, dma_cap_mask_t *dstp)
1429 {
1430 clear_bit(tx_type, dstp->bits);
1431 }
1432
1433 #define dma_cap_zero(mask) __dma_cap_zero(&(mask))
__dma_cap_zero(dma_cap_mask_t * dstp)1434 static inline void __dma_cap_zero(dma_cap_mask_t *dstp)
1435 {
1436 bitmap_zero(dstp->bits, DMA_TX_TYPE_END);
1437 }
1438
1439 #define dma_has_cap(tx, mask) __dma_has_cap((tx), &(mask))
1440 static inline int
__dma_has_cap(enum dma_transaction_type tx_type,dma_cap_mask_t * srcp)1441 __dma_has_cap(enum dma_transaction_type tx_type, dma_cap_mask_t *srcp)
1442 {
1443 return test_bit(tx_type, srcp->bits);
1444 }
1445
1446 #define for_each_dma_cap_mask(cap, mask) \
1447 for_each_set_bit(cap, mask.bits, DMA_TX_TYPE_END)
1448
1449 /**
1450 * dma_async_issue_pending - flush pending transactions to HW
1451 * @chan: target DMA channel
1452 *
1453 * This allows drivers to push copies to HW in batches,
1454 * reducing MMIO writes where possible.
1455 */
dma_async_issue_pending(struct dma_chan * chan)1456 static inline void dma_async_issue_pending(struct dma_chan *chan)
1457 {
1458 chan->device->device_issue_pending(chan);
1459 }
1460
1461 /**
1462 * dma_async_is_tx_complete - poll for transaction completion
1463 * @chan: DMA channel
1464 * @cookie: transaction identifier to check status of
1465 * @last: returns last completed cookie, can be NULL
1466 * @used: returns last issued cookie, can be NULL
1467 *
1468 * If @last and @used are passed in, upon return they reflect the driver
1469 * internal state and can be used with dma_async_is_complete() to check
1470 * the status of multiple cookies without re-checking hardware state.
1471 */
dma_async_is_tx_complete(struct dma_chan * chan,dma_cookie_t cookie,dma_cookie_t * last,dma_cookie_t * used)1472 static inline enum dma_status dma_async_is_tx_complete(struct dma_chan *chan,
1473 dma_cookie_t cookie, dma_cookie_t *last, dma_cookie_t *used)
1474 {
1475 struct dma_tx_state state;
1476 enum dma_status status;
1477
1478 status = chan->device->device_tx_status(chan, cookie, &state);
1479 if (last)
1480 *last = state.last;
1481 if (used)
1482 *used = state.used;
1483 return status;
1484 }
1485
1486 /**
1487 * dma_async_is_complete - test a cookie against chan state
1488 * @cookie: transaction identifier to test status of
1489 * @last_complete: last know completed transaction
1490 * @last_used: last cookie value handed out
1491 *
1492 * dma_async_is_complete() is used in dma_async_is_tx_complete()
1493 * the test logic is separated for lightweight testing of multiple cookies
1494 */
dma_async_is_complete(dma_cookie_t cookie,dma_cookie_t last_complete,dma_cookie_t last_used)1495 static inline enum dma_status dma_async_is_complete(dma_cookie_t cookie,
1496 dma_cookie_t last_complete, dma_cookie_t last_used)
1497 {
1498 if (last_complete <= last_used) {
1499 if ((cookie <= last_complete) || (cookie > last_used))
1500 return DMA_COMPLETE;
1501 } else {
1502 if ((cookie <= last_complete) && (cookie > last_used))
1503 return DMA_COMPLETE;
1504 }
1505 return DMA_IN_PROGRESS;
1506 }
1507
1508 static inline void
dma_set_tx_state(struct dma_tx_state * st,dma_cookie_t last,dma_cookie_t used,u32 residue)1509 dma_set_tx_state(struct dma_tx_state *st, dma_cookie_t last, dma_cookie_t used, u32 residue)
1510 {
1511 if (!st)
1512 return;
1513
1514 st->last = last;
1515 st->used = used;
1516 st->residue = residue;
1517 }
1518
1519 #ifdef CONFIG_DMA_ENGINE
1520 struct dma_chan *dma_find_channel(enum dma_transaction_type tx_type);
1521 enum dma_status dma_sync_wait(struct dma_chan *chan, dma_cookie_t cookie);
1522 enum dma_status dma_wait_for_async_tx(struct dma_async_tx_descriptor *tx);
1523 void dma_issue_pending_all(void);
1524 struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask,
1525 dma_filter_fn fn, void *fn_param,
1526 struct device_node *np);
1527
1528 struct dma_chan *dma_request_chan(struct device *dev, const char *name);
1529 struct dma_chan *dma_request_chan_by_mask(const dma_cap_mask_t *mask);
1530
1531 void dma_release_channel(struct dma_chan *chan);
1532 int dma_get_slave_caps(struct dma_chan *chan, struct dma_slave_caps *caps);
1533 #else
dma_find_channel(enum dma_transaction_type tx_type)1534 static inline struct dma_chan *dma_find_channel(enum dma_transaction_type tx_type)
1535 {
1536 return NULL;
1537 }
dma_sync_wait(struct dma_chan * chan,dma_cookie_t cookie)1538 static inline enum dma_status dma_sync_wait(struct dma_chan *chan, dma_cookie_t cookie)
1539 {
1540 return DMA_COMPLETE;
1541 }
dma_wait_for_async_tx(struct dma_async_tx_descriptor * tx)1542 static inline enum dma_status dma_wait_for_async_tx(struct dma_async_tx_descriptor *tx)
1543 {
1544 return DMA_COMPLETE;
1545 }
dma_issue_pending_all(void)1546 static inline void dma_issue_pending_all(void)
1547 {
1548 }
__dma_request_channel(const dma_cap_mask_t * mask,dma_filter_fn fn,void * fn_param,struct device_node * np)1549 static inline struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask,
1550 dma_filter_fn fn,
1551 void *fn_param,
1552 struct device_node *np)
1553 {
1554 return NULL;
1555 }
dma_request_chan(struct device * dev,const char * name)1556 static inline struct dma_chan *dma_request_chan(struct device *dev,
1557 const char *name)
1558 {
1559 return ERR_PTR(-ENODEV);
1560 }
dma_request_chan_by_mask(const dma_cap_mask_t * mask)1561 static inline struct dma_chan *dma_request_chan_by_mask(
1562 const dma_cap_mask_t *mask)
1563 {
1564 return ERR_PTR(-ENODEV);
1565 }
dma_release_channel(struct dma_chan * chan)1566 static inline void dma_release_channel(struct dma_chan *chan)
1567 {
1568 }
dma_get_slave_caps(struct dma_chan * chan,struct dma_slave_caps * caps)1569 static inline int dma_get_slave_caps(struct dma_chan *chan,
1570 struct dma_slave_caps *caps)
1571 {
1572 return -ENXIO;
1573 }
1574 #endif
1575
dmaengine_desc_set_reuse(struct dma_async_tx_descriptor * tx)1576 static inline int dmaengine_desc_set_reuse(struct dma_async_tx_descriptor *tx)
1577 {
1578 struct dma_slave_caps caps;
1579 int ret;
1580
1581 ret = dma_get_slave_caps(tx->chan, &caps);
1582 if (ret)
1583 return ret;
1584
1585 if (!caps.descriptor_reuse)
1586 return -EPERM;
1587
1588 tx->flags |= DMA_CTRL_REUSE;
1589 return 0;
1590 }
1591
dmaengine_desc_clear_reuse(struct dma_async_tx_descriptor * tx)1592 static inline void dmaengine_desc_clear_reuse(struct dma_async_tx_descriptor *tx)
1593 {
1594 tx->flags &= ~DMA_CTRL_REUSE;
1595 }
1596
dmaengine_desc_test_reuse(struct dma_async_tx_descriptor * tx)1597 static inline bool dmaengine_desc_test_reuse(struct dma_async_tx_descriptor *tx)
1598 {
1599 return (tx->flags & DMA_CTRL_REUSE) == DMA_CTRL_REUSE;
1600 }
1601
dmaengine_desc_free(struct dma_async_tx_descriptor * desc)1602 static inline int dmaengine_desc_free(struct dma_async_tx_descriptor *desc)
1603 {
1604 /* this is supported for reusable desc, so check that */
1605 if (!dmaengine_desc_test_reuse(desc))
1606 return -EPERM;
1607
1608 return desc->desc_free(desc);
1609 }
1610
1611 /* --- DMA device --- */
1612
1613 int dma_async_device_register(struct dma_device *device);
1614 int dmaenginem_async_device_register(struct dma_device *device);
1615 void dma_async_device_unregister(struct dma_device *device);
1616 int dma_async_device_channel_register(struct dma_device *device,
1617 struct dma_chan *chan,
1618 const char *name);
1619 void dma_async_device_channel_unregister(struct dma_device *device,
1620 struct dma_chan *chan);
1621 void dma_run_dependencies(struct dma_async_tx_descriptor *tx);
1622 #define dma_request_channel(mask, x, y) \
1623 __dma_request_channel(&(mask), x, y, NULL)
1624
1625 /* Deprecated, please use dma_request_chan() directly */
1626 static inline struct dma_chan * __deprecated
dma_request_slave_channel(struct device * dev,const char * name)1627 dma_request_slave_channel(struct device *dev, const char *name)
1628 {
1629 struct dma_chan *ch = dma_request_chan(dev, name);
1630
1631 return IS_ERR(ch) ? NULL : ch;
1632 }
1633
1634 static inline struct dma_chan
dma_request_slave_channel_compat(const dma_cap_mask_t mask,dma_filter_fn fn,void * fn_param,struct device * dev,const char * name)1635 *dma_request_slave_channel_compat(const dma_cap_mask_t mask,
1636 dma_filter_fn fn, void *fn_param,
1637 struct device *dev, const char *name)
1638 {
1639 struct dma_chan *chan;
1640
1641 chan = dma_request_slave_channel(dev, name);
1642 if (chan)
1643 return chan;
1644
1645 if (!fn || !fn_param)
1646 return NULL;
1647
1648 return __dma_request_channel(&mask, fn, fn_param, NULL);
1649 }
1650
1651 static inline char *
dmaengine_get_direction_text(enum dma_transfer_direction dir)1652 dmaengine_get_direction_text(enum dma_transfer_direction dir)
1653 {
1654 switch (dir) {
1655 case DMA_DEV_TO_MEM:
1656 return "DEV_TO_MEM";
1657 case DMA_MEM_TO_DEV:
1658 return "MEM_TO_DEV";
1659 case DMA_MEM_TO_MEM:
1660 return "MEM_TO_MEM";
1661 case DMA_DEV_TO_DEV:
1662 return "DEV_TO_DEV";
1663 default:
1664 return "invalid";
1665 }
1666 }
1667
dmaengine_get_dma_device(struct dma_chan * chan)1668 static inline struct device *dmaengine_get_dma_device(struct dma_chan *chan)
1669 {
1670 if (chan->dev->chan_dma_dev)
1671 return &chan->dev->device;
1672
1673 return chan->device->dev;
1674 }
1675
1676 #endif /* DMAENGINE_H */
1677