-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdma_xfer.h
More file actions
340 lines (312 loc) · 7.42 KB
/
dma_xfer.h
File metadata and controls
340 lines (312 loc) · 7.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
/*
* Copyright (C) 2016 University of Granada
* Miguel Jimenez Lopez <klyone@ugr.es>
*
* DMA Transfer functions (header).
*
* This source code is licensed under the GNU General Public License,
* Version 2. See the file COPYING for more details.
*/
#ifndef DMA_XFER_H
#define DMA_XFER_H
#include <linux/types.h>
#include <linux/scatterlist.h>
#include <linux/dmaengine.h>
#include <linux/dma-direction.h>
#include <linux/device.h>
#include <linux/list.h>
#include "dma_sg.h"
/**
*
* DMA Cyclic mode info.
*
*/
struct dma_cyclic_info {
dma_addr_t dma_addr;
size_t len;
size_t period_len;
};
/**
*
* DMA memcpy mode info.
*
*/
struct dma_memcpy_info {
dma_addr_t dst;
dma_addr_t src;
size_t len;
};
/**
*
* DMA Transfer (xfer) structure. It represents a DMA transaction.
*
*/
struct dma_xfer {
/* SG structures */
struct sg_table sgt;
struct list_head list_dma_sg;
enum dma_data_direction dma_map_dir;
/* memcpy and cyclic stuff */
struct dma_cyclic_info dcyc_info;
struct dma_memcpy_info dmemcpy_info;
/* DMAengine stuff */
struct dma_chan * dma_chan;
struct dma_slave_config dma_config;
enum dma_transfer_direction dma_dir;
struct dma_async_tx_descriptor * dma_desc;
dma_cookie_t dma_cookie;
/* Reference to internal Linux dev */
struct device * hwdev;
/* dma_xfer linked list */
struct list_head node;
};
/**
*
* dma_sg_create - Create a new DMA Xfer.
*
* @dma_chan: DMA channel.
* @dma_config: DMA configuration settings.
* @hwdev: reference to internal Linux device.
* @gfp: Specific flags to request memory.
*
* Return: A DMA Xfer.
*
*/
struct dma_xfer * dma_xfer_create(struct dma_chan * dma_chan, \
struct dma_slave_config * dma_config, struct device * hwdev, \
gfp_t gfp);
/**
*
* dma_xfer_add_sg - Add a new DMA SG to the DMA Xfer.
*
* @xfer: DMA Xfer pointer.
* @sg: DMA SG pointer.
*
* Return: 0 if sucess and an error code otherwise.
*
*/
int dma_xfer_add_sg(struct dma_xfer * xfer, struct dma_sg * sg);
/**
*
* dma_xfer_del_sg - Remove a DMA SG from the DMA Xfer.
*
* @xfer: DMA Xfer pointer.
* @sg: DMA SG pointer.
*
* Return: 0 if sucess and an error code otherwise.
*
*/
int dma_xfer_del_sg(struct dma_xfer * xfer, struct dma_sg * sg);
/**
*
* dma_xfer_clear_sg - Remove all DMA SGs from the DMA Xfer.
*
* @xfer: DMA Xfer pointer.
*
* Return: 0 if sucess and an error code otherwise.
*
*/
int dma_xfer_clear_sg(struct dma_xfer * xfer);
/**
*
* dma_xfer_map_sg - Map all the DMA SG structures related with
* the DMA Xfer. This function also creates and initializes the
* Scatter-Gather Table for the DMA transaction.
*
* @xfer: DMA Xfer pointer.
* @dma_map_dir: DMA direction (@see <linux/dma-direction.h>)
* DMA_BIDIRECTIONAL
* DMA_TO_DEVICE
* DMA_FROM_DEVICE
* DMA_NONE
*
* @gfp: Specific flags to request memory.
*
* Return: 0 if sucess and an error code otherwise.
*
*/
int dma_xfer_map_sg(struct dma_xfer * xfer, \
enum dma_data_direction dma_map_dir, \
gfp_t gfp);
/**
*
* dma_xfer_tx_map_sg - Map all the DMA SG structures related with
* the TX DMA Xfer. This function also creates and initializes the
* Scatter-Gather Table for the DMA transaction.
*
* @xfer: DMA Xfer pointer.
* @gfp: Specific flags to request memory.
*
* Return: 0 if sucess and an error code otherwise.
*
*/
int dma_xfer_tx_map_sg(struct dma_xfer * xfer, \
gfp_t gfp);
/**
*
* dma_xfer_rx_map_sg - Map all the DMA SG structures related with
* the RX DMA Xfer. This function also creates and initializes the
* Scatter-Gather Table for the DMA transaction.
*
* @xfer: DMA Xfer pointer.
* @gfp: Specific flags to request memory.
*
* Return: 0 if sucess and an error code otherwise.
*
*/
int dma_xfer_rx_map_sg(struct dma_xfer * xfer, \
gfp_t gfp);
/**
*
* dma_xfer_prep_start_sg - Prepare everything before the start
* of a DMA SG transfer.
*
* @xfer: DMA Xfer pointer.
* @dma_dir: DMA direction (@see <linux/dmaengine.h>).
* DMA_MEM_TO_MEM
* DMA_MEM_TO_DEV
* DMA_DEV_TO_MEM
* DMA_DEV_TO_DEV
* DMA_TRANS_NONE
*
* @dma_cb_f: DMA Callback function.
* @dma_cb_param: DMA Callback parameter.
* @flags: DMA controller flags.
* @context: Extra arguments for some DMA drivers.
*
* Return: 0 if sucess and an error code otherwise.
*
*/
int dma_xfer_prep_start_sg(struct dma_xfer * xfer, \
enum dma_transfer_direction dma_dir, \
void (*dma_cb_f)(void * param), \
void * dma_cb_param, \
unsigned long flags, \
void * context);
/**
*
* dma_xfer_prep_tx_start_sg - Prepare everything before the start
* of a TX DMA SG transfer.
*
* @xfer: DMA Xfer pointer.
* @dma_cb_f: DMA Callback function.
* @dma_cb_param: DMA Callback parameter.
* @flags: DMA controller flags.
* @context: Extra arguments for some DMA drivers.
*
* Return: 0 if sucess and an error code otherwise.
*
*/
int dma_xfer_prep_tx_start_sg(struct dma_xfer * xfer, \
void (*dma_cb_f)(void * param), \
void * dma_cb_param, \
unsigned long flags, \
void * context);
/**
*
* dma_xfer_prep_rx_start_sg - Prepare everything before the start
* of a RX DMA SG transfer.
*
* @xfer: DMA Xfer pointer.
* @dma_cb_f: DMA Callback function.
* @dma_cb_param: DMA Callback parameter.
* @flags: DMA controller flags.
* @context: Extra arguments for some DMA drivers.
*
* Return: 0 if sucess and an error code otherwise.
*
*/
int dma_xfer_prep_rx_start_sg(struct dma_xfer * xfer, \
void (*dma_cb_f)(void * param), \
void * dma_cb_param, \
unsigned long flags, \
void * context);
/**
*
* dma_xfer_cyclic_setup - Setup the info related with the
* DMA cyclic mode.
*
* @xfer: DMA Xfer pointer.
* @dcyc_info: DMA cyclic mode info.
*
*/
void dma_xfer_cyclic_setup(struct dma_xfer * xfer, \
struct dma_cyclic_info * dcyc_info);
/**
*
* dma_xfer_prep_start_cyclic - Prepare everything before the
* start of a DMA Cyclic transfer.
*
* @xfer: DMA Xfer pointer.
* @dma_dir: DMA direction (@see <linux/dmaengine.h>).
* DMA_MEM_TO_MEM
* DMA_MEM_TO_DEV
* DMA_DEV_TO_MEM
* DMA_DEV_TO_DEV
* DMA_TRANS_NONE
*
* @dma_cb_f: DMA Callback function.
* @dma_cb_param: DMA Callback parameter.
* @flags: DMA controller flags.
*
*/
int dma_xfer_prep_start_cyclic(struct dma_xfer *xfer, \
enum dma_transfer_direction dma_dir, \
void (*dma_cb_f)(void * param), \
void * dma_cb_param, \
unsigned long flags);
/**
*
* dma_xfer_memcpy_setup - Setup the info related with the
* DMA memcpy mode.
*
* @xfer: DMA Xfer pointer.
* @dmemcpy_info: DMA memcpy mode info.
*
*/
void dma_xfer_memcpy_setup(struct dma_xfer * xfer, \
struct dma_memcpy_info * dmemcpy_info);
/**
*
* dma_xfer_prep_start_memcpy - Prepare everything before the
* start of a DMA memcpy transfer.
*
* @xfer: DMA Xfer pointer.
* @dma_cb_f: DMA Callback function.
* @dma_cb_param: DMA Callback parameter.
* @flags: DMA controller flags.
*
*/
int dma_xfer_prep_start_memcpy(struct dma_xfer *xfer, \
void (*dma_cb_f)(void * param), \
void * dma_cb_param, \
unsigned long flags);
/**
*
* dma_xfer_start - Start a DMA transfer.
*
* @xfer: DMA Xfer pointer.
*
* Return: 0 if sucess and an error code otherwise.
*
*/
int dma_xfer_start(struct dma_xfer * xfer);
/**
*
* dma_xfer_status - Get the DMA Xfer status.
*
* @xfer: DMA Xfer pointer.
*
* Return: DMA Xfer status.
*
*/
enum dma_status dma_xfer_status(struct dma_xfer * xfer);
/**
*
* dma_xfer_free - Destroy a DMA Xfer.
*
* @xfer: DMA Xfer pointer.
*
*/
void dma_xfer_free(struct dma_xfer * xfer);
#endif /* DMA_XFER_H */