dma-fence-chain.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * fence-chain: chain fences together in a timeline
  4. *
  5. * Copyright (C) 2018 Advanced Micro Devices, Inc.
  6. * Authors:
  7. * Christian König <christian.koenig@amd.com>
  8. */
  9. #ifndef __LINUX_DMA_FENCE_CHAIN_H
  10. #define __LINUX_DMA_FENCE_CHAIN_H
  11. #include <linux/dma-fence.h>
  12. #include <linux/irq_work.h>
  13. /**
  14. * struct dma_fence_chain - fence to represent an node of a fence chain
  15. * @base: fence base class
  16. * @lock: spinlock for fence handling
  17. * @prev: previous fence of the chain
  18. * @prev_seqno: original previous seqno before garbage collection
  19. * @fence: encapsulated fence
  20. * @cb: callback structure for signaling
  21. * @work: irq work item for signaling
  22. */
  23. struct dma_fence_chain {
  24. struct dma_fence base;
  25. spinlock_t lock;
  26. struct dma_fence __rcu *prev;
  27. u64 prev_seqno;
  28. struct dma_fence *fence;
  29. struct dma_fence_cb cb;
  30. struct irq_work work;
  31. };
  32. extern const struct dma_fence_ops dma_fence_chain_ops;
  33. /**
  34. * to_dma_fence_chain - cast a fence to a dma_fence_chain
  35. * @fence: fence to cast to a dma_fence_array
  36. *
  37. * Returns NULL if the fence is not a dma_fence_chain,
  38. * or the dma_fence_chain otherwise.
  39. */
  40. static inline struct dma_fence_chain *
  41. to_dma_fence_chain(struct dma_fence *fence)
  42. {
  43. if (!fence || fence->ops != &dma_fence_chain_ops)
  44. return NULL;
  45. return container_of(fence, struct dma_fence_chain, base);
  46. }
  47. /**
  48. * dma_fence_chain_for_each - iterate over all fences in chain
  49. * @iter: current fence
  50. * @head: starting point
  51. *
  52. * Iterate over all fences in the chain. We keep a reference to the current
  53. * fence while inside the loop which must be dropped when breaking out.
  54. */
  55. #define dma_fence_chain_for_each(iter, head) \
  56. for (iter = dma_fence_get(head); iter; \
  57. iter = dma_fence_chain_walk(iter))
  58. struct dma_fence *dma_fence_chain_walk(struct dma_fence *fence);
  59. int dma_fence_chain_find_seqno(struct dma_fence **pfence, uint64_t seqno);
  60. void dma_fence_chain_init(struct dma_fence_chain *chain,
  61. struct dma_fence *prev,
  62. struct dma_fence *fence,
  63. uint64_t seqno);
  64. #endif /* __LINUX_DMA_FENCE_CHAIN_H */