cam_req_mgr.h 15 KB

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