cam_req_mgr.h 14 KB

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