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