dma-fence-array.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 <gustavo@padovan.org>
  9. * Christian König <christian.koenig@amd.com>
  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. extern const struct dma_fence_ops dma_fence_array_ops;
  42. /**
  43. * dma_fence_is_array - check if a fence is from the array subsclass
  44. * @fence: fence to test
  45. *
  46. * Return true if it is a dma_fence_array and false otherwise.
  47. */
  48. static inline bool dma_fence_is_array(struct dma_fence *fence)
  49. {
  50. return fence->ops == &dma_fence_array_ops;
  51. }
  52. /**
  53. * to_dma_fence_array - cast a fence to a dma_fence_array
  54. * @fence: fence to cast to a dma_fence_array
  55. *
  56. * Returns NULL if the fence is not a dma_fence_array,
  57. * or the dma_fence_array otherwise.
  58. */
  59. static inline struct dma_fence_array *
  60. to_dma_fence_array(struct dma_fence *fence)
  61. {
  62. if (fence->ops != &dma_fence_array_ops)
  63. return NULL;
  64. return container_of(fence, struct dma_fence_array, base);
  65. }
  66. struct dma_fence_array *dma_fence_array_create(int num_fences,
  67. struct dma_fence **fences,
  68. u64 context, unsigned seqno,
  69. bool signal_on_any);
  70. bool dma_fence_match_context(struct dma_fence *fence, u64 context);
  71. #endif /* __LINUX_DMA_FENCE_ARRAY_H */