cam_sync_synx.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /* SPDX-License-Identifier: GPL-2.0-only
  2. *
  3. * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
  4. */
  5. #ifndef __CAM_SYNC_SYNX_H__
  6. #define __CAM_SYNC_SYNX_H__
  7. #include <linux/types.h>
  8. #include <linux/spinlock_types.h>
  9. #include <linux/bitmap.h>
  10. #include <synx_api.h>
  11. #include "cam_sync.h"
  12. #include "cam_debug_util.h"
  13. #define CAM_SYNX_MAX_OBJS 256
  14. #define CAM_SYNX_OBJ_NAME_LEN 64
  15. /* Synx obj state */
  16. enum cam_synx_obj_state {
  17. CAM_SYNX_OBJ_STATE_INVALID,
  18. CAM_SYNX_OBJ_STATE_ACTIVE,
  19. CAM_SYNX_OBJ_STATE_SIGNALED,
  20. };
  21. /**
  22. * struct cam_synx_obj_release_params - Synx release payload
  23. * Based on the flag row_idx or synx_obj is consumed
  24. *
  25. * @synx_row_idx : Synx obj row idx
  26. * @synx_obj : Synx object handle
  27. * @use_row_idx : Use row idx
  28. */
  29. struct cam_synx_obj_release_params {
  30. union {
  31. int32_t synx_row_idx;
  32. uint32_t synx_obj;
  33. } u;
  34. bool use_row_idx;
  35. };
  36. /**
  37. * struct cam_synx_obj_fence_signal_sync_obj - SYNX -> sync signal info
  38. * Payload to signal sync on a synx fence being signaled
  39. *
  40. * @synx_obj : Synx object handle
  41. * @status : Sync signal status
  42. */
  43. struct cam_synx_obj_signal_sync_obj {
  44. int32_t synx_obj;
  45. int32_t status;
  46. };
  47. /* Synx obj callback function type */
  48. typedef int (*cam_sync_callback_for_synx_obj)(int32_t sync_obj,
  49. struct cam_synx_obj_signal_sync_obj *signal_sync_obj);
  50. /**
  51. * @brief Find the synx obj in the device's table
  52. *
  53. * @param synx_obj : Synx obj
  54. * @param idx : Synx object table index
  55. *
  56. * @return Status of operation. Zero in case of success.
  57. */
  58. int cam_synx_obj_find_obj_in_table(uint32_t synx_obj, int32_t *idx);
  59. /**
  60. * @brief Create a synx object
  61. *
  62. * @param name : Synx obj name
  63. * @param flags : Creation flags
  64. * @param synx_obj : Created synx obj handle
  65. * @param row_idx : Created synx obj table row idx
  66. *
  67. * @return Status of operation. Zero in case of success.
  68. * -EINVAL will be returned if params were invalid.
  69. * -ENOMEM will be returned if the kernel can't allocate space for
  70. * synx object.
  71. */
  72. int cam_synx_obj_create(const char *name, uint32_t flags, uint32_t *synx_obj,
  73. int32_t *row_idx);
  74. /**
  75. * @brief Signal a synx obj when sync obj is signaled
  76. *
  77. * @param row_idx : Synx obj table row index
  78. * @param signal_synx_obj : Info on synx obj to be signaled
  79. *
  80. * @return Status of operation. Negative in case of error. Zero otherwise.
  81. */
  82. int cam_synx_obj_internal_signal(int32_t row_idx,
  83. struct cam_synx_obj_signal *signal_synx_obj);
  84. /**
  85. * @brief Import a synx obj for synchronization
  86. *
  87. * @param name : Synx obj name
  88. * @param flags : Import flags
  89. * @param fence : DMA fence ptr
  90. * @param synx_obj : New synx obj handle
  91. * @param row_idx : Imported obj table row idx
  92. *
  93. * @return 0 upon success, -EINVAL if synx object is bad state
  94. */
  95. int cam_synx_obj_import_dma_fence(const char *name, uint32_t flags, void *fence,
  96. uint32_t *synx_obj, int32_t *row_idx);
  97. /**
  98. * @brief Release a synx object
  99. *
  100. * @param release_params : Synx obj release info
  101. *
  102. * @return 0 upon success, negative value otherwise
  103. */
  104. int cam_synx_obj_release(struct cam_synx_obj_release_params *release_params);
  105. /**
  106. * @brief Signal a synx obj [userspace API]
  107. *
  108. * @param signal_synx_obj : Signal info
  109. *
  110. * @return 0 upon success, negative value otherwise
  111. */
  112. int cam_synx_obj_signal_obj(struct cam_synx_obj_signal *signal_synx_obj);
  113. /**
  114. * @brief Synx obj register callback
  115. *
  116. * @param sync_obj : Sync object
  117. * @param row_idx : Synx obj table row idx
  118. * @param sync_cb : Sync object callback
  119. *
  120. * @return Status of operation. Negative in case of error. Zero otherwise.
  121. */
  122. int cam_synx_obj_register_cb(int32_t *sync_obj, int32_t row_idx,
  123. cam_sync_callback_for_synx_obj sync_cb);
  124. /**
  125. * @brief: cam synx driver close
  126. *
  127. */
  128. void cam_synx_obj_close(void);
  129. /**
  130. * @brief: cam synx driver initialize
  131. *
  132. */
  133. int cam_synx_obj_driver_init(void);
  134. /**
  135. * @brief: cam synx driver deinit
  136. *
  137. */
  138. void cam_synx_obj_driver_deinit(void);
  139. #endif /* __CAM_SYNC_SYNX_H__ */