blob: aac4a5eeca3c38caba7b76236a1f2c07eaa8e0e9 [file] [log] [blame]
Suresh Vankadarac092e592018-01-11 18:52:41 +05301/* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -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_ICP_HW_MGR_H
14#define CAM_ICP_HW_MGR_H
15
16#include <linux/types.h>
17#include <linux/completion.h>
18#include <media/cam_icp.h>
19#include "cam_icp_hw_intf.h"
20#include "cam_hw_mgr_intf.h"
21#include "cam_hw_intf.h"
22#include "cam_a5_hw_intf.h"
23#include "hfi_session_defs.h"
24#include "cam_req_mgr_workq.h"
25#include "cam_mem_mgr.h"
Lakshmi Narayana Kalavala2743a0d2017-05-30 10:41:37 -070026#include "cam_smmu_api.h"
Suresh Vankadara34494fc2017-08-12 18:18:09 +053027#include "cam_soc_util.h"
Junzhe Zoubc37c562017-11-20 18:23:49 -080028#include "cam_req_mgr_timer.h"
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -070029
30#define CAM_ICP_ROLE_PARENT 1
31#define CAM_ICP_ROLE_CHILD 2
32
33#define CAM_FRAME_CMD_MAX 20
34
35#define CAM_MAX_OUT_RES 6
Sagar Goref13f75c2017-11-02 17:50:15 -070036#define CAM_MAX_IN_RES 8
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -070037
Suresh Vankadara38f7a652017-09-25 20:58:41 +053038#define ICP_WORKQ_NUM_TASK 100
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -070039#define ICP_WORKQ_TASK_CMD_TYPE 1
40#define ICP_WORKQ_TASK_MSG_TYPE 2
41
42#define ICP_PACKET_SIZE 0
43#define ICP_PACKET_TYPE 1
Suresh Vankadara8e06cfb2017-06-13 16:27:08 +053044#define ICP_PACKET_OPCODE 2
Suresh Vankadaraadcf0582017-05-24 09:53:36 +053045#define ICP_MAX_OUTPUT_SUPPORTED 6
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -070046
Suresh Vankadara22697d32017-07-03 12:14:09 -070047#define ICP_FRAME_PROCESS_SUCCESS 0
48#define ICP_FRAME_PROCESS_FAILURE 1
Lakshmi Narayana Kalavaladac0b6c2017-09-13 15:33:42 -070049#define ICP_MSG_BUF_SIZE 256
50#define ICP_DBG_BUF_SIZE 102400
Suresh Vankadara22697d32017-07-03 12:14:09 -070051
Suresh Vankadara34494fc2017-08-12 18:18:09 +053052#define ICP_CLK_HW_IPE 0x0
53#define ICP_CLK_HW_BPS 0x1
54#define ICP_CLK_HW_MAX 0x2
55
56#define ICP_OVER_CLK_THRESHOLD 15
57
Suresh Vankadaraaa6ff8f2017-10-26 22:51:27 +053058#define CPAS_IPE0_BIT 0x1000
59#define CPAS_IPE1_BIT 0x2000
60#define CPAS_BPS_BIT 0x400
61
Alok Pandey78093d32017-11-08 18:56:54 +053062#define ICP_PWR_CLP_BPS 0x00000001
63#define ICP_PWR_CLP_IPE0 0x00010000
64#define ICP_PWR_CLP_IPE1 0x00020000
65
Suresh Vankadarac7b0c672017-11-25 00:44:10 +053066#define CAM_ICP_CTX_STATE_FREE 0x0
67#define CAM_ICP_CTX_STATE_IN_USE 0x1
68#define CAM_ICP_CTX_STATE_ACQUIRED 0x2
69#define CAM_ICP_CTX_STATE_RELEASE 0x3
70
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -070071/**
72 * struct icp_hfi_mem_info
73 * @qtbl: Memory info of queue table
74 * @cmd_q: Memory info of command queue
75 * @msg_q: Memory info of message queue
76 * @dbg_q: Memory info of debug queue
77 * @sec_heap: Memory info of secondary heap
78 * @fw_buf: Memory info of firmware
79 */
80struct icp_hfi_mem_info {
81 struct cam_mem_mgr_memory_desc qtbl;
82 struct cam_mem_mgr_memory_desc cmd_q;
83 struct cam_mem_mgr_memory_desc msg_q;
84 struct cam_mem_mgr_memory_desc dbg_q;
85 struct cam_mem_mgr_memory_desc sec_heap;
86 struct cam_mem_mgr_memory_desc fw_buf;
Lakshmi Narayana Kalavala2743a0d2017-05-30 10:41:37 -070087 struct cam_smmu_region_info shmem;
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -070088};
89
90/**
91 * struct hfi_cmd_work_data
92 * @type: Task type
93 * @data: Pointer to command data
94 * @request_id: Request id
95 */
96struct hfi_cmd_work_data {
97 uint32_t type;
98 void *data;
99 int32_t request_id;
100};
101
102/**
103 * struct hfi_msg_work_data
104 * @type: Task type
105 * @data: Pointer to message data
106 * @irq_status: IRQ status
107 */
108struct hfi_msg_work_data {
109 uint32_t type;
110 void *data;
111 uint32_t irq_status;
112};
113
114/**
Junzhe Zoubc37c562017-11-20 18:23:49 -0800115 * struct clk_work_data
116 * @type: Task type
117 * @data: Pointer to clock info
118 */
119struct clk_work_data {
120 uint32_t type;
121 void *data;
122};
123
124/**
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -0700125 * struct hfi_frame_process_info
126 * @hfi_frame_cmd: Frame process command info
127 * @bitmap: Bitmap for hfi_frame_cmd
128 * @bits: Used in hfi_frame_cmd bitmap
129 * @lock: Lock for hfi_frame_cmd
130 * @request_id: Request id list
131 * @num_out_resources: Number of out syncs
132 * @out_resource: Out sync info
Suresh Vankadara34494fc2017-08-12 18:18:09 +0530133 * @fw_process_flag: Frame process flag
134 * @clk_info: Clock information for a request
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -0700135 */
136struct hfi_frame_process_info {
137 struct hfi_cmd_ipebps_async hfi_frame_cmd[CAM_FRAME_CMD_MAX];
138 void *bitmap;
139 size_t bits;
140 struct mutex lock;
Sagar Gorecdd6a5e2017-05-17 19:06:59 -0700141 uint64_t request_id[CAM_FRAME_CMD_MAX];
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -0700142 uint32_t num_out_resources[CAM_FRAME_CMD_MAX];
143 uint32_t out_resource[CAM_FRAME_CMD_MAX][CAM_MAX_OUT_RES];
Suresh Vankadaraad2d3a92017-09-25 12:18:11 +0530144 uint32_t in_resource[CAM_FRAME_CMD_MAX];
Junzhe Zou4b11e7a2017-11-13 17:21:32 -0800145 uint32_t in_free_resource[CAM_FRAME_CMD_MAX];
Suresh Vankadara34494fc2017-08-12 18:18:09 +0530146 uint32_t fw_process_flag[CAM_FRAME_CMD_MAX];
147 struct cam_icp_clk_bw_request clk_info[CAM_FRAME_CMD_MAX];
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -0700148};
149
150/**
Suresh Vankadara34494fc2017-08-12 18:18:09 +0530151 * struct cam_ctx_clk_info
152 * @curr_fc: Context latest request frame cycles
153 * @rt_flag: Flag to indicate real time request
154 * @base_clk: Base clock to process the request
Suresh Vankadara38f7a652017-09-25 20:58:41 +0530155 * @reserved: Reserved field
Suresh Vankadara34494fc2017-08-12 18:18:09 +0530156 * #uncompressed_bw: Current bandwidth voting
157 * @compressed_bw: Current compressed bandwidth voting
158 * @clk_rate: Supported clock rates for the context
159 */
160struct cam_ctx_clk_info {
161 uint32_t curr_fc;
162 uint32_t rt_flag;
163 uint32_t base_clk;
Suresh Vankadara38f7a652017-09-25 20:58:41 +0530164 uint32_t reserved;
165 uint64_t uncompressed_bw;
166 uint64_t compressed_bw;
Suresh Vankadara34494fc2017-08-12 18:18:09 +0530167 int32_t clk_rate[CAM_MAX_VOTE];
168};
169/**
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -0700170 * struct cam_icp_hw_ctx_data
171 * @context_priv: Context private data
172 * @ctx_mutex: Mutex for context
173 * @fw_handle: Firmware handle
174 * @scratch_mem_size: Scratch memory size
175 * @acquire_dev_cmd: Acquire command
176 * @icp_dev_acquire_info: Acquire device info
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -0700177 * @ctxt_event_cb: Context callback function
Suresh Vankadarac7b0c672017-11-25 00:44:10 +0530178 * @state: context state
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -0700179 * @role: Role of a context in case of chaining
180 * @chain_ctx: Peer context
181 * @hfi_frame_process: Frame process command
182 * @wait_complete: Completion info
183 * @temp_payload: Payload for destroy handle data
Suresh Vankadara34494fc2017-08-12 18:18:09 +0530184 * @ctx_id: Context Id
185 * @clk_info: Current clock info of a context
Suresh Vankadarac092e592018-01-11 18:52:41 +0530186 * @watch_dog: watchdog timer handle
187 * @watch_dog_reset_counter: Counter for watch dog reset
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -0700188 */
189struct cam_icp_hw_ctx_data {
190 void *context_priv;
191 struct mutex ctx_mutex;
192 uint32_t fw_handle;
193 uint32_t scratch_mem_size;
194 struct cam_acquire_dev_cmd acquire_dev_cmd;
Suresh Vankadaraadcf0582017-05-24 09:53:36 +0530195 struct cam_icp_acquire_dev_info *icp_dev_acquire_info;
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -0700196 cam_hw_event_cb_func ctxt_event_cb;
Suresh Vankadarac7b0c672017-11-25 00:44:10 +0530197 uint32_t state;
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -0700198 uint32_t role;
199 struct cam_icp_hw_ctx_data *chain_ctx;
200 struct hfi_frame_process_info hfi_frame_process;
201 struct completion wait_complete;
202 struct ipe_bps_destroy temp_payload;
Suresh Vankadara5a1ae562017-06-03 12:59:15 +0530203 uint32_t ctx_id;
Suresh Vankadara34494fc2017-08-12 18:18:09 +0530204 struct cam_ctx_clk_info clk_info;
Suresh Vankadarac092e592018-01-11 18:52:41 +0530205 struct cam_req_mgr_timer *watch_dog;
206 uint32_t watch_dog_reset_counter;
Suresh Vankadara34494fc2017-08-12 18:18:09 +0530207};
208
209/**
210 * struct icp_cmd_generic_blob
211 * @ctx: Current context info
212 * @frame_info_idx: Index used for frame process info
213 */
214struct icp_cmd_generic_blob {
215 struct cam_icp_hw_ctx_data *ctx;
216 uint32_t frame_info_idx;
217};
218
219/**
220 * struct cam_icp_clk_info
221 * @base_clk: Base clock to process request
222 * @curr_clk: Current clock of hadrware
223 * @threshold: Threshold for overclk count
224 * @over_clked: Over clock count
Junzhe Zoubc37c562017-11-20 18:23:49 -0800225 * @uncompressed_bw: Current bandwidth voting
Suresh Vankadara34494fc2017-08-12 18:18:09 +0530226 * @compressed_bw: Current compressed bandwidth voting
Junzhe Zoubc37c562017-11-20 18:23:49 -0800227 * @hw_type: IPE/BPS device type
228 * @watch_dog: watchdog timer handle
Suresh Vankadarac092e592018-01-11 18:52:41 +0530229 * @watch_dog_reset_counter: Counter for watch dog reset
Suresh Vankadara34494fc2017-08-12 18:18:09 +0530230 */
231struct cam_icp_clk_info {
232 uint32_t base_clk;
233 uint32_t curr_clk;
234 uint32_t threshold;
235 uint32_t over_clked;
Suresh Vankadara38f7a652017-09-25 20:58:41 +0530236 uint64_t uncompressed_bw;
237 uint64_t compressed_bw;
Junzhe Zoubc37c562017-11-20 18:23:49 -0800238 uint32_t hw_type;
239 struct cam_req_mgr_timer *watch_dog;
Suresh Vankadarac092e592018-01-11 18:52:41 +0530240 uint32_t watch_dog_reset_counter;
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -0700241};
242
243/**
244 * struct cam_icp_hw_mgr
245 * @hw_mgr_mutex: Mutex for ICP hardware manager
246 * @hw_mgr_lock: Spinlock for ICP hardware manager
247 * @devices: Devices of ICP hardware manager
248 * @ctx_data: Context data
249 * @icp_caps: ICP capabilities
250 * @fw_download: Firmware download state
251 * @iommu_hdl: Non secure IOMMU handle
252 * @iommu_sec_hdl: Secure IOMMU handle
253 * @hfi_mem: Memory for hfi
254 * @cmd_work: Work queue for hfi commands
255 * @msg_work: Work queue for hfi messages
256 * @msg_buf: Buffer for message data from firmware
257 * @dbg_buf: Buffer for debug data from firmware
258 * @a5_complete: Completion info
259 * @cmd_work_data: Pointer to command work queue task
260 * @msg_work_data: Pointer to message work queue task
261 * @ctxt_cnt: Active context count
Suresh Vankadara6657bc22017-07-31 10:33:04 +0530262 * @ipe_ctxt_cnt: IPE Active context count
263 * @bps_ctxt_cnt: BPS Active context count
264 * @dentry: Debugfs entry
265 * @a5_debug: A5 debug flag
266 * @icp_pc_flag: Flag to enable/disable power collapse
Alok Pandey1aef7b52017-12-16 20:42:03 +0530267 * @ipe_bps_pc_flag: Flag to enable/disable
268 * power collapse for ipe & bps
Suresh Vankadara34494fc2017-08-12 18:18:09 +0530269 * @icp_debug_clk: Set clock based on debug value
270 * @icp_default_clk: Set this clok if user doesn't supply
271 * @clk_info: Clock info of hardware
Lakshmi Narayana Kalavala2c714282017-09-08 12:27:36 -0700272 * @secure_mode: Flag to enable/disable secure camera
Lakshmi Narayana Kalavaladac0b6c2017-09-13 15:33:42 -0700273 * @a5_jtag_debug: entry to enable A5 JTAG debugging
274 * @a5_debug_q : entry to enable FW debug message
275 * @a5_dbg_lvl : debug level set to FW.
Suresh Vankadaraaa6ff8f2017-10-26 22:51:27 +0530276 * @ipe0_enable: Flag for IPE0
277 * @ipe1_enable: Flag for IPE1
278 * @bps_enable: Flag for BPS
Suresh Vankadara466bed22017-11-30 06:30:20 +0530279 * @core_info: 32 bit value , tells IPE0/1 and BPS
Vishalsingh Hajeri71fc3c52018-01-15 20:28:29 -0800280 * @a5_dev_intf : Device interface for A5
281 * @ipe0_dev_intf: Device interface for IPE0
282 * @ipe1_dev_intf: Device interface for IPE1
283 * @bps_dev_intf: Device interface for BPS
284 * @ipe_clk_state: IPE clock state flag
285 * @bps_clk_state: BPS clock state flag
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -0700286 */
287struct cam_icp_hw_mgr {
288 struct mutex hw_mgr_mutex;
289 spinlock_t hw_mgr_lock;
290
291 struct cam_hw_intf **devices[CAM_ICP_DEV_MAX];
292 struct cam_icp_hw_ctx_data ctx_data[CAM_ICP_CTX_MAX];
293 struct cam_icp_query_cap_cmd icp_caps;
294
295 bool fw_download;
296 int32_t iommu_hdl;
297 int32_t iommu_sec_hdl;
298 struct icp_hfi_mem_info hfi_mem;
299 struct cam_req_mgr_core_workq *cmd_work;
300 struct cam_req_mgr_core_workq *msg_work;
Lakshmi Narayana Kalavaladac0b6c2017-09-13 15:33:42 -0700301 uint32_t msg_buf[ICP_MSG_BUF_SIZE];
302 uint32_t dbg_buf[ICP_DBG_BUF_SIZE];
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -0700303 struct completion a5_complete;
304 struct hfi_cmd_work_data *cmd_work_data;
305 struct hfi_msg_work_data *msg_work_data;
306 uint32_t ctxt_cnt;
Suresh Vankadara6657bc22017-07-31 10:33:04 +0530307 uint32_t ipe_ctxt_cnt;
308 uint32_t bps_ctxt_cnt;
Lakshmi Narayana Kalavala2743a0d2017-05-30 10:41:37 -0700309 struct dentry *dentry;
310 bool a5_debug;
Suresh Vankadara6657bc22017-07-31 10:33:04 +0530311 bool icp_pc_flag;
Alok Pandey1aef7b52017-12-16 20:42:03 +0530312 bool ipe_bps_pc_flag;
Suresh Vankadara34494fc2017-08-12 18:18:09 +0530313 uint64_t icp_debug_clk;
314 uint64_t icp_default_clk;
315 struct cam_icp_clk_info clk_info[ICP_CLK_HW_MAX];
Lakshmi Narayana Kalavala2c714282017-09-08 12:27:36 -0700316 bool secure_mode;
Lakshmi Narayana Kalavaladac0b6c2017-09-13 15:33:42 -0700317 bool a5_jtag_debug;
318 bool a5_debug_q;
319 u64 a5_dbg_lvl;
Suresh Vankadaraaa6ff8f2017-10-26 22:51:27 +0530320 bool ipe0_enable;
321 bool ipe1_enable;
322 bool bps_enable;
Suresh Vankadara466bed22017-11-30 06:30:20 +0530323 uint32_t core_info;
Karthik Anantha Ram9f13d0e2017-11-30 14:55:44 -0800324 struct cam_hw_intf *a5_dev_intf;
325 struct cam_hw_intf *ipe0_dev_intf;
326 struct cam_hw_intf *ipe1_dev_intf;
327 struct cam_hw_intf *bps_dev_intf;
Vishalsingh Hajeri71fc3c52018-01-15 20:28:29 -0800328 bool ipe_clk_state;
329 bool bps_clk_state;
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -0700330};
331
Suresh Vankadara5499a5f2017-06-16 22:13:56 +0530332static int cam_icp_mgr_hw_close(void *hw_priv, void *hw_close_args);
Harsh Shah6baba8c2017-10-16 19:23:29 -0700333static int cam_icp_mgr_hw_open(void *hw_mgr_priv, void *download_fw_args);
Suresh Vankadara466bed22017-11-30 06:30:20 +0530334static int cam_icp_mgr_icp_resume(struct cam_icp_hw_mgr *hw_mgr);
335static int cam_icp_mgr_icp_power_collapse(struct cam_icp_hw_mgr *hw_mgr);
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -0700336#endif /* CAM_ICP_HW_MGR_H */