mali_kbase_dma_fence.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. *
  3. * (C) COPYRIGHT 2010-2016 ARM Limited. All rights reserved.
  4. *
  5. * This program is free software and is provided to you under the terms of the
  6. * GNU General Public License version 2 as published by the Free Software
  7. * Foundation, and any use by you of this program is subject to the terms
  8. * of such GNU licence.
  9. *
  10. * A copy of the licence is included with the program, and can also be obtained
  11. * from Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  12. * Boston, MA 02110-1301, USA.
  13. *
  14. */
  15. #include "config.h"
  16. #ifndef _KBASE_DMA_FENCE_H_
  17. #define _KBASE_DMA_FENCE_H_
  18. #ifdef CONFIG_MALI_DMA_FENCE
  19. //#include <linux/fence.h>
  20. #include <linux/dma-fence.h>
  21. #include <linux/list.h>
  22. #include <linux/reservation.h>
  23. /* Forward declaration from mali_kbase_defs.h */
  24. struct kbase_jd_atom;
  25. struct kbase_context;
  26. /**
  27. * struct kbase_dma_fence_cb - Mali dma-fence callback data struct
  28. * @fence_cb: Callback function
  29. * @katom: Pointer to katom that is waiting on this callback
  30. * @fence: Pointer to the fence object on which this callback is waiting
  31. * @node: List head for linking this callback to the katom
  32. */
  33. struct kbase_dma_fence_cb {
  34. struct dma_fence_cb fence_cb;
  35. struct kbase_jd_atom *katom;
  36. struct dma_fence *fence;
  37. struct list_head node;
  38. };
  39. /**
  40. * struct kbase_dma_fence_resv_info - Structure with list of reservation objects
  41. * @resv_objs: Array of reservation objects to attach the
  42. * new fence to.
  43. * @dma_fence_resv_count: Number of reservation objects in the array.
  44. * @dma_fence_excl_bitmap: Specifies which resv_obj are exclusive.
  45. *
  46. * This is used by some functions to pass around a collection of data about
  47. * reservation objects.
  48. */
  49. struct kbase_dma_fence_resv_info {
  50. struct reservation_object **resv_objs;
  51. unsigned int dma_fence_resv_count;
  52. unsigned long *dma_fence_excl_bitmap;
  53. };
  54. /**
  55. * kbase_dma_fence_add_reservation() - Adds a resv to the array of resv_objs
  56. * @resv: Reservation object to add to the array.
  57. * @info: Pointer to struct with current reservation info
  58. * @exclusive: Boolean indicating if exclusive access is needed
  59. *
  60. * The function adds a new reservation_object to an existing array of
  61. * reservation_objects. At the same time keeps track of which objects require
  62. * exclusive access in dma_fence_excl_bitmap.
  63. */
  64. void kbase_dma_fence_add_reservation(struct reservation_object *resv,
  65. struct kbase_dma_fence_resv_info *info,
  66. bool exclusive);
  67. /**
  68. * kbase_dma_fence_wait() - Creates a new fence and attaches it to the resv_objs
  69. * @katom: Katom with the external dependency.
  70. * @info: Pointer to struct with current reservation info
  71. *
  72. * Return: An error code or 0 if succeeds
  73. */
  74. int kbase_dma_fence_wait(struct kbase_jd_atom *katom,
  75. struct kbase_dma_fence_resv_info *info);
  76. /**
  77. * kbase_dma_fence_cancel_ctx() - Cancel all dma-fences blocked atoms on kctx
  78. * @kctx: Pointer to kbase context
  79. *
  80. * This function will cancel and clean up all katoms on @kctx that is waiting
  81. * on dma-buf fences.
  82. *
  83. * Locking: jctx.lock needs to be held when calling this function.
  84. */
  85. void kbase_dma_fence_cancel_all_atoms(struct kbase_context *kctx);
  86. /**
  87. * kbase_dma_fence_cancel_callbacks() - Cancel only callbacks on katom
  88. * @katom: Pointer to katom whose callbacks are to be canceled
  89. *
  90. * This function cancels all dma-buf fence callbacks on @katom, but does not
  91. * cancel the katom itself.
  92. *
  93. * The caller is responsible for ensuring that jd_done_nolock is called on
  94. * @katom.
  95. *
  96. * Locking: jctx.lock must be held when calling this function.
  97. */
  98. void kbase_dma_fence_cancel_callbacks(struct kbase_jd_atom *katom);
  99. /**
  100. * kbase_dma_fence_signal() - Signal katom's fence and clean up after wait
  101. * @katom: Pointer to katom to signal and clean up
  102. *
  103. * This function will signal the @katom's fence, if it has one, and clean up
  104. * the callback data from the katom's wait on earlier fences.
  105. *
  106. * Locking: jctx.lock must be held while calling this function.
  107. */
  108. void kbase_dma_fence_signal(struct kbase_jd_atom *katom);
  109. /**
  110. * kbase_dma_fence_term() - Terminate Mali dma-fence context
  111. * @kctx: kbase context to terminate
  112. */
  113. void kbase_dma_fence_term(struct kbase_context *kctx);
  114. /**
  115. * kbase_dma_fence_init() - Initialize Mali dma-fence context
  116. * @kctx: kbase context to initialize
  117. */
  118. int kbase_dma_fence_init(struct kbase_context *kctx);
  119. /**
  120. * kbase_dma_fence_waiters_remove()- Remove katom from dma-fence wait list
  121. * @katom: Pointer to katom to remove from list
  122. */
  123. void kbase_dma_fence_waiters_remove(struct kbase_jd_atom *katom);
  124. #else // ifdef CONFIG_MALI_DMA_FENCE
  125. /* Dummy functions for when dma-buf fence isn't enabled. */
  126. static inline int kbase_dma_fence_init(struct kbase_context *kctx)
  127. {
  128. return 0;
  129. }
  130. static inline void kbase_dma_fence_term(struct kbase_context *kctx) {}
  131. #endif // ifdef CONFIG_MALI_DMA_FENCE
  132. #endif // ifndef _KBASE_DMA_FENCE_H_