blob: 21cd6dd66117d213a5f69876eb08e7aa6b7e423a [file] [log] [blame]
Sagar Gore8d91a622017-02-23 14:57:18 -08001/* Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13#ifndef _CAM_REQ_MGR_UTIL_API_H_
14#define _CAM_REQ_MGR_UTIL_API_H_
15
16#include <media/cam_req_mgr.h>
17#include "cam_req_mgr_util_priv.h"
18
19/**
20 * state of a handle(session/device)
21 * @HDL_FREE: free handle
22 * @HDL_ACTIVE: active handles
23 */
24enum hdl_state {
25 HDL_FREE,
26 HDL_ACTIVE
27};
28
29/**
30 * handle type
31 * @HDL_TYPE_DEV: for device and link
32 * @HDL_TYPE_SESSION: for session
33 */
34enum hdl_type {
35 HDL_TYPE_DEV = 1,
36 HDL_TYPE_SESSION
37};
38
39/**
40 * struct handle
41 * @session_hdl: session handle
42 * @hdl_value: Allocated handle
43 * @type: session/device handle
44 * @state: free/used
45 * @ops: ops structure
46 * @priv: private data of a handle
47 */
48struct handle {
49 int32_t session_hdl;
50 uint32_t hdl_value;
51 enum hdl_type type;
52 enum hdl_state state;
53 void *ops;
54 void *priv;
55};
56
57/**
58 * struct cam_req_mgr_util_hdl_tbl
59 * @hdl: row of handles
60 * @bitmap: bit map to get free hdl row idx
61 * @bits: size of bit map in bits
62 */
63struct cam_req_mgr_util_hdl_tbl {
64 struct handle hdl[CAM_REQ_MGR_MAX_HANDLES];
65 void *bitmap;
66 size_t bits;
67};
68
69/**
70 * cam_req_mgr_util APIs for KMD drivers and cam_req_mgr
71 * @session_hdl: session_hdl info
72 * @v4l2_sub_dev_flag: flag to create v4l2 sub device
73 * @media_entity_flag: flag for media entity
74 * @reserved: reserved field
75 * @ops: ops pointer for a device handle
76 * @priv: private data for a device handle
77 */
78struct cam_create_dev_hdl {
79 int32_t session_hdl;
80 int32_t v4l2_sub_dev_flag;
81 int32_t media_entity_flag;
82 int32_t reserved;
83 void *ops;
84 void *priv;
85};
86
87/**
88 * cam_create_session_hdl() - create a session handle
89 * @priv: private data for a session handle
90 *
91 * cam_req_mgr core calls this function to get
92 * a unique session handle. Returns a unique session
93 * handle
94 */
95int32_t cam_create_session_hdl(void *priv);
96
97/**
98 * cam_create_device_hdl() - create a device handle
99 * @hdl_data: session hdl, flags, ops and priv dara as input
100 *
101 * cam_req_mgr_core calls this function to get
102 * session and link handles
103 * KMD drivers calls this function to create
104 * a device handle. Returns a unique device handle
105 */
106int32_t cam_create_device_hdl(struct cam_create_dev_hdl *hdl_data);
107
108/**
109 * cam_get_device_priv() - get private data of a handle
110 * @dev_hdl: handle for a session/link/device
111 *
112 * cam_req_mgr_core and KMD drivers use this function to
113 * get private data of a handle. Returns a private data
114 * structure pointer.
115 */
116void *cam_get_device_priv(int32_t dev_hdl);
117
118/**
119 * cam_get_device_ops() - get ops of a handle
120 * @dev_hdl: handle for a session/link/device
121 *
122 * cam_req_mgr_core and KMD drivers use this function to
123 * get ops of a handle. Returns a pointer to ops.
124 */
125void *cam_get_device_ops(int32_t dev_hdl);
126
127/**
128 * cam_destroy_device_hdl() - destroy device handle
129 * @dev_hdl: handle for a link/device.
130 *
131 * Returns success/failure
132 */
133int32_t cam_destroy_device_hdl(int32_t dev_hdl);
134
135/**
136 * cam_destroy_session_hdl() - destroy device handle
137 * @dev_hdl: handle for a session
138 *
139 * Returns success/failure
140 */
141int32_t cam_destroy_session_hdl(int32_t dev_hdl);
142
143
144/* Internal functions */
145/**
146 * cam_req_mgr_util_init() - init function of cam_req_mgr_util
147 *
148 * This is called as part of probe function to initialize
149 * handle table, bitmap, locks
150 */
151int cam_req_mgr_util_init(void);
152
153/**
154 * cam_req_mgr_util_deinit() - deinit function of cam_req_mgr_util
155 *
156 * This function is called in case of probe failure
157 */
158int32_t cam_req_mgr_util_deinit(void);
159
160/**
161 * cam_req_mgr_util_free_hdls() - free handles in case of crash
162 *
163 * Called from cam_req_mgr_dev release function to make sure
164 * all data structures are cleaned to avoid leaks
165 *
166 * cam_req_mgr core can call this function at the end of
167 * camera to make sure all stale entries are printed and
168 * cleaned
169 */
170int32_t cam_req_mgr_util_free_hdls(void);
171
172#endif /* _CAM_REQ_MGR_UTIL_API_H_ */