async_tx.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. /**
  24. * dma_chan_ref - object used to manage dma channels received from the
  25. * dmaengine core.
  26. * @chan - the channel being tracked
  27. * @node - node for the channel to be placed on async_tx_master_list
  28. * @rcu - for list_del_rcu
  29. * @count - number of times this channel is listed in the pool
  30. * (for channels with multiple capabiities)
  31. */
  32. struct dma_chan_ref {
  33. struct dma_chan *chan;
  34. struct list_head node;
  35. struct rcu_head rcu;
  36. atomic_t count;
  37. };
  38. /**
  39. * async_tx_flags - modifiers for the async_* calls
  40. * @ASYNC_TX_XOR_ZERO_DST: this flag must be used for xor operations where the
  41. * the destination address is not a source. The asynchronous case handles this
  42. * implicitly, the synchronous case needs to zero the destination block.
  43. * @ASYNC_TX_XOR_DROP_DST: this flag must be used if the destination address is
  44. * also one of the source addresses. In the synchronous case the destination
  45. * address is an implied source, whereas the asynchronous case it must be listed
  46. * as a source. The destination address must be the first address in the source
  47. * array.
  48. * @ASYNC_TX_ASSUME_COHERENT: skip cache maintenance operations
  49. * @ASYNC_TX_ACK: immediately ack the descriptor, precludes setting up a
  50. * dependency chain
  51. * @ASYNC_TX_DEP_ACK: ack the dependency descriptor. Useful for chaining.
  52. * @ASYNC_TX_KMAP_SRC: if the transaction is to be performed synchronously
  53. * take an atomic mapping (KM_USER0) on the source page(s)
  54. * @ASYNC_TX_KMAP_DST: if the transaction is to be performed synchronously
  55. * take an atomic mapping (KM_USER0) on the dest page(s)
  56. */
  57. enum async_tx_flags {
  58. ASYNC_TX_XOR_ZERO_DST = (1 << 0),
  59. ASYNC_TX_XOR_DROP_DST = (1 << 1),
  60. ASYNC_TX_ASSUME_COHERENT = (1 << 2),
  61. ASYNC_TX_ACK = (1 << 3),
  62. ASYNC_TX_DEP_ACK = (1 << 4),
  63. ASYNC_TX_KMAP_SRC = (1 << 5),
  64. ASYNC_TX_KMAP_DST = (1 << 6),
  65. };
  66. #ifdef CONFIG_DMA_ENGINE
  67. void async_tx_issue_pending_all(void);
  68. enum dma_status dma_wait_for_async_tx(struct dma_async_tx_descriptor *tx);
  69. void async_tx_run_dependencies(struct dma_async_tx_descriptor *tx);
  70. struct dma_chan *
  71. async_tx_find_channel(struct dma_async_tx_descriptor *depend_tx,
  72. enum dma_transaction_type tx_type);
  73. #else
  74. static inline void async_tx_issue_pending_all(void)
  75. {
  76. do { } while (0);
  77. }
  78. static inline enum dma_status
  79. dma_wait_for_async_tx(struct dma_async_tx_descriptor *tx)
  80. {
  81. return DMA_SUCCESS;
  82. }
  83. static inline void
  84. async_tx_run_dependencies(struct dma_async_tx_descriptor *tx,
  85. struct dma_chan *host_chan)
  86. {
  87. do { } while (0);
  88. }
  89. static inline struct dma_chan *
  90. async_tx_find_channel(struct dma_async_tx_descriptor *depend_tx,
  91. enum dma_transaction_type tx_type)
  92. {
  93. return NULL;
  94. }
  95. #endif
  96. /**
  97. * async_tx_sync_epilog - actions to take if an operation is run synchronously
  98. * @flags: async_tx flags
  99. * @depend_tx: transaction depends on depend_tx
  100. * @cb_fn: function to call when the transaction completes
  101. * @cb_fn_param: parameter to pass to the callback routine
  102. */
  103. static inline void
  104. async_tx_sync_epilog(unsigned long flags,
  105. struct dma_async_tx_descriptor *depend_tx,
  106. dma_async_tx_callback cb_fn, void *cb_fn_param)
  107. {
  108. if (cb_fn)
  109. cb_fn(cb_fn_param);
  110. if (depend_tx && (flags & ASYNC_TX_DEP_ACK))
  111. async_tx_ack(depend_tx);
  112. }
  113. void
  114. async_tx_submit(struct dma_chan *chan, struct dma_async_tx_descriptor *tx,
  115. enum async_tx_flags flags, struct dma_async_tx_descriptor *depend_tx,
  116. dma_async_tx_callback cb_fn, void *cb_fn_param);
  117. struct dma_async_tx_descriptor *
  118. async_xor(struct page *dest, struct page **src_list, unsigned int offset,
  119. int src_cnt, size_t len, enum async_tx_flags flags,
  120. struct dma_async_tx_descriptor *depend_tx,
  121. dma_async_tx_callback cb_fn, void *cb_fn_param);
  122. struct dma_async_tx_descriptor *
  123. async_xor_zero_sum(struct page *dest, struct page **src_list,
  124. unsigned int offset, int src_cnt, size_t len,
  125. u32 *result, 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. struct dma_async_tx_descriptor *
  129. async_memcpy(struct page *dest, struct page *src, unsigned int dest_offset,
  130. unsigned int src_offset, size_t len, enum async_tx_flags flags,
  131. struct dma_async_tx_descriptor *depend_tx,
  132. dma_async_tx_callback cb_fn, void *cb_fn_param);
  133. struct dma_async_tx_descriptor *
  134. async_memset(struct page *dest, int val, unsigned int offset,
  135. size_t len, enum async_tx_flags flags,
  136. struct dma_async_tx_descriptor *depend_tx,
  137. dma_async_tx_callback cb_fn, void *cb_fn_param);
  138. struct dma_async_tx_descriptor *
  139. async_trigger_callback(enum async_tx_flags flags,
  140. struct dma_async_tx_descriptor *depend_tx,
  141. dma_async_tx_callback cb_fn, void *cb_fn_param);
  142. #endif /* _ASYNC_TX_H_ */