1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Support for Intel Camera Imaging ISP subsystem. 4 * Copyright (c) 2010 - 2015, Intel Corporation. 5 * 6 * This program is free software; you can redistribute it and/or modify it 7 * under the terms and conditions of the GNU General Public License, 8 * version 2, as published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 * more details. 14 */ 15 16 #ifndef __IA_CSS_PIPELINE_H__ 17 #define __IA_CSS_PIPELINE_H__ 18 19 #include "sh_css_internal.h" 20 #include "ia_css_pipe_public.h" 21 #include "ia_css_pipeline_common.h" 22 23 #define IA_CSS_PIPELINE_NUM_MAX (20) 24 25 /* Pipeline stage to be executed on SP/ISP */ 26 struct ia_css_pipeline_stage { 27 unsigned int stage_num; 28 struct ia_css_binary *binary; /* built-in binary */ 29 struct ia_css_binary_info *binary_info; 30 const struct ia_css_fw_info *firmware; /* acceleration binary */ 31 /* SP function for SP stage */ 32 enum ia_css_pipeline_stage_sp_func sp_func; 33 unsigned int max_input_width; /* For SP raw copy */ 34 struct sh_css_binary_args args; 35 int mode; 36 bool out_frame_allocated[IA_CSS_BINARY_MAX_OUTPUT_PORTS]; 37 bool vf_frame_allocated; 38 struct ia_css_pipeline_stage *next; 39 bool enable_zoom; 40 }; 41 42 /* Pipeline of n stages to be executed on SP/ISP per stage */ 43 struct ia_css_pipeline { 44 enum ia_css_pipe_id pipe_id; 45 u8 pipe_num; 46 bool stop_requested; 47 struct ia_css_pipeline_stage *stages; 48 struct ia_css_pipeline_stage *current_stage; 49 unsigned int num_stages; 50 struct ia_css_frame in_frame; 51 struct ia_css_frame out_frame[IA_CSS_PIPE_MAX_OUTPUT_STAGE]; 52 struct ia_css_frame vf_frame[IA_CSS_PIPE_MAX_OUTPUT_STAGE]; 53 unsigned int dvs_frame_delay; 54 unsigned int inout_port_config; 55 int num_execs; 56 bool acquire_isp_each_stage; 57 u32 pipe_qos_config; 58 }; 59 60 #define DEFAULT_PIPELINE { \ 61 .pipe_id = IA_CSS_PIPE_ID_PREVIEW, \ 62 .in_frame = DEFAULT_FRAME, \ 63 .out_frame = {DEFAULT_FRAME}, \ 64 .vf_frame = {DEFAULT_FRAME}, \ 65 .dvs_frame_delay = IA_CSS_FRAME_DELAY_1, \ 66 .num_execs = -1, \ 67 .acquire_isp_each_stage = true, \ 68 .pipe_qos_config = QOS_INVALID \ 69 } 70 71 /* Stage descriptor used to create a new stage in the pipeline */ 72 struct ia_css_pipeline_stage_desc { 73 struct ia_css_binary *binary; 74 const struct ia_css_fw_info *firmware; 75 enum ia_css_pipeline_stage_sp_func sp_func; 76 unsigned int max_input_width; 77 unsigned int mode; 78 struct ia_css_frame *in_frame; 79 struct ia_css_frame *out_frame[IA_CSS_BINARY_MAX_OUTPUT_PORTS]; 80 struct ia_css_frame *vf_frame; 81 }; 82 83 /* @brief initialize the pipeline module 84 * 85 * @return None 86 * 87 * Initializes the pipeline module. This API has to be called 88 * before any operation on the pipeline module is done 89 */ 90 void ia_css_pipeline_init(void); 91 92 /* @brief initialize the pipeline structure with default values 93 * 94 * @param[out] pipeline structure to be initialized with defaults 95 * @param[in] pipe_id 96 * @param[in] pipe_num Number that uniquely identifies a pipeline. 97 * @return 0 or error code upon error. 98 * 99 * Initializes the pipeline structure with a set of default values. 100 * This API is expected to be used when a pipeline structure is allocated 101 * externally and needs sane defaults 102 */ 103 int ia_css_pipeline_create( 104 struct ia_css_pipeline *pipeline, 105 enum ia_css_pipe_id pipe_id, 106 unsigned int pipe_num, 107 unsigned int dvs_frame_delay); 108 109 /* @brief destroy a pipeline 110 * 111 * @param[in] pipeline 112 * @return None 113 * 114 */ 115 void ia_css_pipeline_destroy(struct ia_css_pipeline *pipeline); 116 117 /* @brief Starts a pipeline 118 * 119 * @param[in] pipe_id 120 * @param[in] pipeline 121 * @return None 122 * 123 */ 124 void ia_css_pipeline_start(enum ia_css_pipe_id pipe_id, 125 struct ia_css_pipeline *pipeline); 126 127 /* @brief Request to stop a pipeline 128 * 129 * @param[in] pipeline 130 * @return 0 or error code upon error. 131 * 132 */ 133 int ia_css_pipeline_request_stop(struct ia_css_pipeline *pipeline); 134 135 /* @brief Check whether pipeline has stopped 136 * 137 * @param[in] pipeline 138 * @return true if the pipeline has stopped 139 * 140 */ 141 bool ia_css_pipeline_has_stopped(struct ia_css_pipeline *pipe); 142 143 /* @brief clean all the stages pipeline and make it as new 144 * 145 * @param[in] pipeline 146 * @return None 147 * 148 */ 149 void ia_css_pipeline_clean(struct ia_css_pipeline *pipeline); 150 151 /* @brief Add a stage to pipeline. 152 * 153 * @param pipeline Pointer to the pipeline to be added to. 154 * @param[in] stage_desc The description of the stage 155 * @param[out] stage The successor of the stage. 156 * @return 0 or error code upon error. 157 * 158 * Add a new stage to a non-NULL pipeline. 159 * The stage consists of an ISP binary or firmware and input and output 160 * arguments. 161 */ 162 int ia_css_pipeline_create_and_add_stage( 163 struct ia_css_pipeline *pipeline, 164 struct ia_css_pipeline_stage_desc *stage_desc, 165 struct ia_css_pipeline_stage **stage); 166 167 /* @brief Finalize the stages in a pipeline 168 * 169 * @param pipeline Pointer to the pipeline to be added to. 170 * @return None 171 * 172 * This API is expected to be called after adding all stages 173 */ 174 void ia_css_pipeline_finalize_stages(struct ia_css_pipeline *pipeline, 175 bool continuous); 176 177 /* @brief gets a stage from the pipeline 178 * 179 * @param[in] pipeline 180 * @return 0 or error code upon error. 181 * 182 */ 183 int ia_css_pipeline_get_stage(struct ia_css_pipeline *pipeline, 184 int mode, 185 struct ia_css_pipeline_stage **stage); 186 187 /* @brief Gets a pipeline stage corresponding Firmware handle from the pipeline 188 * 189 * @param[in] pipeline 190 * @param[in] fw_handle 191 * @param[out] stage Pointer to Stage 192 * 193 * @return 0 or error code upon error. 194 * 195 */ 196 int ia_css_pipeline_get_stage_from_fw(struct ia_css_pipeline 197 *pipeline, 198 u32 fw_handle, 199 struct ia_css_pipeline_stage **stage); 200 201 /* @brief Gets the Firmware handle corresponding the stage num from the pipeline 202 * 203 * @param[in] pipeline 204 * @param[in] stage_num 205 * @param[out] fw_handle 206 * 207 * @return 0 or error code upon error. 208 * 209 */ 210 int ia_css_pipeline_get_fw_from_stage(struct ia_css_pipeline 211 *pipeline, 212 u32 stage_num, 213 uint32_t *fw_handle); 214 215 /* @brief gets the output stage from the pipeline 216 * 217 * @param[in] pipeline 218 * @return 0 or error code upon error. 219 * 220 */ 221 int ia_css_pipeline_get_output_stage( 222 struct ia_css_pipeline *pipeline, 223 int mode, 224 struct ia_css_pipeline_stage **stage); 225 226 /* @brief Checks whether the pipeline uses params 227 * 228 * @param[in] pipeline 229 * @return true if the pipeline uses params 230 * 231 */ 232 bool ia_css_pipeline_uses_params(struct ia_css_pipeline *pipeline); 233 234 /** 235 * @brief get the SP thread ID. 236 * 237 * @param[in] key The query key, typical use is pipe_num. 238 * @param[out] val The query value. 239 * 240 * @return 241 * true, if the query succeeds; 242 * false, if the query fails. 243 */ 244 bool ia_css_pipeline_get_sp_thread_id(unsigned int key, unsigned int *val); 245 246 #if defined(ISP2401) 247 /** 248 * @brief Get the pipeline io status 249 * 250 * @param[in] None 251 * @return 252 * Pointer to pipe_io_status 253 */ 254 struct sh_css_sp_pipeline_io_status *ia_css_pipeline_get_pipe_io_status(void); 255 #endif 256 257 /** 258 * @brief Map an SP thread to this pipeline 259 * 260 * @param[in] pipe_num 261 * @param[in] map true for mapping and false for unmapping sp threads. 262 * 263 */ 264 void ia_css_pipeline_map(unsigned int pipe_num, bool map); 265 266 /** 267 * @brief Checks whether the pipeline is mapped to SP threads 268 * 269 * @param[in] Query key, typical use is pipe_num 270 * 271 * return 272 * true, pipeline is mapped to SP threads 273 * false, pipeline is not mapped to SP threads 274 */ 275 bool ia_css_pipeline_is_mapped(unsigned int key); 276 277 /** 278 * @brief Print pipeline thread mapping 279 * 280 * @param[in] none 281 * 282 * return none 283 */ 284 void ia_css_pipeline_dump_thread_map_info(void); 285 286 #endif /*__IA_CSS_PIPELINE_H__*/ 287