async_tx.h 4.8 KB

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