dma-fence-array.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * fence-array: aggregates fence to be waited together
  3. *
  4. * Copyright (C) 2016 Collabora Ltd
  5. * Copyright (C) 2016 Advanced Micro Devices, Inc.
  6. * Authors:
  7. * Gustavo Padovan <gustavo@padovan.org>
  8. * Christian König <christian.koenig@amd.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License version 2 as published by
  12. * the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful, but WITHOUT
  15. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  16. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  17. * more details.
  18. */
  19. #ifndef __LINUX_DMA_FENCE_ARRAY_H
  20. #define __LINUX_DMA_FENCE_ARRAY_H
  21. #include <linux/dma-fence.h>
  22. #include <linux/irq_work.h>
  23. /**
  24. * struct dma_fence_array_cb - callback helper for fence array
  25. * @cb: fence callback structure for signaling
  26. * @array: reference to the parent fence array object
  27. */
  28. struct dma_fence_array_cb {
  29. struct dma_fence_cb cb;
  30. struct dma_fence_array *array;
  31. };
  32. /**
  33. * struct dma_fence_array - fence to represent an array of fences
  34. * @base: fence base class
  35. * @lock: spinlock for fence handling
  36. * @num_fences: number of fences in the array
  37. * @num_pending: fences in the array still pending
  38. * @fences: array of the fences
  39. */
  40. struct dma_fence_array {
  41. struct dma_fence base;
  42. spinlock_t lock;
  43. unsigned num_fences;
  44. atomic_t num_pending;
  45. struct dma_fence **fences;
  46. struct irq_work work;
  47. };
  48. extern const struct dma_fence_ops dma_fence_array_ops;
  49. /**
  50. * dma_fence_is_array - check if a fence is from the array subsclass
  51. * @fence: fence to test
  52. *
  53. * Return true if it is a dma_fence_array and false otherwise.
  54. */
  55. static inline bool dma_fence_is_array(struct dma_fence *fence)
  56. {
  57. return fence->ops == &dma_fence_array_ops;
  58. }
  59. /**
  60. * to_dma_fence_array - cast a fence to a dma_fence_array
  61. * @fence: fence to cast to a dma_fence_array
  62. *
  63. * Returns NULL if the fence is not a dma_fence_array,
  64. * or the dma_fence_array otherwise.
  65. */
  66. static inline struct dma_fence_array *
  67. to_dma_fence_array(struct dma_fence *fence)
  68. {
  69. if (fence->ops != &dma_fence_array_ops)
  70. return NULL;
  71. return container_of(fence, struct dma_fence_array, base);
  72. }
  73. struct dma_fence_array *dma_fence_array_create(int num_fences,
  74. struct dma_fence **fences,
  75. u64 context, unsigned seqno,
  76. bool signal_on_any);
  77. bool dma_fence_match_context(struct dma_fence *fence, u64 context);
  78. #endif /* __LINUX_DMA_FENCE_ARRAY_H */