cam_sync_api.h 5.1 KB

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