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 |
| 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 Vankadara | 8e06cfb | 2017-06-13 16:27:08 +0530 | [diff] [blame] | 42 | #define ICP_PACKET_OPCODE 2 |
Suresh Vankadara | adcf058 | 2017-05-24 09:53:36 +0530 | [diff] [blame] | 43 | #define ICP_MAX_OUTPUT_SUPPORTED 6 |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 44 | |
Suresh Vankadara | 22697d3 | 2017-07-03 12:14:09 -0700 | [diff] [blame] | 45 | #define ICP_FRAME_PROCESS_SUCCESS 0 |
| 46 | #define ICP_FRAME_PROCESS_FAILURE 1 |
| 47 | |
Suresh Vankadara | 34494fc | 2017-08-12 18:18:09 +0530 | [diff] [blame] | 48 | #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 Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 54 | /** |
| 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 | */ |
| 63 | struct 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 Kalavala | 2743a0d | 2017-05-30 10:41:37 -0700 | [diff] [blame] | 70 | struct cam_smmu_region_info shmem; |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | /** |
| 74 | * struct hfi_cmd_work_data |
| 75 | * @type: Task type |
| 76 | * @data: Pointer to command data |
| 77 | * @request_id: Request id |
| 78 | */ |
| 79 | struct 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 | */ |
| 91 | struct 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 Vankadara | 34494fc | 2017-08-12 18:18:09 +0530 | [diff] [blame] | 106 | * @fw_process_flag: Frame process flag |
| 107 | * @clk_info: Clock information for a request |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 108 | */ |
| 109 | struct 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 Gore | cdd6a5e | 2017-05-17 19:06:59 -0700 | [diff] [blame] | 114 | uint64_t request_id[CAM_FRAME_CMD_MAX]; |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 115 | uint32_t num_out_resources[CAM_FRAME_CMD_MAX]; |
| 116 | uint32_t out_resource[CAM_FRAME_CMD_MAX][CAM_MAX_OUT_RES]; |
Suresh Vankadara | 34494fc | 2017-08-12 18:18:09 +0530 | [diff] [blame] | 117 | uint32_t fw_process_flag[CAM_FRAME_CMD_MAX]; |
| 118 | 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] | 119 | }; |
| 120 | |
| 121 | /** |
Suresh Vankadara | 34494fc | 2017-08-12 18:18:09 +0530 | [diff] [blame] | 122 | * 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 | */ |
| 130 | struct 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 Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 139 | * 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 Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 146 | * @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 Vankadara | 34494fc | 2017-08-12 18:18:09 +0530 | [diff] [blame] | 153 | * @ctx_id: Context Id |
| 154 | * @clk_info: Current clock info of a context |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 155 | */ |
| 156 | struct 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 Vankadara | adcf058 | 2017-05-24 09:53:36 +0530 | [diff] [blame] | 162 | struct cam_icp_acquire_dev_info *icp_dev_acquire_info; |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 163 | cam_hw_event_cb_func ctxt_event_cb; |
Suresh Vankadara | adcf058 | 2017-05-24 09:53:36 +0530 | [diff] [blame] | 164 | bool in_use; |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 165 | 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 Vankadara | 5a1ae56 | 2017-06-03 12:59:15 +0530 | [diff] [blame] | 170 | uint32_t ctx_id; |
Suresh Vankadara | 34494fc | 2017-08-12 18:18:09 +0530 | [diff] [blame] | 171 | 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 | */ |
| 179 | struct 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 | */ |
| 193 | struct 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 Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 200 | }; |
| 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 Vankadara | 6657bc2 | 2017-07-31 10:33:04 +0530 | [diff] [blame] | 221 | * @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 Vankadara | 34494fc | 2017-08-12 18:18:09 +0530 | [diff] [blame] | 226 | * @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 Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 229 | */ |
| 230 | struct 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 Vankadara | 6657bc2 | 2017-07-31 10:33:04 +0530 | [diff] [blame] | 250 | uint32_t ipe_ctxt_cnt; |
| 251 | uint32_t bps_ctxt_cnt; |
Lakshmi Narayana Kalavala | 2743a0d | 2017-05-30 10:41:37 -0700 | [diff] [blame] | 252 | struct dentry *dentry; |
| 253 | bool a5_debug; |
Suresh Vankadara | 6657bc2 | 2017-07-31 10:33:04 +0530 | [diff] [blame] | 254 | bool icp_pc_flag; |
Suresh Vankadara | 34494fc | 2017-08-12 18:18:09 +0530 | [diff] [blame] | 255 | 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 Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 258 | }; |
| 259 | |
Suresh Vankadara | 5499a5f | 2017-06-16 22:13:56 +0530 | [diff] [blame] | 260 | static int cam_icp_mgr_hw_close(void *hw_priv, void *hw_close_args); |
| 261 | static int cam_icp_mgr_download_fw(void *hw_mgr_priv, void *download_fw_args); |
Lakshmi Narayana Kalavala | 85c4035 | 2017-05-15 16:19:13 -0700 | [diff] [blame] | 262 | #endif /* CAM_ICP_HW_MGR_H */ |