blob: e4865b3d410a6a267f61566838a75ec3db99240d [file] [log] [blame]
Venkat Chintaddbe5132018-01-30 12:00:29 -08001/* Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
Sagar Gore8d91a622017-02-23 14:57:18 -08002 *
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#ifndef _CAM_REQ_MGR_CORE_H_
13#define _CAM_REQ_MGR_CORE_H_
14
Ravikishore Pampana6c2e1c12017-10-16 18:46:15 +053015#include <linux/spinlock.h>
Sagar Gore8d91a622017-02-23 14:57:18 -080016#include "cam_req_mgr_interface.h"
17#include "cam_req_mgr_core_defs.h"
Sagar Gored79f95e2017-03-14 18:32:17 -070018#include "cam_req_mgr_timer.h"
Sagar Gore8d91a622017-02-23 14:57:18 -080019
Sagar Gored79f95e2017-03-14 18:32:17 -070020#define CAM_REQ_MGR_MAX_LINKED_DEV 16
21#define MAX_REQ_SLOTS 48
22
23#define CAM_REQ_MGR_WATCHDOG_TIMEOUT 5000
24#define CAM_REQ_MGR_SCHED_REQ_TIMEOUT 1000
25#define CAM_REQ_MGR_SIMULATE_SCHED_REQ 30
26
27#define FORCE_DISABLE_RECOVERY 2
28#define FORCE_ENABLE_RECOVERY 1
29#define AUTO_RECOVERY 0
30
Sagar Goreb56c81e2017-05-08 17:15:47 -070031#define CRM_WORKQ_NUM_TASKS 60
Sagar Gore8d91a622017-02-23 14:57:18 -080032
Pavan Kumar Chilamkurthi1fd03442017-11-07 17:07:21 -080033#define MAX_SYNC_COUNT 65535
34
Sagar Gore8d91a622017-02-23 14:57:18 -080035/**
Sagar Gored79f95e2017-03-14 18:32:17 -070036 * enum crm_workq_task_type
37 * @codes: to identify which type of task is present
Sagar Gore8d91a622017-02-23 14:57:18 -080038 */
Sagar Gored79f95e2017-03-14 18:32:17 -070039enum crm_workq_task_type {
40 CRM_WORKQ_TASK_GET_DEV_INFO,
41 CRM_WORKQ_TASK_SETUP_LINK,
42 CRM_WORKQ_TASK_DEV_ADD_REQ,
43 CRM_WORKQ_TASK_APPLY_REQ,
44 CRM_WORKQ_TASK_NOTIFY_SOF,
45 CRM_WORKQ_TASK_NOTIFY_ERR,
46 CRM_WORKQ_TASK_SCHED_REQ,
47 CRM_WORKQ_TASK_FLUSH_REQ,
48 CRM_WORKQ_TASK_INVALID,
49};
50
51/**
52 * struct crm_task_payload
Junzhe Zou2df84502017-05-26 13:20:23 -070053 * @type : to identify which type of task is present
54 * @u : union of payload of all types of tasks supported
55 * @sched_req : contains info of incoming reqest from CSL to CRM
56 * @flush_info : contains info of cancelled reqest
57 * @dev_req : contains tracking info of available req id at device
58 * @send_req : contains info of apply settings to be sent to devs in link
59 * @apply_req : contains info of which request is applied at device
60 * @notify_trigger : contains notification from IFE to CRM about trigger
61 * @notify_err : contains error info happened while processing request
Sagar Gored79f95e2017-03-14 18:32:17 -070062 * -
63 */
64struct crm_task_payload {
65 enum crm_workq_task_type type;
66 union {
67 struct cam_req_mgr_sched_request sched_req;
68 struct cam_req_mgr_flush_info flush_info;
69 struct cam_req_mgr_add_request dev_req;
70 struct cam_req_mgr_send_request send_req;
Junzhe Zou2df84502017-05-26 13:20:23 -070071 struct cam_req_mgr_trigger_notify notify_trigger;
Sagar Gored79f95e2017-03-14 18:32:17 -070072 struct cam_req_mgr_error_notify notify_err;
73 } u;
74};
75
76/**
77 * enum crm_req_state
78 * State machine for life cycle of request in pd table
79 * EMPTY : indicates req slot is empty
80 * PENDING : indicates req slot is waiting for reqs from all devs
81 * READY : indicates req slot is ready to be sent to devs
82 * INVALID : indicates req slot is not in valid state
83 */
84enum crm_req_state {
85 CRM_REQ_STATE_EMPTY,
86 CRM_REQ_STATE_PENDING,
87 CRM_REQ_STATE_READY,
88 CRM_REQ_STATE_INVALID,
89};
90
91/**
92 * enum crm_slot_status
93 * State machine for life cycle of request in input queue
94 * NO_REQ : empty slot
95 * REQ_ADDED : new entry in slot
Junzhe Zou2df84502017-05-26 13:20:23 -070096 * PENDING : waiting for next trigger to apply
97 * APPLIED : req is sent to all devices
Sagar Gored79f95e2017-03-14 18:32:17 -070098 * INVALID : invalid state
99 */
100enum crm_slot_status {
101 CRM_SLOT_STATUS_NO_REQ,
102 CRM_SLOT_STATUS_REQ_ADDED,
103 CRM_SLOT_STATUS_REQ_PENDING,
104 CRM_SLOT_STATUS_REQ_APPLIED,
105 CRM_SLOT_STATUS_INVALID,
Sagar Gore8d91a622017-02-23 14:57:18 -0800106};
107
108/**
109 * enum cam_req_mgr_link_state
110 * State machine for life cycle of link in crm
Sagar Gored79f95e2017-03-14 18:32:17 -0700111 * AVAILABLE : link available
112 * IDLE : link initialized but not ready yet
113 * READY : link is ready for use
Junzhe Zou2df84502017-05-26 13:20:23 -0700114 * ERR : link has encountered error
Sagar Gored79f95e2017-03-14 18:32:17 -0700115 * MAX : invalid state
Sagar Gore8d91a622017-02-23 14:57:18 -0800116 */
117enum cam_req_mgr_link_state {
118 CAM_CRM_LINK_STATE_AVAILABLE,
119 CAM_CRM_LINK_STATE_IDLE,
120 CAM_CRM_LINK_STATE_READY,
Sagar Gored79f95e2017-03-14 18:32:17 -0700121 CAM_CRM_LINK_STATE_ERR,
122 CAM_CRM_LINK_STATE_MAX,
Sagar Gore8d91a622017-02-23 14:57:18 -0800123};
124
125/**
Sagar Gored79f95e2017-03-14 18:32:17 -0700126 * struct cam_req_mgr_traverse
Karthik Anantha Ramfa643332017-11-06 13:49:31 -0800127 * @idx : slot index
128 * @result : contains which all tables were able to apply successfully
129 * @tbl : pointer of pipeline delay based request table
130 * @apply_data : pointer which various tables will update during traverse
131 * @in_q : input request queue pointer
132 * @validate_only : Whether to validate only and/or update settings
Vishalsingh Hajeri87c3131b2018-02-09 17:36:35 -0800133 * @self_link : To indicate whether the check is for the given link or the
134 * other sync link
Sagar Gore8d91a622017-02-23 14:57:18 -0800135 */
Sagar Gored79f95e2017-03-14 18:32:17 -0700136struct cam_req_mgr_traverse {
137 int32_t idx;
138 uint32_t result;
139 struct cam_req_mgr_req_tbl *tbl;
140 struct cam_req_mgr_apply *apply_data;
141 struct cam_req_mgr_req_queue *in_q;
Karthik Anantha Ramfa643332017-11-06 13:49:31 -0800142 bool validate_only;
Vishalsingh Hajeri87c3131b2018-02-09 17:36:35 -0800143 bool self_link;
Sagar Gored79f95e2017-03-14 18:32:17 -0700144};
145
146/**
147 * struct cam_req_mgr_apply
148 * @idx : corresponding input queue slot index
149 * @pd : pipeline delay of device
150 * @req_id : req id for dev with above pd to process
151 * @skip_idx: skip applying settings when this is set.
152 */
153struct cam_req_mgr_apply {
Sagar Gore8d91a622017-02-23 14:57:18 -0800154 int32_t idx;
Sagar Gored79f95e2017-03-14 18:32:17 -0700155 int32_t pd;
156 int64_t req_id;
157 int32_t skip_idx;
Sagar Gore8d91a622017-02-23 14:57:18 -0800158};
159
160/**
Sagar Gored79f95e2017-03-14 18:32:17 -0700161 * struct cam_req_mgr_tbl_slot
162 * @idx : slot index
163 * @req_ready_map : mask tracking which all devices have request ready
164 * @state : state machine for life cycle of a slot
Sagar Gore8d91a622017-02-23 14:57:18 -0800165 */
Sagar Gored79f95e2017-03-14 18:32:17 -0700166struct cam_req_mgr_tbl_slot {
167 int32_t idx;
168 uint32_t req_ready_map;
169 enum crm_req_state state;
Sagar Gore8d91a622017-02-23 14:57:18 -0800170};
171
172/**
Sagar Gored79f95e2017-03-14 18:32:17 -0700173 * struct cam_req_mgr_req_tbl
174 * @id : table indetifier
175 * @pd : pipeline delay of table
176 * @dev_count : num of devices having same pipeline delay
177 * @dev_mask : mask to track which devices are linked
178 * @skip_traverse : to indicate how many traverses need to be dropped
179 * by this table especially in the beginning or bubble recovery
180 * @next : pointer to next pipeline delay request table
181 * @pd_delta : differnce between this table's pipeline delay and next
182 * @num_slots : number of request slots present in the table
183 * @slot : array of slots tracking requests availability at devices
Sagar Gorea4d7dfd2017-09-13 19:56:24 -0700184 * @inject_delay : insert extra bubbling for flash type of use cases
Sagar Gore8d91a622017-02-23 14:57:18 -0800185 */
Sagar Gored79f95e2017-03-14 18:32:17 -0700186struct cam_req_mgr_req_tbl {
187 int32_t id;
188 int32_t pd;
189 int32_t dev_count;
190 int32_t dev_mask;
191 int32_t skip_traverse;
192 struct cam_req_mgr_req_tbl *next;
193 int32_t pd_delta;
194 int32_t num_slots;
195 struct cam_req_mgr_tbl_slot slot[MAX_REQ_SLOTS];
Sagar Gorea4d7dfd2017-09-13 19:56:24 -0700196 uint32_t inject_delay;
Sagar Gore8d91a622017-02-23 14:57:18 -0800197};
198
199/**
Sagar Gored79f95e2017-03-14 18:32:17 -0700200 * struct cam_req_mgr_slot
201 * - Internal Book keeping
Junzhe Zou2df84502017-05-26 13:20:23 -0700202 * @idx : slot index
203 * @skip_idx : if req id in this slot needs to be skipped/not applied
204 * @status : state machine for life cycle of a slot
Sagar Gored79f95e2017-03-14 18:32:17 -0700205 * - members updated due to external events
Junzhe Zou2df84502017-05-26 13:20:23 -0700206 * @recover : if user enabled recovery for this request.
207 * @req_id : mask tracking which all devices have request ready
Pavan Kumar Chilamkurthi1fd03442017-11-07 17:07:21 -0800208 * @sync_mode : Sync mode in which req id in this slot has to applied
Sagar Gore8d91a622017-02-23 14:57:18 -0800209 */
Sagar Gored79f95e2017-03-14 18:32:17 -0700210struct cam_req_mgr_slot {
211 int32_t idx;
212 int32_t skip_idx;
213 enum crm_slot_status status;
214 int32_t recover;
215 int64_t req_id;
Pavan Kumar Chilamkurthi1fd03442017-11-07 17:07:21 -0800216 int32_t sync_mode;
Sagar Gored79f95e2017-03-14 18:32:17 -0700217};
218
219/**
220 * struct cam_req_mgr_req_queue
221 * @num_slots : max num of input queue slots
222 * @slot : request slot holding incoming request id and bubble info.
223 * @rd_idx : indicates slot index currently in process.
224 * @wr_idx : indicates slot index to hold new upcoming req.
225 */
226struct cam_req_mgr_req_queue {
227 int32_t num_slots;
228 struct cam_req_mgr_slot slot[MAX_REQ_SLOTS];
229 int32_t rd_idx;
230 int32_t wr_idx;
231};
232
233/**
234 * struct cam_req_mgr_req_data
235 * @in_q : Poiner to Input request queue
236 * @l_tbl : unique pd request tables.
237 * @num_tbl : how many unique pd value devices are present
238 * @apply_data : Holds information about request id for a request
239 * @lock : mutex lock protecting request data ops.
240 */
241struct cam_req_mgr_req_data {
242 struct cam_req_mgr_req_queue *in_q;
243 struct cam_req_mgr_req_tbl *l_tbl;
244 int32_t num_tbl;
245 struct cam_req_mgr_apply apply_data[CAM_PIPELINE_DELAY_MAX];
246 struct mutex lock;
Sagar Gore8d91a622017-02-23 14:57:18 -0800247};
248
249/**
250 * struct cam_req_mgr_connected_device
Sagar Gored79f95e2017-03-14 18:32:17 -0700251 * - Device Properties
252 * @dev_hdl : device handle
253 * @dev_bit : unique bit assigned to device in link
Sagar Gore8d91a622017-02-23 14:57:18 -0800254 * - Device characteristics
Sagar Gored79f95e2017-03-14 18:32:17 -0700255 * @pd_tbl : tracks latest available req id at this device
256 * @dev_info : holds dev characteristics such as pipeline delay, dev name
257 * @ops : holds func pointer to call methods on this device
258 * @parent : pvt data - like link which this dev hdl belongs to
Sagar Gore8d91a622017-02-23 14:57:18 -0800259 */
260struct cam_req_mgr_connected_device {
Sagar Gored79f95e2017-03-14 18:32:17 -0700261 int32_t dev_hdl;
262 int64_t dev_bit;
263 struct cam_req_mgr_req_tbl *pd_tbl;
264 struct cam_req_mgr_device_info dev_info;
265 struct cam_req_mgr_kmd_ops *ops;
266 void *parent;
Sagar Gore8d91a622017-02-23 14:57:18 -0800267};
268
269/**
270 * struct cam_req_mgr_core_link
Sagar Gored79f95e2017-03-14 18:32:17 -0700271 * - Link Properties
Ravikishore Pampana6c2e1c12017-10-16 18:46:15 +0530272 * @link_hdl : Link identifier
273 * @num_devs : num of connected devices to this link
274 * @max_delay : Max of pipeline delay of all connected devs
275 * @workq : Pointer to handle workq related jobs
276 * @pd_mask : each set bit indicates the device with pd equal to
277 * bit position is available.
Sagar Gore8d91a622017-02-23 14:57:18 -0800278 * - List of connected devices
Ravikishore Pampana6c2e1c12017-10-16 18:46:15 +0530279 * @l_dev : List of connected devices to this link
Sagar Gored79f95e2017-03-14 18:32:17 -0700280 * - Request handling data struct
Ravikishore Pampana6c2e1c12017-10-16 18:46:15 +0530281 * @req : req data holder.
Sagar Gored79f95e2017-03-14 18:32:17 -0700282 * - Timer
Ravikishore Pampana6c2e1c12017-10-16 18:46:15 +0530283 * @watchdog : watchdog timer to recover from sof freeze
Sagar Gore8d91a622017-02-23 14:57:18 -0800284 * - Link private data
Ravikishore Pampana6c2e1c12017-10-16 18:46:15 +0530285 * @workq_comp : conditional variable to block user thread for workq
286 * to finish schedule request processing
287 * @state : link state machine
288 * @parent : pvt data - link's parent is session
289 * @lock : mutex lock to guard link data operations
290 * @link_state_spin_lock : spin lock to protect link state variable
291 * @subscribe_event : irqs that link subscribes, IFE should send
292 * notification to CRM at those hw events.
293 * @trigger_mask : mask on which irq the req is already applied
Pavan Kumar Chilamkurthi1fd03442017-11-07 17:07:21 -0800294 * @sync_link : pointer to the sync link for synchronization
295 * @sof_counter : sof counter during sync_mode
296 * @sync_self_ref : reference sync count against which the difference
297 * between sync_counts for a given link is checked
298 * @frame_skip_flag : flag that determines if a frame needs to be skipped
299 *
Sagar Gore8d91a622017-02-23 14:57:18 -0800300 */
301struct cam_req_mgr_core_link {
Sagar Gored79f95e2017-03-14 18:32:17 -0700302 int32_t link_hdl;
303 int32_t num_devs;
304 enum cam_pipeline_delay max_delay;
305 struct cam_req_mgr_core_workq *workq;
306 int32_t pd_mask;
307 struct cam_req_mgr_connected_device *l_dev;
308 struct cam_req_mgr_req_data req;
309 struct cam_req_mgr_timer *watchdog;
310 struct completion workq_comp;
311 enum cam_req_mgr_link_state state;
312 void *parent;
313 struct mutex lock;
Ravikishore Pampana6c2e1c12017-10-16 18:46:15 +0530314 spinlock_t link_state_spin_lock;
Junzhe Zou2df84502017-05-26 13:20:23 -0700315 uint32_t subscribe_event;
316 uint32_t trigger_mask;
Pavan Kumar Chilamkurthi1fd03442017-11-07 17:07:21 -0800317 struct cam_req_mgr_core_link *sync_link;
318 int64_t sof_counter;
319 int64_t sync_self_ref;
320 bool frame_skip_flag;
Sagar Gore8d91a622017-02-23 14:57:18 -0800321};
322
323/**
324 * struct cam_req_mgr_core_session
325 * - Session Properties
Sagar Gored79f95e2017-03-14 18:32:17 -0700326 * @session_hdl : session identifier
327 * @num_links : num of active links for current session
Sagar Gore8d91a622017-02-23 14:57:18 -0800328 * - Links of this session
Sagar Gored79f95e2017-03-14 18:32:17 -0700329 * @links : pointer to array of links within session
330 * @in_q : Input request queue one per session
Sagar Gore8d91a622017-02-23 14:57:18 -0800331 * - Session private data
Sagar Gored79f95e2017-03-14 18:32:17 -0700332 * @entry : pvt data - entry in the list of sessions
333 * @lock : pvt data - spin lock to guard session data
334 * - Debug data
335 * @force_err_recovery : For debugging, we can force bubble recovery
336 * to be always ON or always OFF using debugfs.
Pavan Kumar Chilamkurthi1fd03442017-11-07 17:07:21 -0800337 * @sync_mode : Sync mode for this session links
Sagar Gore8d91a622017-02-23 14:57:18 -0800338 */
339struct cam_req_mgr_core_session {
Sagar Gored79f95e2017-03-14 18:32:17 -0700340 int32_t session_hdl;
341 uint32_t num_links;
342 struct cam_req_mgr_core_link *links[MAX_LINKS_PER_SESSION];
Sagar Gored79f95e2017-03-14 18:32:17 -0700343 struct list_head entry;
344 struct mutex lock;
345 int32_t force_err_recovery;
Pavan Kumar Chilamkurthi1fd03442017-11-07 17:07:21 -0800346 int32_t sync_mode;
Sagar Gore8d91a622017-02-23 14:57:18 -0800347};
348
349/**
350 * struct cam_req_mgr_core_device
351 * - Core camera request manager data struct
Sagar Gored79f95e2017-03-14 18:32:17 -0700352 * @session_head : list head holding sessions
353 * @crm_lock : mutex lock to protect session creation & destruction
Sagar Gore8d91a622017-02-23 14:57:18 -0800354 */
355struct cam_req_mgr_core_device {
Sagar Gored79f95e2017-03-14 18:32:17 -0700356 struct list_head session_head;
357 struct mutex crm_lock;
Sagar Gore8d91a622017-02-23 14:57:18 -0800358};
359
Sagar Gore8d91a622017-02-23 14:57:18 -0800360/**
361 * cam_req_mgr_create_session()
Sagar Gored79f95e2017-03-14 18:32:17 -0700362 * @brief : creates session
363 * @ses_info : output param for session handle
Sagar Gore8d91a622017-02-23 14:57:18 -0800364 *
Sagar Gored79f95e2017-03-14 18:32:17 -0700365 * called as part of session creation.
Sagar Gore8d91a622017-02-23 14:57:18 -0800366 */
Sagar Gored79f95e2017-03-14 18:32:17 -0700367int cam_req_mgr_create_session(struct cam_req_mgr_session_info *ses_info);
Sagar Gore8d91a622017-02-23 14:57:18 -0800368
369/**
370 * cam_req_mgr_destroy_session()
Sagar Gored79f95e2017-03-14 18:32:17 -0700371 * @brief : destroy session
372 * @ses_info : session handle info, input param
Sagar Gore8d91a622017-02-23 14:57:18 -0800373 *
374 * Called as part of session destroy
375 * return success/failure
376 */
Sagar Gored79f95e2017-03-14 18:32:17 -0700377int cam_req_mgr_destroy_session(struct cam_req_mgr_session_info *ses_info);
Sagar Gore8d91a622017-02-23 14:57:18 -0800378
379/**
380 * cam_req_mgr_link()
Sagar Gored79f95e2017-03-14 18:32:17 -0700381 * @brief : creates a link for a session
382 * @link_info : handle and session info to create a link
Sagar Gore8d91a622017-02-23 14:57:18 -0800383 *
Sagar Gored79f95e2017-03-14 18:32:17 -0700384 * link is formed in a session for multiple devices. it creates
Sagar Gore8d91a622017-02-23 14:57:18 -0800385 * a unique link handle for the link and is specific to a
386 * session. Returns link handle
387 */
388int cam_req_mgr_link(struct cam_req_mgr_link_info *link_info);
389
390/**
391 * cam_req_mgr_unlink()
Sagar Gored79f95e2017-03-14 18:32:17 -0700392 * @brief : destroy a link in a session
393 * @unlink_info : session and link handle info
Sagar Gore8d91a622017-02-23 14:57:18 -0800394 *
Sagar Gored79f95e2017-03-14 18:32:17 -0700395 * link is destroyed in a session
Sagar Gore8d91a622017-02-23 14:57:18 -0800396 */
397int cam_req_mgr_unlink(struct cam_req_mgr_unlink_info *unlink_info);
398
399/**
400 * cam_req_mgr_schedule_request()
401 * @brief: Request is scheduled
402 * @sched_req: request id, session and link id info, bubble recovery info
403 */
404int cam_req_mgr_schedule_request(
405 struct cam_req_mgr_sched_request *sched_req);
406
407/**
Pavan Kumar Chilamkurthi1fd03442017-11-07 17:07:21 -0800408 * cam_req_mgr_sync_mode_setup()
Sagar Gore8d91a622017-02-23 14:57:18 -0800409 * @brief: sync for links in a session
Pavan Kumar Chilamkurthi1fd03442017-11-07 17:07:21 -0800410 * @sync_info: session, links info and master link info
Sagar Gore8d91a622017-02-23 14:57:18 -0800411 */
Pavan Kumar Chilamkurthi1fd03442017-11-07 17:07:21 -0800412int cam_req_mgr_sync_config(struct cam_req_mgr_sync_mode *sync_info);
Sagar Gore8d91a622017-02-23 14:57:18 -0800413
414/**
415 * cam_req_mgr_flush_requests()
416 * @brief: flush all requests
417 * @flush_info: requests related to link and session
418 */
419int cam_req_mgr_flush_requests(
420 struct cam_req_mgr_flush_info *flush_info);
421
422/**
423 * cam_req_mgr_core_device_init()
424 * @brief: initialize crm core
425 */
426int cam_req_mgr_core_device_init(void);
427
428/**
429 * cam_req_mgr_core_device_deinit()
430 * @brief: cleanp crm core
431 */
432int cam_req_mgr_core_device_deinit(void);
Soundrapandian Jeyaprakash8d16e272017-10-12 11:05:37 -0700433
434/**
435 * cam_req_mgr_handle_core_shutdown()
436 * @brief: Handles camera close
437 */
438void cam_req_mgr_handle_core_shutdown(void);
Jing Zhou0f645332017-11-17 12:16:40 -0800439
440/**
441 * cam_req_mgr_link_control()
442 * @brief: Handles link control operations
443 * @control: Link control command
444 */
445int cam_req_mgr_link_control(struct cam_req_mgr_link_control *control);
446
Sagar Gore8d91a622017-02-23 14:57:18 -0800447#endif
448