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_BINARY_H_
17 #define _IA_CSS_BINARY_H_
18 
19 #include <type_support.h>
20 #include "ia_css_types.h"
21 #include "ia_css_err.h"
22 #include "ia_css_stream_format.h"
23 #include "ia_css_stream_public.h"
24 #include "ia_css_frame_public.h"
25 #include "sh_css_metrics.h"
26 #include "isp/kernels/fixedbds/fixedbds_1.0/ia_css_fixedbds_types.h"
27 
28 /* The binary mode is used in pre-processor expressions so we cannot
29  * use an enum here. */
30 #define IA_CSS_BINARY_MODE_COPY       0
31 #define IA_CSS_BINARY_MODE_PREVIEW    1
32 #define IA_CSS_BINARY_MODE_PRIMARY    2
33 #define IA_CSS_BINARY_MODE_VIDEO      3
34 #define IA_CSS_BINARY_MODE_PRE_ISP    4
35 #define IA_CSS_BINARY_MODE_GDC        5
36 #define IA_CSS_BINARY_MODE_POST_ISP   6
37 #define IA_CSS_BINARY_MODE_ANR        7
38 #define IA_CSS_BINARY_MODE_CAPTURE_PP 8
39 #define IA_CSS_BINARY_MODE_VF_PP      9
40 #define IA_CSS_BINARY_MODE_PRE_DE     10
41 #define IA_CSS_BINARY_MODE_PRIMARY_HQ_STAGE0    11
42 #define IA_CSS_BINARY_MODE_PRIMARY_HQ_STAGE1    12
43 #define IA_CSS_BINARY_MODE_PRIMARY_HQ_STAGE2    13
44 #define IA_CSS_BINARY_MODE_PRIMARY_HQ_STAGE3    14
45 #define IA_CSS_BINARY_MODE_PRIMARY_HQ_STAGE4    15
46 #define IA_CSS_BINARY_MODE_PRIMARY_HQ_STAGE5    16
47 #define IA_CSS_BINARY_NUM_MODES       17
48 
49 #define MAX_NUM_PRIMARY_STAGES 6
50 #define NUM_PRIMARY_HQ_STAGES  6  /* number of primary stages for ISP2.6.1 high quality pipe */
51 #define NUM_PRIMARY_STAGES     1  /* number of primary satges for ISP1/ISP2.2 pipe */
52 
53 /* Indicate where binaries can read input from */
54 #define IA_CSS_BINARY_INPUT_SENSOR   0
55 #define IA_CSS_BINARY_INPUT_MEMORY   1
56 #define IA_CSS_BINARY_INPUT_VARIABLE 2
57 
58 /* Should be included without the path.
59    However, that requires adding the path to numerous makefiles
60    that have nothing to do with isp parameters.
61  */
62 #include "runtime/isp_param/interface/ia_css_isp_param_types.h"
63 
64 /* now these ports only include output ports but not vf output ports */
65 enum {
66 	IA_CSS_BINARY_OUTPUT_PORT_0 = 0,
67 	IA_CSS_BINARY_OUTPUT_PORT_1 = 1,
68 	IA_CSS_BINARY_MAX_OUTPUT_PORTS = 2
69 };
70 
71 struct ia_css_cas_binary_descr {
72 	unsigned int num_stage;
73 	unsigned int num_output_stage;
74 	struct ia_css_frame_info *in_info;
75 	struct ia_css_frame_info *internal_out_info;
76 	struct ia_css_frame_info *out_info;
77 	struct ia_css_frame_info *vf_info;
78 	bool *is_output_stage;
79 };
80 
81 struct ia_css_binary_descr {
82 	int mode;
83 	bool online;
84 	bool continuous;
85 	bool striped;
86 	bool two_ppc;
87 	bool enable_yuv_ds;
88 	bool enable_high_speed;
89 	bool enable_dvs_6axis;
90 	bool enable_reduced_pipe;
91 	bool enable_dz;
92 	bool enable_xnr;
93 	bool enable_fractional_ds;
94 	bool enable_dpc;
95 
96 	/* ISP2401 */
97 	bool enable_tnr;
98 
99 	bool enable_capture_pp_bli;
100 	struct ia_css_resolution dvs_env;
101 	enum atomisp_input_format stream_format;
102 	struct ia_css_frame_info *in_info;		/* the info of the input-frame with the
103 							   ISP required resolution. */
104 	struct ia_css_frame_info *bds_out_info;
105 	struct ia_css_frame_info *out_info[IA_CSS_BINARY_MAX_OUTPUT_PORTS];
106 	struct ia_css_frame_info *vf_info;
107 	unsigned int isp_pipe_version;
108 	unsigned int required_bds_factor;
109 	int stream_config_left_padding;
110 };
111 
112 struct ia_css_binary {
113 	const struct ia_css_binary_xinfo *info;
114 	enum atomisp_input_format input_format;
115 	struct ia_css_frame_info in_frame_info;
116 	struct ia_css_frame_info internal_frame_info;
117 	struct ia_css_frame_info out_frame_info[IA_CSS_BINARY_MAX_OUTPUT_PORTS];
118 	struct ia_css_resolution effective_in_frame_res;
119 	struct ia_css_frame_info vf_frame_info;
120 	int                      input_buf_vectors;
121 	int                      deci_factor_log2;
122 	int                      vf_downscale_log2;
123 	int                      s3atbl_width;
124 	int                      s3atbl_height;
125 	int                      s3atbl_isp_width;
126 	int                      s3atbl_isp_height;
127 	unsigned int             morph_tbl_width;
128 	unsigned int             morph_tbl_aligned_width;
129 	unsigned int             morph_tbl_height;
130 	int                      sctbl_width_per_color;
131 	int                      sctbl_aligned_width_per_color;
132 	int                      sctbl_height;
133 	int                      sctbl_legacy_width_per_color;
134 	int                      sctbl_legacy_height;
135 	struct ia_css_sdis_info	 dis;
136 	struct ia_css_resolution dvs_envelope;
137 	bool                     online;
138 	unsigned int             uds_xc;
139 	unsigned int             uds_yc;
140 	unsigned int             left_padding;
141 	struct sh_css_binary_metrics metrics;
142 	struct ia_css_isp_param_host_segments mem_params;
143 	struct ia_css_isp_param_css_segments  css_params;
144 };
145 
146 #define IA_CSS_BINARY_DEFAULT_SETTINGS { \
147 	.input_format		= ATOMISP_INPUT_FORMAT_YUV420_8_LEGACY, \
148 	.in_frame_info		= IA_CSS_BINARY_DEFAULT_FRAME_INFO, \
149 	.internal_frame_info	= IA_CSS_BINARY_DEFAULT_FRAME_INFO, \
150 	.out_frame_info		= {IA_CSS_BINARY_DEFAULT_FRAME_INFO}, \
151 	.vf_frame_info		= IA_CSS_BINARY_DEFAULT_FRAME_INFO, \
152 }
153 
154 int
155 ia_css_binary_init_infos(void);
156 
157 int
158 ia_css_binary_uninit(void);
159 
160 int
161 ia_css_binary_fill_info(const struct ia_css_binary_xinfo *xinfo,
162 			bool online,
163 			bool two_ppc,
164 			enum atomisp_input_format stream_format,
165 			const struct ia_css_frame_info *in_info,
166 			const struct ia_css_frame_info *bds_out_info,
167 			const struct ia_css_frame_info *out_info[],
168 			const struct ia_css_frame_info *vf_info,
169 			struct ia_css_binary *binary,
170 			struct ia_css_resolution *dvs_env,
171 			int stream_config_left_padding,
172 			bool accelerator);
173 
174 int
175 ia_css_binary_find(struct ia_css_binary_descr *descr,
176 		   struct ia_css_binary *binary);
177 
178 /* @brief Get the shading information of the specified shading correction type.
179  *
180  * @param[in] binary: The isp binary which has the shading correction.
181  * @param[in] type: The shading correction type.
182  * @param[in] required_bds_factor: The bayer downscaling factor required in the pipe.
183  * @param[in] stream_config: The stream configuration.
184  * @param[out] shading_info: The shading information.
185  *		The shading information necessary as API is stored in the shading_info.
186  *		The driver needs to get this information to generate
187  *		the shading table directly required from ISP.
188  * @param[out] pipe_config: The pipe configuration.
189  *		The shading information related to ISP (but, not necessary as API) is stored in the pipe_config.
190  * @return	0 or error code upon error.
191  *
192  */
193 int
194 ia_css_binary_get_shading_info(const struct ia_css_binary *binary,
195 			       enum ia_css_shading_correction_type type,
196 			       unsigned int required_bds_factor,
197 			       const struct ia_css_stream_config *stream_config,
198 			       struct ia_css_shading_info *shading_info,
199 			       struct ia_css_pipe_config *pipe_config);
200 
201 int
202 ia_css_binary_3a_grid_info(const struct ia_css_binary *binary,
203 			   struct ia_css_grid_info *info,
204 			   struct ia_css_pipe *pipe);
205 
206 void
207 ia_css_binary_dvs_grid_info(const struct ia_css_binary *binary,
208 			    struct ia_css_grid_info *info,
209 			    struct ia_css_pipe *pipe);
210 
211 void
212 ia_css_binary_dvs_stat_grid_info(
213     const struct ia_css_binary *binary,
214     struct ia_css_grid_info *info,
215     struct ia_css_pipe *pipe);
216 
217 unsigned
218 ia_css_binary_max_vf_width(void);
219 
220 void
221 ia_css_binary_destroy_isp_parameters(struct ia_css_binary *binary);
222 
223 void
224 ia_css_binary_get_isp_binaries(struct ia_css_binary_xinfo **binaries,
225 			       uint32_t *num_isp_binaries);
226 
227 #endif /* _IA_CSS_BINARY_H_ */
228