async_tx.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  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. /* on architectures without dma-mapping capabilities we need to ensure
  24. * that the asynchronous path compiles away
  25. */
  26. #ifdef CONFIG_HAS_DMA
  27. #define __async_inline
  28. #else
  29. #define __async_inline __always_inline
  30. #endif
  31. /**
  32. * dma_chan_ref - object used to manage dma channels received from the
  33. * dmaengine core.
  34. * @chan - the channel being tracked
  35. * @node - node for the channel to be placed on async_tx_master_list
  36. * @rcu - for list_del_rcu
  37. * @count - number of times this channel is listed in the pool
  38. * (for channels with multiple capabiities)
  39. */
  40. struct dma_chan_ref {
  41. struct dma_chan *chan;
  42. struct list_head node;
  43. struct rcu_head rcu;
  44. atomic_t count;
  45. };
  46. /**
  47. * async_tx_flags - modifiers for the async_* calls
  48. * @ASYNC_TX_XOR_ZERO_DST: this flag must be used for xor operations where the
  49. * the destination address is not a source. The asynchronous case handles this
  50. * implicitly, the synchronous case needs to zero the destination block.
  51. * @ASYNC_TX_XOR_DROP_DST: this flag must be used if the destination address is
  52. * also one of the source addresses. In the synchronous case the destination
  53. * address is an implied source, whereas the asynchronous case it must be listed
  54. * as a source. The destination address must be the first address in the source
  55. * array.
  56. * @ASYNC_TX_ACK: immediately ack the descriptor, precludes setting up a
  57. * dependency chain
  58. */
  59. enum async_tx_flags {
  60. ASYNC_TX_XOR_ZERO_DST = (1 << 0),
  61. ASYNC_TX_XOR_DROP_DST = (1 << 1),
  62. ASYNC_TX_ACK = (1 << 2),
  63. };
  64. /**
  65. * struct async_submit_ctl - async_tx submission/completion modifiers
  66. * @flags: submission modifiers
  67. * @depend_tx: parent dependency of the current operation being submitted
  68. * @cb_fn: callback routine to run at operation completion
  69. * @cb_param: parameter for the callback routine
  70. * @scribble: caller provided space for dma/page address conversions
  71. */
  72. struct async_submit_ctl {
  73. enum async_tx_flags flags;
  74. struct dma_async_tx_descriptor *depend_tx;
  75. dma_async_tx_callback cb_fn;
  76. void *cb_param;
  77. void *scribble;
  78. };
  79. #ifdef CONFIG_DMA_ENGINE
  80. #define async_tx_issue_pending_all dma_issue_pending_all
  81. #ifdef CONFIG_ARCH_HAS_ASYNC_TX_FIND_CHANNEL
  82. #include <asm/async_tx.h>
  83. #else
  84. #define async_tx_find_channel(dep, type, dst, dst_count, src, src_count, len) \
  85. __async_tx_find_channel(dep, type)
  86. struct dma_chan *
  87. __async_tx_find_channel(struct async_submit_ctl *submit,
  88. enum dma_transaction_type tx_type);
  89. #endif /* CONFIG_ARCH_HAS_ASYNC_TX_FIND_CHANNEL */
  90. #else
  91. static inline void async_tx_issue_pending_all(void)
  92. {
  93. do { } while (0);
  94. }
  95. static inline struct dma_chan *
  96. async_tx_find_channel(struct async_submit_ctl *submit,
  97. enum dma_transaction_type tx_type, struct page **dst,
  98. int dst_count, struct page **src, int src_count,
  99. size_t len)
  100. {
  101. return NULL;
  102. }
  103. #endif
  104. /**
  105. * async_tx_sync_epilog - actions to take if an operation is run synchronously
  106. * @cb_fn: function to call when the transaction completes
  107. * @cb_fn_param: parameter to pass to the callback routine
  108. */
  109. static inline void
  110. async_tx_sync_epilog(struct async_submit_ctl *submit)
  111. {
  112. if (submit->cb_fn)
  113. submit->cb_fn(submit->cb_param);
  114. }
  115. typedef union {
  116. unsigned long addr;
  117. struct page *page;
  118. dma_addr_t dma;
  119. } addr_conv_t;
  120. static inline void
  121. init_async_submit(struct async_submit_ctl *args, enum async_tx_flags flags,
  122. struct dma_async_tx_descriptor *tx,
  123. dma_async_tx_callback cb_fn, void *cb_param,
  124. addr_conv_t *scribble)
  125. {
  126. args->flags = flags;
  127. args->depend_tx = tx;
  128. args->cb_fn = cb_fn;
  129. args->cb_param = cb_param;
  130. args->scribble = scribble;
  131. }
  132. void async_tx_submit(struct dma_chan *chan, struct dma_async_tx_descriptor *tx,
  133. struct async_submit_ctl *submit);
  134. struct dma_async_tx_descriptor *
  135. async_xor(struct page *dest, struct page **src_list, unsigned int offset,
  136. int src_cnt, size_t len, struct async_submit_ctl *submit);
  137. struct dma_async_tx_descriptor *
  138. async_xor_val(struct page *dest, struct page **src_list, unsigned int offset,
  139. int src_cnt, size_t len, u32 *result,
  140. struct async_submit_ctl *submit);
  141. struct dma_async_tx_descriptor *
  142. async_memcpy(struct page *dest, struct page *src, unsigned int dest_offset,
  143. unsigned int src_offset, size_t len,
  144. struct async_submit_ctl *submit);
  145. struct dma_async_tx_descriptor *
  146. async_memset(struct page *dest, int val, unsigned int offset,
  147. size_t len, struct async_submit_ctl *submit);
  148. struct dma_async_tx_descriptor *async_trigger_callback(struct async_submit_ctl *submit);
  149. void async_tx_quiesce(struct dma_async_tx_descriptor **tx);
  150. #endif /* _ASYNC_TX_H_ */