cam_sync_private.h 6.5 KB

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