cam_sync_synx.h 4.5 KB

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