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