cam_sync_synx.h 4.1 KB

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