1
2
3
4
5
6#ifndef DMAENGINE_H
7#define DMAENGINE_H
8
9#include <linux/bug.h>
10#include <linux/dmaengine.h>
11
12
13
14
15
16static inline void dma_cookie_init(struct dma_chan *chan)
17{
18 chan->cookie = DMA_MIN_COOKIE;
19 chan->completed_cookie = DMA_MIN_COOKIE;
20}
21
22
23
24
25
26
27
28
29static inline dma_cookie_t dma_cookie_assign(struct dma_async_tx_descriptor *tx)
30{
31 struct dma_chan *chan = tx->chan;
32 dma_cookie_t cookie;
33
34 cookie = chan->cookie + 1;
35 if (cookie < DMA_MIN_COOKIE)
36 cookie = DMA_MIN_COOKIE;
37 tx->cookie = chan->cookie = cookie;
38
39 return cookie;
40}
41
42
43
44
45
46
47
48
49
50
51
52static inline void dma_cookie_complete(struct dma_async_tx_descriptor *tx)
53{
54 BUG_ON(tx->cookie < DMA_MIN_COOKIE);
55 tx->chan->completed_cookie = tx->cookie;
56 tx->cookie = 0;
57}
58
59
60
61
62
63
64
65
66
67
68static inline enum dma_status dma_cookie_status(struct dma_chan *chan,
69 dma_cookie_t cookie, struct dma_tx_state *state)
70{
71 dma_cookie_t used, complete;
72
73 used = chan->cookie;
74 complete = chan->completed_cookie;
75 barrier();
76 if (state) {
77 state->last = complete;
78 state->used = used;
79 state->residue = 0;
80 state->in_flight_bytes = 0;
81 }
82 return dma_async_is_complete(cookie, complete, used);
83}
84
85static inline void dma_set_residue(struct dma_tx_state *state, u32 residue)
86{
87 if (state)
88 state->residue = residue;
89}
90
91static inline void dma_set_in_flight_bytes(struct dma_tx_state *state,
92 u32 in_flight_bytes)
93{
94 if (state)
95 state->in_flight_bytes = in_flight_bytes;
96}
97
98struct dmaengine_desc_callback {
99 dma_async_tx_callback callback;
100 dma_async_tx_callback_result callback_result;
101 void *callback_param;
102};
103
104
105
106
107
108
109
110
111
112
113static inline void
114dmaengine_desc_get_callback(struct dma_async_tx_descriptor *tx,
115 struct dmaengine_desc_callback *cb)
116{
117 cb->callback = tx->callback;
118 cb->callback_result = tx->callback_result;
119 cb->callback_param = tx->callback_param;
120}
121
122
123
124
125
126
127
128
129
130
131static inline void
132dmaengine_desc_callback_invoke(struct dmaengine_desc_callback *cb,
133 const struct dmaengine_result *result)
134{
135 struct dmaengine_result dummy_result = {
136 .result = DMA_TRANS_NOERROR,
137 .residue = 0
138 };
139
140 if (cb->callback_result) {
141 if (!result)
142 result = &dummy_result;
143 cb->callback_result(cb->callback_param, result);
144 } else if (cb->callback) {
145 cb->callback(cb->callback_param);
146 }
147}
148
149
150
151
152
153
154
155
156
157
158
159static inline void
160dmaengine_desc_get_callback_invoke(struct dma_async_tx_descriptor *tx,
161 const struct dmaengine_result *result)
162{
163 struct dmaengine_desc_callback cb;
164
165 dmaengine_desc_get_callback(tx, &cb);
166 dmaengine_desc_callback_invoke(&cb, result);
167}
168
169
170
171
172
173
174
175
176static inline bool
177dmaengine_desc_callback_valid(struct dmaengine_desc_callback *cb)
178{
179 return (cb->callback) ? true : false;
180}
181
182struct dma_chan *dma_get_slave_channel(struct dma_chan *chan);
183struct dma_chan *dma_get_any_slave_channel(struct dma_device *device);
184
185#ifdef CONFIG_DEBUG_FS
186#include <linux/debugfs.h>
187
188static inline struct dentry *
189dmaengine_get_debugfs_root(struct dma_device *dma_dev) {
190 return dma_dev->dbg_dev_root;
191}
192#else
193struct dentry;
194static inline struct dentry *
195dmaengine_get_debugfs_root(struct dma_device *dma_dev)
196{
197 return NULL;
198}
199#endif
200
201#endif
202