cam_sync_private.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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 100
  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. * @cb_dispatch_work : Work representing the call dispatch
  90. * @list : List member used to append this node to a linked list
  91. */
  92. struct sync_callback_info {
  93. sync_callback callback_func;
  94. void *cb_data;
  95. int status;
  96. int32_t sync_obj;
  97. struct work_struct cb_dispatch_work;
  98. struct list_head list;
  99. };
  100. /**
  101. * struct sync_user_payload - Single node of information about a user space
  102. * payload registered from user space
  103. *
  104. * @payload_data : Payload data, opaque to kernel
  105. * @list : List member used to append this node to a linked list
  106. */
  107. struct sync_user_payload {
  108. uint64_t payload_data[CAM_SYNC_PAYLOAD_WORDS];
  109. struct list_head list;
  110. };
  111. /**
  112. * struct sync_table_row - Single row of information about a sync object, used
  113. * for internal book keeping in the sync driver
  114. *
  115. * @name : Optional string representation of the sync object
  116. * @type : Type of the sync object (individual or group)
  117. * @sync_id : Integer id representing this sync object
  118. * @parents_list : Linked list of parents of this sync object
  119. * @children_list : Linked list of children of this sync object
  120. * @state : State (INVALID, ACTIVE, SIGNALED_SUCCESS or
  121. * SIGNALED_ERROR)
  122. * @remaining : Count of remaining children that not been signaled
  123. * @signaled : Completion variable on which block calls will wait
  124. * @callback_list : Linked list of kernel callbacks registered
  125. * @user_payload_list : LInked list of user space payloads registered
  126. * @ref_cnt : ref count of the number of usage of the fence.
  127. */
  128. struct sync_table_row {
  129. char name[CAM_SYNC_OBJ_NAME_LEN];
  130. enum sync_type type;
  131. int32_t sync_id;
  132. /* List of parents, which are merged objects */
  133. struct list_head parents_list;
  134. /* List of children, which constitute the merged object */
  135. struct list_head children_list;
  136. uint32_t state;
  137. uint32_t remaining;
  138. struct completion signaled;
  139. struct list_head callback_list;
  140. struct list_head user_payload_list;
  141. atomic_t ref_cnt;
  142. };
  143. /**
  144. * struct cam_signalable_info - Information for a single sync object that is
  145. * ready to be signaled
  146. *
  147. * @sync_obj : Sync object id of signalable object
  148. * @status : Status with which to signal
  149. * @list : List member used to append this node to a linked list
  150. */
  151. struct cam_signalable_info {
  152. int32_t sync_obj;
  153. uint32_t status;
  154. struct list_head list;
  155. };
  156. /**
  157. * struct sync_device - Internal struct to book keep sync driver details
  158. *
  159. * @vdev : Video device
  160. * @v4l2_dev : V4L2 device
  161. * @sync_table : Table of all sync objects
  162. * @row_spinlocks : Spinlock array, one for each row in the table
  163. * @table_lock : Mutex used to lock the table
  164. * @open_cnt : Count of file open calls made on the sync driver
  165. * @dentry : Debugfs entry
  166. * @work_queue : Work queue used for dispatching kernel callbacks
  167. * @cam_sync_eventq : Event queue used to dispatch user payloads to user space
  168. * @bitmap : Bitmap representation of all sync objects
  169. * @params : Parameters for synx call back registration
  170. * @version : version support
  171. */
  172. struct sync_device {
  173. struct video_device *vdev;
  174. struct v4l2_device v4l2_dev;
  175. struct sync_table_row sync_table[CAM_SYNC_MAX_OBJS];
  176. spinlock_t row_spinlocks[CAM_SYNC_MAX_OBJS];
  177. struct mutex table_lock;
  178. int open_cnt;
  179. struct dentry *dentry;
  180. struct workqueue_struct *work_queue;
  181. struct v4l2_fh *cam_sync_eventq;
  182. spinlock_t cam_sync_eventq_lock;
  183. DECLARE_BITMAP(bitmap, CAM_SYNC_MAX_OBJS);
  184. #if IS_REACHABLE(CONFIG_MSM_GLOBAL_SYNX)
  185. struct synx_register_params params;
  186. #endif
  187. uint32_t version;
  188. };
  189. #endif /* __CAM_SYNC_PRIVATE_H__ */