This source file includes following definitions.
- dma_cookie_init
- dma_cookie_assign
- dma_cookie_complete
- dma_cookie_status
- dma_set_residue
- dmaengine_desc_get_callback
- dmaengine_desc_callback_invoke
- dmaengine_desc_get_callback_invoke
- dmaengine_desc_callback_valid
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
16 static 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
29 static 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
52 static 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
68 static 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 }
81 return dma_async_is_complete(cookie, complete, used);
82 }
83
84 static inline void dma_set_residue(struct dma_tx_state *state, u32 residue)
85 {
86 if (state)
87 state->residue = residue;
88 }
89
90 struct dmaengine_desc_callback {
91 dma_async_tx_callback callback;
92 dma_async_tx_callback_result callback_result;
93 void *callback_param;
94 };
95
96
97
98
99
100
101
102
103
104
105 static inline void
106 dmaengine_desc_get_callback(struct dma_async_tx_descriptor *tx,
107 struct dmaengine_desc_callback *cb)
108 {
109 cb->callback = tx->callback;
110 cb->callback_result = tx->callback_result;
111 cb->callback_param = tx->callback_param;
112 }
113
114
115
116
117
118
119
120
121
122
123 static inline void
124 dmaengine_desc_callback_invoke(struct dmaengine_desc_callback *cb,
125 const struct dmaengine_result *result)
126 {
127 struct dmaengine_result dummy_result = {
128 .result = DMA_TRANS_NOERROR,
129 .residue = 0
130 };
131
132 if (cb->callback_result) {
133 if (!result)
134 result = &dummy_result;
135 cb->callback_result(cb->callback_param, result);
136 } else if (cb->callback) {
137 cb->callback(cb->callback_param);
138 }
139 }
140
141
142
143
144
145
146
147
148
149
150
151 static inline void
152 dmaengine_desc_get_callback_invoke(struct dma_async_tx_descriptor *tx,
153 const struct dmaengine_result *result)
154 {
155 struct dmaengine_desc_callback cb;
156
157 dmaengine_desc_get_callback(tx, &cb);
158 dmaengine_desc_callback_invoke(&cb, result);
159 }
160
161
162
163
164
165
166
167
168 static inline bool
169 dmaengine_desc_callback_valid(struct dmaengine_desc_callback *cb)
170 {
171 return (cb->callback) ? true : false;
172 }
173
174 #endif