Shravya Samala | 43583ea | 2020-04-29 14:25:37 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #ifndef _CAM_ISP_CONTEXT_H_ |
| 14 | #define _CAM_ISP_CONTEXT_H_ |
| 15 | |
| 16 | |
| 17 | #include <linux/spinlock.h> |
| 18 | #include <uapi/media/cam_isp.h> |
| 19 | |
| 20 | #include "cam_context.h" |
| 21 | #include "cam_isp_hw_mgr_intf.h" |
| 22 | |
| 23 | /* |
| 24 | * Maximum hw resource - This number is based on the maximum |
| 25 | * output port resource. The current maximum resource number |
Vishalsingh Hajeri | 8f6e1dd | 2018-05-17 12:19:39 -0700 | [diff] [blame] | 26 | * is 20. |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 27 | */ |
Vishalsingh Hajeri | 8f6e1dd | 2018-05-17 12:19:39 -0700 | [diff] [blame] | 28 | #define CAM_ISP_CTX_RES_MAX 20 |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 29 | |
| 30 | /* |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 31 | * Maximum configuration entry size - This is based on the |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 32 | * worst case DUAL IFE use case plus some margin. |
| 33 | */ |
Harsh Shah | 9d676dd | 2017-08-30 16:30:04 -0700 | [diff] [blame] | 34 | #define CAM_ISP_CTX_CFG_MAX 22 |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 35 | |
Shravya Samala | 43583ea | 2020-04-29 14:25:37 +0530 | [diff] [blame] | 36 | /* Maximum allowed sof count in rdi only bubble state |
| 37 | * till buf_done is received for bubble req_id. |
| 38 | */ |
| 39 | #define CAM_ISP_CTX_BUBBLE_SOF_COUNT_MAX 3 |
| 40 | |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 41 | /* |
| 42 | * Maximum entries in state monitoring array for error logging |
| 43 | */ |
| 44 | #define CAM_ISP_CTX_STATE_MONITOR_MAX_ENTRIES 20 |
| 45 | |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 46 | /* forward declaration */ |
| 47 | struct cam_isp_context; |
| 48 | |
| 49 | /* cam isp context irq handling function type */ |
| 50 | typedef int (*cam_isp_hw_event_cb_func)(struct cam_isp_context *ctx_isp, |
| 51 | void *evt_data); |
| 52 | |
| 53 | /** |
| 54 | * enum cam_isp_ctx_activated_substate - sub states for activated |
| 55 | * |
| 56 | */ |
| 57 | enum cam_isp_ctx_activated_substate { |
| 58 | CAM_ISP_CTX_ACTIVATED_SOF, |
| 59 | CAM_ISP_CTX_ACTIVATED_APPLIED, |
| 60 | CAM_ISP_CTX_ACTIVATED_EPOCH, |
| 61 | CAM_ISP_CTX_ACTIVATED_BUBBLE, |
| 62 | CAM_ISP_CTX_ACTIVATED_BUBBLE_APPLIED, |
Alok Pandey | fdfa5ba | 2017-09-22 14:21:25 +0530 | [diff] [blame] | 63 | CAM_ISP_CTX_ACTIVATED_HW_ERROR, |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 64 | CAM_ISP_CTX_ACTIVATED_HALT, |
| 65 | CAM_ISP_CTX_ACTIVATED_MAX, |
| 66 | }; |
| 67 | |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 68 | /** |
| 69 | * enum cam_isp_state_change_trigger - Different types of ISP events |
| 70 | * |
| 71 | */ |
| 72 | enum cam_isp_state_change_trigger { |
| 73 | CAM_ISP_STATE_CHANGE_TRIGGER_ERROR, |
| 74 | CAM_ISP_STATE_CHANGE_TRIGGER_SOF, |
| 75 | CAM_ISP_STATE_CHANGE_TRIGGER_REG_UPDATE, |
| 76 | CAM_ISP_STATE_CHANGE_TRIGGER_EPOCH, |
| 77 | CAM_ISP_STATE_CHANGE_TRIGGER_EOF, |
| 78 | CAM_ISP_STATE_CHANGE_TRIGGER_DONE, |
| 79 | CAM_ISP_STATE_CHANGE_TRIGGER_MAX |
| 80 | }; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 81 | |
| 82 | /** |
| 83 | * struct cam_isp_ctx_irq_ops - Function table for handling IRQ callbacks |
| 84 | * |
| 85 | * @irq_ops: Array of handle function pointers. |
| 86 | * |
| 87 | */ |
| 88 | struct cam_isp_ctx_irq_ops { |
| 89 | cam_isp_hw_event_cb_func irq_ops[CAM_ISP_HW_EVENT_MAX]; |
| 90 | }; |
| 91 | |
| 92 | /** |
| 93 | * struct cam_isp_ctx_req - ISP context request object |
| 94 | * |
| 95 | * @base: Common request object ponter |
| 96 | * @cfg: ISP hardware configuration array |
| 97 | * @num_cfg: Number of ISP hardware configuration entries |
| 98 | * @fence_map_out: Output fence mapping array |
| 99 | * @num_fence_map_out: Number of the output fence map |
| 100 | * @fence_map_in: Input fence mapping array |
| 101 | * @num_fence_map_in: Number of input fence map |
| 102 | * @num_acked: Count to track acked entried for output. |
| 103 | * If count equals the number of fence out, it means |
| 104 | * the request has been completed. |
| 105 | * @bubble_report: Flag to track if bubble report is active on |
| 106 | * current request |
Vishalsingh Hajeri | e5450be | 2018-01-18 20:31:19 -0800 | [diff] [blame] | 107 | * @hw_update_data: HW update data for this request |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 108 | * |
| 109 | */ |
| 110 | struct cam_isp_ctx_req { |
Vishalsingh Hajeri | e5450be | 2018-01-18 20:31:19 -0800 | [diff] [blame] | 111 | struct cam_ctx_request *base; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 112 | |
Vishalsingh Hajeri | e5450be | 2018-01-18 20:31:19 -0800 | [diff] [blame] | 113 | struct cam_hw_update_entry cfg[CAM_ISP_CTX_CFG_MAX]; |
| 114 | uint32_t num_cfg; |
| 115 | struct cam_hw_fence_map_entry fence_map_out |
| 116 | [CAM_ISP_CTX_RES_MAX]; |
| 117 | uint32_t num_fence_map_out; |
| 118 | struct cam_hw_fence_map_entry fence_map_in[CAM_ISP_CTX_RES_MAX]; |
| 119 | uint32_t num_fence_map_in; |
| 120 | uint32_t num_acked; |
| 121 | int32_t bubble_report; |
| 122 | struct cam_isp_prepare_hw_update_data hw_update_data; |
Junzhe Zou | 09820a7 | 2018-09-06 18:11:41 -0700 | [diff] [blame] | 123 | bool bubble_detected; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | /** |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 127 | * struct cam_isp_context_state_monitor - ISP context state |
| 128 | * monitoring for |
| 129 | * debug purposes |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 130 | * |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 131 | *@curr_state: Current sub state that received req |
| 132 | *@req_type: Event type of incoming req |
| 133 | *@req_id: Request id |
| 134 | *@evt_time_stamp Current time stamp |
| 135 | * |
| 136 | */ |
| 137 | struct cam_isp_context_state_monitor { |
| 138 | enum cam_isp_ctx_activated_substate curr_state; |
| 139 | enum cam_isp_state_change_trigger trigger; |
| 140 | uint32_t req_id; |
| 141 | int64_t frame_id; |
| 142 | uint64_t evt_time_stamp; |
| 143 | }; |
| 144 | |
| 145 | /** |
| 146 | * struct cam_isp_context - ISP context object |
| 147 | * |
| 148 | * @base: Common context object pointer |
| 149 | * @frame_id: Frame id tracking for the isp context |
| 150 | * @substate_actiavted: Current substate for the activated state. |
Ayush Kumar | f13969a9 | 2019-07-18 13:02:43 +0530 | [diff] [blame] | 151 | * @process_bubble: Atomic variable to check if ctx is still |
| 152 | * processing bubble |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 153 | * @substate_machine: ISP substate machine for external interface |
| 154 | * @substate_machine_irq: ISP substate machine for irq handling |
| 155 | * @req_base: Common request object storage |
| 156 | * @req_isp: ISP private request object storage |
| 157 | * @hw_ctx: HW object returned by the acquire device command |
| 158 | * @sof_timestamp_val: Captured time stamp value at sof hw event |
Karthik Anantha Ram | c93754c | 2018-03-28 14:21:14 -0700 | [diff] [blame] | 159 | * @boot_timestamp: Boot time stamp for a given req_id |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 160 | * @active_req_cnt: Counter for the active request |
| 161 | * @reported_req_id: Last reported request id |
| 162 | * @subscribe_event: The irq event mask that CRM subscribes to, IFE |
| 163 | * will invoke CRM cb at those event. |
| 164 | * @last_applied_req_id: Last applied request id |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 165 | * @state_monitor_head: Write index to the state monitoring array |
| 166 | * @cam_isp_ctx_state_monitor: State monitoring array |
Lynus Vaz | cbda4b0 | 2018-03-26 15:48:01 +0530 | [diff] [blame] | 167 | * @rdi_only_context: Get context type information. |
| 168 | * true, if context is rdi only context |
Shravya Samala | 43583ea | 2020-04-29 14:25:37 +0530 | [diff] [blame] | 169 | * @bubble_sof_count: Atomic variable to check if ctx has any sof's |
| 170 | * while processing bubble |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 171 | * |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 172 | */ |
| 173 | struct cam_isp_context { |
| 174 | struct cam_context *base; |
| 175 | |
| 176 | int64_t frame_id; |
| 177 | uint32_t substate_activated; |
Ayush Kumar | f13969a9 | 2019-07-18 13:02:43 +0530 | [diff] [blame] | 178 | atomic_t process_bubble; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 179 | struct cam_ctx_ops *substate_machine; |
| 180 | struct cam_isp_ctx_irq_ops *substate_machine_irq; |
| 181 | |
| 182 | struct cam_ctx_request req_base[CAM_CTX_REQ_MAX]; |
| 183 | struct cam_isp_ctx_req req_isp[CAM_CTX_REQ_MAX]; |
| 184 | |
| 185 | void *hw_ctx; |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 186 | uint64_t sof_timestamp_val; |
Karthik Anantha Ram | c93754c | 2018-03-28 14:21:14 -0700 | [diff] [blame] | 187 | uint64_t boot_timestamp; |
Jing Zhou | dedc476 | 2017-06-19 17:45:36 +0530 | [diff] [blame] | 188 | int32_t active_req_cnt; |
| 189 | int64_t reported_req_id; |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 190 | uint32_t subscribe_event; |
Alok Pandey | fdfa5ba | 2017-09-22 14:21:25 +0530 | [diff] [blame] | 191 | int64_t last_applied_req_id; |
Vishalsingh Hajeri | c0cab06 | 2017-09-28 18:25:16 -0700 | [diff] [blame] | 192 | atomic64_t state_monitor_head; |
| 193 | struct cam_isp_context_state_monitor cam_isp_ctx_state_monitor[ |
| 194 | CAM_ISP_CTX_STATE_MONITOR_MAX_ENTRIES]; |
Lynus Vaz | cbda4b0 | 2018-03-26 15:48:01 +0530 | [diff] [blame] | 195 | bool rdi_only_context; |
Shravya Samala | 43583ea | 2020-04-29 14:25:37 +0530 | [diff] [blame] | 196 | atomic_t bubble_sof_count; |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 197 | }; |
| 198 | |
| 199 | /** |
| 200 | * cam_isp_context_init() |
| 201 | * |
| 202 | * @brief: Initialization function for the ISP context |
| 203 | * |
| 204 | * @ctx: ISP context obj to be initialized |
| 205 | * @bridge_ops: Bridge call back funciton |
| 206 | * @hw_intf: ISP hw manager interface |
Pavan Kumar Chilamkurthi | 96fd3c9 | 2018-01-25 14:16:57 -0800 | [diff] [blame] | 207 | * @ctx_id: ID for this context |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 208 | * |
| 209 | */ |
| 210 | int cam_isp_context_init(struct cam_isp_context *ctx, |
| 211 | struct cam_context *ctx_base, |
| 212 | struct cam_req_mgr_kmd_ops *bridge_ops, |
Pavan Kumar Chilamkurthi | 96fd3c9 | 2018-01-25 14:16:57 -0800 | [diff] [blame] | 213 | struct cam_hw_mgr_intf *hw_intf, |
| 214 | uint32_t ctx_id); |
Jing Zhou | d352ed1 | 2017-03-20 23:59:56 -0700 | [diff] [blame] | 215 | |
| 216 | /** |
| 217 | * cam_isp_context_deinit() |
| 218 | * |
| 219 | * @brief: Deinitialize function for the ISP context |
| 220 | * |
| 221 | * @ctx: ISP context obj to be deinitialized |
| 222 | * |
| 223 | */ |
| 224 | int cam_isp_context_deinit(struct cam_isp_context *ctx); |
| 225 | |
| 226 | |
| 227 | #endif /* __CAM_ISP_CONTEXT_H__ */ |