cam_sync.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. /* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */
  2. /*
  3. * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.
  4. * Copyright (c) 2016-2021, The Linux Foundation. All rights reserved.
  5. */
  6. #ifndef __UAPI_CAM_SYNC_H__
  7. #define __UAPI_CAM_SYNC_H__
  8. #include <linux/videodev2.h>
  9. #include <linux/types.h>
  10. #include <linux/ioctl.h>
  11. #include <linux/media.h>
  12. #define CAM_SYNC_DEVICE_NAME "cam_sync_device"
  13. /* V4L event which user space will subscribe to */
  14. #define CAM_SYNC_V4L_EVENT (V4L2_EVENT_PRIVATE_START + 0)
  15. #define CAM_SYNC_V4L_EVENT_V2 (V4L2_EVENT_PRIVATE_START + 1)
  16. /* Specific event ids to get notified in user space */
  17. #define CAM_SYNC_V4L_EVENT_ID_CB_TRIG 0
  18. /* Size of opaque payload sent to kernel for safekeeping until signal time */
  19. #define CAM_SYNC_USER_PAYLOAD_SIZE 2
  20. /* Device type for sync device needed for device discovery */
  21. #define CAM_SYNC_DEVICE_TYPE (MEDIA_ENT_F_OLD_BASE)
  22. #define CAM_SYNC_GET_PAYLOAD_PTR(ev, type) \
  23. (type *)((char *)ev.u.data + sizeof(struct cam_sync_ev_header))
  24. #define CAM_SYNC_GET_HEADER_PTR(ev) \
  25. ((struct cam_sync_ev_header *)ev.u.data)
  26. #define CAM_SYNC_GET_PAYLOAD_PTR_V2(ev, type) \
  27. (type *)((char *)ev.u.data + sizeof(struct cam_sync_ev_header_v2))
  28. #define CAM_SYNC_GET_HEADER_PTR_V2(ev) \
  29. ((struct cam_sync_ev_header_v2 *)ev.u.data)
  30. #define CAM_SYNC_STATE_INVALID 0
  31. #define CAM_SYNC_STATE_ACTIVE 1
  32. #define CAM_SYNC_STATE_SIGNALED_SUCCESS 2
  33. #define CAM_SYNC_STATE_SIGNALED_ERROR 3
  34. #define CAM_SYNC_STATE_SIGNALED_CANCEL 4
  35. /* Top level common sync event reason types */
  36. #define CAM_SYNC_COMMON_EVENT_START 0
  37. #define CAM_SYNC_COMMON_EVENT_UNUSED (CAM_SYNC_COMMON_EVENT_START + 0)
  38. #define CAM_SYNC_COMMON_EVENT_SUCCESS (CAM_SYNC_COMMON_EVENT_START + 1)
  39. #define CAM_SYNC_COMMON_EVENT_FLUSH (CAM_SYNC_COMMON_EVENT_START + 2)
  40. #define CAM_SYNC_COMMON_EVENT_STOP (CAM_SYNC_COMMON_EVENT_START + 3)
  41. #define CAM_SYNC_COMMON_EVENT_SYNX (CAM_SYNC_COMMON_EVENT_START + 4)
  42. #define CAM_SYNC_COMMON_REG_PAYLOAD_EVENT (CAM_SYNC_COMMON_EVENT_START + 5)
  43. #define CAM_SYNC_COMMON_SYNC_SIGNAL_EVENT (CAM_SYNC_COMMON_EVENT_START + 6)
  44. #define CAM_SYNC_COMMON_RELEASE_EVENT (CAM_SYNC_COMMON_EVENT_START + 7)
  45. #define CAM_SYNC_COMMON_EVENT_END (CAM_SYNC_COMMON_EVENT_START + 50)
  46. /* ISP Sync event reason types */
  47. #define CAM_SYNC_ISP_EVENT_START (CAM_SYNC_COMMON_EVENT_END + 1)
  48. #define CAM_SYNC_ISP_EVENT_UNKNOWN (CAM_SYNC_ISP_EVENT_START + 0)
  49. #define CAM_SYNC_ISP_EVENT_BUBBLE (CAM_SYNC_ISP_EVENT_START + 1)
  50. #define CAM_SYNC_ISP_EVENT_OVERFLOW (CAM_SYNC_ISP_EVENT_START + 2)
  51. #define CAM_SYNC_ISP_EVENT_P2I_ERROR (CAM_SYNC_ISP_EVENT_START + 3)
  52. #define CAM_SYNC_ISP_EVENT_VIOLATION (CAM_SYNC_ISP_EVENT_START + 4)
  53. #define CAM_SYNC_ISP_EVENT_BUSIF_OVERFLOW (CAM_SYNC_ISP_EVENT_START + 5)
  54. #define CAM_SYNC_ISP_EVENT_FLUSH (CAM_SYNC_ISP_EVENT_START + 6)
  55. #define CAM_SYNC_ISP_EVENT_HW_STOP (CAM_SYNC_ISP_EVENT_START + 7)
  56. #define CAM_SYNC_ISP_EVENT_RECOVERY_OVERFLOW (CAM_SYNC_ISP_EVENT_START + 8)
  57. #define CAM_SYNC_ISP_EVENT_CSID_OUTPUT_FIFO_OVERFLOW (CAM_SYNC_ISP_EVENT_START + 9)
  58. #define CAM_SYNC_ISP_EVENT_CSID_RX_ERROR (CAM_SYNC_ISP_EVENT_START + 10)
  59. #define CAM_SYNC_ISP_EVENT_CSID_SENSOR_SWITCH_ERROR (CAM_SYNC_ISP_EVENT_START + 11)
  60. #define CAM_SYNC_ISP_EVENT_END (CAM_SYNC_ISP_EVENT_START + 50)
  61. /* ICP Sync event reason types */
  62. #define CAM_SYNC_ICP_EVENT_START (CAM_SYNC_ISP_EVENT_END + 1)
  63. #define CAM_SYNC_ICP_EVENT_UNKNOWN (CAM_SYNC_ICP_EVENT_START + 0)
  64. #define CAM_SYNC_ICP_EVENT_FRAME_PROCESS_FAILURE (CAM_SYNC_ICP_EVENT_START + 1)
  65. #define CAM_SYNC_ICP_EVENT_CONFIG_ERR (CAM_SYNC_ICP_EVENT_START + 2)
  66. #define CAM_SYNC_ICP_EVENT_NO_MEMORY (CAM_SYNC_ICP_EVENT_START + 3)
  67. #define CAM_SYNC_ICP_EVENT_BAD_STATE (CAM_SYNC_ICP_EVENT_START + 4)
  68. #define CAM_SYNC_ICP_EVENT_BAD_PARAM (CAM_SYNC_ICP_EVENT_START + 5)
  69. #define CAM_SYNC_ICP_EVENT_BAD_ITEM (CAM_SYNC_ICP_EVENT_START + 6)
  70. #define CAM_SYNC_ICP_EVENT_INVALID_FORMAT (CAM_SYNC_ICP_EVENT_START + 7)
  71. #define CAM_SYNC_ICP_EVENT_UNSUPPORTED (CAM_SYNC_ICP_EVENT_START + 8)
  72. #define CAM_SYNC_ICP_EVENT_OUT_OF_BOUND (CAM_SYNC_ICP_EVENT_START + 9)
  73. #define CAM_SYNC_ICP_EVENT_TIME_OUT (CAM_SYNC_ICP_EVENT_START + 10)
  74. #define CAM_SYNC_ICP_EVENT_ABORTED (CAM_SYNC_ICP_EVENT_START + 11)
  75. #define CAM_SYNC_ICP_EVENT_HW_VIOLATION (CAM_SYNC_ICP_EVENT_START + 12)
  76. #define CAM_SYNC_ICP_EVENT_CMD_ERROR (CAM_SYNC_ICP_EVENT_START + 13)
  77. #define CAM_SYNC_ICP_EVENT_HFI_ERR_COMMAND_SIZE (CAM_SYNC_ICP_EVENT_START + 14)
  78. #define CAM_SYNC_ICP_EVENT_HFI_ERR_MESSAGE_SIZE (CAM_SYNC_ICP_EVENT_START + 15)
  79. #define CAM_SYNC_ICP_EVENT_HFI_ERR_QUEUE_EMPTY (CAM_SYNC_ICP_EVENT_START + 16)
  80. #define CAM_SYNC_ICP_EVENT_HFI_ERR_QUEUE_FULL (CAM_SYNC_ICP_EVENT_START + 17)
  81. #define CAM_SYNC_ICP_EVENT_END (CAM_SYNC_ICP_EVENT_START + 50)
  82. /* JPEG Sync event reason types */
  83. #define CAM_SYNC_JPEG_EVENT_START (CAM_SYNC_ICP_EVENT_END + 1)
  84. #define CAM_SYNC_JPEG_EVENT_UNKNOWN (CAM_SYNC_JPEG_EVENT_START + 0)
  85. #define CAM_SYNC_JPEG_EVENT_INVLD_CMD (CAM_SYNC_JPEG_EVENT_START + 1)
  86. #define CAM_SYNC_JPEG_EVENT_SET_IRQ_CB (CAM_SYNC_JPEG_EVENT_START + 2)
  87. #define CAM_SYNC_JPEG_EVENT_HW_RESET_FAILED (CAM_SYNC_JPEG_EVENT_START + 3)
  88. #define CAM_SYNC_JPEG_EVENT_CDM_CHANGE_BASE_ERR (CAM_SYNC_JPEG_EVENT_START + 4)
  89. #define CAM_SYNC_JPEG_EVENT_CDM_CONFIG_ERR (CAM_SYNC_JPEG_EVENT_START + 5)
  90. #define CAM_SYNC_JPEG_EVENT_START_HW_ERR (CAM_SYNC_JPEG_EVENT_START + 6)
  91. #define CAM_SYNC_JPEG_EVENT_START_HW_HANG (CAM_SYNC_JPEG_EVENT_START + 7)
  92. #define CAM_SYNC_JPEG_EVENT_MISR_CONFIG_ERR (CAM_SYNC_JPEG_EVENT_START + 8)
  93. #define CAM_SYNC_JPEG_EVENT_END (CAM_SYNC_JPEG_EVENT_START + 50)
  94. /* FD Sync event reason types */
  95. #define CAM_SYNC_FD_EVENT_START (CAM_SYNC_JPEG_EVENT_END + 1)
  96. #define CAM_SYNC_FD_EVENT_UNKNOWN (CAM_SYNC_FD_EVENT_START + 0)
  97. #define CAM_SYNC_FD_EVENT_IRQ_FRAME_DONE (CAM_SYNC_FD_EVENT_START + 1)
  98. #define CAM_SYNC_FD_EVENT_IRQ_RESET_DONE (CAM_SYNC_FD_EVENT_START + 2)
  99. #define CAM_SYNC_FD_EVENT_HALT (CAM_SYNC_FD_EVENT_START + 3)
  100. #define CAM_SYNC_FD_EVENT_END (CAM_SYNC_FD_EVENT_START + 50)
  101. /* LRME Sync event reason types */
  102. #define CAM_SYNC_LRME_EVENT_START (CAM_SYNC_FD_EVENT_END + 1)
  103. #define CAM_SYNC_LRME_EVENT_UNKNOWN (CAM_SYNC_LRME_EVENT_START + 0)
  104. #define CAM_SYNC_LRME_EVENT_CB_ERROR (CAM_SYNC_LRME_EVENT_START + 1)
  105. #define CAM_SYNC_LRME_EVENT_END (CAM_SYNC_LRME_EVENT_START + 50)
  106. /* OPE Sync event reason types */
  107. #define CAM_SYNC_OPE_EVENT_START (CAM_SYNC_LRME_EVENT_END + 1)
  108. #define CAM_SYNC_OPE_EVENT_UNKNOWN (CAM_SYNC_OPE_EVENT_START + 0)
  109. #define CAM_SYNC_OPE_EVENT_PAGE_FAULT (CAM_SYNC_OPE_EVENT_START + 1)
  110. #define CAM_SYNC_OPE_EVENT_HW_HANG (CAM_SYNC_OPE_EVENT_START + 2)
  111. #define CAM_SYNC_OPE_EVENT_HALT (CAM_SYNC_OPE_EVENT_START + 3)
  112. #define CAM_SYNC_OPE_EVENT_CONFIG_ERR (CAM_SYNC_OPE_EVENT_START + 4)
  113. #define CAM_SYNC_OPE_EVENT_HW_FLUSH (CAM_SYNC_OPE_EVENT_START + 5)
  114. #define CAM_SYNC_OPE_EVENT_HW_RESUBMIT (CAM_SYNC_OPE_EVENT_START + 6)
  115. #define CAM_SYNC_OPE_EVENT_HW_RESET_DONE (CAM_SYNC_OPE_EVENT_START + 7)
  116. #define CAM_SYNC_OPE_EVENT_HW_ERROR (CAM_SYNC_OPE_EVENT_START + 8)
  117. #define CAM_SYNC_OPE_EVENT_INVLD_CMD (CAM_SYNC_OPE_EVENT_START + 9)
  118. #define CAM_SYNC_OPE_EVENT_HW_RESET_FAILED (CAM_SYNC_OPE_EVENT_START + 10)
  119. #define CAM_SYNC_OPE_EVENT_END (CAM_SYNC_OPE_EVENT_START + 50)
  120. /* CRE Sync event reason types */
  121. #define CAM_SYNC_CRE_EVENT_START (CAM_SYNC_OPE_EVENT_END + 1)
  122. #define CAM_SYNC_CRE_EVENT_UNKNOWN (CAM_SYNC_CRE_EVENT_START + 0)
  123. #define CAM_SYNC_CRE_EVENT_CONFIG_ERR (CAM_SYNC_CRE_EVENT_START + 1)
  124. #define CAM_SYNC_CRE_EVENT_INVLD_CMD (CAM_SYNC_CRE_EVENT_START + 2)
  125. #define CAM_SYNC_CRE_EVENT_SET_IRQ_CB (CAM_SYNC_CRE_EVENT_START + 3)
  126. #define CAM_SYNC_CRE_EVENT_HW_RESET_FAILED (CAM_SYNC_CRE_EVENT_START + 4)
  127. #define CAM_SYNC_CRE_EVENT_HW_ERR (CAM_SYNC_CRE_EVENT_START + 5)
  128. #define CAM_SYNC_CRE_EVENT_END (CAM_SYNC_CRE_EVENT_START + 50)
  129. #define CAM_SYNC_EVENT_MAX 8
  130. #define CAM_SYNC_EVENT_REASON_CODE_INDEX 0
  131. /* Fence types supported by the driver */
  132. #define CAM_GENERIC_FENCE_TYPE_SYNC_OBJ 0x1
  133. #define CAM_GENERIC_FENCE_TYPE_DMA_FENCE 0x2
  134. /**
  135. * struct cam_sync_ev_header - Event header for sync event notification
  136. *
  137. * @sync_obj: Sync object
  138. * @status: Status of the object
  139. */
  140. struct cam_sync_ev_header {
  141. __s32 sync_obj;
  142. __s32 status;
  143. };
  144. /**
  145. * struct cam_sync_ev_header_v2 - Event header for sync event notification
  146. *
  147. * @sync_obj: Sync object
  148. * @status: Status of the object
  149. * @version: sync driver version
  150. * @evt_param: event parameter
  151. */
  152. struct cam_sync_ev_header_v2 {
  153. __s32 sync_obj;
  154. __s32 status;
  155. uint32_t version;
  156. uint32_t evt_param[CAM_SYNC_EVENT_MAX];
  157. };
  158. /**
  159. * struct cam_sync_info - Sync object creation information
  160. *
  161. * @name: Optional string representation of the sync object
  162. * @sync_obj: Sync object returned after creation in kernel
  163. */
  164. struct cam_sync_info {
  165. char name[64];
  166. __s32 sync_obj;
  167. };
  168. /**
  169. * struct cam_sync_signal - Sync object signaling struct
  170. *
  171. * @sync_obj: Sync object to be signaled
  172. * @sync_state: State of the sync object to which it should be signaled
  173. */
  174. struct cam_sync_signal {
  175. __s32 sync_obj;
  176. __u32 sync_state;
  177. };
  178. /**
  179. * struct cam_sync_merge - Merge information for sync objects
  180. *
  181. * @sync_objs: Pointer to sync objects
  182. * @num_objs: Number of objects in the array
  183. * @merged: Merged sync object
  184. */
  185. struct cam_sync_merge {
  186. __u64 sync_objs;
  187. __u32 num_objs;
  188. __s32 merged;
  189. };
  190. /**
  191. * struct cam_sync_userpayload_info - Payload info from user space
  192. *
  193. * @sync_obj: Sync object for which payload has to be registered for
  194. * @reserved: Reserved
  195. * @payload: Pointer to user payload
  196. */
  197. struct cam_sync_userpayload_info {
  198. __s32 sync_obj;
  199. __u32 reserved;
  200. __u64 payload[CAM_SYNC_USER_PAYLOAD_SIZE];
  201. };
  202. /**
  203. * struct cam_sync_wait - Sync object wait information
  204. *
  205. * @sync_obj: Sync object to wait on
  206. * @reserved: Reserved
  207. * @timeout_ms: Timeout in milliseconds
  208. */
  209. struct cam_sync_wait {
  210. __s32 sync_obj;
  211. __u32 reserved;
  212. uint64_t timeout_ms;
  213. };
  214. /**
  215. * struct cam_generic_fence_config - Fence config
  216. * Based on the operation, fields could be
  217. * input/output
  218. *
  219. * @version: Struct version
  220. * @name: Optional string representation [used for create/import]
  221. * @fence_sel_mask: Fence select mask, if set for fence types other than the type
  222. * this input is processed for, the corresponding types would be
  223. * processed as well. For example if one wants to import a sync
  224. * object for an existing dma fence, set mask |= CAM_GENERIC_FENCE_TYPE_SYNC_OBJ,
  225. * a new sync object would be returned in sync_obj linked to an
  226. * existing dma_fence_fd.
  227. * @sync_obj: Sync object
  228. * @dma_fence_fd: DMA fence fd
  229. * @synx_obj: Synx object
  230. * @reason_code: Indicates if the operation was successful or not
  231. * for this set of fences. It is the responsibility of
  232. * the caller to clean up any partially processed batched
  233. * fences
  234. * @num_valid_params: Valid number of params being used
  235. * @valid_param_mask: Mask to indicate the field types in params
  236. * @params: Additional params
  237. */
  238. struct cam_generic_fence_config {
  239. __u32 version;
  240. char name[64];
  241. __u32 fence_sel_mask;
  242. __s32 sync_obj;
  243. __s32 dma_fence_fd;
  244. __s32 synx_obj;
  245. __s32 reason_code;
  246. __u32 num_valid_params;
  247. __u32 valid_param_mask;
  248. __u32 params[4];
  249. };
  250. /**
  251. * struct cam_dma_fence_signal - DMA fence signaling info
  252. *
  253. * @version: Struct version
  254. * @dma_fence_fd: DMA fence to be signaled
  255. * @status: Any status if applicable, 0 for success
  256. * @num_valid_params: Valid number of params being used
  257. * @valid_param_mask: Mask to indicate the field types in params
  258. * @params: Additional params
  259. */
  260. struct cam_dma_fence_signal {
  261. __u32 version;
  262. __s32 dma_fence_fd;
  263. __s32 status;
  264. __u32 num_valid_params;
  265. __u32 valid_param_mask;
  266. __s32 params[3];
  267. };
  268. /**
  269. * struct cam_generic_fence_input_info - Parent structure that
  270. * provides info on fence batching
  271. *
  272. * @version: Struct version
  273. * @num_fences_requested: Number of fences to process
  274. * @num_fences_processed: Number of fences processed
  275. * If userland requests 5 fences to be created
  276. * and it fails on the 3rd, num processed will be
  277. * 3. This can be used by userspace to clean
  278. * partially batched fences
  279. * @num_valid_params: Valid number of params being used
  280. * @valid_param_mask: Mask to indicate the field types in params
  281. * @params: Additional params
  282. * @fence_info: Variable length fence info input based on num_fences
  283. */
  284. struct cam_generic_fence_input_info {
  285. __u32 version;
  286. __u32 num_fences_requested;
  287. __u32 num_fences_processed;
  288. __u32 num_valid_params;
  289. __u32 valid_param_mask;
  290. __s32 params[3];
  291. struct cam_generic_fence_config fence_cfg[1];
  292. };
  293. /**
  294. * struct cam_generic_fence_cmd_args - Generic fence cmd args
  295. *
  296. * @version: Struct version
  297. * @fence_type: Type of fence the ioctl cmd is for [dma/sync/synx]
  298. * @input_handle_type: Type of the fence input handle [user handle is expected]
  299. * @input_data_size: Size of the data pointed to by input_handle
  300. * @input_handle: Handle to the fence input data [create/signal/import...]
  301. * corresponding to the fence_type
  302. * @num_valid_params: Valid number of reserved params being used
  303. * @valid_param_mask: Mask to indicate the field types in params
  304. * @params: Additional params
  305. */
  306. struct cam_generic_fence_cmd_args {
  307. __u32 version;
  308. __u32 fence_type;
  309. __u32 input_handle_type;
  310. __u32 input_data_size;
  311. __u64 input_handle;
  312. __u32 num_valid_params;
  313. __u32 valid_param_mask;
  314. __u32 params[6];
  315. };
  316. /**
  317. * struct cam_private_ioctl_arg - Sync driver ioctl argument
  318. *
  319. * @id: IOCTL command id
  320. * @size: Size of command payload
  321. * @result: Result of command execution
  322. * @reserved: Reserved
  323. * @ioctl_ptr: Pointer to user data
  324. */
  325. struct cam_private_ioctl_arg {
  326. __u32 id;
  327. __u32 size;
  328. __u32 result;
  329. __u32 reserved;
  330. __u64 ioctl_ptr;
  331. };
  332. #define CAM_PRIVATE_IOCTL_CMD \
  333. _IOWR('V', BASE_VIDIOC_PRIVATE, struct cam_private_ioctl_arg)
  334. /* Exclusive sync object IOCTL cmds */
  335. #define CAM_SYNC_CREATE 0
  336. #define CAM_SYNC_DESTROY 1
  337. #define CAM_SYNC_SIGNAL 2
  338. #define CAM_SYNC_MERGE 3
  339. #define CAM_SYNC_REGISTER_PAYLOAD 4
  340. #define CAM_SYNC_DEREGISTER_PAYLOAD 5
  341. #define CAM_SYNC_WAIT 6
  342. /* Generic fence [sync/dma/synx] IOCTL cmds */
  343. #define CAM_GENERIC_FENCE_CREATE 11
  344. #define CAM_GENERIC_FENCE_RELEASE 12
  345. #define CAM_GENERIC_FENCE_IMPORT 13
  346. #define CAM_GENERIC_FENCE_SIGNAL 14
  347. #endif /* __UAPI_CAM_SYNC_H__ */