dmaengine.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * The contents of this file are private to DMA engine drivers, and is not
  3. * part of the API to be used by DMA engine users.
  4. */
  5. #ifndef DMAENGINE_H
  6. #define DMAENGINE_H
  7. #include <linux/bug.h>
  8. #include <linux/dmaengine.h>
  9. /**
  10. * dma_cookie_init - initialize the cookies for a DMA channel
  11. * @chan: dma channel to initialize
  12. */
  13. static inline void dma_cookie_init(struct dma_chan *chan)
  14. {
  15. chan->cookie = DMA_MIN_COOKIE;
  16. chan->completed_cookie = DMA_MIN_COOKIE;
  17. }
  18. /**
  19. * dma_cookie_assign - assign a DMA engine cookie to the descriptor
  20. * @tx: descriptor needing cookie
  21. *
  22. * Assign a unique non-zero per-channel cookie to the descriptor.
  23. * Note: caller is expected to hold a lock to prevent concurrency.
  24. */
  25. static inline dma_cookie_t dma_cookie_assign(struct dma_async_tx_descriptor *tx)
  26. {
  27. struct dma_chan *chan = tx->chan;
  28. dma_cookie_t cookie;
  29. cookie = chan->cookie + 1;
  30. if (cookie < DMA_MIN_COOKIE)
  31. cookie = DMA_MIN_COOKIE;
  32. tx->cookie = chan->cookie = cookie;
  33. return cookie;
  34. }
  35. /**
  36. * dma_cookie_complete - complete a descriptor
  37. * @tx: descriptor to complete
  38. *
  39. * Mark this descriptor complete by updating the channels completed
  40. * cookie marker. Zero the descriptors cookie to prevent accidental
  41. * repeated completions.
  42. *
  43. * Note: caller is expected to hold a lock to prevent concurrency.
  44. */
  45. static inline void dma_cookie_complete(struct dma_async_tx_descriptor *tx)
  46. {
  47. BUG_ON(tx->cookie < DMA_MIN_COOKIE);
  48. tx->chan->completed_cookie = tx->cookie;
  49. tx->cookie = 0;
  50. }
  51. /**
  52. * dma_cookie_status - report cookie status
  53. * @chan: dma channel
  54. * @cookie: cookie we are interested in
  55. * @state: dma_tx_state structure to return last/used cookies
  56. *
  57. * Report the status of the cookie, filling in the state structure if
  58. * non-NULL. No locking is required.
  59. */
  60. static inline enum dma_status dma_cookie_status(struct dma_chan *chan,
  61. dma_cookie_t cookie, struct dma_tx_state *state)
  62. {
  63. dma_cookie_t used, complete;
  64. used = chan->cookie;
  65. complete = chan->completed_cookie;
  66. barrier();
  67. if (state) {
  68. state->last = complete;
  69. state->used = used;
  70. state->residue = 0;
  71. }
  72. return dma_async_is_complete(cookie, complete, used);
  73. }
  74. static inline void dma_set_residue(struct dma_tx_state *state, u32 residue)
  75. {
  76. if (state)
  77. state->residue = residue;
  78. }
  79. #endif