cam_req_mgr.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  1. /* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */
  2. /*
  3. * Copyright (c) 2016-2019, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef __UAPI_LINUX_CAM_REQ_MGR_H
  6. #define __UAPI_LINUX_CAM_REQ_MGR_H
  7. #include <linux/videodev2.h>
  8. #include <linux/types.h>
  9. #include <linux/ioctl.h>
  10. #include <linux/media.h>
  11. #include <media/cam_defs.h>
  12. #define CAM_REQ_MGR_VNODE_NAME "cam-req-mgr-devnode"
  13. #define CAM_DEVICE_TYPE_BASE (MEDIA_ENT_F_OLD_BASE)
  14. #define CAM_VNODE_DEVICE_TYPE (CAM_DEVICE_TYPE_BASE)
  15. #define CAM_SENSOR_DEVICE_TYPE (CAM_DEVICE_TYPE_BASE + 1)
  16. #define CAM_IFE_DEVICE_TYPE (CAM_DEVICE_TYPE_BASE + 2)
  17. #define CAM_ICP_DEVICE_TYPE (CAM_DEVICE_TYPE_BASE + 3)
  18. #define CAM_LRME_DEVICE_TYPE (CAM_DEVICE_TYPE_BASE + 4)
  19. #define CAM_JPEG_DEVICE_TYPE (CAM_DEVICE_TYPE_BASE + 5)
  20. #define CAM_FD_DEVICE_TYPE (CAM_DEVICE_TYPE_BASE + 6)
  21. #define CAM_CPAS_DEVICE_TYPE (CAM_DEVICE_TYPE_BASE + 7)
  22. #define CAM_CSIPHY_DEVICE_TYPE (CAM_DEVICE_TYPE_BASE + 8)
  23. #define CAM_ACTUATOR_DEVICE_TYPE (CAM_DEVICE_TYPE_BASE + 9)
  24. #define CAM_CCI_DEVICE_TYPE (CAM_DEVICE_TYPE_BASE + 10)
  25. #define CAM_FLASH_DEVICE_TYPE (CAM_DEVICE_TYPE_BASE + 11)
  26. #define CAM_EEPROM_DEVICE_TYPE (CAM_DEVICE_TYPE_BASE + 12)
  27. #define CAM_OIS_DEVICE_TYPE (CAM_DEVICE_TYPE_BASE + 13)
  28. #define CAM_CUSTOM_DEVICE_TYPE (CAM_DEVICE_TYPE_BASE + 14)
  29. /* cam_req_mgr hdl info */
  30. #define CAM_REQ_MGR_HDL_IDX_POS 8
  31. #define CAM_REQ_MGR_HDL_IDX_MASK ((1 << CAM_REQ_MGR_HDL_IDX_POS) - 1)
  32. #define CAM_REQ_MGR_GET_HDL_IDX(hdl) (hdl & CAM_REQ_MGR_HDL_IDX_MASK)
  33. /**
  34. * Max handles supported by cam_req_mgr
  35. * It includes both session and device handles
  36. */
  37. #define CAM_REQ_MGR_MAX_HANDLES 64
  38. #define CAM_REQ_MGR_MAX_HANDLES_V2 128
  39. #define MAX_LINKS_PER_SESSION 2
  40. /* V4L event type which user space will subscribe to */
  41. #define V4L_EVENT_CAM_REQ_MGR_EVENT (V4L2_EVENT_PRIVATE_START + 0)
  42. /* Specific event ids to get notified in user space */
  43. #define V4L_EVENT_CAM_REQ_MGR_SOF 0
  44. #define V4L_EVENT_CAM_REQ_MGR_ERROR 1
  45. #define V4L_EVENT_CAM_REQ_MGR_SOF_BOOT_TS 2
  46. /* SOF Event status */
  47. #define CAM_REQ_MGR_SOF_EVENT_SUCCESS 0
  48. #define CAM_REQ_MGR_SOF_EVENT_ERROR 1
  49. /* Link control operations */
  50. #define CAM_REQ_MGR_LINK_ACTIVATE 0
  51. #define CAM_REQ_MGR_LINK_DEACTIVATE 1
  52. /**
  53. * Request Manager : flush_type
  54. * @CAM_REQ_MGR_FLUSH_TYPE_ALL: Req mgr will remove all the pending
  55. * requests from input/processing queue.
  56. * @CAM_REQ_MGR_FLUSH_TYPE_CANCEL_REQ: Req mgr will remove only particular
  57. * request id from input/processing queue.
  58. * @CAM_REQ_MGR_FLUSH_TYPE_MAX: Max number of the flush type
  59. * @opcode: CAM_REQ_MGR_FLUSH_REQ
  60. */
  61. #define CAM_REQ_MGR_FLUSH_TYPE_ALL 0
  62. #define CAM_REQ_MGR_FLUSH_TYPE_CANCEL_REQ 1
  63. #define CAM_REQ_MGR_FLUSH_TYPE_MAX 2
  64. /**
  65. * Request Manager : Sync Mode type
  66. * @CAM_REQ_MGR_SYNC_MODE_NO_SYNC: Req mgr will apply non-sync mode for this
  67. * request.
  68. * @CAM_REQ_MGR_SYNC_MODE_SYNC: Req mgr will apply sync mode for this request.
  69. */
  70. #define CAM_REQ_MGR_SYNC_MODE_NO_SYNC 0
  71. #define CAM_REQ_MGR_SYNC_MODE_SYNC 1
  72. /**
  73. * struct cam_req_mgr_event_data
  74. * @session_hdl: session handle
  75. * @link_hdl: link handle
  76. * @frame_id: frame id
  77. * @reserved: reserved for 64 bit aligngment
  78. * @req_id: request id
  79. * @tv_sec: timestamp in seconds
  80. * @tv_usec: timestamp in micro seconds
  81. */
  82. struct cam_req_mgr_event_data {
  83. int32_t session_hdl;
  84. int32_t link_hdl;
  85. int32_t frame_id;
  86. int32_t reserved;
  87. int64_t req_id;
  88. uint64_t tv_sec;
  89. uint64_t tv_usec;
  90. };
  91. /**
  92. * struct cam_req_mgr_session_info
  93. * @session_hdl: In/Output param - session_handle
  94. * @opcode1: CAM_REQ_MGR_CREATE_SESSION
  95. * @opcode2: CAM_REQ_MGR_DESTROY_SESSION
  96. */
  97. struct cam_req_mgr_session_info {
  98. int32_t session_hdl;
  99. int32_t reserved;
  100. };
  101. /**
  102. * struct cam_req_mgr_link_info
  103. * @session_hdl: Input param - Identifier for CSL session
  104. * @num_devices: Input Param - Num of devices to be linked
  105. * @dev_hdls: Input param - List of device handles to be linked
  106. * @link_hdl: Output Param -Identifier for link
  107. * @opcode: CAM_REQ_MGR_LINK
  108. */
  109. struct cam_req_mgr_link_info {
  110. int32_t session_hdl;
  111. uint32_t num_devices;
  112. int32_t dev_hdls[CAM_REQ_MGR_MAX_HANDLES];
  113. int32_t link_hdl;
  114. };
  115. struct cam_req_mgr_link_info_v2 {
  116. int32_t session_hdl;
  117. uint32_t num_devices;
  118. int32_t dev_hdls[CAM_REQ_MGR_MAX_HANDLES_V2];
  119. int32_t link_hdl;
  120. };
  121. struct cam_req_mgr_ver_info {
  122. uint32_t version;
  123. union {
  124. struct cam_req_mgr_link_info link_info_v1;
  125. struct cam_req_mgr_link_info_v2 link_info_v2;
  126. } u;
  127. };
  128. /**
  129. * struct cam_req_mgr_unlink_info
  130. * @session_hdl: input param - session handle
  131. * @link_hdl: input param - link handle
  132. * @opcode: CAM_REQ_MGR_UNLINK
  133. */
  134. struct cam_req_mgr_unlink_info {
  135. int32_t session_hdl;
  136. int32_t link_hdl;
  137. };
  138. /**
  139. * struct cam_req_mgr_flush_info
  140. * @brief: User can tell drivers to flush a particular request id or
  141. * flush all requests from its pending processing queue. Flush is a
  142. * blocking call and driver shall ensure all requests are flushed
  143. * before returning.
  144. * @session_hdl: Input param - Identifier for CSL session
  145. * @link_hdl: Input Param -Identifier for link
  146. * @flush_type: User can cancel a particular req id or can flush
  147. * all requests in queue
  148. * @reserved: reserved for 64 bit aligngment
  149. * @req_id: field is valid only if flush type is cancel request
  150. * for flush all this field value is not considered.
  151. * @opcode: CAM_REQ_MGR_FLUSH_REQ
  152. */
  153. struct cam_req_mgr_flush_info {
  154. int32_t session_hdl;
  155. int32_t link_hdl;
  156. uint32_t flush_type;
  157. uint32_t reserved;
  158. int64_t req_id;
  159. };
  160. /** struct cam_req_mgr_sched_info
  161. * @session_hdl: Input param - Identifier for CSL session
  162. * @link_hdl: Input Param -Identifier for link
  163. * inluding itself.
  164. * @bubble_enable: Input Param - Cam req mgr will do bubble recovery if this
  165. * flag is set.
  166. * @sync_mode: Type of Sync mode for this request
  167. * @additional_timeout: Additional timeout value (in ms) associated with
  168. * this request. This value needs to be 0 in cases where long exposure is
  169. * not configured for the sensor.The max timeout that will be supported
  170. * is 50000 ms
  171. * @reserved: Reserved
  172. * @req_id: Input Param - Request Id from which all requests will be flushed
  173. */
  174. struct cam_req_mgr_sched_request {
  175. int32_t session_hdl;
  176. int32_t link_hdl;
  177. int32_t bubble_enable;
  178. int32_t sync_mode;
  179. int32_t additional_timeout;
  180. int32_t reserved;
  181. int64_t req_id;
  182. };
  183. /**
  184. * struct cam_req_mgr_sync_mode
  185. * @session_hdl: Input param - Identifier for CSL session
  186. * @sync_mode: Input Param - Type of sync mode
  187. * @num_links: Input Param - Num of links in sync mode (Valid only
  188. * when sync_mode is one of SYNC enabled modes)
  189. * @link_hdls: Input Param - Array of link handles to be in sync mode
  190. * (Valid only when sync_mode is one of SYNC
  191. * enabled modes)
  192. * @master_link_hdl: Input Param - To dictate which link's SOF drives system
  193. * (Valid only when sync_mode is one of SYNC
  194. * enabled modes)
  195. *
  196. * @opcode: CAM_REQ_MGR_SYNC_MODE
  197. */
  198. struct cam_req_mgr_sync_mode {
  199. int32_t session_hdl;
  200. int32_t sync_mode;
  201. int32_t num_links;
  202. int32_t link_hdls[MAX_LINKS_PER_SESSION];
  203. int32_t master_link_hdl;
  204. int32_t reserved;
  205. };
  206. /**
  207. * struct cam_req_mgr_link_control
  208. * @ops: Link operations: activate/deactive
  209. * @session_hdl: Input param - Identifier for CSL session
  210. * @num_links: Input Param - Num of links
  211. * @reserved: reserved field
  212. * @link_hdls: Input Param - Links to be activated/deactivated
  213. *
  214. * @opcode: CAM_REQ_MGR_LINK_CONTROL
  215. */
  216. struct cam_req_mgr_link_control {
  217. int32_t ops;
  218. int32_t session_hdl;
  219. int32_t num_links;
  220. int32_t reserved;
  221. int32_t link_hdls[MAX_LINKS_PER_SESSION];
  222. };
  223. /**
  224. * cam_req_mgr specific opcode ids
  225. */
  226. #define CAM_REQ_MGR_CREATE_DEV_NODES (CAM_COMMON_OPCODE_MAX + 1)
  227. #define CAM_REQ_MGR_CREATE_SESSION (CAM_COMMON_OPCODE_MAX + 2)
  228. #define CAM_REQ_MGR_DESTROY_SESSION (CAM_COMMON_OPCODE_MAX + 3)
  229. #define CAM_REQ_MGR_LINK (CAM_COMMON_OPCODE_MAX + 4)
  230. #define CAM_REQ_MGR_UNLINK (CAM_COMMON_OPCODE_MAX + 5)
  231. #define CAM_REQ_MGR_SCHED_REQ (CAM_COMMON_OPCODE_MAX + 6)
  232. #define CAM_REQ_MGR_FLUSH_REQ (CAM_COMMON_OPCODE_MAX + 7)
  233. #define CAM_REQ_MGR_SYNC_MODE (CAM_COMMON_OPCODE_MAX + 8)
  234. #define CAM_REQ_MGR_ALLOC_BUF (CAM_COMMON_OPCODE_MAX + 9)
  235. #define CAM_REQ_MGR_MAP_BUF (CAM_COMMON_OPCODE_MAX + 10)
  236. #define CAM_REQ_MGR_RELEASE_BUF (CAM_COMMON_OPCODE_MAX + 11)
  237. #define CAM_REQ_MGR_CACHE_OPS (CAM_COMMON_OPCODE_MAX + 12)
  238. #define CAM_REQ_MGR_LINK_CONTROL (CAM_COMMON_OPCODE_MAX + 13)
  239. #define CAM_REQ_MGR_LINK_V2 (CAM_COMMON_OPCODE_MAX + 14)
  240. /* end of cam_req_mgr opcodes */
  241. #define CAM_MEM_FLAG_HW_READ_WRITE (1<<0)
  242. #define CAM_MEM_FLAG_HW_READ_ONLY (1<<1)
  243. #define CAM_MEM_FLAG_HW_WRITE_ONLY (1<<2)
  244. #define CAM_MEM_FLAG_KMD_ACCESS (1<<3)
  245. #define CAM_MEM_FLAG_UMD_ACCESS (1<<4)
  246. #define CAM_MEM_FLAG_PROTECTED_MODE (1<<5)
  247. #define CAM_MEM_FLAG_CMD_BUF_TYPE (1<<6)
  248. #define CAM_MEM_FLAG_PIXEL_BUF_TYPE (1<<7)
  249. #define CAM_MEM_FLAG_STATS_BUF_TYPE (1<<8)
  250. #define CAM_MEM_FLAG_PACKET_BUF_TYPE (1<<9)
  251. #define CAM_MEM_FLAG_CACHE (1<<10)
  252. #define CAM_MEM_FLAG_HW_SHARED_ACCESS (1<<11)
  253. #define CAM_MEM_FLAG_CDSP_OUTPUT (1<<12)
  254. #define CAM_MEM_MMU_MAX_HANDLE 16
  255. /* Maximum allowed buffers in existence */
  256. #define CAM_MEM_BUFQ_MAX 1024
  257. #define CAM_MEM_MGR_SECURE_BIT_POS 15
  258. #define CAM_MEM_MGR_HDL_IDX_SIZE 15
  259. #define CAM_MEM_MGR_HDL_FD_SIZE 16
  260. #define CAM_MEM_MGR_HDL_IDX_END_POS 16
  261. #define CAM_MEM_MGR_HDL_FD_END_POS 32
  262. #define CAM_MEM_MGR_HDL_IDX_MASK ((1 << CAM_MEM_MGR_HDL_IDX_SIZE) - 1)
  263. #define GET_MEM_HANDLE(idx, fd) \
  264. ((idx & CAM_MEM_MGR_HDL_IDX_MASK) | \
  265. (fd << (CAM_MEM_MGR_HDL_FD_END_POS - CAM_MEM_MGR_HDL_FD_SIZE))) \
  266. #define GET_FD_FROM_HANDLE(hdl) \
  267. (hdl >> (CAM_MEM_MGR_HDL_FD_END_POS - CAM_MEM_MGR_HDL_FD_SIZE)) \
  268. #define CAM_MEM_MGR_GET_HDL_IDX(hdl) (hdl & CAM_MEM_MGR_HDL_IDX_MASK)
  269. #define CAM_MEM_MGR_SET_SECURE_HDL(hdl, flag) \
  270. ((flag) ? (hdl |= (1 << CAM_MEM_MGR_SECURE_BIT_POS)) : \
  271. ((hdl) &= ~(1 << CAM_MEM_MGR_SECURE_BIT_POS)))
  272. #define CAM_MEM_MGR_IS_SECURE_HDL(hdl) \
  273. (((hdl) & \
  274. (1<<CAM_MEM_MGR_SECURE_BIT_POS)) >> CAM_MEM_MGR_SECURE_BIT_POS)
  275. /**
  276. * memory allocation type
  277. */
  278. #define CAM_MEM_DMA_NONE 0
  279. #define CAM_MEM_DMA_BIDIRECTIONAL 1
  280. #define CAM_MEM_DMA_TO_DEVICE 2
  281. #define CAM_MEM_DMA_FROM_DEVICE 3
  282. /**
  283. * memory cache operation
  284. */
  285. #define CAM_MEM_CLEAN_CACHE 1
  286. #define CAM_MEM_INV_CACHE 2
  287. #define CAM_MEM_CLEAN_INV_CACHE 3
  288. /**
  289. * struct cam_mem_alloc_out_params
  290. * @buf_handle: buffer handle
  291. * @fd: output buffer file descriptor
  292. * @vaddr: virtual address pointer
  293. */
  294. struct cam_mem_alloc_out_params {
  295. uint32_t buf_handle;
  296. int32_t fd;
  297. uint64_t vaddr;
  298. };
  299. /**
  300. * struct cam_mem_map_out_params
  301. * @buf_handle: buffer handle
  302. * @reserved: reserved for future
  303. * @vaddr: virtual address pointer
  304. */
  305. struct cam_mem_map_out_params {
  306. uint32_t buf_handle;
  307. uint32_t reserved;
  308. uint64_t vaddr;
  309. };
  310. /**
  311. * struct cam_mem_mgr_alloc_cmd
  312. * @len: size of buffer to allocate
  313. * @align: alignment of the buffer
  314. * @mmu_hdls: array of mmu handles
  315. * @num_hdl: number of handles
  316. * @flags: flags of the buffer
  317. * @out: out params
  318. */
  319. /* CAM_REQ_MGR_ALLOC_BUF */
  320. struct cam_mem_mgr_alloc_cmd {
  321. uint64_t len;
  322. uint64_t align;
  323. int32_t mmu_hdls[CAM_MEM_MMU_MAX_HANDLE];
  324. uint32_t num_hdl;
  325. uint32_t flags;
  326. struct cam_mem_alloc_out_params out;
  327. };
  328. /**
  329. * struct cam_mem_mgr_map_cmd
  330. * @mmu_hdls: array of mmu handles
  331. * @num_hdl: number of handles
  332. * @flags: flags of the buffer
  333. * @fd: output buffer file descriptor
  334. * @reserved: reserved field
  335. * @out: out params
  336. */
  337. /* CAM_REQ_MGR_MAP_BUF */
  338. struct cam_mem_mgr_map_cmd {
  339. int32_t mmu_hdls[CAM_MEM_MMU_MAX_HANDLE];
  340. uint32_t num_hdl;
  341. uint32_t flags;
  342. int32_t fd;
  343. uint32_t reserved;
  344. struct cam_mem_map_out_params out;
  345. };
  346. /**
  347. * struct cam_mem_mgr_map_cmd
  348. * @buf_handle: buffer handle
  349. * @reserved: reserved field
  350. */
  351. /* CAM_REQ_MGR_RELEASE_BUF */
  352. struct cam_mem_mgr_release_cmd {
  353. int32_t buf_handle;
  354. uint32_t reserved;
  355. };
  356. /**
  357. * struct cam_mem_mgr_map_cmd
  358. * @buf_handle: buffer handle
  359. * @ops: cache operations
  360. */
  361. /* CAM_REQ_MGR_CACHE_OPS */
  362. struct cam_mem_cache_ops_cmd {
  363. int32_t buf_handle;
  364. uint32_t mem_cache_ops;
  365. };
  366. /**
  367. * Request Manager : error message type
  368. * @CAM_REQ_MGR_ERROR_TYPE_DEVICE: Device error message, fatal to session
  369. * @CAM_REQ_MGR_ERROR_TYPE_REQUEST: Error on a single request, not fatal
  370. * @CAM_REQ_MGR_ERROR_TYPE_BUFFER: Buffer was not filled, not fatal
  371. * @CAM_REQ_MGR_ERROR_TYPE_RECOVERY: Fatal error, can be recovered
  372. * @CAM_REQ_MGR_ERROR_TYPE_SOF_FREEZE: SOF freeze, can be recovered
  373. */
  374. #define CAM_REQ_MGR_ERROR_TYPE_DEVICE 0
  375. #define CAM_REQ_MGR_ERROR_TYPE_REQUEST 1
  376. #define CAM_REQ_MGR_ERROR_TYPE_BUFFER 2
  377. #define CAM_REQ_MGR_ERROR_TYPE_RECOVERY 3
  378. #define CAM_REQ_MGR_ERROR_TYPE_SOF_FREEZE 4
  379. /**
  380. * struct cam_req_mgr_error_msg
  381. * @error_type: type of error
  382. * @request_id: request id of frame
  383. * @device_hdl: device handle
  384. * @linke_hdl: link_hdl
  385. * @resource_size: size of the resource
  386. */
  387. struct cam_req_mgr_error_msg {
  388. uint32_t error_type;
  389. uint32_t request_id;
  390. int32_t device_hdl;
  391. int32_t link_hdl;
  392. uint64_t resource_size;
  393. };
  394. /**
  395. * struct cam_req_mgr_frame_msg
  396. * @request_id: request id of the frame
  397. * @frame_id: frame id of the frame
  398. * @timestamp: timestamp of the frame
  399. * @link_hdl: link handle associated with this message
  400. * @sof_status: sof status success or fail
  401. */
  402. struct cam_req_mgr_frame_msg {
  403. uint64_t request_id;
  404. uint64_t frame_id;
  405. uint64_t timestamp;
  406. int32_t link_hdl;
  407. uint32_t sof_status;
  408. };
  409. /**
  410. * struct cam_req_mgr_message
  411. * @session_hdl: session to which the frame belongs to
  412. * @reserved: reserved field
  413. * @u: union which can either be error or frame message
  414. */
  415. struct cam_req_mgr_message {
  416. int32_t session_hdl;
  417. int32_t reserved;
  418. union {
  419. struct cam_req_mgr_error_msg err_msg;
  420. struct cam_req_mgr_frame_msg frame_msg;
  421. } u;
  422. };
  423. #endif /* __UAPI_LINUX_CAM_REQ_MGR_H */