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