cam_sync_private.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef __CAM_SYNC_PRIVATE_H__
  7. #define __CAM_SYNC_PRIVATE_H__
  8. #include <linux/bitmap.h>
  9. #include <linux/videodev2.h>
  10. #include <linux/workqueue.h>
  11. #include <linux/interrupt.h>
  12. #include <linux/debugfs.h>
  13. #include <media/v4l2-fh.h>
  14. #include <media/v4l2-device.h>
  15. #include <media/v4l2-subdev.h>
  16. #include <media/v4l2-event.h>
  17. #include <media/v4l2-ioctl.h>
  18. #include "cam_sync_api.h"
  19. #include "cam_sync_dma_fence.h"
  20. #if IS_ENABLED(CONFIG_TARGET_SYNX_ENABLE)
  21. #include "cam_sync_synx.h"
  22. #endif
  23. #if IS_REACHABLE(CONFIG_MSM_GLOBAL_SYNX) || IS_ENABLED(CONFIG_TARGET_SYNX_ENABLE)
  24. #include <synx_api.h>
  25. #endif
  26. #ifdef CONFIG_CAM_SYNC_DBG
  27. #define CDBG(fmt, args...) pr_err(fmt, ##args)
  28. #else
  29. #define CDBG(fmt, args...) pr_debug(fmt, ##args)
  30. #endif
  31. #define CAM_SYNC_OBJ_NAME_LEN 64
  32. #define CAM_SYNC_MAX_OBJS 2048
  33. #define CAM_GENERIC_FENCE_BATCH_MAX 10
  34. #define CAM_SYNC_MAX_V4L2_EVENTS 250
  35. #define CAM_SYNC_DEBUG_FILENAME "cam_debug"
  36. #define CAM_SYNC_DEBUG_BASEDIR "cam"
  37. #define CAM_SYNC_DEBUG_BUF_SIZE 32
  38. #define CAM_SYNC_PAYLOAD_WORDS 2
  39. #define CAM_SYNC_NAME "cam_sync"
  40. #define CAM_SYNC_WORKQUEUE_NAME "HIPRIO_SYNC_WORK_QUEUE"
  41. #define CAM_SYNC_TYPE_INDV 0
  42. #define CAM_SYNC_TYPE_GROUP 1
  43. /**
  44. * enum sync_type - Enum to indicate the type of sync object,
  45. * i.e. individual or group.
  46. *
  47. * @SYNC_TYPE_INDV : Object is an individual sync object
  48. * @SYNC_TYPE_GROUP : Object is a group sync object
  49. */
  50. enum sync_type {
  51. SYNC_TYPE_INDV,
  52. SYNC_TYPE_GROUP
  53. };
  54. /**
  55. * enum sync_list_clean_type - Enum to indicate the type of list clean action
  56. * to be peformed, i.e. specific sync ID or all list sync ids.
  57. *
  58. * @SYNC_CLEAN_ONE : Specific object to be cleaned in the list
  59. * @SYNC_CLEAN_ALL : Clean all objects in the list
  60. */
  61. enum sync_list_clean_type {
  62. SYNC_LIST_CLEAN_ONE,
  63. SYNC_LIST_CLEAN_ALL
  64. };
  65. /**
  66. * struct sync_parent_info - Single node of information about a parent
  67. * of a sync object, usually part of the parents linked list
  68. *
  69. * @sync_id : Sync object id of parent
  70. * @list : List member used to append this node to a linked list
  71. */
  72. struct sync_parent_info {
  73. int32_t sync_id;
  74. struct list_head list;
  75. };
  76. /**
  77. * struct sync_parent_info - Single node of information about a child
  78. * of a sync object, usually part of the children linked list
  79. *
  80. * @sync_id : Sync object id of child
  81. * @list : List member used to append this node to a linked list
  82. */
  83. struct sync_child_info {
  84. int32_t sync_id;
  85. struct list_head list;
  86. };
  87. /**
  88. * struct sync_callback_info - Single node of information about a kernel
  89. * callback registered on a sync object
  90. *
  91. * @callback_func : Callback function, registered by client driver
  92. * @cb_data : Callback data, registered by client driver
  93. * @status : Status with which callback will be invoked in client
  94. * @sync_obj : Sync id of the object for which callback is registered
  95. * @workq_scheduled_ts : workqueue scheduled timestamp
  96. * @cb_dispatch_work : Work representing the call dispatch
  97. * @list : List member used to append this node to a linked list
  98. */
  99. struct sync_callback_info {
  100. sync_callback callback_func;
  101. void *cb_data;
  102. int status;
  103. int32_t sync_obj;
  104. ktime_t workq_scheduled_ts;
  105. struct work_struct cb_dispatch_work;
  106. struct list_head list;
  107. };
  108. /**
  109. * struct sync_user_payload - Single node of information about a user space
  110. * payload registered from user space
  111. *
  112. * @payload_data : Payload data, opaque to kernel
  113. * @list : List member used to append this node to a linked list
  114. */
  115. struct sync_user_payload {
  116. uint64_t payload_data[CAM_SYNC_PAYLOAD_WORDS];
  117. struct list_head list;
  118. };
  119. /**
  120. * struct sync_dma_fence_info - DMA fence info associated with this sync obj
  121. *
  122. * @dma_fence_fd : DMA fence fd
  123. * @dma_fence_row_idx : Index of the row corresponding to this dma fence
  124. * in the dma fence table
  125. * @sync_created_with_dma : If sync obj and dma fence are created together
  126. */
  127. struct sync_dma_fence_info {
  128. int32_t dma_fence_fd;
  129. int32_t dma_fence_row_idx;
  130. bool sync_created_with_dma;
  131. };
  132. /**
  133. * struct sync_synx_obj_info - Synx object info associated with this sync obj
  134. *
  135. * @synx_obj : Synx object handle
  136. * @synx_obj_row_idx : Index of the row corresponding to this synx obj
  137. * in the synx obj table
  138. * @sync_created_with_synx : If sync obj and synx obj are created together
  139. */
  140. struct sync_synx_obj_info {
  141. uint32_t synx_obj;
  142. int32_t synx_obj_row_idx;
  143. bool sync_created_with_synx;
  144. };
  145. /**
  146. * struct sync_table_row - Single row of information about a sync object, used
  147. * for internal book keeping in the sync driver
  148. *
  149. * @name : Optional string representation of the sync object
  150. * @type : Type of the sync object (individual or group)
  151. * @sync_id : Integer id representing this sync object
  152. * @parents_list : Linked list of parents of this sync object
  153. * @children_list : Linked list of children of this sync object
  154. * @state : State (INVALID, ACTIVE, SIGNALED_SUCCESS or
  155. * SIGNALED_ERROR)
  156. * @remaining : Count of remaining children that not been signaled
  157. * @signaled : Completion variable on which block calls will wait
  158. * @callback_list : Linked list of kernel callbacks registered
  159. * @user_payload_list : LInked list of user space payloads registered
  160. * @ref_cnt : ref count of the number of usage of the fence.
  161. * @ext_fence_mask : Mask to indicate associated external fence types
  162. * @dma_fence_info : dma fence info if associated
  163. * @synx_obj_info : synx obj info if associated
  164. */
  165. struct sync_table_row {
  166. char name[CAM_SYNC_OBJ_NAME_LEN];
  167. enum sync_type type;
  168. int32_t sync_id;
  169. /* List of parents, which are merged objects */
  170. struct list_head parents_list;
  171. /* List of children, which constitute the merged object */
  172. struct list_head children_list;
  173. uint32_t state;
  174. uint32_t remaining;
  175. struct completion signaled;
  176. struct list_head callback_list;
  177. struct list_head user_payload_list;
  178. atomic_t ref_cnt;
  179. unsigned long ext_fence_mask;
  180. struct sync_dma_fence_info dma_fence_info;
  181. struct sync_synx_obj_info synx_obj_info;
  182. };
  183. /**
  184. * struct cam_signalable_info - Information for a single sync object that is
  185. * ready to be signaled
  186. *
  187. * @sync_obj : Sync object id of signalable object
  188. * @status : Status with which to signal
  189. * @list : List member used to append this node to a linked list
  190. */
  191. struct cam_signalable_info {
  192. int32_t sync_obj;
  193. uint32_t status;
  194. struct list_head list;
  195. };
  196. /**
  197. * struct sync_device - Internal struct to book keep sync driver details
  198. *
  199. * @vdev : Video device
  200. * @v4l2_dev : V4L2 device
  201. * @sync_table : Table of all sync objects
  202. * @row_spinlocks : Spinlock array, one for each row in the table
  203. * @table_lock : Mutex used to lock the table
  204. * @open_cnt : Count of file open calls made on the sync driver
  205. * @dentry : Debugfs entry
  206. * @work_queue : Work queue used for dispatching kernel callbacks
  207. * @cam_sync_eventq : Event queue used to dispatch user payloads to user space
  208. * @bitmap : Bitmap representation of all sync objects
  209. * @params : Parameters for synx call back registration
  210. * @version : version support
  211. */
  212. struct sync_device {
  213. struct video_device *vdev;
  214. struct v4l2_device v4l2_dev;
  215. struct sync_table_row sync_table[CAM_SYNC_MAX_OBJS];
  216. spinlock_t row_spinlocks[CAM_SYNC_MAX_OBJS];
  217. struct mutex table_lock;
  218. int open_cnt;
  219. struct dentry *dentry;
  220. struct workqueue_struct *work_queue;
  221. struct v4l2_fh *cam_sync_eventq;
  222. spinlock_t cam_sync_eventq_lock;
  223. DECLARE_BITMAP(bitmap, CAM_SYNC_MAX_OBJS);
  224. #if IS_REACHABLE(CONFIG_MSM_GLOBAL_SYNX)
  225. struct synx_register_params params;
  226. #endif
  227. uint32_t version;
  228. };
  229. #endif /* __CAM_SYNC_PRIVATE_H__ */