cam_req_mgr.h 13 KB

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