Shravya Samala | 43583ea | 2020-04-29 14:25:37 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 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 | #include <linux/debugfs.h> |
| 14 | #include <linux/videodev2.h> |
| 15 | #include <linux/slab.h> |
| 16 | #include <linux/uaccess.h> |
Jing Zhou | b524a85 | 2017-05-16 15:47:30 +0530 | [diff] [blame] | 17 | #include <linux/ratelimit.h> |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 18 | |
| 19 | #include "cam_isp_context.h" |
| 20 | #include "cam_isp_log.h" |
| 21 | #include "cam_mem_mgr.h" |
| 22 | #include "cam_sync_api.h" |
Jing Zhou | b524a85 | 2017-05-16 15:47:30 +0530 | [diff] [blame] | 23 | #include "cam_req_mgr_dev.h" |
Gregory Bergschneider | 5164f3a | 2017-07-07 10:26:17 -0600 | [diff] [blame] | 24 | #include "cam_trace.h" |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 25 | #include "cam_debug_util.h" |
Suraj Dongre | 2681192 | 2018-06-27 19:30:01 -0700 | [diff] [blame] | 26 | #include "cam_packet_util.h" |
| 27 | #include "cam_context_utils.h" |
Trishansh Bhardwaj | 0508a77 | 2018-10-01 12:32:49 +0530 | [diff] [blame] | 28 | #include "cam_common_util.h" |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 29 | |
Rishabh Jain | dbcea3a | 2019-03-15 12:46:51 +0530 | [diff] [blame] | 30 | static const char isp_dev_name[] = "cam-isp"; |
Suraj Dongre | 2681192 | 2018-06-27 19:30:01 -0700 | [diff] [blame] | 31 | |
| 32 | static int cam_isp_context_dump_active_request(void *data, unsigned long iova, |
| 33 | uint32_t buf_info); |
| 34 | |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 35 | static void __cam_isp_ctx_update_state_monitor_array( |
| 36 | struct cam_isp_context *ctx_isp, |
| 37 | enum cam_isp_state_change_trigger trigger_type, |
| 38 | uint32_t req_id) |
| 39 | { |
Alok Pandey | 6a9a5c3 | 2018-07-27 13:39:03 +0530 | [diff] [blame] | 40 | uint64_t iterator = 0; |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 41 | |
Alok Pandey | 6a9a5c3 | 2018-07-27 13:39:03 +0530 | [diff] [blame] | 42 | div64_u64_rem(atomic64_add_return(1, &ctx_isp->state_monitor_head), |
| 43 | CAM_ISP_CTX_STATE_MONITOR_MAX_ENTRIES, &iterator); |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 44 | ctx_isp->cam_isp_ctx_state_monitor[iterator].curr_state = |
| 45 | ctx_isp->substate_activated; |
| 46 | ctx_isp->cam_isp_ctx_state_monitor[iterator].trigger = |
| 47 | trigger_type; |
| 48 | ctx_isp->cam_isp_ctx_state_monitor[iterator].req_id = |
| 49 | req_id; |
| 50 | ctx_isp->cam_isp_ctx_state_monitor[iterator].evt_time_stamp = |
| 51 | jiffies_to_msecs(jiffies); |
| 52 | } |
| 53 | |
| 54 | static const char *__cam_isp_ctx_substate_val_to_type( |
| 55 | uint32_t type) |
| 56 | { |
| 57 | switch (type) { |
| 58 | case CAM_ISP_CTX_ACTIVATED_SOF: |
| 59 | return "SOF"; |
| 60 | case CAM_ISP_CTX_ACTIVATED_APPLIED: |
| 61 | return "APPLIED"; |
| 62 | case CAM_ISP_CTX_ACTIVATED_EPOCH: |
| 63 | return "EPOCH"; |
| 64 | case CAM_ISP_CTX_ACTIVATED_BUBBLE: |
| 65 | return "BUBBLE"; |
| 66 | case CAM_ISP_CTX_ACTIVATED_BUBBLE_APPLIED: |
| 67 | return "BUBBLE_APPLIED"; |
| 68 | case CAM_ISP_CTX_ACTIVATED_HALT: |
| 69 | return "HALT"; |
| 70 | default: |
| 71 | return "CAM_ISP_CTX_INVALID_STATE"; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | static const char *__cam_isp_hw_evt_val_to_type( |
| 76 | uint32_t evt_id) |
| 77 | { |
| 78 | switch (evt_id) { |
| 79 | case CAM_ISP_STATE_CHANGE_TRIGGER_ERROR: |
| 80 | return "ERROR"; |
| 81 | case CAM_ISP_STATE_CHANGE_TRIGGER_SOF: |
| 82 | return "SOF"; |
| 83 | case CAM_ISP_STATE_CHANGE_TRIGGER_REG_UPDATE: |
| 84 | return "REG_UPDATE"; |
| 85 | case CAM_ISP_STATE_CHANGE_TRIGGER_EPOCH: |
| 86 | return "EPOCH"; |
| 87 | case CAM_ISP_STATE_CHANGE_TRIGGER_EOF: |
| 88 | return "EOF"; |
| 89 | case CAM_ISP_STATE_CHANGE_TRIGGER_DONE: |
| 90 | return "DONE"; |
| 91 | default: |
| 92 | return "CAM_ISP_EVENT_INVALID"; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | static void __cam_isp_ctx_dump_state_monitor_array( |
| 97 | struct cam_isp_context *ctx_isp) |
| 98 | { |
| 99 | int i = 0; |
| 100 | uint64_t state_head = 0; |
| 101 | uint64_t index; |
Alok Pandey | 6a9a5c3 | 2018-07-27 13:39:03 +0530 | [diff] [blame] | 102 | struct cam_isp_context_state_monitor *cam_isp_ctx_state_monitor; |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 103 | |
| 104 | state_head = atomic64_read(&ctx_isp->state_monitor_head); |
| 105 | CAM_ERR_RATE_LIMIT(CAM_ISP, |
| 106 | "Dumping state information for preceding requests"); |
| 107 | |
| 108 | for (i = CAM_ISP_CTX_STATE_MONITOR_MAX_ENTRIES - 1; i >= 0; |
| 109 | i--) { |
Alok Pandey | 6a9a5c3 | 2018-07-27 13:39:03 +0530 | [diff] [blame] | 110 | div64_u64_rem(((state_head - i) + |
| 111 | CAM_ISP_CTX_STATE_MONITOR_MAX_ENTRIES), |
| 112 | CAM_ISP_CTX_STATE_MONITOR_MAX_ENTRIES, &index); |
| 113 | cam_isp_ctx_state_monitor = |
| 114 | &ctx_isp->cam_isp_ctx_state_monitor[index]; |
| 115 | |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 116 | CAM_ERR_RATE_LIMIT(CAM_ISP, |
Alok Pandey | 6a9a5c3 | 2018-07-27 13:39:03 +0530 | [diff] [blame] | 117 | "time[0x%llx] req_id[%u] state[%s] evt_type[%s]", |
| 118 | cam_isp_ctx_state_monitor->evt_time_stamp, |
| 119 | cam_isp_ctx_state_monitor->req_id, |
| 120 | __cam_isp_ctx_substate_val_to_type( |
| 121 | cam_isp_ctx_state_monitor->curr_state), |
| 122 | __cam_isp_hw_evt_val_to_type( |
| 123 | cam_isp_ctx_state_monitor->trigger)); |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 124 | } |
| 125 | } |
| 126 | |
Jing Zhou | 77962c5 | 2017-09-18 19:13:34 -0700 | [diff] [blame] | 127 | static int __cam_isp_ctx_enqueue_request_in_order( |
| 128 | struct cam_context *ctx, struct cam_ctx_request *req) |
| 129 | { |
| 130 | struct cam_ctx_request *req_current; |
| 131 | struct cam_ctx_request *req_prev; |
| 132 | struct list_head temp_list; |
| 133 | |
| 134 | INIT_LIST_HEAD(&temp_list); |
| 135 | spin_lock_bh(&ctx->lock); |
| 136 | if (list_empty(&ctx->pending_req_list)) { |
| 137 | list_add_tail(&req->list, &ctx->pending_req_list); |
| 138 | } else { |
| 139 | list_for_each_entry_safe_reverse( |
| 140 | req_current, req_prev, &ctx->pending_req_list, list) { |
| 141 | if (req->request_id < req_current->request_id) { |
| 142 | list_del_init(&req_current->list); |
| 143 | list_add(&req_current->list, &temp_list); |
| 144 | continue; |
| 145 | } else if (req->request_id == req_current->request_id) { |
| 146 | CAM_WARN(CAM_ISP, |
| 147 | "Received duplicated request %lld", |
| 148 | req->request_id); |
| 149 | } |
| 150 | break; |
| 151 | } |
| 152 | list_add_tail(&req->list, &ctx->pending_req_list); |
| 153 | |
| 154 | if (!list_empty(&temp_list)) { |
| 155 | list_for_each_entry_safe( |
| 156 | req_current, req_prev, &temp_list, list) { |
| 157 | list_del_init(&req_current->list); |
| 158 | list_add_tail(&req_current->list, |
| 159 | &ctx->pending_req_list); |
| 160 | } |
| 161 | } |
| 162 | } |
| 163 | spin_unlock_bh(&ctx->lock); |
| 164 | return 0; |
| 165 | } |
| 166 | |
Ravikishore Pampana | 24f712e | 2017-11-13 23:09:30 +0530 | [diff] [blame] | 167 | static int __cam_isp_ctx_enqueue_init_request( |
| 168 | struct cam_context *ctx, struct cam_ctx_request *req) |
| 169 | { |
| 170 | int rc = 0; |
| 171 | struct cam_ctx_request *req_old; |
| 172 | struct cam_isp_ctx_req *req_isp_old; |
| 173 | struct cam_isp_ctx_req *req_isp_new; |
| 174 | |
| 175 | spin_lock_bh(&ctx->lock); |
| 176 | if (list_empty(&ctx->pending_req_list)) { |
| 177 | list_add_tail(&req->list, &ctx->pending_req_list); |
| 178 | CAM_DBG(CAM_ISP, "INIT packet added req id= %d", |
| 179 | req->request_id); |
| 180 | goto end; |
| 181 | } |
| 182 | |
| 183 | req_old = list_first_entry(&ctx->pending_req_list, |
| 184 | struct cam_ctx_request, list); |
| 185 | req_isp_old = (struct cam_isp_ctx_req *) req_old->req_priv; |
| 186 | req_isp_new = (struct cam_isp_ctx_req *) req->req_priv; |
Vishalsingh Hajeri | e5450be | 2018-01-18 20:31:19 -0800 | [diff] [blame] | 187 | if (req_isp_old->hw_update_data.packet_opcode_type == |
| 188 | CAM_ISP_PACKET_INIT_DEV) { |
Ravikishore Pampana | 24f712e | 2017-11-13 23:09:30 +0530 | [diff] [blame] | 189 | if ((req_isp_old->num_cfg + req_isp_new->num_cfg) >= |
| 190 | CAM_ISP_CTX_CFG_MAX) { |
| 191 | CAM_WARN(CAM_ISP, "Can not merge INIT pkt"); |
| 192 | rc = -ENOMEM; |
| 193 | } |
| 194 | |
| 195 | if (req_isp_old->num_fence_map_out != 0 || |
| 196 | req_isp_old->num_fence_map_in != 0) { |
| 197 | CAM_WARN(CAM_ISP, "Invalid INIT pkt sequence"); |
| 198 | rc = -EINVAL; |
| 199 | } |
| 200 | |
| 201 | if (!rc) { |
| 202 | memcpy(req_isp_old->fence_map_out, |
| 203 | req_isp_new->fence_map_out, |
| 204 | sizeof(req_isp_new->fence_map_out[0])* |
| 205 | req_isp_new->num_fence_map_out); |
| 206 | req_isp_old->num_fence_map_out = |
| 207 | req_isp_new->num_fence_map_out; |
| 208 | |
| 209 | memcpy(req_isp_old->fence_map_in, |
| 210 | req_isp_new->fence_map_in, |
| 211 | sizeof(req_isp_new->fence_map_in[0])* |
| 212 | req_isp_new->num_fence_map_in); |
| 213 | req_isp_old->num_fence_map_in = |
| 214 | req_isp_new->num_fence_map_in; |
| 215 | |
| 216 | memcpy(&req_isp_old->cfg[req_isp_old->num_cfg], |
| 217 | req_isp_new->cfg, |
| 218 | sizeof(req_isp_new->cfg[0])* |
| 219 | req_isp_new->num_cfg); |
| 220 | req_isp_old->num_cfg += req_isp_new->num_cfg; |
| 221 | |
| 222 | list_add_tail(&req->list, &ctx->free_req_list); |
| 223 | } |
| 224 | } else { |
| 225 | CAM_WARN(CAM_ISP, |
| 226 | "Received Update pkt before INIT pkt. req_id= %lld", |
| 227 | req->request_id); |
| 228 | rc = -EINVAL; |
| 229 | } |
| 230 | end: |
| 231 | spin_unlock_bh(&ctx->lock); |
| 232 | return rc; |
| 233 | } |
| 234 | |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 235 | static const char *__cam_isp_resource_handle_id_to_type( |
| 236 | uint32_t resource_handle) |
Karthik Anantha Ram | ba3bd97 | 2017-09-25 15:35:26 -0700 | [diff] [blame] | 237 | { |
| 238 | switch (resource_handle) { |
| 239 | case CAM_ISP_IFE_OUT_RES_FULL: |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 240 | return "FULL"; |
Karthik Anantha Ram | ba3bd97 | 2017-09-25 15:35:26 -0700 | [diff] [blame] | 241 | case CAM_ISP_IFE_OUT_RES_DS4: |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 242 | return "DS4"; |
Karthik Anantha Ram | ba3bd97 | 2017-09-25 15:35:26 -0700 | [diff] [blame] | 243 | case CAM_ISP_IFE_OUT_RES_DS16: |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 244 | return "DS16"; |
Karthik Anantha Ram | ba3bd97 | 2017-09-25 15:35:26 -0700 | [diff] [blame] | 245 | case CAM_ISP_IFE_OUT_RES_RAW_DUMP: |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 246 | return "RAW_DUMP"; |
Karthik Anantha Ram | ba3bd97 | 2017-09-25 15:35:26 -0700 | [diff] [blame] | 247 | case CAM_ISP_IFE_OUT_RES_FD: |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 248 | return "FD"; |
Karthik Anantha Ram | ba3bd97 | 2017-09-25 15:35:26 -0700 | [diff] [blame] | 249 | case CAM_ISP_IFE_OUT_RES_PDAF: |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 250 | return "PDAF"; |
Karthik Anantha Ram | ba3bd97 | 2017-09-25 15:35:26 -0700 | [diff] [blame] | 251 | case CAM_ISP_IFE_OUT_RES_RDI_0: |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 252 | return "RDI_0"; |
Karthik Anantha Ram | ba3bd97 | 2017-09-25 15:35:26 -0700 | [diff] [blame] | 253 | case CAM_ISP_IFE_OUT_RES_RDI_1: |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 254 | return "RDI_1"; |
Karthik Anantha Ram | ba3bd97 | 2017-09-25 15:35:26 -0700 | [diff] [blame] | 255 | case CAM_ISP_IFE_OUT_RES_RDI_2: |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 256 | return "RDI_2"; |
Karthik Anantha Ram | ba3bd97 | 2017-09-25 15:35:26 -0700 | [diff] [blame] | 257 | case CAM_ISP_IFE_OUT_RES_RDI_3: |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 258 | return "RDI_3"; |
Karthik Anantha Ram | ba3bd97 | 2017-09-25 15:35:26 -0700 | [diff] [blame] | 259 | case CAM_ISP_IFE_OUT_RES_STATS_HDR_BE: |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 260 | return "STATS_HDR_BE"; |
Karthik Anantha Ram | ba3bd97 | 2017-09-25 15:35:26 -0700 | [diff] [blame] | 261 | case CAM_ISP_IFE_OUT_RES_STATS_HDR_BHIST: |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 262 | return "STATS_HDR_BHIST"; |
Karthik Anantha Ram | ba3bd97 | 2017-09-25 15:35:26 -0700 | [diff] [blame] | 263 | case CAM_ISP_IFE_OUT_RES_STATS_TL_BG: |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 264 | return "STATS_TL_BG"; |
Karthik Anantha Ram | ba3bd97 | 2017-09-25 15:35:26 -0700 | [diff] [blame] | 265 | case CAM_ISP_IFE_OUT_RES_STATS_BF: |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 266 | return "STATS_BF"; |
Karthik Anantha Ram | ba3bd97 | 2017-09-25 15:35:26 -0700 | [diff] [blame] | 267 | case CAM_ISP_IFE_OUT_RES_STATS_AWB_BG: |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 268 | return "STATS_AWB_BG"; |
Karthik Anantha Ram | ba3bd97 | 2017-09-25 15:35:26 -0700 | [diff] [blame] | 269 | case CAM_ISP_IFE_OUT_RES_STATS_BHIST: |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 270 | return "STATS_BHIST"; |
Karthik Anantha Ram | ba3bd97 | 2017-09-25 15:35:26 -0700 | [diff] [blame] | 271 | case CAM_ISP_IFE_OUT_RES_STATS_RS: |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 272 | return "STATS_RS"; |
Karthik Anantha Ram | ba3bd97 | 2017-09-25 15:35:26 -0700 | [diff] [blame] | 273 | case CAM_ISP_IFE_OUT_RES_STATS_CS: |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 274 | return "STATS_CS"; |
Karthik Anantha Ram | ba3bd97 | 2017-09-25 15:35:26 -0700 | [diff] [blame] | 275 | default: |
| 276 | return "CAM_ISP_Invalid_Resource_Type"; |
| 277 | } |
| 278 | } |
| 279 | |
Gregory Bergschneider | 5164f3a | 2017-07-07 10:26:17 -0600 | [diff] [blame] | 280 | static uint64_t __cam_isp_ctx_get_event_ts(uint32_t evt_id, void *evt_data) |
| 281 | { |
| 282 | uint64_t ts = 0; |
| 283 | |
| 284 | if (!evt_data) |
| 285 | return 0; |
| 286 | |
| 287 | switch (evt_id) { |
| 288 | case CAM_ISP_HW_EVENT_ERROR: |
| 289 | ts = ((struct cam_isp_hw_error_event_data *)evt_data)-> |
| 290 | timestamp; |
| 291 | break; |
| 292 | case CAM_ISP_HW_EVENT_SOF: |
| 293 | ts = ((struct cam_isp_hw_sof_event_data *)evt_data)-> |
| 294 | timestamp; |
| 295 | break; |
| 296 | case CAM_ISP_HW_EVENT_REG_UPDATE: |
| 297 | ts = ((struct cam_isp_hw_reg_update_event_data *)evt_data)-> |
| 298 | timestamp; |
| 299 | break; |
| 300 | case CAM_ISP_HW_EVENT_EPOCH: |
| 301 | ts = ((struct cam_isp_hw_epoch_event_data *)evt_data)-> |
| 302 | timestamp; |
| 303 | break; |
| 304 | case CAM_ISP_HW_EVENT_EOF: |
| 305 | ts = ((struct cam_isp_hw_eof_event_data *)evt_data)-> |
| 306 | timestamp; |
| 307 | break; |
| 308 | case CAM_ISP_HW_EVENT_DONE: |
| 309 | break; |
| 310 | default: |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 311 | CAM_DBG(CAM_ISP, "Invalid Event Type %d", evt_id); |
Gregory Bergschneider | 5164f3a | 2017-07-07 10:26:17 -0600 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | return ts; |
| 315 | } |
| 316 | |
Karthik Anantha Ram | ba3bd97 | 2017-09-25 15:35:26 -0700 | [diff] [blame] | 317 | static void __cam_isp_ctx_handle_buf_done_fail_log( |
| 318 | struct cam_isp_ctx_req *req_isp) |
| 319 | { |
| 320 | int i; |
| 321 | |
Harsh Shah | 1b8eb23 | 2017-10-09 19:20:52 -0700 | [diff] [blame] | 322 | if (req_isp->num_fence_map_out >= CAM_ISP_CTX_RES_MAX) { |
| 323 | CAM_ERR_RATE_LIMIT(CAM_ISP, |
| 324 | "Num Resources exceed mMAX %d >= %d ", |
| 325 | req_isp->num_fence_map_out, CAM_ISP_CTX_RES_MAX); |
| 326 | return; |
| 327 | } |
| 328 | |
Karthik Anantha Ram | ba3bd97 | 2017-09-25 15:35:26 -0700 | [diff] [blame] | 329 | CAM_ERR_RATE_LIMIT(CAM_ISP, |
| 330 | "Resource Handles that fail to generate buf_done in prev frame"); |
| 331 | for (i = 0; i < req_isp->num_fence_map_out; i++) { |
| 332 | if (req_isp->fence_map_out[i].sync_id != -1) |
| 333 | CAM_ERR_RATE_LIMIT(CAM_ISP, |
| 334 | "Resource_Handle: [%s] Sync_ID: [0x%x]", |
| 335 | __cam_isp_resource_handle_id_to_type( |
| 336 | req_isp->fence_map_out[i].resource_handle), |
| 337 | req_isp->fence_map_out[i].sync_id); |
| 338 | } |
| 339 | } |
| 340 | |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 341 | static int __cam_isp_ctx_handle_buf_done_in_activated_state( |
| 342 | struct cam_isp_context *ctx_isp, |
| 343 | struct cam_isp_hw_done_event_data *done, |
| 344 | uint32_t bubble_state) |
| 345 | { |
| 346 | int rc = 0; |
| 347 | int i, j; |
| 348 | struct cam_ctx_request *req; |
| 349 | struct cam_isp_ctx_req *req_isp; |
| 350 | struct cam_context *ctx = ctx_isp->base; |
| 351 | |
| 352 | if (list_empty(&ctx->active_req_list)) { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 353 | CAM_DBG(CAM_ISP, "Buf done with no active request!"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 354 | goto end; |
| 355 | } |
| 356 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 357 | CAM_DBG(CAM_ISP, "Enter with bubble_state %d", bubble_state); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 358 | |
| 359 | req = list_first_entry(&ctx->active_req_list, |
| 360 | struct cam_ctx_request, list); |
Gregory Bergschneider | 5164f3a | 2017-07-07 10:26:17 -0600 | [diff] [blame] | 361 | |
| 362 | trace_cam_buf_done("ISP", ctx, req); |
| 363 | |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 364 | req_isp = (struct cam_isp_ctx_req *) req->req_priv; |
| 365 | for (i = 0; i < done->num_handles; i++) { |
| 366 | for (j = 0; j < req_isp->num_fence_map_out; j++) { |
| 367 | if (done->resource_handle[i] == |
| 368 | req_isp->fence_map_out[j].resource_handle) |
| 369 | break; |
| 370 | } |
| 371 | |
| 372 | if (j == req_isp->num_fence_map_out) { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 373 | CAM_ERR(CAM_ISP, |
| 374 | "Can not find matching lane handle 0x%x!", |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 375 | done->resource_handle[i]); |
| 376 | rc = -EINVAL; |
| 377 | continue; |
| 378 | } |
| 379 | |
Harsh Shah | 1b8eb23 | 2017-10-09 19:20:52 -0700 | [diff] [blame] | 380 | if (req_isp->fence_map_out[j].sync_id == -1) { |
| 381 | __cam_isp_ctx_handle_buf_done_fail_log(req_isp); |
| 382 | continue; |
| 383 | } |
Jing Zhou | bb536a8 | 2017-05-18 15:20:38 -0700 | [diff] [blame] | 384 | |
Junzhe Zou | 09820a7 | 2018-09-06 18:11:41 -0700 | [diff] [blame] | 385 | if (!req_isp->bubble_detected) { |
vhajeri | 0554525 | 2017-11-10 18:43:08 -0800 | [diff] [blame] | 386 | CAM_DBG(CAM_ISP, |
| 387 | "Sync with success: req %lld res 0x%x fd 0x%x", |
| 388 | req->request_id, |
| 389 | req_isp->fence_map_out[j].resource_handle, |
| 390 | req_isp->fence_map_out[j].sync_id); |
| 391 | |
| 392 | rc = cam_sync_signal(req_isp->fence_map_out[j].sync_id, |
| 393 | CAM_SYNC_STATE_SIGNALED_SUCCESS); |
| 394 | if (rc) |
| 395 | CAM_DBG(CAM_ISP, "Sync failed with rc = %d", |
Jeyaprakash Soundrapandian | 32e5ae5 | 2017-11-17 23:44:44 -0800 | [diff] [blame] | 396 | rc); |
| 397 | } else if (!req_isp->bubble_report) { |
| 398 | CAM_DBG(CAM_ISP, |
| 399 | "Sync with failure: req %lld res 0x%x fd 0x%x", |
| 400 | req->request_id, |
| 401 | req_isp->fence_map_out[j].resource_handle, |
| 402 | req_isp->fence_map_out[j].sync_id); |
| 403 | |
| 404 | rc = cam_sync_signal(req_isp->fence_map_out[j].sync_id, |
| 405 | CAM_SYNC_STATE_SIGNALED_ERROR); |
| 406 | if (rc) |
| 407 | CAM_ERR(CAM_ISP, "Sync failed with rc = %d", |
vhajeri | 0554525 | 2017-11-10 18:43:08 -0800 | [diff] [blame] | 408 | rc); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 409 | } else { |
| 410 | /* |
| 411 | * Ignore the buffer done if bubble detect is on |
Junzhe Zou | 09820a7 | 2018-09-06 18:11:41 -0700 | [diff] [blame] | 412 | * Increment the ack number here, and queue the |
| 413 | * request back to pending list whenever all the |
| 414 | * buffers are done. |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 415 | */ |
Junzhe Zou | 09820a7 | 2018-09-06 18:11:41 -0700 | [diff] [blame] | 416 | req_isp->num_acked++; |
Harsh Shah | 1b8eb23 | 2017-10-09 19:20:52 -0700 | [diff] [blame] | 417 | CAM_DBG(CAM_ISP, |
| 418 | "buf done with bubble state %d recovery %d", |
| 419 | bubble_state, req_isp->bubble_report); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 420 | continue; |
| 421 | } |
| 422 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 423 | CAM_DBG(CAM_ISP, "req %lld, reset sync id 0x%x", |
Harsh Shah | 1b8eb23 | 2017-10-09 19:20:52 -0700 | [diff] [blame] | 424 | req->request_id, |
| 425 | req_isp->fence_map_out[j].sync_id); |
| 426 | if (!rc) { |
| 427 | req_isp->num_acked++; |
| 428 | req_isp->fence_map_out[j].sync_id = -1; |
| 429 | } |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 430 | } |
| 431 | |
Harsh Shah | 1b8eb23 | 2017-10-09 19:20:52 -0700 | [diff] [blame] | 432 | if (req_isp->num_acked > req_isp->num_fence_map_out) { |
| 433 | /* Should not happen */ |
| 434 | CAM_ERR(CAM_ISP, |
| 435 | "WARNING: req_id %lld num_acked %d > map_out %d", |
| 436 | req->request_id, req_isp->num_acked, |
| 437 | req_isp->num_fence_map_out); |
| 438 | WARN_ON(req_isp->num_acked > req_isp->num_fence_map_out); |
| 439 | } |
Junzhe Zou | 09820a7 | 2018-09-06 18:11:41 -0700 | [diff] [blame] | 440 | |
| 441 | if (req_isp->num_acked != req_isp->num_fence_map_out) |
| 442 | return rc; |
| 443 | |
| 444 | ctx_isp->active_req_cnt--; |
| 445 | |
| 446 | if (req_isp->bubble_detected && req_isp->bubble_report) { |
| 447 | req_isp->num_acked = 0; |
| 448 | req_isp->bubble_detected = false; |
| 449 | list_del_init(&req->list); |
| 450 | list_add(&req->list, &ctx->pending_req_list); |
Ayush Kumar | f13969a9 | 2019-07-18 13:02:43 +0530 | [diff] [blame] | 451 | atomic_set(&ctx_isp->process_bubble, 0); |
Junzhe Zou | 09820a7 | 2018-09-06 18:11:41 -0700 | [diff] [blame] | 452 | |
| 453 | CAM_DBG(CAM_REQ, |
| 454 | "Move active request %lld to pending list(cnt = %d) [bubble recovery]", |
| 455 | req->request_id, ctx_isp->active_req_cnt); |
| 456 | } else { |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 457 | list_del_init(&req->list); |
| 458 | list_add_tail(&req->list, &ctx->free_req_list); |
Junzhe Zou | 09820a7 | 2018-09-06 18:11:41 -0700 | [diff] [blame] | 459 | |
Karthik Anantha Ram | 5438d57 | 2018-06-15 10:48:19 -0700 | [diff] [blame] | 460 | CAM_DBG(CAM_REQ, |
| 461 | "Move active request %lld to free list(cnt = %d) [all fences done]", |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 462 | req->request_id, ctx_isp->active_req_cnt); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | end: |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 466 | __cam_isp_ctx_update_state_monitor_array(ctx_isp, |
| 467 | CAM_ISP_STATE_CHANGE_TRIGGER_DONE, |
| 468 | ctx_isp->base->req_list->request_id); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 469 | return rc; |
| 470 | } |
| 471 | |
Karthik Anantha Ram | c93754c | 2018-03-28 14:21:14 -0700 | [diff] [blame] | 472 | static void __cam_isp_ctx_send_sof_boot_timestamp( |
| 473 | struct cam_isp_context *ctx_isp, uint64_t request_id, |
| 474 | uint32_t sof_event_status) |
| 475 | { |
| 476 | struct cam_req_mgr_message req_msg; |
| 477 | |
| 478 | req_msg.session_hdl = ctx_isp->base->session_hdl; |
| 479 | req_msg.u.frame_msg.frame_id = ctx_isp->frame_id; |
| 480 | req_msg.u.frame_msg.request_id = request_id; |
| 481 | req_msg.u.frame_msg.timestamp = ctx_isp->boot_timestamp; |
| 482 | req_msg.u.frame_msg.link_hdl = ctx_isp->base->link_hdl; |
| 483 | req_msg.u.frame_msg.sof_status = sof_event_status; |
| 484 | |
| 485 | CAM_DBG(CAM_ISP, |
| 486 | "request id:%lld frame number:%lld boot time stamp:0x%llx", |
| 487 | request_id, ctx_isp->frame_id, |
| 488 | ctx_isp->boot_timestamp); |
| 489 | |
| 490 | if (cam_req_mgr_notify_message(&req_msg, |
| 491 | V4L_EVENT_CAM_REQ_MGR_SOF_BOOT_TS, |
| 492 | V4L_EVENT_CAM_REQ_MGR_EVENT)) |
| 493 | CAM_ERR(CAM_ISP, |
| 494 | "Error in notifying the boot time for req id:%lld", |
| 495 | request_id); |
| 496 | } |
| 497 | |
| 498 | |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 499 | static void __cam_isp_ctx_send_sof_timestamp( |
| 500 | struct cam_isp_context *ctx_isp, uint64_t request_id, |
| 501 | uint32_t sof_event_status) |
| 502 | { |
| 503 | struct cam_req_mgr_message req_msg; |
| 504 | |
| 505 | req_msg.session_hdl = ctx_isp->base->session_hdl; |
| 506 | req_msg.u.frame_msg.frame_id = ctx_isp->frame_id; |
| 507 | req_msg.u.frame_msg.request_id = request_id; |
| 508 | req_msg.u.frame_msg.timestamp = ctx_isp->sof_timestamp_val; |
| 509 | req_msg.u.frame_msg.link_hdl = ctx_isp->base->link_hdl; |
| 510 | req_msg.u.frame_msg.sof_status = sof_event_status; |
| 511 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 512 | CAM_DBG(CAM_ISP, |
| 513 | "request id:%lld frame number:%lld SOF time stamp:0x%llx", |
| 514 | request_id, ctx_isp->frame_id, |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 515 | ctx_isp->sof_timestamp_val); |
Karthik Anantha Ram | c93754c | 2018-03-28 14:21:14 -0700 | [diff] [blame] | 516 | CAM_DBG(CAM_ISP, "sof status:%d", sof_event_status); |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 517 | |
Harsh Shah | 67fa231 | 2017-10-30 04:03:07 -0700 | [diff] [blame] | 518 | if (cam_req_mgr_notify_message(&req_msg, |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 519 | V4L_EVENT_CAM_REQ_MGR_SOF, V4L_EVENT_CAM_REQ_MGR_EVENT)) |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 520 | CAM_ERR(CAM_ISP, |
| 521 | "Error in notifying the sof time for req id:%lld", |
| 522 | request_id); |
Karthik Anantha Ram | c93754c | 2018-03-28 14:21:14 -0700 | [diff] [blame] | 523 | |
| 524 | __cam_isp_ctx_send_sof_boot_timestamp(ctx_isp, |
| 525 | request_id, sof_event_status); |
| 526 | |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 527 | } |
| 528 | |
Karthik Anantha Ram | 1532607 | 2018-05-18 14:47:00 -0700 | [diff] [blame] | 529 | static int __cam_isp_ctx_reg_upd_in_epoch_state( |
| 530 | struct cam_isp_context *ctx_isp, void *evt_data) |
| 531 | { |
| 532 | if (ctx_isp->frame_id == 1) |
| 533 | CAM_DBG(CAM_ISP, "Reg update for early PCR"); |
| 534 | else |
| 535 | CAM_WARN(CAM_ISP, |
| 536 | "Unexpected reg update in activated substate:%d for frame_id:%lld", |
| 537 | ctx_isp->substate_activated, ctx_isp->frame_id); |
| 538 | return 0; |
| 539 | } |
| 540 | |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 541 | static int __cam_isp_ctx_reg_upd_in_activated_state( |
| 542 | struct cam_isp_context *ctx_isp, void *evt_data) |
| 543 | { |
| 544 | int rc = 0; |
| 545 | struct cam_ctx_request *req; |
| 546 | struct cam_context *ctx = ctx_isp->base; |
| 547 | struct cam_isp_ctx_req *req_isp; |
| 548 | |
Junzhe Zou | fdcd472 | 2018-06-11 18:05:33 -0700 | [diff] [blame] | 549 | if (list_empty(&ctx->wait_req_list)) { |
| 550 | CAM_ERR(CAM_ISP, "Reg upd ack with no waiting request"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 551 | goto end; |
| 552 | } |
Junzhe Zou | fdcd472 | 2018-06-11 18:05:33 -0700 | [diff] [blame] | 553 | req = list_first_entry(&ctx->wait_req_list, |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 554 | struct cam_ctx_request, list); |
| 555 | list_del_init(&req->list); |
| 556 | |
| 557 | req_isp = (struct cam_isp_ctx_req *) req->req_priv; |
| 558 | if (req_isp->num_fence_map_out != 0) { |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 559 | list_add_tail(&req->list, &ctx->active_req_list); |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 560 | ctx_isp->active_req_cnt++; |
Karthik Anantha Ram | 5438d57 | 2018-06-15 10:48:19 -0700 | [diff] [blame] | 561 | CAM_DBG(CAM_REQ, "move request %lld to active list(cnt = %d)", |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 562 | req->request_id, ctx_isp->active_req_cnt); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 563 | } else { |
| 564 | /* no io config, so the request is completed. */ |
| 565 | list_add_tail(&req->list, &ctx->free_req_list); |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 566 | CAM_DBG(CAM_ISP, |
| 567 | "move active request %lld to free list(cnt = %d)", |
| 568 | req->request_id, ctx_isp->active_req_cnt); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | /* |
| 572 | * This function only called directly from applied and bubble applied |
| 573 | * state so change substate here. |
| 574 | */ |
| 575 | ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_EPOCH; |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 576 | CAM_DBG(CAM_ISP, "next substate %d", ctx_isp->substate_activated); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 577 | |
| 578 | end: |
| 579 | return rc; |
| 580 | } |
| 581 | |
| 582 | static int __cam_isp_ctx_notify_sof_in_actived_state( |
| 583 | struct cam_isp_context *ctx_isp, void *evt_data) |
| 584 | { |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 585 | int rc = 0; |
| 586 | struct cam_req_mgr_trigger_notify notify; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 587 | struct cam_context *ctx = ctx_isp->base; |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 588 | struct cam_ctx_request *req; |
| 589 | uint64_t request_id = 0; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 590 | |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 591 | /* |
| 592 | * notify reqmgr with sof signal. Note, due to scheduling delay |
| 593 | * we can run into situation that two active requests has already |
| 594 | * be in the active queue while we try to do the notification. |
| 595 | * In this case, we need to skip the current notification. This |
| 596 | * helps the state machine to catch up the delay. |
| 597 | */ |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 598 | if (ctx->ctx_crm_intf && ctx->ctx_crm_intf->notify_trigger && |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 599 | ctx_isp->active_req_cnt <= 2) { |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 600 | if (ctx_isp->subscribe_event & CAM_TRIGGER_POINT_SOF) { |
| 601 | notify.link_hdl = ctx->link_hdl; |
| 602 | notify.dev_hdl = ctx->dev_hdl; |
| 603 | notify.frame_id = ctx_isp->frame_id; |
| 604 | notify.trigger = CAM_TRIGGER_POINT_SOF; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 605 | |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 606 | ctx->ctx_crm_intf->notify_trigger(¬ify); |
| 607 | CAM_DBG(CAM_ISP, "Notify CRM SOF frame %lld", |
| 608 | ctx_isp->frame_id); |
| 609 | } |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 610 | |
| 611 | list_for_each_entry(req, &ctx->active_req_list, list) { |
| 612 | if (req->request_id > ctx_isp->reported_req_id) { |
| 613 | request_id = req->request_id; |
| 614 | ctx_isp->reported_req_id = request_id; |
| 615 | break; |
| 616 | } |
| 617 | } |
| 618 | |
Ravikishore Pampana | 6648f17 | 2017-12-08 20:29:11 +0530 | [diff] [blame] | 619 | if (ctx_isp->substate_activated == CAM_ISP_CTX_ACTIVATED_BUBBLE) |
| 620 | request_id = 0; |
| 621 | |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 622 | __cam_isp_ctx_send_sof_timestamp(ctx_isp, request_id, |
| 623 | CAM_REQ_MGR_SOF_EVENT_SUCCESS); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 624 | } else { |
Harsh Shah | cb0072c | 2017-09-26 19:22:10 -0700 | [diff] [blame] | 625 | CAM_ERR_RATE_LIMIT(CAM_ISP, "Can not notify SOF to CRM"); |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 626 | rc = -EFAULT; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 627 | } |
| 628 | |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 629 | return 0; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 630 | } |
| 631 | |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 632 | static int __cam_isp_ctx_notify_eof_in_actived_state( |
| 633 | struct cam_isp_context *ctx_isp, void *evt_data) |
| 634 | { |
| 635 | int rc = 0; |
| 636 | struct cam_req_mgr_trigger_notify notify; |
| 637 | struct cam_context *ctx = ctx_isp->base; |
| 638 | |
| 639 | if (!(ctx_isp->subscribe_event & CAM_TRIGGER_POINT_EOF)) |
| 640 | return rc; |
| 641 | |
| 642 | /* notify reqmgr with eof signal */ |
| 643 | if (ctx->ctx_crm_intf && ctx->ctx_crm_intf->notify_trigger) { |
| 644 | notify.link_hdl = ctx->link_hdl; |
| 645 | notify.dev_hdl = ctx->dev_hdl; |
| 646 | notify.frame_id = ctx_isp->frame_id; |
| 647 | notify.trigger = CAM_TRIGGER_POINT_EOF; |
| 648 | |
| 649 | ctx->ctx_crm_intf->notify_trigger(¬ify); |
| 650 | CAM_DBG(CAM_ISP, "Notify CRM EOF frame %lld\n", |
| 651 | ctx_isp->frame_id); |
| 652 | } else { |
| 653 | CAM_ERR(CAM_ISP, "Can not notify EOF to CRM"); |
| 654 | rc = -EFAULT; |
| 655 | } |
| 656 | |
| 657 | return rc; |
| 658 | } |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 659 | |
Alok Pandey | fdfa5ba | 2017-09-22 14:21:25 +0530 | [diff] [blame] | 660 | static int __cam_isp_ctx_reg_upd_in_hw_error( |
| 661 | struct cam_isp_context *ctx_isp, void *evt_data) |
| 662 | { |
| 663 | ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_SOF; |
| 664 | return 0; |
| 665 | } |
| 666 | |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 667 | static int __cam_isp_ctx_sof_in_activated_state( |
| 668 | struct cam_isp_context *ctx_isp, void *evt_data) |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 669 | { |
| 670 | int rc = 0; |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 671 | struct cam_isp_hw_sof_event_data *sof_event_data = evt_data; |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 672 | struct cam_ctx_request *req; |
| 673 | struct cam_context *ctx = ctx_isp->base; |
| 674 | |
| 675 | req = list_last_entry(&ctx->pending_req_list, |
| 676 | struct cam_ctx_request, list); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 677 | |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 678 | if (!evt_data) { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 679 | CAM_ERR(CAM_ISP, "in valid sof event data"); |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 680 | return -EINVAL; |
| 681 | } |
| 682 | |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 683 | ctx_isp->frame_id++; |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 684 | ctx_isp->sof_timestamp_val = sof_event_data->timestamp; |
Karthik Anantha Ram | c93754c | 2018-03-28 14:21:14 -0700 | [diff] [blame] | 685 | ctx_isp->boot_timestamp = sof_event_data->boot_time; |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 686 | __cam_isp_ctx_update_state_monitor_array(ctx_isp, |
| 687 | CAM_ISP_STATE_CHANGE_TRIGGER_SOF, req->request_id); |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 688 | CAM_DBG(CAM_ISP, "frame id: %lld time stamp:0x%llx", |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 689 | ctx_isp->frame_id, ctx_isp->sof_timestamp_val); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 690 | |
| 691 | return rc; |
| 692 | } |
| 693 | |
| 694 | static int __cam_isp_ctx_reg_upd_in_sof(struct cam_isp_context *ctx_isp, |
| 695 | void *evt_data) |
| 696 | { |
| 697 | int rc = 0; |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 698 | struct cam_ctx_request *req = NULL; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 699 | struct cam_isp_ctx_req *req_isp; |
| 700 | struct cam_context *ctx = ctx_isp->base; |
| 701 | |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 702 | if (ctx->state != CAM_CTX_ACTIVATED && ctx_isp->frame_id > 1) { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 703 | CAM_DBG(CAM_ISP, "invalid RUP"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 704 | goto end; |
| 705 | } |
| 706 | |
| 707 | /* |
| 708 | * This is for the first update. The initial setting will |
| 709 | * cause the reg_upd in the first frame. |
| 710 | */ |
Junzhe Zou | e7d56fc | 2018-08-10 14:50:17 -0700 | [diff] [blame] | 711 | if (!list_empty(&ctx->wait_req_list)) { |
| 712 | req = list_first_entry(&ctx->wait_req_list, |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 713 | struct cam_ctx_request, list); |
| 714 | list_del_init(&req->list); |
| 715 | req_isp = (struct cam_isp_ctx_req *) req->req_priv; |
Junzhe Zou | e7d56fc | 2018-08-10 14:50:17 -0700 | [diff] [blame] | 716 | if (req_isp->num_fence_map_out == req_isp->num_acked) |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 717 | list_add_tail(&req->list, &ctx->free_req_list); |
Junzhe Zou | e7d56fc | 2018-08-10 14:50:17 -0700 | [diff] [blame] | 718 | else |
| 719 | CAM_ERR(CAM_ISP, |
| 720 | "receive rup in unexpected state"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 721 | } |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 722 | if (req != NULL) { |
| 723 | __cam_isp_ctx_update_state_monitor_array(ctx_isp, |
| 724 | CAM_ISP_STATE_CHANGE_TRIGGER_REG_UPDATE, |
| 725 | req->request_id); |
| 726 | } |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 727 | end: |
| 728 | return rc; |
| 729 | } |
| 730 | |
| 731 | static int __cam_isp_ctx_epoch_in_applied(struct cam_isp_context *ctx_isp, |
| 732 | void *evt_data) |
| 733 | { |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 734 | struct cam_ctx_request *req; |
| 735 | struct cam_isp_ctx_req *req_isp; |
| 736 | struct cam_context *ctx = ctx_isp->base; |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 737 | uint64_t request_id = 0; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 738 | |
Karthik Anantha Ram | 4cb91db | 2018-08-10 11:16:19 -0700 | [diff] [blame] | 739 | if (list_empty(&ctx->wait_req_list)) { |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 740 | /* |
Karthik Anantha Ram | 4cb91db | 2018-08-10 11:16:19 -0700 | [diff] [blame] | 741 | * If no wait req in epoch, this is an error case. |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 742 | * The recovery is to go back to sof state |
| 743 | */ |
Junzhe Zou | e7d56fc | 2018-08-10 14:50:17 -0700 | [diff] [blame] | 744 | CAM_ERR(CAM_ISP, "No wait request"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 745 | ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_SOF; |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 746 | |
| 747 | /* Send SOF event as empty frame*/ |
| 748 | __cam_isp_ctx_send_sof_timestamp(ctx_isp, request_id, |
| 749 | CAM_REQ_MGR_SOF_EVENT_SUCCESS); |
| 750 | |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 751 | goto end; |
| 752 | } |
| 753 | |
Karthik Anantha Ram | 4cb91db | 2018-08-10 11:16:19 -0700 | [diff] [blame] | 754 | req = list_first_entry(&ctx->wait_req_list, struct cam_ctx_request, |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 755 | list); |
| 756 | req_isp = (struct cam_isp_ctx_req *)req->req_priv; |
Junzhe Zou | 09820a7 | 2018-09-06 18:11:41 -0700 | [diff] [blame] | 757 | req_isp->bubble_detected = true; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 758 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 759 | CAM_DBG(CAM_ISP, "Report Bubble flag %d", req_isp->bubble_report); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 760 | if (req_isp->bubble_report && ctx->ctx_crm_intf && |
| 761 | ctx->ctx_crm_intf->notify_err) { |
| 762 | struct cam_req_mgr_error_notify notify; |
| 763 | |
| 764 | notify.link_hdl = ctx->link_hdl; |
| 765 | notify.dev_hdl = ctx->dev_hdl; |
| 766 | notify.req_id = req->request_id; |
| 767 | notify.error = CRM_KMD_ERR_BUBBLE; |
| 768 | ctx->ctx_crm_intf->notify_err(¬ify); |
Ayush Kumar | f13969a9 | 2019-07-18 13:02:43 +0530 | [diff] [blame] | 769 | atomic_set(&ctx_isp->process_bubble, 1); |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 770 | CAM_DBG(CAM_ISP, "Notify CRM about Bubble frame %lld", |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 771 | ctx_isp->frame_id); |
Jing Zhou | 45b55cc | 2017-05-16 17:27:18 -0700 | [diff] [blame] | 772 | } else { |
Jing Zhou | 45b55cc | 2017-05-16 17:27:18 -0700 | [diff] [blame] | 773 | req_isp->bubble_report = 0; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 774 | } |
| 775 | |
Junzhe Zou | 09820a7 | 2018-09-06 18:11:41 -0700 | [diff] [blame] | 776 | /* |
| 777 | * Always move the request to active list. Let buf done |
| 778 | * function handles the rest. |
| 779 | */ |
| 780 | CAM_DBG(CAM_REQ, "move request %lld to active list(cnt = %d)", |
| 781 | req->request_id, ctx_isp->active_req_cnt); |
| 782 | ctx_isp->active_req_cnt++; |
| 783 | list_del_init(&req->list); |
| 784 | list_add_tail(&req->list, &ctx->active_req_list); |
| 785 | |
Ravikishore Pampana | 6648f17 | 2017-12-08 20:29:11 +0530 | [diff] [blame] | 786 | if (req->request_id > ctx_isp->reported_req_id) { |
| 787 | request_id = req->request_id; |
| 788 | ctx_isp->reported_req_id = request_id; |
| 789 | } |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 790 | __cam_isp_ctx_send_sof_timestamp(ctx_isp, request_id, |
| 791 | CAM_REQ_MGR_SOF_EVENT_ERROR); |
| 792 | |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 793 | ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_BUBBLE; |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 794 | CAM_DBG(CAM_ISP, "next substate %d", |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 795 | ctx_isp->substate_activated); |
| 796 | end: |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 797 | if (request_id == 0) { |
| 798 | req = list_last_entry(&ctx->active_req_list, |
| 799 | struct cam_ctx_request, list); |
| 800 | __cam_isp_ctx_update_state_monitor_array(ctx_isp, |
| 801 | CAM_ISP_STATE_CHANGE_TRIGGER_EPOCH, req->request_id); |
| 802 | } else { |
| 803 | __cam_isp_ctx_update_state_monitor_array(ctx_isp, |
| 804 | CAM_ISP_STATE_CHANGE_TRIGGER_EPOCH, request_id); |
| 805 | } |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 806 | return 0; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | |
| 810 | static int __cam_isp_ctx_buf_done_in_applied(struct cam_isp_context *ctx_isp, |
| 811 | void *evt_data) |
| 812 | { |
| 813 | int rc = 0; |
| 814 | struct cam_isp_hw_done_event_data *done = |
| 815 | (struct cam_isp_hw_done_event_data *) evt_data; |
| 816 | |
| 817 | rc = __cam_isp_ctx_handle_buf_done_in_activated_state(ctx_isp, done, 0); |
| 818 | return rc; |
| 819 | } |
| 820 | |
| 821 | |
| 822 | static int __cam_isp_ctx_sof_in_epoch(struct cam_isp_context *ctx_isp, |
| 823 | void *evt_data) |
| 824 | { |
| 825 | int rc = 0; |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 826 | struct cam_context *ctx = ctx_isp->base; |
| 827 | struct cam_isp_hw_sof_event_data *sof_event_data = evt_data; |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 828 | struct cam_ctx_request *req; |
Jing Zhou | 93b3ec1 | 2017-06-15 17:43:39 -0700 | [diff] [blame] | 829 | |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 830 | if (!evt_data) { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 831 | CAM_ERR(CAM_ISP, "in valid sof event data"); |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 832 | return -EINVAL; |
| 833 | } |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 834 | |
| 835 | ctx_isp->frame_id++; |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 836 | ctx_isp->sof_timestamp_val = sof_event_data->timestamp; |
Karthik Anantha Ram | c93754c | 2018-03-28 14:21:14 -0700 | [diff] [blame] | 837 | ctx_isp->boot_timestamp = sof_event_data->boot_time; |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 838 | |
Jing Zhou | 93b3ec1 | 2017-06-15 17:43:39 -0700 | [diff] [blame] | 839 | if (list_empty(&ctx->active_req_list)) |
| 840 | ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_SOF; |
| 841 | else |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 842 | CAM_DBG(CAM_ISP, "Still need to wait for the buf done"); |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 843 | |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 844 | req = list_last_entry(&ctx->active_req_list, |
| 845 | struct cam_ctx_request, list); |
Junzhe Zou | e7d56fc | 2018-08-10 14:50:17 -0700 | [diff] [blame] | 846 | if (req) |
| 847 | __cam_isp_ctx_update_state_monitor_array(ctx_isp, |
| 848 | CAM_ISP_STATE_CHANGE_TRIGGER_SOF, |
| 849 | ctx->req_list->request_id); |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 850 | CAM_DBG(CAM_ISP, "next substate %d", |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 851 | ctx_isp->substate_activated); |
| 852 | |
| 853 | return rc; |
| 854 | } |
| 855 | |
| 856 | static int __cam_isp_ctx_buf_done_in_epoch(struct cam_isp_context *ctx_isp, |
| 857 | void *evt_data) |
| 858 | { |
| 859 | int rc = 0; |
| 860 | struct cam_isp_hw_done_event_data *done = |
| 861 | (struct cam_isp_hw_done_event_data *) evt_data; |
| 862 | |
| 863 | rc = __cam_isp_ctx_handle_buf_done_in_activated_state(ctx_isp, done, 0); |
| 864 | return rc; |
| 865 | } |
| 866 | |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 867 | static int __cam_isp_ctx_buf_done_in_bubble( |
| 868 | struct cam_isp_context *ctx_isp, void *evt_data) |
| 869 | { |
| 870 | int rc = 0; |
| 871 | struct cam_isp_hw_done_event_data *done = |
| 872 | (struct cam_isp_hw_done_event_data *) evt_data; |
| 873 | |
| 874 | rc = __cam_isp_ctx_handle_buf_done_in_activated_state(ctx_isp, done, 1); |
| 875 | return rc; |
| 876 | } |
| 877 | |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 878 | static int __cam_isp_ctx_epoch_in_bubble_applied( |
| 879 | struct cam_isp_context *ctx_isp, void *evt_data) |
| 880 | { |
| 881 | struct cam_ctx_request *req; |
| 882 | struct cam_isp_ctx_req *req_isp; |
| 883 | struct cam_context *ctx = ctx_isp->base; |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 884 | uint64_t request_id = 0; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 885 | |
| 886 | /* |
| 887 | * This means we missed the reg upd ack. So we need to |
| 888 | * transition to BUBBLE state again. |
| 889 | */ |
| 890 | |
Junzhe Zou | e7d56fc | 2018-08-10 14:50:17 -0700 | [diff] [blame] | 891 | if (list_empty(&ctx->wait_req_list)) { |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 892 | /* |
| 893 | * If no pending req in epoch, this is an error case. |
| 894 | * Just go back to the bubble state. |
| 895 | */ |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 896 | CAM_ERR(CAM_ISP, "No pending request."); |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 897 | __cam_isp_ctx_send_sof_timestamp(ctx_isp, request_id, |
| 898 | CAM_REQ_MGR_SOF_EVENT_SUCCESS); |
| 899 | |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 900 | ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_BUBBLE; |
| 901 | goto end; |
| 902 | } |
| 903 | |
Junzhe Zou | e7d56fc | 2018-08-10 14:50:17 -0700 | [diff] [blame] | 904 | req = list_first_entry(&ctx->wait_req_list, struct cam_ctx_request, |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 905 | list); |
| 906 | req_isp = (struct cam_isp_ctx_req *)req->req_priv; |
Junzhe Zou | 09820a7 | 2018-09-06 18:11:41 -0700 | [diff] [blame] | 907 | req_isp->bubble_detected = true; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 908 | |
| 909 | if (req_isp->bubble_report && ctx->ctx_crm_intf && |
| 910 | ctx->ctx_crm_intf->notify_err) { |
| 911 | struct cam_req_mgr_error_notify notify; |
| 912 | |
| 913 | notify.link_hdl = ctx->link_hdl; |
| 914 | notify.dev_hdl = ctx->dev_hdl; |
| 915 | notify.req_id = req->request_id; |
| 916 | notify.error = CRM_KMD_ERR_BUBBLE; |
| 917 | ctx->ctx_crm_intf->notify_err(¬ify); |
Karthik Anantha Ram | 5438d57 | 2018-06-15 10:48:19 -0700 | [diff] [blame] | 918 | CAM_DBG(CAM_REQ, |
| 919 | "Notify CRM about Bubble req_id %llu frame %lld", |
| 920 | req->request_id, ctx_isp->frame_id); |
Jing Zhou | 45b55cc | 2017-05-16 17:27:18 -0700 | [diff] [blame] | 921 | } else { |
Jing Zhou | 45b55cc | 2017-05-16 17:27:18 -0700 | [diff] [blame] | 922 | req_isp->bubble_report = 0; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 923 | } |
| 924 | |
Junzhe Zou | 09820a7 | 2018-09-06 18:11:41 -0700 | [diff] [blame] | 925 | /* |
| 926 | * Always move the request to active list. Let buf done |
| 927 | * function handles the rest. |
| 928 | */ |
| 929 | CAM_DBG(CAM_ISP, "move request %lld to active list(cnt = %d)", |
| 930 | req->request_id, ctx_isp->active_req_cnt); |
| 931 | ctx_isp->active_req_cnt++; |
| 932 | list_del_init(&req->list); |
| 933 | list_add_tail(&req->list, &ctx->active_req_list); |
| 934 | |
Ravikishore Pampana | 6648f17 | 2017-12-08 20:29:11 +0530 | [diff] [blame] | 935 | if (!req_isp->bubble_report) { |
| 936 | if (req->request_id > ctx_isp->reported_req_id) { |
| 937 | request_id = req->request_id; |
| 938 | ctx_isp->reported_req_id = request_id; |
| 939 | __cam_isp_ctx_send_sof_timestamp(ctx_isp, request_id, |
| 940 | CAM_REQ_MGR_SOF_EVENT_ERROR); |
| 941 | } else |
| 942 | __cam_isp_ctx_send_sof_timestamp(ctx_isp, request_id, |
| 943 | CAM_REQ_MGR_SOF_EVENT_SUCCESS); |
| 944 | } else |
| 945 | __cam_isp_ctx_send_sof_timestamp(ctx_isp, request_id, |
| 946 | CAM_REQ_MGR_SOF_EVENT_SUCCESS); |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 947 | |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 948 | ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_BUBBLE; |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 949 | CAM_DBG(CAM_ISP, "next substate %d", ctx_isp->substate_activated); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 950 | end: |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 951 | req = list_last_entry(&ctx->active_req_list, struct cam_ctx_request, |
| 952 | list); |
Junzhe Zou | e7d56fc | 2018-08-10 14:50:17 -0700 | [diff] [blame] | 953 | if (req) |
| 954 | __cam_isp_ctx_update_state_monitor_array(ctx_isp, |
| 955 | CAM_ISP_STATE_CHANGE_TRIGGER_EPOCH, req->request_id); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 956 | return 0; |
| 957 | } |
| 958 | |
| 959 | static int __cam_isp_ctx_buf_done_in_bubble_applied( |
| 960 | struct cam_isp_context *ctx_isp, void *evt_data) |
| 961 | { |
| 962 | int rc = 0; |
| 963 | struct cam_isp_hw_done_event_data *done = |
| 964 | (struct cam_isp_hw_done_event_data *) evt_data; |
| 965 | |
| 966 | rc = __cam_isp_ctx_handle_buf_done_in_activated_state(ctx_isp, done, 1); |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 967 | __cam_isp_ctx_update_state_monitor_array(ctx_isp, |
| 968 | CAM_ISP_STATE_CHANGE_TRIGGER_DONE, |
| 969 | ctx_isp->base->req_list->request_id); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 970 | return rc; |
| 971 | } |
| 972 | |
| 973 | static int __cam_isp_ctx_handle_error(struct cam_isp_context *ctx_isp, |
| 974 | void *evt_data) |
| 975 | { |
| 976 | int rc = 0; |
Alok Pandey | fdfa5ba | 2017-09-22 14:21:25 +0530 | [diff] [blame] | 977 | uint32_t i = 0; |
| 978 | bool found = 0; |
| 979 | struct cam_ctx_request *req = NULL; |
| 980 | struct cam_ctx_request *req_temp; |
| 981 | struct cam_isp_ctx_req *req_isp = NULL; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 982 | struct cam_req_mgr_error_notify notify; |
Alok Pandey | fdfa5ba | 2017-09-22 14:21:25 +0530 | [diff] [blame] | 983 | uint64_t error_request_id; |
Vishalsingh Hajeri | 7a431b7 | 2018-03-01 14:07:24 -0800 | [diff] [blame] | 984 | struct cam_hw_fence_map_entry *fence_map_out = NULL; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 985 | |
| 986 | struct cam_context *ctx = ctx_isp->base; |
| 987 | struct cam_isp_hw_error_event_data *error_event_data = |
| 988 | (struct cam_isp_hw_error_event_data *)evt_data; |
| 989 | |
| 990 | uint32_t error_type = error_event_data->error_type; |
| 991 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 992 | CAM_DBG(CAM_ISP, "Enter error_type = %d", error_type); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 993 | if ((error_type == CAM_ISP_HW_ERROR_OVERFLOW) || |
| 994 | (error_type == CAM_ISP_HW_ERROR_BUSIF_OVERFLOW)) |
Alok Pandey | fdfa5ba | 2017-09-22 14:21:25 +0530 | [diff] [blame] | 995 | notify.error = CRM_KMD_ERR_OVERFLOW; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 996 | |
| 997 | /* |
| 998 | * Need to check the active req |
| 999 | * move all of them to the pending request list |
| 1000 | * Note this funciton need revisit! |
| 1001 | */ |
| 1002 | |
| 1003 | if (list_empty(&ctx->active_req_list)) { |
Harsh Shah | cb0072c | 2017-09-26 19:22:10 -0700 | [diff] [blame] | 1004 | CAM_ERR_RATE_LIMIT(CAM_ISP, |
| 1005 | "handling error with no active request"); |
Alok Pandey | fdfa5ba | 2017-09-22 14:21:25 +0530 | [diff] [blame] | 1006 | } else { |
| 1007 | list_for_each_entry_safe(req, req_temp, |
| 1008 | &ctx->active_req_list, list) { |
| 1009 | req_isp = (struct cam_isp_ctx_req *) req->req_priv; |
| 1010 | if (!req_isp->bubble_report) { |
| 1011 | for (i = 0; i < req_isp->num_fence_map_out; |
| 1012 | i++) { |
Vishalsingh Hajeri | 7a431b7 | 2018-03-01 14:07:24 -0800 | [diff] [blame] | 1013 | fence_map_out = |
| 1014 | &req_isp->fence_map_out[i]; |
Alok Pandey | fdfa5ba | 2017-09-22 14:21:25 +0530 | [diff] [blame] | 1015 | CAM_ERR(CAM_ISP, "req %llu, Sync fd %x", |
Vishalsingh Hajeri | 7a431b7 | 2018-03-01 14:07:24 -0800 | [diff] [blame] | 1016 | req->request_id, |
| 1017 | req_isp->fence_map_out[i].sync_id); |
Alok Pandey | fdfa5ba | 2017-09-22 14:21:25 +0530 | [diff] [blame] | 1018 | if (req_isp->fence_map_out[i].sync_id |
| 1019 | != -1) { |
| 1020 | rc = cam_sync_signal( |
Vishalsingh Hajeri | 7a431b7 | 2018-03-01 14:07:24 -0800 | [diff] [blame] | 1021 | fence_map_out->sync_id, |
Alok Pandey | fdfa5ba | 2017-09-22 14:21:25 +0530 | [diff] [blame] | 1022 | CAM_SYNC_STATE_SIGNALED_ERROR); |
Vishalsingh Hajeri | 7a431b7 | 2018-03-01 14:07:24 -0800 | [diff] [blame] | 1023 | fence_map_out->sync_id = |
| 1024 | -1; |
Alok Pandey | fdfa5ba | 2017-09-22 14:21:25 +0530 | [diff] [blame] | 1025 | } |
| 1026 | } |
| 1027 | list_del_init(&req->list); |
| 1028 | list_add_tail(&req->list, &ctx->free_req_list); |
| 1029 | ctx_isp->active_req_cnt--; |
| 1030 | } else { |
| 1031 | found = 1; |
| 1032 | break; |
| 1033 | } |
| 1034 | } |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1035 | } |
| 1036 | |
Alok Pandey | fdfa5ba | 2017-09-22 14:21:25 +0530 | [diff] [blame] | 1037 | if (found) { |
| 1038 | list_for_each_entry_safe_reverse(req, req_temp, |
| 1039 | &ctx->active_req_list, list) { |
| 1040 | req_isp = (struct cam_isp_ctx_req *) req->req_priv; |
| 1041 | list_del_init(&req->list); |
| 1042 | list_add(&req->list, &ctx->pending_req_list); |
| 1043 | ctx_isp->active_req_cnt--; |
| 1044 | } |
| 1045 | } |
| 1046 | |
| 1047 | do { |
| 1048 | if (list_empty(&ctx->pending_req_list)) { |
| 1049 | error_request_id = ctx_isp->last_applied_req_id + 1; |
| 1050 | req_isp = NULL; |
| 1051 | break; |
| 1052 | } |
| 1053 | req = list_first_entry(&ctx->pending_req_list, |
| 1054 | struct cam_ctx_request, list); |
| 1055 | req_isp = (struct cam_isp_ctx_req *) req->req_priv; |
| 1056 | error_request_id = ctx_isp->last_applied_req_id; |
| 1057 | |
| 1058 | if (req_isp->bubble_report) |
| 1059 | break; |
| 1060 | |
| 1061 | for (i = 0; i < req_isp->num_fence_map_out; i++) { |
| 1062 | if (req_isp->fence_map_out[i].sync_id != -1) |
| 1063 | rc = cam_sync_signal( |
| 1064 | req_isp->fence_map_out[i].sync_id, |
| 1065 | CAM_SYNC_STATE_SIGNALED_ERROR); |
| 1066 | req_isp->fence_map_out[i].sync_id = -1; |
| 1067 | } |
| 1068 | list_del_init(&req->list); |
| 1069 | list_add_tail(&req->list, &ctx->free_req_list); |
| 1070 | |
| 1071 | } while (req->request_id < ctx_isp->last_applied_req_id); |
| 1072 | |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1073 | |
| 1074 | if (ctx->ctx_crm_intf && ctx->ctx_crm_intf->notify_err) { |
| 1075 | notify.link_hdl = ctx->link_hdl; |
| 1076 | notify.dev_hdl = ctx->dev_hdl; |
Alok Pandey | fdfa5ba | 2017-09-22 14:21:25 +0530 | [diff] [blame] | 1077 | notify.req_id = error_request_id; |
| 1078 | |
| 1079 | if (req_isp && req_isp->bubble_report) |
| 1080 | notify.error = CRM_KMD_ERR_BUBBLE; |
| 1081 | |
| 1082 | CAM_WARN(CAM_ISP, "Notify CRM: req %lld, frame %lld\n", |
| 1083 | error_request_id, ctx_isp->frame_id); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1084 | |
| 1085 | ctx->ctx_crm_intf->notify_err(¬ify); |
Alok Pandey | fdfa5ba | 2017-09-22 14:21:25 +0530 | [diff] [blame] | 1086 | ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_HW_ERROR; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1087 | } else { |
Harsh Shah | cb0072c | 2017-09-26 19:22:10 -0700 | [diff] [blame] | 1088 | CAM_ERR_RATE_LIMIT(CAM_ISP, "Can not notify ERRROR to CRM"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1089 | rc = -EFAULT; |
| 1090 | } |
| 1091 | |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 1092 | |
| 1093 | list_del_init(&req->list); |
| 1094 | list_add(&req->list, &ctx->pending_req_list); |
| 1095 | /* might need to check if active list is empty */ |
| 1096 | if (req != NULL) { |
| 1097 | __cam_isp_ctx_update_state_monitor_array(ctx_isp, |
| 1098 | CAM_ISP_STATE_CHANGE_TRIGGER_ERROR, req->request_id); |
| 1099 | } |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1100 | CAM_DBG(CAM_ISP, "Exit"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1101 | return rc; |
| 1102 | } |
| 1103 | |
| 1104 | static struct cam_isp_ctx_irq_ops |
| 1105 | cam_isp_ctx_activated_state_machine_irq[CAM_ISP_CTX_ACTIVATED_MAX] = { |
| 1106 | /* SOF */ |
| 1107 | { |
| 1108 | .irq_ops = { |
Alok Pandey | fdfa5ba | 2017-09-22 14:21:25 +0530 | [diff] [blame] | 1109 | __cam_isp_ctx_handle_error, |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 1110 | __cam_isp_ctx_sof_in_activated_state, |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1111 | __cam_isp_ctx_reg_upd_in_sof, |
| 1112 | __cam_isp_ctx_notify_sof_in_actived_state, |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1113 | __cam_isp_ctx_notify_eof_in_actived_state, |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1114 | NULL, |
| 1115 | }, |
| 1116 | }, |
| 1117 | /* APPLIED */ |
| 1118 | { |
| 1119 | .irq_ops = { |
| 1120 | __cam_isp_ctx_handle_error, |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 1121 | __cam_isp_ctx_sof_in_activated_state, |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1122 | __cam_isp_ctx_reg_upd_in_activated_state, |
| 1123 | __cam_isp_ctx_epoch_in_applied, |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1124 | __cam_isp_ctx_notify_eof_in_actived_state, |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1125 | __cam_isp_ctx_buf_done_in_applied, |
| 1126 | }, |
| 1127 | }, |
| 1128 | /* EPOCH */ |
| 1129 | { |
| 1130 | .irq_ops = { |
| 1131 | __cam_isp_ctx_handle_error, |
| 1132 | __cam_isp_ctx_sof_in_epoch, |
Karthik Anantha Ram | 1532607 | 2018-05-18 14:47:00 -0700 | [diff] [blame] | 1133 | __cam_isp_ctx_reg_upd_in_epoch_state, |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1134 | __cam_isp_ctx_notify_sof_in_actived_state, |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1135 | __cam_isp_ctx_notify_eof_in_actived_state, |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1136 | __cam_isp_ctx_buf_done_in_epoch, |
| 1137 | }, |
| 1138 | }, |
| 1139 | /* BUBBLE */ |
| 1140 | { |
| 1141 | .irq_ops = { |
Alok Pandey | fdfa5ba | 2017-09-22 14:21:25 +0530 | [diff] [blame] | 1142 | __cam_isp_ctx_handle_error, |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 1143 | __cam_isp_ctx_sof_in_activated_state, |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1144 | NULL, |
| 1145 | __cam_isp_ctx_notify_sof_in_actived_state, |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1146 | __cam_isp_ctx_notify_eof_in_actived_state, |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1147 | __cam_isp_ctx_buf_done_in_bubble, |
| 1148 | }, |
| 1149 | }, |
| 1150 | /* Bubble Applied */ |
| 1151 | { |
| 1152 | .irq_ops = { |
Alok Pandey | fdfa5ba | 2017-09-22 14:21:25 +0530 | [diff] [blame] | 1153 | __cam_isp_ctx_handle_error, |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 1154 | __cam_isp_ctx_sof_in_activated_state, |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1155 | __cam_isp_ctx_reg_upd_in_activated_state, |
| 1156 | __cam_isp_ctx_epoch_in_bubble_applied, |
| 1157 | NULL, |
| 1158 | __cam_isp_ctx_buf_done_in_bubble_applied, |
| 1159 | }, |
| 1160 | }, |
Alok Pandey | fdfa5ba | 2017-09-22 14:21:25 +0530 | [diff] [blame] | 1161 | /* HW ERROR */ |
| 1162 | { |
| 1163 | .irq_ops = { |
| 1164 | NULL, |
| 1165 | __cam_isp_ctx_sof_in_activated_state, |
| 1166 | __cam_isp_ctx_reg_upd_in_hw_error, |
| 1167 | NULL, |
| 1168 | NULL, |
| 1169 | NULL, |
| 1170 | }, |
| 1171 | }, |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1172 | /* HALT */ |
| 1173 | { |
| 1174 | }, |
| 1175 | }; |
| 1176 | |
| 1177 | static int __cam_isp_ctx_apply_req_in_activated_state( |
| 1178 | struct cam_context *ctx, struct cam_req_mgr_apply_request *apply, |
| 1179 | uint32_t next_state) |
| 1180 | { |
| 1181 | int rc = 0; |
| 1182 | struct cam_ctx_request *req; |
Karthik Anantha Ram | b947440 | 2018-08-27 16:14:56 -0700 | [diff] [blame] | 1183 | struct cam_ctx_request *active_req = NULL; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1184 | struct cam_isp_ctx_req *req_isp; |
Harsh Shah | 1b8eb23 | 2017-10-09 19:20:52 -0700 | [diff] [blame] | 1185 | struct cam_isp_ctx_req *active_req_isp; |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 1186 | struct cam_isp_context *ctx_isp = NULL; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1187 | struct cam_hw_config_args cfg; |
| 1188 | |
| 1189 | if (list_empty(&ctx->pending_req_list)) { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1190 | CAM_ERR(CAM_ISP, "No available request for Apply id %lld", |
| 1191 | apply->request_id); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1192 | rc = -EFAULT; |
| 1193 | goto end; |
| 1194 | } |
Jing Zhou | 9eabf47 | 2017-05-16 11:59:41 -0700 | [diff] [blame] | 1195 | |
| 1196 | /* |
| 1197 | * When the pipeline has issue, the requests can be queued up in the |
| 1198 | * pipeline. In this case, we should reject the additional request. |
| 1199 | * The maximum number of request allowed to be outstanding is 2. |
| 1200 | * |
| 1201 | */ |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 1202 | ctx_isp = (struct cam_isp_context *) ctx->ctx_priv; |
Ayush Kumar | f13969a9 | 2019-07-18 13:02:43 +0530 | [diff] [blame] | 1203 | if (atomic_read(&ctx_isp->process_bubble)) { |
| 1204 | CAM_ERR_RATE_LIMIT(CAM_ISP, |
| 1205 | "Processing bubble cannot apply Request Id %llu", |
| 1206 | apply->request_id); |
| 1207 | rc = -EAGAIN; |
| 1208 | goto end; |
| 1209 | } |
| 1210 | |
Karthik Anantha Ram | b947440 | 2018-08-27 16:14:56 -0700 | [diff] [blame] | 1211 | spin_lock_bh(&ctx->lock); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1212 | req = list_first_entry(&ctx->pending_req_list, struct cam_ctx_request, |
| 1213 | list); |
Karthik Anantha Ram | b947440 | 2018-08-27 16:14:56 -0700 | [diff] [blame] | 1214 | spin_unlock_bh(&ctx->lock); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1215 | |
| 1216 | /* |
| 1217 | * Check whehter the request id is matching the tip, if not, this means |
| 1218 | * we are in the middle of the error handling. Need to reject this apply |
| 1219 | */ |
| 1220 | if (req->request_id != apply->request_id) { |
Harsh Shah | f713639 | 2017-08-29 12:42:52 -0700 | [diff] [blame] | 1221 | CAM_ERR_RATE_LIMIT(CAM_ISP, |
| 1222 | "Invalid Request Id asking %llu existing %llu", |
| 1223 | apply->request_id, req->request_id); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1224 | rc = -EFAULT; |
| 1225 | goto end; |
| 1226 | } |
| 1227 | |
Karthik Anantha Ram | 5438d57 | 2018-06-15 10:48:19 -0700 | [diff] [blame] | 1228 | CAM_DBG(CAM_REQ, "Apply request %lld in substate %d", req->request_id, |
| 1229 | ctx_isp->substate_activated); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1230 | req_isp = (struct cam_isp_ctx_req *) req->req_priv; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1231 | |
Chandan Gera | 5c1e31b | 2018-12-09 07:44:05 +0530 | [diff] [blame] | 1232 | if (ctx_isp->active_req_cnt >= 4) { |
Karthik Anantha Ram | ba3bd97 | 2017-09-25 15:35:26 -0700 | [diff] [blame] | 1233 | CAM_ERR_RATE_LIMIT(CAM_ISP, |
Harsh Shah | 1b8eb23 | 2017-10-09 19:20:52 -0700 | [diff] [blame] | 1234 | "Reject apply request (id %lld) due to congestion(cnt = %d)", |
| 1235 | req->request_id, |
Karthik Anantha Ram | ba3bd97 | 2017-09-25 15:35:26 -0700 | [diff] [blame] | 1236 | ctx_isp->active_req_cnt); |
Karthik Anantha Ram | b947440 | 2018-08-27 16:14:56 -0700 | [diff] [blame] | 1237 | |
| 1238 | spin_lock_bh(&ctx->lock); |
| 1239 | if (!list_empty(&ctx->active_req_list)) |
Harsh Shah | 1b8eb23 | 2017-10-09 19:20:52 -0700 | [diff] [blame] | 1240 | active_req = list_first_entry(&ctx->active_req_list, |
| 1241 | struct cam_ctx_request, list); |
Karthik Anantha Ram | b947440 | 2018-08-27 16:14:56 -0700 | [diff] [blame] | 1242 | else |
Harsh Shah | 1b8eb23 | 2017-10-09 19:20:52 -0700 | [diff] [blame] | 1243 | CAM_ERR_RATE_LIMIT(CAM_ISP, |
| 1244 | "WARNING: should not happen (cnt = %d) but active_list empty", |
| 1245 | ctx_isp->active_req_cnt); |
Karthik Anantha Ram | b947440 | 2018-08-27 16:14:56 -0700 | [diff] [blame] | 1246 | spin_unlock_bh(&ctx->lock); |
| 1247 | |
| 1248 | if (active_req) { |
| 1249 | active_req_isp = |
| 1250 | (struct cam_isp_ctx_req *) active_req->req_priv; |
| 1251 | __cam_isp_ctx_handle_buf_done_fail_log(active_req_isp); |
Harsh Shah | 1b8eb23 | 2017-10-09 19:20:52 -0700 | [diff] [blame] | 1252 | } |
Karthik Anantha Ram | b947440 | 2018-08-27 16:14:56 -0700 | [diff] [blame] | 1253 | |
| 1254 | rc = -EFAULT; |
| 1255 | goto end; |
Karthik Anantha Ram | ba3bd97 | 2017-09-25 15:35:26 -0700 | [diff] [blame] | 1256 | } |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1257 | req_isp->bubble_report = apply->report_if_bubble; |
| 1258 | |
| 1259 | cfg.ctxt_to_hw_map = ctx_isp->hw_ctx; |
Venkat Chinta | d983df8 | 2018-03-14 12:54:40 -0700 | [diff] [blame] | 1260 | cfg.request_id = req->request_id; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1261 | cfg.hw_update_entries = req_isp->cfg; |
| 1262 | cfg.num_hw_update_entries = req_isp->num_cfg; |
Vishalsingh Hajeri | e5450be | 2018-01-18 20:31:19 -0800 | [diff] [blame] | 1263 | cfg.priv = &req_isp->hw_update_data; |
Junzhe Zou | 4d505a5 | 2018-04-10 14:43:33 -0700 | [diff] [blame] | 1264 | cfg.init_packet = 0; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1265 | |
| 1266 | rc = ctx->hw_mgr_intf->hw_config(ctx->hw_mgr_intf->hw_mgr_priv, &cfg); |
| 1267 | if (rc) { |
Harsh Shah | cb0072c | 2017-09-26 19:22:10 -0700 | [diff] [blame] | 1268 | CAM_ERR_RATE_LIMIT(CAM_ISP, "Can not apply the configuration"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1269 | } else { |
Jing Zhou | 93b3ec1 | 2017-06-15 17:43:39 -0700 | [diff] [blame] | 1270 | spin_lock_bh(&ctx->lock); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1271 | ctx_isp->substate_activated = next_state; |
Alok Pandey | fdfa5ba | 2017-09-22 14:21:25 +0530 | [diff] [blame] | 1272 | ctx_isp->last_applied_req_id = apply->request_id; |
Junzhe Zou | fdcd472 | 2018-06-11 18:05:33 -0700 | [diff] [blame] | 1273 | list_del_init(&req->list); |
| 1274 | list_add_tail(&req->list, &ctx->wait_req_list); |
Alok Pandey | fdfa5ba | 2017-09-22 14:21:25 +0530 | [diff] [blame] | 1275 | CAM_DBG(CAM_ISP, "new substate state %d, applied req %lld", |
| 1276 | next_state, ctx_isp->last_applied_req_id); |
Jing Zhou | 93b3ec1 | 2017-06-15 17:43:39 -0700 | [diff] [blame] | 1277 | spin_unlock_bh(&ctx->lock); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1278 | } |
| 1279 | end: |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 1280 | if (ctx_isp != NULL) { |
| 1281 | __cam_isp_ctx_update_state_monitor_array(ctx_isp, |
| 1282 | CAM_ISP_STATE_CHANGE_TRIGGER_SOF, |
| 1283 | ctx->req_list->request_id); |
| 1284 | } |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1285 | return rc; |
| 1286 | } |
| 1287 | |
| 1288 | static int __cam_isp_ctx_apply_req_in_sof( |
| 1289 | struct cam_context *ctx, struct cam_req_mgr_apply_request *apply) |
| 1290 | { |
| 1291 | int rc = 0; |
| 1292 | struct cam_isp_context *ctx_isp = |
| 1293 | (struct cam_isp_context *) ctx->ctx_priv; |
| 1294 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1295 | CAM_DBG(CAM_ISP, "current substate %d", |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1296 | ctx_isp->substate_activated); |
| 1297 | rc = __cam_isp_ctx_apply_req_in_activated_state(ctx, apply, |
| 1298 | CAM_ISP_CTX_ACTIVATED_APPLIED); |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1299 | CAM_DBG(CAM_ISP, "new substate %d", ctx_isp->substate_activated); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1300 | |
| 1301 | return rc; |
| 1302 | } |
| 1303 | |
| 1304 | static int __cam_isp_ctx_apply_req_in_epoch( |
| 1305 | struct cam_context *ctx, struct cam_req_mgr_apply_request *apply) |
| 1306 | { |
| 1307 | int rc = 0; |
| 1308 | struct cam_isp_context *ctx_isp = |
| 1309 | (struct cam_isp_context *) ctx->ctx_priv; |
| 1310 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1311 | CAM_DBG(CAM_ISP, "current substate %d", |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1312 | ctx_isp->substate_activated); |
| 1313 | rc = __cam_isp_ctx_apply_req_in_activated_state(ctx, apply, |
| 1314 | CAM_ISP_CTX_ACTIVATED_APPLIED); |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1315 | CAM_DBG(CAM_ISP, "new substate %d", ctx_isp->substate_activated); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1316 | |
| 1317 | return rc; |
| 1318 | } |
| 1319 | |
| 1320 | static int __cam_isp_ctx_apply_req_in_bubble( |
| 1321 | struct cam_context *ctx, struct cam_req_mgr_apply_request *apply) |
| 1322 | { |
| 1323 | int rc = 0; |
| 1324 | struct cam_isp_context *ctx_isp = |
| 1325 | (struct cam_isp_context *) ctx->ctx_priv; |
| 1326 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1327 | CAM_DBG(CAM_ISP, "current substate %d", |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1328 | ctx_isp->substate_activated); |
| 1329 | rc = __cam_isp_ctx_apply_req_in_activated_state(ctx, apply, |
| 1330 | CAM_ISP_CTX_ACTIVATED_BUBBLE_APPLIED); |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1331 | CAM_DBG(CAM_ISP, "new substate %d", ctx_isp->substate_activated); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1332 | |
| 1333 | return rc; |
| 1334 | } |
| 1335 | |
Jing Zhou | b524a85 | 2017-05-16 15:47:30 +0530 | [diff] [blame] | 1336 | static int __cam_isp_ctx_flush_req(struct cam_context *ctx, |
| 1337 | struct list_head *req_list, struct cam_req_mgr_flush_request *flush_req) |
| 1338 | { |
| 1339 | int i, rc; |
| 1340 | uint32_t cancel_req_id_found = 0; |
| 1341 | struct cam_ctx_request *req; |
| 1342 | struct cam_ctx_request *req_temp; |
| 1343 | struct cam_isp_ctx_req *req_isp; |
Alok Pandey | f308aec | 2018-01-22 18:10:59 +0530 | [diff] [blame] | 1344 | struct list_head flush_list; |
Jing Zhou | b524a85 | 2017-05-16 15:47:30 +0530 | [diff] [blame] | 1345 | |
Alok Pandey | f308aec | 2018-01-22 18:10:59 +0530 | [diff] [blame] | 1346 | INIT_LIST_HEAD(&flush_list); |
Jing Zhou | b524a85 | 2017-05-16 15:47:30 +0530 | [diff] [blame] | 1347 | if (list_empty(req_list)) { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1348 | CAM_DBG(CAM_ISP, "request list is empty"); |
Junzhe Zou | fdcd472 | 2018-06-11 18:05:33 -0700 | [diff] [blame] | 1349 | if (flush_req->type == CAM_REQ_MGR_FLUSH_TYPE_CANCEL_REQ) { |
| 1350 | CAM_ERR(CAM_ISP, "no request to cancel"); |
| 1351 | return -EINVAL; |
| 1352 | } else |
| 1353 | return 0; |
Jing Zhou | b524a85 | 2017-05-16 15:47:30 +0530 | [diff] [blame] | 1354 | } |
| 1355 | |
Karthik Anantha Ram | 5438d57 | 2018-06-15 10:48:19 -0700 | [diff] [blame] | 1356 | CAM_DBG(CAM_REQ, "Flush [%u] in progress for req_id %llu", |
| 1357 | flush_req->type, flush_req->req_id); |
Jing Zhou | b524a85 | 2017-05-16 15:47:30 +0530 | [diff] [blame] | 1358 | list_for_each_entry_safe(req, req_temp, req_list, list) { |
Alok Pandey | f308aec | 2018-01-22 18:10:59 +0530 | [diff] [blame] | 1359 | if (flush_req->type == CAM_REQ_MGR_FLUSH_TYPE_CANCEL_REQ) { |
| 1360 | if (req->request_id != flush_req->req_id) { |
| 1361 | continue; |
| 1362 | } else { |
| 1363 | list_del_init(&req->list); |
| 1364 | list_add_tail(&req->list, &flush_list); |
| 1365 | cancel_req_id_found = 1; |
| 1366 | break; |
| 1367 | } |
| 1368 | } |
Jing Zhou | b524a85 | 2017-05-16 15:47:30 +0530 | [diff] [blame] | 1369 | list_del_init(&req->list); |
Alok Pandey | f308aec | 2018-01-22 18:10:59 +0530 | [diff] [blame] | 1370 | list_add_tail(&req->list, &flush_list); |
| 1371 | } |
Alok Pandey | f308aec | 2018-01-22 18:10:59 +0530 | [diff] [blame] | 1372 | |
| 1373 | list_for_each_entry_safe(req, req_temp, &flush_list, list) { |
Jing Zhou | b524a85 | 2017-05-16 15:47:30 +0530 | [diff] [blame] | 1374 | req_isp = (struct cam_isp_ctx_req *) req->req_priv; |
| 1375 | for (i = 0; i < req_isp->num_fence_map_out; i++) { |
| 1376 | if (req_isp->fence_map_out[i].sync_id != -1) { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1377 | CAM_DBG(CAM_ISP, "Flush req 0x%llx, fence %d", |
| 1378 | req->request_id, |
Jing Zhou | b524a85 | 2017-05-16 15:47:30 +0530 | [diff] [blame] | 1379 | req_isp->fence_map_out[i].sync_id); |
| 1380 | rc = cam_sync_signal( |
| 1381 | req_isp->fence_map_out[i].sync_id, |
| 1382 | CAM_SYNC_STATE_SIGNALED_ERROR); |
| 1383 | if (rc) |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1384 | CAM_ERR_RATE_LIMIT(CAM_ISP, |
| 1385 | "signal fence failed\n"); |
Jing Zhou | b524a85 | 2017-05-16 15:47:30 +0530 | [diff] [blame] | 1386 | req_isp->fence_map_out[i].sync_id = -1; |
| 1387 | } |
| 1388 | } |
| 1389 | list_add_tail(&req->list, &ctx->free_req_list); |
Jing Zhou | b524a85 | 2017-05-16 15:47:30 +0530 | [diff] [blame] | 1390 | } |
Jing Zhou | b524a85 | 2017-05-16 15:47:30 +0530 | [diff] [blame] | 1391 | |
| 1392 | if (flush_req->type == CAM_REQ_MGR_FLUSH_TYPE_CANCEL_REQ && |
Vishalsingh Hajeri | 53ba6ff | 2018-05-09 18:07:15 -0700 | [diff] [blame] | 1393 | !cancel_req_id_found) { |
| 1394 | CAM_INFO(CAM_ISP, |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1395 | "Flush request id:%lld is not found in the list", |
| 1396 | flush_req->req_id); |
Vishalsingh Hajeri | 53ba6ff | 2018-05-09 18:07:15 -0700 | [diff] [blame] | 1397 | return -EINVAL; |
| 1398 | } |
Jing Zhou | b524a85 | 2017-05-16 15:47:30 +0530 | [diff] [blame] | 1399 | |
| 1400 | return 0; |
| 1401 | } |
| 1402 | |
| 1403 | static int __cam_isp_ctx_flush_req_in_top_state( |
| 1404 | struct cam_context *ctx, |
| 1405 | struct cam_req_mgr_flush_request *flush_req) |
| 1406 | { |
Alok Pandey | 12ce5ba | 2018-07-03 14:34:22 +0530 | [diff] [blame] | 1407 | struct cam_isp_context *ctx_isp = |
| 1408 | (struct cam_isp_context *) ctx->ctx_priv; |
| 1409 | struct cam_isp_stop_args stop_isp; |
| 1410 | struct cam_hw_stop_args stop_args; |
| 1411 | struct cam_isp_start_args start_isp; |
Mangalaram ARCHANA | c91892a | 2019-07-12 14:47:01 +0530 | [diff] [blame] | 1412 | struct cam_hw_reset_args reset_args; |
Jing Zhou | b524a85 | 2017-05-16 15:47:30 +0530 | [diff] [blame] | 1413 | int rc = 0; |
| 1414 | |
Mangalaram ARCHANA | c91892a | 2019-07-12 14:47:01 +0530 | [diff] [blame] | 1415 | CAM_DBG(CAM_ISP, "ctx id:%d try to flush pending list", |
| 1416 | ctx->ctx_id); |
Venkat Chinta | c8e610f | 2018-05-08 17:40:44 -0700 | [diff] [blame] | 1417 | spin_lock_bh(&ctx->lock); |
Jing Zhou | b524a85 | 2017-05-16 15:47:30 +0530 | [diff] [blame] | 1418 | rc = __cam_isp_ctx_flush_req(ctx, &ctx->pending_req_list, flush_req); |
Venkat Chinta | c8e610f | 2018-05-08 17:40:44 -0700 | [diff] [blame] | 1419 | spin_unlock_bh(&ctx->lock); |
Alok Pandey | 12ce5ba | 2018-07-03 14:34:22 +0530 | [diff] [blame] | 1420 | |
Ayush Kumar | f13969a9 | 2019-07-18 13:02:43 +0530 | [diff] [blame] | 1421 | atomic_set(&ctx_isp->process_bubble, 0); |
Shravya Samala | 43583ea | 2020-04-29 14:25:37 +0530 | [diff] [blame] | 1422 | atomic_set(&ctx_isp->bubble_sof_count, 0); |
Alok Pandey | 12ce5ba | 2018-07-03 14:34:22 +0530 | [diff] [blame] | 1423 | if (flush_req->type == CAM_REQ_MGR_FLUSH_TYPE_ALL) { |
| 1424 | /* if active and wait list are empty, return */ |
| 1425 | spin_lock_bh(&ctx->lock); |
| 1426 | if ((list_empty(&ctx->wait_req_list)) && |
| 1427 | (list_empty(&ctx->active_req_list))) { |
| 1428 | spin_unlock_bh(&ctx->lock); |
Mangalaram ARCHANA | c91892a | 2019-07-12 14:47:01 +0530 | [diff] [blame] | 1429 | CAM_DBG(CAM_ISP, |
| 1430 | "ctx id:%d active and wait list are empty", |
| 1431 | ctx->ctx_id); |
Alok Pandey | 12ce5ba | 2018-07-03 14:34:22 +0530 | [diff] [blame] | 1432 | goto end; |
| 1433 | } |
| 1434 | spin_unlock_bh(&ctx->lock); |
| 1435 | |
| 1436 | /* Stop hw first before active list flush */ |
| 1437 | stop_args.ctxt_to_hw_map = ctx_isp->hw_ctx; |
| 1438 | stop_isp.hw_stop_cmd = CAM_ISP_HW_STOP_AT_FRAME_BOUNDARY; |
| 1439 | stop_isp.stop_only = true; |
| 1440 | stop_args.args = (void *)&stop_isp; |
| 1441 | ctx->hw_mgr_intf->hw_stop(ctx->hw_mgr_intf->hw_mgr_priv, |
| 1442 | &stop_args); |
Mangalaram ARCHANA | c91892a | 2019-07-12 14:47:01 +0530 | [diff] [blame] | 1443 | CAM_DBG(CAM_ISP, "try to reset hw"); |
| 1444 | /* Reset hw */ |
| 1445 | reset_args.ctxt_to_hw_map = ctx_isp->hw_ctx; |
| 1446 | rc = ctx->hw_mgr_intf->hw_reset(ctx->hw_mgr_intf->hw_mgr_priv, |
| 1447 | &reset_args); |
| 1448 | if (rc) |
| 1449 | goto end; |
Alok Pandey | 12ce5ba | 2018-07-03 14:34:22 +0530 | [diff] [blame] | 1450 | |
| 1451 | spin_lock_bh(&ctx->lock); |
Mangalaram ARCHANA | c91892a | 2019-07-12 14:47:01 +0530 | [diff] [blame] | 1452 | CAM_DBG(CAM_ISP, "ctx id:%d try to flush wait list", |
| 1453 | ctx->ctx_id); |
Alok Pandey | 12ce5ba | 2018-07-03 14:34:22 +0530 | [diff] [blame] | 1454 | rc = __cam_isp_ctx_flush_req(ctx, &ctx->wait_req_list, |
| 1455 | flush_req); |
Mangalaram ARCHANA | c91892a | 2019-07-12 14:47:01 +0530 | [diff] [blame] | 1456 | CAM_DBG(CAM_ISP, "ctx id:%d try to flush active list", |
| 1457 | ctx->ctx_id); |
Alok Pandey | 12ce5ba | 2018-07-03 14:34:22 +0530 | [diff] [blame] | 1458 | rc = __cam_isp_ctx_flush_req(ctx, &ctx->active_req_list, |
| 1459 | flush_req); |
Junzhe Zou | 09820a7 | 2018-09-06 18:11:41 -0700 | [diff] [blame] | 1460 | ctx_isp->active_req_cnt = 0; |
Alok Pandey | 12ce5ba | 2018-07-03 14:34:22 +0530 | [diff] [blame] | 1461 | spin_unlock_bh(&ctx->lock); |
| 1462 | |
| 1463 | /* Start hw */ |
| 1464 | start_isp.hw_config.ctxt_to_hw_map = ctx_isp->hw_ctx; |
| 1465 | start_isp.start_only = true; |
| 1466 | start_isp.hw_config.priv = NULL; |
| 1467 | |
| 1468 | rc = ctx->hw_mgr_intf->hw_start(ctx->hw_mgr_intf->hw_mgr_priv, |
| 1469 | &start_isp); |
| 1470 | } |
| 1471 | |
| 1472 | end: |
Mangalaram ARCHANA | c91892a | 2019-07-12 14:47:01 +0530 | [diff] [blame] | 1473 | ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_SOF; |
| 1474 | CAM_DBG(CAM_ISP, "ctx id:%d Flush request in top state %d", |
| 1475 | ctx->ctx_id, ctx->state); |
Jing Zhou | b524a85 | 2017-05-16 15:47:30 +0530 | [diff] [blame] | 1476 | return rc; |
| 1477 | } |
| 1478 | |
| 1479 | static int __cam_isp_ctx_flush_req_in_ready( |
| 1480 | struct cam_context *ctx, |
| 1481 | struct cam_req_mgr_flush_request *flush_req) |
| 1482 | { |
| 1483 | int rc = 0; |
| 1484 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1485 | CAM_DBG(CAM_ISP, "try to flush pending list"); |
Venkat Chinta | c8e610f | 2018-05-08 17:40:44 -0700 | [diff] [blame] | 1486 | spin_lock_bh(&ctx->lock); |
Jing Zhou | b524a85 | 2017-05-16 15:47:30 +0530 | [diff] [blame] | 1487 | rc = __cam_isp_ctx_flush_req(ctx, &ctx->pending_req_list, flush_req); |
| 1488 | |
Alok Pandey | 12ce5ba | 2018-07-03 14:34:22 +0530 | [diff] [blame] | 1489 | /* if nothing is in pending req list, change state to acquire */ |
Jing Zhou | b524a85 | 2017-05-16 15:47:30 +0530 | [diff] [blame] | 1490 | if (list_empty(&ctx->pending_req_list)) |
| 1491 | ctx->state = CAM_CTX_ACQUIRED; |
Harsh Shah | 7835b3b | 2017-11-20 17:39:11 -0800 | [diff] [blame] | 1492 | spin_unlock_bh(&ctx->lock); |
Jing Zhou | b524a85 | 2017-05-16 15:47:30 +0530 | [diff] [blame] | 1493 | |
Gregory Bergschneider | 5164f3a | 2017-07-07 10:26:17 -0600 | [diff] [blame] | 1494 | trace_cam_context_state("ISP", ctx); |
| 1495 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1496 | CAM_DBG(CAM_ISP, "Flush request in ready state. next state %d", |
| 1497 | ctx->state); |
Jing Zhou | b524a85 | 2017-05-16 15:47:30 +0530 | [diff] [blame] | 1498 | return rc; |
| 1499 | } |
| 1500 | |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1501 | static struct cam_ctx_ops |
| 1502 | cam_isp_ctx_activated_state_machine[CAM_ISP_CTX_ACTIVATED_MAX] = { |
| 1503 | /* SOF */ |
| 1504 | { |
| 1505 | .ioctl_ops = {}, |
| 1506 | .crm_ops = { |
| 1507 | .apply_req = __cam_isp_ctx_apply_req_in_sof, |
| 1508 | }, |
| 1509 | .irq_ops = NULL, |
| 1510 | }, |
| 1511 | /* APPLIED */ |
| 1512 | { |
| 1513 | .ioctl_ops = {}, |
| 1514 | .crm_ops = {}, |
| 1515 | .irq_ops = NULL, |
| 1516 | }, |
| 1517 | /* EPOCH */ |
| 1518 | { |
| 1519 | .ioctl_ops = {}, |
| 1520 | .crm_ops = { |
| 1521 | .apply_req = __cam_isp_ctx_apply_req_in_epoch, |
| 1522 | }, |
| 1523 | .irq_ops = NULL, |
| 1524 | }, |
| 1525 | /* BUBBLE */ |
| 1526 | { |
| 1527 | .ioctl_ops = {}, |
| 1528 | .crm_ops = { |
| 1529 | .apply_req = __cam_isp_ctx_apply_req_in_bubble, |
| 1530 | }, |
| 1531 | .irq_ops = NULL, |
| 1532 | }, |
| 1533 | /* Bubble Applied */ |
| 1534 | { |
| 1535 | .ioctl_ops = {}, |
| 1536 | .crm_ops = {}, |
| 1537 | .irq_ops = NULL, |
| 1538 | }, |
Jing Zhou | 4d4f03e | 2018-01-16 18:10:31 -0800 | [diff] [blame] | 1539 | /* HW ERROR */ |
| 1540 | { |
| 1541 | .ioctl_ops = {}, |
| 1542 | .crm_ops = {}, |
| 1543 | .irq_ops = NULL, |
| 1544 | }, |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1545 | /* HALT */ |
| 1546 | { |
| 1547 | .ioctl_ops = {}, |
| 1548 | .crm_ops = {}, |
| 1549 | .irq_ops = NULL, |
| 1550 | }, |
| 1551 | }; |
| 1552 | |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1553 | static int __cam_isp_ctx_rdi_only_sof_in_top_state( |
| 1554 | struct cam_isp_context *ctx_isp, void *evt_data) |
| 1555 | { |
| 1556 | int rc = 0; |
| 1557 | struct cam_context *ctx = ctx_isp->base; |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1558 | struct cam_req_mgr_trigger_notify notify; |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1559 | struct cam_isp_hw_sof_event_data *sof_event_data = evt_data; |
| 1560 | uint64_t request_id = 0; |
| 1561 | |
| 1562 | if (!evt_data) { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1563 | CAM_ERR(CAM_ISP, "in valid sof event data"); |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1564 | return -EINVAL; |
| 1565 | } |
| 1566 | |
| 1567 | ctx_isp->frame_id++; |
| 1568 | ctx_isp->sof_timestamp_val = sof_event_data->timestamp; |
Karthik Anantha Ram | c93754c | 2018-03-28 14:21:14 -0700 | [diff] [blame] | 1569 | ctx_isp->boot_timestamp = sof_event_data->boot_time; |
| 1570 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1571 | CAM_DBG(CAM_ISP, "frame id: %lld time stamp:0x%llx", |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1572 | ctx_isp->frame_id, ctx_isp->sof_timestamp_val); |
| 1573 | |
| 1574 | /* |
| 1575 | * notify reqmgr with sof signal. Note, due to scheduling delay |
| 1576 | * we can run into situation that two active requests has already |
| 1577 | * be in the active queue while we try to do the notification. |
| 1578 | * In this case, we need to skip the current notification. This |
| 1579 | * helps the state machine to catch up the delay. |
| 1580 | */ |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1581 | if (ctx->ctx_crm_intf && ctx->ctx_crm_intf->notify_trigger && |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1582 | ctx_isp->active_req_cnt <= 2) { |
| 1583 | notify.link_hdl = ctx->link_hdl; |
| 1584 | notify.dev_hdl = ctx->dev_hdl; |
| 1585 | notify.frame_id = ctx_isp->frame_id; |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1586 | notify.trigger = CAM_TRIGGER_POINT_SOF; |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1587 | |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1588 | ctx->ctx_crm_intf->notify_trigger(¬ify); |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1589 | CAM_DBG(CAM_ISP, "Notify CRM SOF frame %lld", |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1590 | ctx_isp->frame_id); |
| 1591 | |
| 1592 | /* |
| 1593 | * It is idle frame with out any applied request id, send |
| 1594 | * request id as zero |
| 1595 | */ |
| 1596 | __cam_isp_ctx_send_sof_timestamp(ctx_isp, request_id, |
| 1597 | CAM_REQ_MGR_SOF_EVENT_SUCCESS); |
| 1598 | } else { |
Harsh Shah | cb0072c | 2017-09-26 19:22:10 -0700 | [diff] [blame] | 1599 | CAM_ERR_RATE_LIMIT(CAM_ISP, "Can not notify SOF to CRM"); |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1600 | } |
| 1601 | |
| 1602 | if (list_empty(&ctx->active_req_list)) |
| 1603 | ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_SOF; |
| 1604 | else |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1605 | CAM_DBG(CAM_ISP, "Still need to wait for the buf done"); |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1606 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1607 | CAM_DBG(CAM_ISP, "next substate %d", |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1608 | ctx_isp->substate_activated); |
| 1609 | return rc; |
| 1610 | } |
| 1611 | |
| 1612 | static int __cam_isp_ctx_rdi_only_sof_in_applied_state( |
| 1613 | struct cam_isp_context *ctx_isp, void *evt_data) |
| 1614 | { |
| 1615 | struct cam_isp_hw_sof_event_data *sof_event_data = evt_data; |
| 1616 | |
| 1617 | if (!evt_data) { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1618 | CAM_ERR(CAM_ISP, "in valid sof event data"); |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1619 | return -EINVAL; |
| 1620 | } |
| 1621 | |
| 1622 | ctx_isp->frame_id++; |
| 1623 | ctx_isp->sof_timestamp_val = sof_event_data->timestamp; |
Karthik Anantha Ram | c93754c | 2018-03-28 14:21:14 -0700 | [diff] [blame] | 1624 | ctx_isp->boot_timestamp = sof_event_data->boot_time; |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1625 | CAM_DBG(CAM_ISP, "frame id: %lld time stamp:0x%llx", |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1626 | ctx_isp->frame_id, ctx_isp->sof_timestamp_val); |
| 1627 | |
| 1628 | ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_BUBBLE_APPLIED; |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1629 | CAM_DBG(CAM_ISP, "next substate %d", ctx_isp->substate_activated); |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1630 | |
| 1631 | return 0; |
| 1632 | } |
| 1633 | |
| 1634 | static int __cam_isp_ctx_rdi_only_sof_in_bubble_applied( |
| 1635 | struct cam_isp_context *ctx_isp, void *evt_data) |
| 1636 | { |
| 1637 | struct cam_ctx_request *req; |
| 1638 | struct cam_isp_ctx_req *req_isp; |
| 1639 | struct cam_context *ctx = ctx_isp->base; |
| 1640 | struct cam_isp_hw_sof_event_data *sof_event_data = evt_data; |
| 1641 | uint64_t request_id = 0; |
| 1642 | |
Ravikishore Pampana | 6648f17 | 2017-12-08 20:29:11 +0530 | [diff] [blame] | 1643 | /* |
| 1644 | * Sof in bubble applied state means, reg update not received. |
| 1645 | * before increment frame id and override time stamp value, send |
| 1646 | * the previous sof time stamp that got captured in the |
| 1647 | * sof in applied state. |
| 1648 | */ |
| 1649 | CAM_DBG(CAM_ISP, "frame id: %lld time stamp:0x%llx", |
| 1650 | ctx_isp->frame_id, ctx_isp->sof_timestamp_val); |
| 1651 | __cam_isp_ctx_send_sof_timestamp(ctx_isp, request_id, |
| 1652 | CAM_REQ_MGR_SOF_EVENT_SUCCESS); |
| 1653 | |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1654 | ctx_isp->frame_id++; |
| 1655 | ctx_isp->sof_timestamp_val = sof_event_data->timestamp; |
Karthik Anantha Ram | c93754c | 2018-03-28 14:21:14 -0700 | [diff] [blame] | 1656 | ctx_isp->boot_timestamp = sof_event_data->boot_time; |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1657 | CAM_DBG(CAM_ISP, "frame id: %lld time stamp:0x%llx", |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1658 | ctx_isp->frame_id, ctx_isp->sof_timestamp_val); |
| 1659 | |
Junzhe Zou | 09820a7 | 2018-09-06 18:11:41 -0700 | [diff] [blame] | 1660 | if (list_empty(&ctx->wait_req_list)) { |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1661 | /* |
| 1662 | * If no pending req in epoch, this is an error case. |
| 1663 | * The recovery is to go back to sof state |
| 1664 | */ |
Junzhe Zou | 09820a7 | 2018-09-06 18:11:41 -0700 | [diff] [blame] | 1665 | CAM_ERR(CAM_ISP, "No wait request"); |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1666 | ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_SOF; |
| 1667 | |
| 1668 | /* Send SOF event as empty frame*/ |
| 1669 | __cam_isp_ctx_send_sof_timestamp(ctx_isp, request_id, |
| 1670 | CAM_REQ_MGR_SOF_EVENT_SUCCESS); |
| 1671 | |
| 1672 | goto end; |
| 1673 | } |
| 1674 | |
Junzhe Zou | 09820a7 | 2018-09-06 18:11:41 -0700 | [diff] [blame] | 1675 | req = list_first_entry(&ctx->wait_req_list, struct cam_ctx_request, |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1676 | list); |
| 1677 | req_isp = (struct cam_isp_ctx_req *)req->req_priv; |
Junzhe Zou | 09820a7 | 2018-09-06 18:11:41 -0700 | [diff] [blame] | 1678 | req_isp->bubble_detected = true; |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1679 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1680 | CAM_DBG(CAM_ISP, "Report Bubble flag %d", req_isp->bubble_report); |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1681 | if (req_isp->bubble_report && ctx->ctx_crm_intf && |
| 1682 | ctx->ctx_crm_intf->notify_err) { |
| 1683 | struct cam_req_mgr_error_notify notify; |
| 1684 | |
| 1685 | notify.link_hdl = ctx->link_hdl; |
| 1686 | notify.dev_hdl = ctx->dev_hdl; |
| 1687 | notify.req_id = req->request_id; |
| 1688 | notify.error = CRM_KMD_ERR_BUBBLE; |
| 1689 | ctx->ctx_crm_intf->notify_err(¬ify); |
Shravya Samala | 43583ea | 2020-04-29 14:25:37 +0530 | [diff] [blame] | 1690 | atomic_set(&ctx_isp->process_bubble, 1); |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1691 | CAM_DBG(CAM_ISP, "Notify CRM about Bubble frame %lld", |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1692 | ctx_isp->frame_id); |
| 1693 | } else { |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1694 | req_isp->bubble_report = 0; |
| 1695 | } |
| 1696 | |
Junzhe Zou | 09820a7 | 2018-09-06 18:11:41 -0700 | [diff] [blame] | 1697 | /* |
| 1698 | * Always move the request to active list. Let buf done |
| 1699 | * function handles the rest. |
| 1700 | */ |
| 1701 | ctx_isp->active_req_cnt++; |
| 1702 | list_del_init(&req->list); |
| 1703 | list_add_tail(&req->list, &ctx->active_req_list); |
| 1704 | CAM_DBG(CAM_ISP, "move request %lld to active list(cnt = %d)", |
| 1705 | req->request_id, ctx_isp->active_req_cnt); |
| 1706 | |
Ravikishore Pampana | 6648f17 | 2017-12-08 20:29:11 +0530 | [diff] [blame] | 1707 | if (!req_isp->bubble_report) { |
| 1708 | if (req->request_id > ctx_isp->reported_req_id) { |
| 1709 | request_id = req->request_id; |
| 1710 | ctx_isp->reported_req_id = request_id; |
| 1711 | __cam_isp_ctx_send_sof_timestamp(ctx_isp, request_id, |
| 1712 | CAM_REQ_MGR_SOF_EVENT_ERROR); |
| 1713 | } else |
| 1714 | __cam_isp_ctx_send_sof_timestamp(ctx_isp, request_id, |
| 1715 | CAM_REQ_MGR_SOF_EVENT_SUCCESS); |
| 1716 | } else |
| 1717 | __cam_isp_ctx_send_sof_timestamp(ctx_isp, request_id, |
| 1718 | CAM_REQ_MGR_SOF_EVENT_SUCCESS); |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1719 | |
| 1720 | /* change the state to bubble, as reg update has not come */ |
| 1721 | ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_BUBBLE; |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1722 | CAM_DBG(CAM_ISP, "next substate %d", ctx_isp->substate_activated); |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1723 | end: |
| 1724 | return 0; |
| 1725 | } |
| 1726 | |
| 1727 | static int __cam_isp_ctx_rdi_only_sof_in_bubble_state( |
| 1728 | struct cam_isp_context *ctx_isp, void *evt_data) |
| 1729 | { |
| 1730 | uint32_t i; |
| 1731 | struct cam_ctx_request *req; |
| 1732 | struct cam_context *ctx = ctx_isp->base; |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1733 | struct cam_req_mgr_trigger_notify notify; |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1734 | struct cam_isp_hw_sof_event_data *sof_event_data = evt_data; |
| 1735 | struct cam_isp_ctx_req *req_isp; |
| 1736 | uint64_t request_id = 0; |
| 1737 | |
| 1738 | if (!evt_data) { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1739 | CAM_ERR(CAM_ISP, "in valid sof event data"); |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1740 | return -EINVAL; |
| 1741 | } |
| 1742 | |
| 1743 | ctx_isp->frame_id++; |
| 1744 | ctx_isp->sof_timestamp_val = sof_event_data->timestamp; |
Karthik Anantha Ram | c93754c | 2018-03-28 14:21:14 -0700 | [diff] [blame] | 1745 | ctx_isp->boot_timestamp = sof_event_data->boot_time; |
Shravya Samala | 43583ea | 2020-04-29 14:25:37 +0530 | [diff] [blame] | 1746 | atomic_inc(&ctx_isp->bubble_sof_count); |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1747 | CAM_DBG(CAM_ISP, "frame id: %lld time stamp:0x%llx", |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1748 | ctx_isp->frame_id, ctx_isp->sof_timestamp_val); |
Shravya Samala | 43583ea | 2020-04-29 14:25:37 +0530 | [diff] [blame] | 1749 | |
| 1750 | if (atomic_read(&ctx_isp->process_bubble) && |
| 1751 | (!list_empty(&ctx->active_req_list)) && |
| 1752 | (atomic_read(&ctx_isp->bubble_sof_count) < |
| 1753 | CAM_ISP_CTX_BUBBLE_SOF_COUNT_MAX)) { |
| 1754 | CAM_INFO(CAM_ISP, |
| 1755 | "Processing bubble, bubble_sof_count :%u", |
| 1756 | atomic_read(&ctx_isp->bubble_sof_count)); |
| 1757 | goto end; |
| 1758 | } |
| 1759 | |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1760 | /* |
| 1761 | * Signal all active requests with error and move the all the active |
| 1762 | * requests to free list |
| 1763 | */ |
| 1764 | while (!list_empty(&ctx->active_req_list)) { |
| 1765 | req = list_first_entry(&ctx->active_req_list, |
| 1766 | struct cam_ctx_request, list); |
| 1767 | list_del_init(&req->list); |
| 1768 | req_isp = (struct cam_isp_ctx_req *) req->req_priv; |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1769 | CAM_DBG(CAM_ISP, "signal fence in active list. fence num %d", |
| 1770 | req_isp->num_fence_map_out); |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1771 | for (i = 0; i < req_isp->num_fence_map_out; i++) |
| 1772 | if (req_isp->fence_map_out[i].sync_id != -1) { |
| 1773 | cam_sync_signal( |
| 1774 | req_isp->fence_map_out[i].sync_id, |
| 1775 | CAM_SYNC_STATE_SIGNALED_ERROR); |
| 1776 | } |
| 1777 | list_add_tail(&req->list, &ctx->free_req_list); |
Harsh Shah | 1b8eb23 | 2017-10-09 19:20:52 -0700 | [diff] [blame] | 1778 | ctx_isp->active_req_cnt--; |
Shravya Samala | 43583ea | 2020-04-29 14:25:37 +0530 | [diff] [blame] | 1779 | atomic_set(&ctx_isp->bubble_sof_count, 0); |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1780 | } |
| 1781 | |
Shravya Samala | 43583ea | 2020-04-29 14:25:37 +0530 | [diff] [blame] | 1782 | ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_SOF; |
| 1783 | end: |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1784 | /* notify reqmgr with sof signal */ |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1785 | if (ctx->ctx_crm_intf && ctx->ctx_crm_intf->notify_trigger) { |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1786 | notify.link_hdl = ctx->link_hdl; |
| 1787 | notify.dev_hdl = ctx->dev_hdl; |
| 1788 | notify.frame_id = ctx_isp->frame_id; |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1789 | notify.trigger = CAM_TRIGGER_POINT_SOF; |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1790 | |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1791 | ctx->ctx_crm_intf->notify_trigger(¬ify); |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1792 | CAM_DBG(CAM_ISP, "Notify CRM SOF frame %lld", |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1793 | ctx_isp->frame_id); |
| 1794 | |
| 1795 | } else { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1796 | CAM_ERR(CAM_ISP, "Can not notify SOF to CRM"); |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1797 | } |
| 1798 | |
| 1799 | /* |
| 1800 | * It is idle frame with out any applied request id, send |
| 1801 | * request id as zero |
| 1802 | */ |
| 1803 | __cam_isp_ctx_send_sof_timestamp(ctx_isp, request_id, |
| 1804 | CAM_REQ_MGR_SOF_EVENT_SUCCESS); |
| 1805 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1806 | CAM_DBG(CAM_ISP, "next substate %d", |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1807 | ctx_isp->substate_activated); |
| 1808 | |
| 1809 | return 0; |
| 1810 | } |
| 1811 | |
| 1812 | static int __cam_isp_ctx_rdi_only_reg_upd_in_bubble_applied_state( |
| 1813 | struct cam_isp_context *ctx_isp, void *evt_data) |
| 1814 | { |
| 1815 | struct cam_ctx_request *req; |
| 1816 | struct cam_context *ctx = ctx_isp->base; |
| 1817 | struct cam_isp_ctx_req *req_isp; |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1818 | struct cam_req_mgr_trigger_notify notify; |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1819 | uint64_t request_id = 0; |
| 1820 | |
Lynus Vaz | cbda4b0 | 2018-03-26 15:48:01 +0530 | [diff] [blame] | 1821 | ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_EPOCH; |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1822 | /* notify reqmgr with sof signal*/ |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1823 | if (ctx->ctx_crm_intf && ctx->ctx_crm_intf->notify_trigger) { |
Junzhe Zou | e7d56fc | 2018-08-10 14:50:17 -0700 | [diff] [blame] | 1824 | if (list_empty(&ctx->wait_req_list)) { |
| 1825 | CAM_ERR(CAM_ISP, "Reg upd ack with no waiting request"); |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1826 | goto error; |
| 1827 | } |
Junzhe Zou | e7d56fc | 2018-08-10 14:50:17 -0700 | [diff] [blame] | 1828 | req = list_first_entry(&ctx->wait_req_list, |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1829 | struct cam_ctx_request, list); |
| 1830 | list_del_init(&req->list); |
| 1831 | |
| 1832 | req_isp = (struct cam_isp_ctx_req *) req->req_priv; |
Lynus Vaz | cbda4b0 | 2018-03-26 15:48:01 +0530 | [diff] [blame] | 1833 | request_id = |
| 1834 | (req_isp->hw_update_data.packet_opcode_type == |
| 1835 | CAM_ISP_PACKET_INIT_DEV) ? |
| 1836 | 0 : req->request_id; |
| 1837 | |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1838 | if (req_isp->num_fence_map_out != 0) { |
| 1839 | list_add_tail(&req->list, &ctx->active_req_list); |
| 1840 | ctx_isp->active_req_cnt++; |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1841 | CAM_DBG(CAM_ISP, |
| 1842 | "move request %lld to active list(cnt = %d)", |
| 1843 | req->request_id, ctx_isp->active_req_cnt); |
Lynus Vaz | cbda4b0 | 2018-03-26 15:48:01 +0530 | [diff] [blame] | 1844 | /* if packet has buffers, set correct request id */ |
| 1845 | request_id = req->request_id; |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1846 | } else { |
| 1847 | /* no io config, so the request is completed. */ |
| 1848 | list_add_tail(&req->list, &ctx->free_req_list); |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1849 | CAM_DBG(CAM_ISP, |
| 1850 | "move active req %lld to free list(cnt=%d)", |
| 1851 | req->request_id, ctx_isp->active_req_cnt); |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1852 | } |
| 1853 | |
| 1854 | notify.link_hdl = ctx->link_hdl; |
| 1855 | notify.dev_hdl = ctx->dev_hdl; |
| 1856 | notify.frame_id = ctx_isp->frame_id; |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1857 | notify.trigger = CAM_TRIGGER_POINT_SOF; |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1858 | |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1859 | ctx->ctx_crm_intf->notify_trigger(¬ify); |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1860 | CAM_DBG(CAM_ISP, "Notify CRM SOF frame %lld", |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1861 | ctx_isp->frame_id); |
| 1862 | } else { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1863 | CAM_ERR(CAM_ISP, "Can not notify SOF to CRM"); |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1864 | } |
Lynus Vaz | cbda4b0 | 2018-03-26 15:48:01 +0530 | [diff] [blame] | 1865 | if (request_id) |
| 1866 | ctx_isp->reported_req_id = request_id; |
| 1867 | |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1868 | __cam_isp_ctx_send_sof_timestamp(ctx_isp, request_id, |
| 1869 | CAM_REQ_MGR_SOF_EVENT_SUCCESS); |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1870 | CAM_DBG(CAM_ISP, "next substate %d", ctx_isp->substate_activated); |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1871 | |
| 1872 | return 0; |
| 1873 | error: |
| 1874 | /* Send SOF event as idle frame*/ |
| 1875 | __cam_isp_ctx_send_sof_timestamp(ctx_isp, request_id, |
| 1876 | CAM_REQ_MGR_SOF_EVENT_SUCCESS); |
| 1877 | |
| 1878 | /* |
| 1879 | * There is no request in the pending list, move the sub state machine |
| 1880 | * to SOF sub state |
| 1881 | */ |
| 1882 | ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_SOF; |
| 1883 | |
| 1884 | return 0; |
| 1885 | } |
| 1886 | |
| 1887 | static struct cam_isp_ctx_irq_ops |
| 1888 | cam_isp_ctx_rdi_only_activated_state_machine_irq |
| 1889 | [CAM_ISP_CTX_ACTIVATED_MAX] = { |
| 1890 | /* SOF */ |
| 1891 | { |
| 1892 | .irq_ops = { |
| 1893 | NULL, |
| 1894 | __cam_isp_ctx_rdi_only_sof_in_top_state, |
| 1895 | __cam_isp_ctx_reg_upd_in_sof, |
| 1896 | NULL, |
| 1897 | NULL, |
| 1898 | NULL, |
| 1899 | }, |
| 1900 | }, |
| 1901 | /* APPLIED */ |
| 1902 | { |
| 1903 | .irq_ops = { |
| 1904 | __cam_isp_ctx_handle_error, |
| 1905 | __cam_isp_ctx_rdi_only_sof_in_applied_state, |
| 1906 | NULL, |
| 1907 | NULL, |
| 1908 | NULL, |
| 1909 | __cam_isp_ctx_buf_done_in_applied, |
| 1910 | }, |
| 1911 | }, |
| 1912 | /* EPOCH */ |
| 1913 | { |
| 1914 | .irq_ops = { |
| 1915 | __cam_isp_ctx_handle_error, |
| 1916 | __cam_isp_ctx_rdi_only_sof_in_top_state, |
| 1917 | NULL, |
| 1918 | NULL, |
| 1919 | NULL, |
| 1920 | __cam_isp_ctx_buf_done_in_epoch, |
| 1921 | }, |
| 1922 | }, |
| 1923 | /* BUBBLE*/ |
| 1924 | { |
| 1925 | .irq_ops = { |
| 1926 | __cam_isp_ctx_handle_error, |
| 1927 | __cam_isp_ctx_rdi_only_sof_in_bubble_state, |
| 1928 | NULL, |
| 1929 | NULL, |
| 1930 | NULL, |
| 1931 | __cam_isp_ctx_buf_done_in_bubble, |
| 1932 | }, |
| 1933 | }, |
| 1934 | /* BUBBLE APPLIED ie PRE_BUBBLE */ |
| 1935 | { |
| 1936 | .irq_ops = { |
| 1937 | __cam_isp_ctx_handle_error, |
| 1938 | __cam_isp_ctx_rdi_only_sof_in_bubble_applied, |
| 1939 | __cam_isp_ctx_rdi_only_reg_upd_in_bubble_applied_state, |
| 1940 | NULL, |
| 1941 | NULL, |
| 1942 | __cam_isp_ctx_buf_done_in_bubble_applied, |
| 1943 | }, |
| 1944 | }, |
Jing Zhou | 4d4f03e | 2018-01-16 18:10:31 -0800 | [diff] [blame] | 1945 | /* HW ERROR */ |
| 1946 | { |
| 1947 | }, |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1948 | /* HALT */ |
| 1949 | { |
| 1950 | }, |
| 1951 | }; |
| 1952 | |
| 1953 | static int __cam_isp_ctx_rdi_only_apply_req_top_state( |
| 1954 | struct cam_context *ctx, struct cam_req_mgr_apply_request *apply) |
| 1955 | { |
| 1956 | int rc = 0; |
| 1957 | struct cam_isp_context *ctx_isp = |
| 1958 | (struct cam_isp_context *) ctx->ctx_priv; |
| 1959 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1960 | CAM_DBG(CAM_ISP, "current substate %d", |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1961 | ctx_isp->substate_activated); |
| 1962 | rc = __cam_isp_ctx_apply_req_in_activated_state(ctx, apply, |
| 1963 | CAM_ISP_CTX_ACTIVATED_APPLIED); |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1964 | CAM_DBG(CAM_ISP, "new substate %d", ctx_isp->substate_activated); |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1965 | |
| 1966 | return rc; |
| 1967 | } |
| 1968 | |
| 1969 | static struct cam_ctx_ops |
| 1970 | cam_isp_ctx_rdi_only_activated_state_machine |
| 1971 | [CAM_ISP_CTX_ACTIVATED_MAX] = { |
| 1972 | /* SOF */ |
| 1973 | { |
| 1974 | .ioctl_ops = {}, |
| 1975 | .crm_ops = { |
| 1976 | .apply_req = __cam_isp_ctx_rdi_only_apply_req_top_state, |
| 1977 | }, |
| 1978 | .irq_ops = NULL, |
| 1979 | }, |
| 1980 | /* APPLIED */ |
| 1981 | { |
| 1982 | .ioctl_ops = {}, |
| 1983 | .crm_ops = {}, |
| 1984 | .irq_ops = NULL, |
| 1985 | }, |
| 1986 | /* EPOCH */ |
| 1987 | { |
| 1988 | .ioctl_ops = {}, |
| 1989 | .crm_ops = { |
| 1990 | .apply_req = __cam_isp_ctx_rdi_only_apply_req_top_state, |
| 1991 | }, |
| 1992 | .irq_ops = NULL, |
| 1993 | }, |
| 1994 | /* PRE BUBBLE */ |
| 1995 | { |
| 1996 | .ioctl_ops = {}, |
| 1997 | .crm_ops = {}, |
| 1998 | .irq_ops = NULL, |
| 1999 | }, |
| 2000 | /* BUBBLE */ |
| 2001 | { |
| 2002 | .ioctl_ops = {}, |
| 2003 | .crm_ops = {}, |
| 2004 | .irq_ops = NULL, |
| 2005 | }, |
Jing Zhou | 4d4f03e | 2018-01-16 18:10:31 -0800 | [diff] [blame] | 2006 | /* HW ERROR */ |
| 2007 | { |
| 2008 | .ioctl_ops = {}, |
| 2009 | .crm_ops = {}, |
| 2010 | .irq_ops = NULL, |
| 2011 | }, |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 2012 | /* HALT */ |
| 2013 | { |
| 2014 | .ioctl_ops = {}, |
| 2015 | .crm_ops = {}, |
| 2016 | .irq_ops = NULL, |
| 2017 | }, |
| 2018 | }; |
| 2019 | |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2020 | /* top level state machine */ |
| 2021 | static int __cam_isp_ctx_release_dev_in_top_state(struct cam_context *ctx, |
| 2022 | struct cam_release_dev_cmd *cmd) |
| 2023 | { |
| 2024 | int rc = 0; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2025 | struct cam_hw_release_args rel_arg; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2026 | struct cam_isp_context *ctx_isp = |
| 2027 | (struct cam_isp_context *) ctx->ctx_priv; |
Jing Zhou | b524a85 | 2017-05-16 15:47:30 +0530 | [diff] [blame] | 2028 | struct cam_req_mgr_flush_request flush_req; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2029 | |
| 2030 | if (ctx_isp->hw_ctx) { |
| 2031 | rel_arg.ctxt_to_hw_map = ctx_isp->hw_ctx; |
| 2032 | ctx->hw_mgr_intf->hw_release(ctx->hw_mgr_intf->hw_mgr_priv, |
| 2033 | &rel_arg); |
| 2034 | ctx_isp->hw_ctx = NULL; |
| 2035 | } |
| 2036 | |
Soundrapandian Jeyaprakash | 8d16e27 | 2017-10-12 11:05:37 -0700 | [diff] [blame] | 2037 | ctx->session_hdl = -1; |
| 2038 | ctx->dev_hdl = -1; |
| 2039 | ctx->link_hdl = -1; |
Jing Zhou | e71fd4a | 2017-05-15 19:44:34 -0700 | [diff] [blame] | 2040 | ctx->ctx_crm_intf = NULL; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2041 | ctx_isp->frame_id = 0; |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 2042 | ctx_isp->active_req_cnt = 0; |
| 2043 | ctx_isp->reported_req_id = 0; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2044 | |
| 2045 | /* |
| 2046 | * Ideally, we should never have any active request here. |
| 2047 | * But we still add some sanity check code here to help the debug |
| 2048 | */ |
| 2049 | if (!list_empty(&ctx->active_req_list)) |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 2050 | CAM_ERR(CAM_ISP, "Active list is not empty"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2051 | |
Jing Zhou | b524a85 | 2017-05-16 15:47:30 +0530 | [diff] [blame] | 2052 | /* Flush all the pending request list */ |
| 2053 | flush_req.type = CAM_REQ_MGR_FLUSH_TYPE_ALL; |
| 2054 | flush_req.link_hdl = ctx->link_hdl; |
| 2055 | flush_req.dev_hdl = ctx->dev_hdl; |
| 2056 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 2057 | CAM_DBG(CAM_ISP, "try to flush pending list"); |
Venkat Chinta | c8e610f | 2018-05-08 17:40:44 -0700 | [diff] [blame] | 2058 | spin_lock_bh(&ctx->lock); |
Jing Zhou | b524a85 | 2017-05-16 15:47:30 +0530 | [diff] [blame] | 2059 | rc = __cam_isp_ctx_flush_req(ctx, &ctx->pending_req_list, &flush_req); |
Venkat Chinta | c8e610f | 2018-05-08 17:40:44 -0700 | [diff] [blame] | 2060 | spin_unlock_bh(&ctx->lock); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2061 | ctx->state = CAM_CTX_AVAILABLE; |
Gregory Bergschneider | 5164f3a | 2017-07-07 10:26:17 -0600 | [diff] [blame] | 2062 | |
| 2063 | trace_cam_context_state("ISP", ctx); |
Karthik Anantha Ram | 5438d57 | 2018-06-15 10:48:19 -0700 | [diff] [blame] | 2064 | CAM_DBG(CAM_ISP, "Release device success[%u] next state %d", |
| 2065 | ctx->ctx_id, ctx->state); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2066 | return rc; |
| 2067 | } |
| 2068 | |
| 2069 | static int __cam_isp_ctx_config_dev_in_top_state( |
| 2070 | struct cam_context *ctx, struct cam_config_dev_cmd *cmd) |
| 2071 | { |
Junzhe Zou | 93be421 | 2018-07-30 14:52:56 -0700 | [diff] [blame] | 2072 | int rc = 0, i; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2073 | struct cam_ctx_request *req = NULL; |
| 2074 | struct cam_isp_ctx_req *req_isp; |
Trishansh Bhardwaj | 0508a77 | 2018-10-01 12:32:49 +0530 | [diff] [blame] | 2075 | uintptr_t packet_addr; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2076 | struct cam_packet *packet; |
| 2077 | size_t len = 0; |
Mukund Madhusudan Atre | 95cec7a | 2019-01-15 17:10:08 -0800 | [diff] [blame] | 2078 | size_t remain_len = 0; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2079 | struct cam_hw_prepare_update_args cfg; |
| 2080 | struct cam_req_mgr_add_request add_req; |
| 2081 | struct cam_isp_context *ctx_isp = |
| 2082 | (struct cam_isp_context *) ctx->ctx_priv; |
| 2083 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 2084 | CAM_DBG(CAM_ISP, "get free request object......"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2085 | |
| 2086 | /* get free request */ |
Jing Zhou | 93b3ec1 | 2017-06-15 17:43:39 -0700 | [diff] [blame] | 2087 | spin_lock_bh(&ctx->lock); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2088 | if (!list_empty(&ctx->free_req_list)) { |
| 2089 | req = list_first_entry(&ctx->free_req_list, |
| 2090 | struct cam_ctx_request, list); |
| 2091 | list_del_init(&req->list); |
| 2092 | } |
Jing Zhou | 93b3ec1 | 2017-06-15 17:43:39 -0700 | [diff] [blame] | 2093 | spin_unlock_bh(&ctx->lock); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2094 | |
| 2095 | if (!req) { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 2096 | CAM_ERR(CAM_ISP, "No more request obj free"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2097 | rc = -ENOMEM; |
| 2098 | goto end; |
| 2099 | } |
| 2100 | |
| 2101 | req_isp = (struct cam_isp_ctx_req *) req->req_priv; |
| 2102 | |
| 2103 | /* for config dev, only memory handle is supported */ |
| 2104 | /* map packet from the memhandle */ |
| 2105 | rc = cam_mem_get_cpu_buf((int32_t) cmd->packet_handle, |
Trishansh Bhardwaj | 0508a77 | 2018-10-01 12:32:49 +0530 | [diff] [blame] | 2106 | &packet_addr, &len); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2107 | if (rc != 0) { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 2108 | CAM_ERR(CAM_ISP, "Can not get packet address"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2109 | rc = -EINVAL; |
| 2110 | goto free_req; |
| 2111 | } |
| 2112 | |
Mukund Madhusudan Atre | 95cec7a | 2019-01-15 17:10:08 -0800 | [diff] [blame] | 2113 | remain_len = len; |
| 2114 | if ((len < sizeof(struct cam_packet)) || |
| 2115 | ((size_t)cmd->offset >= len - sizeof(struct cam_packet))) { |
| 2116 | CAM_ERR(CAM_ISP, "invalid buff length: %zu or offset", len); |
| 2117 | return -EINVAL; |
| 2118 | } |
| 2119 | |
| 2120 | remain_len -= (size_t)cmd->offset; |
Trishansh Bhardwaj | 0508a77 | 2018-10-01 12:32:49 +0530 | [diff] [blame] | 2121 | packet = (struct cam_packet *)(packet_addr + (uint32_t)cmd->offset); |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 2122 | CAM_DBG(CAM_ISP, "pack_handle %llx", cmd->packet_handle); |
Trishansh Bhardwaj | 0508a77 | 2018-10-01 12:32:49 +0530 | [diff] [blame] | 2123 | CAM_DBG(CAM_ISP, "packet address is 0x%zx", packet_addr); |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 2124 | CAM_DBG(CAM_ISP, "packet with length %zu, offset 0x%llx", |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2125 | len, cmd->offset); |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 2126 | CAM_DBG(CAM_ISP, "Packet request id %lld", |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2127 | packet->header.request_id); |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 2128 | CAM_DBG(CAM_ISP, "Packet size 0x%x", packet->header.size); |
| 2129 | CAM_DBG(CAM_ISP, "packet op %d", packet->header.op_code); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2130 | |
| 2131 | /* preprocess the configuration */ |
| 2132 | memset(&cfg, 0, sizeof(cfg)); |
| 2133 | cfg.packet = packet; |
Mukund Madhusudan Atre | 95cec7a | 2019-01-15 17:10:08 -0800 | [diff] [blame] | 2134 | cfg.remain_len = remain_len; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2135 | cfg.ctxt_to_hw_map = ctx_isp->hw_ctx; |
| 2136 | cfg.max_hw_update_entries = CAM_ISP_CTX_CFG_MAX; |
| 2137 | cfg.hw_update_entries = req_isp->cfg; |
| 2138 | cfg.max_out_map_entries = CAM_ISP_CTX_RES_MAX; |
| 2139 | cfg.max_in_map_entries = CAM_ISP_CTX_RES_MAX; |
| 2140 | cfg.out_map_entries = req_isp->fence_map_out; |
| 2141 | cfg.in_map_entries = req_isp->fence_map_in; |
Vishalsingh Hajeri | e5450be | 2018-01-18 20:31:19 -0800 | [diff] [blame] | 2142 | cfg.priv = &req_isp->hw_update_data; |
Suraj Dongre | 2681192 | 2018-06-27 19:30:01 -0700 | [diff] [blame] | 2143 | cfg.pf_data = &(req->pf_data); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2144 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 2145 | CAM_DBG(CAM_ISP, "try to prepare config packet......"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2146 | |
| 2147 | rc = ctx->hw_mgr_intf->hw_prepare_update( |
| 2148 | ctx->hw_mgr_intf->hw_mgr_priv, &cfg); |
| 2149 | if (rc != 0) { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 2150 | CAM_ERR(CAM_ISP, "Prepare config packet failed in HW layer"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2151 | rc = -EFAULT; |
| 2152 | goto free_req; |
| 2153 | } |
| 2154 | req_isp->num_cfg = cfg.num_hw_update_entries; |
| 2155 | req_isp->num_fence_map_out = cfg.num_out_map_entries; |
| 2156 | req_isp->num_fence_map_in = cfg.num_in_map_entries; |
| 2157 | req_isp->num_acked = 0; |
Junzhe Zou | 09820a7 | 2018-09-06 18:11:41 -0700 | [diff] [blame] | 2158 | req_isp->bubble_detected = false; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2159 | |
Junzhe Zou | 93be421 | 2018-07-30 14:52:56 -0700 | [diff] [blame] | 2160 | for (i = 0; i < req_isp->num_fence_map_out; i++) { |
| 2161 | rc = cam_sync_get_obj_ref(req_isp->fence_map_out[i].sync_id); |
| 2162 | if (rc) { |
| 2163 | CAM_ERR(CAM_ISP, "Can't get ref for fence %d", |
| 2164 | req_isp->fence_map_out[i].sync_id); |
| 2165 | goto put_ref; |
| 2166 | } |
| 2167 | } |
| 2168 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 2169 | CAM_DBG(CAM_ISP, "num_entry: %d, num fence out: %d, num fence in: %d", |
Ravikishore Pampana | 24f712e | 2017-11-13 23:09:30 +0530 | [diff] [blame] | 2170 | req_isp->num_cfg, req_isp->num_fence_map_out, |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2171 | req_isp->num_fence_map_in); |
| 2172 | |
| 2173 | req->request_id = packet->header.request_id; |
| 2174 | req->status = 1; |
| 2175 | |
Lynus Vaz | cbda4b0 | 2018-03-26 15:48:01 +0530 | [diff] [blame] | 2176 | CAM_DBG(CAM_ISP, "Packet request id %lld packet opcode:%d", |
Vishalsingh Hajeri | e5450be | 2018-01-18 20:31:19 -0800 | [diff] [blame] | 2177 | packet->header.request_id, |
| 2178 | req_isp->hw_update_data.packet_opcode_type); |
Ravikishore Pampana | 24f712e | 2017-11-13 23:09:30 +0530 | [diff] [blame] | 2179 | |
Vishalsingh Hajeri | e5450be | 2018-01-18 20:31:19 -0800 | [diff] [blame] | 2180 | if (req_isp->hw_update_data.packet_opcode_type == |
| 2181 | CAM_ISP_PACKET_INIT_DEV) { |
Ravikishore Pampana | 24f712e | 2017-11-13 23:09:30 +0530 | [diff] [blame] | 2182 | if (ctx->state < CAM_CTX_ACTIVATED) { |
| 2183 | rc = __cam_isp_ctx_enqueue_init_request(ctx, req); |
| 2184 | if (rc) |
| 2185 | CAM_ERR(CAM_ISP, "Enqueue INIT pkt failed"); |
| 2186 | } else { |
| 2187 | rc = -EINVAL; |
| 2188 | CAM_ERR(CAM_ISP, "Recevied INIT pkt in wrong state"); |
| 2189 | } |
| 2190 | } else { |
| 2191 | if (ctx->state >= CAM_CTX_READY && ctx->ctx_crm_intf->add_req) { |
| 2192 | add_req.link_hdl = ctx->link_hdl; |
| 2193 | add_req.dev_hdl = ctx->dev_hdl; |
| 2194 | add_req.req_id = req->request_id; |
| 2195 | add_req.skip_before_applying = 0; |
| 2196 | rc = ctx->ctx_crm_intf->add_req(&add_req); |
| 2197 | if (rc) { |
| 2198 | CAM_ERR(CAM_ISP, "Add req failed: req id=%llu", |
| 2199 | req->request_id); |
| 2200 | } else { |
| 2201 | __cam_isp_ctx_enqueue_request_in_order( |
| 2202 | ctx, req); |
| 2203 | } |
| 2204 | } else { |
| 2205 | rc = -EINVAL; |
| 2206 | CAM_ERR(CAM_ISP, "Recevied Update in wrong state"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2207 | } |
| 2208 | } |
Ravikishore Pampana | 24f712e | 2017-11-13 23:09:30 +0530 | [diff] [blame] | 2209 | if (rc) |
Junzhe Zou | 93be421 | 2018-07-30 14:52:56 -0700 | [diff] [blame] | 2210 | goto put_ref; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2211 | |
Karthik Anantha Ram | 5438d57 | 2018-06-15 10:48:19 -0700 | [diff] [blame] | 2212 | CAM_DBG(CAM_REQ, |
| 2213 | "Preprocessing Config req_id %lld successful on ctx %u", |
| 2214 | req->request_id, ctx->ctx_id); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2215 | |
| 2216 | return rc; |
| 2217 | |
Junzhe Zou | 93be421 | 2018-07-30 14:52:56 -0700 | [diff] [blame] | 2218 | put_ref: |
| 2219 | for (--i; i >= 0; i--) { |
| 2220 | rc = cam_sync_put_obj_ref(req_isp->fence_map_out[i].sync_id); |
| 2221 | if (rc) |
| 2222 | CAM_ERR(CAM_CTXT, "Failed to put ref of fence %d", |
| 2223 | req_isp->fence_map_out[i].sync_id); |
| 2224 | } |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2225 | free_req: |
Jing Zhou | 93b3ec1 | 2017-06-15 17:43:39 -0700 | [diff] [blame] | 2226 | spin_lock_bh(&ctx->lock); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2227 | list_add_tail(&req->list, &ctx->free_req_list); |
Jing Zhou | 93b3ec1 | 2017-06-15 17:43:39 -0700 | [diff] [blame] | 2228 | spin_unlock_bh(&ctx->lock); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2229 | end: |
| 2230 | return rc; |
| 2231 | } |
| 2232 | |
| 2233 | static int __cam_isp_ctx_acquire_dev_in_available(struct cam_context *ctx, |
| 2234 | struct cam_acquire_dev_cmd *cmd) |
| 2235 | { |
| 2236 | int rc = 0; |
| 2237 | struct cam_hw_acquire_args param; |
| 2238 | struct cam_isp_resource *isp_res = NULL; |
| 2239 | struct cam_create_dev_hdl req_hdl_param; |
| 2240 | struct cam_hw_release_args release; |
| 2241 | struct cam_isp_context *ctx_isp = |
| 2242 | (struct cam_isp_context *) ctx->ctx_priv; |
Sridhar Gujje | 20c475a | 2018-11-14 15:58:09 +0530 | [diff] [blame] | 2243 | struct cam_hw_cmd_args hw_cmd_args; |
| 2244 | struct cam_isp_hw_cmd_args isp_hw_cmd_args; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2245 | |
| 2246 | if (!ctx->hw_mgr_intf) { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 2247 | CAM_ERR(CAM_ISP, "HW interface is not ready"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2248 | rc = -EFAULT; |
| 2249 | goto end; |
| 2250 | } |
| 2251 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 2252 | CAM_DBG(CAM_ISP, |
| 2253 | "session_hdl 0x%x, num_resources %d, hdl type %d, res %lld", |
| 2254 | cmd->session_handle, cmd->num_resources, |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2255 | cmd->handle_type, cmd->resource_hdl); |
| 2256 | |
| 2257 | if (cmd->num_resources > CAM_ISP_CTX_RES_MAX) { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 2258 | CAM_ERR(CAM_ISP, "Too much resources in the acquire"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2259 | rc = -ENOMEM; |
| 2260 | goto end; |
| 2261 | } |
| 2262 | |
| 2263 | /* for now we only support user pointer */ |
| 2264 | if (cmd->handle_type != 1) { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 2265 | CAM_ERR(CAM_ISP, "Only user pointer is supported"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2266 | rc = -EINVAL; |
| 2267 | goto end; |
| 2268 | } |
| 2269 | |
| 2270 | isp_res = kzalloc( |
| 2271 | sizeof(*isp_res)*cmd->num_resources, GFP_KERNEL); |
| 2272 | if (!isp_res) { |
| 2273 | rc = -ENOMEM; |
| 2274 | goto end; |
| 2275 | } |
| 2276 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 2277 | CAM_DBG(CAM_ISP, "start copy %d resources from user", |
| 2278 | cmd->num_resources); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2279 | |
Trishansh Bhardwaj | 0508a77 | 2018-10-01 12:32:49 +0530 | [diff] [blame] | 2280 | if (copy_from_user(isp_res, u64_to_user_ptr(cmd->resource_hdl), |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2281 | sizeof(*isp_res)*cmd->num_resources)) { |
| 2282 | rc = -EFAULT; |
| 2283 | goto free_res; |
| 2284 | } |
| 2285 | |
| 2286 | param.context_data = ctx; |
| 2287 | param.event_cb = ctx->irq_cb_intf; |
| 2288 | param.num_acq = cmd->num_resources; |
Trishansh Bhardwaj | 0508a77 | 2018-10-01 12:32:49 +0530 | [diff] [blame] | 2289 | param.acquire_info = (uintptr_t) isp_res; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2290 | |
| 2291 | /* call HW manager to reserve the resource */ |
| 2292 | rc = ctx->hw_mgr_intf->hw_acquire(ctx->hw_mgr_intf->hw_mgr_priv, |
| 2293 | ¶m); |
| 2294 | if (rc != 0) { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 2295 | CAM_ERR(CAM_ISP, "Acquire device failed"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2296 | goto free_res; |
| 2297 | } |
| 2298 | |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 2299 | /* Query the context has rdi only resource */ |
| 2300 | hw_cmd_args.ctxt_to_hw_map = param.ctxt_to_hw_map; |
Suraj Dongre | 2681192 | 2018-06-27 19:30:01 -0700 | [diff] [blame] | 2301 | hw_cmd_args.cmd_type = CAM_HW_MGR_CMD_INTERNAL; |
| 2302 | isp_hw_cmd_args.cmd_type = CAM_ISP_HW_MGR_CMD_IS_RDI_ONLY_CONTEXT; |
| 2303 | hw_cmd_args.u.internal_args = (void *)&isp_hw_cmd_args; |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 2304 | rc = ctx->hw_mgr_intf->hw_cmd(ctx->hw_mgr_intf->hw_mgr_priv, |
| 2305 | &hw_cmd_args); |
| 2306 | if (rc) { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 2307 | CAM_ERR(CAM_ISP, "HW command failed"); |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 2308 | goto free_hw; |
| 2309 | } |
| 2310 | |
Suraj Dongre | 2681192 | 2018-06-27 19:30:01 -0700 | [diff] [blame] | 2311 | if (isp_hw_cmd_args.u.is_rdi_only_context) { |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 2312 | /* |
| 2313 | * this context has rdi only resource assign rdi only |
| 2314 | * state machine |
| 2315 | */ |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 2316 | CAM_DBG(CAM_ISP, "RDI only session Context"); |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 2317 | |
| 2318 | ctx_isp->substate_machine_irq = |
| 2319 | cam_isp_ctx_rdi_only_activated_state_machine_irq; |
| 2320 | ctx_isp->substate_machine = |
| 2321 | cam_isp_ctx_rdi_only_activated_state_machine; |
| 2322 | } else { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 2323 | CAM_DBG(CAM_ISP, "Session has PIX or PIX and RDI resources"); |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 2324 | ctx_isp->substate_machine_irq = |
| 2325 | cam_isp_ctx_activated_state_machine_irq; |
| 2326 | ctx_isp->substate_machine = |
| 2327 | cam_isp_ctx_activated_state_machine; |
| 2328 | } |
| 2329 | |
Suraj Dongre | 2681192 | 2018-06-27 19:30:01 -0700 | [diff] [blame] | 2330 | ctx_isp->rdi_only_context = isp_hw_cmd_args.u.is_rdi_only_context; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2331 | ctx_isp->hw_ctx = param.ctxt_to_hw_map; |
Suraj Dongre | 2681192 | 2018-06-27 19:30:01 -0700 | [diff] [blame] | 2332 | ctx->ctxt_to_hw_map = param.ctxt_to_hw_map; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2333 | |
| 2334 | req_hdl_param.session_hdl = cmd->session_handle; |
| 2335 | /* bridge is not ready for these flags. so false for now */ |
| 2336 | req_hdl_param.v4l2_sub_dev_flag = 0; |
| 2337 | req_hdl_param.media_entity_flag = 0; |
| 2338 | req_hdl_param.ops = ctx->crm_ctx_intf; |
| 2339 | req_hdl_param.priv = ctx; |
| 2340 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 2341 | CAM_DBG(CAM_ISP, "get device handle form bridge"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2342 | ctx->dev_hdl = cam_create_device_hdl(&req_hdl_param); |
| 2343 | if (ctx->dev_hdl <= 0) { |
| 2344 | rc = -EFAULT; |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 2345 | CAM_ERR(CAM_ISP, "Can not create device handle"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2346 | goto free_hw; |
| 2347 | } |
| 2348 | cmd->dev_handle = ctx->dev_hdl; |
| 2349 | |
| 2350 | /* store session information */ |
| 2351 | ctx->session_hdl = cmd->session_handle; |
Sridhar Gujje | 20c475a | 2018-11-14 15:58:09 +0530 | [diff] [blame] | 2352 | |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2353 | ctx->state = CAM_CTX_ACQUIRED; |
| 2354 | |
Gregory Bergschneider | 5164f3a | 2017-07-07 10:26:17 -0600 | [diff] [blame] | 2355 | trace_cam_context_state("ISP", ctx); |
Karthik Anantha Ram | 5438d57 | 2018-06-15 10:48:19 -0700 | [diff] [blame] | 2356 | CAM_DBG(CAM_ISP, |
Sridhar Gujje | 20c475a | 2018-11-14 15:58:09 +0530 | [diff] [blame] | 2357 | "Acquire success on session_hdl 0x%x num_rsrces %d RDI only %d ctx %u", |
| 2358 | cmd->session_handle, cmd->num_resources, |
Junzhe Zou | 2520a0e | 2018-09-04 15:17:08 -0700 | [diff] [blame] | 2359 | (isp_hw_cmd_args.u.is_rdi_only_context ? 1 : 0), ctx->ctx_id); |
Sridhar Gujje | 20c475a | 2018-11-14 15:58:09 +0530 | [diff] [blame] | 2360 | kfree(isp_res); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2361 | return rc; |
| 2362 | |
| 2363 | free_hw: |
| 2364 | release.ctxt_to_hw_map = ctx_isp->hw_ctx; |
| 2365 | ctx->hw_mgr_intf->hw_release(ctx->hw_mgr_intf->hw_mgr_priv, &release); |
| 2366 | ctx_isp->hw_ctx = NULL; |
| 2367 | free_res: |
Sridhar Gujje | 20c475a | 2018-11-14 15:58:09 +0530 | [diff] [blame] | 2368 | kfree(isp_res); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2369 | end: |
| 2370 | return rc; |
| 2371 | } |
| 2372 | |
| 2373 | static int __cam_isp_ctx_config_dev_in_acquired(struct cam_context *ctx, |
| 2374 | struct cam_config_dev_cmd *cmd) |
| 2375 | { |
| 2376 | int rc = 0; |
| 2377 | |
| 2378 | rc = __cam_isp_ctx_config_dev_in_top_state(ctx, cmd); |
| 2379 | |
Karthik Anantha Ram | 34dc265 | 2017-10-20 15:49:54 -0700 | [diff] [blame] | 2380 | if (!rc && (ctx->link_hdl >= 0)) { |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2381 | ctx->state = CAM_CTX_READY; |
Gregory Bergschneider | 5164f3a | 2017-07-07 10:26:17 -0600 | [diff] [blame] | 2382 | trace_cam_context_state("ISP", ctx); |
| 2383 | } |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2384 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 2385 | CAM_DBG(CAM_ISP, "next state %d", ctx->state); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2386 | return rc; |
| 2387 | } |
| 2388 | |
| 2389 | static int __cam_isp_ctx_link_in_acquired(struct cam_context *ctx, |
| 2390 | struct cam_req_mgr_core_dev_link_setup *link) |
| 2391 | { |
| 2392 | int rc = 0; |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 2393 | struct cam_isp_context *ctx_isp = |
| 2394 | (struct cam_isp_context *) ctx->ctx_priv; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2395 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 2396 | CAM_DBG(CAM_ISP, "Enter........."); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2397 | |
| 2398 | ctx->link_hdl = link->link_hdl; |
| 2399 | ctx->ctx_crm_intf = link->crm_cb; |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 2400 | ctx_isp->subscribe_event = link->subscribe_event; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2401 | |
| 2402 | /* change state only if we had the init config */ |
Sridhar Gujje | 20c475a | 2018-11-14 15:58:09 +0530 | [diff] [blame] | 2403 | if (!list_empty(&ctx->pending_req_list)) { |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2404 | ctx->state = CAM_CTX_READY; |
Gregory Bergschneider | 5164f3a | 2017-07-07 10:26:17 -0600 | [diff] [blame] | 2405 | trace_cam_context_state("ISP", ctx); |
| 2406 | } |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2407 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 2408 | CAM_DBG(CAM_ISP, "next state %d", ctx->state); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2409 | |
| 2410 | return rc; |
| 2411 | } |
| 2412 | |
| 2413 | static int __cam_isp_ctx_unlink_in_acquired(struct cam_context *ctx, |
| 2414 | struct cam_req_mgr_core_dev_link_setup *unlink) |
| 2415 | { |
| 2416 | int rc = 0; |
| 2417 | |
Karthik Anantha Ram | 34dc265 | 2017-10-20 15:49:54 -0700 | [diff] [blame] | 2418 | ctx->link_hdl = -1; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2419 | ctx->ctx_crm_intf = NULL; |
| 2420 | |
| 2421 | return rc; |
| 2422 | } |
| 2423 | |
| 2424 | static int __cam_isp_ctx_get_dev_info_in_acquired(struct cam_context *ctx, |
| 2425 | struct cam_req_mgr_device_info *dev_info) |
| 2426 | { |
| 2427 | int rc = 0; |
| 2428 | |
| 2429 | dev_info->dev_hdl = ctx->dev_hdl; |
| 2430 | strlcpy(dev_info->name, CAM_ISP_DEV_NAME, sizeof(dev_info->name)); |
| 2431 | dev_info->dev_id = CAM_REQ_MGR_DEVICE_IFE; |
| 2432 | dev_info->p_delay = 1; |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 2433 | dev_info->trigger = CAM_TRIGGER_POINT_SOF; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2434 | |
| 2435 | return rc; |
| 2436 | } |
| 2437 | |
| 2438 | static int __cam_isp_ctx_start_dev_in_ready(struct cam_context *ctx, |
| 2439 | struct cam_start_stop_dev_cmd *cmd) |
| 2440 | { |
| 2441 | int rc = 0; |
Alok Pandey | 12ce5ba | 2018-07-03 14:34:22 +0530 | [diff] [blame] | 2442 | struct cam_isp_start_args start_isp; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2443 | struct cam_ctx_request *req; |
| 2444 | struct cam_isp_ctx_req *req_isp; |
| 2445 | struct cam_isp_context *ctx_isp = |
| 2446 | (struct cam_isp_context *) ctx->ctx_priv; |
| 2447 | |
| 2448 | if (cmd->session_handle != ctx->session_hdl || |
| 2449 | cmd->dev_handle != ctx->dev_hdl) { |
| 2450 | rc = -EPERM; |
| 2451 | goto end; |
| 2452 | } |
| 2453 | |
| 2454 | if (list_empty(&ctx->pending_req_list)) { |
| 2455 | /* should never happen */ |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 2456 | CAM_ERR(CAM_ISP, "Start device with empty configuration"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2457 | rc = -EFAULT; |
| 2458 | goto end; |
| 2459 | } else { |
| 2460 | req = list_first_entry(&ctx->pending_req_list, |
| 2461 | struct cam_ctx_request, list); |
| 2462 | } |
| 2463 | req_isp = (struct cam_isp_ctx_req *) req->req_priv; |
| 2464 | |
| 2465 | if (!ctx_isp->hw_ctx) { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 2466 | CAM_ERR(CAM_ISP, "Wrong hw context pointer."); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2467 | rc = -EFAULT; |
| 2468 | goto end; |
| 2469 | } |
Vishalsingh Hajeri | e5450be | 2018-01-18 20:31:19 -0800 | [diff] [blame] | 2470 | |
Alok Pandey | 12ce5ba | 2018-07-03 14:34:22 +0530 | [diff] [blame] | 2471 | start_isp.hw_config.ctxt_to_hw_map = ctx_isp->hw_ctx; |
| 2472 | start_isp.hw_config.request_id = req->request_id; |
| 2473 | start_isp.hw_config.hw_update_entries = req_isp->cfg; |
| 2474 | start_isp.hw_config.num_hw_update_entries = req_isp->num_cfg; |
| 2475 | start_isp.hw_config.priv = &req_isp->hw_update_data; |
| 2476 | start_isp.hw_config.init_packet = 1; |
| 2477 | start_isp.start_only = false; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2478 | |
Ayush Kumar | f13969a9 | 2019-07-18 13:02:43 +0530 | [diff] [blame] | 2479 | atomic_set(&ctx_isp->process_bubble, 0); |
Shravya Samala | 43583ea | 2020-04-29 14:25:37 +0530 | [diff] [blame] | 2480 | atomic_set(&ctx_isp->bubble_sof_count, 0); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2481 | ctx_isp->frame_id = 0; |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 2482 | ctx_isp->active_req_cnt = 0; |
| 2483 | ctx_isp->reported_req_id = 0; |
Lynus Vaz | cbda4b0 | 2018-03-26 15:48:01 +0530 | [diff] [blame] | 2484 | ctx_isp->substate_activated = ctx_isp->rdi_only_context ? |
Harsh Shah | b2e04694 | 2018-05-09 15:41:07 -0700 | [diff] [blame] | 2485 | CAM_ISP_CTX_ACTIVATED_APPLIED : |
| 2486 | (req_isp->num_fence_map_out) ? CAM_ISP_CTX_ACTIVATED_EPOCH : |
| 2487 | CAM_ISP_CTX_ACTIVATED_SOF; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2488 | |
| 2489 | /* |
| 2490 | * Only place to change state before calling the hw due to |
| 2491 | * hardware tasklet has higher priority that can cause the |
| 2492 | * irq handling comes early |
| 2493 | */ |
| 2494 | ctx->state = CAM_CTX_ACTIVATED; |
Gregory Bergschneider | 5164f3a | 2017-07-07 10:26:17 -0600 | [diff] [blame] | 2495 | trace_cam_context_state("ISP", ctx); |
Alok Pandey | 12ce5ba | 2018-07-03 14:34:22 +0530 | [diff] [blame] | 2496 | rc = ctx->hw_mgr_intf->hw_start(ctx->hw_mgr_intf->hw_mgr_priv, |
| 2497 | &start_isp); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2498 | if (rc) { |
| 2499 | /* HW failure. user need to clean up the resource */ |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 2500 | CAM_ERR(CAM_ISP, "Start HW failed"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2501 | ctx->state = CAM_CTX_READY; |
Gregory Bergschneider | 5164f3a | 2017-07-07 10:26:17 -0600 | [diff] [blame] | 2502 | trace_cam_context_state("ISP", ctx); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2503 | goto end; |
| 2504 | } |
Karthik Anantha Ram | 5438d57 | 2018-06-15 10:48:19 -0700 | [diff] [blame] | 2505 | CAM_DBG(CAM_ISP, "start device success ctx %u", ctx->ctx_id); |
Harsh Shah | b2e04694 | 2018-05-09 15:41:07 -0700 | [diff] [blame] | 2506 | |
Junzhe Zou | e7d56fc | 2018-08-10 14:50:17 -0700 | [diff] [blame] | 2507 | list_del_init(&req->list); |
| 2508 | |
Harsh Shah | b2e04694 | 2018-05-09 15:41:07 -0700 | [diff] [blame] | 2509 | if (req_isp->num_fence_map_out) { |
Harsh Shah | b2e04694 | 2018-05-09 15:41:07 -0700 | [diff] [blame] | 2510 | list_add_tail(&req->list, &ctx->active_req_list); |
Junzhe Zou | e7d56fc | 2018-08-10 14:50:17 -0700 | [diff] [blame] | 2511 | ctx_isp->active_req_cnt++; |
| 2512 | } else { |
| 2513 | list_add_tail(&req->list, &ctx->wait_req_list); |
Harsh Shah | b2e04694 | 2018-05-09 15:41:07 -0700 | [diff] [blame] | 2514 | } |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2515 | end: |
| 2516 | return rc; |
| 2517 | } |
| 2518 | |
| 2519 | static int __cam_isp_ctx_unlink_in_ready(struct cam_context *ctx, |
| 2520 | struct cam_req_mgr_core_dev_link_setup *unlink) |
| 2521 | { |
| 2522 | int rc = 0; |
| 2523 | |
Karthik Anantha Ram | 34dc265 | 2017-10-20 15:49:54 -0700 | [diff] [blame] | 2524 | ctx->link_hdl = -1; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2525 | ctx->ctx_crm_intf = NULL; |
| 2526 | ctx->state = CAM_CTX_ACQUIRED; |
Gregory Bergschneider | 5164f3a | 2017-07-07 10:26:17 -0600 | [diff] [blame] | 2527 | trace_cam_context_state("ISP", ctx); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2528 | |
| 2529 | return rc; |
| 2530 | } |
| 2531 | |
| 2532 | static int __cam_isp_ctx_stop_dev_in_activated_unlock( |
Ravikishore Pampana | f7c7fd0 | 2018-02-02 18:11:38 +0530 | [diff] [blame] | 2533 | struct cam_context *ctx, struct cam_start_stop_dev_cmd *stop_cmd) |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2534 | { |
| 2535 | int rc = 0; |
| 2536 | uint32_t i; |
| 2537 | struct cam_hw_stop_args stop; |
| 2538 | struct cam_ctx_request *req; |
| 2539 | struct cam_isp_ctx_req *req_isp; |
| 2540 | struct cam_isp_context *ctx_isp = |
| 2541 | (struct cam_isp_context *) ctx->ctx_priv; |
Alok Pandey | 12ce5ba | 2018-07-03 14:34:22 +0530 | [diff] [blame] | 2542 | struct cam_isp_stop_args stop_isp; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2543 | |
| 2544 | /* Mask off all the incoming hardware events */ |
Jing Zhou | 93b3ec1 | 2017-06-15 17:43:39 -0700 | [diff] [blame] | 2545 | spin_lock_bh(&ctx->lock); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2546 | ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_HALT; |
Jing Zhou | 93b3ec1 | 2017-06-15 17:43:39 -0700 | [diff] [blame] | 2547 | spin_unlock_bh(&ctx->lock); |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 2548 | CAM_DBG(CAM_ISP, "next substate %d", ctx_isp->substate_activated); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2549 | |
| 2550 | /* stop hw first */ |
| 2551 | if (ctx_isp->hw_ctx) { |
| 2552 | stop.ctxt_to_hw_map = ctx_isp->hw_ctx; |
Alok Pandey | 12ce5ba | 2018-07-03 14:34:22 +0530 | [diff] [blame] | 2553 | |
| 2554 | if (stop_cmd) |
| 2555 | stop_isp.hw_stop_cmd = |
| 2556 | CAM_ISP_HW_STOP_AT_FRAME_BOUNDARY; |
| 2557 | else |
| 2558 | stop_isp.hw_stop_cmd = CAM_ISP_HW_STOP_IMMEDIATELY; |
| 2559 | |
| 2560 | stop_isp.stop_only = false; |
| 2561 | stop.args = (void *) &stop_isp; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2562 | ctx->hw_mgr_intf->hw_stop(ctx->hw_mgr_intf->hw_mgr_priv, |
| 2563 | &stop); |
| 2564 | } |
| 2565 | |
| 2566 | while (!list_empty(&ctx->pending_req_list)) { |
| 2567 | req = list_first_entry(&ctx->pending_req_list, |
| 2568 | struct cam_ctx_request, list); |
| 2569 | list_del_init(&req->list); |
| 2570 | req_isp = (struct cam_isp_ctx_req *) req->req_priv; |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 2571 | CAM_DBG(CAM_ISP, "signal fence in pending list. fence num %d", |
| 2572 | req_isp->num_fence_map_out); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2573 | for (i = 0; i < req_isp->num_fence_map_out; i++) |
| 2574 | if (req_isp->fence_map_out[i].sync_id != -1) { |
| 2575 | cam_sync_signal( |
| 2576 | req_isp->fence_map_out[i].sync_id, |
| 2577 | CAM_SYNC_STATE_SIGNALED_ERROR); |
| 2578 | } |
| 2579 | list_add_tail(&req->list, &ctx->free_req_list); |
| 2580 | } |
| 2581 | |
Alok Pandey | 12ce5ba | 2018-07-03 14:34:22 +0530 | [diff] [blame] | 2582 | while (!list_empty(&ctx->wait_req_list)) { |
| 2583 | req = list_first_entry(&ctx->wait_req_list, |
| 2584 | struct cam_ctx_request, list); |
| 2585 | list_del_init(&req->list); |
| 2586 | req_isp = (struct cam_isp_ctx_req *) req->req_priv; |
| 2587 | CAM_DBG(CAM_ISP, "signal fence in wait list. fence num %d", |
| 2588 | req_isp->num_fence_map_out); |
| 2589 | for (i = 0; i < req_isp->num_fence_map_out; i++) |
| 2590 | if (req_isp->fence_map_out[i].sync_id != -1) { |
| 2591 | cam_sync_signal( |
| 2592 | req_isp->fence_map_out[i].sync_id, |
| 2593 | CAM_SYNC_STATE_SIGNALED_ERROR); |
| 2594 | } |
| 2595 | list_add_tail(&req->list, &ctx->free_req_list); |
| 2596 | } |
| 2597 | |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2598 | while (!list_empty(&ctx->active_req_list)) { |
| 2599 | req = list_first_entry(&ctx->active_req_list, |
| 2600 | struct cam_ctx_request, list); |
| 2601 | list_del_init(&req->list); |
| 2602 | req_isp = (struct cam_isp_ctx_req *) req->req_priv; |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 2603 | CAM_DBG(CAM_ISP, "signal fence in active list. fence num %d", |
| 2604 | req_isp->num_fence_map_out); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2605 | for (i = 0; i < req_isp->num_fence_map_out; i++) |
| 2606 | if (req_isp->fence_map_out[i].sync_id != -1) { |
| 2607 | cam_sync_signal( |
| 2608 | req_isp->fence_map_out[i].sync_id, |
| 2609 | CAM_SYNC_STATE_SIGNALED_ERROR); |
| 2610 | } |
| 2611 | list_add_tail(&req->list, &ctx->free_req_list); |
| 2612 | } |
| 2613 | ctx_isp->frame_id = 0; |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 2614 | ctx_isp->active_req_cnt = 0; |
| 2615 | ctx_isp->reported_req_id = 0; |
Ayush Kumar | f13969a9 | 2019-07-18 13:02:43 +0530 | [diff] [blame] | 2616 | atomic_set(&ctx_isp->process_bubble, 0); |
Shravya Samala | 43583ea | 2020-04-29 14:25:37 +0530 | [diff] [blame] | 2617 | atomic_set(&ctx_isp->bubble_sof_count, 0); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2618 | |
Karthik Anantha Ram | 5438d57 | 2018-06-15 10:48:19 -0700 | [diff] [blame] | 2619 | CAM_DBG(CAM_ISP, "Stop device success next state %d on ctx %u", |
| 2620 | ctx->state, ctx->ctx_id); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2621 | return rc; |
| 2622 | } |
| 2623 | |
| 2624 | static int __cam_isp_ctx_stop_dev_in_activated(struct cam_context *ctx, |
| 2625 | struct cam_start_stop_dev_cmd *cmd) |
| 2626 | { |
| 2627 | int rc = 0; |
| 2628 | |
Ravikishore Pampana | f7c7fd0 | 2018-02-02 18:11:38 +0530 | [diff] [blame] | 2629 | __cam_isp_ctx_stop_dev_in_activated_unlock(ctx, cmd); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2630 | ctx->state = CAM_CTX_ACQUIRED; |
Gregory Bergschneider | 5164f3a | 2017-07-07 10:26:17 -0600 | [diff] [blame] | 2631 | trace_cam_context_state("ISP", ctx); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2632 | return rc; |
| 2633 | } |
| 2634 | |
| 2635 | static int __cam_isp_ctx_release_dev_in_activated(struct cam_context *ctx, |
| 2636 | struct cam_release_dev_cmd *cmd) |
| 2637 | { |
| 2638 | int rc = 0; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2639 | |
Ravikishore Pampana | f7c7fd0 | 2018-02-02 18:11:38 +0530 | [diff] [blame] | 2640 | rc = __cam_isp_ctx_stop_dev_in_activated_unlock(ctx, NULL); |
Harsh Shah | 2d96c5e | 2017-09-29 11:58:45 -0700 | [diff] [blame] | 2641 | if (rc) |
| 2642 | CAM_ERR(CAM_ISP, "Stop device failed rc=%d", rc); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2643 | |
Harsh Shah | 2d96c5e | 2017-09-29 11:58:45 -0700 | [diff] [blame] | 2644 | rc = __cam_isp_ctx_release_dev_in_top_state(ctx, cmd); |
| 2645 | if (rc) |
| 2646 | CAM_ERR(CAM_ISP, "Release device failed rc=%d", rc); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2647 | |
| 2648 | return rc; |
| 2649 | } |
| 2650 | |
Jing Zhou | 30504bd | 2017-11-21 11:36:07 -0800 | [diff] [blame] | 2651 | static int __cam_isp_ctx_link_pause(struct cam_context *ctx) |
| 2652 | { |
| 2653 | int rc = 0; |
Suraj Dongre | 2681192 | 2018-06-27 19:30:01 -0700 | [diff] [blame] | 2654 | struct cam_hw_cmd_args hw_cmd_args; |
| 2655 | struct cam_isp_hw_cmd_args isp_hw_cmd_args; |
Jing Zhou | 30504bd | 2017-11-21 11:36:07 -0800 | [diff] [blame] | 2656 | struct cam_isp_context *ctx_isp = |
| 2657 | (struct cam_isp_context *) ctx->ctx_priv; |
| 2658 | |
| 2659 | hw_cmd_args.ctxt_to_hw_map = ctx_isp->hw_ctx; |
Suraj Dongre | 2681192 | 2018-06-27 19:30:01 -0700 | [diff] [blame] | 2660 | hw_cmd_args.cmd_type = CAM_HW_MGR_CMD_INTERNAL; |
| 2661 | isp_hw_cmd_args.cmd_type = CAM_ISP_HW_MGR_CMD_PAUSE_HW; |
| 2662 | hw_cmd_args.u.internal_args = (void *)&isp_hw_cmd_args; |
Jing Zhou | 30504bd | 2017-11-21 11:36:07 -0800 | [diff] [blame] | 2663 | rc = ctx->hw_mgr_intf->hw_cmd(ctx->hw_mgr_intf->hw_mgr_priv, |
| 2664 | &hw_cmd_args); |
| 2665 | |
| 2666 | return rc; |
| 2667 | } |
| 2668 | |
| 2669 | static int __cam_isp_ctx_link_resume(struct cam_context *ctx) |
| 2670 | { |
| 2671 | int rc = 0; |
Suraj Dongre | 2681192 | 2018-06-27 19:30:01 -0700 | [diff] [blame] | 2672 | struct cam_hw_cmd_args hw_cmd_args; |
| 2673 | struct cam_isp_hw_cmd_args isp_hw_cmd_args; |
Jing Zhou | 30504bd | 2017-11-21 11:36:07 -0800 | [diff] [blame] | 2674 | struct cam_isp_context *ctx_isp = |
| 2675 | (struct cam_isp_context *) ctx->ctx_priv; |
| 2676 | |
| 2677 | hw_cmd_args.ctxt_to_hw_map = ctx_isp->hw_ctx; |
Suraj Dongre | 2681192 | 2018-06-27 19:30:01 -0700 | [diff] [blame] | 2678 | hw_cmd_args.cmd_type = CAM_HW_MGR_CMD_INTERNAL; |
| 2679 | isp_hw_cmd_args.cmd_type = CAM_ISP_HW_MGR_CMD_RESUME_HW; |
| 2680 | hw_cmd_args.u.internal_args = (void *)&isp_hw_cmd_args; |
Jing Zhou | 30504bd | 2017-11-21 11:36:07 -0800 | [diff] [blame] | 2681 | rc = ctx->hw_mgr_intf->hw_cmd(ctx->hw_mgr_intf->hw_mgr_priv, |
| 2682 | &hw_cmd_args); |
| 2683 | |
| 2684 | return rc; |
| 2685 | } |
| 2686 | |
Karthik Anantha Ram | 3ef71c3 | 2018-06-21 16:38:15 -0700 | [diff] [blame] | 2687 | static int __cam_isp_ctx_handle_sof_freeze_evt( |
| 2688 | struct cam_context *ctx) |
| 2689 | { |
| 2690 | int rc = 0; |
Suraj Dongre | 2681192 | 2018-06-27 19:30:01 -0700 | [diff] [blame] | 2691 | struct cam_hw_cmd_args hw_cmd_args; |
| 2692 | struct cam_isp_hw_cmd_args isp_hw_cmd_args; |
Karthik Anantha Ram | 3ef71c3 | 2018-06-21 16:38:15 -0700 | [diff] [blame] | 2693 | struct cam_isp_context *ctx_isp = |
| 2694 | (struct cam_isp_context *) ctx->ctx_priv; |
| 2695 | |
| 2696 | hw_cmd_args.ctxt_to_hw_map = ctx_isp->hw_ctx; |
Suraj Dongre | 2681192 | 2018-06-27 19:30:01 -0700 | [diff] [blame] | 2697 | hw_cmd_args.cmd_type = CAM_HW_MGR_CMD_INTERNAL; |
| 2698 | isp_hw_cmd_args.cmd_type = CAM_ISP_HW_MGR_CMD_SOF_DEBUG; |
| 2699 | isp_hw_cmd_args.u.sof_irq_enable = 1; |
| 2700 | hw_cmd_args.u.internal_args = (void *)&isp_hw_cmd_args; |
Karthik Anantha Ram | 3ef71c3 | 2018-06-21 16:38:15 -0700 | [diff] [blame] | 2701 | |
| 2702 | rc = ctx->hw_mgr_intf->hw_cmd(ctx->hw_mgr_intf->hw_mgr_priv, |
| 2703 | &hw_cmd_args); |
| 2704 | |
| 2705 | return rc; |
| 2706 | } |
| 2707 | |
Jing Zhou | 30504bd | 2017-11-21 11:36:07 -0800 | [diff] [blame] | 2708 | static int __cam_isp_ctx_process_evt(struct cam_context *ctx, |
| 2709 | struct cam_req_mgr_link_evt_data *link_evt_data) |
| 2710 | { |
| 2711 | int rc = 0; |
| 2712 | |
| 2713 | switch (link_evt_data->evt_type) { |
| 2714 | case CAM_REQ_MGR_LINK_EVT_ERR: |
| 2715 | /* No need to handle this message now */ |
| 2716 | break; |
| 2717 | case CAM_REQ_MGR_LINK_EVT_PAUSE: |
| 2718 | __cam_isp_ctx_link_pause(ctx); |
| 2719 | break; |
| 2720 | case CAM_REQ_MGR_LINK_EVT_RESUME: |
| 2721 | __cam_isp_ctx_link_resume(ctx); |
| 2722 | break; |
Karthik Anantha Ram | 3ef71c3 | 2018-06-21 16:38:15 -0700 | [diff] [blame] | 2723 | case CAM_REQ_MGR_LINK_EVT_SOF_FREEZE: |
| 2724 | __cam_isp_ctx_handle_sof_freeze_evt(ctx); |
| 2725 | break; |
Jing Zhou | 30504bd | 2017-11-21 11:36:07 -0800 | [diff] [blame] | 2726 | default: |
| 2727 | CAM_WARN(CAM_ISP, "Unknown event from CRM"); |
| 2728 | break; |
| 2729 | } |
| 2730 | return rc; |
| 2731 | } |
| 2732 | |
Harsh Shah | 6e4bc93 | 2017-11-07 06:15:12 -0800 | [diff] [blame] | 2733 | static int __cam_isp_ctx_unlink_in_activated(struct cam_context *ctx, |
| 2734 | struct cam_req_mgr_core_dev_link_setup *unlink) |
| 2735 | { |
| 2736 | int rc = 0; |
| 2737 | |
| 2738 | CAM_WARN(CAM_ISP, |
| 2739 | "Received unlink in activated state. It's unexpected"); |
Ravikishore Pampana | f7c7fd0 | 2018-02-02 18:11:38 +0530 | [diff] [blame] | 2740 | |
| 2741 | rc = __cam_isp_ctx_stop_dev_in_activated_unlock(ctx, NULL); |
Harsh Shah | 6e4bc93 | 2017-11-07 06:15:12 -0800 | [diff] [blame] | 2742 | if (rc) |
| 2743 | CAM_WARN(CAM_ISP, "Stop device failed rc=%d", rc); |
| 2744 | |
| 2745 | rc = __cam_isp_ctx_unlink_in_ready(ctx, unlink); |
| 2746 | if (rc) |
| 2747 | CAM_ERR(CAM_ISP, "Unlink failed rc=%d", rc); |
| 2748 | |
| 2749 | return rc; |
| 2750 | } |
| 2751 | |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2752 | static int __cam_isp_ctx_apply_req(struct cam_context *ctx, |
| 2753 | struct cam_req_mgr_apply_request *apply) |
| 2754 | { |
| 2755 | int rc = 0; |
Vishalsingh Hajeri | 7a431b7 | 2018-03-01 14:07:24 -0800 | [diff] [blame] | 2756 | struct cam_ctx_ops *ctx_ops = NULL; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2757 | struct cam_isp_context *ctx_isp = |
| 2758 | (struct cam_isp_context *) ctx->ctx_priv; |
| 2759 | |
Junzhe Zou | 5fa08b1 | 2017-08-15 10:08:12 -0700 | [diff] [blame] | 2760 | trace_cam_apply_req("ISP", apply->request_id); |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 2761 | CAM_DBG(CAM_ISP, "Enter: apply req in Substate %d request _id:%lld", |
| 2762 | ctx_isp->substate_activated, apply->request_id); |
Vishalsingh Hajeri | 7a431b7 | 2018-03-01 14:07:24 -0800 | [diff] [blame] | 2763 | ctx_ops = &ctx_isp->substate_machine[ctx_isp->substate_activated]; |
| 2764 | if (ctx_ops->crm_ops.apply_req) { |
| 2765 | rc = ctx_ops->crm_ops.apply_req(ctx, apply); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2766 | } else { |
Harsh Shah | cb0072c | 2017-09-26 19:22:10 -0700 | [diff] [blame] | 2767 | CAM_ERR_RATE_LIMIT(CAM_ISP, |
| 2768 | "No handle function in activated substate %d", |
| 2769 | ctx_isp->substate_activated); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2770 | rc = -EFAULT; |
| 2771 | } |
| 2772 | |
| 2773 | if (rc) |
Harsh Shah | cb0072c | 2017-09-26 19:22:10 -0700 | [diff] [blame] | 2774 | CAM_ERR_RATE_LIMIT(CAM_ISP, |
| 2775 | "Apply failed in active substate %d", |
| 2776 | ctx_isp->substate_activated); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2777 | return rc; |
| 2778 | } |
| 2779 | |
| 2780 | |
| 2781 | |
| 2782 | static int __cam_isp_ctx_handle_irq_in_activated(void *context, |
| 2783 | uint32_t evt_id, void *evt_data) |
| 2784 | { |
| 2785 | int rc = 0; |
Vishalsingh Hajeri | 7a431b7 | 2018-03-01 14:07:24 -0800 | [diff] [blame] | 2786 | struct cam_isp_ctx_irq_ops *irq_ops = NULL; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2787 | struct cam_context *ctx = (struct cam_context *)context; |
| 2788 | struct cam_isp_context *ctx_isp = |
| 2789 | (struct cam_isp_context *)ctx->ctx_priv; |
| 2790 | |
Jing Zhou | 93b3ec1 | 2017-06-15 17:43:39 -0700 | [diff] [blame] | 2791 | spin_lock_bh(&ctx->lock); |
Gregory Bergschneider | 5164f3a | 2017-07-07 10:26:17 -0600 | [diff] [blame] | 2792 | |
| 2793 | trace_cam_isp_activated_irq(ctx, ctx_isp->substate_activated, evt_id, |
| 2794 | __cam_isp_ctx_get_event_ts(evt_id, evt_data)); |
| 2795 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 2796 | CAM_DBG(CAM_ISP, "Enter: State %d, Substate %d, evt id %d", |
| 2797 | ctx->state, ctx_isp->substate_activated, evt_id); |
Vishalsingh Hajeri | 7a431b7 | 2018-03-01 14:07:24 -0800 | [diff] [blame] | 2798 | irq_ops = &ctx_isp->substate_machine_irq[ctx_isp->substate_activated]; |
| 2799 | if (irq_ops->irq_ops[evt_id]) { |
| 2800 | rc = irq_ops->irq_ops[evt_id](ctx_isp, evt_data); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2801 | } else { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 2802 | CAM_DBG(CAM_ISP, "No handle function for substate %d", |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2803 | ctx_isp->substate_activated); |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 2804 | __cam_isp_ctx_dump_state_monitor_array(ctx_isp); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2805 | } |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 2806 | CAM_DBG(CAM_ISP, "Exit: State %d Substate %d", |
| 2807 | ctx->state, ctx_isp->substate_activated); |
Jing Zhou | 93b3ec1 | 2017-06-15 17:43:39 -0700 | [diff] [blame] | 2808 | spin_unlock_bh(&ctx->lock); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2809 | return rc; |
| 2810 | } |
| 2811 | |
| 2812 | /* top state machine */ |
| 2813 | static struct cam_ctx_ops |
| 2814 | cam_isp_ctx_top_state_machine[CAM_CTX_STATE_MAX] = { |
| 2815 | /* Uninit */ |
| 2816 | { |
| 2817 | .ioctl_ops = {}, |
| 2818 | .crm_ops = {}, |
| 2819 | .irq_ops = NULL, |
| 2820 | }, |
| 2821 | /* Available */ |
| 2822 | { |
| 2823 | .ioctl_ops = { |
| 2824 | .acquire_dev = __cam_isp_ctx_acquire_dev_in_available, |
| 2825 | }, |
| 2826 | .crm_ops = {}, |
| 2827 | .irq_ops = NULL, |
| 2828 | }, |
| 2829 | /* Acquired */ |
| 2830 | { |
| 2831 | .ioctl_ops = { |
| 2832 | .release_dev = __cam_isp_ctx_release_dev_in_top_state, |
| 2833 | .config_dev = __cam_isp_ctx_config_dev_in_acquired, |
| 2834 | }, |
| 2835 | .crm_ops = { |
| 2836 | .link = __cam_isp_ctx_link_in_acquired, |
| 2837 | .unlink = __cam_isp_ctx_unlink_in_acquired, |
| 2838 | .get_dev_info = __cam_isp_ctx_get_dev_info_in_acquired, |
Jing Zhou | b524a85 | 2017-05-16 15:47:30 +0530 | [diff] [blame] | 2839 | .flush_req = __cam_isp_ctx_flush_req_in_top_state, |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2840 | }, |
| 2841 | .irq_ops = NULL, |
Suraj Dongre | 2681192 | 2018-06-27 19:30:01 -0700 | [diff] [blame] | 2842 | .pagefault_ops = cam_isp_context_dump_active_request, |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2843 | }, |
| 2844 | /* Ready */ |
| 2845 | { |
| 2846 | .ioctl_ops = { |
| 2847 | .start_dev = __cam_isp_ctx_start_dev_in_ready, |
| 2848 | .release_dev = __cam_isp_ctx_release_dev_in_top_state, |
| 2849 | .config_dev = __cam_isp_ctx_config_dev_in_top_state, |
| 2850 | }, |
| 2851 | .crm_ops = { |
| 2852 | .unlink = __cam_isp_ctx_unlink_in_ready, |
Jing Zhou | b524a85 | 2017-05-16 15:47:30 +0530 | [diff] [blame] | 2853 | .flush_req = __cam_isp_ctx_flush_req_in_ready, |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2854 | }, |
| 2855 | .irq_ops = NULL, |
Suraj Dongre | 2681192 | 2018-06-27 19:30:01 -0700 | [diff] [blame] | 2856 | .pagefault_ops = cam_isp_context_dump_active_request, |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2857 | }, |
| 2858 | /* Activated */ |
| 2859 | { |
| 2860 | .ioctl_ops = { |
| 2861 | .stop_dev = __cam_isp_ctx_stop_dev_in_activated, |
| 2862 | .release_dev = __cam_isp_ctx_release_dev_in_activated, |
| 2863 | .config_dev = __cam_isp_ctx_config_dev_in_top_state, |
| 2864 | }, |
| 2865 | .crm_ops = { |
Harsh Shah | 6e4bc93 | 2017-11-07 06:15:12 -0800 | [diff] [blame] | 2866 | .unlink = __cam_isp_ctx_unlink_in_activated, |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2867 | .apply_req = __cam_isp_ctx_apply_req, |
Junzhe Zou | fdcd472 | 2018-06-11 18:05:33 -0700 | [diff] [blame] | 2868 | .flush_req = __cam_isp_ctx_flush_req_in_top_state, |
Jing Zhou | 30504bd | 2017-11-21 11:36:07 -0800 | [diff] [blame] | 2869 | .process_evt = __cam_isp_ctx_process_evt, |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2870 | }, |
| 2871 | .irq_ops = __cam_isp_ctx_handle_irq_in_activated, |
Suraj Dongre | 2681192 | 2018-06-27 19:30:01 -0700 | [diff] [blame] | 2872 | .pagefault_ops = cam_isp_context_dump_active_request, |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2873 | }, |
| 2874 | }; |
| 2875 | |
| 2876 | |
Suraj Dongre | 2681192 | 2018-06-27 19:30:01 -0700 | [diff] [blame] | 2877 | static int cam_isp_context_dump_active_request(void *data, unsigned long iova, |
| 2878 | uint32_t buf_info) |
| 2879 | { |
| 2880 | |
| 2881 | struct cam_context *ctx = (struct cam_context *)data; |
| 2882 | struct cam_ctx_request *req = NULL; |
| 2883 | struct cam_ctx_request *req_temp = NULL; |
| 2884 | struct cam_isp_ctx_req *req_isp = NULL; |
| 2885 | struct cam_isp_prepare_hw_update_data *hw_update_data = NULL; |
| 2886 | struct cam_hw_mgr_dump_pf_data *pf_dbg_entry = NULL; |
| 2887 | bool mem_found = false; |
| 2888 | int rc = 0; |
| 2889 | |
| 2890 | struct cam_isp_context *isp_ctx = |
| 2891 | (struct cam_isp_context *)ctx->ctx_priv; |
| 2892 | |
| 2893 | if (!isp_ctx) { |
| 2894 | CAM_ERR(CAM_ISP, "Invalid isp ctx"); |
| 2895 | return -EINVAL; |
| 2896 | } |
| 2897 | |
| 2898 | CAM_INFO(CAM_ISP, "iommu fault handler for isp ctx %d state %d", |
| 2899 | ctx->ctx_id, ctx->state); |
| 2900 | |
| 2901 | list_for_each_entry_safe(req, req_temp, |
| 2902 | &ctx->active_req_list, list) { |
| 2903 | req_isp = (struct cam_isp_ctx_req *) req->req_priv; |
| 2904 | hw_update_data = &req_isp->hw_update_data; |
| 2905 | pf_dbg_entry = &(req->pf_data); |
| 2906 | CAM_INFO(CAM_ISP, "req_id : %lld ", req->request_id); |
| 2907 | |
| 2908 | rc = cam_context_dump_pf_info_to_hw(ctx, pf_dbg_entry->packet, |
| 2909 | iova, buf_info, &mem_found); |
| 2910 | if (rc) |
| 2911 | CAM_ERR(CAM_ISP, "Failed to dump pf info"); |
| 2912 | |
| 2913 | if (mem_found) |
| 2914 | CAM_ERR(CAM_ISP, "Found page fault in req %lld %d", |
| 2915 | req->request_id, rc); |
| 2916 | } |
| 2917 | |
| 2918 | return rc; |
| 2919 | } |
| 2920 | |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2921 | int cam_isp_context_init(struct cam_isp_context *ctx, |
| 2922 | struct cam_context *ctx_base, |
| 2923 | struct cam_req_mgr_kmd_ops *crm_node_intf, |
Pavan Kumar Chilamkurthi | 96fd3c9 | 2018-01-25 14:16:57 -0800 | [diff] [blame] | 2924 | struct cam_hw_mgr_intf *hw_intf, |
| 2925 | uint32_t ctx_id) |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2926 | |
| 2927 | { |
| 2928 | int rc = -1; |
| 2929 | int i; |
| 2930 | |
| 2931 | if (!ctx || !ctx_base) { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 2932 | CAM_ERR(CAM_ISP, "Invalid Context"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2933 | goto err; |
| 2934 | } |
| 2935 | |
| 2936 | /* ISP context setup */ |
| 2937 | memset(ctx, 0, sizeof(*ctx)); |
| 2938 | |
| 2939 | ctx->base = ctx_base; |
| 2940 | ctx->frame_id = 0; |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 2941 | ctx->active_req_cnt = 0; |
| 2942 | ctx->reported_req_id = 0; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2943 | ctx->hw_ctx = NULL; |
| 2944 | ctx->substate_activated = CAM_ISP_CTX_ACTIVATED_SOF; |
| 2945 | ctx->substate_machine = cam_isp_ctx_activated_state_machine; |
| 2946 | ctx->substate_machine_irq = cam_isp_ctx_activated_state_machine_irq; |
| 2947 | |
| 2948 | for (i = 0; i < CAM_CTX_REQ_MAX; i++) { |
| 2949 | ctx->req_base[i].req_priv = &ctx->req_isp[i]; |
| 2950 | ctx->req_isp[i].base = &ctx->req_base[i]; |
| 2951 | } |
| 2952 | |
| 2953 | /* camera context setup */ |
Pavan Kumar Chilamkurthi | 96fd3c9 | 2018-01-25 14:16:57 -0800 | [diff] [blame] | 2954 | rc = cam_context_init(ctx_base, isp_dev_name, CAM_ISP, ctx_id, |
| 2955 | crm_node_intf, hw_intf, ctx->req_base, CAM_CTX_REQ_MAX); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2956 | if (rc) { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 2957 | CAM_ERR(CAM_ISP, "Camera Context Base init failed"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2958 | goto err; |
| 2959 | } |
| 2960 | |
| 2961 | /* link camera context with isp context */ |
| 2962 | ctx_base->state_machine = cam_isp_ctx_top_state_machine; |
| 2963 | ctx_base->ctx_priv = ctx; |
| 2964 | |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 2965 | /* initializing current state for error logging */ |
| 2966 | for (i = 0; i < CAM_ISP_CTX_STATE_MONITOR_MAX_ENTRIES; i++) { |
| 2967 | ctx->cam_isp_ctx_state_monitor[i].curr_state = |
| 2968 | CAM_ISP_CTX_ACTIVATED_MAX; |
| 2969 | } |
| 2970 | atomic64_set(&ctx->state_monitor_head, -1); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2971 | err: |
| 2972 | return rc; |
| 2973 | } |
| 2974 | |
| 2975 | int cam_isp_context_deinit(struct cam_isp_context *ctx) |
| 2976 | { |
| 2977 | int rc = 0; |
| 2978 | |
| 2979 | if (ctx->base) |
| 2980 | cam_context_deinit(ctx->base); |
| 2981 | |
| 2982 | if (ctx->substate_activated != CAM_ISP_CTX_ACTIVATED_SOF) |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 2983 | CAM_ERR(CAM_ISP, "ISP context substate is invalid"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2984 | |
| 2985 | memset(ctx, 0, sizeof(*ctx)); |
| 2986 | return rc; |
| 2987 | } |