fence-array.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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_FENCE_ARRAY_H
  20. #define __LINUX_FENCE_ARRAY_H
  21. #include <linux/fence.h>
  22. /**
  23. * struct fence_array_cb - callback helper for fence array
  24. * @cb: fence callback structure for signaling
  25. * @array: reference to the parent fence array object
  26. */
  27. struct fence_array_cb {
  28. struct fence_cb cb;
  29. struct fence_array *array;
  30. };
  31. /**
  32. * struct fence_array - fence to represent an array of fences
  33. * @base: fence base class
  34. * @lock: spinlock for fence handling
  35. * @num_fences: number of fences in the array
  36. * @num_pending: fences in the array still pending
  37. * @fences: array of the fences
  38. */
  39. struct fence_array {
  40. struct fence base;
  41. spinlock_t lock;
  42. unsigned num_fences;
  43. atomic_t num_pending;
  44. struct fence **fences;
  45. };
  46. extern const struct fence_ops fence_array_ops;
  47. /**
  48. * fence_is_array - check if a fence is from the array subsclass
  49. *
  50. * Return true if it is a fence_array and false otherwise.
  51. */
  52. static inline bool fence_is_array(struct fence *fence)
  53. {
  54. return fence->ops == &fence_array_ops;
  55. }
  56. /**
  57. * to_fence_array - cast a fence to a fence_array
  58. * @fence: fence to cast to a fence_array
  59. *
  60. * Returns NULL if the fence is not a fence_array,
  61. * or the fence_array otherwise.
  62. */
  63. static inline struct fence_array *to_fence_array(struct fence *fence)
  64. {
  65. if (fence->ops != &fence_array_ops)
  66. return NULL;
  67. return container_of(fence, struct fence_array, base);
  68. }
  69. struct fence_array *fence_array_create(int num_fences, struct fence **fences,
  70. u64 context, unsigned seqno,
  71. bool signal_on_any);
  72. #endif /* __LINUX_FENCE_ARRAY_H */