blob: 9f14cd540cd2810f2c4ab4b8e69fe665f5d98811 [file] [log] [blame]
Dan Williams9bc89cd2007-01-02 11:10:44 -07001/*
2 * Copyright © 2006, Intel Corporation.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
16 *
17 */
18#ifndef _ASYNC_TX_H_
19#define _ASYNC_TX_H_
20#include <linux/dmaengine.h>
21#include <linux/spinlock.h>
22#include <linux/interrupt.h>
23
Dan Williams06164f32009-03-25 09:13:25 -070024/* on architectures without dma-mapping capabilities we need to ensure
25 * that the asynchronous path compiles away
26 */
27#ifdef CONFIG_HAS_DMA
28#define __async_inline
29#else
30#define __async_inline __always_inline
31#endif
32
Dan Williams9bc89cd2007-01-02 11:10:44 -070033/**
34 * dma_chan_ref - object used to manage dma channels received from the
35 * dmaengine core.
36 * @chan - the channel being tracked
37 * @node - node for the channel to be placed on async_tx_master_list
38 * @rcu - for list_del_rcu
39 * @count - number of times this channel is listed in the pool
40 * (for channels with multiple capabiities)
41 */
42struct dma_chan_ref {
43 struct dma_chan *chan;
44 struct list_head node;
45 struct rcu_head rcu;
46 atomic_t count;
47};
48
49/**
50 * async_tx_flags - modifiers for the async_* calls
51 * @ASYNC_TX_XOR_ZERO_DST: this flag must be used for xor operations where the
52 * the destination address is not a source. The asynchronous case handles this
53 * implicitly, the synchronous case needs to zero the destination block.
54 * @ASYNC_TX_XOR_DROP_DST: this flag must be used if the destination address is
55 * also one of the source addresses. In the synchronous case the destination
56 * address is an implied source, whereas the asynchronous case it must be listed
57 * as a source. The destination address must be the first address in the source
58 * array.
Dan Williams9bc89cd2007-01-02 11:10:44 -070059 * @ASYNC_TX_ACK: immediately ack the descriptor, precludes setting up a
60 * dependency chain
Dan Williams9bc89cd2007-01-02 11:10:44 -070061 */
62enum async_tx_flags {
63 ASYNC_TX_XOR_ZERO_DST = (1 << 0),
64 ASYNC_TX_XOR_DROP_DST = (1 << 1),
Dan Williams88ba2aa2009-04-09 16:16:18 -070065 ASYNC_TX_ACK = (1 << 2),
Dan Williams9bc89cd2007-01-02 11:10:44 -070066};
67
68#ifdef CONFIG_DMA_ENGINE
Dan Williams2ba05622009-01-06 11:38:14 -070069#define async_tx_issue_pending_all dma_issue_pending_all
Dan Williams47437b22008-02-02 19:49:59 -070070#ifdef CONFIG_ARCH_HAS_ASYNC_TX_FIND_CHANNEL
71#include <asm/async_tx.h>
72#else
73#define async_tx_find_channel(dep, type, dst, dst_count, src, src_count, len) \
74 __async_tx_find_channel(dep, type)
Dan Williams9bc89cd2007-01-02 11:10:44 -070075struct dma_chan *
Dan Williams47437b22008-02-02 19:49:59 -070076__async_tx_find_channel(struct dma_async_tx_descriptor *depend_tx,
Dan Williams9bc89cd2007-01-02 11:10:44 -070077 enum dma_transaction_type tx_type);
Dan Williams47437b22008-02-02 19:49:59 -070078#endif /* CONFIG_ARCH_HAS_ASYNC_TX_FIND_CHANNEL */
Dan Williams9bc89cd2007-01-02 11:10:44 -070079#else
80static inline void async_tx_issue_pending_all(void)
81{
82 do { } while (0);
83}
84
Dan Williams9bc89cd2007-01-02 11:10:44 -070085static inline struct dma_chan *
86async_tx_find_channel(struct dma_async_tx_descriptor *depend_tx,
Dan Williams47437b22008-02-02 19:49:59 -070087 enum dma_transaction_type tx_type, struct page **dst, int dst_count,
88 struct page **src, int src_count, size_t len)
Dan Williams9bc89cd2007-01-02 11:10:44 -070089{
90 return NULL;
91}
92#endif
93
94/**
95 * async_tx_sync_epilog - actions to take if an operation is run synchronously
Dan Williams9bc89cd2007-01-02 11:10:44 -070096 * @cb_fn: function to call when the transaction completes
97 * @cb_fn_param: parameter to pass to the callback routine
98 */
99static inline void
Dan Williams3dce0172008-07-17 17:59:55 -0700100async_tx_sync_epilog(dma_async_tx_callback cb_fn, void *cb_fn_param)
Dan Williams9bc89cd2007-01-02 11:10:44 -0700101{
102 if (cb_fn)
103 cb_fn(cb_fn_param);
Dan Williams9bc89cd2007-01-02 11:10:44 -0700104}
105
106void
107async_tx_submit(struct dma_chan *chan, struct dma_async_tx_descriptor *tx,
108 enum async_tx_flags flags, struct dma_async_tx_descriptor *depend_tx,
109 dma_async_tx_callback cb_fn, void *cb_fn_param);
110
111struct dma_async_tx_descriptor *
112async_xor(struct page *dest, struct page **src_list, unsigned int offset,
113 int src_cnt, size_t len, enum async_tx_flags flags,
114 struct dma_async_tx_descriptor *depend_tx,
115 dma_async_tx_callback cb_fn, void *cb_fn_param);
116
117struct dma_async_tx_descriptor *
Dan Williams099f53c2009-04-08 14:28:37 -0700118async_xor_val(struct page *dest, struct page **src_list,
Dan Williams9bc89cd2007-01-02 11:10:44 -0700119 unsigned int offset, int src_cnt, size_t len,
120 u32 *result, enum async_tx_flags flags,
121 struct dma_async_tx_descriptor *depend_tx,
122 dma_async_tx_callback cb_fn, void *cb_fn_param);
123
124struct dma_async_tx_descriptor *
125async_memcpy(struct page *dest, struct page *src, unsigned int dest_offset,
126 unsigned int src_offset, size_t len, enum async_tx_flags flags,
127 struct dma_async_tx_descriptor *depend_tx,
128 dma_async_tx_callback cb_fn, void *cb_fn_param);
129
130struct dma_async_tx_descriptor *
131async_memset(struct page *dest, int val, unsigned int offset,
132 size_t len, enum async_tx_flags flags,
133 struct dma_async_tx_descriptor *depend_tx,
134 dma_async_tx_callback cb_fn, void *cb_fn_param);
135
136struct dma_async_tx_descriptor *
137async_trigger_callback(enum async_tx_flags flags,
138 struct dma_async_tx_descriptor *depend_tx,
139 dma_async_tx_callback cb_fn, void *cb_fn_param);
Dan Williamsd2c52b72008-07-17 17:59:55 -0700140
141void async_tx_quiesce(struct dma_async_tx_descriptor **tx);
Dan Williams9bc89cd2007-01-02 11:10:44 -0700142#endif /* _ASYNC_TX_H_ */