Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2017, The Linux Foundation. All rights reserved. |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #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 | |
Jing Zhou | 77962c5 | 2017-09-18 19:13:34 -0700 | [diff] [blame] | 27 | static int __cam_isp_ctx_enqueue_request_in_order( |
| 28 | struct cam_context *ctx, struct cam_ctx_request *req) |
| 29 | { |
| 30 | struct cam_ctx_request *req_current; |
| 31 | struct cam_ctx_request *req_prev; |
| 32 | struct list_head temp_list; |
| 33 | |
| 34 | INIT_LIST_HEAD(&temp_list); |
| 35 | spin_lock_bh(&ctx->lock); |
| 36 | if (list_empty(&ctx->pending_req_list)) { |
| 37 | list_add_tail(&req->list, &ctx->pending_req_list); |
| 38 | } else { |
| 39 | list_for_each_entry_safe_reverse( |
| 40 | req_current, req_prev, &ctx->pending_req_list, list) { |
| 41 | if (req->request_id < req_current->request_id) { |
| 42 | list_del_init(&req_current->list); |
| 43 | list_add(&req_current->list, &temp_list); |
| 44 | continue; |
| 45 | } else if (req->request_id == req_current->request_id) { |
| 46 | CAM_WARN(CAM_ISP, |
| 47 | "Received duplicated request %lld", |
| 48 | req->request_id); |
| 49 | } |
| 50 | break; |
| 51 | } |
| 52 | list_add_tail(&req->list, &ctx->pending_req_list); |
| 53 | |
| 54 | if (!list_empty(&temp_list)) { |
| 55 | list_for_each_entry_safe( |
| 56 | req_current, req_prev, &temp_list, list) { |
| 57 | list_del_init(&req_current->list); |
| 58 | list_add_tail(&req_current->list, |
| 59 | &ctx->pending_req_list); |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | spin_unlock_bh(&ctx->lock); |
| 64 | return 0; |
| 65 | } |
| 66 | |
Karthik Anantha Ram | ba3bd97 | 2017-09-25 15:35:26 -0700 | [diff] [blame] | 67 | static const char *__cam_isp_resource_handle_id_to_type |
| 68 | (uint32_t resource_handle) |
| 69 | { |
| 70 | switch (resource_handle) { |
| 71 | case CAM_ISP_IFE_OUT_RES_FULL: |
| 72 | return "CAM_ISP_IFE_OUT_RES_FULL"; |
| 73 | case CAM_ISP_IFE_OUT_RES_DS4: |
| 74 | return "CAM_ISP_IFE_OUT_RES_DS4"; |
| 75 | case CAM_ISP_IFE_OUT_RES_DS16: |
| 76 | return "CAM_ISP_IFE_OUT_RES_DS16"; |
| 77 | case CAM_ISP_IFE_OUT_RES_RAW_DUMP: |
| 78 | return "CAM_ISP_IFE_OUT_RES_RAW_DUMP"; |
| 79 | case CAM_ISP_IFE_OUT_RES_FD: |
| 80 | return "CAM_ISP_IFE_OUT_RES_FD"; |
| 81 | case CAM_ISP_IFE_OUT_RES_PDAF: |
| 82 | return "CAM_ISP_IFE_OUT_RES_PDAF"; |
| 83 | case CAM_ISP_IFE_OUT_RES_RDI_0: |
| 84 | return "CAM_ISP_IFE_OUT_RES_RDI_0"; |
| 85 | case CAM_ISP_IFE_OUT_RES_RDI_1: |
| 86 | return "CAM_ISP_IFE_OUT_RES_RDI_1"; |
| 87 | case CAM_ISP_IFE_OUT_RES_RDI_2: |
| 88 | return "CAM_ISP_IFE_OUT_RES_RDI_2"; |
| 89 | case CAM_ISP_IFE_OUT_RES_RDI_3: |
| 90 | return "CAM_ISP_IFE_OUT_RES_RDI_3"; |
| 91 | case CAM_ISP_IFE_OUT_RES_STATS_HDR_BE: |
| 92 | return "CAM_ISP_IFE_OUT_RES_STATS_HDR_BE"; |
| 93 | case CAM_ISP_IFE_OUT_RES_STATS_HDR_BHIST: |
| 94 | return "CAM_ISP_IFE_OUT_RES_STATS_HDR_BHIST"; |
| 95 | case CAM_ISP_IFE_OUT_RES_STATS_TL_BG: |
| 96 | return "CAM_ISP_IFE_OUT_RES_STATS_TL_BG"; |
| 97 | case CAM_ISP_IFE_OUT_RES_STATS_BF: |
| 98 | return "CAM_ISP_IFE_OUT_RES_STATS_BF"; |
| 99 | case CAM_ISP_IFE_OUT_RES_STATS_AWB_BG: |
| 100 | return "CAM_ISP_IFE_OUT_RES_STATS_AWB_BG"; |
| 101 | case CAM_ISP_IFE_OUT_RES_STATS_BHIST: |
| 102 | return "CAM_ISP_IFE_OUT_RES_STATS_BHIST"; |
| 103 | case CAM_ISP_IFE_OUT_RES_STATS_RS: |
| 104 | return "CAM_ISP_IFE_OUT_RES_STATS_RS"; |
| 105 | case CAM_ISP_IFE_OUT_RES_STATS_CS: |
| 106 | return "CAM_ISP_IFE_OUT_RES_STATS_CS"; |
| 107 | default: |
| 108 | return "CAM_ISP_Invalid_Resource_Type"; |
| 109 | } |
| 110 | } |
| 111 | |
Gregory Bergschneider | 5164f3a | 2017-07-07 10:26:17 -0600 | [diff] [blame] | 112 | static uint64_t __cam_isp_ctx_get_event_ts(uint32_t evt_id, void *evt_data) |
| 113 | { |
| 114 | uint64_t ts = 0; |
| 115 | |
| 116 | if (!evt_data) |
| 117 | return 0; |
| 118 | |
| 119 | switch (evt_id) { |
| 120 | case CAM_ISP_HW_EVENT_ERROR: |
| 121 | ts = ((struct cam_isp_hw_error_event_data *)evt_data)-> |
| 122 | timestamp; |
| 123 | break; |
| 124 | case CAM_ISP_HW_EVENT_SOF: |
| 125 | ts = ((struct cam_isp_hw_sof_event_data *)evt_data)-> |
| 126 | timestamp; |
| 127 | break; |
| 128 | case CAM_ISP_HW_EVENT_REG_UPDATE: |
| 129 | ts = ((struct cam_isp_hw_reg_update_event_data *)evt_data)-> |
| 130 | timestamp; |
| 131 | break; |
| 132 | case CAM_ISP_HW_EVENT_EPOCH: |
| 133 | ts = ((struct cam_isp_hw_epoch_event_data *)evt_data)-> |
| 134 | timestamp; |
| 135 | break; |
| 136 | case CAM_ISP_HW_EVENT_EOF: |
| 137 | ts = ((struct cam_isp_hw_eof_event_data *)evt_data)-> |
| 138 | timestamp; |
| 139 | break; |
| 140 | case CAM_ISP_HW_EVENT_DONE: |
| 141 | break; |
| 142 | default: |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 143 | CAM_DBG(CAM_ISP, "Invalid Event Type %d", evt_id); |
Gregory Bergschneider | 5164f3a | 2017-07-07 10:26:17 -0600 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | return ts; |
| 147 | } |
| 148 | |
Karthik Anantha Ram | ba3bd97 | 2017-09-25 15:35:26 -0700 | [diff] [blame] | 149 | static void __cam_isp_ctx_handle_buf_done_fail_log( |
| 150 | struct cam_isp_ctx_req *req_isp) |
| 151 | { |
| 152 | int i; |
| 153 | |
Harsh Shah | 1b8eb23 | 2017-10-09 19:20:52 -0700 | [diff] [blame] | 154 | if (req_isp->num_fence_map_out >= CAM_ISP_CTX_RES_MAX) { |
| 155 | CAM_ERR_RATE_LIMIT(CAM_ISP, |
| 156 | "Num Resources exceed mMAX %d >= %d ", |
| 157 | req_isp->num_fence_map_out, CAM_ISP_CTX_RES_MAX); |
| 158 | return; |
| 159 | } |
| 160 | |
Karthik Anantha Ram | ba3bd97 | 2017-09-25 15:35:26 -0700 | [diff] [blame] | 161 | CAM_ERR_RATE_LIMIT(CAM_ISP, |
| 162 | "Resource Handles that fail to generate buf_done in prev frame"); |
| 163 | for (i = 0; i < req_isp->num_fence_map_out; i++) { |
| 164 | if (req_isp->fence_map_out[i].sync_id != -1) |
| 165 | CAM_ERR_RATE_LIMIT(CAM_ISP, |
| 166 | "Resource_Handle: [%s] Sync_ID: [0x%x]", |
| 167 | __cam_isp_resource_handle_id_to_type( |
| 168 | req_isp->fence_map_out[i].resource_handle), |
| 169 | req_isp->fence_map_out[i].sync_id); |
| 170 | } |
| 171 | } |
| 172 | |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 173 | static int __cam_isp_ctx_handle_buf_done_in_activated_state( |
| 174 | struct cam_isp_context *ctx_isp, |
| 175 | struct cam_isp_hw_done_event_data *done, |
| 176 | uint32_t bubble_state) |
| 177 | { |
| 178 | int rc = 0; |
| 179 | int i, j; |
| 180 | struct cam_ctx_request *req; |
| 181 | struct cam_isp_ctx_req *req_isp; |
| 182 | struct cam_context *ctx = ctx_isp->base; |
| 183 | |
| 184 | if (list_empty(&ctx->active_req_list)) { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 185 | CAM_DBG(CAM_ISP, "Buf done with no active request!"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 186 | goto end; |
| 187 | } |
| 188 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 189 | CAM_DBG(CAM_ISP, "Enter with bubble_state %d", bubble_state); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 190 | |
| 191 | req = list_first_entry(&ctx->active_req_list, |
| 192 | struct cam_ctx_request, list); |
Gregory Bergschneider | 5164f3a | 2017-07-07 10:26:17 -0600 | [diff] [blame] | 193 | |
| 194 | trace_cam_buf_done("ISP", ctx, req); |
| 195 | |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 196 | req_isp = (struct cam_isp_ctx_req *) req->req_priv; |
| 197 | for (i = 0; i < done->num_handles; i++) { |
| 198 | for (j = 0; j < req_isp->num_fence_map_out; j++) { |
| 199 | if (done->resource_handle[i] == |
| 200 | req_isp->fence_map_out[j].resource_handle) |
| 201 | break; |
| 202 | } |
| 203 | |
| 204 | if (j == req_isp->num_fence_map_out) { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 205 | CAM_ERR(CAM_ISP, |
| 206 | "Can not find matching lane handle 0x%x!", |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 207 | done->resource_handle[i]); |
| 208 | rc = -EINVAL; |
| 209 | continue; |
| 210 | } |
| 211 | |
Harsh Shah | 1b8eb23 | 2017-10-09 19:20:52 -0700 | [diff] [blame] | 212 | if (req_isp->fence_map_out[j].sync_id == -1) { |
| 213 | __cam_isp_ctx_handle_buf_done_fail_log(req_isp); |
| 214 | continue; |
| 215 | } |
Jing Zhou | bb536a8 | 2017-05-18 15:20:38 -0700 | [diff] [blame] | 216 | |
Harsh Shah | 1b8eb23 | 2017-10-09 19:20:52 -0700 | [diff] [blame] | 217 | if (!bubble_state) { |
| 218 | CAM_DBG(CAM_ISP, |
| 219 | "Sync with success: req %lld res 0x%x fd 0x%x", |
| 220 | req->request_id, |
| 221 | req_isp->fence_map_out[j].resource_handle, |
| 222 | req_isp->fence_map_out[j].sync_id); |
| 223 | |
| 224 | rc = cam_sync_signal(req_isp->fence_map_out[j].sync_id, |
| 225 | CAM_SYNC_STATE_SIGNALED_SUCCESS); |
| 226 | if (rc) |
| 227 | CAM_DBG(CAM_ISP, "Sync failed with rc = %d", |
| 228 | rc); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 229 | } else if (!req_isp->bubble_report) { |
Harsh Shah | 1b8eb23 | 2017-10-09 19:20:52 -0700 | [diff] [blame] | 230 | CAM_DBG(CAM_ISP, |
| 231 | "Sync with failure: req %lld res 0x%x fd 0x%x", |
| 232 | req->request_id, |
| 233 | req_isp->fence_map_out[j].resource_handle, |
| 234 | req_isp->fence_map_out[j].sync_id); |
| 235 | |
Jing Zhou | bb536a8 | 2017-05-18 15:20:38 -0700 | [diff] [blame] | 236 | rc = cam_sync_signal(req_isp->fence_map_out[j].sync_id, |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 237 | CAM_SYNC_STATE_SIGNALED_ERROR); |
Jing Zhou | bb536a8 | 2017-05-18 15:20:38 -0700 | [diff] [blame] | 238 | if (rc) |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 239 | CAM_ERR(CAM_ISP, "Sync failed with rc = %d", |
Harsh Shah | 1b8eb23 | 2017-10-09 19:20:52 -0700 | [diff] [blame] | 240 | rc); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 241 | } else { |
| 242 | /* |
| 243 | * Ignore the buffer done if bubble detect is on |
| 244 | * In most case, active list should be empty when |
| 245 | * bubble detects. But for safety, we just move the |
| 246 | * current active request to the pending list here. |
| 247 | */ |
Harsh Shah | 1b8eb23 | 2017-10-09 19:20:52 -0700 | [diff] [blame] | 248 | CAM_DBG(CAM_ISP, |
| 249 | "buf done with bubble state %d recovery %d", |
| 250 | bubble_state, req_isp->bubble_report); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 251 | list_del_init(&req->list); |
| 252 | list_add(&req->list, &ctx->pending_req_list); |
| 253 | continue; |
| 254 | } |
| 255 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 256 | CAM_DBG(CAM_ISP, "req %lld, reset sync id 0x%x", |
Harsh Shah | 1b8eb23 | 2017-10-09 19:20:52 -0700 | [diff] [blame] | 257 | req->request_id, |
| 258 | req_isp->fence_map_out[j].sync_id); |
| 259 | if (!rc) { |
| 260 | req_isp->num_acked++; |
| 261 | req_isp->fence_map_out[j].sync_id = -1; |
| 262 | } |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 263 | } |
| 264 | |
Harsh Shah | 1b8eb23 | 2017-10-09 19:20:52 -0700 | [diff] [blame] | 265 | if (req_isp->num_acked > req_isp->num_fence_map_out) { |
| 266 | /* Should not happen */ |
| 267 | CAM_ERR(CAM_ISP, |
| 268 | "WARNING: req_id %lld num_acked %d > map_out %d", |
| 269 | req->request_id, req_isp->num_acked, |
| 270 | req_isp->num_fence_map_out); |
| 271 | WARN_ON(req_isp->num_acked > req_isp->num_fence_map_out); |
| 272 | } |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 273 | if (req_isp->num_acked == req_isp->num_fence_map_out) { |
| 274 | list_del_init(&req->list); |
| 275 | list_add_tail(&req->list, &ctx->free_req_list); |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 276 | ctx_isp->active_req_cnt--; |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 277 | CAM_DBG(CAM_ISP, |
| 278 | "Move active request %lld to free list(cnt = %d)", |
| 279 | req->request_id, ctx_isp->active_req_cnt); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | end: |
| 283 | return rc; |
| 284 | } |
| 285 | |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 286 | static void __cam_isp_ctx_send_sof_timestamp( |
| 287 | struct cam_isp_context *ctx_isp, uint64_t request_id, |
| 288 | uint32_t sof_event_status) |
| 289 | { |
| 290 | struct cam_req_mgr_message req_msg; |
| 291 | |
| 292 | req_msg.session_hdl = ctx_isp->base->session_hdl; |
| 293 | req_msg.u.frame_msg.frame_id = ctx_isp->frame_id; |
| 294 | req_msg.u.frame_msg.request_id = request_id; |
| 295 | req_msg.u.frame_msg.timestamp = ctx_isp->sof_timestamp_val; |
| 296 | req_msg.u.frame_msg.link_hdl = ctx_isp->base->link_hdl; |
| 297 | req_msg.u.frame_msg.sof_status = sof_event_status; |
| 298 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 299 | CAM_DBG(CAM_ISP, |
| 300 | "request id:%lld frame number:%lld SOF time stamp:0x%llx", |
| 301 | request_id, ctx_isp->frame_id, |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 302 | ctx_isp->sof_timestamp_val); |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 303 | CAM_DBG(CAM_ISP, " sof status:%d", sof_event_status); |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 304 | |
| 305 | if (cam_req_mgr_notify_frame_message(&req_msg, |
| 306 | V4L_EVENT_CAM_REQ_MGR_SOF, V4L_EVENT_CAM_REQ_MGR_EVENT)) |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 307 | CAM_ERR(CAM_ISP, |
| 308 | "Error in notifying the sof time for req id:%lld", |
| 309 | request_id); |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 310 | } |
| 311 | |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 312 | static int __cam_isp_ctx_reg_upd_in_activated_state( |
| 313 | struct cam_isp_context *ctx_isp, void *evt_data) |
| 314 | { |
| 315 | int rc = 0; |
| 316 | struct cam_ctx_request *req; |
| 317 | struct cam_context *ctx = ctx_isp->base; |
| 318 | struct cam_isp_ctx_req *req_isp; |
| 319 | |
| 320 | if (list_empty(&ctx->pending_req_list)) { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 321 | CAM_ERR(CAM_ISP, "Reg upd ack with no pending request"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 322 | goto end; |
| 323 | } |
| 324 | req = list_first_entry(&ctx->pending_req_list, |
| 325 | struct cam_ctx_request, list); |
| 326 | list_del_init(&req->list); |
| 327 | |
| 328 | req_isp = (struct cam_isp_ctx_req *) req->req_priv; |
| 329 | if (req_isp->num_fence_map_out != 0) { |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 330 | list_add_tail(&req->list, &ctx->active_req_list); |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 331 | ctx_isp->active_req_cnt++; |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 332 | CAM_DBG(CAM_ISP, "move request %lld to active list(cnt = %d)", |
| 333 | req->request_id, ctx_isp->active_req_cnt); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 334 | } else { |
| 335 | /* no io config, so the request is completed. */ |
| 336 | list_add_tail(&req->list, &ctx->free_req_list); |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 337 | CAM_DBG(CAM_ISP, |
| 338 | "move active request %lld to free list(cnt = %d)", |
| 339 | req->request_id, ctx_isp->active_req_cnt); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | /* |
| 343 | * This function only called directly from applied and bubble applied |
| 344 | * state so change substate here. |
| 345 | */ |
| 346 | ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_EPOCH; |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 347 | CAM_DBG(CAM_ISP, "next substate %d", ctx_isp->substate_activated); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 348 | |
| 349 | end: |
| 350 | return rc; |
| 351 | } |
| 352 | |
| 353 | static int __cam_isp_ctx_notify_sof_in_actived_state( |
| 354 | struct cam_isp_context *ctx_isp, void *evt_data) |
| 355 | { |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 356 | int rc = 0; |
| 357 | struct cam_req_mgr_trigger_notify notify; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 358 | struct cam_context *ctx = ctx_isp->base; |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 359 | struct cam_ctx_request *req; |
| 360 | uint64_t request_id = 0; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 361 | |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 362 | /* |
| 363 | * notify reqmgr with sof signal. Note, due to scheduling delay |
| 364 | * we can run into situation that two active requests has already |
| 365 | * be in the active queue while we try to do the notification. |
| 366 | * In this case, we need to skip the current notification. This |
| 367 | * helps the state machine to catch up the delay. |
| 368 | */ |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 369 | if (ctx->ctx_crm_intf && ctx->ctx_crm_intf->notify_trigger && |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 370 | ctx_isp->active_req_cnt <= 2) { |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 371 | if (ctx_isp->subscribe_event & CAM_TRIGGER_POINT_SOF) { |
| 372 | notify.link_hdl = ctx->link_hdl; |
| 373 | notify.dev_hdl = ctx->dev_hdl; |
| 374 | notify.frame_id = ctx_isp->frame_id; |
| 375 | notify.trigger = CAM_TRIGGER_POINT_SOF; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 376 | |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 377 | ctx->ctx_crm_intf->notify_trigger(¬ify); |
| 378 | CAM_DBG(CAM_ISP, "Notify CRM SOF frame %lld", |
| 379 | ctx_isp->frame_id); |
| 380 | } |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 381 | |
| 382 | list_for_each_entry(req, &ctx->active_req_list, list) { |
| 383 | if (req->request_id > ctx_isp->reported_req_id) { |
| 384 | request_id = req->request_id; |
| 385 | ctx_isp->reported_req_id = request_id; |
| 386 | break; |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | __cam_isp_ctx_send_sof_timestamp(ctx_isp, request_id, |
| 391 | CAM_REQ_MGR_SOF_EVENT_SUCCESS); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 392 | } else { |
Harsh Shah | cb0072c | 2017-09-26 19:22:10 -0700 | [diff] [blame] | 393 | CAM_ERR_RATE_LIMIT(CAM_ISP, "Can not notify SOF to CRM"); |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 394 | rc = -EFAULT; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 395 | } |
| 396 | |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 397 | return 0; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 398 | } |
| 399 | |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 400 | static int __cam_isp_ctx_notify_eof_in_actived_state( |
| 401 | struct cam_isp_context *ctx_isp, void *evt_data) |
| 402 | { |
| 403 | int rc = 0; |
| 404 | struct cam_req_mgr_trigger_notify notify; |
| 405 | struct cam_context *ctx = ctx_isp->base; |
| 406 | |
| 407 | if (!(ctx_isp->subscribe_event & CAM_TRIGGER_POINT_EOF)) |
| 408 | return rc; |
| 409 | |
| 410 | /* notify reqmgr with eof signal */ |
| 411 | if (ctx->ctx_crm_intf && ctx->ctx_crm_intf->notify_trigger) { |
| 412 | notify.link_hdl = ctx->link_hdl; |
| 413 | notify.dev_hdl = ctx->dev_hdl; |
| 414 | notify.frame_id = ctx_isp->frame_id; |
| 415 | notify.trigger = CAM_TRIGGER_POINT_EOF; |
| 416 | |
| 417 | ctx->ctx_crm_intf->notify_trigger(¬ify); |
| 418 | CAM_DBG(CAM_ISP, "Notify CRM EOF frame %lld\n", |
| 419 | ctx_isp->frame_id); |
| 420 | } else { |
| 421 | CAM_ERR(CAM_ISP, "Can not notify EOF to CRM"); |
| 422 | rc = -EFAULT; |
| 423 | } |
| 424 | |
| 425 | return rc; |
| 426 | } |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 427 | |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 428 | static int __cam_isp_ctx_sof_in_activated_state( |
| 429 | struct cam_isp_context *ctx_isp, void *evt_data) |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 430 | { |
| 431 | int rc = 0; |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 432 | struct cam_isp_hw_sof_event_data *sof_event_data = evt_data; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 433 | |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 434 | if (!evt_data) { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 435 | CAM_ERR(CAM_ISP, "in valid sof event data"); |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 436 | return -EINVAL; |
| 437 | } |
| 438 | |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 439 | ctx_isp->frame_id++; |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 440 | ctx_isp->sof_timestamp_val = sof_event_data->timestamp; |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 441 | CAM_DBG(CAM_ISP, "frame id: %lld time stamp:0x%llx", |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 442 | ctx_isp->frame_id, ctx_isp->sof_timestamp_val); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 443 | |
| 444 | return rc; |
| 445 | } |
| 446 | |
| 447 | static int __cam_isp_ctx_reg_upd_in_sof(struct cam_isp_context *ctx_isp, |
| 448 | void *evt_data) |
| 449 | { |
| 450 | int rc = 0; |
| 451 | struct cam_ctx_request *req; |
| 452 | struct cam_isp_ctx_req *req_isp; |
| 453 | struct cam_context *ctx = ctx_isp->base; |
| 454 | |
| 455 | if (ctx->state != CAM_CTX_ACTIVATED) { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 456 | CAM_DBG(CAM_ISP, "invalid RUP"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 457 | goto end; |
| 458 | } |
| 459 | |
| 460 | /* |
| 461 | * This is for the first update. The initial setting will |
| 462 | * cause the reg_upd in the first frame. |
| 463 | */ |
| 464 | if (!list_empty(&ctx->pending_req_list)) { |
| 465 | req = list_first_entry(&ctx->pending_req_list, |
| 466 | struct cam_ctx_request, list); |
| 467 | list_del_init(&req->list); |
| 468 | req_isp = (struct cam_isp_ctx_req *) req->req_priv; |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 469 | if (req_isp->num_fence_map_out == req_isp->num_acked) { |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 470 | list_add_tail(&req->list, &ctx->free_req_list); |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 471 | } else { |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 472 | /* need to handle the buf done */ |
| 473 | list_add_tail(&req->list, &ctx->active_req_list); |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 474 | ctx_isp->active_req_cnt++; |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 475 | CAM_DBG(CAM_ISP, |
| 476 | "move request %lld to active list(cnt = %d)", |
| 477 | req->request_id, |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 478 | ctx_isp->active_req_cnt); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 479 | ctx_isp->substate_activated = |
| 480 | CAM_ISP_CTX_ACTIVATED_EPOCH; |
| 481 | } |
| 482 | } |
| 483 | end: |
| 484 | return rc; |
| 485 | } |
| 486 | |
| 487 | static int __cam_isp_ctx_epoch_in_applied(struct cam_isp_context *ctx_isp, |
| 488 | void *evt_data) |
| 489 | { |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 490 | struct cam_ctx_request *req; |
| 491 | struct cam_isp_ctx_req *req_isp; |
| 492 | struct cam_context *ctx = ctx_isp->base; |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 493 | uint64_t request_id = 0; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 494 | |
| 495 | if (list_empty(&ctx->pending_req_list)) { |
| 496 | /* |
| 497 | * If no pending req in epoch, this is an error case. |
| 498 | * The recovery is to go back to sof state |
| 499 | */ |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 500 | CAM_ERR(CAM_ISP, "No pending request"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 501 | ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_SOF; |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 502 | |
| 503 | /* Send SOF event as empty frame*/ |
| 504 | __cam_isp_ctx_send_sof_timestamp(ctx_isp, request_id, |
| 505 | CAM_REQ_MGR_SOF_EVENT_SUCCESS); |
| 506 | |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 507 | goto end; |
| 508 | } |
| 509 | |
| 510 | req = list_first_entry(&ctx->pending_req_list, struct cam_ctx_request, |
| 511 | list); |
| 512 | req_isp = (struct cam_isp_ctx_req *)req->req_priv; |
| 513 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 514 | CAM_DBG(CAM_ISP, "Report Bubble flag %d", req_isp->bubble_report); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 515 | if (req_isp->bubble_report && ctx->ctx_crm_intf && |
| 516 | ctx->ctx_crm_intf->notify_err) { |
| 517 | struct cam_req_mgr_error_notify notify; |
| 518 | |
| 519 | notify.link_hdl = ctx->link_hdl; |
| 520 | notify.dev_hdl = ctx->dev_hdl; |
| 521 | notify.req_id = req->request_id; |
| 522 | notify.error = CRM_KMD_ERR_BUBBLE; |
| 523 | ctx->ctx_crm_intf->notify_err(¬ify); |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 524 | CAM_DBG(CAM_ISP, "Notify CRM about Bubble frame %lld", |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 525 | ctx_isp->frame_id); |
Jing Zhou | 45b55cc | 2017-05-16 17:27:18 -0700 | [diff] [blame] | 526 | } else { |
| 527 | /* |
| 528 | * Since can not bubble report, always move the request to |
| 529 | * active list. |
| 530 | */ |
| 531 | list_del_init(&req->list); |
| 532 | list_add_tail(&req->list, &ctx->active_req_list); |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 533 | ctx_isp->active_req_cnt++; |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 534 | CAM_DBG(CAM_ISP, "move request %lld to active list(cnt = %d)", |
| 535 | req->request_id, ctx_isp->active_req_cnt); |
Jing Zhou | 45b55cc | 2017-05-16 17:27:18 -0700 | [diff] [blame] | 536 | req_isp->bubble_report = 0; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 537 | } |
| 538 | |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 539 | request_id = req->request_id; |
| 540 | __cam_isp_ctx_send_sof_timestamp(ctx_isp, request_id, |
| 541 | CAM_REQ_MGR_SOF_EVENT_ERROR); |
| 542 | |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 543 | ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_BUBBLE; |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 544 | CAM_DBG(CAM_ISP, "next substate %d", |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 545 | ctx_isp->substate_activated); |
| 546 | end: |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 547 | return 0; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | |
| 551 | static int __cam_isp_ctx_buf_done_in_applied(struct cam_isp_context *ctx_isp, |
| 552 | void *evt_data) |
| 553 | { |
| 554 | int rc = 0; |
| 555 | struct cam_isp_hw_done_event_data *done = |
| 556 | (struct cam_isp_hw_done_event_data *) evt_data; |
| 557 | |
| 558 | rc = __cam_isp_ctx_handle_buf_done_in_activated_state(ctx_isp, done, 0); |
| 559 | return rc; |
| 560 | } |
| 561 | |
| 562 | |
| 563 | static int __cam_isp_ctx_sof_in_epoch(struct cam_isp_context *ctx_isp, |
| 564 | void *evt_data) |
| 565 | { |
| 566 | int rc = 0; |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 567 | struct cam_context *ctx = ctx_isp->base; |
| 568 | struct cam_isp_hw_sof_event_data *sof_event_data = evt_data; |
Jing Zhou | 93b3ec1 | 2017-06-15 17:43:39 -0700 | [diff] [blame] | 569 | |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 570 | if (!evt_data) { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 571 | CAM_ERR(CAM_ISP, "in valid sof event data"); |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 572 | return -EINVAL; |
| 573 | } |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 574 | |
| 575 | ctx_isp->frame_id++; |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 576 | ctx_isp->sof_timestamp_val = sof_event_data->timestamp; |
| 577 | |
Jing Zhou | 93b3ec1 | 2017-06-15 17:43:39 -0700 | [diff] [blame] | 578 | if (list_empty(&ctx->active_req_list)) |
| 579 | ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_SOF; |
| 580 | else |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 581 | CAM_DBG(CAM_ISP, "Still need to wait for the buf done"); |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 582 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 583 | CAM_DBG(CAM_ISP, "next substate %d", |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 584 | ctx_isp->substate_activated); |
| 585 | |
| 586 | return rc; |
| 587 | } |
| 588 | |
| 589 | static int __cam_isp_ctx_buf_done_in_epoch(struct cam_isp_context *ctx_isp, |
| 590 | void *evt_data) |
| 591 | { |
| 592 | int rc = 0; |
| 593 | struct cam_isp_hw_done_event_data *done = |
| 594 | (struct cam_isp_hw_done_event_data *) evt_data; |
| 595 | |
| 596 | rc = __cam_isp_ctx_handle_buf_done_in_activated_state(ctx_isp, done, 0); |
| 597 | return rc; |
| 598 | } |
| 599 | |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 600 | static int __cam_isp_ctx_buf_done_in_bubble( |
| 601 | struct cam_isp_context *ctx_isp, void *evt_data) |
| 602 | { |
| 603 | int rc = 0; |
| 604 | struct cam_isp_hw_done_event_data *done = |
| 605 | (struct cam_isp_hw_done_event_data *) evt_data; |
| 606 | |
| 607 | rc = __cam_isp_ctx_handle_buf_done_in_activated_state(ctx_isp, done, 1); |
| 608 | return rc; |
| 609 | } |
| 610 | |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 611 | static int __cam_isp_ctx_epoch_in_bubble_applied( |
| 612 | struct cam_isp_context *ctx_isp, void *evt_data) |
| 613 | { |
| 614 | struct cam_ctx_request *req; |
| 615 | struct cam_isp_ctx_req *req_isp; |
| 616 | struct cam_context *ctx = ctx_isp->base; |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 617 | uint64_t request_id = 0; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 618 | |
| 619 | /* |
| 620 | * This means we missed the reg upd ack. So we need to |
| 621 | * transition to BUBBLE state again. |
| 622 | */ |
| 623 | |
| 624 | if (list_empty(&ctx->pending_req_list)) { |
| 625 | /* |
| 626 | * If no pending req in epoch, this is an error case. |
| 627 | * Just go back to the bubble state. |
| 628 | */ |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 629 | CAM_ERR(CAM_ISP, "No pending request."); |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 630 | __cam_isp_ctx_send_sof_timestamp(ctx_isp, request_id, |
| 631 | CAM_REQ_MGR_SOF_EVENT_SUCCESS); |
| 632 | |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 633 | ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_BUBBLE; |
| 634 | goto end; |
| 635 | } |
| 636 | |
| 637 | req = list_first_entry(&ctx->pending_req_list, struct cam_ctx_request, |
| 638 | list); |
| 639 | req_isp = (struct cam_isp_ctx_req *)req->req_priv; |
| 640 | |
| 641 | if (req_isp->bubble_report && ctx->ctx_crm_intf && |
| 642 | ctx->ctx_crm_intf->notify_err) { |
| 643 | struct cam_req_mgr_error_notify notify; |
| 644 | |
| 645 | notify.link_hdl = ctx->link_hdl; |
| 646 | notify.dev_hdl = ctx->dev_hdl; |
| 647 | notify.req_id = req->request_id; |
| 648 | notify.error = CRM_KMD_ERR_BUBBLE; |
| 649 | ctx->ctx_crm_intf->notify_err(¬ify); |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 650 | CAM_DBG(CAM_ISP, "Notify CRM about Bubble frame %lld", |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 651 | ctx_isp->frame_id); |
Jing Zhou | 45b55cc | 2017-05-16 17:27:18 -0700 | [diff] [blame] | 652 | } else { |
| 653 | /* |
| 654 | * If we can not report bubble, then treat it as if no bubble |
| 655 | * report. Just move the req to active list. |
| 656 | */ |
| 657 | list_del_init(&req->list); |
| 658 | list_add_tail(&req->list, &ctx->active_req_list); |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 659 | ctx_isp->active_req_cnt++; |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 660 | CAM_DBG(CAM_ISP, "move request %lld to active list(cnt = %d)", |
| 661 | req->request_id, ctx_isp->active_req_cnt); |
Jing Zhou | 45b55cc | 2017-05-16 17:27:18 -0700 | [diff] [blame] | 662 | req_isp->bubble_report = 0; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 663 | } |
| 664 | |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 665 | request_id = req->request_id; |
| 666 | __cam_isp_ctx_send_sof_timestamp(ctx_isp, request_id, |
| 667 | CAM_REQ_MGR_SOF_EVENT_ERROR); |
| 668 | |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 669 | ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_BUBBLE; |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 670 | CAM_DBG(CAM_ISP, "next substate %d", ctx_isp->substate_activated); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 671 | end: |
| 672 | return 0; |
| 673 | } |
| 674 | |
| 675 | static int __cam_isp_ctx_buf_done_in_bubble_applied( |
| 676 | struct cam_isp_context *ctx_isp, void *evt_data) |
| 677 | { |
| 678 | int rc = 0; |
| 679 | struct cam_isp_hw_done_event_data *done = |
| 680 | (struct cam_isp_hw_done_event_data *) evt_data; |
| 681 | |
| 682 | rc = __cam_isp_ctx_handle_buf_done_in_activated_state(ctx_isp, done, 1); |
| 683 | return rc; |
| 684 | } |
| 685 | |
| 686 | static int __cam_isp_ctx_handle_error(struct cam_isp_context *ctx_isp, |
| 687 | void *evt_data) |
| 688 | { |
| 689 | int rc = 0; |
| 690 | struct cam_ctx_request *req; |
| 691 | struct cam_req_mgr_error_notify notify; |
| 692 | |
| 693 | struct cam_context *ctx = ctx_isp->base; |
| 694 | struct cam_isp_hw_error_event_data *error_event_data = |
| 695 | (struct cam_isp_hw_error_event_data *)evt_data; |
| 696 | |
| 697 | uint32_t error_type = error_event_data->error_type; |
| 698 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 699 | CAM_DBG(CAM_ISP, "Enter error_type = %d", error_type); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 700 | if ((error_type == CAM_ISP_HW_ERROR_OVERFLOW) || |
| 701 | (error_type == CAM_ISP_HW_ERROR_BUSIF_OVERFLOW)) |
| 702 | notify.error = CRM_KMD_ERR_FATAL; |
| 703 | |
| 704 | /* |
| 705 | * Need to check the active req |
| 706 | * move all of them to the pending request list |
| 707 | * Note this funciton need revisit! |
| 708 | */ |
| 709 | |
| 710 | if (list_empty(&ctx->active_req_list)) { |
Harsh Shah | cb0072c | 2017-09-26 19:22:10 -0700 | [diff] [blame] | 711 | CAM_ERR_RATE_LIMIT(CAM_ISP, |
| 712 | "handling error with no active request"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 713 | rc = -EINVAL; |
| 714 | goto end; |
| 715 | } |
| 716 | |
| 717 | req = list_first_entry(&ctx->active_req_list, |
| 718 | struct cam_ctx_request, list); |
| 719 | |
| 720 | if (ctx->ctx_crm_intf && ctx->ctx_crm_intf->notify_err) { |
| 721 | notify.link_hdl = ctx->link_hdl; |
| 722 | notify.dev_hdl = ctx->dev_hdl; |
| 723 | notify.req_id = req->request_id; |
| 724 | |
| 725 | ctx->ctx_crm_intf->notify_err(¬ify); |
Harsh Shah | cb0072c | 2017-09-26 19:22:10 -0700 | [diff] [blame] | 726 | CAM_ERR_RATE_LIMIT(CAM_ISP, "Notify CRM about ERROR frame %lld", |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 727 | ctx_isp->frame_id); |
| 728 | } else { |
Harsh Shah | cb0072c | 2017-09-26 19:22:10 -0700 | [diff] [blame] | 729 | CAM_ERR_RATE_LIMIT(CAM_ISP, "Can not notify ERRROR to CRM"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 730 | rc = -EFAULT; |
| 731 | } |
| 732 | |
| 733 | list_del_init(&req->list); |
| 734 | list_add(&req->list, &ctx->pending_req_list); |
| 735 | /* might need to check if active list is empty */ |
| 736 | |
| 737 | end: |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 738 | CAM_DBG(CAM_ISP, "Exit"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 739 | return rc; |
| 740 | } |
| 741 | |
| 742 | static struct cam_isp_ctx_irq_ops |
| 743 | cam_isp_ctx_activated_state_machine_irq[CAM_ISP_CTX_ACTIVATED_MAX] = { |
| 744 | /* SOF */ |
| 745 | { |
| 746 | .irq_ops = { |
| 747 | NULL, |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 748 | __cam_isp_ctx_sof_in_activated_state, |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 749 | __cam_isp_ctx_reg_upd_in_sof, |
| 750 | __cam_isp_ctx_notify_sof_in_actived_state, |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 751 | __cam_isp_ctx_notify_eof_in_actived_state, |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 752 | NULL, |
| 753 | }, |
| 754 | }, |
| 755 | /* APPLIED */ |
| 756 | { |
| 757 | .irq_ops = { |
| 758 | __cam_isp_ctx_handle_error, |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 759 | __cam_isp_ctx_sof_in_activated_state, |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 760 | __cam_isp_ctx_reg_upd_in_activated_state, |
| 761 | __cam_isp_ctx_epoch_in_applied, |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 762 | __cam_isp_ctx_notify_eof_in_actived_state, |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 763 | __cam_isp_ctx_buf_done_in_applied, |
| 764 | }, |
| 765 | }, |
| 766 | /* EPOCH */ |
| 767 | { |
| 768 | .irq_ops = { |
| 769 | __cam_isp_ctx_handle_error, |
| 770 | __cam_isp_ctx_sof_in_epoch, |
| 771 | NULL, |
| 772 | __cam_isp_ctx_notify_sof_in_actived_state, |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 773 | __cam_isp_ctx_notify_eof_in_actived_state, |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 774 | __cam_isp_ctx_buf_done_in_epoch, |
| 775 | }, |
| 776 | }, |
| 777 | /* BUBBLE */ |
| 778 | { |
| 779 | .irq_ops = { |
| 780 | NULL, |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 781 | __cam_isp_ctx_sof_in_activated_state, |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 782 | NULL, |
| 783 | __cam_isp_ctx_notify_sof_in_actived_state, |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 784 | __cam_isp_ctx_notify_eof_in_actived_state, |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 785 | __cam_isp_ctx_buf_done_in_bubble, |
| 786 | }, |
| 787 | }, |
| 788 | /* Bubble Applied */ |
| 789 | { |
| 790 | .irq_ops = { |
| 791 | NULL, |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 792 | __cam_isp_ctx_sof_in_activated_state, |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 793 | __cam_isp_ctx_reg_upd_in_activated_state, |
| 794 | __cam_isp_ctx_epoch_in_bubble_applied, |
| 795 | NULL, |
| 796 | __cam_isp_ctx_buf_done_in_bubble_applied, |
| 797 | }, |
| 798 | }, |
| 799 | /* HALT */ |
| 800 | { |
| 801 | }, |
| 802 | }; |
| 803 | |
| 804 | static int __cam_isp_ctx_apply_req_in_activated_state( |
| 805 | struct cam_context *ctx, struct cam_req_mgr_apply_request *apply, |
| 806 | uint32_t next_state) |
| 807 | { |
| 808 | int rc = 0; |
| 809 | struct cam_ctx_request *req; |
Harsh Shah | 1b8eb23 | 2017-10-09 19:20:52 -0700 | [diff] [blame] | 810 | struct cam_ctx_request *active_req; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 811 | struct cam_isp_ctx_req *req_isp; |
Harsh Shah | 1b8eb23 | 2017-10-09 19:20:52 -0700 | [diff] [blame] | 812 | struct cam_isp_ctx_req *active_req_isp; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 813 | struct cam_isp_context *ctx_isp; |
| 814 | struct cam_hw_config_args cfg; |
| 815 | |
| 816 | if (list_empty(&ctx->pending_req_list)) { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 817 | CAM_ERR(CAM_ISP, "No available request for Apply id %lld", |
| 818 | apply->request_id); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 819 | rc = -EFAULT; |
| 820 | goto end; |
| 821 | } |
Jing Zhou | 9eabf47 | 2017-05-16 11:59:41 -0700 | [diff] [blame] | 822 | |
| 823 | /* |
| 824 | * When the pipeline has issue, the requests can be queued up in the |
| 825 | * pipeline. In this case, we should reject the additional request. |
| 826 | * The maximum number of request allowed to be outstanding is 2. |
| 827 | * |
| 828 | */ |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 829 | ctx_isp = (struct cam_isp_context *) ctx->ctx_priv; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 830 | req = list_first_entry(&ctx->pending_req_list, struct cam_ctx_request, |
| 831 | list); |
| 832 | |
| 833 | /* |
| 834 | * Check whehter the request id is matching the tip, if not, this means |
| 835 | * we are in the middle of the error handling. Need to reject this apply |
| 836 | */ |
| 837 | if (req->request_id != apply->request_id) { |
Harsh Shah | f713639 | 2017-08-29 12:42:52 -0700 | [diff] [blame] | 838 | CAM_ERR_RATE_LIMIT(CAM_ISP, |
| 839 | "Invalid Request Id asking %llu existing %llu", |
| 840 | apply->request_id, req->request_id); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 841 | rc = -EFAULT; |
| 842 | goto end; |
| 843 | } |
| 844 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 845 | CAM_DBG(CAM_ISP, "Apply request %lld", req->request_id); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 846 | req_isp = (struct cam_isp_ctx_req *) req->req_priv; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 847 | |
Karthik Anantha Ram | ba3bd97 | 2017-09-25 15:35:26 -0700 | [diff] [blame] | 848 | if (ctx_isp->active_req_cnt >= 2) { |
| 849 | CAM_ERR_RATE_LIMIT(CAM_ISP, |
Harsh Shah | 1b8eb23 | 2017-10-09 19:20:52 -0700 | [diff] [blame] | 850 | "Reject apply request (id %lld) due to congestion(cnt = %d)", |
| 851 | req->request_id, |
Karthik Anantha Ram | ba3bd97 | 2017-09-25 15:35:26 -0700 | [diff] [blame] | 852 | ctx_isp->active_req_cnt); |
Harsh Shah | 1b8eb23 | 2017-10-09 19:20:52 -0700 | [diff] [blame] | 853 | if (!list_empty(&ctx->active_req_list)) { |
| 854 | active_req = list_first_entry(&ctx->active_req_list, |
| 855 | struct cam_ctx_request, list); |
| 856 | active_req_isp = |
| 857 | (struct cam_isp_ctx_req *) active_req->req_priv; |
| 858 | __cam_isp_ctx_handle_buf_done_fail_log(active_req_isp); |
| 859 | } else { |
| 860 | CAM_ERR_RATE_LIMIT(CAM_ISP, |
| 861 | "WARNING: should not happen (cnt = %d) but active_list empty", |
| 862 | ctx_isp->active_req_cnt); |
| 863 | } |
| 864 | rc = -EFAULT; |
| 865 | goto end; |
Karthik Anantha Ram | ba3bd97 | 2017-09-25 15:35:26 -0700 | [diff] [blame] | 866 | } |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 867 | req_isp->bubble_report = apply->report_if_bubble; |
| 868 | |
| 869 | cfg.ctxt_to_hw_map = ctx_isp->hw_ctx; |
| 870 | cfg.hw_update_entries = req_isp->cfg; |
| 871 | cfg.num_hw_update_entries = req_isp->num_cfg; |
| 872 | |
| 873 | rc = ctx->hw_mgr_intf->hw_config(ctx->hw_mgr_intf->hw_mgr_priv, &cfg); |
| 874 | if (rc) { |
Harsh Shah | cb0072c | 2017-09-26 19:22:10 -0700 | [diff] [blame] | 875 | CAM_ERR_RATE_LIMIT(CAM_ISP, "Can not apply the configuration"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 876 | } else { |
Jing Zhou | 93b3ec1 | 2017-06-15 17:43:39 -0700 | [diff] [blame] | 877 | spin_lock_bh(&ctx->lock); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 878 | ctx_isp->substate_activated = next_state; |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 879 | CAM_DBG(CAM_ISP, "new state %d", next_state); |
Jing Zhou | 93b3ec1 | 2017-06-15 17:43:39 -0700 | [diff] [blame] | 880 | spin_unlock_bh(&ctx->lock); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 881 | } |
| 882 | end: |
| 883 | return rc; |
| 884 | } |
| 885 | |
| 886 | static int __cam_isp_ctx_apply_req_in_sof( |
| 887 | struct cam_context *ctx, struct cam_req_mgr_apply_request *apply) |
| 888 | { |
| 889 | int rc = 0; |
| 890 | struct cam_isp_context *ctx_isp = |
| 891 | (struct cam_isp_context *) ctx->ctx_priv; |
| 892 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 893 | CAM_DBG(CAM_ISP, "current substate %d", |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 894 | ctx_isp->substate_activated); |
| 895 | rc = __cam_isp_ctx_apply_req_in_activated_state(ctx, apply, |
| 896 | CAM_ISP_CTX_ACTIVATED_APPLIED); |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 897 | CAM_DBG(CAM_ISP, "new substate %d", ctx_isp->substate_activated); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 898 | |
| 899 | return rc; |
| 900 | } |
| 901 | |
| 902 | static int __cam_isp_ctx_apply_req_in_epoch( |
| 903 | struct cam_context *ctx, struct cam_req_mgr_apply_request *apply) |
| 904 | { |
| 905 | int rc = 0; |
| 906 | struct cam_isp_context *ctx_isp = |
| 907 | (struct cam_isp_context *) ctx->ctx_priv; |
| 908 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 909 | CAM_DBG(CAM_ISP, "current substate %d", |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 910 | ctx_isp->substate_activated); |
| 911 | rc = __cam_isp_ctx_apply_req_in_activated_state(ctx, apply, |
| 912 | CAM_ISP_CTX_ACTIVATED_APPLIED); |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 913 | CAM_DBG(CAM_ISP, "new substate %d", ctx_isp->substate_activated); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 914 | |
| 915 | return rc; |
| 916 | } |
| 917 | |
| 918 | static int __cam_isp_ctx_apply_req_in_bubble( |
| 919 | struct cam_context *ctx, struct cam_req_mgr_apply_request *apply) |
| 920 | { |
| 921 | int rc = 0; |
| 922 | struct cam_isp_context *ctx_isp = |
| 923 | (struct cam_isp_context *) ctx->ctx_priv; |
| 924 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 925 | CAM_DBG(CAM_ISP, "current substate %d", |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 926 | ctx_isp->substate_activated); |
| 927 | rc = __cam_isp_ctx_apply_req_in_activated_state(ctx, apply, |
| 928 | CAM_ISP_CTX_ACTIVATED_BUBBLE_APPLIED); |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 929 | CAM_DBG(CAM_ISP, "new substate %d", ctx_isp->substate_activated); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 930 | |
| 931 | return rc; |
| 932 | } |
| 933 | |
Jing Zhou | b524a85 | 2017-05-16 15:47:30 +0530 | [diff] [blame] | 934 | static int __cam_isp_ctx_flush_req(struct cam_context *ctx, |
| 935 | struct list_head *req_list, struct cam_req_mgr_flush_request *flush_req) |
| 936 | { |
| 937 | int i, rc; |
| 938 | uint32_t cancel_req_id_found = 0; |
| 939 | struct cam_ctx_request *req; |
| 940 | struct cam_ctx_request *req_temp; |
| 941 | struct cam_isp_ctx_req *req_isp; |
| 942 | |
| 943 | spin_lock(&ctx->lock); |
| 944 | if (list_empty(req_list)) { |
| 945 | spin_unlock(&ctx->lock); |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 946 | CAM_DBG(CAM_ISP, "request list is empty"); |
Jing Zhou | b524a85 | 2017-05-16 15:47:30 +0530 | [diff] [blame] | 947 | return 0; |
| 948 | } |
| 949 | |
| 950 | list_for_each_entry_safe(req, req_temp, req_list, list) { |
| 951 | if ((flush_req->type == CAM_REQ_MGR_FLUSH_TYPE_CANCEL_REQ) |
| 952 | && (req->request_id != flush_req->req_id)) |
| 953 | continue; |
| 954 | |
| 955 | list_del_init(&req->list); |
| 956 | req_isp = (struct cam_isp_ctx_req *) req->req_priv; |
| 957 | for (i = 0; i < req_isp->num_fence_map_out; i++) { |
| 958 | if (req_isp->fence_map_out[i].sync_id != -1) { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 959 | CAM_DBG(CAM_ISP, "Flush req 0x%llx, fence %d", |
| 960 | req->request_id, |
Jing Zhou | b524a85 | 2017-05-16 15:47:30 +0530 | [diff] [blame] | 961 | req_isp->fence_map_out[i].sync_id); |
| 962 | rc = cam_sync_signal( |
| 963 | req_isp->fence_map_out[i].sync_id, |
| 964 | CAM_SYNC_STATE_SIGNALED_ERROR); |
| 965 | if (rc) |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 966 | CAM_ERR_RATE_LIMIT(CAM_ISP, |
| 967 | "signal fence failed\n"); |
Jing Zhou | b524a85 | 2017-05-16 15:47:30 +0530 | [diff] [blame] | 968 | req_isp->fence_map_out[i].sync_id = -1; |
| 969 | } |
| 970 | } |
| 971 | list_add_tail(&req->list, &ctx->free_req_list); |
| 972 | |
| 973 | /* If flush request id found, exit the loop */ |
| 974 | if (flush_req->type == CAM_REQ_MGR_FLUSH_TYPE_CANCEL_REQ) { |
| 975 | cancel_req_id_found = 1; |
| 976 | break; |
| 977 | } |
| 978 | } |
| 979 | spin_unlock(&ctx->lock); |
| 980 | |
| 981 | if (flush_req->type == CAM_REQ_MGR_FLUSH_TYPE_CANCEL_REQ && |
| 982 | !cancel_req_id_found) |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 983 | CAM_DBG(CAM_ISP, |
| 984 | "Flush request id:%lld is not found in the list", |
| 985 | flush_req->req_id); |
Jing Zhou | b524a85 | 2017-05-16 15:47:30 +0530 | [diff] [blame] | 986 | |
| 987 | return 0; |
| 988 | } |
| 989 | |
| 990 | static int __cam_isp_ctx_flush_req_in_top_state( |
| 991 | struct cam_context *ctx, |
| 992 | struct cam_req_mgr_flush_request *flush_req) |
| 993 | { |
| 994 | int rc = 0; |
| 995 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 996 | CAM_DBG(CAM_ISP, "try to flush pending list"); |
Jing Zhou | b524a85 | 2017-05-16 15:47:30 +0530 | [diff] [blame] | 997 | 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] | 998 | CAM_DBG(CAM_ISP, "Flush request in top state %d", |
| 999 | ctx->state); |
Jing Zhou | b524a85 | 2017-05-16 15:47:30 +0530 | [diff] [blame] | 1000 | return rc; |
| 1001 | } |
| 1002 | |
| 1003 | static int __cam_isp_ctx_flush_req_in_ready( |
| 1004 | struct cam_context *ctx, |
| 1005 | struct cam_req_mgr_flush_request *flush_req) |
| 1006 | { |
| 1007 | int rc = 0; |
| 1008 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1009 | CAM_DBG(CAM_ISP, "try to flush pending list"); |
Jing Zhou | b524a85 | 2017-05-16 15:47:30 +0530 | [diff] [blame] | 1010 | rc = __cam_isp_ctx_flush_req(ctx, &ctx->pending_req_list, flush_req); |
| 1011 | |
| 1012 | /* if nothing is in pending req list, change state to acquire*/ |
| 1013 | spin_lock(&ctx->lock); |
| 1014 | if (list_empty(&ctx->pending_req_list)) |
| 1015 | ctx->state = CAM_CTX_ACQUIRED; |
| 1016 | spin_unlock(&ctx->lock); |
| 1017 | |
Gregory Bergschneider | 5164f3a | 2017-07-07 10:26:17 -0600 | [diff] [blame] | 1018 | trace_cam_context_state("ISP", ctx); |
| 1019 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1020 | CAM_DBG(CAM_ISP, "Flush request in ready state. next state %d", |
| 1021 | ctx->state); |
Jing Zhou | b524a85 | 2017-05-16 15:47:30 +0530 | [diff] [blame] | 1022 | return rc; |
| 1023 | } |
| 1024 | |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1025 | static struct cam_ctx_ops |
| 1026 | cam_isp_ctx_activated_state_machine[CAM_ISP_CTX_ACTIVATED_MAX] = { |
| 1027 | /* SOF */ |
| 1028 | { |
| 1029 | .ioctl_ops = {}, |
| 1030 | .crm_ops = { |
| 1031 | .apply_req = __cam_isp_ctx_apply_req_in_sof, |
| 1032 | }, |
| 1033 | .irq_ops = NULL, |
| 1034 | }, |
| 1035 | /* APPLIED */ |
| 1036 | { |
| 1037 | .ioctl_ops = {}, |
| 1038 | .crm_ops = {}, |
| 1039 | .irq_ops = NULL, |
| 1040 | }, |
| 1041 | /* EPOCH */ |
| 1042 | { |
| 1043 | .ioctl_ops = {}, |
| 1044 | .crm_ops = { |
| 1045 | .apply_req = __cam_isp_ctx_apply_req_in_epoch, |
| 1046 | }, |
| 1047 | .irq_ops = NULL, |
| 1048 | }, |
| 1049 | /* BUBBLE */ |
| 1050 | { |
| 1051 | .ioctl_ops = {}, |
| 1052 | .crm_ops = { |
| 1053 | .apply_req = __cam_isp_ctx_apply_req_in_bubble, |
| 1054 | }, |
| 1055 | .irq_ops = NULL, |
| 1056 | }, |
| 1057 | /* Bubble Applied */ |
| 1058 | { |
| 1059 | .ioctl_ops = {}, |
| 1060 | .crm_ops = {}, |
| 1061 | .irq_ops = NULL, |
| 1062 | }, |
| 1063 | /* HALT */ |
| 1064 | { |
| 1065 | .ioctl_ops = {}, |
| 1066 | .crm_ops = {}, |
| 1067 | .irq_ops = NULL, |
| 1068 | }, |
| 1069 | }; |
| 1070 | |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1071 | static int __cam_isp_ctx_rdi_only_sof_in_top_state( |
| 1072 | struct cam_isp_context *ctx_isp, void *evt_data) |
| 1073 | { |
| 1074 | int rc = 0; |
| 1075 | struct cam_context *ctx = ctx_isp->base; |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1076 | struct cam_req_mgr_trigger_notify notify; |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1077 | struct cam_isp_hw_sof_event_data *sof_event_data = evt_data; |
| 1078 | uint64_t request_id = 0; |
| 1079 | |
| 1080 | if (!evt_data) { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1081 | CAM_ERR(CAM_ISP, "in valid sof event data"); |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1082 | return -EINVAL; |
| 1083 | } |
| 1084 | |
| 1085 | ctx_isp->frame_id++; |
| 1086 | ctx_isp->sof_timestamp_val = sof_event_data->timestamp; |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1087 | CAM_DBG(CAM_ISP, "frame id: %lld time stamp:0x%llx", |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1088 | ctx_isp->frame_id, ctx_isp->sof_timestamp_val); |
| 1089 | |
| 1090 | /* |
| 1091 | * notify reqmgr with sof signal. Note, due to scheduling delay |
| 1092 | * we can run into situation that two active requests has already |
| 1093 | * be in the active queue while we try to do the notification. |
| 1094 | * In this case, we need to skip the current notification. This |
| 1095 | * helps the state machine to catch up the delay. |
| 1096 | */ |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1097 | if (ctx->ctx_crm_intf && ctx->ctx_crm_intf->notify_trigger && |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1098 | ctx_isp->active_req_cnt <= 2) { |
| 1099 | notify.link_hdl = ctx->link_hdl; |
| 1100 | notify.dev_hdl = ctx->dev_hdl; |
| 1101 | notify.frame_id = ctx_isp->frame_id; |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1102 | notify.trigger = CAM_TRIGGER_POINT_SOF; |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1103 | |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1104 | ctx->ctx_crm_intf->notify_trigger(¬ify); |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1105 | CAM_DBG(CAM_ISP, "Notify CRM SOF frame %lld", |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1106 | ctx_isp->frame_id); |
| 1107 | |
| 1108 | /* |
| 1109 | * It is idle frame with out any applied request id, send |
| 1110 | * request id as zero |
| 1111 | */ |
| 1112 | __cam_isp_ctx_send_sof_timestamp(ctx_isp, request_id, |
| 1113 | CAM_REQ_MGR_SOF_EVENT_SUCCESS); |
| 1114 | } else { |
Harsh Shah | cb0072c | 2017-09-26 19:22:10 -0700 | [diff] [blame] | 1115 | CAM_ERR_RATE_LIMIT(CAM_ISP, "Can not notify SOF to CRM"); |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | if (list_empty(&ctx->active_req_list)) |
| 1119 | ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_SOF; |
| 1120 | else |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1121 | CAM_DBG(CAM_ISP, "Still need to wait for the buf done"); |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1122 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1123 | CAM_DBG(CAM_ISP, "next substate %d", |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1124 | ctx_isp->substate_activated); |
| 1125 | return rc; |
| 1126 | } |
| 1127 | |
| 1128 | static int __cam_isp_ctx_rdi_only_sof_in_applied_state( |
| 1129 | struct cam_isp_context *ctx_isp, void *evt_data) |
| 1130 | { |
| 1131 | struct cam_isp_hw_sof_event_data *sof_event_data = evt_data; |
| 1132 | |
| 1133 | if (!evt_data) { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1134 | CAM_ERR(CAM_ISP, "in valid sof event data"); |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1135 | return -EINVAL; |
| 1136 | } |
| 1137 | |
| 1138 | ctx_isp->frame_id++; |
| 1139 | ctx_isp->sof_timestamp_val = sof_event_data->timestamp; |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1140 | CAM_DBG(CAM_ISP, "frame id: %lld time stamp:0x%llx", |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1141 | ctx_isp->frame_id, ctx_isp->sof_timestamp_val); |
| 1142 | |
| 1143 | ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_BUBBLE_APPLIED; |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1144 | CAM_DBG(CAM_ISP, "next substate %d", ctx_isp->substate_activated); |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1145 | |
| 1146 | return 0; |
| 1147 | } |
| 1148 | |
| 1149 | static int __cam_isp_ctx_rdi_only_sof_in_bubble_applied( |
| 1150 | struct cam_isp_context *ctx_isp, void *evt_data) |
| 1151 | { |
| 1152 | struct cam_ctx_request *req; |
| 1153 | struct cam_isp_ctx_req *req_isp; |
| 1154 | struct cam_context *ctx = ctx_isp->base; |
| 1155 | struct cam_isp_hw_sof_event_data *sof_event_data = evt_data; |
| 1156 | uint64_t request_id = 0; |
| 1157 | |
| 1158 | ctx_isp->frame_id++; |
| 1159 | ctx_isp->sof_timestamp_val = sof_event_data->timestamp; |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1160 | CAM_DBG(CAM_ISP, "frame id: %lld time stamp:0x%llx", |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1161 | ctx_isp->frame_id, ctx_isp->sof_timestamp_val); |
| 1162 | |
| 1163 | if (list_empty(&ctx->pending_req_list)) { |
| 1164 | /* |
| 1165 | * If no pending req in epoch, this is an error case. |
| 1166 | * The recovery is to go back to sof state |
| 1167 | */ |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1168 | CAM_ERR(CAM_ISP, "No pending request"); |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1169 | ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_SOF; |
| 1170 | |
| 1171 | /* Send SOF event as empty frame*/ |
| 1172 | __cam_isp_ctx_send_sof_timestamp(ctx_isp, request_id, |
| 1173 | CAM_REQ_MGR_SOF_EVENT_SUCCESS); |
| 1174 | |
| 1175 | goto end; |
| 1176 | } |
| 1177 | |
| 1178 | req = list_first_entry(&ctx->pending_req_list, struct cam_ctx_request, |
| 1179 | list); |
| 1180 | req_isp = (struct cam_isp_ctx_req *)req->req_priv; |
| 1181 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1182 | CAM_DBG(CAM_ISP, "Report Bubble flag %d", req_isp->bubble_report); |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1183 | if (req_isp->bubble_report && ctx->ctx_crm_intf && |
| 1184 | ctx->ctx_crm_intf->notify_err) { |
| 1185 | struct cam_req_mgr_error_notify notify; |
| 1186 | |
| 1187 | notify.link_hdl = ctx->link_hdl; |
| 1188 | notify.dev_hdl = ctx->dev_hdl; |
| 1189 | notify.req_id = req->request_id; |
| 1190 | notify.error = CRM_KMD_ERR_BUBBLE; |
| 1191 | ctx->ctx_crm_intf->notify_err(¬ify); |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1192 | CAM_DBG(CAM_ISP, "Notify CRM about Bubble frame %lld", |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1193 | ctx_isp->frame_id); |
| 1194 | } else { |
| 1195 | /* |
| 1196 | * Since can not bubble report, always move the request to |
| 1197 | * active list. |
| 1198 | */ |
| 1199 | list_del_init(&req->list); |
| 1200 | list_add_tail(&req->list, &ctx->active_req_list); |
| 1201 | ctx_isp->active_req_cnt++; |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1202 | CAM_DBG(CAM_ISP, "move request %lld to active list(cnt = %d)", |
| 1203 | req->request_id, ctx_isp->active_req_cnt); |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1204 | req_isp->bubble_report = 0; |
| 1205 | } |
| 1206 | |
| 1207 | request_id = req->request_id; |
| 1208 | __cam_isp_ctx_send_sof_timestamp(ctx_isp, request_id, |
| 1209 | CAM_REQ_MGR_SOF_EVENT_ERROR); |
| 1210 | |
| 1211 | /* change the state to bubble, as reg update has not come */ |
| 1212 | ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_BUBBLE; |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1213 | CAM_DBG(CAM_ISP, "next substate %d", ctx_isp->substate_activated); |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1214 | end: |
| 1215 | return 0; |
| 1216 | } |
| 1217 | |
| 1218 | static int __cam_isp_ctx_rdi_only_sof_in_bubble_state( |
| 1219 | struct cam_isp_context *ctx_isp, void *evt_data) |
| 1220 | { |
| 1221 | uint32_t i; |
| 1222 | struct cam_ctx_request *req; |
| 1223 | struct cam_context *ctx = ctx_isp->base; |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1224 | struct cam_req_mgr_trigger_notify notify; |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1225 | struct cam_isp_hw_sof_event_data *sof_event_data = evt_data; |
| 1226 | struct cam_isp_ctx_req *req_isp; |
| 1227 | uint64_t request_id = 0; |
| 1228 | |
| 1229 | if (!evt_data) { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1230 | CAM_ERR(CAM_ISP, "in valid sof event data"); |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1231 | return -EINVAL; |
| 1232 | } |
| 1233 | |
| 1234 | ctx_isp->frame_id++; |
| 1235 | ctx_isp->sof_timestamp_val = sof_event_data->timestamp; |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1236 | CAM_DBG(CAM_ISP, "frame id: %lld time stamp:0x%llx", |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1237 | ctx_isp->frame_id, ctx_isp->sof_timestamp_val); |
| 1238 | /* |
| 1239 | * Signal all active requests with error and move the all the active |
| 1240 | * requests to free list |
| 1241 | */ |
| 1242 | while (!list_empty(&ctx->active_req_list)) { |
| 1243 | req = list_first_entry(&ctx->active_req_list, |
| 1244 | struct cam_ctx_request, list); |
| 1245 | list_del_init(&req->list); |
| 1246 | req_isp = (struct cam_isp_ctx_req *) req->req_priv; |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1247 | CAM_DBG(CAM_ISP, "signal fence in active list. fence num %d", |
| 1248 | req_isp->num_fence_map_out); |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1249 | for (i = 0; i < req_isp->num_fence_map_out; i++) |
| 1250 | if (req_isp->fence_map_out[i].sync_id != -1) { |
| 1251 | cam_sync_signal( |
| 1252 | req_isp->fence_map_out[i].sync_id, |
| 1253 | CAM_SYNC_STATE_SIGNALED_ERROR); |
| 1254 | } |
| 1255 | list_add_tail(&req->list, &ctx->free_req_list); |
Harsh Shah | 1b8eb23 | 2017-10-09 19:20:52 -0700 | [diff] [blame] | 1256 | ctx_isp->active_req_cnt--; |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1257 | } |
| 1258 | |
| 1259 | /* notify reqmgr with sof signal */ |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1260 | if (ctx->ctx_crm_intf && ctx->ctx_crm_intf->notify_trigger) { |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1261 | notify.link_hdl = ctx->link_hdl; |
| 1262 | notify.dev_hdl = ctx->dev_hdl; |
| 1263 | notify.frame_id = ctx_isp->frame_id; |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1264 | notify.trigger = CAM_TRIGGER_POINT_SOF; |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1265 | |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1266 | ctx->ctx_crm_intf->notify_trigger(¬ify); |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1267 | CAM_DBG(CAM_ISP, "Notify CRM SOF frame %lld", |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1268 | ctx_isp->frame_id); |
| 1269 | |
| 1270 | } else { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1271 | CAM_ERR(CAM_ISP, "Can not notify SOF to CRM"); |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1272 | } |
| 1273 | |
| 1274 | /* |
| 1275 | * It is idle frame with out any applied request id, send |
| 1276 | * request id as zero |
| 1277 | */ |
| 1278 | __cam_isp_ctx_send_sof_timestamp(ctx_isp, request_id, |
| 1279 | CAM_REQ_MGR_SOF_EVENT_SUCCESS); |
| 1280 | |
| 1281 | ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_SOF; |
| 1282 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1283 | CAM_DBG(CAM_ISP, "next substate %d", |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1284 | ctx_isp->substate_activated); |
| 1285 | |
| 1286 | return 0; |
| 1287 | } |
| 1288 | |
| 1289 | static int __cam_isp_ctx_rdi_only_reg_upd_in_bubble_applied_state( |
| 1290 | struct cam_isp_context *ctx_isp, void *evt_data) |
| 1291 | { |
| 1292 | struct cam_ctx_request *req; |
| 1293 | struct cam_context *ctx = ctx_isp->base; |
| 1294 | struct cam_isp_ctx_req *req_isp; |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1295 | struct cam_req_mgr_trigger_notify notify; |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1296 | uint64_t request_id = 0; |
| 1297 | |
| 1298 | /* notify reqmgr with sof signal*/ |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1299 | if (ctx->ctx_crm_intf && ctx->ctx_crm_intf->notify_trigger) { |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1300 | if (list_empty(&ctx->pending_req_list)) { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1301 | CAM_ERR(CAM_ISP, "Reg upd ack with no pending request"); |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1302 | goto error; |
| 1303 | } |
| 1304 | req = list_first_entry(&ctx->pending_req_list, |
| 1305 | struct cam_ctx_request, list); |
| 1306 | list_del_init(&req->list); |
| 1307 | |
| 1308 | req_isp = (struct cam_isp_ctx_req *) req->req_priv; |
| 1309 | request_id = req->request_id; |
| 1310 | if (req_isp->num_fence_map_out != 0) { |
| 1311 | list_add_tail(&req->list, &ctx->active_req_list); |
| 1312 | ctx_isp->active_req_cnt++; |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1313 | CAM_DBG(CAM_ISP, |
| 1314 | "move request %lld to active list(cnt = %d)", |
| 1315 | req->request_id, ctx_isp->active_req_cnt); |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1316 | } else { |
| 1317 | /* no io config, so the request is completed. */ |
| 1318 | list_add_tail(&req->list, &ctx->free_req_list); |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1319 | CAM_DBG(CAM_ISP, |
| 1320 | "move active req %lld to free list(cnt=%d)", |
| 1321 | req->request_id, ctx_isp->active_req_cnt); |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1322 | } |
| 1323 | |
| 1324 | notify.link_hdl = ctx->link_hdl; |
| 1325 | notify.dev_hdl = ctx->dev_hdl; |
| 1326 | notify.frame_id = ctx_isp->frame_id; |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1327 | notify.trigger = CAM_TRIGGER_POINT_SOF; |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1328 | |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1329 | ctx->ctx_crm_intf->notify_trigger(¬ify); |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1330 | CAM_DBG(CAM_ISP, "Notify CRM SOF frame %lld", |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1331 | ctx_isp->frame_id); |
| 1332 | } else { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1333 | CAM_ERR(CAM_ISP, "Can not notify SOF to CRM"); |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1334 | } |
| 1335 | __cam_isp_ctx_send_sof_timestamp(ctx_isp, request_id, |
| 1336 | CAM_REQ_MGR_SOF_EVENT_SUCCESS); |
| 1337 | |
| 1338 | ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_EPOCH; |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1339 | CAM_DBG(CAM_ISP, "next substate %d", ctx_isp->substate_activated); |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1340 | |
| 1341 | return 0; |
| 1342 | error: |
| 1343 | /* Send SOF event as idle frame*/ |
| 1344 | __cam_isp_ctx_send_sof_timestamp(ctx_isp, request_id, |
| 1345 | CAM_REQ_MGR_SOF_EVENT_SUCCESS); |
| 1346 | |
| 1347 | /* |
| 1348 | * There is no request in the pending list, move the sub state machine |
| 1349 | * to SOF sub state |
| 1350 | */ |
| 1351 | ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_SOF; |
| 1352 | |
| 1353 | return 0; |
| 1354 | } |
| 1355 | |
| 1356 | static struct cam_isp_ctx_irq_ops |
| 1357 | cam_isp_ctx_rdi_only_activated_state_machine_irq |
| 1358 | [CAM_ISP_CTX_ACTIVATED_MAX] = { |
| 1359 | /* SOF */ |
| 1360 | { |
| 1361 | .irq_ops = { |
| 1362 | NULL, |
| 1363 | __cam_isp_ctx_rdi_only_sof_in_top_state, |
| 1364 | __cam_isp_ctx_reg_upd_in_sof, |
| 1365 | NULL, |
| 1366 | NULL, |
| 1367 | NULL, |
| 1368 | }, |
| 1369 | }, |
| 1370 | /* APPLIED */ |
| 1371 | { |
| 1372 | .irq_ops = { |
| 1373 | __cam_isp_ctx_handle_error, |
| 1374 | __cam_isp_ctx_rdi_only_sof_in_applied_state, |
| 1375 | NULL, |
| 1376 | NULL, |
| 1377 | NULL, |
| 1378 | __cam_isp_ctx_buf_done_in_applied, |
| 1379 | }, |
| 1380 | }, |
| 1381 | /* EPOCH */ |
| 1382 | { |
| 1383 | .irq_ops = { |
| 1384 | __cam_isp_ctx_handle_error, |
| 1385 | __cam_isp_ctx_rdi_only_sof_in_top_state, |
| 1386 | NULL, |
| 1387 | NULL, |
| 1388 | NULL, |
| 1389 | __cam_isp_ctx_buf_done_in_epoch, |
| 1390 | }, |
| 1391 | }, |
| 1392 | /* BUBBLE*/ |
| 1393 | { |
| 1394 | .irq_ops = { |
| 1395 | __cam_isp_ctx_handle_error, |
| 1396 | __cam_isp_ctx_rdi_only_sof_in_bubble_state, |
| 1397 | NULL, |
| 1398 | NULL, |
| 1399 | NULL, |
| 1400 | __cam_isp_ctx_buf_done_in_bubble, |
| 1401 | }, |
| 1402 | }, |
| 1403 | /* BUBBLE APPLIED ie PRE_BUBBLE */ |
| 1404 | { |
| 1405 | .irq_ops = { |
| 1406 | __cam_isp_ctx_handle_error, |
| 1407 | __cam_isp_ctx_rdi_only_sof_in_bubble_applied, |
| 1408 | __cam_isp_ctx_rdi_only_reg_upd_in_bubble_applied_state, |
| 1409 | NULL, |
| 1410 | NULL, |
| 1411 | __cam_isp_ctx_buf_done_in_bubble_applied, |
| 1412 | }, |
| 1413 | }, |
| 1414 | |
| 1415 | /* HALT */ |
| 1416 | { |
| 1417 | }, |
| 1418 | }; |
| 1419 | |
| 1420 | static int __cam_isp_ctx_rdi_only_apply_req_top_state( |
| 1421 | struct cam_context *ctx, struct cam_req_mgr_apply_request *apply) |
| 1422 | { |
| 1423 | int rc = 0; |
| 1424 | struct cam_isp_context *ctx_isp = |
| 1425 | (struct cam_isp_context *) ctx->ctx_priv; |
| 1426 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1427 | CAM_DBG(CAM_ISP, "current substate %d", |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1428 | ctx_isp->substate_activated); |
| 1429 | rc = __cam_isp_ctx_apply_req_in_activated_state(ctx, apply, |
| 1430 | CAM_ISP_CTX_ACTIVATED_APPLIED); |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1431 | CAM_DBG(CAM_ISP, "new substate %d", ctx_isp->substate_activated); |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1432 | |
| 1433 | return rc; |
| 1434 | } |
| 1435 | |
| 1436 | static struct cam_ctx_ops |
| 1437 | cam_isp_ctx_rdi_only_activated_state_machine |
| 1438 | [CAM_ISP_CTX_ACTIVATED_MAX] = { |
| 1439 | /* SOF */ |
| 1440 | { |
| 1441 | .ioctl_ops = {}, |
| 1442 | .crm_ops = { |
| 1443 | .apply_req = __cam_isp_ctx_rdi_only_apply_req_top_state, |
| 1444 | }, |
| 1445 | .irq_ops = NULL, |
| 1446 | }, |
| 1447 | /* APPLIED */ |
| 1448 | { |
| 1449 | .ioctl_ops = {}, |
| 1450 | .crm_ops = {}, |
| 1451 | .irq_ops = NULL, |
| 1452 | }, |
| 1453 | /* EPOCH */ |
| 1454 | { |
| 1455 | .ioctl_ops = {}, |
| 1456 | .crm_ops = { |
| 1457 | .apply_req = __cam_isp_ctx_rdi_only_apply_req_top_state, |
| 1458 | }, |
| 1459 | .irq_ops = NULL, |
| 1460 | }, |
| 1461 | /* PRE BUBBLE */ |
| 1462 | { |
| 1463 | .ioctl_ops = {}, |
| 1464 | .crm_ops = {}, |
| 1465 | .irq_ops = NULL, |
| 1466 | }, |
| 1467 | /* BUBBLE */ |
| 1468 | { |
| 1469 | .ioctl_ops = {}, |
| 1470 | .crm_ops = {}, |
| 1471 | .irq_ops = NULL, |
| 1472 | }, |
| 1473 | /* HALT */ |
| 1474 | { |
| 1475 | .ioctl_ops = {}, |
| 1476 | .crm_ops = {}, |
| 1477 | .irq_ops = NULL, |
| 1478 | }, |
| 1479 | }; |
| 1480 | |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1481 | |
| 1482 | /* top level state machine */ |
| 1483 | static int __cam_isp_ctx_release_dev_in_top_state(struct cam_context *ctx, |
| 1484 | struct cam_release_dev_cmd *cmd) |
| 1485 | { |
| 1486 | int rc = 0; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1487 | struct cam_hw_release_args rel_arg; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1488 | struct cam_isp_context *ctx_isp = |
| 1489 | (struct cam_isp_context *) ctx->ctx_priv; |
Jing Zhou | b524a85 | 2017-05-16 15:47:30 +0530 | [diff] [blame] | 1490 | struct cam_req_mgr_flush_request flush_req; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1491 | |
| 1492 | if (ctx_isp->hw_ctx) { |
| 1493 | rel_arg.ctxt_to_hw_map = ctx_isp->hw_ctx; |
| 1494 | ctx->hw_mgr_intf->hw_release(ctx->hw_mgr_intf->hw_mgr_priv, |
| 1495 | &rel_arg); |
| 1496 | ctx_isp->hw_ctx = NULL; |
| 1497 | } |
| 1498 | |
Soundrapandian Jeyaprakash | 8d16e27 | 2017-10-12 11:05:37 -0700 | [diff] [blame] | 1499 | ctx->session_hdl = -1; |
| 1500 | ctx->dev_hdl = -1; |
| 1501 | ctx->link_hdl = -1; |
Jing Zhou | e71fd4a | 2017-05-15 19:44:34 -0700 | [diff] [blame] | 1502 | ctx->ctx_crm_intf = NULL; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1503 | ctx_isp->frame_id = 0; |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 1504 | ctx_isp->active_req_cnt = 0; |
| 1505 | ctx_isp->reported_req_id = 0; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1506 | |
| 1507 | /* |
| 1508 | * Ideally, we should never have any active request here. |
| 1509 | * But we still add some sanity check code here to help the debug |
| 1510 | */ |
| 1511 | if (!list_empty(&ctx->active_req_list)) |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1512 | CAM_ERR(CAM_ISP, "Active list is not empty"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1513 | |
Jing Zhou | b524a85 | 2017-05-16 15:47:30 +0530 | [diff] [blame] | 1514 | /* Flush all the pending request list */ |
| 1515 | flush_req.type = CAM_REQ_MGR_FLUSH_TYPE_ALL; |
| 1516 | flush_req.link_hdl = ctx->link_hdl; |
| 1517 | flush_req.dev_hdl = ctx->dev_hdl; |
| 1518 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1519 | CAM_DBG(CAM_ISP, "try to flush pending list"); |
Jing Zhou | b524a85 | 2017-05-16 15:47:30 +0530 | [diff] [blame] | 1520 | rc = __cam_isp_ctx_flush_req(ctx, &ctx->pending_req_list, &flush_req); |
| 1521 | |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1522 | ctx->state = CAM_CTX_AVAILABLE; |
Gregory Bergschneider | 5164f3a | 2017-07-07 10:26:17 -0600 | [diff] [blame] | 1523 | |
| 1524 | trace_cam_context_state("ISP", ctx); |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1525 | CAM_DBG(CAM_ISP, "next state %d", ctx->state); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1526 | return rc; |
| 1527 | } |
| 1528 | |
| 1529 | static int __cam_isp_ctx_config_dev_in_top_state( |
| 1530 | struct cam_context *ctx, struct cam_config_dev_cmd *cmd) |
| 1531 | { |
| 1532 | int rc = 0; |
| 1533 | struct cam_ctx_request *req = NULL; |
| 1534 | struct cam_isp_ctx_req *req_isp; |
| 1535 | uint64_t packet_addr; |
| 1536 | struct cam_packet *packet; |
| 1537 | size_t len = 0; |
| 1538 | struct cam_hw_prepare_update_args cfg; |
| 1539 | struct cam_req_mgr_add_request add_req; |
| 1540 | struct cam_isp_context *ctx_isp = |
| 1541 | (struct cam_isp_context *) ctx->ctx_priv; |
| 1542 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1543 | CAM_DBG(CAM_ISP, "get free request object......"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1544 | |
| 1545 | /* get free request */ |
Jing Zhou | 93b3ec1 | 2017-06-15 17:43:39 -0700 | [diff] [blame] | 1546 | spin_lock_bh(&ctx->lock); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1547 | if (!list_empty(&ctx->free_req_list)) { |
| 1548 | req = list_first_entry(&ctx->free_req_list, |
| 1549 | struct cam_ctx_request, list); |
| 1550 | list_del_init(&req->list); |
| 1551 | } |
Jing Zhou | 93b3ec1 | 2017-06-15 17:43:39 -0700 | [diff] [blame] | 1552 | spin_unlock_bh(&ctx->lock); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1553 | |
| 1554 | if (!req) { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1555 | CAM_ERR(CAM_ISP, "No more request obj free"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1556 | rc = -ENOMEM; |
| 1557 | goto end; |
| 1558 | } |
| 1559 | |
| 1560 | req_isp = (struct cam_isp_ctx_req *) req->req_priv; |
| 1561 | |
| 1562 | /* for config dev, only memory handle is supported */ |
| 1563 | /* map packet from the memhandle */ |
| 1564 | rc = cam_mem_get_cpu_buf((int32_t) cmd->packet_handle, |
| 1565 | (uint64_t *) &packet_addr, &len); |
| 1566 | if (rc != 0) { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1567 | CAM_ERR(CAM_ISP, "Can not get packet address"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1568 | rc = -EINVAL; |
| 1569 | goto free_req; |
| 1570 | } |
| 1571 | |
| 1572 | packet = (struct cam_packet *) (packet_addr + cmd->offset); |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1573 | CAM_DBG(CAM_ISP, "pack_handle %llx", cmd->packet_handle); |
| 1574 | CAM_DBG(CAM_ISP, "packet address is 0x%llx", packet_addr); |
| 1575 | CAM_DBG(CAM_ISP, "packet with length %zu, offset 0x%llx", |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1576 | len, cmd->offset); |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1577 | CAM_DBG(CAM_ISP, "Packet request id %lld", |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1578 | packet->header.request_id); |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1579 | CAM_DBG(CAM_ISP, "Packet size 0x%x", packet->header.size); |
| 1580 | CAM_DBG(CAM_ISP, "packet op %d", packet->header.op_code); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1581 | |
| 1582 | /* preprocess the configuration */ |
| 1583 | memset(&cfg, 0, sizeof(cfg)); |
| 1584 | cfg.packet = packet; |
| 1585 | cfg.ctxt_to_hw_map = ctx_isp->hw_ctx; |
| 1586 | cfg.max_hw_update_entries = CAM_ISP_CTX_CFG_MAX; |
| 1587 | cfg.hw_update_entries = req_isp->cfg; |
| 1588 | cfg.max_out_map_entries = CAM_ISP_CTX_RES_MAX; |
| 1589 | cfg.max_in_map_entries = CAM_ISP_CTX_RES_MAX; |
| 1590 | cfg.out_map_entries = req_isp->fence_map_out; |
| 1591 | cfg.in_map_entries = req_isp->fence_map_in; |
| 1592 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1593 | CAM_DBG(CAM_ISP, "try to prepare config packet......"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1594 | |
| 1595 | rc = ctx->hw_mgr_intf->hw_prepare_update( |
| 1596 | ctx->hw_mgr_intf->hw_mgr_priv, &cfg); |
| 1597 | if (rc != 0) { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1598 | CAM_ERR(CAM_ISP, "Prepare config packet failed in HW layer"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1599 | rc = -EFAULT; |
| 1600 | goto free_req; |
| 1601 | } |
| 1602 | req_isp->num_cfg = cfg.num_hw_update_entries; |
| 1603 | req_isp->num_fence_map_out = cfg.num_out_map_entries; |
| 1604 | req_isp->num_fence_map_in = cfg.num_in_map_entries; |
| 1605 | req_isp->num_acked = 0; |
| 1606 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1607 | CAM_DBG(CAM_ISP, "num_entry: %d, num fence out: %d, num fence in: %d", |
| 1608 | req_isp->num_cfg, req_isp->num_fence_map_out, |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1609 | req_isp->num_fence_map_in); |
| 1610 | |
| 1611 | req->request_id = packet->header.request_id; |
| 1612 | req->status = 1; |
| 1613 | |
| 1614 | if (ctx->state == CAM_CTX_ACTIVATED && ctx->ctx_crm_intf->add_req) { |
| 1615 | add_req.link_hdl = ctx->link_hdl; |
| 1616 | add_req.dev_hdl = ctx->dev_hdl; |
| 1617 | add_req.req_id = req->request_id; |
Sagar Gore | a4d7dfd | 2017-09-13 19:56:24 -0700 | [diff] [blame] | 1618 | add_req.skip_before_applying = 0; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1619 | rc = ctx->ctx_crm_intf->add_req(&add_req); |
| 1620 | if (rc) { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1621 | CAM_ERR(CAM_ISP, "Error: Adding request id=%llu", |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1622 | req->request_id); |
| 1623 | goto free_req; |
| 1624 | } |
| 1625 | } |
| 1626 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1627 | CAM_DBG(CAM_ISP, "Packet request id 0x%llx", |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1628 | packet->header.request_id); |
| 1629 | |
Jing Zhou | 77962c5 | 2017-09-18 19:13:34 -0700 | [diff] [blame] | 1630 | __cam_isp_ctx_enqueue_request_in_order(ctx, req); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1631 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1632 | CAM_DBG(CAM_ISP, "Preprocessing Config %lld successful", |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1633 | req->request_id); |
| 1634 | |
| 1635 | return rc; |
| 1636 | |
| 1637 | free_req: |
Jing Zhou | 93b3ec1 | 2017-06-15 17:43:39 -0700 | [diff] [blame] | 1638 | spin_lock_bh(&ctx->lock); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1639 | list_add_tail(&req->list, &ctx->free_req_list); |
Jing Zhou | 93b3ec1 | 2017-06-15 17:43:39 -0700 | [diff] [blame] | 1640 | spin_unlock_bh(&ctx->lock); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1641 | end: |
| 1642 | return rc; |
| 1643 | } |
| 1644 | |
| 1645 | static int __cam_isp_ctx_acquire_dev_in_available(struct cam_context *ctx, |
| 1646 | struct cam_acquire_dev_cmd *cmd) |
| 1647 | { |
| 1648 | int rc = 0; |
| 1649 | struct cam_hw_acquire_args param; |
| 1650 | struct cam_isp_resource *isp_res = NULL; |
| 1651 | struct cam_create_dev_hdl req_hdl_param; |
| 1652 | struct cam_hw_release_args release; |
| 1653 | struct cam_isp_context *ctx_isp = |
| 1654 | (struct cam_isp_context *) ctx->ctx_priv; |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1655 | struct cam_isp_hw_cmd_args hw_cmd_args; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1656 | |
| 1657 | if (!ctx->hw_mgr_intf) { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1658 | CAM_ERR(CAM_ISP, "HW interface is not ready"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1659 | rc = -EFAULT; |
| 1660 | goto end; |
| 1661 | } |
| 1662 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1663 | CAM_DBG(CAM_ISP, |
| 1664 | "session_hdl 0x%x, num_resources %d, hdl type %d, res %lld", |
| 1665 | cmd->session_handle, cmd->num_resources, |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1666 | cmd->handle_type, cmd->resource_hdl); |
| 1667 | |
| 1668 | if (cmd->num_resources > CAM_ISP_CTX_RES_MAX) { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1669 | CAM_ERR(CAM_ISP, "Too much resources in the acquire"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1670 | rc = -ENOMEM; |
| 1671 | goto end; |
| 1672 | } |
| 1673 | |
| 1674 | /* for now we only support user pointer */ |
| 1675 | if (cmd->handle_type != 1) { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1676 | CAM_ERR(CAM_ISP, "Only user pointer is supported"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1677 | rc = -EINVAL; |
| 1678 | goto end; |
| 1679 | } |
| 1680 | |
| 1681 | isp_res = kzalloc( |
| 1682 | sizeof(*isp_res)*cmd->num_resources, GFP_KERNEL); |
| 1683 | if (!isp_res) { |
| 1684 | rc = -ENOMEM; |
| 1685 | goto end; |
| 1686 | } |
| 1687 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1688 | CAM_DBG(CAM_ISP, "start copy %d resources from user", |
| 1689 | cmd->num_resources); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1690 | |
| 1691 | if (copy_from_user(isp_res, (void __user *)cmd->resource_hdl, |
| 1692 | sizeof(*isp_res)*cmd->num_resources)) { |
| 1693 | rc = -EFAULT; |
| 1694 | goto free_res; |
| 1695 | } |
| 1696 | |
| 1697 | param.context_data = ctx; |
| 1698 | param.event_cb = ctx->irq_cb_intf; |
| 1699 | param.num_acq = cmd->num_resources; |
| 1700 | param.acquire_info = (uint64_t) isp_res; |
| 1701 | |
| 1702 | /* call HW manager to reserve the resource */ |
| 1703 | rc = ctx->hw_mgr_intf->hw_acquire(ctx->hw_mgr_intf->hw_mgr_priv, |
| 1704 | ¶m); |
| 1705 | if (rc != 0) { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1706 | CAM_ERR(CAM_ISP, "Acquire device failed"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1707 | goto free_res; |
| 1708 | } |
| 1709 | |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1710 | /* Query the context has rdi only resource */ |
| 1711 | hw_cmd_args.ctxt_to_hw_map = param.ctxt_to_hw_map; |
| 1712 | hw_cmd_args.cmd_type = CAM_ISP_HW_MGR_CMD_IS_RDI_ONLY_CONTEXT; |
| 1713 | rc = ctx->hw_mgr_intf->hw_cmd(ctx->hw_mgr_intf->hw_mgr_priv, |
| 1714 | &hw_cmd_args); |
| 1715 | if (rc) { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1716 | CAM_ERR(CAM_ISP, "HW command failed"); |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1717 | goto free_hw; |
| 1718 | } |
| 1719 | |
| 1720 | if (hw_cmd_args.u.is_rdi_only_context) { |
| 1721 | /* |
| 1722 | * this context has rdi only resource assign rdi only |
| 1723 | * state machine |
| 1724 | */ |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1725 | CAM_DBG(CAM_ISP, "RDI only session Context"); |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1726 | |
| 1727 | ctx_isp->substate_machine_irq = |
| 1728 | cam_isp_ctx_rdi_only_activated_state_machine_irq; |
| 1729 | ctx_isp->substate_machine = |
| 1730 | cam_isp_ctx_rdi_only_activated_state_machine; |
| 1731 | } else { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1732 | CAM_DBG(CAM_ISP, "Session has PIX or PIX and RDI resources"); |
Ravikishore Pampana | ad6bc90 | 2017-07-12 19:37:06 +0530 | [diff] [blame] | 1733 | ctx_isp->substate_machine_irq = |
| 1734 | cam_isp_ctx_activated_state_machine_irq; |
| 1735 | ctx_isp->substate_machine = |
| 1736 | cam_isp_ctx_activated_state_machine; |
| 1737 | } |
| 1738 | |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1739 | ctx_isp->hw_ctx = param.ctxt_to_hw_map; |
| 1740 | |
| 1741 | req_hdl_param.session_hdl = cmd->session_handle; |
| 1742 | /* bridge is not ready for these flags. so false for now */ |
| 1743 | req_hdl_param.v4l2_sub_dev_flag = 0; |
| 1744 | req_hdl_param.media_entity_flag = 0; |
| 1745 | req_hdl_param.ops = ctx->crm_ctx_intf; |
| 1746 | req_hdl_param.priv = ctx; |
| 1747 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1748 | CAM_DBG(CAM_ISP, "get device handle form bridge"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1749 | ctx->dev_hdl = cam_create_device_hdl(&req_hdl_param); |
| 1750 | if (ctx->dev_hdl <= 0) { |
| 1751 | rc = -EFAULT; |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1752 | CAM_ERR(CAM_ISP, "Can not create device handle"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1753 | goto free_hw; |
| 1754 | } |
| 1755 | cmd->dev_handle = ctx->dev_hdl; |
| 1756 | |
| 1757 | /* store session information */ |
| 1758 | ctx->session_hdl = cmd->session_handle; |
| 1759 | |
| 1760 | ctx->state = CAM_CTX_ACQUIRED; |
| 1761 | |
Gregory Bergschneider | 5164f3a | 2017-07-07 10:26:17 -0600 | [diff] [blame] | 1762 | trace_cam_context_state("ISP", ctx); |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1763 | CAM_DBG(CAM_ISP, "Acquire success."); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1764 | kfree(isp_res); |
| 1765 | return rc; |
| 1766 | |
| 1767 | free_hw: |
| 1768 | release.ctxt_to_hw_map = ctx_isp->hw_ctx; |
| 1769 | ctx->hw_mgr_intf->hw_release(ctx->hw_mgr_intf->hw_mgr_priv, &release); |
| 1770 | ctx_isp->hw_ctx = NULL; |
| 1771 | free_res: |
| 1772 | kfree(isp_res); |
| 1773 | end: |
| 1774 | return rc; |
| 1775 | } |
| 1776 | |
| 1777 | static int __cam_isp_ctx_config_dev_in_acquired(struct cam_context *ctx, |
| 1778 | struct cam_config_dev_cmd *cmd) |
| 1779 | { |
| 1780 | int rc = 0; |
| 1781 | |
| 1782 | rc = __cam_isp_ctx_config_dev_in_top_state(ctx, cmd); |
| 1783 | |
Karthik Anantha Ram | 34dc265 | 2017-10-20 15:49:54 -0700 | [diff] [blame^] | 1784 | if (!rc && (ctx->link_hdl >= 0)) { |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1785 | ctx->state = CAM_CTX_READY; |
Gregory Bergschneider | 5164f3a | 2017-07-07 10:26:17 -0600 | [diff] [blame] | 1786 | trace_cam_context_state("ISP", ctx); |
| 1787 | } |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1788 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1789 | CAM_DBG(CAM_ISP, "next state %d", ctx->state); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1790 | return rc; |
| 1791 | } |
| 1792 | |
| 1793 | static int __cam_isp_ctx_link_in_acquired(struct cam_context *ctx, |
| 1794 | struct cam_req_mgr_core_dev_link_setup *link) |
| 1795 | { |
| 1796 | int rc = 0; |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1797 | struct cam_isp_context *ctx_isp = |
| 1798 | (struct cam_isp_context *) ctx->ctx_priv; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1799 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1800 | CAM_DBG(CAM_ISP, "Enter........."); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1801 | |
| 1802 | ctx->link_hdl = link->link_hdl; |
| 1803 | ctx->ctx_crm_intf = link->crm_cb; |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1804 | ctx_isp->subscribe_event = link->subscribe_event; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1805 | |
| 1806 | /* change state only if we had the init config */ |
Gregory Bergschneider | 5164f3a | 2017-07-07 10:26:17 -0600 | [diff] [blame] | 1807 | if (!list_empty(&ctx->pending_req_list)) { |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1808 | ctx->state = CAM_CTX_READY; |
Gregory Bergschneider | 5164f3a | 2017-07-07 10:26:17 -0600 | [diff] [blame] | 1809 | trace_cam_context_state("ISP", ctx); |
| 1810 | } |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1811 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1812 | CAM_DBG(CAM_ISP, "next state %d", ctx->state); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1813 | |
| 1814 | return rc; |
| 1815 | } |
| 1816 | |
| 1817 | static int __cam_isp_ctx_unlink_in_acquired(struct cam_context *ctx, |
| 1818 | struct cam_req_mgr_core_dev_link_setup *unlink) |
| 1819 | { |
| 1820 | int rc = 0; |
| 1821 | |
Karthik Anantha Ram | 34dc265 | 2017-10-20 15:49:54 -0700 | [diff] [blame^] | 1822 | ctx->link_hdl = -1; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1823 | ctx->ctx_crm_intf = NULL; |
| 1824 | |
| 1825 | return rc; |
| 1826 | } |
| 1827 | |
| 1828 | static int __cam_isp_ctx_get_dev_info_in_acquired(struct cam_context *ctx, |
| 1829 | struct cam_req_mgr_device_info *dev_info) |
| 1830 | { |
| 1831 | int rc = 0; |
| 1832 | |
| 1833 | dev_info->dev_hdl = ctx->dev_hdl; |
| 1834 | strlcpy(dev_info->name, CAM_ISP_DEV_NAME, sizeof(dev_info->name)); |
| 1835 | dev_info->dev_id = CAM_REQ_MGR_DEVICE_IFE; |
| 1836 | dev_info->p_delay = 1; |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1837 | dev_info->trigger = CAM_TRIGGER_POINT_SOF; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1838 | |
| 1839 | return rc; |
| 1840 | } |
| 1841 | |
| 1842 | static int __cam_isp_ctx_start_dev_in_ready(struct cam_context *ctx, |
| 1843 | struct cam_start_stop_dev_cmd *cmd) |
| 1844 | { |
| 1845 | int rc = 0; |
| 1846 | struct cam_hw_start_args arg; |
| 1847 | struct cam_ctx_request *req; |
| 1848 | struct cam_isp_ctx_req *req_isp; |
| 1849 | struct cam_isp_context *ctx_isp = |
| 1850 | (struct cam_isp_context *) ctx->ctx_priv; |
| 1851 | |
| 1852 | if (cmd->session_handle != ctx->session_hdl || |
| 1853 | cmd->dev_handle != ctx->dev_hdl) { |
| 1854 | rc = -EPERM; |
| 1855 | goto end; |
| 1856 | } |
| 1857 | |
| 1858 | if (list_empty(&ctx->pending_req_list)) { |
| 1859 | /* should never happen */ |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1860 | CAM_ERR(CAM_ISP, "Start device with empty configuration"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1861 | rc = -EFAULT; |
| 1862 | goto end; |
| 1863 | } else { |
| 1864 | req = list_first_entry(&ctx->pending_req_list, |
| 1865 | struct cam_ctx_request, list); |
| 1866 | } |
| 1867 | req_isp = (struct cam_isp_ctx_req *) req->req_priv; |
| 1868 | |
| 1869 | if (!ctx_isp->hw_ctx) { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1870 | CAM_ERR(CAM_ISP, "Wrong hw context pointer."); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1871 | rc = -EFAULT; |
| 1872 | goto end; |
| 1873 | } |
| 1874 | arg.ctxt_to_hw_map = ctx_isp->hw_ctx; |
| 1875 | arg.hw_update_entries = req_isp->cfg; |
| 1876 | arg.num_hw_update_entries = req_isp->num_cfg; |
| 1877 | |
| 1878 | ctx_isp->frame_id = 0; |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 1879 | ctx_isp->active_req_cnt = 0; |
| 1880 | ctx_isp->reported_req_id = 0; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1881 | ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_SOF; |
| 1882 | |
| 1883 | /* |
| 1884 | * Only place to change state before calling the hw due to |
| 1885 | * hardware tasklet has higher priority that can cause the |
| 1886 | * irq handling comes early |
| 1887 | */ |
| 1888 | ctx->state = CAM_CTX_ACTIVATED; |
Gregory Bergschneider | 5164f3a | 2017-07-07 10:26:17 -0600 | [diff] [blame] | 1889 | trace_cam_context_state("ISP", ctx); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1890 | rc = ctx->hw_mgr_intf->hw_start(ctx->hw_mgr_intf->hw_mgr_priv, &arg); |
| 1891 | if (rc) { |
| 1892 | /* HW failure. user need to clean up the resource */ |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1893 | CAM_ERR(CAM_ISP, "Start HW failed"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1894 | ctx->state = CAM_CTX_READY; |
Gregory Bergschneider | 5164f3a | 2017-07-07 10:26:17 -0600 | [diff] [blame] | 1895 | trace_cam_context_state("ISP", ctx); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1896 | goto end; |
| 1897 | } |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1898 | CAM_DBG(CAM_ISP, "start device success"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1899 | end: |
| 1900 | return rc; |
| 1901 | } |
| 1902 | |
| 1903 | static int __cam_isp_ctx_unlink_in_ready(struct cam_context *ctx, |
| 1904 | struct cam_req_mgr_core_dev_link_setup *unlink) |
| 1905 | { |
| 1906 | int rc = 0; |
| 1907 | |
Karthik Anantha Ram | 34dc265 | 2017-10-20 15:49:54 -0700 | [diff] [blame^] | 1908 | ctx->link_hdl = -1; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1909 | ctx->ctx_crm_intf = NULL; |
| 1910 | ctx->state = CAM_CTX_ACQUIRED; |
Gregory Bergschneider | 5164f3a | 2017-07-07 10:26:17 -0600 | [diff] [blame] | 1911 | trace_cam_context_state("ISP", ctx); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1912 | |
| 1913 | return rc; |
| 1914 | } |
| 1915 | |
| 1916 | static int __cam_isp_ctx_stop_dev_in_activated_unlock( |
| 1917 | struct cam_context *ctx) |
| 1918 | { |
| 1919 | int rc = 0; |
| 1920 | uint32_t i; |
| 1921 | struct cam_hw_stop_args stop; |
| 1922 | struct cam_ctx_request *req; |
| 1923 | struct cam_isp_ctx_req *req_isp; |
| 1924 | struct cam_isp_context *ctx_isp = |
| 1925 | (struct cam_isp_context *) ctx->ctx_priv; |
| 1926 | |
| 1927 | /* Mask off all the incoming hardware events */ |
Jing Zhou | 93b3ec1 | 2017-06-15 17:43:39 -0700 | [diff] [blame] | 1928 | spin_lock_bh(&ctx->lock); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1929 | ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_HALT; |
Jing Zhou | 93b3ec1 | 2017-06-15 17:43:39 -0700 | [diff] [blame] | 1930 | spin_unlock_bh(&ctx->lock); |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1931 | CAM_DBG(CAM_ISP, "next substate %d", ctx_isp->substate_activated); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1932 | |
| 1933 | /* stop hw first */ |
| 1934 | if (ctx_isp->hw_ctx) { |
| 1935 | stop.ctxt_to_hw_map = ctx_isp->hw_ctx; |
| 1936 | ctx->hw_mgr_intf->hw_stop(ctx->hw_mgr_intf->hw_mgr_priv, |
| 1937 | &stop); |
| 1938 | } |
| 1939 | |
| 1940 | while (!list_empty(&ctx->pending_req_list)) { |
| 1941 | req = list_first_entry(&ctx->pending_req_list, |
| 1942 | struct cam_ctx_request, list); |
| 1943 | list_del_init(&req->list); |
| 1944 | req_isp = (struct cam_isp_ctx_req *) req->req_priv; |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1945 | CAM_DBG(CAM_ISP, "signal fence in pending list. fence num %d", |
| 1946 | req_isp->num_fence_map_out); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1947 | for (i = 0; i < req_isp->num_fence_map_out; i++) |
| 1948 | if (req_isp->fence_map_out[i].sync_id != -1) { |
| 1949 | cam_sync_signal( |
| 1950 | req_isp->fence_map_out[i].sync_id, |
| 1951 | CAM_SYNC_STATE_SIGNALED_ERROR); |
| 1952 | } |
| 1953 | list_add_tail(&req->list, &ctx->free_req_list); |
| 1954 | } |
| 1955 | |
| 1956 | while (!list_empty(&ctx->active_req_list)) { |
| 1957 | req = list_first_entry(&ctx->active_req_list, |
| 1958 | struct cam_ctx_request, list); |
| 1959 | list_del_init(&req->list); |
| 1960 | req_isp = (struct cam_isp_ctx_req *) req->req_priv; |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1961 | CAM_DBG(CAM_ISP, "signal fence in active list. fence num %d", |
| 1962 | req_isp->num_fence_map_out); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1963 | for (i = 0; i < req_isp->num_fence_map_out; i++) |
| 1964 | if (req_isp->fence_map_out[i].sync_id != -1) { |
| 1965 | cam_sync_signal( |
| 1966 | req_isp->fence_map_out[i].sync_id, |
| 1967 | CAM_SYNC_STATE_SIGNALED_ERROR); |
| 1968 | } |
| 1969 | list_add_tail(&req->list, &ctx->free_req_list); |
| 1970 | } |
| 1971 | ctx_isp->frame_id = 0; |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 1972 | ctx_isp->active_req_cnt = 0; |
| 1973 | ctx_isp->reported_req_id = 0; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1974 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 1975 | CAM_DBG(CAM_ISP, "next state %d", ctx->state); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1976 | return rc; |
| 1977 | } |
| 1978 | |
| 1979 | static int __cam_isp_ctx_stop_dev_in_activated(struct cam_context *ctx, |
| 1980 | struct cam_start_stop_dev_cmd *cmd) |
| 1981 | { |
| 1982 | int rc = 0; |
| 1983 | |
| 1984 | __cam_isp_ctx_stop_dev_in_activated_unlock(ctx); |
| 1985 | ctx->state = CAM_CTX_ACQUIRED; |
Gregory Bergschneider | 5164f3a | 2017-07-07 10:26:17 -0600 | [diff] [blame] | 1986 | trace_cam_context_state("ISP", ctx); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1987 | return rc; |
| 1988 | } |
| 1989 | |
| 1990 | static int __cam_isp_ctx_release_dev_in_activated(struct cam_context *ctx, |
| 1991 | struct cam_release_dev_cmd *cmd) |
| 1992 | { |
| 1993 | int rc = 0; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1994 | |
Harsh Shah | 2d96c5e | 2017-09-29 11:58:45 -0700 | [diff] [blame] | 1995 | rc = __cam_isp_ctx_stop_dev_in_activated_unlock(ctx); |
| 1996 | if (rc) |
| 1997 | CAM_ERR(CAM_ISP, "Stop device failed rc=%d", rc); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 1998 | |
Harsh Shah | 2d96c5e | 2017-09-29 11:58:45 -0700 | [diff] [blame] | 1999 | rc = __cam_isp_ctx_release_dev_in_top_state(ctx, cmd); |
| 2000 | if (rc) |
| 2001 | CAM_ERR(CAM_ISP, "Release device failed rc=%d", rc); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2002 | |
| 2003 | return rc; |
| 2004 | } |
| 2005 | |
| 2006 | static int __cam_isp_ctx_apply_req(struct cam_context *ctx, |
| 2007 | struct cam_req_mgr_apply_request *apply) |
| 2008 | { |
| 2009 | int rc = 0; |
| 2010 | struct cam_isp_context *ctx_isp = |
| 2011 | (struct cam_isp_context *) ctx->ctx_priv; |
| 2012 | |
Junzhe Zou | 5fa08b1 | 2017-08-15 10:08:12 -0700 | [diff] [blame] | 2013 | trace_cam_apply_req("ISP", apply->request_id); |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 2014 | CAM_DBG(CAM_ISP, "Enter: apply req in Substate %d request _id:%lld", |
| 2015 | ctx_isp->substate_activated, apply->request_id); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2016 | if (ctx_isp->substate_machine[ctx_isp->substate_activated]. |
| 2017 | crm_ops.apply_req) { |
| 2018 | rc = ctx_isp->substate_machine[ctx_isp->substate_activated]. |
| 2019 | crm_ops.apply_req(ctx, apply); |
| 2020 | } else { |
Harsh Shah | cb0072c | 2017-09-26 19:22:10 -0700 | [diff] [blame] | 2021 | CAM_ERR_RATE_LIMIT(CAM_ISP, |
| 2022 | "No handle function in activated substate %d", |
| 2023 | ctx_isp->substate_activated); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2024 | rc = -EFAULT; |
| 2025 | } |
| 2026 | |
| 2027 | if (rc) |
Harsh Shah | cb0072c | 2017-09-26 19:22:10 -0700 | [diff] [blame] | 2028 | CAM_ERR_RATE_LIMIT(CAM_ISP, |
| 2029 | "Apply failed in active substate %d", |
| 2030 | ctx_isp->substate_activated); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2031 | return rc; |
| 2032 | } |
| 2033 | |
| 2034 | |
| 2035 | |
| 2036 | static int __cam_isp_ctx_handle_irq_in_activated(void *context, |
| 2037 | uint32_t evt_id, void *evt_data) |
| 2038 | { |
| 2039 | int rc = 0; |
| 2040 | struct cam_context *ctx = (struct cam_context *)context; |
| 2041 | struct cam_isp_context *ctx_isp = |
| 2042 | (struct cam_isp_context *)ctx->ctx_priv; |
| 2043 | |
Jing Zhou | 93b3ec1 | 2017-06-15 17:43:39 -0700 | [diff] [blame] | 2044 | spin_lock_bh(&ctx->lock); |
Gregory Bergschneider | 5164f3a | 2017-07-07 10:26:17 -0600 | [diff] [blame] | 2045 | |
| 2046 | trace_cam_isp_activated_irq(ctx, ctx_isp->substate_activated, evt_id, |
| 2047 | __cam_isp_ctx_get_event_ts(evt_id, evt_data)); |
| 2048 | |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 2049 | CAM_DBG(CAM_ISP, "Enter: State %d, Substate %d, evt id %d", |
| 2050 | ctx->state, ctx_isp->substate_activated, evt_id); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2051 | if (ctx_isp->substate_machine_irq[ctx_isp->substate_activated]. |
| 2052 | irq_ops[evt_id]) { |
| 2053 | rc = ctx_isp->substate_machine_irq[ctx_isp->substate_activated]. |
| 2054 | irq_ops[evt_id](ctx_isp, evt_data); |
| 2055 | } else { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 2056 | CAM_DBG(CAM_ISP, "No handle function for substate %d", |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2057 | ctx_isp->substate_activated); |
| 2058 | } |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 2059 | CAM_DBG(CAM_ISP, "Exit: State %d Substate %d", |
| 2060 | ctx->state, ctx_isp->substate_activated); |
Jing Zhou | 93b3ec1 | 2017-06-15 17:43:39 -0700 | [diff] [blame] | 2061 | spin_unlock_bh(&ctx->lock); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2062 | return rc; |
| 2063 | } |
| 2064 | |
| 2065 | /* top state machine */ |
| 2066 | static struct cam_ctx_ops |
| 2067 | cam_isp_ctx_top_state_machine[CAM_CTX_STATE_MAX] = { |
| 2068 | /* Uninit */ |
| 2069 | { |
| 2070 | .ioctl_ops = {}, |
| 2071 | .crm_ops = {}, |
| 2072 | .irq_ops = NULL, |
| 2073 | }, |
| 2074 | /* Available */ |
| 2075 | { |
| 2076 | .ioctl_ops = { |
| 2077 | .acquire_dev = __cam_isp_ctx_acquire_dev_in_available, |
| 2078 | }, |
| 2079 | .crm_ops = {}, |
| 2080 | .irq_ops = NULL, |
| 2081 | }, |
| 2082 | /* Acquired */ |
| 2083 | { |
| 2084 | .ioctl_ops = { |
| 2085 | .release_dev = __cam_isp_ctx_release_dev_in_top_state, |
| 2086 | .config_dev = __cam_isp_ctx_config_dev_in_acquired, |
| 2087 | }, |
| 2088 | .crm_ops = { |
| 2089 | .link = __cam_isp_ctx_link_in_acquired, |
| 2090 | .unlink = __cam_isp_ctx_unlink_in_acquired, |
| 2091 | .get_dev_info = __cam_isp_ctx_get_dev_info_in_acquired, |
Jing Zhou | b524a85 | 2017-05-16 15:47:30 +0530 | [diff] [blame] | 2092 | .flush_req = __cam_isp_ctx_flush_req_in_top_state, |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2093 | }, |
| 2094 | .irq_ops = NULL, |
| 2095 | }, |
| 2096 | /* Ready */ |
| 2097 | { |
| 2098 | .ioctl_ops = { |
| 2099 | .start_dev = __cam_isp_ctx_start_dev_in_ready, |
| 2100 | .release_dev = __cam_isp_ctx_release_dev_in_top_state, |
| 2101 | .config_dev = __cam_isp_ctx_config_dev_in_top_state, |
| 2102 | }, |
| 2103 | .crm_ops = { |
| 2104 | .unlink = __cam_isp_ctx_unlink_in_ready, |
Jing Zhou | b524a85 | 2017-05-16 15:47:30 +0530 | [diff] [blame] | 2105 | .flush_req = __cam_isp_ctx_flush_req_in_ready, |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2106 | }, |
| 2107 | .irq_ops = NULL, |
| 2108 | }, |
| 2109 | /* Activated */ |
| 2110 | { |
| 2111 | .ioctl_ops = { |
| 2112 | .stop_dev = __cam_isp_ctx_stop_dev_in_activated, |
| 2113 | .release_dev = __cam_isp_ctx_release_dev_in_activated, |
| 2114 | .config_dev = __cam_isp_ctx_config_dev_in_top_state, |
| 2115 | }, |
| 2116 | .crm_ops = { |
| 2117 | .apply_req = __cam_isp_ctx_apply_req, |
Jing Zhou | b524a85 | 2017-05-16 15:47:30 +0530 | [diff] [blame] | 2118 | .flush_req = __cam_isp_ctx_flush_req_in_top_state, |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2119 | }, |
| 2120 | .irq_ops = __cam_isp_ctx_handle_irq_in_activated, |
| 2121 | }, |
| 2122 | }; |
| 2123 | |
| 2124 | |
| 2125 | int cam_isp_context_init(struct cam_isp_context *ctx, |
| 2126 | struct cam_context *ctx_base, |
| 2127 | struct cam_req_mgr_kmd_ops *crm_node_intf, |
| 2128 | struct cam_hw_mgr_intf *hw_intf) |
| 2129 | |
| 2130 | { |
| 2131 | int rc = -1; |
| 2132 | int i; |
| 2133 | |
| 2134 | if (!ctx || !ctx_base) { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 2135 | CAM_ERR(CAM_ISP, "Invalid Context"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2136 | goto err; |
| 2137 | } |
| 2138 | |
| 2139 | /* ISP context setup */ |
| 2140 | memset(ctx, 0, sizeof(*ctx)); |
| 2141 | |
| 2142 | ctx->base = ctx_base; |
| 2143 | ctx->frame_id = 0; |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 2144 | ctx->active_req_cnt = 0; |
| 2145 | ctx->reported_req_id = 0; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2146 | ctx->hw_ctx = NULL; |
| 2147 | ctx->substate_activated = CAM_ISP_CTX_ACTIVATED_SOF; |
| 2148 | ctx->substate_machine = cam_isp_ctx_activated_state_machine; |
| 2149 | ctx->substate_machine_irq = cam_isp_ctx_activated_state_machine_irq; |
| 2150 | |
| 2151 | for (i = 0; i < CAM_CTX_REQ_MAX; i++) { |
| 2152 | ctx->req_base[i].req_priv = &ctx->req_isp[i]; |
| 2153 | ctx->req_isp[i].base = &ctx->req_base[i]; |
| 2154 | } |
| 2155 | |
| 2156 | /* camera context setup */ |
| 2157 | rc = cam_context_init(ctx_base, crm_node_intf, hw_intf, ctx->req_base, |
| 2158 | CAM_CTX_REQ_MAX); |
| 2159 | if (rc) { |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 2160 | CAM_ERR(CAM_ISP, "Camera Context Base init failed"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2161 | goto err; |
| 2162 | } |
| 2163 | |
| 2164 | /* link camera context with isp context */ |
| 2165 | ctx_base->state_machine = cam_isp_ctx_top_state_machine; |
| 2166 | ctx_base->ctx_priv = ctx; |
| 2167 | |
| 2168 | err: |
| 2169 | return rc; |
| 2170 | } |
| 2171 | |
| 2172 | int cam_isp_context_deinit(struct cam_isp_context *ctx) |
| 2173 | { |
| 2174 | int rc = 0; |
| 2175 | |
| 2176 | if (ctx->base) |
| 2177 | cam_context_deinit(ctx->base); |
| 2178 | |
| 2179 | if (ctx->substate_activated != CAM_ISP_CTX_ACTIVATED_SOF) |
Jigarkumar Zala | 7c4fd37 | 2017-07-24 18:43:04 -0700 | [diff] [blame] | 2180 | CAM_ERR(CAM_ISP, "ISP context substate is invalid"); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2181 | |
| 2182 | memset(ctx, 0, sizeof(*ctx)); |
| 2183 | return rc; |
| 2184 | } |
| 2185 | |