async_tx.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. * @ASYNC_TX_DEP_ACK: ack the dependency descriptor. Useful for chaining.
  59. */
  60. enum async_tx_flags {
  61. ASYNC_TX_XOR_ZERO_DST = (1 << 0),
  62. ASYNC_TX_XOR_DROP_DST = (1 << 1),
  63. ASYNC_TX_ACK = (1 << 3),
  64. ASYNC_TX_DEP_ACK = (1 << 4),
  65. };
  66. #ifdef CONFIG_DMA_ENGINE
  67. #define async_tx_issue_pending_all dma_issue_pending_all
  68. #ifdef CONFIG_ARCH_HAS_ASYNC_TX_FIND_CHANNEL
  69. #include <asm/async_tx.h>
  70. #else
  71. #define async_tx_find_channel(dep, type, dst, dst_count, src, src_count, len) \
  72. __async_tx_find_channel(dep, type)
  73. struct dma_chan *
  74. __async_tx_find_channel(struct dma_async_tx_descriptor *depend_tx,
  75. enum dma_transaction_type tx_type);
  76. #endif /* CONFIG_ARCH_HAS_ASYNC_TX_FIND_CHANNEL */
  77. #else
  78. static inline void async_tx_issue_pending_all(void)
  79. {
  80. do { } while (0);
  81. }
  82. static inline struct dma_chan *
  83. async_tx_find_channel(struct dma_async_tx_descriptor *depend_tx,
  84. enum dma_transaction_type tx_type, struct page **dst, int dst_count,
  85. struct page **src, int src_count, size_t len)
  86. {
  87. return NULL;
  88. }
  89. #endif
  90. /**
  91. * async_tx_sync_epilog - actions to take if an operation is run synchronously
  92. * @cb_fn: function to call when the transaction completes
  93. * @cb_fn_param: parameter to pass to the callback routine
  94. */
  95. static inline void
  96. async_tx_sync_epilog(dma_async_tx_callback cb_fn, void *cb_fn_param)
  97. {
  98. if (cb_fn)
  99. cb_fn(cb_fn_param);
  100. }
  101. void
  102. async_tx_submit(struct dma_chan *chan, struct dma_async_tx_descriptor *tx,
  103. enum async_tx_flags flags, struct dma_async_tx_descriptor *depend_tx,
  104. dma_async_tx_callback cb_fn, void *cb_fn_param);
  105. struct dma_async_tx_descriptor *
  106. async_xor(struct page *dest, struct page **src_list, unsigned int offset,
  107. int src_cnt, size_t len, enum async_tx_flags flags,
  108. struct dma_async_tx_descriptor *depend_tx,
  109. dma_async_tx_callback cb_fn, void *cb_fn_param);
  110. struct dma_async_tx_descriptor *
  111. async_xor_val(struct page *dest, struct page **src_list,
  112. unsigned int offset, int src_cnt, size_t len,
  113. u32 *result, 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. struct dma_async_tx_descriptor *
  117. async_memcpy(struct page *dest, struct page *src, unsigned int dest_offset,
  118. unsigned int src_offset, size_t len, enum async_tx_flags flags,
  119. struct dma_async_tx_descriptor *depend_tx,
  120. dma_async_tx_callback cb_fn, void *cb_fn_param);
  121. struct dma_async_tx_descriptor *
  122. async_memset(struct page *dest, int val, unsigned int offset,
  123. size_t len, enum async_tx_flags flags,
  124. struct dma_async_tx_descriptor *depend_tx,
  125. dma_async_tx_callback cb_fn, void *cb_fn_param);
  126. struct dma_async_tx_descriptor *
  127. async_trigger_callback(enum async_tx_flags flags,
  128. struct dma_async_tx_descriptor *depend_tx,
  129. dma_async_tx_callback cb_fn, void *cb_fn_param);
  130. void async_tx_quiesce(struct dma_async_tx_descriptor **tx);
  131. #endif /* _ASYNC_TX_H_ */