cam_sync_util.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef __CAM_SYNC_UTIL_H__
  7. #define __CAM_SYNC_UTIL_H__
  8. #include "cam_sync_private.h"
  9. #include "cam_debug_util.h"
  10. extern struct sync_device *sync_dev;
  11. /**
  12. * struct cam_sync_check_for_dma_release -
  13. * Checks if the dma fence being released
  14. * was created with the sync obj
  15. *
  16. * @dma_fence_row_idx : Get DMA fence row idx that is associated with
  17. * the sync obj
  18. * @dma_fence_fd : Check if DMA fence fd is associated with
  19. * sync obj
  20. * @sync_created_with_dma : Set if the dma fence fd was created
  21. * with sync obj
  22. */
  23. struct cam_sync_check_for_dma_release {
  24. int32_t dma_fence_row_idx;
  25. int32_t dma_fence_fd;
  26. bool sync_created_with_dma;
  27. };
  28. /**
  29. * struct cam_sync_check_for_synx_release -
  30. * Checks if the synx obj being released
  31. * was created with the sync obj
  32. *
  33. * @synx_obj : Check if synx obj is associated with
  34. * sync obj
  35. * @synx_obj_row_idx : Get synx obj row idx that is associated with
  36. * the sync obj
  37. * @sync_created_with_synx : Set if the dma fence fd was created
  38. * with sync obj
  39. */
  40. struct cam_sync_check_for_synx_release {
  41. int32_t synx_obj;
  42. int32_t synx_obj_row_idx;
  43. bool sync_created_with_synx;
  44. };
  45. /**
  46. * @brief: Finds an empty row in the sync table and sets its corresponding bit
  47. * in the bit array
  48. *
  49. * @param sync_dev : Pointer to the sync device instance
  50. * @param idx : Pointer to an long containing the index found in the bit
  51. * array
  52. *
  53. * @return Status of operation. Negative in case of error. Zero otherwise.
  54. */
  55. int cam_sync_util_find_and_set_empty_row(struct sync_device *sync_dev,
  56. long *idx);
  57. /**
  58. * @brief: Function to initialize an empty row in the sync table. This should be
  59. * called only for individual sync objects.
  60. *
  61. * @param table : Pointer to the sync objects table
  62. * @param idx : Index of row to initialize
  63. * @param name : Optional string representation of the sync object. Should be
  64. * 63 characters or less
  65. * @param type : type of row to be initialized
  66. * @return Status of operation. Negative in case of error. Zero otherwise.
  67. */
  68. int cam_sync_init_row(struct sync_table_row *table,
  69. uint32_t idx, const char *name, uint32_t type);
  70. /**
  71. * @brief: Function to uninitialize a row in the sync table
  72. *
  73. * @param table : Pointer to the sync objects table
  74. * @param idx : Index of row to initialize
  75. * @optional param check_for_dma_release : checks for dma fence release
  76. * @optional param check_for_synx_release : checks for synx obj release
  77. *
  78. * @return Status of operation. Negative in case of error. Zero otherwise.
  79. */
  80. int cam_sync_deinit_object(struct sync_table_row *table, uint32_t idx,
  81. struct cam_sync_check_for_dma_release *check_for_dma_release,
  82. struct cam_sync_check_for_synx_release *check_for_synx_release);
  83. /**
  84. * @brief: Function to initialize a row in the sync table when the object is a
  85. * group object, also known as a merged sync object
  86. *
  87. * @param table : Pointer to the sync objects table
  88. * @param idx : Index of row to initialize
  89. * @param sync_objs : Array of sync objects which will merged
  90. * or grouped together
  91. * @param num_objs : Number of sync objects in the array
  92. *
  93. * @return Status of operation. Negative in case of error. Zero otherwise.
  94. */
  95. int cam_sync_init_group_object(struct sync_table_row *table,
  96. uint32_t idx,
  97. uint32_t *sync_objs,
  98. uint32_t num_objs);
  99. /**
  100. * @brief: Function to dispatch a kernel callback for a sync callback
  101. *
  102. * @param cb_dispatch_work : Pointer to the work_struct that needs to be
  103. * dispatched
  104. *
  105. * @return None
  106. */
  107. void cam_sync_util_cb_dispatch(struct work_struct *cb_dispatch_work);
  108. /**
  109. * @brief: Function to dispatch callbacks for a signaled sync object
  110. *
  111. * @sync_obj : Sync object that is signaled
  112. * @status : Status of the signaled object
  113. * @evt_param : Event paramaeter
  114. *
  115. * @return None
  116. */
  117. void cam_sync_util_dispatch_signaled_cb(int32_t sync_obj,
  118. uint32_t status, uint32_t evt_param);
  119. /**
  120. * @brief: Function to send V4L event to user space
  121. * @param id : V4L event id to send
  122. * @param sync_obj : Sync obj for which event needs to be sent
  123. * @param status : Status of the event
  124. * @payload : Payload that needs to be sent to user space
  125. * @len : Length of the payload
  126. * @evt_param : Event Paramenter
  127. *
  128. * @return None
  129. */
  130. void cam_sync_util_send_v4l2_event(uint32_t id,
  131. uint32_t sync_obj,
  132. int status,
  133. void *payload,
  134. int len,
  135. uint32_t evt_param);
  136. /**
  137. * @brief: Function which gets the next state of the sync object based on the
  138. * current state and the new state
  139. *
  140. * @param current_state : Current state of the sync object
  141. * @param new_state : New state of the sync object
  142. *
  143. * @return Next state of the sync object
  144. */
  145. int cam_sync_util_update_parent_state(struct sync_table_row *parent_row,
  146. int new_state);
  147. /**
  148. * @brief: Function to clean up the children of a sync object
  149. * @row : Row whose child list to clean
  150. * @list_clean_type : Clean specific object or clean all objects
  151. * @sync_obj : Sync object to be clean if list clean type is
  152. * SYNC_LIST_CLEAN_ONE
  153. *
  154. * @return None
  155. */
  156. void cam_sync_util_cleanup_children_list(struct sync_table_row *row,
  157. uint32_t list_clean_type, uint32_t sync_obj);
  158. /**
  159. * @brief: Function to clean up the parents of a sync object
  160. * @row : Row whose parent list to clean
  161. * @list_clean_type : Clean specific object or clean all objects
  162. * @sync_obj : Sync object to be clean if list clean type is
  163. * SYNC_LIST_CLEAN_ONE
  164. *
  165. * @return None
  166. */
  167. void cam_sync_util_cleanup_parents_list(struct sync_table_row *row,
  168. uint32_t list_clean_type, uint32_t sync_obj);
  169. /**
  170. * @brief: Function to dump sync obj & monitor data
  171. * @row : Row whose data to dump
  172. *
  173. * @return None
  174. */
  175. void cam_sync_dump_monitor_array(struct sync_table_row *row);
  176. /**
  177. * @brief: Function to add a new entry to the monitor table
  178. * @idx : Index of row to update
  179. * @mutex : Mutex lock when expand monitor table
  180. * @mon_data : Pointer to the monitor data array
  181. * @op : Operation id
  182. *
  183. * @return None
  184. */
  185. void cam_generic_fence_update_monitor_array(int idx,
  186. struct mutex *lock,
  187. struct cam_generic_fence_monitor_data **mon_data,
  188. enum cam_fence_op op);
  189. /**
  190. * @brief: Function to dump monitor array for sync/dma/synx
  191. * @obj_info : Monitor object that needs to be dumped
  192. *
  193. * @return None
  194. */
  195. void cam_generic_fence_dump_monitor_array(
  196. struct cam_generic_fence_monitor_obj_info *obj_info);
  197. #endif /* __CAM_SYNC_UTIL_H__ */