cam_sync_api.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef __CAM_SYNC_API_H__
  7. #define __CAM_SYNC_API_H__
  8. #include <linux/mutex.h>
  9. #include <linux/list.h>
  10. #include <linux/completion.h>
  11. #include <linux/videodev2.h>
  12. #include <media/cam_sync.h>
  13. #define SYNC_DEBUG_NAME_LEN 63
  14. typedef void (*sync_callback)(int32_t sync_obj, int status, void *data);
  15. enum cam_sync_synx_supported_cores {
  16. CAM_ICP_0_SYNX_CORE = 1,
  17. CAM_ICP_1_SYNX_CORE,
  18. CAM_INVALID_SYNX_CORE,
  19. };
  20. /* Kernel APIs */
  21. /**
  22. * @brief: Creates a sync object
  23. *
  24. * The newly created sync obj is assigned to sync_obj.
  25. * sync object.
  26. *
  27. * @param sync_obj : Pointer to int referencing the sync object.
  28. * @param name : Optional parameter associating a name with the sync object for
  29. * debug purposes. Only first SYNC_DEBUG_NAME_LEN bytes are accepted,
  30. * rest will be ignored.
  31. *
  32. * @return Status of operation. Zero in case of success.
  33. * -EINVAL will be returned if sync_obj is an invalid pointer.
  34. * -ENOMEM will be returned if the kernel can't allocate space for
  35. * sync object.
  36. */
  37. int cam_sync_create(int32_t *sync_obj, const char *name);
  38. /**
  39. * @brief: Registers a callback with a sync object
  40. *
  41. * @param cb_func : Pointer to callback to be registered
  42. * @param userdata : Opaque pointer which will be passed back with callback.
  43. * @param sync_obj : int referencing the sync object.
  44. *
  45. * @return Status of operation. Zero in case of success.
  46. * -EINVAL will be returned if userdata is invalid.
  47. * -ENOMEM will be returned if cb_func is invalid.
  48. */
  49. int cam_sync_register_callback(sync_callback cb_func,
  50. void *userdata, int32_t sync_obj);
  51. /**
  52. * @brief: De-registers a callback with a sync object
  53. *
  54. * @param cb_func : Pointer to callback to be de-registered
  55. * @param userdata : Opaque pointer which will be passed back with callback.
  56. * @param sync_obj : int referencing the sync object.
  57. *
  58. * @return Status of operation. Zero in case of success.
  59. * -EINVAL will be returned if userdata is invalid.
  60. * -ENOMEM will be returned if cb_func is invalid.
  61. * -ENOENT will be returned if call back not found
  62. */
  63. int cam_sync_deregister_callback(sync_callback cb_func,
  64. void *userdata, int32_t sync_obj);
  65. /**
  66. * @brief: Signals a sync object with the status argument.
  67. *
  68. * This function will signal the sync object referenced by the sync_obj
  69. * parameter and when doing so, will trigger callbacks in both user space and
  70. * kernel. Callbacks will triggered asynchronously and their order of execution
  71. * is not guaranteed. The status parameter will indicate whether the entity
  72. * performing the signaling wants to convey an error case or a success case.
  73. *
  74. * @param sync_obj : int referencing the sync object.
  75. * @param status : Status of the signaling. Can be either SYNC_SIGNAL_ERROR or
  76. * SYNC_SIGNAL_SUCCESS.
  77. * @param evt_param : Event parameter
  78. *
  79. * @return Status of operation. Negative in case of error. Zero otherwise.
  80. */
  81. int cam_sync_signal(int32_t sync_obj, uint32_t status, uint32_t evt_param);
  82. /**
  83. * @brief: Merges multiple sync objects
  84. *
  85. * This function will merge multiple sync objects into a sync group.
  86. *
  87. * @param sync_obj : pointer to a block of ints to be merged
  88. * @param num_objs : Number of ints in the block
  89. *
  90. * @return Status of operation. Negative in case of error. Zero otherwise.
  91. */
  92. int cam_sync_merge(int32_t *sync_obj, uint32_t num_objs, int32_t *merged_obj);
  93. /**
  94. * @brief: get ref count of sync obj
  95. *
  96. * This function will increment ref count for the sync object, and the ref
  97. * count will be decremented when this sync object is signaled.
  98. *
  99. * @param sync_obj: sync object
  100. *
  101. * @return Status of operation. Negative in case of error. Zero otherwise.
  102. */
  103. int cam_sync_get_obj_ref(int32_t sync_obj);
  104. /**
  105. * @brief: put ref count of sync obj
  106. *
  107. * This function will decrement ref count for the sync object.
  108. *
  109. * @param sync_obj: sync object
  110. *
  111. * @return Status of operation. Negative in case of error. Zero otherwise.
  112. */
  113. int cam_sync_put_obj_ref(int32_t sync_obj);
  114. /**
  115. * @brief: Destroys a sync object
  116. *
  117. * @param sync_obj: int referencing the sync object to be destroyed
  118. *
  119. * @return Status of operation. Negative in case of error. Zero otherwise.
  120. */
  121. int cam_sync_destroy(int32_t sync_obj);
  122. /**
  123. * @brief: Waits for a sync object synchronously
  124. *
  125. * Does a wait on the sync object identified by sync_obj for a maximum
  126. * of timeout_ms milliseconds. Must not be called from interrupt context as
  127. * this API can sleep. Should be called from process context only.
  128. *
  129. * @param sync_obj : int referencing the sync object to be waited upon
  130. * @param timeout_ms : Timeout in ms.
  131. *
  132. * @return Status of operation. Zero in case of success
  133. * -EINVAL if sync object is in bad state or arguments are invalid
  134. * -ETIMEDOUT if wait times out
  135. */
  136. int cam_sync_wait(int32_t sync_obj, uint64_t timeout_ms);
  137. /**
  138. * @brief: Check if sync object is valid
  139. *
  140. * @param sync_obj: int referencing the sync object to be checked
  141. *
  142. * @return Status of operation. Zero in case of success
  143. * -EINVAL if sync object is in bad state or arguments are invalid
  144. */
  145. int cam_sync_check_valid(int32_t sync_obj);
  146. /**
  147. * @brief: Synx recovery for a given core
  148. *
  149. * @param core_id: Core ID we want to recover for
  150. *
  151. * @return Status of operation. Zero in case of success
  152. * -EINVAL if core_id is invalid
  153. */
  154. int cam_sync_synx_core_recovery(
  155. enum cam_sync_synx_supported_cores core_id);
  156. /**
  157. * @brief : API to register SYNC to platform framework.
  158. *
  159. * @return struct platform_device pointer on on success, or ERR_PTR() on error.
  160. */
  161. int cam_sync_init(void);
  162. /**
  163. * @brief : API to remove SYNC from platform framework.
  164. */
  165. void cam_sync_exit(void);
  166. #endif /* __CAM_SYNC_API_H__ */