blob: 8c0961fc50d306760ffe3243fd38912c2e7ae836 [file] [log] [blame]
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -07001/* Copyright (c) 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_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"
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -070028
29#define CAM_ICP_ROLE_PARENT 1
30#define CAM_ICP_ROLE_CHILD 2
31
32#define CAM_FRAME_CMD_MAX 20
33
34#define CAM_MAX_OUT_RES 6
Sagar Goref13f75c2017-11-02 17:50:15 -070035#define CAM_MAX_IN_RES 8
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -070036
Suresh Vankadara38f7a652017-09-25 20:58:41 +053037#define ICP_WORKQ_NUM_TASK 100
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -070038#define ICP_WORKQ_TASK_CMD_TYPE 1
39#define ICP_WORKQ_TASK_MSG_TYPE 2
40
41#define ICP_PACKET_SIZE 0
42#define ICP_PACKET_TYPE 1
Suresh Vankadara8e06cfb2017-06-13 16:27:08 +053043#define ICP_PACKET_OPCODE 2
Suresh Vankadaraadcf0582017-05-24 09:53:36 +053044#define ICP_MAX_OUTPUT_SUPPORTED 6
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -070045
Suresh Vankadara22697d32017-07-03 12:14:09 -070046#define ICP_FRAME_PROCESS_SUCCESS 0
47#define ICP_FRAME_PROCESS_FAILURE 1
Lakshmi Narayana Kalavaladac0b6c2017-09-13 15:33:42 -070048#define ICP_MSG_BUF_SIZE 256
49#define ICP_DBG_BUF_SIZE 102400
Suresh Vankadara22697d32017-07-03 12:14:09 -070050
Suresh Vankadara34494fc2017-08-12 18:18:09 +053051#define ICP_CLK_HW_IPE 0x0
52#define ICP_CLK_HW_BPS 0x1
53#define ICP_CLK_HW_MAX 0x2
54
55#define ICP_OVER_CLK_THRESHOLD 15
56
Suresh Vankadaraaa6ff8f2017-10-26 22:51:27 +053057#define CPAS_IPE0_BIT 0x1000
58#define CPAS_IPE1_BIT 0x2000
59#define CPAS_BPS_BIT 0x400
60
Alok Pandey78093d32017-11-08 18:56:54 +053061#define ICP_PWR_CLP_BPS 0x00000001
62#define ICP_PWR_CLP_IPE0 0x00010000
63#define ICP_PWR_CLP_IPE1 0x00020000
64
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -070065/**
66 * struct icp_hfi_mem_info
67 * @qtbl: Memory info of queue table
68 * @cmd_q: Memory info of command queue
69 * @msg_q: Memory info of message queue
70 * @dbg_q: Memory info of debug queue
71 * @sec_heap: Memory info of secondary heap
72 * @fw_buf: Memory info of firmware
73 */
74struct icp_hfi_mem_info {
75 struct cam_mem_mgr_memory_desc qtbl;
76 struct cam_mem_mgr_memory_desc cmd_q;
77 struct cam_mem_mgr_memory_desc msg_q;
78 struct cam_mem_mgr_memory_desc dbg_q;
79 struct cam_mem_mgr_memory_desc sec_heap;
80 struct cam_mem_mgr_memory_desc fw_buf;
Lakshmi Narayana Kalavala2743a0d2017-05-30 10:41:37 -070081 struct cam_smmu_region_info shmem;
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -070082};
83
84/**
85 * struct hfi_cmd_work_data
86 * @type: Task type
87 * @data: Pointer to command data
88 * @request_id: Request id
89 */
90struct hfi_cmd_work_data {
91 uint32_t type;
92 void *data;
93 int32_t request_id;
94};
95
96/**
97 * struct hfi_msg_work_data
98 * @type: Task type
99 * @data: Pointer to message data
100 * @irq_status: IRQ status
101 */
102struct hfi_msg_work_data {
103 uint32_t type;
104 void *data;
105 uint32_t irq_status;
106};
107
108/**
109 * struct hfi_frame_process_info
110 * @hfi_frame_cmd: Frame process command info
111 * @bitmap: Bitmap for hfi_frame_cmd
112 * @bits: Used in hfi_frame_cmd bitmap
113 * @lock: Lock for hfi_frame_cmd
114 * @request_id: Request id list
115 * @num_out_resources: Number of out syncs
116 * @out_resource: Out sync info
Suresh Vankadara34494fc2017-08-12 18:18:09 +0530117 * @fw_process_flag: Frame process flag
118 * @clk_info: Clock information for a request
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -0700119 */
120struct hfi_frame_process_info {
121 struct hfi_cmd_ipebps_async hfi_frame_cmd[CAM_FRAME_CMD_MAX];
122 void *bitmap;
123 size_t bits;
124 struct mutex lock;
Sagar Gorecdd6a5e2017-05-17 19:06:59 -0700125 uint64_t request_id[CAM_FRAME_CMD_MAX];
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -0700126 uint32_t num_out_resources[CAM_FRAME_CMD_MAX];
127 uint32_t out_resource[CAM_FRAME_CMD_MAX][CAM_MAX_OUT_RES];
Suresh Vankadaraad2d3a92017-09-25 12:18:11 +0530128 uint32_t in_resource[CAM_FRAME_CMD_MAX];
Suresh Vankadara34494fc2017-08-12 18:18:09 +0530129 uint32_t fw_process_flag[CAM_FRAME_CMD_MAX];
130 struct cam_icp_clk_bw_request clk_info[CAM_FRAME_CMD_MAX];
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -0700131};
132
133/**
Suresh Vankadara34494fc2017-08-12 18:18:09 +0530134 * struct cam_ctx_clk_info
135 * @curr_fc: Context latest request frame cycles
136 * @rt_flag: Flag to indicate real time request
137 * @base_clk: Base clock to process the request
Suresh Vankadara38f7a652017-09-25 20:58:41 +0530138 * @reserved: Reserved field
Suresh Vankadara34494fc2017-08-12 18:18:09 +0530139 * #uncompressed_bw: Current bandwidth voting
140 * @compressed_bw: Current compressed bandwidth voting
141 * @clk_rate: Supported clock rates for the context
142 */
143struct cam_ctx_clk_info {
144 uint32_t curr_fc;
145 uint32_t rt_flag;
146 uint32_t base_clk;
Suresh Vankadara38f7a652017-09-25 20:58:41 +0530147 uint32_t reserved;
148 uint64_t uncompressed_bw;
149 uint64_t compressed_bw;
Suresh Vankadara34494fc2017-08-12 18:18:09 +0530150 int32_t clk_rate[CAM_MAX_VOTE];
151};
152/**
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -0700153 * struct cam_icp_hw_ctx_data
154 * @context_priv: Context private data
155 * @ctx_mutex: Mutex for context
156 * @fw_handle: Firmware handle
157 * @scratch_mem_size: Scratch memory size
158 * @acquire_dev_cmd: Acquire command
159 * @icp_dev_acquire_info: Acquire device info
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -0700160 * @ctxt_event_cb: Context callback function
161 * @in_use: Flag for context usage
162 * @role: Role of a context in case of chaining
163 * @chain_ctx: Peer context
164 * @hfi_frame_process: Frame process command
165 * @wait_complete: Completion info
166 * @temp_payload: Payload for destroy handle data
Suresh Vankadara34494fc2017-08-12 18:18:09 +0530167 * @ctx_id: Context Id
168 * @clk_info: Current clock info of a context
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -0700169 */
170struct cam_icp_hw_ctx_data {
171 void *context_priv;
172 struct mutex ctx_mutex;
173 uint32_t fw_handle;
174 uint32_t scratch_mem_size;
175 struct cam_acquire_dev_cmd acquire_dev_cmd;
Suresh Vankadaraadcf0582017-05-24 09:53:36 +0530176 struct cam_icp_acquire_dev_info *icp_dev_acquire_info;
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -0700177 cam_hw_event_cb_func ctxt_event_cb;
Suresh Vankadaraadcf0582017-05-24 09:53:36 +0530178 bool in_use;
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -0700179 uint32_t role;
180 struct cam_icp_hw_ctx_data *chain_ctx;
181 struct hfi_frame_process_info hfi_frame_process;
182 struct completion wait_complete;
183 struct ipe_bps_destroy temp_payload;
Suresh Vankadara5a1ae562017-06-03 12:59:15 +0530184 uint32_t ctx_id;
Suresh Vankadara34494fc2017-08-12 18:18:09 +0530185 struct cam_ctx_clk_info clk_info;
186};
187
188/**
189 * struct icp_cmd_generic_blob
190 * @ctx: Current context info
191 * @frame_info_idx: Index used for frame process info
192 */
193struct icp_cmd_generic_blob {
194 struct cam_icp_hw_ctx_data *ctx;
195 uint32_t frame_info_idx;
196};
197
198/**
199 * struct cam_icp_clk_info
200 * @base_clk: Base clock to process request
201 * @curr_clk: Current clock of hadrware
202 * @threshold: Threshold for overclk count
203 * @over_clked: Over clock count
204 * #uncompressed_bw: Current bandwidth voting
205 * @compressed_bw: Current compressed bandwidth voting
206 */
207struct cam_icp_clk_info {
208 uint32_t base_clk;
209 uint32_t curr_clk;
210 uint32_t threshold;
211 uint32_t over_clked;
Suresh Vankadara38f7a652017-09-25 20:58:41 +0530212 uint64_t uncompressed_bw;
213 uint64_t compressed_bw;
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -0700214};
215
216/**
217 * struct cam_icp_hw_mgr
218 * @hw_mgr_mutex: Mutex for ICP hardware manager
219 * @hw_mgr_lock: Spinlock for ICP hardware manager
220 * @devices: Devices of ICP hardware manager
221 * @ctx_data: Context data
222 * @icp_caps: ICP capabilities
223 * @fw_download: Firmware download state
224 * @iommu_hdl: Non secure IOMMU handle
225 * @iommu_sec_hdl: Secure IOMMU handle
226 * @hfi_mem: Memory for hfi
227 * @cmd_work: Work queue for hfi commands
228 * @msg_work: Work queue for hfi messages
229 * @msg_buf: Buffer for message data from firmware
230 * @dbg_buf: Buffer for debug data from firmware
231 * @a5_complete: Completion info
232 * @cmd_work_data: Pointer to command work queue task
233 * @msg_work_data: Pointer to message work queue task
234 * @ctxt_cnt: Active context count
Suresh Vankadara6657bc22017-07-31 10:33:04 +0530235 * @ipe_ctxt_cnt: IPE Active context count
236 * @bps_ctxt_cnt: BPS Active context count
237 * @dentry: Debugfs entry
238 * @a5_debug: A5 debug flag
239 * @icp_pc_flag: Flag to enable/disable power collapse
Suresh Vankadara34494fc2017-08-12 18:18:09 +0530240 * @icp_debug_clk: Set clock based on debug value
241 * @icp_default_clk: Set this clok if user doesn't supply
242 * @clk_info: Clock info of hardware
Lakshmi Narayana Kalavala2c714282017-09-08 12:27:36 -0700243 * @secure_mode: Flag to enable/disable secure camera
Lakshmi Narayana Kalavaladac0b6c2017-09-13 15:33:42 -0700244 * @a5_jtag_debug: entry to enable A5 JTAG debugging
245 * @a5_debug_q : entry to enable FW debug message
246 * @a5_dbg_lvl : debug level set to FW.
Suresh Vankadaraaa6ff8f2017-10-26 22:51:27 +0530247 * @ipe0_enable: Flag for IPE0
248 * @ipe1_enable: Flag for IPE1
249 * @bps_enable: Flag for BPS
Alok Pandey78093d32017-11-08 18:56:54 +0530250 * @core_info: 32 bit value , tells IPE0/1 and BPS
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -0700251 */
252struct cam_icp_hw_mgr {
253 struct mutex hw_mgr_mutex;
254 spinlock_t hw_mgr_lock;
255
256 struct cam_hw_intf **devices[CAM_ICP_DEV_MAX];
257 struct cam_icp_hw_ctx_data ctx_data[CAM_ICP_CTX_MAX];
258 struct cam_icp_query_cap_cmd icp_caps;
259
260 bool fw_download;
261 int32_t iommu_hdl;
262 int32_t iommu_sec_hdl;
263 struct icp_hfi_mem_info hfi_mem;
264 struct cam_req_mgr_core_workq *cmd_work;
265 struct cam_req_mgr_core_workq *msg_work;
Lakshmi Narayana Kalavaladac0b6c2017-09-13 15:33:42 -0700266 uint32_t msg_buf[ICP_MSG_BUF_SIZE];
267 uint32_t dbg_buf[ICP_DBG_BUF_SIZE];
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -0700268 struct completion a5_complete;
269 struct hfi_cmd_work_data *cmd_work_data;
270 struct hfi_msg_work_data *msg_work_data;
271 uint32_t ctxt_cnt;
Suresh Vankadara6657bc22017-07-31 10:33:04 +0530272 uint32_t ipe_ctxt_cnt;
273 uint32_t bps_ctxt_cnt;
Lakshmi Narayana Kalavala2743a0d2017-05-30 10:41:37 -0700274 struct dentry *dentry;
275 bool a5_debug;
Suresh Vankadara6657bc22017-07-31 10:33:04 +0530276 bool icp_pc_flag;
Suresh Vankadara34494fc2017-08-12 18:18:09 +0530277 uint64_t icp_debug_clk;
278 uint64_t icp_default_clk;
279 struct cam_icp_clk_info clk_info[ICP_CLK_HW_MAX];
Lakshmi Narayana Kalavala2c714282017-09-08 12:27:36 -0700280 bool secure_mode;
Lakshmi Narayana Kalavaladac0b6c2017-09-13 15:33:42 -0700281 bool a5_jtag_debug;
282 bool a5_debug_q;
283 u64 a5_dbg_lvl;
Suresh Vankadaraaa6ff8f2017-10-26 22:51:27 +0530284 bool ipe0_enable;
285 bool ipe1_enable;
286 bool bps_enable;
Alok Pandey78093d32017-11-08 18:56:54 +0530287 uint32_t core_info;
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -0700288};
289
Suresh Vankadara5499a5f2017-06-16 22:13:56 +0530290static int cam_icp_mgr_hw_close(void *hw_priv, void *hw_close_args);
Harsh Shah6baba8c2017-10-16 19:23:29 -0700291static int cam_icp_mgr_hw_open(void *hw_mgr_priv, void *download_fw_args);
Alok Pandey78093d32017-11-08 18:56:54 +0530292static int cam_icp_mgr_icp_resume(struct cam_icp_hw_mgr *hw_mgr);
293static int cam_icp_mgr_icp_power_collapse(struct cam_icp_hw_mgr *hw_mgr);
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -0700294#endif /* CAM_ICP_HW_MGR_H */