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