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 };
58 
59 #define DEFAULT_PIPELINE { \
60 	.pipe_id		= IA_CSS_PIPE_ID_PREVIEW, \
61 	.in_frame		= DEFAULT_FRAME, \
62 	.out_frame		= {DEFAULT_FRAME}, \
63 	.vf_frame		= {DEFAULT_FRAME}, \
64 	.dvs_frame_delay	= IA_CSS_FRAME_DELAY_1, \
65 	.num_execs		= -1, \
66 	.acquire_isp_each_stage	= true, \
67 }
68 
69 /* Stage descriptor used to create a new stage in the pipeline */
70 struct ia_css_pipeline_stage_desc {
71 	struct ia_css_binary *binary;
72 	const struct ia_css_fw_info *firmware;
73 	enum ia_css_pipeline_stage_sp_func sp_func;
74 	unsigned int max_input_width;
75 	unsigned int mode;
76 	struct ia_css_frame *in_frame;
77 	struct ia_css_frame *out_frame[IA_CSS_BINARY_MAX_OUTPUT_PORTS];
78 	struct ia_css_frame *vf_frame;
79 };
80 
81 /* @brief initialize the pipeline module
82  *
83  * @return    None
84  *
85  * Initializes the pipeline module. This API has to be called
86  * before any operation on the pipeline module is done
87  */
88 void ia_css_pipeline_init(void);
89 
90 /* @brief initialize the pipeline structure with default values
91  *
92  * @param[out] pipeline  structure to be initialized with defaults
93  * @param[in] pipe_id
94  * @param[in] pipe_num Number that uniquely identifies a pipeline.
95  * @return                     0 or error code upon error.
96  *
97  * Initializes the pipeline structure with a set of default values.
98  * This API is expected to be used when a pipeline structure is allocated
99  * externally and needs sane defaults
100  */
101 int ia_css_pipeline_create(
102     struct ia_css_pipeline *pipeline,
103     enum ia_css_pipe_id pipe_id,
104     unsigned int pipe_num,
105     unsigned int dvs_frame_delay);
106 
107 /* @brief destroy a pipeline
108  *
109  * @param[in] pipeline
110  * @return    None
111  *
112  */
113 void ia_css_pipeline_destroy(struct ia_css_pipeline *pipeline);
114 
115 /* @brief Starts a pipeline
116  *
117  * @param[in] pipe_id
118  * @param[in] pipeline
119  * @return    None
120  *
121  */
122 void ia_css_pipeline_start(enum ia_css_pipe_id pipe_id,
123 			   struct ia_css_pipeline *pipeline);
124 
125 /* @brief Request to stop a pipeline
126  *
127  * @param[in] pipeline
128  * @return                     0 or error code upon error.
129  *
130  */
131 int ia_css_pipeline_request_stop(struct ia_css_pipeline *pipeline);
132 
133 /* @brief Check whether pipeline has stopped
134  *
135  * @param[in] pipeline
136  * @return    true if the pipeline has stopped
137  *
138  */
139 bool ia_css_pipeline_has_stopped(struct ia_css_pipeline *pipe);
140 
141 /* @brief clean all the stages pipeline and make it as new
142  *
143  * @param[in] pipeline
144  * @return    None
145  *
146  */
147 void ia_css_pipeline_clean(struct ia_css_pipeline *pipeline);
148 
149 /* @brief Add a stage to pipeline.
150  *
151  * @param     pipeline               Pointer to the pipeline to be added to.
152  * @param[in] stage_desc       The description of the stage
153  * @param[out] stage            The successor of the stage.
154  * @return                     0 or error code upon error.
155  *
156  * Add a new stage to a non-NULL pipeline.
157  * The stage consists of an ISP binary or firmware and input and output
158  * arguments.
159 */
160 int ia_css_pipeline_create_and_add_stage(
161     struct ia_css_pipeline *pipeline,
162     struct ia_css_pipeline_stage_desc *stage_desc,
163     struct ia_css_pipeline_stage **stage);
164 
165 /* @brief Finalize the stages in a pipeline
166  *
167  * @param     pipeline               Pointer to the pipeline to be added to.
168  * @return                     None
169  *
170  * This API is expected to be called after adding all stages
171 */
172 void ia_css_pipeline_finalize_stages(struct ia_css_pipeline *pipeline,
173 				     bool continuous);
174 
175 /* @brief gets a stage from the pipeline
176  *
177  * @param[in] pipeline
178  * @return                     0 or error code upon error.
179  *
180  */
181 int ia_css_pipeline_get_stage(struct ia_css_pipeline *pipeline,
182 	int mode,
183 	struct ia_css_pipeline_stage **stage);
184 
185 /* @brief Gets a pipeline stage corresponding Firmware handle from the pipeline
186  *
187  * @param[in] pipeline
188  * @param[in] fw_handle
189  * @param[out] stage Pointer to Stage
190  *
191  * @return   0 or error code upon error.
192  *
193  */
194 int ia_css_pipeline_get_stage_from_fw(struct ia_css_pipeline
195 	*pipeline,
196 	u32 fw_handle,
197 	struct ia_css_pipeline_stage **stage);
198 
199 /* @brief Gets the Firmware handle corresponding the stage num from the pipeline
200  *
201  * @param[in] pipeline
202  * @param[in] stage_num
203  * @param[out] fw_handle
204  *
205  * @return   0 or error code upon error.
206  *
207  */
208 int ia_css_pipeline_get_fw_from_stage(struct ia_css_pipeline
209 	*pipeline,
210 	u32 stage_num,
211 	uint32_t *fw_handle);
212 
213 /* @brief gets the output stage from the pipeline
214  *
215  * @param[in] pipeline
216  * @return                     0 or error code upon error.
217  *
218  */
219 int ia_css_pipeline_get_output_stage(
220     struct ia_css_pipeline *pipeline,
221     int mode,
222     struct ia_css_pipeline_stage **stage);
223 
224 /* @brief Checks whether the pipeline uses params
225  *
226  * @param[in] pipeline
227  * @return    true if the pipeline uses params
228  *
229  */
230 bool ia_css_pipeline_uses_params(struct ia_css_pipeline *pipeline);
231 
232 /**
233  * @brief get the SP thread ID.
234  *
235  * @param[in]	key	The query key, typical use is pipe_num.
236  * @param[out]	val	The query value.
237  *
238  * @return
239  *	true, if the query succeeds;
240  *	false, if the query fails.
241  */
242 bool ia_css_pipeline_get_sp_thread_id(unsigned int key, unsigned int *val);
243 
244 #if defined(ISP2401)
245 /**
246  * @brief Get the pipeline io status
247  *
248  * @param[in] None
249  * @return
250  *	Pointer to pipe_io_status
251  */
252 struct sh_css_sp_pipeline_io_status *ia_css_pipeline_get_pipe_io_status(void);
253 #endif
254 
255 /**
256  * @brief Map an SP thread to this pipeline
257  *
258  * @param[in]	pipe_num
259  * @param[in]	map true for mapping and false for unmapping sp threads.
260  *
261  */
262 void ia_css_pipeline_map(unsigned int pipe_num, bool map);
263 
264 /**
265  * @brief Checks whether the pipeline is mapped to SP threads
266  *
267  * @param[in]	Query key, typical use is pipe_num
268  *
269  * return
270  *	true, pipeline is mapped to SP threads
271  *	false, pipeline is not mapped to SP threads
272  */
273 bool ia_css_pipeline_is_mapped(unsigned int key);
274 
275 /**
276  * @brief Print pipeline thread mapping
277  *
278  * @param[in]	none
279  *
280  * return none
281  */
282 void ia_css_pipeline_dump_thread_map_info(void);
283 
284 #endif /*__IA_CSS_PIPELINE_H__*/
285