Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 1 | /* 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 Kalavala | 2743a0d | 2017-05-30 10:41:37 -0700 | [diff] [blame] | 26 | #include "cam_smmu_api.h" |
Suresh Vankadara | 34494fc | 2017-08-12 18:18:09 +0530 | [diff] [blame] | 27 | #include "cam_soc_util.h" |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 28 | |
| 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 Gore | f13f75c | 2017-11-02 17:50:15 -0700 | [diff] [blame] | 35 | #define CAM_MAX_IN_RES 8 |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 36 | |
Suresh Vankadara | 38f7a65 | 2017-09-25 20:58:41 +0530 | [diff] [blame] | 37 | #define ICP_WORKQ_NUM_TASK 100 |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 38 | #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 Vankadara | 8e06cfb | 2017-06-13 16:27:08 +0530 | [diff] [blame] | 43 | #define ICP_PACKET_OPCODE 2 |
Suresh Vankadara | adcf058 | 2017-05-24 09:53:36 +0530 | [diff] [blame] | 44 | #define ICP_MAX_OUTPUT_SUPPORTED 6 |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 45 | |
Suresh Vankadara | 22697d3 | 2017-07-03 12:14:09 -0700 | [diff] [blame] | 46 | #define ICP_FRAME_PROCESS_SUCCESS 0 |
| 47 | #define ICP_FRAME_PROCESS_FAILURE 1 |
Lakshmi Narayana Kalavala | dac0b6c | 2017-09-13 15:33:42 -0700 | [diff] [blame] | 48 | #define ICP_MSG_BUF_SIZE 256 |
| 49 | #define ICP_DBG_BUF_SIZE 102400 |
Suresh Vankadara | 22697d3 | 2017-07-03 12:14:09 -0700 | [diff] [blame] | 50 | |
Suresh Vankadara | 34494fc | 2017-08-12 18:18:09 +0530 | [diff] [blame] | 51 | #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 Vankadara | aa6ff8f | 2017-10-26 22:51:27 +0530 | [diff] [blame] | 57 | #define CPAS_IPE0_BIT 0x1000 |
| 58 | #define CPAS_IPE1_BIT 0x2000 |
| 59 | #define CPAS_BPS_BIT 0x400 |
| 60 | |
Alok Pandey | 78093d3 | 2017-11-08 18:56:54 +0530 | [diff] [blame^] | 61 | #define ICP_PWR_CLP_BPS 0x00000001 |
| 62 | #define ICP_PWR_CLP_IPE0 0x00010000 |
| 63 | #define ICP_PWR_CLP_IPE1 0x00020000 |
| 64 | |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 65 | /** |
| 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 | */ |
| 74 | struct 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 Kalavala | 2743a0d | 2017-05-30 10:41:37 -0700 | [diff] [blame] | 81 | struct cam_smmu_region_info shmem; |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | /** |
| 85 | * struct hfi_cmd_work_data |
| 86 | * @type: Task type |
| 87 | * @data: Pointer to command data |
| 88 | * @request_id: Request id |
| 89 | */ |
| 90 | struct 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 | */ |
| 102 | struct 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 Vankadara | 34494fc | 2017-08-12 18:18:09 +0530 | [diff] [blame] | 117 | * @fw_process_flag: Frame process flag |
| 118 | * @clk_info: Clock information for a request |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 119 | */ |
| 120 | struct 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 Gore | cdd6a5e | 2017-05-17 19:06:59 -0700 | [diff] [blame] | 125 | uint64_t request_id[CAM_FRAME_CMD_MAX]; |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 126 | uint32_t num_out_resources[CAM_FRAME_CMD_MAX]; |
| 127 | uint32_t out_resource[CAM_FRAME_CMD_MAX][CAM_MAX_OUT_RES]; |
Suresh Vankadara | ad2d3a9 | 2017-09-25 12:18:11 +0530 | [diff] [blame] | 128 | uint32_t in_resource[CAM_FRAME_CMD_MAX]; |
Suresh Vankadara | 34494fc | 2017-08-12 18:18:09 +0530 | [diff] [blame] | 129 | uint32_t fw_process_flag[CAM_FRAME_CMD_MAX]; |
| 130 | struct cam_icp_clk_bw_request clk_info[CAM_FRAME_CMD_MAX]; |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 131 | }; |
| 132 | |
| 133 | /** |
Suresh Vankadara | 34494fc | 2017-08-12 18:18:09 +0530 | [diff] [blame] | 134 | * 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 Vankadara | 38f7a65 | 2017-09-25 20:58:41 +0530 | [diff] [blame] | 138 | * @reserved: Reserved field |
Suresh Vankadara | 34494fc | 2017-08-12 18:18:09 +0530 | [diff] [blame] | 139 | * #uncompressed_bw: Current bandwidth voting |
| 140 | * @compressed_bw: Current compressed bandwidth voting |
| 141 | * @clk_rate: Supported clock rates for the context |
| 142 | */ |
| 143 | struct cam_ctx_clk_info { |
| 144 | uint32_t curr_fc; |
| 145 | uint32_t rt_flag; |
| 146 | uint32_t base_clk; |
Suresh Vankadara | 38f7a65 | 2017-09-25 20:58:41 +0530 | [diff] [blame] | 147 | uint32_t reserved; |
| 148 | uint64_t uncompressed_bw; |
| 149 | uint64_t compressed_bw; |
Suresh Vankadara | 34494fc | 2017-08-12 18:18:09 +0530 | [diff] [blame] | 150 | int32_t clk_rate[CAM_MAX_VOTE]; |
| 151 | }; |
| 152 | /** |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 153 | * 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 Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 160 | * @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 Vankadara | 34494fc | 2017-08-12 18:18:09 +0530 | [diff] [blame] | 167 | * @ctx_id: Context Id |
| 168 | * @clk_info: Current clock info of a context |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 169 | */ |
| 170 | struct 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 Vankadara | adcf058 | 2017-05-24 09:53:36 +0530 | [diff] [blame] | 176 | struct cam_icp_acquire_dev_info *icp_dev_acquire_info; |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 177 | cam_hw_event_cb_func ctxt_event_cb; |
Suresh Vankadara | adcf058 | 2017-05-24 09:53:36 +0530 | [diff] [blame] | 178 | bool in_use; |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 179 | 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 Vankadara | 5a1ae56 | 2017-06-03 12:59:15 +0530 | [diff] [blame] | 184 | uint32_t ctx_id; |
Suresh Vankadara | 34494fc | 2017-08-12 18:18:09 +0530 | [diff] [blame] | 185 | 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 | */ |
| 193 | struct 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 | */ |
| 207 | struct cam_icp_clk_info { |
| 208 | uint32_t base_clk; |
| 209 | uint32_t curr_clk; |
| 210 | uint32_t threshold; |
| 211 | uint32_t over_clked; |
Suresh Vankadara | 38f7a65 | 2017-09-25 20:58:41 +0530 | [diff] [blame] | 212 | uint64_t uncompressed_bw; |
| 213 | uint64_t compressed_bw; |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 214 | }; |
| 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 Vankadara | 6657bc2 | 2017-07-31 10:33:04 +0530 | [diff] [blame] | 235 | * @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 Vankadara | 34494fc | 2017-08-12 18:18:09 +0530 | [diff] [blame] | 240 | * @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 Kalavala | 2c71428 | 2017-09-08 12:27:36 -0700 | [diff] [blame] | 243 | * @secure_mode: Flag to enable/disable secure camera |
Lakshmi Narayana Kalavala | dac0b6c | 2017-09-13 15:33:42 -0700 | [diff] [blame] | 244 | * @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 Vankadara | aa6ff8f | 2017-10-26 22:51:27 +0530 | [diff] [blame] | 247 | * @ipe0_enable: Flag for IPE0 |
| 248 | * @ipe1_enable: Flag for IPE1 |
| 249 | * @bps_enable: Flag for BPS |
Alok Pandey | 78093d3 | 2017-11-08 18:56:54 +0530 | [diff] [blame^] | 250 | * @core_info: 32 bit value , tells IPE0/1 and BPS |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 251 | */ |
| 252 | struct 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 Kalavala | dac0b6c | 2017-09-13 15:33:42 -0700 | [diff] [blame] | 266 | uint32_t msg_buf[ICP_MSG_BUF_SIZE]; |
| 267 | uint32_t dbg_buf[ICP_DBG_BUF_SIZE]; |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 268 | 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 Vankadara | 6657bc2 | 2017-07-31 10:33:04 +0530 | [diff] [blame] | 272 | uint32_t ipe_ctxt_cnt; |
| 273 | uint32_t bps_ctxt_cnt; |
Lakshmi Narayana Kalavala | 2743a0d | 2017-05-30 10:41:37 -0700 | [diff] [blame] | 274 | struct dentry *dentry; |
| 275 | bool a5_debug; |
Suresh Vankadara | 6657bc2 | 2017-07-31 10:33:04 +0530 | [diff] [blame] | 276 | bool icp_pc_flag; |
Suresh Vankadara | 34494fc | 2017-08-12 18:18:09 +0530 | [diff] [blame] | 277 | 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 Kalavala | 2c71428 | 2017-09-08 12:27:36 -0700 | [diff] [blame] | 280 | bool secure_mode; |
Lakshmi Narayana Kalavala | dac0b6c | 2017-09-13 15:33:42 -0700 | [diff] [blame] | 281 | bool a5_jtag_debug; |
| 282 | bool a5_debug_q; |
| 283 | u64 a5_dbg_lvl; |
Suresh Vankadara | aa6ff8f | 2017-10-26 22:51:27 +0530 | [diff] [blame] | 284 | bool ipe0_enable; |
| 285 | bool ipe1_enable; |
| 286 | bool bps_enable; |
Alok Pandey | 78093d3 | 2017-11-08 18:56:54 +0530 | [diff] [blame^] | 287 | uint32_t core_info; |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 288 | }; |
| 289 | |
Suresh Vankadara | 5499a5f | 2017-06-16 22:13:56 +0530 | [diff] [blame] | 290 | static int cam_icp_mgr_hw_close(void *hw_priv, void *hw_close_args); |
Harsh Shah | 6baba8c | 2017-10-16 19:23:29 -0700 | [diff] [blame] | 291 | static int cam_icp_mgr_hw_open(void *hw_mgr_priv, void *download_fw_args); |
Alok Pandey | 78093d3 | 2017-11-08 18:56:54 +0530 | [diff] [blame^] | 292 | static int cam_icp_mgr_icp_resume(struct cam_icp_hw_mgr *hw_mgr); |
| 293 | static int cam_icp_mgr_icp_power_collapse(struct cam_icp_hw_mgr *hw_mgr); |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 294 | #endif /* CAM_ICP_HW_MGR_H */ |