blob: d4f54827f2a1c51924715d435b413958a1b85eb9 [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
35
36#define ICP_WORKQ_NUM_TASK 30
37#define ICP_WORKQ_TASK_CMD_TYPE 1
38#define ICP_WORKQ_TASK_MSG_TYPE 2
39
40#define ICP_PACKET_SIZE 0
41#define ICP_PACKET_TYPE 1
Suresh Vankadara8e06cfb2017-06-13 16:27:08 +053042#define ICP_PACKET_OPCODE 2
Suresh Vankadaraadcf0582017-05-24 09:53:36 +053043#define ICP_MAX_OUTPUT_SUPPORTED 6
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -070044
Suresh Vankadara22697d32017-07-03 12:14:09 -070045#define ICP_FRAME_PROCESS_SUCCESS 0
46#define ICP_FRAME_PROCESS_FAILURE 1
47
Suresh Vankadara34494fc2017-08-12 18:18:09 +053048#define ICP_CLK_HW_IPE 0x0
49#define ICP_CLK_HW_BPS 0x1
50#define ICP_CLK_HW_MAX 0x2
51
52#define ICP_OVER_CLK_THRESHOLD 15
53
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -070054/**
55 * struct icp_hfi_mem_info
56 * @qtbl: Memory info of queue table
57 * @cmd_q: Memory info of command queue
58 * @msg_q: Memory info of message queue
59 * @dbg_q: Memory info of debug queue
60 * @sec_heap: Memory info of secondary heap
61 * @fw_buf: Memory info of firmware
62 */
63struct icp_hfi_mem_info {
64 struct cam_mem_mgr_memory_desc qtbl;
65 struct cam_mem_mgr_memory_desc cmd_q;
66 struct cam_mem_mgr_memory_desc msg_q;
67 struct cam_mem_mgr_memory_desc dbg_q;
68 struct cam_mem_mgr_memory_desc sec_heap;
69 struct cam_mem_mgr_memory_desc fw_buf;
Lakshmi Narayana Kalavala2743a0d2017-05-30 10:41:37 -070070 struct cam_smmu_region_info shmem;
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -070071};
72
73/**
74 * struct hfi_cmd_work_data
75 * @type: Task type
76 * @data: Pointer to command data
77 * @request_id: Request id
78 */
79struct hfi_cmd_work_data {
80 uint32_t type;
81 void *data;
82 int32_t request_id;
83};
84
85/**
86 * struct hfi_msg_work_data
87 * @type: Task type
88 * @data: Pointer to message data
89 * @irq_status: IRQ status
90 */
91struct hfi_msg_work_data {
92 uint32_t type;
93 void *data;
94 uint32_t irq_status;
95};
96
97/**
98 * struct hfi_frame_process_info
99 * @hfi_frame_cmd: Frame process command info
100 * @bitmap: Bitmap for hfi_frame_cmd
101 * @bits: Used in hfi_frame_cmd bitmap
102 * @lock: Lock for hfi_frame_cmd
103 * @request_id: Request id list
104 * @num_out_resources: Number of out syncs
105 * @out_resource: Out sync info
Suresh Vankadara34494fc2017-08-12 18:18:09 +0530106 * @fw_process_flag: Frame process flag
107 * @clk_info: Clock information for a request
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -0700108 */
109struct hfi_frame_process_info {
110 struct hfi_cmd_ipebps_async hfi_frame_cmd[CAM_FRAME_CMD_MAX];
111 void *bitmap;
112 size_t bits;
113 struct mutex lock;
Sagar Gorecdd6a5e2017-05-17 19:06:59 -0700114 uint64_t request_id[CAM_FRAME_CMD_MAX];
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -0700115 uint32_t num_out_resources[CAM_FRAME_CMD_MAX];
116 uint32_t out_resource[CAM_FRAME_CMD_MAX][CAM_MAX_OUT_RES];
Suresh Vankadara34494fc2017-08-12 18:18:09 +0530117 uint32_t fw_process_flag[CAM_FRAME_CMD_MAX];
118 struct cam_icp_clk_bw_request clk_info[CAM_FRAME_CMD_MAX];
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -0700119};
120
121/**
Suresh Vankadara34494fc2017-08-12 18:18:09 +0530122 * struct cam_ctx_clk_info
123 * @curr_fc: Context latest request frame cycles
124 * @rt_flag: Flag to indicate real time request
125 * @base_clk: Base clock to process the request
126 * #uncompressed_bw: Current bandwidth voting
127 * @compressed_bw: Current compressed bandwidth voting
128 * @clk_rate: Supported clock rates for the context
129 */
130struct cam_ctx_clk_info {
131 uint32_t curr_fc;
132 uint32_t rt_flag;
133 uint32_t base_clk;
134 uint32_t uncompressed_bw;
135 uint32_t compressed_bw;
136 int32_t clk_rate[CAM_MAX_VOTE];
137};
138/**
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -0700139 * struct cam_icp_hw_ctx_data
140 * @context_priv: Context private data
141 * @ctx_mutex: Mutex for context
142 * @fw_handle: Firmware handle
143 * @scratch_mem_size: Scratch memory size
144 * @acquire_dev_cmd: Acquire command
145 * @icp_dev_acquire_info: Acquire device info
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -0700146 * @ctxt_event_cb: Context callback function
147 * @in_use: Flag for context usage
148 * @role: Role of a context in case of chaining
149 * @chain_ctx: Peer context
150 * @hfi_frame_process: Frame process command
151 * @wait_complete: Completion info
152 * @temp_payload: Payload for destroy handle data
Suresh Vankadara34494fc2017-08-12 18:18:09 +0530153 * @ctx_id: Context Id
154 * @clk_info: Current clock info of a context
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -0700155 */
156struct cam_icp_hw_ctx_data {
157 void *context_priv;
158 struct mutex ctx_mutex;
159 uint32_t fw_handle;
160 uint32_t scratch_mem_size;
161 struct cam_acquire_dev_cmd acquire_dev_cmd;
Suresh Vankadaraadcf0582017-05-24 09:53:36 +0530162 struct cam_icp_acquire_dev_info *icp_dev_acquire_info;
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -0700163 cam_hw_event_cb_func ctxt_event_cb;
Suresh Vankadaraadcf0582017-05-24 09:53:36 +0530164 bool in_use;
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -0700165 uint32_t role;
166 struct cam_icp_hw_ctx_data *chain_ctx;
167 struct hfi_frame_process_info hfi_frame_process;
168 struct completion wait_complete;
169 struct ipe_bps_destroy temp_payload;
Suresh Vankadara5a1ae562017-06-03 12:59:15 +0530170 uint32_t ctx_id;
Suresh Vankadara34494fc2017-08-12 18:18:09 +0530171 struct cam_ctx_clk_info clk_info;
172};
173
174/**
175 * struct icp_cmd_generic_blob
176 * @ctx: Current context info
177 * @frame_info_idx: Index used for frame process info
178 */
179struct icp_cmd_generic_blob {
180 struct cam_icp_hw_ctx_data *ctx;
181 uint32_t frame_info_idx;
182};
183
184/**
185 * struct cam_icp_clk_info
186 * @base_clk: Base clock to process request
187 * @curr_clk: Current clock of hadrware
188 * @threshold: Threshold for overclk count
189 * @over_clked: Over clock count
190 * #uncompressed_bw: Current bandwidth voting
191 * @compressed_bw: Current compressed bandwidth voting
192 */
193struct cam_icp_clk_info {
194 uint32_t base_clk;
195 uint32_t curr_clk;
196 uint32_t threshold;
197 uint32_t over_clked;
198 uint32_t uncompressed_bw;
199 uint32_t compressed_bw;
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -0700200};
201
202/**
203 * struct cam_icp_hw_mgr
204 * @hw_mgr_mutex: Mutex for ICP hardware manager
205 * @hw_mgr_lock: Spinlock for ICP hardware manager
206 * @devices: Devices of ICP hardware manager
207 * @ctx_data: Context data
208 * @icp_caps: ICP capabilities
209 * @fw_download: Firmware download state
210 * @iommu_hdl: Non secure IOMMU handle
211 * @iommu_sec_hdl: Secure IOMMU handle
212 * @hfi_mem: Memory for hfi
213 * @cmd_work: Work queue for hfi commands
214 * @msg_work: Work queue for hfi messages
215 * @msg_buf: Buffer for message data from firmware
216 * @dbg_buf: Buffer for debug data from firmware
217 * @a5_complete: Completion info
218 * @cmd_work_data: Pointer to command work queue task
219 * @msg_work_data: Pointer to message work queue task
220 * @ctxt_cnt: Active context count
Suresh Vankadara6657bc22017-07-31 10:33:04 +0530221 * @ipe_ctxt_cnt: IPE Active context count
222 * @bps_ctxt_cnt: BPS Active context count
223 * @dentry: Debugfs entry
224 * @a5_debug: A5 debug flag
225 * @icp_pc_flag: Flag to enable/disable power collapse
Suresh Vankadara34494fc2017-08-12 18:18:09 +0530226 * @icp_debug_clk: Set clock based on debug value
227 * @icp_default_clk: Set this clok if user doesn't supply
228 * @clk_info: Clock info of hardware
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -0700229 */
230struct cam_icp_hw_mgr {
231 struct mutex hw_mgr_mutex;
232 spinlock_t hw_mgr_lock;
233
234 struct cam_hw_intf **devices[CAM_ICP_DEV_MAX];
235 struct cam_icp_hw_ctx_data ctx_data[CAM_ICP_CTX_MAX];
236 struct cam_icp_query_cap_cmd icp_caps;
237
238 bool fw_download;
239 int32_t iommu_hdl;
240 int32_t iommu_sec_hdl;
241 struct icp_hfi_mem_info hfi_mem;
242 struct cam_req_mgr_core_workq *cmd_work;
243 struct cam_req_mgr_core_workq *msg_work;
244 uint32_t msg_buf[256];
245 uint32_t dbg_buf[256];
246 struct completion a5_complete;
247 struct hfi_cmd_work_data *cmd_work_data;
248 struct hfi_msg_work_data *msg_work_data;
249 uint32_t ctxt_cnt;
Suresh Vankadara6657bc22017-07-31 10:33:04 +0530250 uint32_t ipe_ctxt_cnt;
251 uint32_t bps_ctxt_cnt;
Lakshmi Narayana Kalavala2743a0d2017-05-30 10:41:37 -0700252 struct dentry *dentry;
253 bool a5_debug;
Suresh Vankadara6657bc22017-07-31 10:33:04 +0530254 bool icp_pc_flag;
Suresh Vankadara34494fc2017-08-12 18:18:09 +0530255 uint64_t icp_debug_clk;
256 uint64_t icp_default_clk;
257 struct cam_icp_clk_info clk_info[ICP_CLK_HW_MAX];
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -0700258};
259
Suresh Vankadara5499a5f2017-06-16 22:13:56 +0530260static int cam_icp_mgr_hw_close(void *hw_priv, void *hw_close_args);
261static int cam_icp_mgr_download_fw(void *hw_mgr_priv, void *download_fw_args);
Lakshmi Narayana Kalavala85c40352017-05-15 16:19:13 -0700262#endif /* CAM_ICP_HW_MGR_H */