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