aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/dmaengine.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/dmaengine.h')
-rw-r--r--include/linux/dmaengine.h275
1 files changed, 259 insertions, 16 deletions
diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
index 78784982b33e..9bebd7f16ef1 100644
--- a/include/linux/dmaengine.h
+++ b/include/linux/dmaengine.h
@@ -31,6 +31,8 @@
31 * if dma_cookie_t is >0 it's a DMA request cookie, <0 it's an error code 31 * if dma_cookie_t is >0 it's a DMA request cookie, <0 it's an error code
32 */ 32 */
33typedef s32 dma_cookie_t; 33typedef s32 dma_cookie_t;
34#define DMA_MIN_COOKIE 1
35#define DMA_MAX_COOKIE INT_MAX
34 36
35#define dma_submit_error(cookie) ((cookie) < 0 ? 1 : 0) 37#define dma_submit_error(cookie) ((cookie) < 0 ? 1 : 0)
36 38
@@ -38,11 +40,13 @@ typedef s32 dma_cookie_t;
38 * enum dma_status - DMA transaction status 40 * enum dma_status - DMA transaction status
39 * @DMA_SUCCESS: transaction completed successfully 41 * @DMA_SUCCESS: transaction completed successfully
40 * @DMA_IN_PROGRESS: transaction not yet processed 42 * @DMA_IN_PROGRESS: transaction not yet processed
43 * @DMA_PAUSED: transaction is paused
41 * @DMA_ERROR: transaction failed 44 * @DMA_ERROR: transaction failed
42 */ 45 */
43enum dma_status { 46enum dma_status {
44 DMA_SUCCESS, 47 DMA_SUCCESS,
45 DMA_IN_PROGRESS, 48 DMA_IN_PROGRESS,
49 DMA_PAUSED,
46 DMA_ERROR, 50 DMA_ERROR,
47}; 51};
48 52
@@ -60,13 +64,15 @@ enum dma_transaction_type {
60 DMA_PQ_VAL, 64 DMA_PQ_VAL,
61 DMA_MEMSET, 65 DMA_MEMSET,
62 DMA_INTERRUPT, 66 DMA_INTERRUPT,
67 DMA_SG,
63 DMA_PRIVATE, 68 DMA_PRIVATE,
64 DMA_ASYNC_TX, 69 DMA_ASYNC_TX,
65 DMA_SLAVE, 70 DMA_SLAVE,
71 DMA_CYCLIC,
66}; 72};
67 73
68/* last transaction type for creation of the capabilities mask */ 74/* last transaction type for creation of the capabilities mask */
69#define DMA_TX_TYPE_END (DMA_SLAVE + 1) 75#define DMA_TX_TYPE_END (DMA_CYCLIC + 1)
70 76
71 77
72/** 78/**
@@ -105,6 +111,28 @@ enum dma_ctrl_flags {
105}; 111};
106 112
107/** 113/**
114 * enum dma_ctrl_cmd - DMA operations that can optionally be exercised
115 * on a running channel.
116 * @DMA_TERMINATE_ALL: terminate all ongoing transfers
117 * @DMA_PAUSE: pause ongoing transfers
118 * @DMA_RESUME: resume paused transfer
119 * @DMA_SLAVE_CONFIG: this command is only implemented by DMA controllers
120 * that need to runtime reconfigure the slave channels (as opposed to passing
121 * configuration data in statically from the platform). An additional
122 * argument of struct dma_slave_config must be passed in with this
123 * command.
124 * @FSLDMA_EXTERNAL_START: this command will put the Freescale DMA controller
125 * into external start mode.
126 */
127enum dma_ctrl_cmd {
128 DMA_TERMINATE_ALL,
129 DMA_PAUSE,
130 DMA_RESUME,
131 DMA_SLAVE_CONFIG,
132 FSLDMA_EXTERNAL_START,
133};
134
135/**
108 * enum sum_check_bits - bit position of pq_check_flags 136 * enum sum_check_bits - bit position of pq_check_flags
109 */ 137 */
110enum sum_check_bits { 138enum sum_check_bits {
@@ -162,7 +190,7 @@ struct dma_chan {
162 struct dma_chan_dev *dev; 190 struct dma_chan_dev *dev;
163 191
164 struct list_head device_node; 192 struct list_head device_node;
165 struct dma_chan_percpu *local; 193 struct dma_chan_percpu __percpu *local;
166 int client_count; 194 int client_count;
167 int table_count; 195 int table_count;
168 void *private; 196 void *private;
@@ -182,6 +210,71 @@ struct dma_chan_dev {
182 atomic_t *idr_ref; 210 atomic_t *idr_ref;
183}; 211};
184 212
213/**
214 * enum dma_slave_buswidth - defines bus with of the DMA slave
215 * device, source or target buses
216 */
217enum dma_slave_buswidth {
218 DMA_SLAVE_BUSWIDTH_UNDEFINED = 0,
219 DMA_SLAVE_BUSWIDTH_1_BYTE = 1,
220 DMA_SLAVE_BUSWIDTH_2_BYTES = 2,
221 DMA_SLAVE_BUSWIDTH_4_BYTES = 4,
222 DMA_SLAVE_BUSWIDTH_8_BYTES = 8,
223};
224
225/**
226 * struct dma_slave_config - dma slave channel runtime config
227 * @direction: whether the data shall go in or out on this slave
228 * channel, right now. DMA_TO_DEVICE and DMA_FROM_DEVICE are
229 * legal values, DMA_BIDIRECTIONAL is not acceptable since we
230 * need to differentiate source and target addresses.
231 * @src_addr: this is the physical address where DMA slave data
232 * should be read (RX), if the source is memory this argument is
233 * ignored.
234 * @dst_addr: this is the physical address where DMA slave data
235 * should be written (TX), if the source is memory this argument
236 * is ignored.
237 * @src_addr_width: this is the width in bytes of the source (RX)
238 * register where DMA data shall be read. If the source
239 * is memory this may be ignored depending on architecture.
240 * Legal values: 1, 2, 4, 8.
241 * @dst_addr_width: same as src_addr_width but for destination
242 * target (TX) mutatis mutandis.
243 * @src_maxburst: the maximum number of words (note: words, as in
244 * units of the src_addr_width member, not bytes) that can be sent
245 * in one burst to the device. Typically something like half the
246 * FIFO depth on I/O peripherals so you don't overflow it. This
247 * may or may not be applicable on memory sources.
248 * @dst_maxburst: same as src_maxburst but for destination target
249 * mutatis mutandis.
250 *
251 * This struct is passed in as configuration data to a DMA engine
252 * in order to set up a certain channel for DMA transport at runtime.
253 * The DMA device/engine has to provide support for an additional
254 * command in the channel config interface, DMA_SLAVE_CONFIG
255 * and this struct will then be passed in as an argument to the
256 * DMA engine device_control() function.
257 *
258 * The rationale for adding configuration information to this struct
259 * is as follows: if it is likely that most DMA slave controllers in
260 * the world will support the configuration option, then make it
261 * generic. If not: if it is fixed so that it be sent in static from
262 * the platform data, then prefer to do that. Else, if it is neither
263 * fixed at runtime, nor generic enough (such as bus mastership on
264 * some CPU family and whatnot) then create a custom slave config
265 * struct and pass that, then make this config a member of that
266 * struct, if applicable.
267 */
268struct dma_slave_config {
269 enum dma_data_direction direction;
270 dma_addr_t src_addr;
271 dma_addr_t dst_addr;
272 enum dma_slave_buswidth src_addr_width;
273 enum dma_slave_buswidth dst_addr_width;
274 u32 src_maxburst;
275 u32 dst_maxburst;
276};
277
185static inline const char *dma_chan_name(struct dma_chan *chan) 278static inline const char *dma_chan_name(struct dma_chan *chan)
186{ 279{
187 return dev_name(&chan->dev->device); 280 return dev_name(&chan->dev->device);
@@ -228,9 +321,84 @@ struct dma_async_tx_descriptor {
228 dma_cookie_t (*tx_submit)(struct dma_async_tx_descriptor *tx); 321 dma_cookie_t (*tx_submit)(struct dma_async_tx_descriptor *tx);
229 dma_async_tx_callback callback; 322 dma_async_tx_callback callback;
230 void *callback_param; 323 void *callback_param;
324#ifdef CONFIG_ASYNC_TX_ENABLE_CHANNEL_SWITCH
231 struct dma_async_tx_descriptor *next; 325 struct dma_async_tx_descriptor *next;
232 struct dma_async_tx_descriptor *parent; 326 struct dma_async_tx_descriptor *parent;
233 spinlock_t lock; 327 spinlock_t lock;
328#endif
329};
330
331#ifndef CONFIG_ASYNC_TX_ENABLE_CHANNEL_SWITCH
332static inline void txd_lock(struct dma_async_tx_descriptor *txd)
333{
334}
335static inline void txd_unlock(struct dma_async_tx_descriptor *txd)
336{
337}
338static inline void txd_chain(struct dma_async_tx_descriptor *txd, struct dma_async_tx_descriptor *next)
339{
340 BUG();
341}
342static inline void txd_clear_parent(struct dma_async_tx_descriptor *txd)
343{
344}
345static inline void txd_clear_next(struct dma_async_tx_descriptor *txd)
346{
347}
348static inline struct dma_async_tx_descriptor *txd_next(struct dma_async_tx_descriptor *txd)
349{
350 return NULL;
351}
352static inline struct dma_async_tx_descriptor *txd_parent(struct dma_async_tx_descriptor *txd)
353{
354 return NULL;
355}
356
357#else
358static inline void txd_lock(struct dma_async_tx_descriptor *txd)
359{
360 spin_lock_bh(&txd->lock);
361}
362static inline void txd_unlock(struct dma_async_tx_descriptor *txd)
363{
364 spin_unlock_bh(&txd->lock);
365}
366static inline void txd_chain(struct dma_async_tx_descriptor *txd, struct dma_async_tx_descriptor *next)
367{
368 txd->next = next;
369 next->parent = txd;
370}
371static inline void txd_clear_parent(struct dma_async_tx_descriptor *txd)
372{
373 txd->parent = NULL;
374}
375static inline void txd_clear_next(struct dma_async_tx_descriptor *txd)
376{
377 txd->next = NULL;
378}
379static inline struct dma_async_tx_descriptor *txd_parent(struct dma_async_tx_descriptor *txd)
380{
381 return txd->parent;
382}
383static inline struct dma_async_tx_descriptor *txd_next(struct dma_async_tx_descriptor *txd)
384{
385 return txd->next;
386}
387#endif
388
389/**
390 * struct dma_tx_state - filled in to report the status of
391 * a transfer.
392 * @last: last completed DMA cookie
393 * @used: last issued DMA cookie (i.e. the one in progress)
394 * @residue: the remaining number of bytes left to transmit
395 * on the selected transfer for states DMA_IN_PROGRESS and
396 * DMA_PAUSED if this is implemented in the driver, else 0
397 */
398struct dma_tx_state {
399 dma_cookie_t last;
400 dma_cookie_t used;
401 u32 residue;
234}; 402};
235 403
236/** 404/**
@@ -259,8 +427,15 @@ struct dma_async_tx_descriptor {
259 * @device_prep_dma_memset: prepares a memset operation 427 * @device_prep_dma_memset: prepares a memset operation
260 * @device_prep_dma_interrupt: prepares an end of chain interrupt operation 428 * @device_prep_dma_interrupt: prepares an end of chain interrupt operation
261 * @device_prep_slave_sg: prepares a slave dma operation 429 * @device_prep_slave_sg: prepares a slave dma operation
262 * @device_terminate_all: terminate all pending operations 430 * @device_prep_dma_cyclic: prepare a cyclic dma operation suitable for audio.
263 * @device_is_tx_complete: poll for transaction completion 431 * The function takes a buffer of size buf_len. The callback function will
432 * be called after period_len bytes have been transferred.
433 * @device_control: manipulate all pending operations on a channel, returns
434 * zero or error code
435 * @device_tx_status: poll for transaction completion, the optional
436 * txstate parameter can be supplied with a pointer to get a
437 * struct with auxilary transfer status information, otherwise the call
438 * will just return a simple status code
264 * @device_issue_pending: push pending transactions to hardware 439 * @device_issue_pending: push pending transactions to hardware
265 */ 440 */
266struct dma_device { 441struct dma_device {
@@ -306,19 +481,62 @@ struct dma_device {
306 unsigned long flags); 481 unsigned long flags);
307 struct dma_async_tx_descriptor *(*device_prep_dma_interrupt)( 482 struct dma_async_tx_descriptor *(*device_prep_dma_interrupt)(
308 struct dma_chan *chan, unsigned long flags); 483 struct dma_chan *chan, unsigned long flags);
484 struct dma_async_tx_descriptor *(*device_prep_dma_sg)(
485 struct dma_chan *chan,
486 struct scatterlist *dst_sg, unsigned int dst_nents,
487 struct scatterlist *src_sg, unsigned int src_nents,
488 unsigned long flags);
309 489
310 struct dma_async_tx_descriptor *(*device_prep_slave_sg)( 490 struct dma_async_tx_descriptor *(*device_prep_slave_sg)(
311 struct dma_chan *chan, struct scatterlist *sgl, 491 struct dma_chan *chan, struct scatterlist *sgl,
312 unsigned int sg_len, enum dma_data_direction direction, 492 unsigned int sg_len, enum dma_data_direction direction,
313 unsigned long flags); 493 unsigned long flags);
314 void (*device_terminate_all)(struct dma_chan *chan); 494 struct dma_async_tx_descriptor *(*device_prep_dma_cyclic)(
315 495 struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len,
316 enum dma_status (*device_is_tx_complete)(struct dma_chan *chan, 496 size_t period_len, enum dma_data_direction direction);
317 dma_cookie_t cookie, dma_cookie_t *last, 497 int (*device_control)(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
318 dma_cookie_t *used); 498 unsigned long arg);
499
500 enum dma_status (*device_tx_status)(struct dma_chan *chan,
501 dma_cookie_t cookie,
502 struct dma_tx_state *txstate);
319 void (*device_issue_pending)(struct dma_chan *chan); 503 void (*device_issue_pending)(struct dma_chan *chan);
320}; 504};
321 505
506static inline int dmaengine_device_control(struct dma_chan *chan,
507 enum dma_ctrl_cmd cmd,
508 unsigned long arg)
509{
510 return chan->device->device_control(chan, cmd, arg);
511}
512
513static inline int dmaengine_slave_config(struct dma_chan *chan,
514 struct dma_slave_config *config)
515{
516 return dmaengine_device_control(chan, DMA_SLAVE_CONFIG,
517 (unsigned long)config);
518}
519
520static inline int dmaengine_terminate_all(struct dma_chan *chan)
521{
522 return dmaengine_device_control(chan, DMA_TERMINATE_ALL, 0);
523}
524
525static inline int dmaengine_pause(struct dma_chan *chan)
526{
527 return dmaengine_device_control(chan, DMA_PAUSE, 0);
528}
529
530static inline int dmaengine_resume(struct dma_chan *chan)
531{
532 return dmaengine_device_control(chan, DMA_RESUME, 0);
533}
534
535static inline dma_cookie_t dmaengine_submit(struct dma_async_tx_descriptor *desc)
536{
537 return desc->tx_submit(desc);
538}
539
322static inline bool dmaengine_check_align(u8 align, size_t off1, size_t off2, size_t len) 540static inline bool dmaengine_check_align(u8 align, size_t off1, size_t off2, size_t len)
323{ 541{
324 size_t mask; 542 size_t mask;
@@ -380,7 +598,7 @@ static inline bool dma_dev_has_pq_continue(struct dma_device *dma)
380 return (dma->max_pq & DMA_HAS_PQ_CONTINUE) == DMA_HAS_PQ_CONTINUE; 598 return (dma->max_pq & DMA_HAS_PQ_CONTINUE) == DMA_HAS_PQ_CONTINUE;
381} 599}
382 600
383static unsigned short dma_dev_to_maxpq(struct dma_device *dma) 601static inline unsigned short dma_dev_to_maxpq(struct dma_device *dma)
384{ 602{
385 return dma->max_pq & ~DMA_HAS_PQ_CONTINUE; 603 return dma->max_pq & ~DMA_HAS_PQ_CONTINUE;
386} 604}
@@ -438,11 +656,11 @@ static inline void net_dmaengine_put(void)
438#ifdef CONFIG_ASYNC_TX_DMA 656#ifdef CONFIG_ASYNC_TX_DMA
439#define async_dmaengine_get() dmaengine_get() 657#define async_dmaengine_get() dmaengine_get()
440#define async_dmaengine_put() dmaengine_put() 658#define async_dmaengine_put() dmaengine_put()
441#ifdef CONFIG_ASYNC_TX_DISABLE_CHANNEL_SWITCH 659#ifndef CONFIG_ASYNC_TX_ENABLE_CHANNEL_SWITCH
442#define async_dma_find_channel(type) dma_find_channel(DMA_ASYNC_TX) 660#define async_dma_find_channel(type) dma_find_channel(DMA_ASYNC_TX)
443#else 661#else
444#define async_dma_find_channel(type) dma_find_channel(type) 662#define async_dma_find_channel(type) dma_find_channel(type)
445#endif /* CONFIG_ASYNC_TX_DISABLE_CHANNEL_SWITCH */ 663#endif /* CONFIG_ASYNC_TX_ENABLE_CHANNEL_SWITCH */
446#else 664#else
447static inline void async_dmaengine_get(void) 665static inline void async_dmaengine_get(void)
448{ 666{
@@ -556,7 +774,15 @@ static inline void dma_async_issue_pending(struct dma_chan *chan)
556static inline enum dma_status dma_async_is_tx_complete(struct dma_chan *chan, 774static inline enum dma_status dma_async_is_tx_complete(struct dma_chan *chan,
557 dma_cookie_t cookie, dma_cookie_t *last, dma_cookie_t *used) 775 dma_cookie_t cookie, dma_cookie_t *last, dma_cookie_t *used)
558{ 776{
559 return chan->device->device_is_tx_complete(chan, cookie, last, used); 777 struct dma_tx_state state;
778 enum dma_status status;
779
780 status = chan->device->device_tx_status(chan, cookie, &state);
781 if (last)
782 *last = state.last;
783 if (used)
784 *used = state.used;
785 return status;
560} 786}
561 787
562#define dma_async_memcpy_complete(chan, cookie, last, used)\ 788#define dma_async_memcpy_complete(chan, cookie, last, used)\
@@ -584,10 +810,22 @@ static inline enum dma_status dma_async_is_complete(dma_cookie_t cookie,
584 return DMA_IN_PROGRESS; 810 return DMA_IN_PROGRESS;
585} 811}
586 812
813static inline void
814dma_set_tx_state(struct dma_tx_state *st, dma_cookie_t last, dma_cookie_t used, u32 residue)
815{
816 if (st) {
817 st->last = last;
818 st->used = used;
819 st->residue = residue;
820 }
821}
822
587enum dma_status dma_sync_wait(struct dma_chan *chan, dma_cookie_t cookie); 823enum dma_status dma_sync_wait(struct dma_chan *chan, dma_cookie_t cookie);
588#ifdef CONFIG_DMA_ENGINE 824#ifdef CONFIG_DMA_ENGINE
589enum dma_status dma_wait_for_async_tx(struct dma_async_tx_descriptor *tx); 825enum dma_status dma_wait_for_async_tx(struct dma_async_tx_descriptor *tx);
590void dma_issue_pending_all(void); 826void dma_issue_pending_all(void);
827struct dma_chan *__dma_request_channel(dma_cap_mask_t *mask, dma_filter_fn fn, void *fn_param);
828void dma_release_channel(struct dma_chan *chan);
591#else 829#else
592static inline enum dma_status dma_wait_for_async_tx(struct dma_async_tx_descriptor *tx) 830static inline enum dma_status dma_wait_for_async_tx(struct dma_async_tx_descriptor *tx)
593{ 831{
@@ -595,7 +833,14 @@ static inline enum dma_status dma_wait_for_async_tx(struct dma_async_tx_descript
595} 833}
596static inline void dma_issue_pending_all(void) 834static inline void dma_issue_pending_all(void)
597{ 835{
598 do { } while (0); 836}
837static inline struct dma_chan *__dma_request_channel(dma_cap_mask_t *mask,
838 dma_filter_fn fn, void *fn_param)
839{
840 return NULL;
841}
842static inline void dma_release_channel(struct dma_chan *chan)
843{
599} 844}
600#endif 845#endif
601 846
@@ -606,8 +851,6 @@ void dma_async_device_unregister(struct dma_device *device);
606void dma_run_dependencies(struct dma_async_tx_descriptor *tx); 851void dma_run_dependencies(struct dma_async_tx_descriptor *tx);
607struct dma_chan *dma_find_channel(enum dma_transaction_type tx_type); 852struct dma_chan *dma_find_channel(enum dma_transaction_type tx_type);
608#define dma_request_channel(mask, x, y) __dma_request_channel(&(mask), x, y) 853#define dma_request_channel(mask, x, y) __dma_request_channel(&(mask), x, y)
609struct dma_chan *__dma_request_channel(dma_cap_mask_t *mask, dma_filter_fn fn, void *fn_param);
610void dma_release_channel(struct dma_chan *chan);
611 854
612/* --- Helper iov-locking functions --- */ 855/* --- Helper iov-locking functions --- */
613 856