2 * The contents of this file are private to DMA engine drivers, and is not
3 * part of the API to be used by DMA engine users.
9 #include <linux/dmaengine.h>
12 * dma_cookie_init - initialize the cookies for a DMA channel
13 * @chan: dma channel to initialize
15 static inline void dma_cookie_init(struct dma_chan *chan)
17 chan->cookie = DMA_MIN_COOKIE;
18 chan->completed_cookie = DMA_MIN_COOKIE;
22 * dma_cookie_assign - assign a DMA engine cookie to the descriptor
23 * @tx: descriptor needing cookie
25 * Assign a unique non-zero per-channel cookie to the descriptor.
26 * Note: caller is expected to hold a lock to prevent concurrency.
28 static inline dma_cookie_t dma_cookie_assign(struct dma_async_tx_descriptor *tx)
30 struct dma_chan *chan = tx->chan;
33 cookie = chan->cookie + 1;
34 if (cookie < DMA_MIN_COOKIE)
35 cookie = DMA_MIN_COOKIE;
36 tx->cookie = chan->cookie = cookie;
42 * dma_cookie_complete - complete a descriptor
43 * @tx: descriptor to complete
45 * Mark this descriptor complete by updating the channels completed
46 * cookie marker. Zero the descriptors cookie to prevent accidental
47 * repeated completions.
49 * Note: caller is expected to hold a lock to prevent concurrency.
51 static inline void dma_cookie_complete(struct dma_async_tx_descriptor *tx)
53 BUG_ON(tx->cookie < DMA_MIN_COOKIE);
54 tx->chan->completed_cookie = tx->cookie;
59 * dma_cookie_status - report cookie status
61 * @cookie: cookie we are interested in
62 * @state: dma_tx_state structure to return last/used cookies
64 * Report the status of the cookie, filling in the state structure if
65 * non-NULL. No locking is required.
67 static inline enum dma_status dma_cookie_status(struct dma_chan *chan,
68 dma_cookie_t cookie, struct dma_tx_state *state)
70 dma_cookie_t used, complete;
73 complete = chan->completed_cookie;
76 state->last = complete;
80 return dma_async_is_complete(cookie, complete, used);
83 static inline void dma_set_residue(struct dma_tx_state *state, u32 residue)
86 state->residue = residue;
89 struct dmaengine_desc_callback {
90 dma_async_tx_callback callback;
95 * dmaengine_desc_get_callback - get the passed in callback function
97 * @cb: temp struct to hold the callback info
99 * Fill the passed in cb struct with what's available in the passed in
100 * tx descriptor struct
101 * No locking is required.
104 dmaengine_desc_get_callback(struct dma_async_tx_descriptor *tx,
105 struct dmaengine_desc_callback *cb)
107 cb->callback = tx->callback;
108 cb->callback_param = tx->callback_param;
112 * dmaengine_desc_callback_invoke - call the callback function in cb struct
113 * @cb: temp struct that is holding the callback info
114 * @result: dummy pointer for now
116 * Call the callback function provided in the cb struct with the parameter
118 * Locking is dependent on the driver.
121 dmaengine_desc_callback_invoke(struct dmaengine_desc_callback *cb,
125 cb->callback(cb->callback_param);
129 * dmaengine_desc_get_callback_invoke - get the callback in tx descriptor and
130 * then immediately call the callback.
131 * @tx: dma async tx descriptor
132 * @result: dummy pointer for now
134 * Call dmaengine_desc_get_callback() and dmaengine_desc_callback_invoke()
135 * in a single function since no work is necessary in between for the driver.
136 * Locking is dependent on the driver.
139 dmaengine_desc_get_callback_invoke(struct dma_async_tx_descriptor *tx,
142 struct dmaengine_desc_callback cb;
144 dmaengine_desc_get_callback(tx, &cb);
145 dmaengine_desc_callback_invoke(&cb, result);
149 * dmaengine_desc_callback_valid - verify the callback is valid in cb
150 * @cb: callback info struct
152 * Return a bool that verifies whether callback in cb is valid or not.
153 * No locking is required.
156 dmaengine_desc_callback_valid(struct dmaengine_desc_callback *cb)
158 return (cb->callback) ? true : false;