cam_sync_private.h 6.4 KB

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