cam_sync_dma_fence.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /* SPDX-License-Identifier: GPL-2.0-only
  2. *
  3. * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
  4. */
  5. #ifndef __CAM_SYNC_DMA_FENCE_H__
  6. #define __CAM_SYNC_DMA_FENCE_H__
  7. #include <linux/dma-fence.h>
  8. #include <linux/spinlock_types.h>
  9. #include <linux/sync_file.h>
  10. #include <linux/file.h>
  11. #include <linux/bitmap.h>
  12. #include "cam_sync.h"
  13. #include "cam_debug_util.h"
  14. #define CAM_DMA_FENCE_MAX_FENCES 128
  15. #define CAM_DMA_FENCE_NAME_LEN 128
  16. /* DMA fence state */
  17. enum cam_dma_fence_state {
  18. CAM_DMA_FENCE_STATE_INVALID,
  19. CAM_DMA_FENCE_STATE_ACTIVE,
  20. CAM_DMA_FENCE_STATE_SIGNALED,
  21. };
  22. /**
  23. * struct cam_dma_fence_release_params - DMA release payload
  24. * Based on the flag row_idx or fd is consumed
  25. *
  26. * @dma_row_idx : DMA fence row idx
  27. * @dma_fence_fd : DMA fence fd
  28. * @use_row_idx : Use row idx
  29. */
  30. struct cam_dma_fence_release_params {
  31. union {
  32. int32_t dma_row_idx;
  33. int32_t dma_fence_fd;
  34. } u;
  35. bool use_row_idx;
  36. };
  37. /**
  38. * struct cam_dma_fence_signal_sync_obj - DMA -> sync signal info
  39. * Payload to signal sync on a dma fence
  40. * being signaled
  41. *
  42. * @status : DMA fence status
  43. * @fd : DMA fence fd if any
  44. */
  45. struct cam_dma_fence_signal_sync_obj {
  46. int32_t status;
  47. int32_t fd;
  48. };
  49. /* DMA fence callback function type */
  50. typedef int (*cam_sync_callback_for_dma_fence)(int32_t sync_obj,
  51. struct cam_dma_fence_signal_sync_obj *signal_sync_obj);
  52. /**
  53. * struct cam_dma_fence_create_sync_obj_payload -
  54. * Payload to create sync for a dma fence
  55. *
  56. * @dma_fence_row_idx : DMA fence row idx
  57. * @fd : DMA fence fd
  58. * @sync_created_with_dma : Set if dma fence and sync obj are being
  59. * created in a single IOCTL call
  60. */
  61. struct cam_dma_fence_create_sync_obj_payload {
  62. int32_t dma_fence_row_idx;
  63. int32_t fd;
  64. bool sync_created_with_dma;
  65. };
  66. /**
  67. * @brief: Signal a dma fence fd [userspace API]
  68. *
  69. * @param signal_dma_fence: Info on DMA fence to be signaled
  70. *
  71. * @return Status of operation. Negative in case of error. Zero otherwise.
  72. */
  73. int cam_dma_fence_signal_fd(
  74. struct cam_dma_fence_signal *signal_dma_fence);
  75. /**
  76. * @brief: Signal a dma fence when sync obj is signaled
  77. *
  78. * @param dma_fence_row_idx : DMA fence row idx
  79. * @param signal_dma_fence : Info on DMA fence to be signaled
  80. *
  81. * @return Status of operation. Negative in case of error. Zero otherwise.
  82. */
  83. int cam_dma_fence_internal_signal(int32_t dma_fence_row_idx,
  84. struct cam_dma_fence_signal *signal_dma_fence);
  85. /**
  86. * @brief: Create a dma fence fd
  87. *
  88. * @param name : DMA fence name, optional param
  89. * will accommodate names of length
  90. * CAM_DMA_FENCE_NAME_LEN
  91. * @output dma_fence_fd : DMA fence fd
  92. * @output dma_fence_row_idx : Row Idx corresponding to DMA fence in the table
  93. *
  94. * @return Status of operation. Negative in case of error. Zero otherwise.
  95. */
  96. int cam_dma_fence_create_fd(
  97. int32_t *dma_fence_fd, int32_t *dma_fence_row_idx, const char *name);
  98. /**
  99. * @brief: Release a dma fence
  100. *
  101. * @param release_params : dma fence info to be released
  102. *
  103. * @return Status of operation. Negative in case of error. Zero otherwise.
  104. */
  105. int cam_dma_fence_release(
  106. struct cam_dma_fence_release_params *release_params);
  107. /**
  108. * @brief: Gets the dma fence from a fd, increments refcnt
  109. *
  110. * @param fd : File descriptor
  111. * @output dma_fence_row_idx : Row idx pertaining to this dma fence
  112. *
  113. * @return Status of operation. Error or valid fence.
  114. */
  115. struct dma_fence *cam_dma_fence_get_fence_from_fd(int32_t fd,
  116. int32_t *dma_fence_row_idx);
  117. /**
  118. * @brief: DMA fence register cb
  119. *
  120. * @param sync_obj : Sync object
  121. * @param dma_fence_idx : DMA fence row idx
  122. * @param sync_cb : Sync object callback
  123. *
  124. * @return Status of operation. Negative in case of error. Zero otherwise.
  125. */
  126. int cam_dma_fence_register_cb(int32_t *sync_obj,
  127. int32_t *dma_fence_row_idx, cam_sync_callback_for_dma_fence sync_cb);
  128. /**
  129. * @brief: get/put on dma fence
  130. *
  131. * @get_or_put : True for get, false for put
  132. * @param dma_fence_row_idx : Idx in the dma fence table pertaining to
  133. * the dma fence on which get/put ref is invoked
  134. *
  135. * @return Status of operation. Negative in case of error. Zero otherwise.
  136. */
  137. int cam_dma_fence_get_put_ref(bool get_or_put, int32_t dma_fence_row_idx);
  138. /**
  139. * @brief: dma fence driver open
  140. *
  141. */
  142. void cam_dma_fence_open(void);
  143. /**
  144. * @brief: dma fence driver close
  145. *
  146. */
  147. void cam_dma_fence_close(void);
  148. /**
  149. * @brief: dma fence driver initialize
  150. *
  151. */
  152. int cam_dma_fence_driver_init(void);
  153. /**
  154. * @brief: dma fence driver deinit
  155. *
  156. */
  157. void cam_dma_fence_driver_deinit(void);
  158. #endif /* __CAM_SYNC_DMA_FENCE_H__ */