1 /* SPDX-License-Identifier: GPL-2.0 */
3 * The contents of this file are private to DMA engine drivers, and is not
4 * part of the API to be used by DMA engine users.
10 #include <linux/dmaengine.h>
13 * dma_cookie_init - initialize the cookies for a DMA channel
14 * @chan: dma channel to initialize
16 static inline void dma_cookie_init(struct dma_chan
*chan
)
18 chan
->cookie
= DMA_MIN_COOKIE
;
19 chan
->completed_cookie
= DMA_MIN_COOKIE
;
23 * dma_cookie_assign - assign a DMA engine cookie to the descriptor
24 * @tx: descriptor needing cookie
26 * Assign a unique non-zero per-channel cookie to the descriptor.
27 * Note: caller is expected to hold a lock to prevent concurrency.
29 static inline dma_cookie_t
dma_cookie_assign(struct dma_async_tx_descriptor
*tx
)
31 struct dma_chan
*chan
= tx
->chan
;
34 cookie
= chan
->cookie
+ 1;
35 if (cookie
< DMA_MIN_COOKIE
)
36 cookie
= DMA_MIN_COOKIE
;
37 tx
->cookie
= chan
->cookie
= cookie
;
43 * dma_cookie_complete - complete a descriptor
44 * @tx: descriptor to complete
46 * Mark this descriptor complete by updating the channels completed
47 * cookie marker. Zero the descriptors cookie to prevent accidental
48 * repeated completions.
50 * Note: caller is expected to hold a lock to prevent concurrency.
52 static inline void dma_cookie_complete(struct dma_async_tx_descriptor
*tx
)
54 BUG_ON(tx
->cookie
< DMA_MIN_COOKIE
);
55 tx
->chan
->completed_cookie
= tx
->cookie
;
60 * dma_cookie_status - report cookie status
62 * @cookie: cookie we are interested in
63 * @state: dma_tx_state structure to return last/used cookies
65 * Report the status of the cookie, filling in the state structure if
66 * non-NULL. No locking is required.
68 static inline enum dma_status
dma_cookie_status(struct dma_chan
*chan
,
69 dma_cookie_t cookie
, struct dma_tx_state
*state
)
71 dma_cookie_t used
, complete
;
74 complete
= chan
->completed_cookie
;
77 state
->last
= complete
;
81 return dma_async_is_complete(cookie
, complete
, used
);
84 static inline void dma_set_residue(struct dma_tx_state
*state
, u32 residue
)
87 state
->residue
= residue
;
90 struct dmaengine_desc_callback
{
91 dma_async_tx_callback callback
;
92 dma_async_tx_callback_result callback_result
;
97 * dmaengine_desc_get_callback - get the passed in callback function
99 * @cb: temp struct to hold the callback info
101 * Fill the passed in cb struct with what's available in the passed in
102 * tx descriptor struct
103 * No locking is required.
106 dmaengine_desc_get_callback(struct dma_async_tx_descriptor
*tx
,
107 struct dmaengine_desc_callback
*cb
)
109 cb
->callback
= tx
->callback
;
110 cb
->callback_result
= tx
->callback_result
;
111 cb
->callback_param
= tx
->callback_param
;
115 * dmaengine_desc_callback_invoke - call the callback function in cb struct
116 * @cb: temp struct that is holding the callback info
117 * @result: transaction result
119 * Call the callback function provided in the cb struct with the parameter
121 * Locking is dependent on the driver.
124 dmaengine_desc_callback_invoke(struct dmaengine_desc_callback
*cb
,
125 const struct dmaengine_result
*result
)
127 struct dmaengine_result dummy_result
= {
128 .result
= DMA_TRANS_NOERROR
,
132 if (cb
->callback_result
) {
134 result
= &dummy_result
;
135 cb
->callback_result(cb
->callback_param
, result
);
136 } else if (cb
->callback
) {
137 cb
->callback(cb
->callback_param
);
142 * dmaengine_desc_get_callback_invoke - get the callback in tx descriptor and
143 * then immediately call the callback.
144 * @tx: dma async tx descriptor
145 * @result: transaction result
147 * Call dmaengine_desc_get_callback() and dmaengine_desc_callback_invoke()
148 * in a single function since no work is necessary in between for the driver.
149 * Locking is dependent on the driver.
152 dmaengine_desc_get_callback_invoke(struct dma_async_tx_descriptor
*tx
,
153 const struct dmaengine_result
*result
)
155 struct dmaengine_desc_callback cb
;
157 dmaengine_desc_get_callback(tx
, &cb
);
158 dmaengine_desc_callback_invoke(&cb
, result
);
162 * dmaengine_desc_callback_valid - verify the callback is valid in cb
163 * @cb: callback info struct
165 * Return a bool that verifies whether callback in cb is valid or not.
166 * No locking is required.
169 dmaengine_desc_callback_valid(struct dmaengine_desc_callback
*cb
)
171 return (cb
->callback
) ? true : false;