cam_sync_private.h 7.3 KB

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