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