cam_sync_api.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. *
  72. * @return Status of operation. Negative in case of error. Zero otherwise.
  73. */
  74. int cam_sync_signal(int32_t sync_obj, uint32_t status);
  75. /**
  76. * @brief: Merges multiple sync objects
  77. *
  78. * This function will merge multiple sync objects into a sync group.
  79. *
  80. * @param sync_obj: pointer to a block of ints to be merged
  81. * @param num_objs: Number of ints in the block
  82. *
  83. * @return Status of operation. Negative in case of error. Zero otherwise.
  84. */
  85. int cam_sync_merge(int32_t *sync_obj, uint32_t num_objs, int32_t *merged_obj);
  86. /**
  87. * @brief: get ref count of sync obj
  88. *
  89. * This function will increment ref count for the sync object, and the ref
  90. * count will be decremented when this sync object is signaled.
  91. *
  92. * @param sync_obj: sync object
  93. *
  94. * @return Status of operation. Negative in case of error. Zero otherwise.
  95. */
  96. int cam_sync_get_obj_ref(int32_t sync_obj);
  97. /**
  98. * @brief: put ref count of sync obj
  99. *
  100. * This function will decrement ref count for the sync object.
  101. *
  102. * @param sync_obj: sync object
  103. *
  104. * @return Status of operation. Negative in case of error. Zero otherwise.
  105. */
  106. int cam_sync_put_obj_ref(int32_t sync_obj);
  107. /**
  108. * @brief: Destroys a sync object
  109. *
  110. * @param sync_obj: int referencing the sync object to be destroyed
  111. *
  112. * @return Status of operation. Negative in case of error. Zero otherwise.
  113. */
  114. int cam_sync_destroy(int32_t sync_obj);
  115. /**
  116. * @brief: Waits for a sync object synchronously
  117. *
  118. * Does a wait on the sync object identified by sync_obj for a maximum
  119. * of timeout_ms milliseconds. Must not be called from interrupt context as
  120. * this API can sleep. Should be called from process context only.
  121. *
  122. * @param sync_obj: int referencing the sync object to be waited upon
  123. * @timeout_ms sync_obj: Timeout in ms.
  124. *
  125. * @return 0 upon success, -EINVAL if sync object is in bad state or arguments
  126. * are invalid, -ETIMEDOUT if wait times out.
  127. */
  128. int cam_sync_wait(int32_t sync_obj, uint64_t timeout_ms);
  129. /**
  130. * @brief: Check if sync object is valid
  131. *
  132. * @param sync_obj: int referencing the sync object to be checked
  133. *
  134. * @return 0 upon success, -EINVAL if sync object is in bad state or arguments
  135. * are invalid
  136. */
  137. int cam_sync_check_valid(int32_t sync_obj);
  138. /**
  139. * @brief : API to register SYNC to platform framework.
  140. * @return struct platform_device pointer on on success, or ERR_PTR() on error.
  141. */
  142. int cam_sync_init(void);
  143. /**
  144. * @brief : API to remove SYNC from platform framework.
  145. */
  146. void cam_sync_exit(void);
  147. #endif /* __CAM_SYNC_API_H__ */