dma-fence-array.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * fence-array: aggregates fence to be waited together
  4. *
  5. * Copyright (C) 2016 Collabora Ltd
  6. * Copyright (C) 2016 Advanced Micro Devices, Inc.
  7. * Authors:
  8. * Gustavo Padovan <[email protected]>
  9. * Christian König <[email protected]>
  10. */
  11. #ifndef __LINUX_DMA_FENCE_ARRAY_H
  12. #define __LINUX_DMA_FENCE_ARRAY_H
  13. #include <linux/dma-fence.h>
  14. #include <linux/irq_work.h>
  15. /**
  16. * struct dma_fence_array_cb - callback helper for fence array
  17. * @cb: fence callback structure for signaling
  18. * @array: reference to the parent fence array object
  19. */
  20. struct dma_fence_array_cb {
  21. struct dma_fence_cb cb;
  22. struct dma_fence_array *array;
  23. };
  24. /**
  25. * struct dma_fence_array - fence to represent an array of fences
  26. * @base: fence base class
  27. * @lock: spinlock for fence handling
  28. * @num_fences: number of fences in the array
  29. * @num_pending: fences in the array still pending
  30. * @fences: array of the fences
  31. * @work: internal irq_work function
  32. */
  33. struct dma_fence_array {
  34. struct dma_fence base;
  35. spinlock_t lock;
  36. unsigned num_fences;
  37. atomic_t num_pending;
  38. struct dma_fence **fences;
  39. struct irq_work work;
  40. };
  41. /**
  42. * to_dma_fence_array - cast a fence to a dma_fence_array
  43. * @fence: fence to cast to a dma_fence_array
  44. *
  45. * Returns NULL if the fence is not a dma_fence_array,
  46. * or the dma_fence_array otherwise.
  47. */
  48. static inline struct dma_fence_array *
  49. to_dma_fence_array(struct dma_fence *fence)
  50. {
  51. if (!fence || !dma_fence_is_array(fence))
  52. return NULL;
  53. return container_of(fence, struct dma_fence_array, base);
  54. }
  55. /**
  56. * dma_fence_array_for_each - iterate over all fences in array
  57. * @fence: current fence
  58. * @index: index into the array
  59. * @head: potential dma_fence_array object
  60. *
  61. * Test if @array is a dma_fence_array object and if yes iterate over all fences
  62. * in the array. If not just iterate over the fence in @array itself.
  63. *
  64. * For a deep dive iterator see dma_fence_unwrap_for_each().
  65. */
  66. #define dma_fence_array_for_each(fence, index, head) \
  67. for (index = 0, fence = dma_fence_array_first(head); fence; \
  68. ++(index), fence = dma_fence_array_next(head, index))
  69. struct dma_fence_array *dma_fence_array_create(int num_fences,
  70. struct dma_fence **fences,
  71. u64 context, unsigned seqno,
  72. bool signal_on_any);
  73. bool dma_fence_match_context(struct dma_fence *fence, u64 context);
  74. struct dma_fence *dma_fence_array_first(struct dma_fence *head);
  75. struct dma_fence *dma_fence_array_next(struct dma_fence *head,
  76. unsigned int index);
  77. #endif /* __LINUX_DMA_FENCE_ARRAY_H */