cam_sync_dma_fence.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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_DMA_FENCE_H__
  6. #define __CAM_SYNC_DMA_FENCE_H__
  7. #include <linux/dma-fence.h>
  8. #include <linux/spinlock_types.h>
  9. #include <linux/sync_file.h>
  10. #include <linux/file.h>
  11. #include <linux/bitmap.h>
  12. #include "cam_sync.h"
  13. #include "cam_debug_util.h"
  14. #define CAM_DMA_FENCE_MAX_FENCES 128
  15. #define CAM_DMA_FENCE_NAME_LEN 128
  16. #define CAM_DMA_FENCE_TABLE_SZ (CAM_DMA_FENCE_MAX_FENCES / CAM_GENERIC_MONITOR_TABLE_ENTRY_SZ)
  17. /* DMA fence state */
  18. enum cam_dma_fence_state {
  19. CAM_DMA_FENCE_STATE_INVALID,
  20. CAM_DMA_FENCE_STATE_ACTIVE,
  21. CAM_DMA_FENCE_STATE_SIGNALED,
  22. };
  23. /**
  24. * struct cam_dma_fence_release_params - DMA release payload
  25. * Based on the flag row_idx or fd is consumed
  26. *
  27. * @dma_row_idx : DMA fence row idx
  28. * @dma_fence_fd : DMA fence fd
  29. * @use_row_idx : Use row idx
  30. */
  31. struct cam_dma_fence_release_params {
  32. union {
  33. int32_t dma_row_idx;
  34. int32_t dma_fence_fd;
  35. } u;
  36. bool use_row_idx;
  37. };
  38. /**
  39. * struct cam_dma_fence_signal_sync_obj - DMA -> sync signal info
  40. * Payload to signal sync on a dma fence
  41. * being signaled
  42. *
  43. * @status : DMA fence status
  44. * @fd : DMA fence fd if any
  45. */
  46. struct cam_dma_fence_signal_sync_obj {
  47. int32_t status;
  48. int32_t fd;
  49. };
  50. /* DMA fence callback function type */
  51. typedef int (*cam_sync_callback_for_dma_fence)(int32_t sync_obj,
  52. struct cam_dma_fence_signal_sync_obj *signal_sync_obj);
  53. /**
  54. * struct cam_dma_fence_create_sync_obj_payload -
  55. * Payload to create sync for a dma fence
  56. *
  57. * @dma_fence_row_idx : DMA fence row idx
  58. * @fd : DMA fence fd
  59. * @sync_created_with_dma : Set if dma fence and sync obj are being
  60. * created in a single IOCTL call
  61. */
  62. struct cam_dma_fence_create_sync_obj_payload {
  63. int32_t dma_fence_row_idx;
  64. int32_t fd;
  65. bool sync_created_with_dma;
  66. };
  67. /**
  68. * @brief: Signal a dma fence fd [userspace API]
  69. *
  70. * @param signal_dma_fence: Info on DMA fence to be signaled
  71. *
  72. * @return Status of operation. Negative in case of error. Zero otherwise.
  73. */
  74. int cam_dma_fence_signal_fd(
  75. struct cam_dma_fence_signal *signal_dma_fence);
  76. /**
  77. * @brief: Signal a dma fence when sync obj is signaled
  78. *
  79. * @param dma_fence_row_idx : DMA fence row idx
  80. * @param signal_dma_fence : Info on DMA fence to be signaled
  81. *
  82. * @return Status of operation. Negative in case of error. Zero otherwise.
  83. */
  84. int cam_dma_fence_internal_signal(int32_t dma_fence_row_idx,
  85. struct cam_dma_fence_signal *signal_dma_fence);
  86. /**
  87. * @brief: Create a dma fence fd
  88. *
  89. * @param name : DMA fence name, optional param
  90. * will accommodate names of length
  91. * CAM_DMA_FENCE_NAME_LEN
  92. * @output dma_fence_fd : DMA fence fd
  93. * @output dma_fence_row_idx : Row Idx corresponding to DMA fence in the table
  94. *
  95. * @return Status of operation. Negative in case of error. Zero otherwise.
  96. */
  97. int cam_dma_fence_create_fd(
  98. int32_t *dma_fence_fd, int32_t *dma_fence_row_idx, const char *name);
  99. /**
  100. * @brief: Release a dma fence
  101. *
  102. * @param release_params : dma fence info to be released
  103. *
  104. * @return Status of operation. Negative in case of error. Zero otherwise.
  105. */
  106. int cam_dma_fence_release(
  107. struct cam_dma_fence_release_params *release_params);
  108. /**
  109. * @brief: Gets the dma fence from a fd, increments refcnt
  110. *
  111. * @param fd : File descriptor
  112. * @output dma_fence_row_idx : Row idx pertaining to this dma fence
  113. *
  114. * @return Status of operation. Error or valid fence.
  115. */
  116. struct dma_fence *cam_dma_fence_get_fence_from_fd(int32_t fd,
  117. int32_t *dma_fence_row_idx);
  118. /**
  119. * @brief: DMA fence register cb
  120. *
  121. * @param sync_obj : Sync object
  122. * @param dma_fence_idx : DMA fence row idx
  123. * @param sync_cb : Sync object callback
  124. *
  125. * @return Status of operation. Negative in case of error. Zero otherwise.
  126. */
  127. int cam_dma_fence_register_cb(int32_t *sync_obj,
  128. int32_t *dma_fence_row_idx, cam_sync_callback_for_dma_fence sync_cb);
  129. /**
  130. * @brief: get/put on dma fence
  131. *
  132. * @get_or_put : True for get, false for put
  133. * @param dma_fence_row_idx : Idx in the dma fence table pertaining to
  134. * the dma fence on which get/put ref is invoked
  135. *
  136. * @return Status of operation. Negative in case of error. Zero otherwise.
  137. */
  138. int cam_dma_fence_get_put_ref(bool get_or_put, int32_t dma_fence_row_idx);
  139. /**
  140. * @brief: dma fence driver open
  141. *
  142. */
  143. void cam_dma_fence_open(void);
  144. /**
  145. * @brief: dma fence driver close
  146. *
  147. */
  148. void cam_dma_fence_close(void);
  149. /**
  150. * @brief: dma fence driver initialize
  151. *
  152. */
  153. int cam_dma_fence_driver_init(void);
  154. /**
  155. * @brief: dma fence driver deinit
  156. *
  157. */
  158. void cam_dma_fence_driver_deinit(void);
  159. #endif /* __CAM_SYNC_DMA_FENCE_H__ */