blob: c1cd00f8afff37d70153a709f629956c2f958906 [file] [log] [blame]
Shravya Samala43583ea2020-04-29 14:25:37 +05301/* Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
Jing Zhoud352ed12017-03-20 23:59:56 -07002 *
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_ISP_CONTEXT_H_
14#define _CAM_ISP_CONTEXT_H_
15
16
17#include <linux/spinlock.h>
18#include <uapi/media/cam_isp.h>
19
20#include "cam_context.h"
21#include "cam_isp_hw_mgr_intf.h"
22
23/*
24 * Maximum hw resource - This number is based on the maximum
25 * output port resource. The current maximum resource number
Vishalsingh Hajeri8f6e1dd2018-05-17 12:19:39 -070026 * is 20.
Jing Zhoud352ed12017-03-20 23:59:56 -070027 */
Vishalsingh Hajeri8f6e1dd2018-05-17 12:19:39 -070028#define CAM_ISP_CTX_RES_MAX 20
Jing Zhoud352ed12017-03-20 23:59:56 -070029
30/*
Vishalsingh Hajeric0cab062017-09-28 18:25:16 -070031 * Maximum configuration entry size - This is based on the
Jing Zhoud352ed12017-03-20 23:59:56 -070032 * worst case DUAL IFE use case plus some margin.
33 */
Harsh Shah9d676dd2017-08-30 16:30:04 -070034#define CAM_ISP_CTX_CFG_MAX 22
Jing Zhoud352ed12017-03-20 23:59:56 -070035
Shravya Samala43583ea2020-04-29 14:25:37 +053036/* Maximum allowed sof count in rdi only bubble state
37 * till buf_done is received for bubble req_id.
38 */
39#define CAM_ISP_CTX_BUBBLE_SOF_COUNT_MAX 3
40
Vishalsingh Hajeric0cab062017-09-28 18:25:16 -070041/*
42 * Maximum entries in state monitoring array for error logging
43 */
44#define CAM_ISP_CTX_STATE_MONITOR_MAX_ENTRIES 20
45
Jing Zhoud352ed12017-03-20 23:59:56 -070046/* forward declaration */
47struct cam_isp_context;
48
49/* cam isp context irq handling function type */
50typedef int (*cam_isp_hw_event_cb_func)(struct cam_isp_context *ctx_isp,
51 void *evt_data);
52
53/**
54 * enum cam_isp_ctx_activated_substate - sub states for activated
55 *
56 */
57enum cam_isp_ctx_activated_substate {
58 CAM_ISP_CTX_ACTIVATED_SOF,
59 CAM_ISP_CTX_ACTIVATED_APPLIED,
60 CAM_ISP_CTX_ACTIVATED_EPOCH,
61 CAM_ISP_CTX_ACTIVATED_BUBBLE,
62 CAM_ISP_CTX_ACTIVATED_BUBBLE_APPLIED,
Alok Pandeyfdfa5ba2017-09-22 14:21:25 +053063 CAM_ISP_CTX_ACTIVATED_HW_ERROR,
Jing Zhoud352ed12017-03-20 23:59:56 -070064 CAM_ISP_CTX_ACTIVATED_HALT,
65 CAM_ISP_CTX_ACTIVATED_MAX,
66};
67
Vishalsingh Hajeric0cab062017-09-28 18:25:16 -070068/**
69 * enum cam_isp_state_change_trigger - Different types of ISP events
70 *
71 */
72enum cam_isp_state_change_trigger {
73 CAM_ISP_STATE_CHANGE_TRIGGER_ERROR,
74 CAM_ISP_STATE_CHANGE_TRIGGER_SOF,
75 CAM_ISP_STATE_CHANGE_TRIGGER_REG_UPDATE,
76 CAM_ISP_STATE_CHANGE_TRIGGER_EPOCH,
77 CAM_ISP_STATE_CHANGE_TRIGGER_EOF,
78 CAM_ISP_STATE_CHANGE_TRIGGER_DONE,
79 CAM_ISP_STATE_CHANGE_TRIGGER_MAX
80};
Jing Zhoud352ed12017-03-20 23:59:56 -070081
82/**
83 * struct cam_isp_ctx_irq_ops - Function table for handling IRQ callbacks
84 *
85 * @irq_ops: Array of handle function pointers.
86 *
87 */
88struct cam_isp_ctx_irq_ops {
89 cam_isp_hw_event_cb_func irq_ops[CAM_ISP_HW_EVENT_MAX];
90};
91
92/**
93 * struct cam_isp_ctx_req - ISP context request object
94 *
95 * @base: Common request object ponter
96 * @cfg: ISP hardware configuration array
97 * @num_cfg: Number of ISP hardware configuration entries
98 * @fence_map_out: Output fence mapping array
99 * @num_fence_map_out: Number of the output fence map
100 * @fence_map_in: Input fence mapping array
101 * @num_fence_map_in: Number of input fence map
102 * @num_acked: Count to track acked entried for output.
103 * If count equals the number of fence out, it means
104 * the request has been completed.
105 * @bubble_report: Flag to track if bubble report is active on
106 * current request
Vishalsingh Hajerie5450be2018-01-18 20:31:19 -0800107 * @hw_update_data: HW update data for this request
Jing Zhoud352ed12017-03-20 23:59:56 -0700108 *
109 */
110struct cam_isp_ctx_req {
Vishalsingh Hajerie5450be2018-01-18 20:31:19 -0800111 struct cam_ctx_request *base;
Jing Zhoud352ed12017-03-20 23:59:56 -0700112
Vishalsingh Hajerie5450be2018-01-18 20:31:19 -0800113 struct cam_hw_update_entry cfg[CAM_ISP_CTX_CFG_MAX];
114 uint32_t num_cfg;
115 struct cam_hw_fence_map_entry fence_map_out
116 [CAM_ISP_CTX_RES_MAX];
117 uint32_t num_fence_map_out;
118 struct cam_hw_fence_map_entry fence_map_in[CAM_ISP_CTX_RES_MAX];
119 uint32_t num_fence_map_in;
120 uint32_t num_acked;
121 int32_t bubble_report;
122 struct cam_isp_prepare_hw_update_data hw_update_data;
Junzhe Zou09820a72018-09-06 18:11:41 -0700123 bool bubble_detected;
Jing Zhoud352ed12017-03-20 23:59:56 -0700124};
125
126/**
Vishalsingh Hajeric0cab062017-09-28 18:25:16 -0700127 * struct cam_isp_context_state_monitor - ISP context state
128 * monitoring for
129 * debug purposes
Jing Zhoud352ed12017-03-20 23:59:56 -0700130 *
Vishalsingh Hajeric0cab062017-09-28 18:25:16 -0700131 *@curr_state: Current sub state that received req
132 *@req_type: Event type of incoming req
133 *@req_id: Request id
134 *@evt_time_stamp Current time stamp
135 *
136 */
137struct cam_isp_context_state_monitor {
138 enum cam_isp_ctx_activated_substate curr_state;
139 enum cam_isp_state_change_trigger trigger;
140 uint32_t req_id;
141 int64_t frame_id;
142 uint64_t evt_time_stamp;
143};
144
145/**
146 * struct cam_isp_context - ISP context object
147 *
148 * @base: Common context object pointer
149 * @frame_id: Frame id tracking for the isp context
150 * @substate_actiavted: Current substate for the activated state.
Ayush Kumarf13969a92019-07-18 13:02:43 +0530151 * @process_bubble: Atomic variable to check if ctx is still
152 * processing bubble
Vishalsingh Hajeric0cab062017-09-28 18:25:16 -0700153 * @substate_machine: ISP substate machine for external interface
154 * @substate_machine_irq: ISP substate machine for irq handling
155 * @req_base: Common request object storage
156 * @req_isp: ISP private request object storage
157 * @hw_ctx: HW object returned by the acquire device command
158 * @sof_timestamp_val: Captured time stamp value at sof hw event
Karthik Anantha Ramc93754c2018-03-28 14:21:14 -0700159 * @boot_timestamp: Boot time stamp for a given req_id
Vishalsingh Hajeric0cab062017-09-28 18:25:16 -0700160 * @active_req_cnt: Counter for the active request
161 * @reported_req_id: Last reported request id
162 * @subscribe_event: The irq event mask that CRM subscribes to, IFE
163 * will invoke CRM cb at those event.
164 * @last_applied_req_id: Last applied request id
Vishalsingh Hajeric0cab062017-09-28 18:25:16 -0700165 * @state_monitor_head: Write index to the state monitoring array
166 * @cam_isp_ctx_state_monitor: State monitoring array
Lynus Vazcbda4b02018-03-26 15:48:01 +0530167 * @rdi_only_context: Get context type information.
168 * true, if context is rdi only context
Shravya Samala43583ea2020-04-29 14:25:37 +0530169 * @bubble_sof_count: Atomic variable to check if ctx has any sof's
170 * while processing bubble
Junzhe Zou2df84502017-05-26 13:20:23 -0700171 *
Jing Zhoud352ed12017-03-20 23:59:56 -0700172 */
173struct cam_isp_context {
174 struct cam_context *base;
175
176 int64_t frame_id;
177 uint32_t substate_activated;
Ayush Kumarf13969a92019-07-18 13:02:43 +0530178 atomic_t process_bubble;
Jing Zhoud352ed12017-03-20 23:59:56 -0700179 struct cam_ctx_ops *substate_machine;
180 struct cam_isp_ctx_irq_ops *substate_machine_irq;
181
182 struct cam_ctx_request req_base[CAM_CTX_REQ_MAX];
183 struct cam_isp_ctx_req req_isp[CAM_CTX_REQ_MAX];
184
185 void *hw_ctx;
Jing Zhoudedc4762017-06-19 17:45:36 +0530186 uint64_t sof_timestamp_val;
Karthik Anantha Ramc93754c2018-03-28 14:21:14 -0700187 uint64_t boot_timestamp;
Jing Zhoudedc4762017-06-19 17:45:36 +0530188 int32_t active_req_cnt;
189 int64_t reported_req_id;
Junzhe Zou2df84502017-05-26 13:20:23 -0700190 uint32_t subscribe_event;
Alok Pandeyfdfa5ba2017-09-22 14:21:25 +0530191 int64_t last_applied_req_id;
Vishalsingh Hajeric0cab062017-09-28 18:25:16 -0700192 atomic64_t state_monitor_head;
193 struct cam_isp_context_state_monitor cam_isp_ctx_state_monitor[
194 CAM_ISP_CTX_STATE_MONITOR_MAX_ENTRIES];
Lynus Vazcbda4b02018-03-26 15:48:01 +0530195 bool rdi_only_context;
Shravya Samala43583ea2020-04-29 14:25:37 +0530196 atomic_t bubble_sof_count;
Jing Zhoud352ed12017-03-20 23:59:56 -0700197};
198
199/**
200 * cam_isp_context_init()
201 *
202 * @brief: Initialization function for the ISP context
203 *
204 * @ctx: ISP context obj to be initialized
205 * @bridge_ops: Bridge call back funciton
206 * @hw_intf: ISP hw manager interface
Pavan Kumar Chilamkurthi96fd3c92018-01-25 14:16:57 -0800207 * @ctx_id: ID for this context
Jing Zhoud352ed12017-03-20 23:59:56 -0700208 *
209 */
210int cam_isp_context_init(struct cam_isp_context *ctx,
211 struct cam_context *ctx_base,
212 struct cam_req_mgr_kmd_ops *bridge_ops,
Pavan Kumar Chilamkurthi96fd3c92018-01-25 14:16:57 -0800213 struct cam_hw_mgr_intf *hw_intf,
214 uint32_t ctx_id);
Jing Zhoud352ed12017-03-20 23:59:56 -0700215
216/**
217 * cam_isp_context_deinit()
218 *
219 * @brief: Deinitialize function for the ISP context
220 *
221 * @ctx: ISP context obj to be deinitialized
222 *
223 */
224int cam_isp_context_deinit(struct cam_isp_context *ctx);
225
226
227#endif /* __CAM_ISP_CONTEXT_H__ */