cam_sync_util.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022 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. * @brief: Finds an empty row in the sync table and sets its corresponding bit
  30. * in the bit array
  31. *
  32. * @param sync_dev : Pointer to the sync device instance
  33. * @param idx : Pointer to an long containing the index found in the bit
  34. * array
  35. *
  36. * @return Status of operation. Negative in case of error. Zero otherwise.
  37. */
  38. int cam_sync_util_find_and_set_empty_row(struct sync_device *sync_dev,
  39. long *idx);
  40. /**
  41. * @brief: Function to initialize an empty row in the sync table. This should be
  42. * called only for individual sync objects.
  43. *
  44. * @param table : Pointer to the sync objects table
  45. * @param idx : Index of row to initialize
  46. * @param name : Optional string representation of the sync object. Should be
  47. * 63 characters or less
  48. * @param type : type of row to be initialized
  49. * @return Status of operation. Negative in case of error. Zero otherwise.
  50. */
  51. int cam_sync_init_row(struct sync_table_row *table,
  52. uint32_t idx, const char *name, uint32_t type);
  53. /**
  54. * @brief: Function to uninitialize a row in the sync table
  55. *
  56. * @param table : Pointer to the sync objects table
  57. * @param idx : Index of row to initialize
  58. * @optional param check_for_dma_release : checks for dma fence release
  59. *
  60. * @return Status of operation. Negative in case of error. Zero otherwise.
  61. */
  62. int cam_sync_deinit_object(struct sync_table_row *table, uint32_t idx,
  63. struct cam_sync_check_for_dma_release *check_for_dma_release);
  64. /**
  65. * @brief: Function to initialize a row in the sync table when the object is a
  66. * group object, also known as a merged sync object
  67. *
  68. * @param table : Pointer to the sync objects table
  69. * @param idx : Index of row to initialize
  70. * @param sync_objs : Array of sync objects which will merged
  71. * or grouped together
  72. * @param num_objs : Number of sync objects in the array
  73. *
  74. * @return Status of operation. Negative in case of error. Zero otherwise.
  75. */
  76. int cam_sync_init_group_object(struct sync_table_row *table,
  77. uint32_t idx,
  78. uint32_t *sync_objs,
  79. uint32_t num_objs);
  80. /**
  81. * @brief: Function to dispatch a kernel callback for a sync callback
  82. *
  83. * @param cb_dispatch_work : Pointer to the work_struct that needs to be
  84. * dispatched
  85. *
  86. * @return None
  87. */
  88. void cam_sync_util_cb_dispatch(struct work_struct *cb_dispatch_work);
  89. /**
  90. * @brief: Function to dispatch callbacks for a signaled sync object
  91. *
  92. * @sync_obj : Sync object that is signaled
  93. * @status : Status of the signaled object
  94. * @evt_param : Event paramaeter
  95. *
  96. * @return None
  97. */
  98. void cam_sync_util_dispatch_signaled_cb(int32_t sync_obj,
  99. uint32_t status, uint32_t evt_param);
  100. /**
  101. * @brief: Function to send V4L event to user space
  102. * @param id : V4L event id to send
  103. * @param sync_obj : Sync obj for which event needs to be sent
  104. * @param status : Status of the event
  105. * @payload : Payload that needs to be sent to user space
  106. * @len : Length of the payload
  107. * @evt_param : Event Paramenter
  108. *
  109. * @return None
  110. */
  111. void cam_sync_util_send_v4l2_event(uint32_t id,
  112. uint32_t sync_obj,
  113. int status,
  114. void *payload,
  115. int len,
  116. uint32_t evt_param);
  117. /**
  118. * @brief: Function which gets the next state of the sync object based on the
  119. * current state and the new state
  120. *
  121. * @param current_state : Current state of the sync object
  122. * @param new_state : New state of the sync object
  123. *
  124. * @return Next state of the sync object
  125. */
  126. int cam_sync_util_update_parent_state(struct sync_table_row *parent_row,
  127. int new_state);
  128. /**
  129. * @brief: Function to clean up the children of a sync object
  130. * @row : Row whose child list to clean
  131. * @list_clean_type : Clean specific object or clean all objects
  132. * @sync_obj : Sync object to be clean if list clean type is
  133. * SYNC_LIST_CLEAN_ONE
  134. *
  135. * @return None
  136. */
  137. void cam_sync_util_cleanup_children_list(struct sync_table_row *row,
  138. uint32_t list_clean_type, uint32_t sync_obj);
  139. /**
  140. * @brief: Function to clean up the parents of a sync object
  141. * @row : Row whose parent list to clean
  142. * @list_clean_type : Clean specific object or clean all objects
  143. * @sync_obj : Sync object to be clean if list clean type is
  144. * SYNC_LIST_CLEAN_ONE
  145. *
  146. * @return None
  147. */
  148. void cam_sync_util_cleanup_parents_list(struct sync_table_row *row,
  149. uint32_t list_clean_type, uint32_t sync_obj);
  150. #endif /* __CAM_SYNC_UTIL_H__ */