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