1 // SPDX-License-Identifier: GPL-2.0
3 * Support for Intel Camera Imaging ISP subsystem.
4 * Copyright (c) 2015, Intel Corporation.
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.
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
16 #include "gdc_device.h" /* gdc_lut_store(), ... */
17 #include "isp.h" /* ISP_VEC_ELEMBITS */
19 #ifndef __INLINE_HMEM__
20 #define __INLINE_HMEM__
23 #define IA_CSS_INCLUDE_PARAMETERS
24 #define IA_CSS_INCLUDE_ACC_PARAMETERS
27 #include "sh_css_params.h"
28 #include "ia_css_queue.h"
29 #include "sw_event_global.h" /* Event IDs */
31 #include "platform_support.h"
32 #include "assert_support.h"
33 #include "misc_support.h" /* NOT_USED */
34 #include "math_support.h" /* max(), min() EVEN_FLOOR()*/
36 #include "ia_css_stream.h"
37 #include "sh_css_params_internal.h"
38 #include "sh_css_param_shading.h"
39 #include "sh_css_param_dvs.h"
40 #include "ia_css_refcount.h"
41 #include "sh_css_internal.h"
42 #include "ia_css_control.h"
43 #include "ia_css_shading.h"
44 #include "sh_css_defs.h"
45 #include "sh_css_sp.h"
46 #include "ia_css_pipeline.h"
47 #include "ia_css_debug.h"
49 #include "ia_css_isp_param.h"
50 #include "ia_css_isp_params.h"
51 #include "ia_css_mipi.h"
52 #include "ia_css_morph.h"
53 #include "ia_css_host_data.h"
54 #include "ia_css_pipe.h"
55 #include "ia_css_pipe_binarydesc.h"
57 /* Include all kernel host interfaces for ISP1 */
59 #include "anr/anr_1.0/ia_css_anr.host.h"
60 #include "cnr/cnr_1.0/ia_css_cnr.host.h"
61 #include "csc/csc_1.0/ia_css_csc.host.h"
62 #include "de/de_1.0/ia_css_de.host.h"
63 #include "dp/dp_1.0/ia_css_dp.host.h"
64 #include "bnr/bnr_1.0/ia_css_bnr.host.h"
65 #include "dvs/dvs_1.0/ia_css_dvs.host.h"
66 #include "fpn/fpn_1.0/ia_css_fpn.host.h"
67 #include "gc/gc_1.0/ia_css_gc.host.h"
68 #include "macc/macc_1.0/ia_css_macc.host.h"
69 #include "ctc/ctc_1.0/ia_css_ctc.host.h"
70 #include "ob/ob_1.0/ia_css_ob.host.h"
71 #include "raw/raw_1.0/ia_css_raw.host.h"
72 #include "fixedbds/fixedbds_1.0/ia_css_fixedbds_param.h"
73 #include "s3a/s3a_1.0/ia_css_s3a.host.h"
74 #include "sc/sc_1.0/ia_css_sc.host.h"
75 #include "sdis/sdis_1.0/ia_css_sdis.host.h"
76 #include "tnr/tnr_1.0/ia_css_tnr.host.h"
77 #include "uds/uds_1.0/ia_css_uds_param.h"
78 #include "wb/wb_1.0/ia_css_wb.host.h"
79 #include "ynr/ynr_1.0/ia_css_ynr.host.h"
80 #include "xnr/xnr_1.0/ia_css_xnr.host.h"
82 /* Include additional kernel host interfaces for ISP2 */
84 #include "aa/aa_2/ia_css_aa2.host.h"
85 #include "anr/anr_2/ia_css_anr2.host.h"
86 #include "bh/bh_2/ia_css_bh.host.h"
87 #include "cnr/cnr_2/ia_css_cnr2.host.h"
88 #include "ctc/ctc1_5/ia_css_ctc1_5.host.h"
89 #include "de/de_2/ia_css_de2.host.h"
90 #include "gc/gc_2/ia_css_gc2.host.h"
91 #include "sdis/sdis_2/ia_css_sdis2.host.h"
92 #include "ynr/ynr_2/ia_css_ynr2.host.h"
93 #include "fc/fc_1.0/ia_css_formats.host.h"
95 #include "xnr/xnr_3.0/ia_css_xnr3.host.h"
98 #include "sh_css_frac.h"
99 #include "ia_css_bufq.h"
101 #define FPNTBL_BYTES(binary) \
102 (sizeof(char) * (binary)->in_frame_info.res.height * \
103 (binary)->in_frame_info.padded_width)
105 #define SCTBL_BYTES(binary) \
106 (sizeof(unsigned short) * (binary)->sctbl_height * \
107 (binary)->sctbl_aligned_width_per_color * IA_CSS_SC_NUM_COLORS)
109 #define MORPH_PLANE_BYTES(binary) \
110 (SH_CSS_MORPH_TABLE_ELEM_BYTES * (binary)->morph_tbl_aligned_width * \
111 (binary)->morph_tbl_height)
113 /* We keep a second copy of the ptr struct for the SP to access.
114 Again, this would not be necessary on the chip. */
115 static ia_css_ptr sp_ddr_ptrs;
117 /* sp group address on DDR */
118 static ia_css_ptr xmem_sp_group_ptrs;
120 static ia_css_ptr xmem_sp_stage_ptrs[IA_CSS_PIPE_ID_NUM]
122 static ia_css_ptr xmem_isp_stage_ptrs[IA_CSS_PIPE_ID_NUM]
125 static ia_css_ptr default_gdc_lut;
126 static int interleaved_lut_temp[4][HRT_GDC_N];
128 /* END DO NOT MOVE INTO VIMALS_WORLD */
130 /* Digital Zoom lookup table. See documentation for more details about the
131 * contents of this table.
133 static const int zoom_table[4][HRT_GDC_N] = {
135 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4,
136 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4,
137 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4,
138 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4,
139 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4,
140 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4,
141 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4,
142 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4,
143 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4,
144 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4,
145 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4,
146 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4,
147 -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4,
148 -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4,
149 -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4,
150 -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4,
151 -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4,
152 -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4,
153 -2 << 4, -2 << 4, -2 << 4, -2 << 4, -2 << 4, -2 << 4, -2 << 4, -2 << 4,
154 -2 << 4, -2 << 4, -2 << 4, -2 << 4, -2 << 4, -2 << 4, -2 << 4, -2 << 4,
155 -2 << 4, -2 << 4, -2 << 4, -2 << 4, -2 << 4, -2 << 4, -2 << 4, -2 << 4,
156 -2 << 4, -2 << 4, -2 << 4, -2 << 4, -2 << 4, -2 << 4, -2 << 4, -2 << 4,
157 -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4,
158 -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4,
159 -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4,
160 -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4,
161 -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4,
162 -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4,
163 -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4,
164 -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4,
165 -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4,
166 -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4,
167 -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4,
168 -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4,
169 -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4,
170 -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4,
171 -7 << 4, -7 << 4, -7 << 4, -7 << 4, -7 << 4, -7 << 4, -7 << 4, -7 << 4,
172 -7 << 4, -7 << 4, -7 << 4, -7 << 4, -7 << 4, -7 << 4, -7 << 4, -7 << 4,
173 -7 << 4, -7 << 4, -7 << 4, -7 << 4, -7 << 4, -7 << 4, -7 << 4, -7 << 4,
174 -7 << 4, -7 << 4, -7 << 4, -7 << 4, -7 << 4, -7 << 4, -7 << 4, -7 << 4,
175 -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4,
176 -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4,
177 -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4,
178 -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4,
179 -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4,
180 -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4,
181 -10 << 4, -10 << 4, -10 << 4, -10 << 4, -10 << 4, -10 << 4, -10 << 4, -10 << 4,
182 -10 << 4, -10 << 4, -10 << 4, -10 << 4, -10 << 4, -10 << 4, -10 << 4, -10 << 4,
183 -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4,
184 -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4,
185 -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4,
186 -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4,
187 -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4,
188 -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4,
189 -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4,
190 -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4,
191 -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4,
192 -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4,
193 -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4,
194 -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4,
195 -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4,
196 -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4,
197 -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4,
198 -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4,
199 -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4,
200 -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4,
201 -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4,
202 -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4,
203 -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4,
204 -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4,
205 -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4,
206 -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4,
207 -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4,
208 -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4,
209 -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4,
210 -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4,
211 -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4,
212 -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4,
213 -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4,
214 -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4,
215 -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4,
216 -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4,
217 -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4,
218 -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4,
219 -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4,
220 -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4,
221 -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4,
222 -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4,
223 -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4,
224 -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4,
225 -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4,
226 -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4,
227 -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4,
228 -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4,
229 -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4,
230 -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4,
231 -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4,
232 -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4,
233 -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4,
234 -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4,
235 -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4,
236 -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4,
237 -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4,
238 -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4,
239 -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4,
240 -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4,
241 -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4,
242 -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4,
243 -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4,
244 -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4,
245 -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4,
246 -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4,
247 -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4,
248 -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4,
249 -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4,
250 -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4,
251 -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4,
252 -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4,
253 -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4,
254 -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4,
255 -7 << 4, -7 << 4, -7 << 4, -7 << 4, -7 << 4, -7 << 4, -7 << 4, -7 << 4,
256 -7 << 4, -7 << 4, -7 << 4, -7 << 4, -7 << 4, -7 << 4, -7 << 4, -7 << 4,
257 -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4,
258 -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4,
259 -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4,
260 -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4,
261 -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4,
262 -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4
265 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4,
266 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4,
267 2 << 4, 2 << 4, 2 << 4, 2 << 4, 2 << 4, 2 << 4, 2 << 4, 2 << 4,
268 2 << 4, 2 << 4, 2 << 4, 2 << 4, 2 << 4, 2 << 4, 2 << 4, 2 << 4,
269 4 << 4, 4 << 4, 4 << 4, 4 << 4, 4 << 4, 4 << 4, 4 << 4, 4 << 4,
270 4 << 4, 4 << 4, 4 << 4, 4 << 4, 4 << 4, 4 << 4, 4 << 4, 4 << 4,
271 7 << 4, 7 << 4, 7 << 4, 7 << 4, 7 << 4, 7 << 4, 7 << 4, 7 << 4,
272 7 << 4, 7 << 4, 7 << 4, 7 << 4, 7 << 4, 7 << 4, 7 << 4, 7 << 4,
273 9 << 4, 9 << 4, 9 << 4, 9 << 4, 9 << 4, 9 << 4, 9 << 4, 9 << 4,
274 9 << 4, 9 << 4, 9 << 4, 9 << 4, 9 << 4, 9 << 4, 9 << 4, 9 << 4,
275 12 << 4, 12 << 4, 12 << 4, 12 << 4, 12 << 4, 12 << 4, 12 << 4, 12 << 4,
276 12 << 4, 12 << 4, 12 << 4, 12 << 4, 12 << 4, 12 << 4, 12 << 4, 12 << 4,
277 16 << 4, 16 << 4, 16 << 4, 16 << 4, 16 << 4, 16 << 4, 16 << 4, 16 << 4,
278 16 << 4, 16 << 4, 16 << 4, 16 << 4, 16 << 4, 16 << 4, 16 << 4, 16 << 4,
279 19 << 4, 19 << 4, 19 << 4, 19 << 4, 19 << 4, 19 << 4, 19 << 4, 19 << 4,
280 19 << 4, 19 << 4, 19 << 4, 19 << 4, 19 << 4, 19 << 4, 19 << 4, 19 << 4,
281 23 << 4, 23 << 4, 23 << 4, 23 << 4, 23 << 4, 23 << 4, 23 << 4, 23 << 4,
282 23 << 4, 23 << 4, 23 << 4, 23 << 4, 23 << 4, 23 << 4, 23 << 4, 23 << 4,
283 27 << 4, 27 << 4, 27 << 4, 27 << 4, 27 << 4, 27 << 4, 27 << 4, 27 << 4,
284 27 << 4, 27 << 4, 27 << 4, 27 << 4, 27 << 4, 27 << 4, 27 << 4, 27 << 4,
285 31 << 4, 31 << 4, 31 << 4, 31 << 4, 31 << 4, 31 << 4, 31 << 4, 31 << 4,
286 31 << 4, 31 << 4, 31 << 4, 31 << 4, 31 << 4, 31 << 4, 31 << 4, 31 << 4,
287 35 << 4, 35 << 4, 35 << 4, 35 << 4, 35 << 4, 35 << 4, 35 << 4, 35 << 4,
288 35 << 4, 35 << 4, 35 << 4, 35 << 4, 35 << 4, 35 << 4, 35 << 4, 35 << 4,
289 39 << 4, 39 << 4, 39 << 4, 39 << 4, 39 << 4, 39 << 4, 39 << 4, 39 << 4,
290 39 << 4, 39 << 4, 39 << 4, 39 << 4, 39 << 4, 39 << 4, 39 << 4, 39 << 4,
291 43 << 4, 43 << 4, 43 << 4, 43 << 4, 43 << 4, 43 << 4, 43 << 4, 43 << 4,
292 43 << 4, 43 << 4, 43 << 4, 43 << 4, 43 << 4, 43 << 4, 43 << 4, 43 << 4,
293 48 << 4, 48 << 4, 48 << 4, 48 << 4, 48 << 4, 48 << 4, 48 << 4, 48 << 4,
294 48 << 4, 48 << 4, 48 << 4, 48 << 4, 48 << 4, 48 << 4, 48 << 4, 48 << 4,
295 53 << 4, 53 << 4, 53 << 4, 53 << 4, 53 << 4, 53 << 4, 53 << 4, 53 << 4,
296 53 << 4, 53 << 4, 53 << 4, 53 << 4, 53 << 4, 53 << 4, 53 << 4, 53 << 4,
297 58 << 4, 58 << 4, 58 << 4, 58 << 4, 58 << 4, 58 << 4, 58 << 4, 58 << 4,
298 58 << 4, 58 << 4, 58 << 4, 58 << 4, 58 << 4, 58 << 4, 58 << 4, 58 << 4,
299 62 << 4, 62 << 4, 62 << 4, 62 << 4, 62 << 4, 62 << 4, 62 << 4, 62 << 4,
300 62 << 4, 62 << 4, 62 << 4, 62 << 4, 62 << 4, 62 << 4, 62 << 4, 62 << 4,
301 67 << 4, 67 << 4, 67 << 4, 67 << 4, 67 << 4, 67 << 4, 67 << 4, 67 << 4,
302 67 << 4, 67 << 4, 67 << 4, 67 << 4, 67 << 4, 67 << 4, 67 << 4, 67 << 4,
303 73 << 4, 73 << 4, 73 << 4, 73 << 4, 73 << 4, 73 << 4, 73 << 4, 73 << 4,
304 73 << 4, 73 << 4, 73 << 4, 73 << 4, 73 << 4, 73 << 4, 73 << 4, 73 << 4,
305 78 << 4, 78 << 4, 78 << 4, 78 << 4, 78 << 4, 78 << 4, 78 << 4, 78 << 4,
306 78 << 4, 78 << 4, 78 << 4, 78 << 4, 78 << 4, 78 << 4, 78 << 4, 78 << 4,
307 83 << 4, 83 << 4, 83 << 4, 83 << 4, 83 << 4, 83 << 4, 83 << 4, 83 << 4,
308 83 << 4, 83 << 4, 83 << 4, 83 << 4, 83 << 4, 83 << 4, 83 << 4, 83 << 4,
309 88 << 4, 88 << 4, 88 << 4, 88 << 4, 88 << 4, 88 << 4, 88 << 4, 88 << 4,
310 88 << 4, 88 << 4, 88 << 4, 88 << 4, 88 << 4, 88 << 4, 88 << 4, 88 << 4,
311 94 << 4, 94 << 4, 94 << 4, 94 << 4, 94 << 4, 94 << 4, 94 << 4, 94 << 4,
312 94 << 4, 94 << 4, 94 << 4, 94 << 4, 94 << 4, 94 << 4, 94 << 4, 94 << 4,
313 99 << 4, 99 << 4, 99 << 4, 99 << 4, 99 << 4, 99 << 4, 99 << 4, 99 << 4,
314 99 << 4, 99 << 4, 99 << 4, 99 << 4, 99 << 4, 99 << 4, 99 << 4, 99 << 4,
315 105 << 4, 105 << 4, 105 << 4, 105 << 4, 105 << 4, 105 << 4, 105 << 4, 105 << 4,
316 105 << 4, 105 << 4, 105 << 4, 105 << 4, 105 << 4, 105 << 4, 105 << 4, 105 << 4,
317 110 << 4, 110 << 4, 110 << 4, 110 << 4, 110 << 4, 110 << 4, 110 << 4, 110 << 4,
318 110 << 4, 110 << 4, 110 << 4, 110 << 4, 110 << 4, 110 << 4, 110 << 4, 110 << 4,
319 116 << 4, 116 << 4, 116 << 4, 116 << 4, 116 << 4, 116 << 4, 116 << 4, 116 << 4,
320 116 << 4, 116 << 4, 116 << 4, 116 << 4, 116 << 4, 116 << 4, 116 << 4, 116 << 4,
321 121 << 4, 121 << 4, 121 << 4, 121 << 4, 121 << 4, 121 << 4, 121 << 4, 121 << 4,
322 121 << 4, 121 << 4, 121 << 4, 121 << 4, 121 << 4, 121 << 4, 121 << 4, 121 << 4,
323 127 << 4, 127 << 4, 127 << 4, 127 << 4, 127 << 4, 127 << 4, 127 << 4, 127 << 4,
324 127 << 4, 127 << 4, 127 << 4, 127 << 4, 127 << 4, 127 << 4, 127 << 4, 127 << 4,
325 132 << 4, 132 << 4, 132 << 4, 132 << 4, 132 << 4, 132 << 4, 132 << 4, 132 << 4,
326 132 << 4, 132 << 4, 132 << 4, 132 << 4, 132 << 4, 132 << 4, 132 << 4, 132 << 4,
327 138 << 4, 138 << 4, 138 << 4, 138 << 4, 138 << 4, 138 << 4, 138 << 4, 138 << 4,
328 138 << 4, 138 << 4, 138 << 4, 138 << 4, 138 << 4, 138 << 4, 138 << 4, 138 << 4,
329 144 << 4, 144 << 4, 144 << 4, 144 << 4, 144 << 4, 144 << 4, 144 << 4, 144 << 4,
330 144 << 4, 144 << 4, 144 << 4, 144 << 4, 144 << 4, 144 << 4, 144 << 4, 144 << 4,
331 149 << 4, 149 << 4, 149 << 4, 149 << 4, 149 << 4, 149 << 4, 149 << 4, 149 << 4,
332 149 << 4, 149 << 4, 149 << 4, 149 << 4, 149 << 4, 149 << 4, 149 << 4, 149 << 4,
333 154 << 4, 154 << 4, 154 << 4, 154 << 4, 154 << 4, 154 << 4, 154 << 4, 154 << 4,
334 154 << 4, 154 << 4, 154 << 4, 154 << 4, 154 << 4, 154 << 4, 154 << 4, 154 << 4,
335 160 << 4, 160 << 4, 160 << 4, 160 << 4, 160 << 4, 160 << 4, 160 << 4, 160 << 4,
336 160 << 4, 160 << 4, 160 << 4, 160 << 4, 160 << 4, 160 << 4, 160 << 4, 160 << 4,
337 165 << 4, 165 << 4, 165 << 4, 165 << 4, 165 << 4, 165 << 4, 165 << 4, 165 << 4,
338 165 << 4, 165 << 4, 165 << 4, 165 << 4, 165 << 4, 165 << 4, 165 << 4, 165 << 4,
339 170 << 4, 170 << 4, 170 << 4, 170 << 4, 170 << 4, 170 << 4, 170 << 4, 170 << 4,
340 170 << 4, 170 << 4, 170 << 4, 170 << 4, 170 << 4, 170 << 4, 170 << 4, 170 << 4,
341 176 << 4, 176 << 4, 176 << 4, 176 << 4, 176 << 4, 176 << 4, 176 << 4, 176 << 4,
342 176 << 4, 176 << 4, 176 << 4, 176 << 4, 176 << 4, 176 << 4, 176 << 4, 176 << 4,
343 181 << 4, 181 << 4, 181 << 4, 181 << 4, 181 << 4, 181 << 4, 181 << 4, 181 << 4,
344 181 << 4, 181 << 4, 181 << 4, 181 << 4, 181 << 4, 181 << 4, 181 << 4, 181 << 4,
345 186 << 4, 186 << 4, 186 << 4, 186 << 4, 186 << 4, 186 << 4, 186 << 4, 186 << 4,
346 186 << 4, 186 << 4, 186 << 4, 186 << 4, 186 << 4, 186 << 4, 186 << 4, 186 << 4,
347 191 << 4, 191 << 4, 191 << 4, 191 << 4, 191 << 4, 191 << 4, 191 << 4, 191 << 4,
348 191 << 4, 191 << 4, 191 << 4, 191 << 4, 191 << 4, 191 << 4, 191 << 4, 191 << 4,
349 195 << 4, 195 << 4, 195 << 4, 195 << 4, 195 << 4, 195 << 4, 195 << 4, 195 << 4,
350 195 << 4, 195 << 4, 195 << 4, 195 << 4, 195 << 4, 195 << 4, 195 << 4, 195 << 4,
351 200 << 4, 200 << 4, 200 << 4, 200 << 4, 200 << 4, 200 << 4, 200 << 4, 200 << 4,
352 200 << 4, 200 << 4, 200 << 4, 200 << 4, 200 << 4, 200 << 4, 200 << 4, 200 << 4,
353 205 << 4, 205 << 4, 205 << 4, 205 << 4, 205 << 4, 205 << 4, 205 << 4, 205 << 4,
354 205 << 4, 205 << 4, 205 << 4, 205 << 4, 205 << 4, 205 << 4, 205 << 4, 205 << 4,
355 209 << 4, 209 << 4, 209 << 4, 209 << 4, 209 << 4, 209 << 4, 209 << 4, 209 << 4,
356 209 << 4, 209 << 4, 209 << 4, 209 << 4, 209 << 4, 209 << 4, 209 << 4, 209 << 4,
357 213 << 4, 213 << 4, 213 << 4, 213 << 4, 213 << 4, 213 << 4, 213 << 4, 213 << 4,
358 213 << 4, 213 << 4, 213 << 4, 213 << 4, 213 << 4, 213 << 4, 213 << 4, 213 << 4,
359 218 << 4, 218 << 4, 218 << 4, 218 << 4, 218 << 4, 218 << 4, 218 << 4, 218 << 4,
360 218 << 4, 218 << 4, 218 << 4, 218 << 4, 218 << 4, 218 << 4, 218 << 4, 218 << 4,
361 222 << 4, 222 << 4, 222 << 4, 222 << 4, 222 << 4, 222 << 4, 222 << 4, 222 << 4,
362 222 << 4, 222 << 4, 222 << 4, 222 << 4, 222 << 4, 222 << 4, 222 << 4, 222 << 4,
363 225 << 4, 225 << 4, 225 << 4, 225 << 4, 225 << 4, 225 << 4, 225 << 4, 225 << 4,
364 225 << 4, 225 << 4, 225 << 4, 225 << 4, 225 << 4, 225 << 4, 225 << 4, 225 << 4,
365 229 << 4, 229 << 4, 229 << 4, 229 << 4, 229 << 4, 229 << 4, 229 << 4, 229 << 4,
366 229 << 4, 229 << 4, 229 << 4, 229 << 4, 229 << 4, 229 << 4, 229 << 4, 229 << 4,
367 232 << 4, 232 << 4, 232 << 4, 232 << 4, 232 << 4, 232 << 4, 232 << 4, 232 << 4,
368 232 << 4, 232 << 4, 232 << 4, 232 << 4, 232 << 4, 232 << 4, 232 << 4, 232 << 4,
369 236 << 4, 236 << 4, 236 << 4, 236 << 4, 236 << 4, 236 << 4, 236 << 4, 236 << 4,
370 236 << 4, 236 << 4, 236 << 4, 236 << 4, 236 << 4, 236 << 4, 236 << 4, 236 << 4,
371 239 << 4, 239 << 4, 239 << 4, 239 << 4, 239 << 4, 239 << 4, 239 << 4, 239 << 4,
372 239 << 4, 239 << 4, 239 << 4, 239 << 4, 239 << 4, 239 << 4, 239 << 4, 239 << 4,
373 241 << 4, 241 << 4, 241 << 4, 241 << 4, 241 << 4, 241 << 4, 241 << 4, 241 << 4,
374 241 << 4, 241 << 4, 241 << 4, 241 << 4, 241 << 4, 241 << 4, 241 << 4, 241 << 4,
375 244 << 4, 244 << 4, 244 << 4, 244 << 4, 244 << 4, 244 << 4, 244 << 4, 244 << 4,
376 244 << 4, 244 << 4, 244 << 4, 244 << 4, 244 << 4, 244 << 4, 244 << 4, 244 << 4,
377 246 << 4, 246 << 4, 246 << 4, 246 << 4, 246 << 4, 246 << 4, 246 << 4, 246 << 4,
378 246 << 4, 246 << 4, 246 << 4, 246 << 4, 246 << 4, 246 << 4, 246 << 4, 246 << 4,
379 248 << 4, 248 << 4, 248 << 4, 248 << 4, 248 << 4, 248 << 4, 248 << 4, 248 << 4,
380 248 << 4, 248 << 4, 248 << 4, 248 << 4, 248 << 4, 248 << 4, 248 << 4, 248 << 4,
381 250 << 4, 250 << 4, 250 << 4, 250 << 4, 250 << 4, 250 << 4, 250 << 4, 250 << 4,
382 250 << 4, 250 << 4, 250 << 4, 250 << 4, 250 << 4, 250 << 4, 250 << 4, 250 << 4,
383 252 << 4, 252 << 4, 252 << 4, 252 << 4, 252 << 4, 252 << 4, 252 << 4, 252 << 4,
384 252 << 4, 252 << 4, 252 << 4, 252 << 4, 252 << 4, 252 << 4, 252 << 4, 252 << 4,
385 253 << 4, 253 << 4, 253 << 4, 253 << 4, 253 << 4, 253 << 4, 253 << 4, 253 << 4,
386 253 << 4, 253 << 4, 253 << 4, 253 << 4, 253 << 4, 253 << 4, 253 << 4, 253 << 4,
387 254 << 4, 254 << 4, 254 << 4, 254 << 4, 254 << 4, 254 << 4, 254 << 4, 254 << 4,
388 254 << 4, 254 << 4, 254 << 4, 254 << 4, 254 << 4, 254 << 4, 254 << 4, 254 << 4,
389 255 << 4, 255 << 4, 255 << 4, 255 << 4, 255 << 4, 255 << 4, 255 << 4, 255 << 4,
390 255 << 4, 255 << 4, 255 << 4, 255 << 4, 255 << 4, 255 << 4, 255 << 4, 255 << 4,
391 255 << 4, 255 << 4, 255 << 4, 255 << 4, 255 << 4, 255 << 4, 255 << 4, 255 << 4,
392 255 << 4, 255 << 4, 255 << 4, 255 << 4, 255 << 4, 255 << 4, 255 << 4, 255 << 4
395 256 << 4, 256 << 4, 256 << 4, 256 << 4, 256 << 4, 256 << 4, 256 << 4, 256 << 4,
396 256 << 4, 256 << 4, 256 << 4, 256 << 4, 256 << 4, 256 << 4, 256 << 4, 256 << 4,
397 255 << 4, 255 << 4, 255 << 4, 255 << 4, 255 << 4, 255 << 4, 255 << 4, 255 << 4,
398 255 << 4, 255 << 4, 255 << 4, 255 << 4, 255 << 4, 255 << 4, 255 << 4, 255 << 4,
399 255 << 4, 255 << 4, 255 << 4, 255 << 4, 255 << 4, 255 << 4, 255 << 4, 255 << 4,
400 255 << 4, 255 << 4, 255 << 4, 255 << 4, 255 << 4, 255 << 4, 255 << 4, 255 << 4,
401 254 << 4, 254 << 4, 254 << 4, 254 << 4, 254 << 4, 254 << 4, 254 << 4, 254 << 4,
402 254 << 4, 254 << 4, 254 << 4, 254 << 4, 254 << 4, 254 << 4, 254 << 4, 254 << 4,
403 253 << 4, 253 << 4, 253 << 4, 253 << 4, 253 << 4, 253 << 4, 253 << 4, 253 << 4,
404 253 << 4, 253 << 4, 253 << 4, 253 << 4, 253 << 4, 253 << 4, 253 << 4, 253 << 4,
405 252 << 4, 252 << 4, 252 << 4, 252 << 4, 252 << 4, 252 << 4, 252 << 4, 252 << 4,
406 252 << 4, 252 << 4, 252 << 4, 252 << 4, 252 << 4, 252 << 4, 252 << 4, 252 << 4,
407 250 << 4, 250 << 4, 250 << 4, 250 << 4, 250 << 4, 250 << 4, 250 << 4, 250 << 4,
408 250 << 4, 250 << 4, 250 << 4, 250 << 4, 250 << 4, 250 << 4, 250 << 4, 250 << 4,
409 248 << 4, 248 << 4, 248 << 4, 248 << 4, 248 << 4, 248 << 4, 248 << 4, 248 << 4,
410 248 << 4, 248 << 4, 248 << 4, 248 << 4, 248 << 4, 248 << 4, 248 << 4, 248 << 4,
411 246 << 4, 246 << 4, 246 << 4, 246 << 4, 246 << 4, 246 << 4, 246 << 4, 246 << 4,
412 246 << 4, 246 << 4, 246 << 4, 246 << 4, 246 << 4, 246 << 4, 246 << 4, 246 << 4,
413 244 << 4, 244 << 4, 244 << 4, 244 << 4, 244 << 4, 244 << 4, 244 << 4, 244 << 4,
414 244 << 4, 244 << 4, 244 << 4, 244 << 4, 244 << 4, 244 << 4, 244 << 4, 244 << 4,
415 241 << 4, 241 << 4, 241 << 4, 241 << 4, 241 << 4, 241 << 4, 241 << 4, 241 << 4,
416 241 << 4, 241 << 4, 241 << 4, 241 << 4, 241 << 4, 241 << 4, 241 << 4, 241 << 4,
417 239 << 4, 239 << 4, 239 << 4, 239 << 4, 239 << 4, 239 << 4, 239 << 4, 239 << 4,
418 239 << 4, 239 << 4, 239 << 4, 239 << 4, 239 << 4, 239 << 4, 239 << 4, 239 << 4,
419 236 << 4, 236 << 4, 236 << 4, 236 << 4, 236 << 4, 236 << 4, 236 << 4, 236 << 4,
420 236 << 4, 236 << 4, 236 << 4, 236 << 4, 236 << 4, 236 << 4, 236 << 4, 236 << 4,
421 232 << 4, 232 << 4, 232 << 4, 232 << 4, 232 << 4, 232 << 4, 232 << 4, 232 << 4,
422 232 << 4, 232 << 4, 232 << 4, 232 << 4, 232 << 4, 232 << 4, 232 << 4, 232 << 4,
423 229 << 4, 229 << 4, 229 << 4, 229 << 4, 229 << 4, 229 << 4, 229 << 4, 229 << 4,
424 229 << 4, 229 << 4, 229 << 4, 229 << 4, 229 << 4, 229 << 4, 229 << 4, 229 << 4,
425 225 << 4, 225 << 4, 225 << 4, 225 << 4, 225 << 4, 225 << 4, 225 << 4, 225 << 4,
426 225 << 4, 225 << 4, 225 << 4, 225 << 4, 225 << 4, 225 << 4, 225 << 4, 225 << 4,
427 222 << 4, 222 << 4, 222 << 4, 222 << 4, 222 << 4, 222 << 4, 222 << 4, 222 << 4,
428 222 << 4, 222 << 4, 222 << 4, 222 << 4, 222 << 4, 222 << 4, 222 << 4, 222 << 4,
429 218 << 4, 218 << 4, 218 << 4, 218 << 4, 218 << 4, 218 << 4, 218 << 4, 218 << 4,
430 218 << 4, 218 << 4, 218 << 4, 218 << 4, 218 << 4, 218 << 4, 218 << 4, 218 << 4,
431 213 << 4, 213 << 4, 213 << 4, 213 << 4, 213 << 4, 213 << 4, 213 << 4, 213 << 4,
432 213 << 4, 213 << 4, 213 << 4, 213 << 4, 213 << 4, 213 << 4, 213 << 4, 213 << 4,
433 209 << 4, 209 << 4, 209 << 4, 209 << 4, 209 << 4, 209 << 4, 209 << 4, 209 << 4,
434 209 << 4, 209 << 4, 209 << 4, 209 << 4, 209 << 4, 209 << 4, 209 << 4, 209 << 4,
435 205 << 4, 205 << 4, 205 << 4, 205 << 4, 205 << 4, 205 << 4, 205 << 4, 205 << 4,
436 205 << 4, 205 << 4, 205 << 4, 205 << 4, 205 << 4, 205 << 4, 205 << 4, 205 << 4,
437 200 << 4, 200 << 4, 200 << 4, 200 << 4, 200 << 4, 200 << 4, 200 << 4, 200 << 4,
438 200 << 4, 200 << 4, 200 << 4, 200 << 4, 200 << 4, 200 << 4, 200 << 4, 200 << 4,
439 195 << 4, 195 << 4, 195 << 4, 195 << 4, 195 << 4, 195 << 4, 195 << 4, 195 << 4,
440 195 << 4, 195 << 4, 195 << 4, 195 << 4, 195 << 4, 195 << 4, 195 << 4, 195 << 4,
441 191 << 4, 191 << 4, 191 << 4, 191 << 4, 191 << 4, 191 << 4, 191 << 4, 191 << 4,
442 191 << 4, 191 << 4, 191 << 4, 191 << 4, 191 << 4, 191 << 4, 191 << 4, 191 << 4,
443 186 << 4, 186 << 4, 186 << 4, 186 << 4, 186 << 4, 186 << 4, 186 << 4, 186 << 4,
444 186 << 4, 186 << 4, 186 << 4, 186 << 4, 186 << 4, 186 << 4, 186 << 4, 186 << 4,
445 181 << 4, 181 << 4, 181 << 4, 181 << 4, 181 << 4, 181 << 4, 181 << 4, 181 << 4,
446 181 << 4, 181 << 4, 181 << 4, 181 << 4, 181 << 4, 181 << 4, 181 << 4, 181 << 4,
447 176 << 4, 176 << 4, 176 << 4, 176 << 4, 176 << 4, 176 << 4, 176 << 4, 176 << 4,
448 176 << 4, 176 << 4, 176 << 4, 176 << 4, 176 << 4, 176 << 4, 176 << 4, 176 << 4,
449 170 << 4, 170 << 4, 170 << 4, 170 << 4, 170 << 4, 170 << 4, 170 << 4, 170 << 4,
450 170 << 4, 170 << 4, 170 << 4, 170 << 4, 170 << 4, 170 << 4, 170 << 4, 170 << 4,
451 165 << 4, 165 << 4, 165 << 4, 165 << 4, 165 << 4, 165 << 4, 165 << 4, 165 << 4,
452 165 << 4, 165 << 4, 165 << 4, 165 << 4, 165 << 4, 165 << 4, 165 << 4, 165 << 4,
453 160 << 4, 160 << 4, 160 << 4, 160 << 4, 160 << 4, 160 << 4, 160 << 4, 160 << 4,
454 160 << 4, 160 << 4, 160 << 4, 160 << 4, 160 << 4, 160 << 4, 160 << 4, 160 << 4,
455 154 << 4, 154 << 4, 154 << 4, 154 << 4, 154 << 4, 154 << 4, 154 << 4, 154 << 4,
456 154 << 4, 154 << 4, 154 << 4, 154 << 4, 154 << 4, 154 << 4, 154 << 4, 154 << 4,
457 149 << 4, 149 << 4, 149 << 4, 149 << 4, 149 << 4, 149 << 4, 149 << 4, 149 << 4,
458 149 << 4, 149 << 4, 149 << 4, 149 << 4, 149 << 4, 149 << 4, 149 << 4, 149 << 4,
459 144 << 4, 144 << 4, 144 << 4, 144 << 4, 144 << 4, 144 << 4, 144 << 4, 144 << 4,
460 144 << 4, 144 << 4, 144 << 4, 144 << 4, 144 << 4, 144 << 4, 144 << 4, 144 << 4,
461 138 << 4, 138 << 4, 138 << 4, 138 << 4, 138 << 4, 138 << 4, 138 << 4, 138 << 4,
462 138 << 4, 138 << 4, 138 << 4, 138 << 4, 138 << 4, 138 << 4, 138 << 4, 138 << 4,
463 132 << 4, 132 << 4, 132 << 4, 132 << 4, 132 << 4, 132 << 4, 132 << 4, 132 << 4,
464 132 << 4, 132 << 4, 132 << 4, 132 << 4, 132 << 4, 132 << 4, 132 << 4, 132 << 4,
465 127 << 4, 127 << 4, 127 << 4, 127 << 4, 127 << 4, 127 << 4, 127 << 4, 127 << 4,
466 127 << 4, 127 << 4, 127 << 4, 127 << 4, 127 << 4, 127 << 4, 127 << 4, 127 << 4,
467 121 << 4, 121 << 4, 121 << 4, 121 << 4, 121 << 4, 121 << 4, 121 << 4, 121 << 4,
468 121 << 4, 121 << 4, 121 << 4, 121 << 4, 121 << 4, 121 << 4, 121 << 4, 121 << 4,
469 116 << 4, 116 << 4, 116 << 4, 116 << 4, 116 << 4, 116 << 4, 116 << 4, 116 << 4,
470 116 << 4, 116 << 4, 116 << 4, 116 << 4, 116 << 4, 116 << 4, 116 << 4, 116 << 4,
471 110 << 4, 110 << 4, 110 << 4, 110 << 4, 110 << 4, 110 << 4, 110 << 4, 110 << 4,
472 110 << 4, 110 << 4, 110 << 4, 110 << 4, 110 << 4, 110 << 4, 110 << 4, 110 << 4,
473 105 << 4, 105 << 4, 105 << 4, 105 << 4, 105 << 4, 105 << 4, 105 << 4, 105 << 4,
474 105 << 4, 105 << 4, 105 << 4, 105 << 4, 105 << 4, 105 << 4, 105 << 4, 105 << 4,
475 99 << 4, 99 << 4, 99 << 4, 99 << 4, 99 << 4, 99 << 4, 99 << 4, 99 << 4,
476 99 << 4, 99 << 4, 99 << 4, 99 << 4, 99 << 4, 99 << 4, 99 << 4, 99 << 4,
477 94 << 4, 94 << 4, 94 << 4, 94 << 4, 94 << 4, 94 << 4, 94 << 4, 94 << 4,
478 94 << 4, 94 << 4, 94 << 4, 94 << 4, 94 << 4, 94 << 4, 94 << 4, 94 << 4,
479 88 << 4, 88 << 4, 88 << 4, 88 << 4, 88 << 4, 88 << 4, 88 << 4, 88 << 4,
480 88 << 4, 88 << 4, 88 << 4, 88 << 4, 88 << 4, 88 << 4, 88 << 4, 88 << 4,
481 83 << 4, 83 << 4, 83 << 4, 83 << 4, 83 << 4, 83 << 4, 83 << 4, 83 << 4,
482 83 << 4, 83 << 4, 83 << 4, 83 << 4, 83 << 4, 83 << 4, 83 << 4, 83 << 4,
483 78 << 4, 78 << 4, 78 << 4, 78 << 4, 78 << 4, 78 << 4, 78 << 4, 78 << 4,
484 78 << 4, 78 << 4, 78 << 4, 78 << 4, 78 << 4, 78 << 4, 78 << 4, 78 << 4,
485 73 << 4, 73 << 4, 73 << 4, 73 << 4, 73 << 4, 73 << 4, 73 << 4, 73 << 4,
486 73 << 4, 73 << 4, 73 << 4, 73 << 4, 73 << 4, 73 << 4, 73 << 4, 73 << 4,
487 67 << 4, 67 << 4, 67 << 4, 67 << 4, 67 << 4, 67 << 4, 67 << 4, 67 << 4,
488 67 << 4, 67 << 4, 67 << 4, 67 << 4, 67 << 4, 67 << 4, 67 << 4, 67 << 4,
489 62 << 4, 62 << 4, 62 << 4, 62 << 4, 62 << 4, 62 << 4, 62 << 4, 62 << 4,
490 62 << 4, 62 << 4, 62 << 4, 62 << 4, 62 << 4, 62 << 4, 62 << 4, 62 << 4,
491 58 << 4, 58 << 4, 58 << 4, 58 << 4, 58 << 4, 58 << 4, 58 << 4, 58 << 4,
492 58 << 4, 58 << 4, 58 << 4, 58 << 4, 58 << 4, 58 << 4, 58 << 4, 58 << 4,
493 53 << 4, 53 << 4, 53 << 4, 53 << 4, 53 << 4, 53 << 4, 53 << 4, 53 << 4,
494 53 << 4, 53 << 4, 53 << 4, 53 << 4, 53 << 4, 53 << 4, 53 << 4, 53 << 4,
495 48 << 4, 48 << 4, 48 << 4, 48 << 4, 48 << 4, 48 << 4, 48 << 4, 48 << 4,
496 48 << 4, 48 << 4, 48 << 4, 48 << 4, 48 << 4, 48 << 4, 48 << 4, 48 << 4,
497 43 << 4, 43 << 4, 43 << 4, 43 << 4, 43 << 4, 43 << 4, 43 << 4, 43 << 4,
498 43 << 4, 43 << 4, 43 << 4, 43 << 4, 43 << 4, 43 << 4, 43 << 4, 43 << 4,
499 39 << 4, 39 << 4, 39 << 4, 39 << 4, 39 << 4, 39 << 4, 39 << 4, 39 << 4,
500 39 << 4, 39 << 4, 39 << 4, 39 << 4, 39 << 4, 39 << 4, 39 << 4, 39 << 4,
501 35 << 4, 35 << 4, 35 << 4, 35 << 4, 35 << 4, 35 << 4, 35 << 4, 35 << 4,
502 35 << 4, 35 << 4, 35 << 4, 35 << 4, 35 << 4, 35 << 4, 35 << 4, 35 << 4,
503 31 << 4, 31 << 4, 31 << 4, 31 << 4, 31 << 4, 31 << 4, 31 << 4, 31 << 4,
504 31 << 4, 31 << 4, 31 << 4, 31 << 4, 31 << 4, 31 << 4, 31 << 4, 31 << 4,
505 27 << 4, 27 << 4, 27 << 4, 27 << 4, 27 << 4, 27 << 4, 27 << 4, 27 << 4,
506 27 << 4, 27 << 4, 27 << 4, 27 << 4, 27 << 4, 27 << 4, 27 << 4, 27 << 4,
507 23 << 4, 23 << 4, 23 << 4, 23 << 4, 23 << 4, 23 << 4, 23 << 4, 23 << 4,
508 23 << 4, 23 << 4, 23 << 4, 23 << 4, 23 << 4, 23 << 4, 23 << 4, 23 << 4,
509 19 << 4, 19 << 4, 19 << 4, 19 << 4, 19 << 4, 19 << 4, 19 << 4, 19 << 4,
510 19 << 4, 19 << 4, 19 << 4, 19 << 4, 19 << 4, 19 << 4, 19 << 4, 19 << 4,
511 16 << 4, 16 << 4, 16 << 4, 16 << 4, 16 << 4, 16 << 4, 16 << 4, 16 << 4,
512 16 << 4, 16 << 4, 16 << 4, 16 << 4, 16 << 4, 16 << 4, 16 << 4, 16 << 4,
513 12 << 4, 12 << 4, 12 << 4, 12 << 4, 12 << 4, 12 << 4, 12 << 4, 12 << 4,
514 12 << 4, 12 << 4, 12 << 4, 12 << 4, 12 << 4, 12 << 4, 12 << 4, 12 << 4,
515 9 << 4, 9 << 4, 9 << 4, 9 << 4, 9 << 4, 9 << 4, 9 << 4, 9 << 4,
516 9 << 4, 9 << 4, 9 << 4, 9 << 4, 9 << 4, 9 << 4, 9 << 4, 9 << 4,
517 7 << 4, 7 << 4, 7 << 4, 7 << 4, 7 << 4, 7 << 4, 7 << 4, 7 << 4,
518 7 << 4, 7 << 4, 7 << 4, 7 << 4, 7 << 4, 7 << 4, 7 << 4, 7 << 4,
519 4 << 4, 4 << 4, 4 << 4, 4 << 4, 4 << 4, 4 << 4, 4 << 4, 4 << 4,
520 4 << 4, 4 << 4, 4 << 4, 4 << 4, 4 << 4, 4 << 4, 4 << 4, 4 << 4,
521 2 << 4, 2 << 4, 2 << 4, 2 << 4, 2 << 4, 2 << 4, 2 << 4, 2 << 4,
522 2 << 4, 2 << 4, 2 << 4, 2 << 4, 2 << 4, 2 << 4, 2 << 4, 2 << 4
525 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4,
526 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4,
527 -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4,
528 -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4,
529 -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4,
530 -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4,
531 -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4,
532 -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4,
533 -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4,
534 -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4,
535 -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4,
536 -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4,
537 -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4,
538 -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4,
539 -10 << 4, -10 << 4, -10 << 4, -10 << 4, -10 << 4, -10 << 4, -10 << 4, -10 << 4,
540 -10 << 4, -10 << 4, -10 << 4, -10 << 4, -10 << 4, -10 << 4, -10 << 4, -10 << 4,
541 -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4,
542 -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4,
543 -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4,
544 -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4,
545 -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4,
546 -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4,
547 -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4,
548 -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4,
549 -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4,
550 -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4,
551 -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4,
552 -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4,
553 -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4,
554 -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4,
555 -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4,
556 -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4,
557 -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4,
558 -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4,
559 -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4,
560 -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4,
561 -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4,
562 -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4,
563 -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4,
564 -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4,
565 -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4,
566 -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4,
567 -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4,
568 -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4,
569 -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4,
570 -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4,
571 -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4,
572 -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4,
573 -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4,
574 -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4,
575 -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4,
576 -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4,
577 -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4,
578 -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4,
579 -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4,
580 -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4,
581 -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4,
582 -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4,
583 -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4,
584 -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4,
585 -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4,
586 -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4,
587 -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4,
588 -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4,
589 -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4,
590 -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4,
591 -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4,
592 -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4,
593 -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4,
594 -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4,
595 -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4,
596 -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4,
597 -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4,
598 -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4,
599 -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4,
600 -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4,
601 -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4,
602 -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4,
603 -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4,
604 -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4,
605 -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4,
606 -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4,
607 -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4,
608 -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4,
609 -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4,
610 -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4,
611 -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4,
612 -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4,
613 -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4,
614 -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4,
615 -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4,
616 -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4,
617 -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4,
618 -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4,
619 -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4,
620 -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4,
621 -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4,
622 -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4,
623 -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4,
624 -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4,
625 -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4,
626 -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4,
627 -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4,
628 -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4,
629 -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4,
630 -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4,
631 -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4,
632 -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4,
633 -2 << 4, -2 << 4, -2 << 4, -2 << 4, -2 << 4, -2 << 4, -2 << 4, -2 << 4,
634 -2 << 4, -2 << 4, -2 << 4, -2 << 4, -2 << 4, -2 << 4, -2 << 4, -2 << 4,
635 -2 << 4, -2 << 4, -2 << 4, -2 << 4, -2 << 4, -2 << 4, -2 << 4, -2 << 4,
636 -2 << 4, -2 << 4, -2 << 4, -2 << 4, -2 << 4, -2 << 4, -2 << 4, -2 << 4,
637 -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4,
638 -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4,
639 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4,
640 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4,
641 -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4,
642 -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4,
643 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4,
644 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4,
645 1 << 4, 1 << 4, 1 << 4, 1 << 4, 1 << 4, 1 << 4, 1 << 4, 1 << 4,
646 1 << 4, 1 << 4, 1 << 4, 1 << 4, 1 << 4, 1 << 4, 1 << 4, 1 << 4,
647 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4,
648 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4,
649 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4,
650 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4,
651 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4,
652 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4
656 static const struct ia_css_dz_config default_dz_config = {
666 static const struct ia_css_vector default_motion_config = {
671 /* ------ deprecated(bz675) : from ------ */
672 static const struct ia_css_shading_settings default_shading_settings = {
673 1 /* enable shading table conversion in the css
674 (This matches the legacy way.) */
677 /* ------ deprecated(bz675) : to ------ */
679 struct ia_css_isp_skc_dvs_statistics {
684 ref_sh_css_ddr_address_map(
685 struct sh_css_ddr_address_map *map,
686 struct sh_css_ddr_address_map *out);
689 write_ia_css_isp_parameter_set_info_to_ddr(
690 struct ia_css_isp_parameter_set_info *me,
694 free_ia_css_isp_parameter_set_info(ia_css_ptr ptr);
697 sh_css_params_write_to_ddr_internal(
698 struct ia_css_pipe *pipe,
699 unsigned int pipe_id,
700 struct ia_css_isp_parameters *params,
701 const struct ia_css_pipeline_stage *stage,
702 struct sh_css_ddr_address_map *ddr_map,
703 struct sh_css_ddr_address_map_size *ddr_map_size);
706 sh_css_create_isp_params(struct ia_css_stream *stream,
707 struct ia_css_isp_parameters **isp_params_out);
710 sh_css_init_isp_params_from_global(struct ia_css_stream *stream,
711 struct ia_css_isp_parameters *params,
712 bool use_default_config,
713 struct ia_css_pipe *pipe_in);
716 sh_css_init_isp_params_from_config(struct ia_css_pipe *pipe,
717 struct ia_css_isp_parameters *params,
718 const struct ia_css_isp_config *config,
719 struct ia_css_pipe *pipe_in);
722 sh_css_set_global_isp_config_on_pipe(
723 struct ia_css_pipe *curr_pipe,
724 const struct ia_css_isp_config *config,
725 struct ia_css_pipe *pipe);
728 sh_css_set_per_frame_isp_config_on_pipe(
729 struct ia_css_stream *stream,
730 const struct ia_css_isp_config *config,
731 struct ia_css_pipe *pipe);
734 sh_css_update_uds_and_crop_info_based_on_zoom_region(
735 const struct ia_css_binary_info *info,
736 const struct ia_css_frame_info *in_frame_info,
737 const struct ia_css_frame_info *out_frame_info,
738 const struct ia_css_resolution *dvs_env,
739 const struct ia_css_dz_config *zoom,
740 const struct ia_css_vector *motion_vector,
741 struct sh_css_uds_info *uds, /* out */
742 struct sh_css_crop_pos *sp_out_crop_pos, /* out */
743 struct ia_css_resolution pipe_in_res,
747 sh_css_params_ddr_address_map(void)
752 /* ****************************************************
753 * Each coefficient is stored as 7bits to fit 2 of them into one
754 * ISP vector element, so we will store 4 coefficents on every
755 * memory word (32bits)
757 * 0: Coefficient 0 used bits
758 * 1: Coefficient 1 used bits
759 * 2: Coefficient 2 used bits
760 * 3: Coefficient 3 used bits
763 * xx33333332222222 | xx11111110000000
765 * ***************************************************
767 static struct ia_css_host_data *
768 convert_allocate_fpntbl(struct ia_css_isp_parameters *params)
772 struct ia_css_host_data *me;
773 unsigned int isp_format_data_size;
774 u32 *isp_format_data_ptr;
778 data_ptr = params->fpn_config.data;
779 isp_format_data_size = params->fpn_config.height * params->fpn_config.width *
782 me = ia_css_host_data_allocate(isp_format_data_size);
787 isp_format_data_ptr = (uint32_t *)me->address;
789 for (i = 0; i < params->fpn_config.height; i++) {
791 j < params->fpn_config.width;
792 j += 4, data_ptr += 4, isp_format_data_ptr++) {
793 int data = data_ptr[0] << 0 |
797 *isp_format_data_ptr = data;
804 store_fpntbl(struct ia_css_isp_parameters *params, ia_css_ptr ptr)
806 struct ia_css_host_data *isp_data;
809 assert(ptr != mmgr_NULL);
811 isp_data = convert_allocate_fpntbl(params);
813 IA_CSS_LEAVE_ERR_PRIVATE(-ENOMEM);
816 ia_css_params_store_ia_css_host_data(ptr, isp_data);
818 ia_css_host_data_free(isp_data);
823 convert_raw_to_fpn(struct ia_css_isp_parameters *params)
830 /* Find the maximum value in the table */
831 for (i = 0; i < params->fpn_config.height * params->fpn_config.width; i++) {
832 int val = params->fpn_config.data[i];
833 /* Make sure FPN value can be represented in 13-bit unsigned
834 * number (ISP precision - 1), but note that actual input range
835 * depends on precision of input frame data.
838 /* Checkpatch patch */
840 } else if (val >= (1 << 13)) {
841 /* Checkpatch patch */
842 /* MW: BUG, is "13" a system or application property */
845 maxval = max(maxval, val);
847 /* Find the lowest shift value to remap the values in the range
848 * 0..maxval to 0..2^shiftval*63.
850 params->fpn_config.shift = 0;
851 while (maxval > 63) {
852 /* MW: BUG, is "63" a system or application property */
854 params->fpn_config.shift++;
856 /* Adjust the values in the table for the shift value */
857 for (i = 0; i < params->fpn_config.height * params->fpn_config.width; i++)
858 ((unsigned short *)params->fpn_config.data)[i] >>= params->fpn_config.shift;
862 ia_css_process_kernel(struct ia_css_stream *stream,
863 struct ia_css_isp_parameters *params,
864 void (*process)(unsigned int pipe_id,
865 const struct ia_css_pipeline_stage *stage,
866 struct ia_css_isp_parameters *params))
870 for (i = 0; i < stream->num_pipes; i++) {
871 struct ia_css_pipe *pipe = stream->pipes[i];
872 struct ia_css_pipeline *pipeline = ia_css_pipe_get_pipeline(pipe);
873 struct ia_css_pipeline_stage *stage;
875 /* update the other buffers to the pipe specific copies */
876 for (stage = pipeline->stages; stage; stage = stage->next) {
877 if (!stage || !stage->binary) continue;
878 process(pipeline->pipe_id, stage, params);
884 sh_css_select_dp_10bpp_config(const struct ia_css_pipe *pipe,
888 /* Currently we check if 10bpp DPC configuration is required based
889 * on the use case,i.e. if BDS and DPC is both enabled. The more cleaner
890 * design choice would be to expose the type of DPC (either 10bpp or 13bpp)
891 * using the binary info, but the current control flow does not allow this
892 * implementation. (This is because the configuration is set before a
893 * binary is selected, and the binary info is not available)
895 if ((!pipe) || (!is_dp_10bpp)) {
896 IA_CSS_LEAVE_ERR_PRIVATE(-EINVAL);
899 *is_dp_10bpp = false;
901 /* check if DPC is enabled from the host */
902 if (pipe->config.enable_dpc) {
903 /*check if BDS is enabled*/
904 unsigned int required_bds_factor = SH_CSS_BDS_FACTOR_1_00;
906 if ((pipe->config.bayer_ds_out_res.width != 0) &&
907 (pipe->config.bayer_ds_out_res.height != 0)) {
908 if (0 == binarydesc_calculate_bds_factor(
909 pipe->config.input_effective_res,
910 pipe->config.bayer_ds_out_res,
911 &required_bds_factor)) {
912 if (required_bds_factor != SH_CSS_BDS_FACTOR_1_00) {
913 /*we use 10bpp BDS configuration*/
925 sh_css_set_black_frame(struct ia_css_stream *stream,
926 const struct ia_css_frame *raw_black_frame)
928 struct ia_css_isp_parameters *params;
929 /* this function desperately needs to be moved to the ISP or SP such
930 * that it can use the DMA.
932 unsigned int height, width, y, x, k, data;
936 assert(raw_black_frame);
938 params = stream->isp_params_configs;
939 height = raw_black_frame->info.res.height;
940 width = raw_black_frame->info.padded_width;
942 ptr = raw_black_frame->data
943 + raw_black_frame->planes.raw.offset;
945 IA_CSS_ENTER_PRIVATE("black_frame=%p", raw_black_frame);
947 if (params->fpn_config.data &&
948 (params->fpn_config.width != width || params->fpn_config.height != height)) {
949 kvfree(params->fpn_config.data);
950 params->fpn_config.data = NULL;
952 if (!params->fpn_config.data) {
953 params->fpn_config.data = kvmalloc(height * width *
954 sizeof(short), GFP_KERNEL);
955 if (!params->fpn_config.data) {
956 IA_CSS_ERROR("out of memory");
957 IA_CSS_LEAVE_ERR_PRIVATE(-ENOMEM);
960 params->fpn_config.width = width;
961 params->fpn_config.height = height;
962 params->fpn_config.shift = 0;
965 /* store raw to fpntbl */
966 for (y = 0; y < height; y++) {
967 for (x = 0; x < width; x += (ISP_VEC_NELEMS * 2)) {
968 int ofs = y * width + x;
970 for (k = 0; k < ISP_VEC_NELEMS; k += 2) {
971 hmm_load(ptr, (void *)(&data), sizeof(int));
972 params->fpn_config.data[ofs + 2 * k] =
973 (short)(data & 0xFFFF);
974 params->fpn_config.data[ofs + 2 * k + 2] =
975 (short)((data >> 16) & 0xFFFF);
976 ptr += sizeof(int); /* byte system address */
978 for (k = 0; k < ISP_VEC_NELEMS; k += 2) {
979 hmm_load(ptr, (void *)(&data), sizeof(int));
980 params->fpn_config.data[ofs + 2 * k + 1] =
981 (short)(data & 0xFFFF);
982 params->fpn_config.data[ofs + 2 * k + 3] =
983 (short)((data >> 16) & 0xFFFF);
984 ptr += sizeof(int); /* byte system address */
990 convert_raw_to_fpn(params);
992 /* overwrite isp parameter */
993 ia_css_process_kernel(stream, params, ia_css_kernel_process_param[IA_CSS_FPN_ID]);
995 IA_CSS_LEAVE_ERR_PRIVATE(0);
1001 sh_css_params_set_binning_factor(struct ia_css_stream *stream,
1002 unsigned int binning_fact)
1004 struct ia_css_isp_parameters *params;
1006 IA_CSS_ENTER_PRIVATE("void");
1009 params = stream->isp_params_configs;
1011 if (params->sensor_binning != binning_fact) {
1012 params->sensor_binning = binning_fact;
1013 params->sc_table_changed = true;
1016 IA_CSS_LEAVE_PRIVATE("void");
1018 return params->sc_table_changed;
1022 sh_css_set_shading_table(struct ia_css_stream *stream,
1023 struct ia_css_isp_parameters *params,
1024 const struct ia_css_shading_table *table)
1026 IA_CSS_ENTER_PRIVATE("");
1034 if (table != params->sc_table) {
1035 params->sc_table = table;
1036 params->sc_table_changed = true;
1037 /* Not very clean, this goes to sh_css.c to invalidate the
1038 * shading table for all pipes. Should replaced by a loop
1039 * and a pipe-specific call.
1041 if (!params->output_frame)
1042 sh_css_invalidate_shading_tables(stream);
1045 IA_CSS_LEAVE_PRIVATE("void");
1049 ia_css_params_store_ia_css_host_data(
1050 ia_css_ptr ddr_addr,
1051 struct ia_css_host_data *data)
1054 assert(data->address);
1055 assert(ddr_addr != mmgr_NULL);
1057 IA_CSS_ENTER_PRIVATE("");
1060 (void *)(data->address),
1061 (size_t)data->size);
1063 IA_CSS_LEAVE_PRIVATE("void");
1066 struct ia_css_host_data *
1067 ia_css_params_alloc_convert_sctbl(
1068 const struct ia_css_pipeline_stage *stage,
1069 const struct ia_css_shading_table *shading_table)
1071 const struct ia_css_binary *binary = stage->binary;
1072 struct ia_css_host_data *sctbl;
1073 unsigned int i, j, aligned_width;
1074 unsigned int sctbl_size;
1078 assert(shading_table);
1080 IA_CSS_ENTER_PRIVATE("");
1082 if (!shading_table) {
1083 IA_CSS_LEAVE_PRIVATE("void");
1087 aligned_width = binary->sctbl_aligned_width_per_color;
1088 sctbl_size = shading_table->height * IA_CSS_SC_NUM_COLORS * aligned_width *
1091 sctbl = ia_css_host_data_allocate((size_t)sctbl_size);
1095 ptr = (short int *)sctbl->address;
1100 for (i = 0; i < shading_table->height; i++) {
1101 for (j = 0; j < IA_CSS_SC_NUM_COLORS; j++) {
1103 &shading_table->data[j]
1104 [i * shading_table->width],
1105 shading_table->width * sizeof(short));
1106 ptr += aligned_width;
1110 IA_CSS_LEAVE_PRIVATE("void");
1114 int ia_css_params_store_sctbl(
1115 const struct ia_css_pipeline_stage *stage,
1117 const struct ia_css_shading_table *sc_config)
1119 struct ia_css_host_data *isp_sc_tbl;
1121 IA_CSS_ENTER_PRIVATE("");
1124 IA_CSS_LEAVE_PRIVATE("void");
1128 isp_sc_tbl = ia_css_params_alloc_convert_sctbl(stage, sc_config);
1130 IA_CSS_LEAVE_ERR_PRIVATE(-ENOMEM);
1133 /* store the shading table to ddr */
1134 ia_css_params_store_ia_css_host_data(sc_tbl, isp_sc_tbl);
1135 ia_css_host_data_free(isp_sc_tbl);
1137 IA_CSS_LEAVE_PRIVATE("void");
1143 sh_css_enable_pipeline(const struct ia_css_binary *binary)
1148 IA_CSS_ENTER_PRIVATE("");
1150 ia_css_isp_param_enable_pipeline(&binary->mem_params);
1152 IA_CSS_LEAVE_PRIVATE("void");
1156 ia_css_process_zoom_and_motion(
1157 struct ia_css_isp_parameters *params,
1158 const struct ia_css_pipeline_stage *first_stage)
1160 /* first_stage can be NULL */
1161 const struct ia_css_pipeline_stage *stage;
1163 struct ia_css_resolution pipe_in_res;
1165 pipe_in_res.width = 0;
1166 pipe_in_res.height = 0;
1170 IA_CSS_ENTER_PRIVATE("");
1172 /* Go through all stages to udate uds and cropping */
1173 for (stage = first_stage; stage; stage = stage->next) {
1174 struct ia_css_binary *binary;
1175 /* note: the var below is made static as it is quite large;
1176 if it is not static it ends up on the stack which could
1177 cause issues for drivers
1179 static struct ia_css_binary tmp_binary;
1181 const struct ia_css_binary_xinfo *info = NULL;
1183 binary = stage->binary;
1185 info = binary->info;
1187 const struct sh_css_binary_args *args = &stage->args;
1188 const struct ia_css_frame_info *out_infos[IA_CSS_BINARY_MAX_OUTPUT_PORTS] = {NULL};
1190 if (args->out_frame[0])
1191 out_infos[0] = &args->out_frame[0]->info;
1192 info = &stage->firmware->info.isp;
1193 ia_css_binary_fill_info(info, false, false,
1194 ATOMISP_INPUT_FORMAT_RAW_10,
1195 args->in_frame ? &args->in_frame->info : NULL,
1198 args->out_vf_frame ? &args->out_vf_frame->info
1203 binary = &tmp_binary;
1204 binary->info = info;
1207 if (stage == first_stage) {
1208 /* we will use pipe_in_res to scale the zoom crop region if needed */
1209 pipe_in_res = binary->effective_in_frame_res;
1212 assert(stage->stage_num < SH_CSS_MAX_STAGES);
1213 if (params->dz_config.zoom_region.resolution.width == 0 &&
1214 params->dz_config.zoom_region.resolution.height == 0) {
1215 sh_css_update_uds_and_crop_info(
1217 &binary->in_frame_info,
1218 &binary->out_frame_info[0],
1219 &binary->dvs_envelope,
1221 ¶ms->motion_config,
1222 ¶ms->uds[stage->stage_num].uds,
1223 ¶ms->uds[stage->stage_num].crop_pos,
1224 stage->enable_zoom);
1226 err = sh_css_update_uds_and_crop_info_based_on_zoom_region(
1228 &binary->in_frame_info,
1229 &binary->out_frame_info[0],
1230 &binary->dvs_envelope,
1232 ¶ms->motion_config,
1233 ¶ms->uds[stage->stage_num].uds,
1234 ¶ms->uds[stage->stage_num].crop_pos,
1236 stage->enable_zoom);
1241 params->isp_params_changed = true;
1243 IA_CSS_LEAVE_PRIVATE("void");
1248 sh_css_set_gamma_table(struct ia_css_isp_parameters *params,
1249 const struct ia_css_gamma_table *table)
1253 IA_CSS_ENTER_PRIVATE("table=%p", table);
1256 params->gc_table = *table;
1257 params->config_changed[IA_CSS_GC_ID] = true;
1259 IA_CSS_LEAVE_PRIVATE("void");
1263 sh_css_get_gamma_table(const struct ia_css_isp_parameters *params,
1264 struct ia_css_gamma_table *table)
1268 IA_CSS_ENTER_PRIVATE("table=%p", table);
1271 *table = params->gc_table;
1273 IA_CSS_LEAVE_PRIVATE("void");
1277 sh_css_set_ctc_table(struct ia_css_isp_parameters *params,
1278 const struct ia_css_ctc_table *table)
1283 IA_CSS_ENTER_PRIVATE("table=%p", table);
1286 params->ctc_table = *table;
1287 params->config_changed[IA_CSS_CTC_ID] = true;
1289 IA_CSS_LEAVE_PRIVATE("void");
1293 sh_css_get_ctc_table(const struct ia_css_isp_parameters *params,
1294 struct ia_css_ctc_table *table)
1299 IA_CSS_ENTER_PRIVATE("table=%p", table);
1302 *table = params->ctc_table;
1304 IA_CSS_LEAVE_PRIVATE("void");
1308 sh_css_set_macc_table(struct ia_css_isp_parameters *params,
1309 const struct ia_css_macc_table *table)
1314 IA_CSS_ENTER_PRIVATE("table=%p", table);
1317 params->macc_table = *table;
1318 params->config_changed[IA_CSS_MACC_ID] = true;
1320 IA_CSS_LEAVE_PRIVATE("void");
1324 sh_css_get_macc_table(const struct ia_css_isp_parameters *params,
1325 struct ia_css_macc_table *table)
1330 IA_CSS_ENTER_PRIVATE("table=%p", table);
1333 *table = params->macc_table;
1335 IA_CSS_LEAVE_PRIVATE("void");
1338 void ia_css_morph_table_free(
1339 struct ia_css_morph_table *me)
1348 for (i = 0; i < IA_CSS_MORPH_TABLE_NUM_PLANES; i++) {
1349 if (me->coordinates_x[i]) {
1350 kvfree(me->coordinates_x[i]);
1351 me->coordinates_x[i] = NULL;
1353 if (me->coordinates_y[i]) {
1354 kvfree(me->coordinates_y[i]);
1355 me->coordinates_y[i] = NULL;
1360 IA_CSS_LEAVE("void");
1363 struct ia_css_morph_table *ia_css_morph_table_allocate(
1365 unsigned int height)
1368 struct ia_css_morph_table *me;
1372 me = kvmalloc(sizeof(*me), GFP_KERNEL);
1374 IA_CSS_ERROR("out of memory");
1378 for (i = 0; i < IA_CSS_MORPH_TABLE_NUM_PLANES; i++) {
1379 me->coordinates_x[i] = NULL;
1380 me->coordinates_y[i] = NULL;
1383 for (i = 0; i < IA_CSS_MORPH_TABLE_NUM_PLANES; i++) {
1384 me->coordinates_x[i] = kvmalloc(height * width *
1385 sizeof(*me->coordinates_x[i]),
1387 me->coordinates_y[i] = kvmalloc(height * width *
1388 sizeof(*me->coordinates_y[i]),
1391 if ((!me->coordinates_x[i]) ||
1392 (!me->coordinates_y[i])) {
1393 ia_css_morph_table_free(me);
1399 me->height = height;
1404 static int sh_css_params_default_morph_table(
1405 struct ia_css_morph_table **table,
1406 const struct ia_css_binary *binary)
1408 /* MW 2400 advanced requires different scaling */
1409 unsigned int i, j, k, step, width, height;
1410 short start_x[IA_CSS_MORPH_TABLE_NUM_PLANES] = { -8, 0, -8, 0, 0, -8 },
1411 start_y[IA_CSS_MORPH_TABLE_NUM_PLANES] = { 0, 0, -8, -8, -8, 0 };
1412 struct ia_css_morph_table *tab;
1417 IA_CSS_ENTER_PRIVATE("");
1419 step = (ISP_VEC_NELEMS / 16) * 128;
1420 width = binary->morph_tbl_width;
1421 height = binary->morph_tbl_height;
1423 tab = ia_css_morph_table_allocate(width, height);
1427 for (i = 0; i < IA_CSS_MORPH_TABLE_NUM_PLANES; i++) {
1428 short val_y = start_y[i];
1430 for (j = 0; j < height; j++) {
1431 short val_x = start_x[i];
1432 unsigned short *x_ptr, *y_ptr;
1434 x_ptr = &tab->coordinates_x[i][j * width];
1435 y_ptr = &tab->coordinates_y[i][j * width];
1436 for (k = 0; k < width;
1437 k++, x_ptr++, y_ptr++, val_x += (short)step) {
1440 else if (k == width - 1)
1441 *x_ptr = val_x + 2 * start_x[i];
1449 val_y += (short)step;
1454 IA_CSS_LEAVE_ERR_PRIVATE(0);
1460 sh_css_set_morph_table(struct ia_css_isp_parameters *params,
1461 const struct ia_css_morph_table *table)
1466 IA_CSS_ENTER_PRIVATE("table=%p", table);
1469 if (table->enable == false)
1471 params->morph_table = table;
1472 params->morph_table_changed = true;
1473 IA_CSS_LEAVE_PRIVATE("void");
1477 ia_css_translate_3a_statistics(
1478 struct ia_css_3a_statistics *host_stats,
1479 const struct ia_css_isp_3a_statistics_map *isp_stats)
1482 if (host_stats->grid.use_dmem) {
1483 IA_CSS_LOG("3A: DMEM");
1484 ia_css_s3a_dmem_decode(host_stats, isp_stats->dmem_stats);
1486 IA_CSS_LOG("3A: VMEM");
1487 ia_css_s3a_vmem_decode(host_stats, isp_stats->vmem_stats_hi,
1488 isp_stats->vmem_stats_lo);
1490 IA_CSS_LOG("3A: HMEM");
1491 ia_css_s3a_hmem_decode(host_stats, isp_stats->hmem_stats);
1493 IA_CSS_LEAVE("void");
1497 ia_css_isp_3a_statistics_map_free(struct ia_css_isp_3a_statistics_map *me)
1500 if (me->data_allocated) {
1501 kvfree(me->data_ptr);
1502 me->data_ptr = NULL;
1503 me->data_allocated = false;
1509 struct ia_css_isp_3a_statistics_map *
1510 ia_css_isp_3a_statistics_map_allocate(
1511 const struct ia_css_isp_3a_statistics *isp_stats,
1514 struct ia_css_isp_3a_statistics_map *me;
1515 /* Windows compiler does not like adding sizes to a void *
1516 * so we use a local char * instead. */
1519 me = kvmalloc(sizeof(*me), GFP_KERNEL);
1521 IA_CSS_LEAVE("cannot allocate memory");
1525 me->data_ptr = data_ptr;
1526 me->data_allocated = !data_ptr;
1528 me->data_ptr = kvmalloc(isp_stats->size, GFP_KERNEL);
1529 if (!me->data_ptr) {
1530 IA_CSS_LEAVE("cannot allocate memory");
1534 base_ptr = me->data_ptr;
1536 me->size = isp_stats->size;
1537 /* GCC complains when we assign a char * to a void *, so these
1538 * casts are necessary unfortunately. */
1539 me->dmem_stats = (void *)base_ptr;
1540 me->vmem_stats_hi = (void *)(base_ptr + isp_stats->dmem_size);
1541 me->vmem_stats_lo = (void *)(base_ptr + isp_stats->dmem_size +
1542 isp_stats->vmem_size);
1543 me->hmem_stats = (void *)(base_ptr + isp_stats->dmem_size +
1544 2 * isp_stats->vmem_size);
1546 IA_CSS_LEAVE("map=%p", me);
1555 ia_css_get_3a_statistics(struct ia_css_3a_statistics *host_stats,
1556 const struct ia_css_isp_3a_statistics *isp_stats)
1558 struct ia_css_isp_3a_statistics_map *map;
1561 IA_CSS_ENTER("host_stats=%p, isp_stats=%p", host_stats, isp_stats);
1566 map = ia_css_isp_3a_statistics_map_allocate(isp_stats, NULL);
1568 hmm_load(isp_stats->data_ptr, map->data_ptr, isp_stats->size);
1569 ia_css_translate_3a_statistics(host_stats, map);
1570 ia_css_isp_3a_statistics_map_free(map);
1572 IA_CSS_ERROR("out of memory");
1576 IA_CSS_LEAVE_ERR(ret);
1580 /* Parameter encoding is not yet orthogonal.
1581 This function hnadles some of the exceptions.
1584 ia_css_set_param_exceptions(const struct ia_css_pipe *pipe,
1585 struct ia_css_isp_parameters *params)
1589 /* Copy also to DP. Should be done by the driver. */
1590 params->dp_config.gr = params->wb_config.gr;
1591 params->dp_config.r = params->wb_config.r;
1592 params->dp_config.b = params->wb_config.b;
1593 params->dp_config.gb = params->wb_config.gb;
1597 sh_css_set_nr_config(struct ia_css_isp_parameters *params,
1598 const struct ia_css_nr_config *config)
1604 IA_CSS_ENTER_PRIVATE("config=%p", config);
1606 ia_css_nr_debug_dtrace(config, IA_CSS_DEBUG_TRACE_PRIVATE);
1607 params->nr_config = *config;
1608 params->yee_config.nr = *config;
1609 params->config_changed[IA_CSS_NR_ID] = true;
1610 params->config_changed[IA_CSS_YEE_ID] = true;
1611 params->config_changed[IA_CSS_BNR_ID] = true;
1613 IA_CSS_LEAVE_PRIVATE("void");
1617 sh_css_set_ee_config(struct ia_css_isp_parameters *params,
1618 const struct ia_css_ee_config *config)
1624 IA_CSS_ENTER_PRIVATE("config=%p", config);
1625 ia_css_ee_debug_dtrace(config, IA_CSS_DEBUG_TRACE_PRIVATE);
1627 params->ee_config = *config;
1628 params->yee_config.ee = *config;
1629 params->config_changed[IA_CSS_YEE_ID] = true;
1631 IA_CSS_LEAVE_PRIVATE("void");
1635 sh_css_get_ee_config(const struct ia_css_isp_parameters *params,
1636 struct ia_css_ee_config *config)
1641 IA_CSS_ENTER_PRIVATE("config=%p", config);
1644 *config = params->ee_config;
1646 ia_css_ee_debug_dtrace(config, IA_CSS_DEBUG_TRACE_PRIVATE);
1647 IA_CSS_LEAVE_PRIVATE("void");
1651 sh_css_set_pipe_dvs_6axis_config(const struct ia_css_pipe *pipe,
1652 struct ia_css_isp_parameters *params,
1653 const struct ia_css_dvs_6axis_config *dvs_config)
1659 assert(dvs_config->height_y == dvs_config->height_uv);
1660 assert((dvs_config->width_y - 1) == 2 * (dvs_config->width_uv - 1));
1661 assert(pipe->mode < IA_CSS_PIPE_ID_NUM);
1663 IA_CSS_ENTER_PRIVATE("dvs_config=%p", dvs_config);
1665 copy_dvs_6axis_table(params->pipe_dvs_6axis_config[pipe->mode], dvs_config);
1667 params->pipe_dvs_6axis_config_changed[pipe->mode] = true;
1669 IA_CSS_LEAVE_PRIVATE("void");
1673 sh_css_get_pipe_dvs_6axis_config(const struct ia_css_pipe *pipe,
1674 const struct ia_css_isp_parameters *params,
1675 struct ia_css_dvs_6axis_config *dvs_config)
1681 assert(dvs_config->height_y == dvs_config->height_uv);
1682 assert((dvs_config->width_y - 1) == 2 * dvs_config->width_uv - 1);
1684 IA_CSS_ENTER_PRIVATE("dvs_config=%p", dvs_config);
1686 if ((pipe->mode < IA_CSS_PIPE_ID_NUM) &&
1687 (dvs_config->width_y == params->pipe_dvs_6axis_config[pipe->mode]->width_y) &&
1688 (dvs_config->height_y == params->pipe_dvs_6axis_config[pipe->mode]->height_y) &&
1689 (dvs_config->width_uv == params->pipe_dvs_6axis_config[pipe->mode]->width_uv) &&
1690 (dvs_config->height_uv == params->pipe_dvs_6axis_config[pipe->mode]->height_uv)
1692 dvs_config->xcoords_y &&
1693 dvs_config->ycoords_y &&
1694 dvs_config->xcoords_uv &&
1695 dvs_config->ycoords_uv) {
1696 copy_dvs_6axis_table(dvs_config, params->pipe_dvs_6axis_config[pipe->mode]);
1699 IA_CSS_LEAVE_PRIVATE("void");
1703 sh_css_set_baa_config(struct ia_css_isp_parameters *params,
1704 const struct ia_css_aa_config *config)
1710 IA_CSS_ENTER_PRIVATE("config=%p", config);
1712 params->bds_config = *config;
1713 params->config_changed[IA_CSS_BDS_ID] = true;
1715 IA_CSS_LEAVE_PRIVATE("void");
1719 sh_css_get_baa_config(const struct ia_css_isp_parameters *params,
1720 struct ia_css_aa_config *config)
1726 IA_CSS_ENTER_PRIVATE("config=%p", config);
1728 *config = params->bds_config;
1730 IA_CSS_LEAVE_PRIVATE("void");
1734 sh_css_set_dz_config(struct ia_css_isp_parameters *params,
1735 const struct ia_css_dz_config *config)
1741 IA_CSS_ENTER_PRIVATE("dx=%d, dy=%d", config->dx, config->dy);
1743 assert(config->dx <= HRT_GDC_N);
1744 assert(config->dy <= HRT_GDC_N);
1746 params->dz_config = *config;
1747 params->dz_config_changed = true;
1748 /* JK: Why isp params changed?? */
1749 params->isp_params_changed = true;
1751 IA_CSS_LEAVE_PRIVATE("void");
1755 sh_css_get_dz_config(const struct ia_css_isp_parameters *params,
1756 struct ia_css_dz_config *config)
1762 IA_CSS_ENTER_PRIVATE("config=%p", config);
1764 *config = params->dz_config;
1766 IA_CSS_LEAVE_PRIVATE("dx=%d, dy=%d", config->dx, config->dy);
1770 sh_css_set_motion_vector(struct ia_css_isp_parameters *params,
1771 const struct ia_css_vector *motion)
1777 IA_CSS_ENTER_PRIVATE("x=%d, y=%d", motion->x, motion->y);
1779 params->motion_config = *motion;
1780 /* JK: Why do isp params change? */
1781 params->motion_config_changed = true;
1782 params->isp_params_changed = true;
1784 IA_CSS_LEAVE_PRIVATE("void");
1788 sh_css_get_motion_vector(const struct ia_css_isp_parameters *params,
1789 struct ia_css_vector *motion)
1795 IA_CSS_ENTER_PRIVATE("motion=%p", motion);
1797 *motion = params->motion_config;
1799 IA_CSS_LEAVE_PRIVATE("x=%d, y=%d", motion->x, motion->y);
1802 struct ia_css_isp_config *
1803 sh_css_pipe_isp_config_get(struct ia_css_pipe *pipe)
1806 IA_CSS_ERROR("pipe=%p", NULL);
1809 return pipe->config.p_isp_config;
1813 ia_css_stream_set_isp_config(
1814 struct ia_css_stream *stream,
1815 const struct ia_css_isp_config *config)
1817 return ia_css_stream_set_isp_config_on_pipe(stream, config, NULL);
1821 ia_css_stream_set_isp_config_on_pipe(
1822 struct ia_css_stream *stream,
1823 const struct ia_css_isp_config *config,
1824 struct ia_css_pipe *pipe)
1828 if ((!stream) || (!config))
1831 IA_CSS_ENTER("stream=%p, config=%p, pipe=%p", stream, config, pipe);
1833 if (config->output_frame)
1834 err = sh_css_set_per_frame_isp_config_on_pipe(stream, config, pipe);
1836 err = sh_css_set_global_isp_config_on_pipe(stream->pipes[0], config, pipe);
1838 IA_CSS_LEAVE_ERR(err);
1843 ia_css_pipe_set_isp_config(struct ia_css_pipe *pipe,
1844 struct ia_css_isp_config *config)
1846 struct ia_css_pipe *pipe_in = pipe;
1849 IA_CSS_ENTER("pipe=%p", pipe);
1851 if ((!pipe) || (!pipe->stream))
1854 ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "config=%p\n", config);
1856 if (config->output_frame)
1857 err = sh_css_set_per_frame_isp_config_on_pipe(pipe->stream, config, pipe);
1859 err = sh_css_set_global_isp_config_on_pipe(pipe, config, pipe_in);
1860 IA_CSS_LEAVE_ERR(err);
1865 sh_css_set_global_isp_config_on_pipe(
1866 struct ia_css_pipe *curr_pipe,
1867 const struct ia_css_isp_config *config,
1868 struct ia_css_pipe *pipe)
1874 IA_CSS_ENTER_PRIVATE("stream=%p, config=%p, pipe=%p", curr_pipe, config, pipe);
1876 err1 = sh_css_init_isp_params_from_config(curr_pipe, curr_pipe->stream->isp_params_configs, config, pipe);
1878 /* Now commit all changes to the SP */
1879 err2 = sh_css_param_update_isp_params(curr_pipe, curr_pipe->stream->isp_params_configs, sh_css_sp_is_running(), pipe);
1881 /* The following code is intentional. The sh_css_init_isp_params_from_config interface
1882 * throws an error when both DPC and BDS is enabled. The CSS API must pass this error
1883 * information to the caller, ie. the host. We do not return this error immediately,
1884 * but instead continue with updating the ISP params to enable testing of features
1885 * which are currently in TR phase. */
1887 err = (err1 != 0) ? err1 : ((err2 != 0) ? err2 : err);
1889 IA_CSS_LEAVE_ERR_PRIVATE(err);
1894 sh_css_set_per_frame_isp_config_on_pipe(
1895 struct ia_css_stream *stream,
1896 const struct ia_css_isp_config *config,
1897 struct ia_css_pipe *pipe)
1900 bool per_frame_config_created = false;
1906 struct sh_css_ddr_address_map *ddr_ptrs;
1907 struct sh_css_ddr_address_map_size *ddr_ptrs_size;
1908 struct ia_css_isp_parameters *params;
1910 IA_CSS_ENTER_PRIVATE("stream=%p, config=%p, pipe=%p", stream, config, pipe);
1917 /* create per-frame ISP params object with default values
1918 * from stream->isp_params_configs if one doesn't already exist
1920 if (!stream->per_frame_isp_params_configs) {
1921 err = sh_css_create_isp_params(stream,
1922 &stream->per_frame_isp_params_configs);
1925 per_frame_config_created = true;
1928 params = stream->per_frame_isp_params_configs;
1930 /* update new ISP params object with the new config */
1931 if (!sh_css_init_isp_params_from_global(stream, params, false, pipe)) {
1935 err2 = sh_css_init_isp_params_from_config(stream->pipes[0], params, config, pipe);
1937 if (per_frame_config_created) {
1938 ddr_ptrs = ¶ms->ddr_ptrs;
1939 ddr_ptrs_size = ¶ms->ddr_ptrs_size;
1940 /* create per pipe reference to general ddr_ptrs */
1941 for (i = 0; i < IA_CSS_PIPE_ID_NUM; i++) {
1942 ref_sh_css_ddr_address_map(ddr_ptrs, ¶ms->pipe_ddr_ptrs[i]);
1943 params->pipe_ddr_ptrs_size[i] = *ddr_ptrs_size;
1947 /* now commit to ddr */
1948 err3 = sh_css_param_update_isp_params(stream->pipes[0], params, sh_css_sp_is_running(), pipe);
1950 /* The following code is intentional. The sh_css_init_sp_params_from_config and
1951 * sh_css_init_isp_params_from_config throws an error when both DPC and BDS is enabled.
1952 * The CSS API must pass this error information to the caller, ie. the host.
1953 * We do not return this error immediately, but instead continue with updating the ISP params
1954 * to enable testing of features which are currently in TR phase. */
1955 err = (err1 != 0) ? err1 :
1956 (err2 != 0) ? err2 :
1957 (err3 != 0) ? err3 : err;
1959 IA_CSS_LEAVE_ERR_PRIVATE(err);
1964 sh_css_init_isp_params_from_config(struct ia_css_pipe *pipe,
1965 struct ia_css_isp_parameters *params,
1966 const struct ia_css_isp_config *config,
1967 struct ia_css_pipe *pipe_in)
1970 bool is_dp_10bpp = true;
1974 IA_CSS_ENTER_PRIVATE("pipe=%p, config=%p, params=%p", pipe, config, params);
1976 ia_css_set_configs(params, config);
1978 sh_css_set_nr_config(params, config->nr_config);
1979 sh_css_set_ee_config(params, config->ee_config);
1980 sh_css_set_baa_config(params, config->baa_config);
1981 if ((pipe->mode < IA_CSS_PIPE_ID_NUM) &&
1982 (params->pipe_dvs_6axis_config[pipe->mode]))
1983 sh_css_set_pipe_dvs_6axis_config(pipe, params, config->dvs_6axis_config);
1984 sh_css_set_dz_config(params, config->dz_config);
1985 sh_css_set_motion_vector(params, config->motion_vector);
1986 sh_css_set_shading_table(pipe->stream, params, config->shading_table);
1987 sh_css_set_morph_table(params, config->morph_table);
1988 sh_css_set_macc_table(params, config->macc_table);
1989 sh_css_set_gamma_table(params, config->gamma_table);
1990 sh_css_set_ctc_table(params, config->ctc_table);
1991 /* ------ deprecated(bz675) : from ------ */
1992 sh_css_set_shading_settings(params, config->shading_settings);
1993 /* ------ deprecated(bz675) : to ------ */
1995 params->dis_coef_table_changed = (config->dvs_coefs);
1996 params->dvs2_coef_table_changed = (config->dvs2_coefs);
1998 params->output_frame = config->output_frame;
1999 params->isp_parameters_id = config->isp_config_id;
2002 sh_css_select_dp_10bpp_config(pipe, &is_dp_10bpp)) {
2003 /* return an error when both DPC and BDS is enabled by the
2005 /* we do not exit from this point immediately to allow internal
2006 * firmware feature testing. */
2015 ia_css_set_param_exceptions(pipe, params);
2018 IA_CSS_LEAVE_ERR_PRIVATE(err);
2023 ia_css_stream_get_isp_config(
2024 const struct ia_css_stream *stream,
2025 struct ia_css_isp_config *config)
2027 IA_CSS_ENTER("void");
2028 ia_css_pipe_get_isp_config(stream->pipes[0], config);
2029 IA_CSS_LEAVE("void");
2033 ia_css_pipe_get_isp_config(struct ia_css_pipe *pipe,
2034 struct ia_css_isp_config *config)
2036 struct ia_css_isp_parameters *params = NULL;
2040 IA_CSS_ENTER("config=%p", config);
2042 params = pipe->stream->isp_params_configs;
2045 ia_css_get_configs(params, config);
2047 sh_css_get_ee_config(params, config->ee_config);
2048 sh_css_get_baa_config(params, config->baa_config);
2049 sh_css_get_pipe_dvs_6axis_config(pipe, params, config->dvs_6axis_config);
2050 sh_css_get_macc_table(params, config->macc_table);
2051 sh_css_get_gamma_table(params, config->gamma_table);
2052 sh_css_get_ctc_table(params, config->ctc_table);
2053 sh_css_get_dz_config(params, config->dz_config);
2054 sh_css_get_motion_vector(params, config->motion_vector);
2055 /* ------ deprecated(bz675) : from ------ */
2056 sh_css_get_shading_settings(params, config->shading_settings);
2057 /* ------ deprecated(bz675) : to ------ */
2059 config->output_frame = params->output_frame;
2060 config->isp_config_id = params->isp_parameters_id;
2062 IA_CSS_LEAVE("void");
2066 * coding style says the return of "mmgr_NULL" is the error signal
2068 * Deprecated: Implement mmgr_realloc()
2070 static bool realloc_isp_css_mm_buf(
2071 ia_css_ptr *curr_buf,
2076 uint16_t mmgr_attribute)
2081 /* Possible optimization: add a function sh_css_isp_css_mm_realloc()
2082 * and implement on top of hmm. */
2084 IA_CSS_ENTER_PRIVATE("void");
2086 if (!force && *curr_size >= needed_size) {
2087 IA_CSS_LEAVE_PRIVATE("false");
2090 /* don't reallocate if single ref to buffer and same size */
2091 if (*curr_size == needed_size && ia_css_refcount_is_single(*curr_buf)) {
2092 IA_CSS_LEAVE_PRIVATE("false");
2096 id = IA_CSS_REFCOUNT_PARAM_BUFFER;
2097 ia_css_refcount_decrement(id, *curr_buf);
2098 *curr_buf = ia_css_refcount_increment(id, hmm_alloc(needed_size,
2107 *curr_size = needed_size;
2109 IA_CSS_LEAVE_PRIVATE("true");
2113 static bool reallocate_buffer(
2114 ia_css_ptr *curr_buf,
2122 IA_CSS_ENTER_PRIVATE("void");
2124 ret = realloc_isp_css_mm_buf(curr_buf,
2125 curr_size, needed_size, force, err, 0);
2127 IA_CSS_LEAVE_PRIVATE("ret=%d", ret);
2131 struct ia_css_isp_3a_statistics *
2132 ia_css_isp_3a_statistics_allocate(const struct ia_css_3a_grid_info *grid)
2134 struct ia_css_isp_3a_statistics *me;
2136 IA_CSS_ENTER("grid=%p", grid);
2140 /* MW: Does "grid->enable" also control the histogram output ?? */
2144 me = kvcalloc(1, sizeof(*me), GFP_KERNEL);
2148 if (grid->use_dmem) {
2149 me->dmem_size = sizeof(struct ia_css_3a_output) *
2150 grid->aligned_width *
2151 grid->aligned_height;
2153 me->vmem_size = ISP_S3ATBL_HI_LO_STRIDE_BYTES *
2154 grid->aligned_height;
2156 me->hmem_size = sizeof_hmem(HMEM0_ID);
2158 /* All subsections need to be aligned to the system bus width */
2159 me->dmem_size = CEIL_MUL(me->dmem_size, HIVE_ISP_DDR_WORD_BYTES);
2160 me->vmem_size = CEIL_MUL(me->vmem_size, HIVE_ISP_DDR_WORD_BYTES);
2161 me->hmem_size = CEIL_MUL(me->hmem_size, HIVE_ISP_DDR_WORD_BYTES);
2163 me->size = me->dmem_size + me->vmem_size * 2 + me->hmem_size;
2164 me->data_ptr = hmm_alloc(me->size, HMM_BO_PRIVATE, 0, NULL, 0);
2165 if (me->data_ptr == mmgr_NULL) {
2171 me->data.dmem.s3a_tbl = me->data_ptr;
2172 if (me->vmem_size) {
2173 me->data.vmem.s3a_tbl_hi = me->data_ptr + me->dmem_size;
2174 me->data.vmem.s3a_tbl_lo = me->data_ptr + me->dmem_size + me->vmem_size;
2177 me->data_hmem.rgby_tbl = me->data_ptr + me->dmem_size + 2 * me->vmem_size;
2180 IA_CSS_LEAVE("return=%p", me);
2185 ia_css_isp_3a_statistics_free(struct ia_css_isp_3a_statistics *me)
2188 hmm_free(me->data_ptr);
2193 struct ia_css_isp_skc_dvs_statistics *ia_css_skc_dvs_statistics_allocate(void)
2198 struct ia_css_metadata *
2199 ia_css_metadata_allocate(const struct ia_css_metadata_info *metadata_info)
2201 struct ia_css_metadata *md = NULL;
2205 if (metadata_info->size == 0)
2208 md = kvmalloc(sizeof(*md), GFP_KERNEL);
2212 md->info = *metadata_info;
2214 md->address = hmm_alloc(metadata_info->size, HMM_BO_PRIVATE, 0, NULL, 0);
2215 if (md->address == mmgr_NULL)
2218 IA_CSS_LEAVE("return=%p", md);
2222 ia_css_metadata_free(md);
2223 IA_CSS_LEAVE("return=%p", NULL);
2228 ia_css_metadata_free(struct ia_css_metadata *me)
2231 /* The enter and leave macros are placed inside
2232 * the condition to avoid false logging of metadata
2233 * free events when metadata is disabled.
2234 * We found this to be confusing during development
2236 IA_CSS_ENTER("me=%p", me);
2237 hmm_free(me->address);
2239 IA_CSS_LEAVE("void");
2244 ia_css_metadata_free_multiple(unsigned int num_bufs,
2245 struct ia_css_metadata **bufs)
2250 for (i = 0; i < num_bufs; i++)
2251 ia_css_metadata_free(bufs[i]);
2255 static unsigned int g_param_buffer_dequeue_count;
2256 static unsigned int g_param_buffer_enqueue_count;
2259 ia_css_stream_isp_parameters_init(struct ia_css_stream *stream)
2263 struct sh_css_ddr_address_map *ddr_ptrs;
2264 struct sh_css_ddr_address_map_size *ddr_ptrs_size;
2265 struct ia_css_isp_parameters *params;
2268 IA_CSS_ENTER_PRIVATE("void");
2271 IA_CSS_LEAVE_ERR_PRIVATE(-EINVAL);
2274 /* TMP: tracking of paramsets */
2275 g_param_buffer_dequeue_count = 0;
2276 g_param_buffer_enqueue_count = 0;
2278 stream->per_frame_isp_params_configs = NULL;
2279 err = sh_css_create_isp_params(stream,
2280 &stream->isp_params_configs);
2284 params = stream->isp_params_configs;
2285 if (!sh_css_init_isp_params_from_global(stream, params, true, NULL)) {
2286 /* we do not return the error immediately to enable internal
2287 * firmware feature testing */
2291 ddr_ptrs = ¶ms->ddr_ptrs;
2292 ddr_ptrs_size = ¶ms->ddr_ptrs_size;
2294 /* create per pipe reference to general ddr_ptrs */
2295 for (i = 0; i < IA_CSS_PIPE_ID_NUM; i++) {
2296 ref_sh_css_ddr_address_map(ddr_ptrs, ¶ms->pipe_ddr_ptrs[i]);
2297 params->pipe_ddr_ptrs_size[i] = *ddr_ptrs_size;
2301 IA_CSS_LEAVE_ERR_PRIVATE(err);
2306 ia_css_set_sdis_config(
2307 struct ia_css_isp_parameters *params,
2308 const struct ia_css_dvs_coefficients *dvs_coefs)
2310 ia_css_set_sdis_horicoef_config(params, dvs_coefs);
2311 ia_css_set_sdis_vertcoef_config(params, dvs_coefs);
2312 ia_css_set_sdis_horiproj_config(params, dvs_coefs);
2313 ia_css_set_sdis_vertproj_config(params, dvs_coefs);
2317 ia_css_set_sdis2_config(
2318 struct ia_css_isp_parameters *params,
2319 const struct ia_css_dvs2_coefficients *dvs2_coefs)
2321 ia_css_set_sdis2_horicoef_config(params, dvs2_coefs);
2322 ia_css_set_sdis2_vertcoef_config(params, dvs2_coefs);
2323 ia_css_set_sdis2_horiproj_config(params, dvs2_coefs);
2324 ia_css_set_sdis2_vertproj_config(params, dvs2_coefs);
2328 sh_css_create_isp_params(struct ia_css_stream *stream,
2329 struct ia_css_isp_parameters **isp_params_out)
2333 struct sh_css_ddr_address_map *ddr_ptrs;
2334 struct sh_css_ddr_address_map_size *ddr_ptrs_size;
2337 struct ia_css_isp_parameters *params =
2338 kvmalloc(sizeof(struct ia_css_isp_parameters), GFP_KERNEL);
2341 *isp_params_out = NULL;
2343 IA_CSS_ERROR("%s:%d error: cannot allocate memory", __FILE__, __LINE__);
2344 IA_CSS_LEAVE_ERR_PRIVATE(err);
2347 memset(params, 0, sizeof(struct ia_css_isp_parameters));
2350 ddr_ptrs = ¶ms->ddr_ptrs;
2351 ddr_ptrs_size = ¶ms->ddr_ptrs_size;
2353 for (i = 0; i < IA_CSS_PIPE_ID_NUM; i++) {
2354 memset(¶ms->pipe_ddr_ptrs[i], 0,
2355 sizeof(params->pipe_ddr_ptrs[i]));
2356 memset(¶ms->pipe_ddr_ptrs_size[i], 0,
2357 sizeof(params->pipe_ddr_ptrs_size[i]));
2360 memset(ddr_ptrs, 0, sizeof(*ddr_ptrs));
2361 memset(ddr_ptrs_size, 0, sizeof(*ddr_ptrs_size));
2363 params_size = sizeof(params->uds);
2364 ddr_ptrs_size->isp_param = params_size;
2365 ddr_ptrs->isp_param =
2366 ia_css_refcount_increment(IA_CSS_REFCOUNT_PARAM_BUFFER,
2367 hmm_alloc(params_size, HMM_BO_PRIVATE, 0, NULL, 0));
2368 succ &= (ddr_ptrs->isp_param != mmgr_NULL);
2370 ddr_ptrs_size->macc_tbl = sizeof(struct ia_css_macc_table);
2371 ddr_ptrs->macc_tbl =
2372 ia_css_refcount_increment(IA_CSS_REFCOUNT_PARAM_BUFFER,
2373 hmm_alloc(sizeof(struct ia_css_macc_table), HMM_BO_PRIVATE, 0, NULL, 0));
2374 succ &= (ddr_ptrs->macc_tbl != mmgr_NULL);
2376 *isp_params_out = params;
2385 sh_css_init_isp_params_from_global(struct ia_css_stream *stream,
2386 struct ia_css_isp_parameters *params,
2387 bool use_default_config,
2388 struct ia_css_pipe *pipe_in)
2392 bool is_dp_10bpp = true;
2393 unsigned int isp_pipe_version = ia_css_pipe_get_isp_pipe_version(
2395 struct ia_css_isp_parameters *stream_params = stream->isp_params_configs;
2397 if (!use_default_config && !stream_params) {
2402 params->output_frame = NULL;
2403 params->isp_parameters_id = 0;
2405 if (use_default_config) {
2406 ia_css_set_xnr3_config(params, &default_xnr3_config);
2408 sh_css_set_nr_config(params, &default_nr_config);
2409 sh_css_set_ee_config(params, &default_ee_config);
2410 if (isp_pipe_version == SH_CSS_ISP_PIPE_VERSION_1)
2411 sh_css_set_macc_table(params, &default_macc_table);
2412 else if (isp_pipe_version == SH_CSS_ISP_PIPE_VERSION_2_2)
2413 sh_css_set_macc_table(params, &default_macc2_table);
2414 sh_css_set_gamma_table(params, &default_gamma_table);
2415 sh_css_set_ctc_table(params, &default_ctc_table);
2416 sh_css_set_baa_config(params, &default_baa_config);
2417 sh_css_set_dz_config(params, &default_dz_config);
2418 /* ------ deprecated(bz675) : from ------ */
2419 sh_css_set_shading_settings(params, &default_shading_settings);
2420 /* ------ deprecated(bz675) : to ------ */
2422 ia_css_set_s3a_config(params, &default_3a_config);
2423 ia_css_set_wb_config(params, &default_wb_config);
2424 ia_css_set_csc_config(params, &default_cc_config);
2425 ia_css_set_tnr_config(params, &default_tnr_config);
2426 ia_css_set_ob_config(params, &default_ob_config);
2427 ia_css_set_dp_config(params, &default_dp_config);
2429 ia_css_set_param_exceptions(pipe_in, params);
2431 ia_css_set_de_config(params, &default_de_config);
2432 ia_css_set_gc_config(params, &default_gc_config);
2433 ia_css_set_anr_config(params, &default_anr_config);
2434 ia_css_set_anr2_config(params, &default_anr_thres);
2435 ia_css_set_ce_config(params, &default_ce_config);
2436 ia_css_set_xnr_table_config(params, &default_xnr_table);
2437 ia_css_set_ecd_config(params, &default_ecd_config);
2438 ia_css_set_ynr_config(params, &default_ynr_config);
2439 ia_css_set_fc_config(params, &default_fc_config);
2440 ia_css_set_cnr_config(params, &default_cnr_config);
2441 ia_css_set_macc_config(params, &default_macc_config);
2442 ia_css_set_ctc_config(params, &default_ctc_config);
2443 ia_css_set_aa_config(params, &default_aa_config);
2444 ia_css_set_r_gamma_config(params, &default_r_gamma_table);
2445 ia_css_set_g_gamma_config(params, &default_g_gamma_table);
2446 ia_css_set_b_gamma_config(params, &default_b_gamma_table);
2447 ia_css_set_yuv2rgb_config(params, &default_yuv2rgb_cc_config);
2448 ia_css_set_rgb2yuv_config(params, &default_rgb2yuv_cc_config);
2449 ia_css_set_xnr_config(params, &default_xnr_config);
2450 ia_css_set_sdis_config(params, &default_sdis_config);
2451 ia_css_set_sdis2_config(params, &default_sdis2_config);
2452 ia_css_set_formats_config(params, &default_formats_config);
2454 params->fpn_config.data = NULL;
2455 params->config_changed[IA_CSS_FPN_ID] = true;
2456 params->fpn_config.enabled = 0;
2458 params->motion_config = default_motion_config;
2459 params->motion_config_changed = true;
2461 params->morph_table = NULL;
2462 params->morph_table_changed = true;
2464 params->sc_table = NULL;
2465 params->sc_table_changed = true;
2467 ia_css_sdis2_clear_coefficients(¶ms->dvs2_coefs);
2468 params->dvs2_coef_table_changed = true;
2470 ia_css_sdis_clear_coefficients(¶ms->dvs_coefs);
2471 params->dis_coef_table_changed = true;
2473 ia_css_set_xnr3_config(params, &stream_params->xnr3_config);
2475 sh_css_set_nr_config(params, &stream_params->nr_config);
2476 sh_css_set_ee_config(params, &stream_params->ee_config);
2477 if (isp_pipe_version == SH_CSS_ISP_PIPE_VERSION_1)
2478 sh_css_set_macc_table(params, &stream_params->macc_table);
2479 else if (isp_pipe_version == SH_CSS_ISP_PIPE_VERSION_2_2)
2480 sh_css_set_macc_table(params, &stream_params->macc_table);
2481 sh_css_set_gamma_table(params, &stream_params->gc_table);
2482 sh_css_set_ctc_table(params, &stream_params->ctc_table);
2483 sh_css_set_baa_config(params, &stream_params->bds_config);
2484 sh_css_set_dz_config(params, &stream_params->dz_config);
2485 /* ------ deprecated(bz675) : from ------ */
2486 sh_css_set_shading_settings(params, &stream_params->shading_settings);
2487 /* ------ deprecated(bz675) : to ------ */
2489 ia_css_set_s3a_config(params, &stream_params->s3a_config);
2490 ia_css_set_wb_config(params, &stream_params->wb_config);
2491 ia_css_set_csc_config(params, &stream_params->cc_config);
2492 ia_css_set_tnr_config(params, &stream_params->tnr_config);
2493 ia_css_set_ob_config(params, &stream_params->ob_config);
2494 ia_css_set_dp_config(params, &stream_params->dp_config);
2495 ia_css_set_de_config(params, &stream_params->de_config);
2496 ia_css_set_gc_config(params, &stream_params->gc_config);
2497 ia_css_set_anr_config(params, &stream_params->anr_config);
2498 ia_css_set_anr2_config(params, &stream_params->anr_thres);
2499 ia_css_set_ce_config(params, &stream_params->ce_config);
2500 ia_css_set_xnr_table_config(params, &stream_params->xnr_table);
2501 ia_css_set_ecd_config(params, &stream_params->ecd_config);
2502 ia_css_set_ynr_config(params, &stream_params->ynr_config);
2503 ia_css_set_fc_config(params, &stream_params->fc_config);
2504 ia_css_set_cnr_config(params, &stream_params->cnr_config);
2505 ia_css_set_macc_config(params, &stream_params->macc_config);
2506 ia_css_set_ctc_config(params, &stream_params->ctc_config);
2507 ia_css_set_aa_config(params, &stream_params->aa_config);
2508 ia_css_set_r_gamma_config(params, &stream_params->r_gamma_table);
2509 ia_css_set_g_gamma_config(params, &stream_params->g_gamma_table);
2510 ia_css_set_b_gamma_config(params, &stream_params->b_gamma_table);
2511 ia_css_set_yuv2rgb_config(params, &stream_params->yuv2rgb_cc_config);
2512 ia_css_set_rgb2yuv_config(params, &stream_params->rgb2yuv_cc_config);
2513 ia_css_set_xnr_config(params, &stream_params->xnr_config);
2514 ia_css_set_formats_config(params, &stream_params->formats_config);
2516 for (i = 0; i < stream->num_pipes; i++) {
2518 sh_css_select_dp_10bpp_config(stream->pipes[i], &is_dp_10bpp)) {
2519 /* set the return value as false if both DPC and
2520 * BDS is enabled by the user. But we do not return
2521 * the value immediately to enable internal firmware
2522 * feature testing. */
2523 retval = !is_dp_10bpp;
2524 /* FIXME: should it ignore this error? */
2531 ia_css_set_param_exceptions(pipe_in, params);
2533 params->fpn_config.data = stream_params->fpn_config.data;
2534 params->config_changed[IA_CSS_FPN_ID] =
2535 stream_params->config_changed[IA_CSS_FPN_ID];
2536 params->fpn_config.enabled = stream_params->fpn_config.enabled;
2538 sh_css_set_motion_vector(params, &stream_params->motion_config);
2539 sh_css_set_morph_table(params, stream_params->morph_table);
2541 if (stream_params->sc_table) {
2542 sh_css_set_shading_table(stream, params, stream_params->sc_table);
2544 params->sc_table = NULL;
2545 params->sc_table_changed = true;
2548 /* Only IA_CSS_PIPE_ID_VIDEO & IA_CSS_PIPE_ID_CAPTURE will support dvs_6axis_config*/
2549 for (i = 0; i < IA_CSS_PIPE_ID_NUM; i++) {
2550 if (stream_params->pipe_dvs_6axis_config[i]) {
2551 if (params->pipe_dvs_6axis_config[i]) {
2552 copy_dvs_6axis_table(params->pipe_dvs_6axis_config[i],
2553 stream_params->pipe_dvs_6axis_config[i]);
2555 params->pipe_dvs_6axis_config[i] =
2556 generate_dvs_6axis_table_from_config(stream_params->pipe_dvs_6axis_config[i]);
2560 ia_css_set_sdis_config(params, &stream_params->dvs_coefs);
2561 params->dis_coef_table_changed = stream_params->dis_coef_table_changed;
2563 ia_css_set_sdis2_config(params, &stream_params->dvs2_coefs);
2564 params->dvs2_coef_table_changed = stream_params->dvs2_coef_table_changed;
2565 params->sensor_binning = stream_params->sensor_binning;
2573 sh_css_params_init(void)
2577 IA_CSS_ENTER_PRIVATE("void");
2579 /* TMP: tracking of paramsets */
2580 g_param_buffer_dequeue_count = 0;
2581 g_param_buffer_enqueue_count = 0;
2583 for (p = 0; p < IA_CSS_PIPE_ID_NUM; p++) {
2584 for (i = 0; i < SH_CSS_MAX_STAGES; i++) {
2585 xmem_sp_stage_ptrs[p][i] =
2586 ia_css_refcount_increment(-1,
2587 hmm_alloc(sizeof(struct sh_css_sp_stage),
2588 HMM_BO_PRIVATE, 0, NULL,
2589 ATOMISP_MAP_FLAG_CLEARED));
2590 xmem_isp_stage_ptrs[p][i] =
2591 ia_css_refcount_increment(-1,
2592 hmm_alloc(sizeof(struct sh_css_sp_stage),
2593 HMM_BO_PRIVATE, 0, NULL,
2594 ATOMISP_MAP_FLAG_CLEARED));
2596 if ((xmem_sp_stage_ptrs[p][i] == mmgr_NULL) ||
2597 (xmem_isp_stage_ptrs[p][i] == mmgr_NULL)) {
2598 sh_css_params_uninit();
2599 IA_CSS_LEAVE_ERR_PRIVATE(-ENOMEM);
2605 ia_css_config_gamma_table();
2606 ia_css_config_ctc_table();
2607 ia_css_config_rgb_gamma_tables();
2608 ia_css_config_xnr_table();
2610 sp_ddr_ptrs = ia_css_refcount_increment(-1,
2611 hmm_alloc(CEIL_MUL(sizeof(struct sh_css_ddr_address_map),
2612 HIVE_ISP_DDR_WORD_BYTES),
2613 HMM_BO_PRIVATE, 0, NULL,
2614 ATOMISP_MAP_FLAG_CLEARED));
2615 xmem_sp_group_ptrs = ia_css_refcount_increment(-1,
2616 hmm_alloc(sizeof(struct sh_css_sp_group),
2617 HMM_BO_PRIVATE, 0, NULL,
2618 ATOMISP_MAP_FLAG_CLEARED));
2620 if ((sp_ddr_ptrs == mmgr_NULL) ||
2621 (xmem_sp_group_ptrs == mmgr_NULL)) {
2623 IA_CSS_LEAVE_ERR_PRIVATE(-ENOMEM);
2626 IA_CSS_LEAVE_ERR_PRIVATE(0);
2630 static void host_lut_store(const void *lut)
2634 for (i = 0; i < N_GDC_ID; i++)
2635 gdc_lut_store((gdc_ID_t)i, (const int (*)[HRT_GDC_N]) lut);
2638 int ia_css_pipe_set_bci_scaler_lut(struct ia_css_pipe *pipe,
2642 bool stream_started = false;
2644 IA_CSS_ENTER("pipe=%p lut=%p", pipe, lut);
2646 if (!lut || !pipe) {
2648 IA_CSS_LEAVE("err=%d", err);
2652 /* If the pipe belongs to a stream and the stream has started, it is not
2653 * safe to store lut to gdc HW. If pipe->stream is NULL, then no stream is
2654 * created with this pipe, so it is safe to do this operation as long as
2655 * ia_css_init() has been called. */
2656 if (pipe->stream && pipe->stream->started) {
2657 ia_css_debug_dtrace(IA_CSS_DEBUG_ERROR,
2658 "unable to set scaler lut since stream has started\n");
2659 stream_started = true;
2663 /* Free any existing tables. */
2664 if (pipe->scaler_pp_lut != mmgr_NULL) {
2665 hmm_free(pipe->scaler_pp_lut);
2666 pipe->scaler_pp_lut = mmgr_NULL;
2669 if (!stream_started) {
2670 pipe->scaler_pp_lut = hmm_alloc(sizeof(zoom_table), HMM_BO_PRIVATE, 0, NULL, 0);
2672 if (pipe->scaler_pp_lut == mmgr_NULL) {
2673 ia_css_debug_dtrace(IA_CSS_DEBUG_ERROR,
2674 "unable to allocate scaler_pp_lut\n");
2677 gdc_lut_convert_to_isp_format((const int(*)[HRT_GDC_N])lut,
2678 interleaved_lut_temp);
2679 hmm_store(pipe->scaler_pp_lut,
2680 (int *)interleaved_lut_temp,
2681 sizeof(zoom_table));
2685 IA_CSS_LEAVE("lut(%u) err=%d", pipe->scaler_pp_lut, err);
2689 /* if pipe is NULL, returns default lut addr. */
2690 ia_css_ptr sh_css_pipe_get_pp_gdc_lut(const struct ia_css_pipe *pipe)
2694 if (pipe->scaler_pp_lut != mmgr_NULL)
2695 return pipe->scaler_pp_lut;
2697 return sh_css_params_get_default_gdc_lut();
2700 int sh_css_params_map_and_store_default_gdc_lut(void)
2704 IA_CSS_ENTER_PRIVATE("void");
2706 /* Is table already mapped? Nothing to do if it is mapped. */
2707 if (default_gdc_lut != mmgr_NULL)
2710 host_lut_store((void *)zoom_table);
2712 default_gdc_lut = hmm_alloc(sizeof(zoom_table), HMM_BO_PRIVATE, 0, NULL, 0);
2714 if (default_gdc_lut == mmgr_NULL)
2717 gdc_lut_convert_to_isp_format((const int(*)[HRT_GDC_N])zoom_table,
2718 interleaved_lut_temp);
2719 hmm_store(default_gdc_lut, (int *)interleaved_lut_temp,
2720 sizeof(zoom_table));
2722 IA_CSS_LEAVE_PRIVATE("lut(%u) err=%d", default_gdc_lut, err);
2726 void sh_css_params_free_default_gdc_lut(void)
2728 IA_CSS_ENTER_PRIVATE("void");
2730 if (default_gdc_lut != mmgr_NULL) {
2731 hmm_free(default_gdc_lut);
2732 default_gdc_lut = mmgr_NULL;
2735 IA_CSS_LEAVE_PRIVATE("void");
2738 ia_css_ptr sh_css_params_get_default_gdc_lut(void)
2740 return default_gdc_lut;
2743 static void free_param_set_callback(
2746 IA_CSS_ENTER_PRIVATE("void");
2748 free_ia_css_isp_parameter_set_info(ptr);
2750 IA_CSS_LEAVE_PRIVATE("void");
2753 static void free_buffer_callback(
2756 IA_CSS_ENTER_PRIVATE("void");
2760 IA_CSS_LEAVE_PRIVATE("void");
2764 sh_css_param_clear_param_sets(void)
2766 IA_CSS_ENTER_PRIVATE("void");
2768 ia_css_refcount_clear(IA_CSS_REFCOUNT_PARAM_SET_POOL, &free_param_set_callback);
2770 IA_CSS_LEAVE_PRIVATE("void");
2774 * MW: we can define hmm_free() to return a NULL
2775 * then you can write ptr = hmm_free(ptr);
2777 #define safe_free(id, x) \
2779 ia_css_refcount_decrement(id, x); \
2783 static void free_map(struct sh_css_ddr_address_map *map)
2787 ia_css_ptr *addrs = (ia_css_ptr *)map;
2789 IA_CSS_ENTER_PRIVATE("void");
2792 for (i = 0; i < (sizeof(struct sh_css_ddr_address_map_size) /
2793 sizeof(size_t)); i++) {
2794 if (addrs[i] == mmgr_NULL)
2796 safe_free(IA_CSS_REFCOUNT_PARAM_BUFFER, addrs[i]);
2799 IA_CSS_LEAVE_PRIVATE("void");
2803 ia_css_stream_isp_parameters_uninit(struct ia_css_stream *stream)
2806 struct ia_css_isp_parameters *params = stream->isp_params_configs;
2807 struct ia_css_isp_parameters *per_frame_params =
2808 stream->per_frame_isp_params_configs;
2810 IA_CSS_ENTER_PRIVATE("void");
2812 IA_CSS_LEAVE_PRIVATE("isp_param_configs is NULL");
2816 /* free existing ddr_ptr maps */
2817 for (i = 0; i < IA_CSS_PIPE_ID_NUM; i++) {
2818 free_map(¶ms->pipe_ddr_ptrs[i]);
2819 if (per_frame_params)
2820 free_map(&per_frame_params->pipe_ddr_ptrs[i]);
2821 /* Free up theDVS table memory blocks before recomputing new table */
2822 if (params->pipe_dvs_6axis_config[i])
2823 free_dvs_6axis_table(¶ms->pipe_dvs_6axis_config[i]);
2824 if (per_frame_params && per_frame_params->pipe_dvs_6axis_config[i])
2825 free_dvs_6axis_table(&per_frame_params->pipe_dvs_6axis_config[i]);
2827 free_map(¶ms->ddr_ptrs);
2828 if (per_frame_params)
2829 free_map(&per_frame_params->ddr_ptrs);
2831 if (params->fpn_config.data) {
2832 kvfree(params->fpn_config.data);
2833 params->fpn_config.data = NULL;
2836 /* Free up sc_config (temporal shading table) if it is allocated. */
2837 if (params->sc_config) {
2838 ia_css_shading_table_free(params->sc_config);
2839 params->sc_config = NULL;
2841 if (per_frame_params) {
2842 if (per_frame_params->sc_config) {
2843 ia_css_shading_table_free(per_frame_params->sc_config);
2844 per_frame_params->sc_config = NULL;
2849 kvfree(per_frame_params);
2850 stream->isp_params_configs = NULL;
2851 stream->per_frame_isp_params_configs = NULL;
2853 IA_CSS_LEAVE_PRIVATE("void");
2857 sh_css_params_uninit(void)
2861 IA_CSS_ENTER_PRIVATE("void");
2863 ia_css_refcount_decrement(-1, sp_ddr_ptrs);
2864 sp_ddr_ptrs = mmgr_NULL;
2865 ia_css_refcount_decrement(-1, xmem_sp_group_ptrs);
2866 xmem_sp_group_ptrs = mmgr_NULL;
2868 for (p = 0; p < IA_CSS_PIPE_ID_NUM; p++)
2869 for (i = 0; i < SH_CSS_MAX_STAGES; i++) {
2870 ia_css_refcount_decrement(-1, xmem_sp_stage_ptrs[p][i]);
2871 xmem_sp_stage_ptrs[p][i] = mmgr_NULL;
2872 ia_css_refcount_decrement(-1, xmem_isp_stage_ptrs[p][i]);
2873 xmem_isp_stage_ptrs[p][i] = mmgr_NULL;
2876 /* go through the pools to clear references */
2877 ia_css_refcount_clear(IA_CSS_REFCOUNT_PARAM_SET_POOL, &free_param_set_callback);
2878 ia_css_refcount_clear(IA_CSS_REFCOUNT_PARAM_BUFFER, &free_buffer_callback);
2879 ia_css_refcount_clear(-1, &free_buffer_callback);
2881 IA_CSS_LEAVE_PRIVATE("void");
2884 static struct ia_css_host_data *
2885 convert_allocate_morph_plane(
2886 unsigned short *data,
2888 unsigned int height,
2889 unsigned int aligned_width)
2891 unsigned int i, j, padding, w;
2892 struct ia_css_host_data *me;
2893 unsigned int isp_data_size;
2896 IA_CSS_ENTER_PRIVATE("void");
2898 /* currently we don't have morph table interpolation yet,
2899 * so we allow a wider table to be used. This will be removed
2901 if (width > aligned_width) {
2905 padding = aligned_width - width;
2908 isp_data_size = height * (w + padding) * sizeof(uint16_t);
2910 me = ia_css_host_data_allocate((size_t)isp_data_size);
2913 IA_CSS_LEAVE_ERR_PRIVATE(-ENOMEM);
2917 isp_data_ptr = (uint16_t *)me->address;
2919 memset(isp_data_ptr, 0, (size_t)isp_data_size);
2921 for (i = 0; i < height; i++) {
2922 for (j = 0; j < w; j++)
2923 *isp_data_ptr++ = (uint16_t)data[j];
2924 isp_data_ptr += padding;
2928 IA_CSS_LEAVE_PRIVATE("void");
2934 unsigned short *data,
2936 unsigned int height,
2938 unsigned int aligned_width)
2940 struct ia_css_host_data *isp_data;
2942 assert(dest != mmgr_NULL);
2944 isp_data = convert_allocate_morph_plane(data, width, height, aligned_width);
2946 IA_CSS_LEAVE_ERR_PRIVATE(-ENOMEM);
2949 ia_css_params_store_ia_css_host_data(dest, isp_data);
2951 ia_css_host_data_free(isp_data);
2955 static void sh_css_update_isp_params_to_ddr(
2956 struct ia_css_isp_parameters *params,
2959 size_t size = sizeof(params->uds);
2961 IA_CSS_ENTER_PRIVATE("void");
2965 hmm_store(ddr_ptr, ¶ms->uds, size);
2966 IA_CSS_LEAVE_PRIVATE("void");
2969 static void sh_css_update_isp_mem_params_to_ddr(
2970 const struct ia_css_binary *binary,
2971 ia_css_ptr ddr_mem_ptr,
2973 enum ia_css_isp_memories mem)
2975 const struct ia_css_host_data *params;
2977 IA_CSS_ENTER_PRIVATE("void");
2979 params = ia_css_isp_param_get_mem_init(&binary->mem_params,
2980 IA_CSS_PARAM_CLASS_PARAM, mem);
2981 hmm_store(ddr_mem_ptr, params->address, size);
2983 IA_CSS_LEAVE_PRIVATE("void");
2986 void ia_css_dequeue_param_buffers(/*unsigned int pipe_num*/ void)
2990 enum sh_css_queue_id param_queue_ids[3] = { IA_CSS_PARAMETER_SET_QUEUE_ID,
2991 IA_CSS_PER_FRAME_PARAMETER_SET_QUEUE_ID,
2992 SH_CSS_INVALID_QUEUE_ID
2995 IA_CSS_ENTER_PRIVATE("void");
2997 if (!sh_css_sp_is_running()) {
2998 IA_CSS_LEAVE_PRIVATE("sp is not running");
2999 /* SP is not running. The queues are not valid */
3003 for (i = 0; SH_CSS_INVALID_QUEUE_ID != param_queue_ids[i]; i++) {
3004 cpy = (ia_css_ptr)0;
3005 /* clean-up old copy */
3006 while (ia_css_bufq_dequeue_buffer(param_queue_ids[i],
3007 (uint32_t *)&cpy) == 0) {
3008 /* TMP: keep track of dequeued param set count
3010 g_param_buffer_dequeue_count++;
3011 ia_css_bufq_enqueue_psys_event(
3012 IA_CSS_PSYS_SW_EVENT_BUFFER_DEQUEUED,
3017 IA_CSS_LOG("dequeued param set %x from %d, release ref", cpy, 0);
3018 free_ia_css_isp_parameter_set_info(cpy);
3019 cpy = (ia_css_ptr)0;
3023 IA_CSS_LEAVE_PRIVATE("void");
3027 process_kernel_parameters(unsigned int pipe_id,
3028 struct ia_css_pipeline_stage *stage,
3029 struct ia_css_isp_parameters *params,
3030 unsigned int isp_pipe_version,
3031 unsigned int raw_bit_depth)
3033 unsigned int param_id;
3035 (void)isp_pipe_version;
3036 (void)raw_bit_depth;
3038 sh_css_enable_pipeline(stage->binary);
3040 if (params->config_changed[IA_CSS_OB_ID]) {
3041 ia_css_ob_configure(¶ms->stream_configs.ob,
3042 isp_pipe_version, raw_bit_depth);
3044 if (params->config_changed[IA_CSS_S3A_ID]) {
3045 ia_css_s3a_configure(raw_bit_depth);
3047 /* Copy stage uds parameters to config, since they can differ per stage.
3049 params->crop_config.crop_pos = params->uds[stage->stage_num].crop_pos;
3050 params->uds_config.crop_pos = params->uds[stage->stage_num].crop_pos;
3051 params->uds_config.uds = params->uds[stage->stage_num].uds;
3052 /* Call parameter process functions for all kernels */
3053 /* Skip SC, since that is called on a temp sc table */
3054 for (param_id = 0; param_id < IA_CSS_NUM_PARAMETER_IDS; param_id++) {
3055 if (param_id == IA_CSS_SC_ID) continue;
3056 if (params->config_changed[param_id])
3057 ia_css_kernel_process_param[param_id](pipe_id, stage, params);
3062 sh_css_param_update_isp_params(struct ia_css_pipe *curr_pipe,
3063 struct ia_css_isp_parameters *params,
3065 struct ia_css_pipe *pipe_in)
3070 unsigned int raw_bit_depth = 10;
3071 unsigned int isp_pipe_version = SH_CSS_ISP_PIPE_VERSION_1;
3072 bool acc_cluster_params_changed = false;
3073 unsigned int thread_id, pipe_num;
3075 (void)acc_cluster_params_changed;
3079 IA_CSS_ENTER_PRIVATE("pipe=%p, isp_parameters_id=%d", pipe_in, params->isp_parameters_id);
3080 raw_bit_depth = ia_css_stream_input_format_bits_per_pixel(curr_pipe->stream);
3082 /* now make the map available to the sp */
3084 IA_CSS_LEAVE_ERR_PRIVATE(err);
3087 /* enqueue a copies of the mem_map to
3088 the designated pipelines */
3089 for (i = 0; i < curr_pipe->stream->num_pipes; i++) {
3090 struct ia_css_pipe *pipe;
3091 struct sh_css_ddr_address_map *cur_map;
3092 struct sh_css_ddr_address_map_size *cur_map_size;
3093 struct ia_css_isp_parameter_set_info isp_params_info;
3094 struct ia_css_pipeline *pipeline;
3095 struct ia_css_pipeline_stage *stage;
3097 enum sh_css_queue_id queue_id;
3099 pipe = curr_pipe->stream->pipes[i];
3100 pipeline = ia_css_pipe_get_pipeline(pipe);
3101 pipe_num = ia_css_pipe_get_pipe_num(pipe);
3102 isp_pipe_version = ia_css_pipe_get_isp_pipe_version(pipe);
3103 ia_css_pipeline_get_sp_thread_id(pipe_num, &thread_id);
3105 ia_css_query_internal_queue_id(params->output_frame
3106 ? IA_CSS_BUFFER_TYPE_PER_FRAME_PARAMETER_SET
3107 : IA_CSS_BUFFER_TYPE_PARAMETER_SET,
3108 thread_id, &queue_id);
3109 if (!sh_css_sp_is_running()) {
3110 /* SP is not running. The queues are not valid */
3114 cur_map = ¶ms->pipe_ddr_ptrs[pipeline->pipe_id];
3115 cur_map_size = ¶ms->pipe_ddr_ptrs_size[pipeline->pipe_id];
3117 /* TODO: Normally, zoom and motion parameters shouldn't
3118 * be part of "isp_params" as it is resolution/pipe dependent
3119 * Therefore, move the zoom config elsewhere (e.g. shading
3120 * table can be taken as an example! @GC
3123 /* we have to do this per pipeline because */
3124 /* the processing is a.o. resolution dependent */
3125 err = ia_css_process_zoom_and_motion(params,
3130 /* check if to actually update the parameters for this pipe */
3131 /* When API change is implemented making good distinction between
3132 * stream config and pipe config this skipping code can be moved out of the #ifdef */
3133 if (pipe_in && (pipe != pipe_in)) {
3134 IA_CSS_LOG("skipping pipe %p", pipe);
3138 /* BZ 125915, should be moved till after "update other buff" */
3139 /* update the other buffers to the pipe specific copies */
3140 for (stage = pipeline->stages; stage; stage = stage->next) {
3143 if (!stage || !stage->binary)
3146 process_kernel_parameters(pipeline->pipe_id,
3148 isp_pipe_version, raw_bit_depth);
3150 err = sh_css_params_write_to_ddr_internal(
3160 for (mem = 0; mem < IA_CSS_NUM_MEMORIES; mem++) {
3161 params->isp_mem_params_changed
3162 [pipeline->pipe_id][stage->stage_num][mem] = false;
3167 /* update isp_params to pipe specific copies */
3168 if (params->isp_params_changed) {
3169 reallocate_buffer(&cur_map->isp_param,
3170 &cur_map_size->isp_param,
3171 cur_map_size->isp_param,
3176 sh_css_update_isp_params_to_ddr(params, cur_map->isp_param);
3179 /* last make referenced copy */
3180 err = ref_sh_css_ddr_address_map(
3182 &isp_params_info.mem_map);
3186 /* Update Parameters ID */
3187 isp_params_info.isp_parameters_id = params->isp_parameters_id;
3189 /* Update output frame pointer */
3190 isp_params_info.output_frame_ptr =
3191 (params->output_frame) ? params->output_frame->data : mmgr_NULL;
3193 /* now write the copy to ddr */
3194 err = write_ia_css_isp_parameter_set_info_to_ddr(&isp_params_info, &cpy);
3198 /* enqueue the set to sp */
3199 IA_CSS_LOG("queue param set %x to %d", cpy, thread_id);
3201 err = ia_css_bufq_enqueue_buffer(thread_id, queue_id, (uint32_t)cpy);
3203 free_ia_css_isp_parameter_set_info(cpy);
3204 IA_CSS_LOG("pfp: FAILED to add config id %d for OF %d to q %d on thread %d",
3205 isp_params_info.isp_parameters_id,
3206 isp_params_info.output_frame_ptr,
3207 queue_id, thread_id);
3210 /* TMP: check discrepancy between nr of enqueued
3211 * parameter sets and dequeued sets
3213 g_param_buffer_enqueue_count++;
3214 assert(g_param_buffer_enqueue_count < g_param_buffer_dequeue_count + 50);
3216 * Tell the SP which queues are not empty,
3217 * by sending the software event.
3219 if (!sh_css_sp_is_running()) {
3220 /* SP is not running. The queues are not valid */
3221 IA_CSS_LEAVE_ERR_PRIVATE(-EBUSY);
3224 ia_css_bufq_enqueue_psys_event(
3225 IA_CSS_PSYS_SW_EVENT_BUFFER_ENQUEUED,
3229 IA_CSS_LOG("pfp: added config id %d for OF %d to q %d on thread %d",
3230 isp_params_info.isp_parameters_id,
3231 isp_params_info.output_frame_ptr,
3232 queue_id, thread_id);
3234 /* clean-up old copy */
3235 ia_css_dequeue_param_buffers(/*pipe_num*/);
3236 params->pipe_dvs_6axis_config_changed[pipeline->pipe_id] = false;
3237 } /* end for each 'active' pipeline */
3238 /* clear the changed flags after all params
3239 for all pipelines have been updated */
3240 params->isp_params_changed = false;
3241 params->sc_table_changed = false;
3242 params->dis_coef_table_changed = false;
3243 params->dvs2_coef_table_changed = false;
3244 params->morph_table_changed = false;
3245 params->dz_config_changed = false;
3246 params->motion_config_changed = false;
3247 /* ------ deprecated(bz675) : from ------ */
3248 params->shading_settings_changed = false;
3249 /* ------ deprecated(bz675) : to ------ */
3251 memset(¶ms->config_changed[0], 0, sizeof(params->config_changed));
3253 IA_CSS_LEAVE_ERR_PRIVATE(err);
3258 sh_css_params_write_to_ddr_internal(
3259 struct ia_css_pipe *pipe,
3260 unsigned int pipe_id,
3261 struct ia_css_isp_parameters *params,
3262 const struct ia_css_pipeline_stage *stage,
3263 struct sh_css_ddr_address_map *ddr_map,
3264 struct sh_css_ddr_address_map_size *ddr_map_size)
3267 const struct ia_css_binary *binary;
3269 unsigned int stage_num;
3271 bool buff_realloced;
3273 /* struct is > 128 bytes so it should not be on stack (see checkpatch) */
3274 static struct ia_css_macc_table converted_macc_table;
3276 IA_CSS_ENTER_PRIVATE("void");
3279 assert(ddr_map_size);
3282 binary = stage->binary;
3285 stage_num = stage->stage_num;
3287 if (binary->info->sp.enable.fpnr) {
3288 buff_realloced = reallocate_buffer(&ddr_map->fpn_tbl,
3289 &ddr_map_size->fpn_tbl,
3290 (size_t)(FPNTBL_BYTES(binary)),
3291 params->config_changed[IA_CSS_FPN_ID],
3294 IA_CSS_LEAVE_ERR_PRIVATE(err);
3297 if (params->config_changed[IA_CSS_FPN_ID] || buff_realloced) {
3298 if (params->fpn_config.enabled) {
3299 err = store_fpntbl(params, ddr_map->fpn_tbl);
3301 IA_CSS_LEAVE_ERR_PRIVATE(err);
3308 if (binary->info->sp.enable.sc) {
3311 enable_conv = params->shading_settings.enable_shading_table_conversion;
3313 buff_realloced = reallocate_buffer(&ddr_map->sc_tbl,
3314 &ddr_map_size->sc_tbl,
3315 SCTBL_BYTES(binary),
3316 params->sc_table_changed,
3319 IA_CSS_LEAVE_ERR_PRIVATE(err);
3323 if (params->shading_settings_changed ||
3324 params->sc_table_changed || buff_realloced) {
3325 if (enable_conv == 0) {
3326 if (params->sc_table) {
3327 /* store the shading table to ddr */
3328 err = ia_css_params_store_sctbl(stage, ddr_map->sc_tbl, params->sc_table);
3330 IA_CSS_LEAVE_ERR_PRIVATE(err);
3333 /* set sc_config to isp */
3334 params->sc_config = (struct ia_css_shading_table *)params->sc_table;
3335 ia_css_kernel_process_param[IA_CSS_SC_ID](pipe_id, stage, params);
3336 params->sc_config = NULL;
3338 /* generate the identical shading table */
3339 if (params->sc_config) {
3340 ia_css_shading_table_free(params->sc_config);
3341 params->sc_config = NULL;
3343 sh_css_params_shading_id_table_generate(¶ms->sc_config,
3344 binary->sctbl_width_per_color,
3345 binary->sctbl_height);
3346 if (!params->sc_config) {
3347 IA_CSS_LEAVE_ERR_PRIVATE(-ENOMEM);
3351 /* store the shading table to ddr */
3352 err = ia_css_params_store_sctbl(stage, ddr_map->sc_tbl, params->sc_config);
3354 IA_CSS_LEAVE_ERR_PRIVATE(err);
3358 /* set sc_config to isp */
3359 ia_css_kernel_process_param[IA_CSS_SC_ID](pipe_id, stage, params);
3361 /* free the shading table */
3362 ia_css_shading_table_free(params->sc_config);
3363 params->sc_config = NULL;
3365 } else { /* legacy */
3366 /* ------ deprecated(bz675) : from ------ */
3367 /* shading table is full resolution, reduce */
3368 if (params->sc_config) {
3369 ia_css_shading_table_free(params->sc_config);
3370 params->sc_config = NULL;
3372 prepare_shading_table(
3373 (const struct ia_css_shading_table *)params->sc_table,
3374 params->sensor_binning,
3376 binary, pipe->required_bds_factor);
3377 if (!params->sc_config) {
3378 IA_CSS_LEAVE_ERR_PRIVATE(-ENOMEM);
3382 /* store the shading table to ddr */
3383 err = ia_css_params_store_sctbl(stage, ddr_map->sc_tbl, params->sc_config);
3385 IA_CSS_LEAVE_ERR_PRIVATE(err);
3389 /* set sc_config to isp */
3390 ia_css_kernel_process_param[IA_CSS_SC_ID](pipe_id, stage, params);
3392 /* free the shading table */
3393 ia_css_shading_table_free(params->sc_config);
3394 params->sc_config = NULL;
3395 /* ------ deprecated(bz675) : to ------ */
3400 if (params->config_changed[IA_CSS_MACC_ID] && binary->info->sp.enable.macc) {
3401 unsigned int i, j, idx;
3402 static const unsigned int idx_map[] = {
3403 0, 1, 3, 2, 6, 7, 5, 4, 12, 13, 15, 14, 10, 11, 9, 8
3406 for (i = 0; i < IA_CSS_MACC_NUM_AXES; i++) {
3407 idx = 4 * idx_map[i];
3410 if (binary->info->sp.pipeline.isp_pipe_version == SH_CSS_ISP_PIPE_VERSION_1) {
3411 converted_macc_table.data[idx] =
3412 (int16_t)sDIGIT_FITTING(params->macc_table.data[j],
3413 13, SH_CSS_MACC_COEF_SHIFT);
3414 converted_macc_table.data[idx + 1] =
3415 (int16_t)sDIGIT_FITTING(params->macc_table.data[j + 1],
3416 13, SH_CSS_MACC_COEF_SHIFT);
3417 converted_macc_table.data[idx + 2] =
3418 (int16_t)sDIGIT_FITTING(params->macc_table.data[j + 2],
3419 13, SH_CSS_MACC_COEF_SHIFT);
3420 converted_macc_table.data[idx + 3] =
3421 (int16_t)sDIGIT_FITTING(params->macc_table.data[j + 3],
3422 13, SH_CSS_MACC_COEF_SHIFT);
3423 } else if (binary->info->sp.pipeline.isp_pipe_version ==
3424 SH_CSS_ISP_PIPE_VERSION_2_2) {
3425 converted_macc_table.data[idx] =
3426 params->macc_table.data[j];
3427 converted_macc_table.data[idx + 1] =
3428 params->macc_table.data[j + 1];
3429 converted_macc_table.data[idx + 2] =
3430 params->macc_table.data[j + 2];
3431 converted_macc_table.data[idx + 3] =
3432 params->macc_table.data[j + 3];
3435 reallocate_buffer(&ddr_map->macc_tbl,
3436 &ddr_map_size->macc_tbl,
3437 ddr_map_size->macc_tbl,
3441 IA_CSS_LEAVE_ERR_PRIVATE(err);
3444 hmm_store(ddr_map->macc_tbl,
3445 converted_macc_table.data,
3446 sizeof(converted_macc_table.data));
3449 if (binary->info->sp.enable.dvs_6axis) {
3450 /* because UV is packed into the Y plane, calc total
3451 * YYU size = /2 gives size of UV-only,
3452 * total YYU size = UV-only * 3.
3454 buff_realloced = reallocate_buffer(
3455 &ddr_map->dvs_6axis_params_y,
3456 &ddr_map_size->dvs_6axis_params_y,
3457 (size_t)((DVS_6AXIS_BYTES(binary) / 2) * 3),
3458 params->pipe_dvs_6axis_config_changed[pipe_id],
3461 IA_CSS_LEAVE_ERR_PRIVATE(err);
3465 if (params->pipe_dvs_6axis_config_changed[pipe_id] || buff_realloced) {
3466 const struct ia_css_frame_info *dvs_in_frame_info;
3468 if (stage->args.delay_frames[0]) {
3469 /*When delay frames are present(as in case of video),
3470 they are used for dvs. Configure DVS using those params*/
3471 dvs_in_frame_info = &stage->args.delay_frames[0]->info;
3473 /*Otherwise, use input frame to configure DVS*/
3474 dvs_in_frame_info = &stage->args.in_frame->info;
3477 /* Generate default DVS unity table on start up*/
3478 if (!params->pipe_dvs_6axis_config[pipe_id]) {
3479 struct ia_css_resolution dvs_offset = {0};
3481 dvs_offset.width = (PIX_SHIFT_FILTER_RUN_IN_X + binary->dvs_envelope.width) / 2;
3482 dvs_offset.height = (PIX_SHIFT_FILTER_RUN_IN_Y + binary->dvs_envelope.height) / 2;
3484 params->pipe_dvs_6axis_config[pipe_id] =
3485 generate_dvs_6axis_table(&binary->out_frame_info[0].res, &dvs_offset);
3486 if (!params->pipe_dvs_6axis_config[pipe_id]) {
3487 IA_CSS_LEAVE_ERR_PRIVATE(-ENOMEM);
3490 params->pipe_dvs_6axis_config_changed[pipe_id] = true;
3492 store_dvs_6axis_config(params->pipe_dvs_6axis_config[pipe_id],
3495 ddr_map->dvs_6axis_params_y);
3496 params->isp_params_changed = true;
3501 if (binary->info->sp.enable.ca_gdc) {
3503 ia_css_ptr *virt_addr_tetra_x[
3505 IA_CSS_MORPH_TABLE_NUM_PLANES];
3506 size_t *virt_size_tetra_x[
3508 IA_CSS_MORPH_TABLE_NUM_PLANES];
3509 ia_css_ptr *virt_addr_tetra_y[
3511 IA_CSS_MORPH_TABLE_NUM_PLANES];
3512 size_t *virt_size_tetra_y[
3514 IA_CSS_MORPH_TABLE_NUM_PLANES];
3516 virt_addr_tetra_x[0] = &ddr_map->tetra_r_x;
3517 virt_addr_tetra_x[1] = &ddr_map->tetra_gr_x;
3518 virt_addr_tetra_x[2] = &ddr_map->tetra_gb_x;
3519 virt_addr_tetra_x[3] = &ddr_map->tetra_b_x;
3520 virt_addr_tetra_x[4] = &ddr_map->tetra_ratb_x;
3521 virt_addr_tetra_x[5] = &ddr_map->tetra_batr_x;
3523 virt_size_tetra_x[0] = &ddr_map_size->tetra_r_x;
3524 virt_size_tetra_x[1] = &ddr_map_size->tetra_gr_x;
3525 virt_size_tetra_x[2] = &ddr_map_size->tetra_gb_x;
3526 virt_size_tetra_x[3] = &ddr_map_size->tetra_b_x;
3527 virt_size_tetra_x[4] = &ddr_map_size->tetra_ratb_x;
3528 virt_size_tetra_x[5] = &ddr_map_size->tetra_batr_x;
3530 virt_addr_tetra_y[0] = &ddr_map->tetra_r_y;
3531 virt_addr_tetra_y[1] = &ddr_map->tetra_gr_y;
3532 virt_addr_tetra_y[2] = &ddr_map->tetra_gb_y;
3533 virt_addr_tetra_y[3] = &ddr_map->tetra_b_y;
3534 virt_addr_tetra_y[4] = &ddr_map->tetra_ratb_y;
3535 virt_addr_tetra_y[5] = &ddr_map->tetra_batr_y;
3537 virt_size_tetra_y[0] = &ddr_map_size->tetra_r_y;
3538 virt_size_tetra_y[1] = &ddr_map_size->tetra_gr_y;
3539 virt_size_tetra_y[2] = &ddr_map_size->tetra_gb_y;
3540 virt_size_tetra_y[3] = &ddr_map_size->tetra_b_y;
3541 virt_size_tetra_y[4] = &ddr_map_size->tetra_ratb_y;
3542 virt_size_tetra_y[5] = &ddr_map_size->tetra_batr_y;
3544 buff_realloced = false;
3545 for (i = 0; i < IA_CSS_MORPH_TABLE_NUM_PLANES; i++) {
3547 reallocate_buffer(virt_addr_tetra_x[i],
3548 virt_size_tetra_x[i],
3550 (MORPH_PLANE_BYTES(binary)),
3551 params->morph_table_changed,
3554 IA_CSS_LEAVE_ERR_PRIVATE(err);
3558 reallocate_buffer(virt_addr_tetra_y[i],
3559 virt_size_tetra_y[i],
3561 (MORPH_PLANE_BYTES(binary)),
3562 params->morph_table_changed,
3565 IA_CSS_LEAVE_ERR_PRIVATE(err);
3569 if (params->morph_table_changed || buff_realloced) {
3570 const struct ia_css_morph_table *table = params->morph_table;
3571 struct ia_css_morph_table *id_table = NULL;
3574 (table->width < binary->morph_tbl_width ||
3575 table->height < binary->morph_tbl_height)) {
3579 err = sh_css_params_default_morph_table(&id_table,
3582 IA_CSS_LEAVE_ERR_PRIVATE(err);
3588 for (i = 0; i < IA_CSS_MORPH_TABLE_NUM_PLANES; i++) {
3589 store_morph_plane(table->coordinates_x[i],
3592 *virt_addr_tetra_x[i],
3593 binary->morph_tbl_aligned_width);
3594 store_morph_plane(table->coordinates_y[i],
3597 *virt_addr_tetra_y[i],
3598 binary->morph_tbl_aligned_width);
3601 ia_css_morph_table_free(id_table);
3605 /* After special cases like SC, FPN since they may change parameters */
3606 for (mem = 0; mem < N_IA_CSS_MEMORIES; mem++) {
3607 const struct ia_css_isp_data *isp_data =
3608 ia_css_isp_param_get_isp_mem_init(&binary->info->sp.mem_initializers,
3609 IA_CSS_PARAM_CLASS_PARAM, mem);
3610 size_t size = isp_data->size;
3612 if (!size) continue;
3613 buff_realloced = reallocate_buffer(&ddr_map->isp_mem_param[stage_num][mem],
3614 &ddr_map_size->isp_mem_param[stage_num][mem],
3616 params->isp_mem_params_changed[pipe_id][stage_num][mem],
3619 IA_CSS_LEAVE_ERR_PRIVATE(err);
3622 if (params->isp_mem_params_changed[pipe_id][stage_num][mem] || buff_realloced) {
3623 sh_css_update_isp_mem_params_to_ddr(binary,
3624 ddr_map->isp_mem_param[stage_num][mem],
3625 ddr_map_size->isp_mem_param[stage_num][mem], mem);
3629 IA_CSS_LEAVE_ERR_PRIVATE(0);
3633 const struct ia_css_fpn_table *ia_css_get_fpn_table(struct ia_css_stream
3636 struct ia_css_isp_parameters *params;
3638 IA_CSS_ENTER_LEAVE("void");
3641 params = stream->isp_params_configs;
3643 return ¶ms->fpn_config;
3646 struct ia_css_shading_table *ia_css_get_shading_table(struct ia_css_stream
3649 struct ia_css_shading_table *table = NULL;
3650 struct ia_css_isp_parameters *params;
3652 IA_CSS_ENTER("void");
3656 params = stream->isp_params_configs;
3660 if (params->shading_settings.enable_shading_table_conversion == 0) {
3661 if (params->sc_table) {
3662 table = (struct ia_css_shading_table *)params->sc_table;
3664 const struct ia_css_binary *binary
3665 = ia_css_stream_get_shading_correction_binary(stream);
3667 /* generate the identical shading table */
3668 if (params->sc_config) {
3669 ia_css_shading_table_free(params->sc_config);
3670 params->sc_config = NULL;
3672 sh_css_params_shading_id_table_generate(¶ms->sc_config,
3673 binary->sctbl_width_per_color,
3674 binary->sctbl_height);
3675 table = params->sc_config;
3676 /* The sc_config will be freed in the
3677 * ia_css_stream_isp_parameters_uninit function. */
3681 /* ------ deprecated(bz675) : from ------ */
3682 const struct ia_css_binary *binary
3683 = ia_css_stream_get_shading_correction_binary(stream);
3684 struct ia_css_pipe *pipe;
3686 /**********************************************************************/
3687 /* following code is copied from function ia_css_stream_get_shading_correction_binary()
3688 * to match with the binary */
3689 pipe = stream->pipes[0];
3691 if (stream->num_pipes == 2) {
3692 assert(stream->pipes[1]);
3693 if (stream->pipes[1]->config.mode == IA_CSS_PIPE_MODE_VIDEO ||
3694 stream->pipes[1]->config.mode == IA_CSS_PIPE_MODE_PREVIEW)
3695 pipe = stream->pipes[1];
3697 /**********************************************************************/
3699 if (params->sc_config) {
3700 ia_css_shading_table_free(params->sc_config);
3701 params->sc_config = NULL;
3703 prepare_shading_table(
3704 (const struct ia_css_shading_table *)params->sc_table,
3705 params->sensor_binning,
3707 binary, pipe->required_bds_factor);
3709 table = params->sc_config;
3710 /* The sc_config will be freed in the
3711 * ia_css_stream_isp_parameters_uninit function. */
3713 /* ------ deprecated(bz675) : to ------ */
3716 IA_CSS_LEAVE("table=%p", table);
3721 ia_css_ptr sh_css_store_sp_group_to_ddr(void)
3723 IA_CSS_ENTER_LEAVE_PRIVATE("void");
3724 hmm_store(xmem_sp_group_ptrs,
3726 sizeof(struct sh_css_sp_group));
3727 return xmem_sp_group_ptrs;
3730 ia_css_ptr sh_css_store_sp_stage_to_ddr(
3734 IA_CSS_ENTER_LEAVE_PRIVATE("void");
3735 hmm_store(xmem_sp_stage_ptrs[pipe][stage],
3737 sizeof(struct sh_css_sp_stage));
3738 return xmem_sp_stage_ptrs[pipe][stage];
3741 ia_css_ptr sh_css_store_isp_stage_to_ddr(
3745 IA_CSS_ENTER_LEAVE_PRIVATE("void");
3746 hmm_store(xmem_isp_stage_ptrs[pipe][stage],
3748 sizeof(struct sh_css_isp_stage));
3749 return xmem_isp_stage_ptrs[pipe][stage];
3752 static int ref_sh_css_ddr_address_map(
3753 struct sh_css_ddr_address_map *map,
3754 struct sh_css_ddr_address_map *out)
3759 /* we will use a union to copy things; overlaying an array
3760 with the struct; that way adding fields in the struct
3761 will keep things working, and we will not get type errors.
3764 struct sh_css_ddr_address_map *map;
3766 } in_addrs, to_addrs;
3768 IA_CSS_ENTER_PRIVATE("void");
3775 assert(sizeof(struct sh_css_ddr_address_map_size) / sizeof(size_t) ==
3776 sizeof(struct sh_css_ddr_address_map) / sizeof(ia_css_ptr));
3778 /* copy map using size info */
3779 for (i = 0; i < (sizeof(struct sh_css_ddr_address_map_size) /
3780 sizeof(size_t)); i++) {
3781 if (in_addrs.addrs[i] == mmgr_NULL)
3782 to_addrs.addrs[i] = mmgr_NULL;
3784 to_addrs.addrs[i] = ia_css_refcount_increment(IA_CSS_REFCOUNT_PARAM_BUFFER,
3788 IA_CSS_LEAVE_ERR_PRIVATE(err);
3792 static int write_ia_css_isp_parameter_set_info_to_ddr(
3793 struct ia_css_isp_parameter_set_info *me,
3799 IA_CSS_ENTER_PRIVATE("void");
3804 *out = ia_css_refcount_increment(IA_CSS_REFCOUNT_PARAM_SET_POOL,
3805 hmm_alloc(sizeof(struct ia_css_isp_parameter_set_info), HMM_BO_PRIVATE, 0, NULL, 0));
3806 succ = (*out != mmgr_NULL);
3809 me, sizeof(struct ia_css_isp_parameter_set_info));
3813 IA_CSS_LEAVE_ERR_PRIVATE(err);
3818 free_ia_css_isp_parameter_set_info(
3822 struct ia_css_isp_parameter_set_info isp_params_info;
3824 ia_css_ptr *addrs = (ia_css_ptr *)&isp_params_info.mem_map;
3826 IA_CSS_ENTER_PRIVATE("ptr = %u", ptr);
3828 /* sanity check - ptr must be valid */
3829 if (!ia_css_refcount_is_valid(ptr)) {
3830 IA_CSS_ERROR("%s: IA_CSS_REFCOUNT_PARAM_SET_POOL(0x%x) invalid arg", __func__,
3833 IA_CSS_LEAVE_ERR_PRIVATE(err);
3837 hmm_load(ptr, &isp_params_info.mem_map, sizeof(struct sh_css_ddr_address_map));
3838 /* copy map using size info */
3839 for (i = 0; i < (sizeof(struct sh_css_ddr_address_map_size) /
3840 sizeof(size_t)); i++) {
3841 if (addrs[i] == mmgr_NULL)
3844 /* sanity check - ptr must be valid */
3845 if (!ia_css_refcount_is_valid(addrs[i])) {
3846 IA_CSS_ERROR("%s: IA_CSS_REFCOUNT_PARAM_BUFFER(0x%x) invalid arg", __func__,
3852 ia_css_refcount_decrement(IA_CSS_REFCOUNT_PARAM_BUFFER, addrs[i]);
3854 ia_css_refcount_decrement(IA_CSS_REFCOUNT_PARAM_SET_POOL, ptr);
3856 IA_CSS_LEAVE_ERR_PRIVATE(err);
3860 /* Mark all parameters as changed to force recomputing the derived ISP parameters */
3862 sh_css_invalidate_params(struct ia_css_stream *stream)
3864 struct ia_css_isp_parameters *params;
3865 unsigned int i, j, mem;
3867 IA_CSS_ENTER_PRIVATE("void");
3870 params = stream->isp_params_configs;
3871 params->isp_params_changed = true;
3872 for (i = 0; i < IA_CSS_PIPE_ID_NUM; i++) {
3873 for (j = 0; j < SH_CSS_MAX_STAGES; j++) {
3874 for (mem = 0; mem < N_IA_CSS_MEMORIES; mem++) {
3875 params->isp_mem_params_changed[i][j][mem] = true;
3880 memset(¶ms->config_changed[0], 1, sizeof(params->config_changed));
3881 params->dis_coef_table_changed = true;
3882 params->dvs2_coef_table_changed = true;
3883 params->morph_table_changed = true;
3884 params->sc_table_changed = true;
3885 params->dz_config_changed = true;
3886 params->motion_config_changed = true;
3888 /*Free up theDVS table memory blocks before recomputing new table */
3889 for (i = 0; i < IA_CSS_PIPE_ID_NUM; i++) {
3890 if (params->pipe_dvs_6axis_config[i]) {
3891 free_dvs_6axis_table(¶ms->pipe_dvs_6axis_config[i]);
3892 params->pipe_dvs_6axis_config_changed[i] = true;
3896 IA_CSS_LEAVE_PRIVATE("void");
3900 sh_css_update_uds_and_crop_info(
3901 const struct ia_css_binary_info *info,
3902 const struct ia_css_frame_info *in_frame_info,
3903 const struct ia_css_frame_info *out_frame_info,
3904 const struct ia_css_resolution *dvs_env,
3905 const struct ia_css_dz_config *zoom,
3906 const struct ia_css_vector *motion_vector,
3907 struct sh_css_uds_info *uds, /* out */
3908 struct sh_css_crop_pos *sp_out_crop_pos, /* out */
3912 IA_CSS_ENTER_PRIVATE("void");
3915 assert(in_frame_info);
3916 assert(out_frame_info);
3919 assert(motion_vector);
3921 assert(sp_out_crop_pos);
3923 uds->curr_dx = enable_zoom ? (uint16_t)zoom->dx : HRT_GDC_N;
3924 uds->curr_dy = enable_zoom ? (uint16_t)zoom->dy : HRT_GDC_N;
3926 if (info->enable.dvs_envelope) {
3927 unsigned int crop_x = 0,
3931 env_width, env_height;
3932 int half_env_x, half_env_y;
3933 int motion_x = motion_vector->x;
3934 int motion_y = motion_vector->y;
3935 bool upscale_x = in_frame_info->res.width < out_frame_info->res.width;
3936 bool upscale_y = in_frame_info->res.height < out_frame_info->res.height;
3938 if (info->enable.uds && !info->enable.ds) {
3940 * we calculate with the envelope that we can actually
3941 * use, the min dvs envelope is for the filter
3944 env_width = dvs_env->width -
3945 SH_CSS_MIN_DVS_ENVELOPE;
3946 env_height = dvs_env->height -
3947 SH_CSS_MIN_DVS_ENVELOPE;
3948 half_env_x = env_width / 2;
3949 half_env_y = env_height / 2;
3951 * for digital zoom, we use the dvs envelope and make
3952 * sure that we don't include the 8 leftmost pixels or
3956 uds_xc = (in_frame_info->res.width
3958 + SH_CSS_MIN_DVS_ENVELOPE) / 2;
3960 uds_xc = (out_frame_info->res.width
3962 + SH_CSS_MIN_DVS_ENVELOPE;
3965 uds_yc = (in_frame_info->res.height
3967 + SH_CSS_MIN_DVS_ENVELOPE) / 2;
3969 uds_yc = (out_frame_info->res.height
3971 + SH_CSS_MIN_DVS_ENVELOPE;
3973 /* clip the motion vector to +/- half the envelope */
3974 motion_x = clamp(motion_x, -half_env_x, half_env_x);
3975 motion_y = clamp(motion_y, -half_env_y, half_env_y);
3978 /* uds can be pipelined, remove top lines */
3980 } else if (info->enable.ds) {
3981 env_width = dvs_env->width;
3982 env_height = dvs_env->height;
3983 half_env_x = env_width / 2;
3984 half_env_y = env_height / 2;
3985 /* clip the motion vector to +/- half the envelope */
3986 motion_x = clamp(motion_x, -half_env_x, half_env_x);
3987 motion_y = clamp(motion_y, -half_env_y, half_env_y);
3988 /* for video with downscaling, the envelope is included
3989 in the input resolution. */
3990 uds_xc = in_frame_info->res.width / 2 + motion_x;
3991 uds_yc = in_frame_info->res.height / 2 + motion_y;
3992 crop_x = info->pipeline.left_cropping;
3993 /* ds == 2 (yuv_ds) can be pipelined, remove top
3995 if (info->enable.ds & 1)
3996 crop_y = info->pipeline.top_cropping;
4000 /* video nodz: here we can only crop. We make sure we
4001 crop at least the first 8x8 pixels away. */
4002 env_width = dvs_env->width -
4003 SH_CSS_MIN_DVS_ENVELOPE;
4004 env_height = dvs_env->height -
4005 SH_CSS_MIN_DVS_ENVELOPE;
4006 half_env_x = env_width / 2;
4007 half_env_y = env_height / 2;
4008 motion_x = clamp(motion_x, -half_env_x, half_env_x);
4009 motion_y = clamp(motion_y, -half_env_y, half_env_y);
4010 crop_x = SH_CSS_MIN_DVS_ENVELOPE
4011 + half_env_x + motion_x;
4012 crop_y = SH_CSS_MIN_DVS_ENVELOPE
4013 + half_env_y + motion_y;
4016 /* Must enforce that the crop position is even */
4017 crop_x = EVEN_FLOOR(crop_x);
4018 crop_y = EVEN_FLOOR(crop_y);
4019 uds_xc = EVEN_FLOOR(uds_xc);
4020 uds_yc = EVEN_FLOOR(uds_yc);
4022 uds->xc = (uint16_t)uds_xc;
4023 uds->yc = (uint16_t)uds_yc;
4024 sp_out_crop_pos->x = (uint16_t)crop_x;
4025 sp_out_crop_pos->y = (uint16_t)crop_y;
4027 /* for down scaling, we always use the center of the image */
4028 uds->xc = (uint16_t)in_frame_info->res.width / 2;
4029 uds->yc = (uint16_t)in_frame_info->res.height / 2;
4030 sp_out_crop_pos->x = (uint16_t)info->pipeline.left_cropping;
4031 sp_out_crop_pos->y = (uint16_t)info->pipeline.top_cropping;
4033 IA_CSS_LEAVE_PRIVATE("void");
4037 sh_css_update_uds_and_crop_info_based_on_zoom_region(
4038 const struct ia_css_binary_info *info,
4039 const struct ia_css_frame_info *in_frame_info,
4040 const struct ia_css_frame_info *out_frame_info,
4041 const struct ia_css_resolution *dvs_env,
4042 const struct ia_css_dz_config *zoom,
4043 const struct ia_css_vector *motion_vector,
4044 struct sh_css_uds_info *uds, /* out */
4045 struct sh_css_crop_pos *sp_out_crop_pos, /* out */
4046 struct ia_css_resolution pipe_in_res,
4049 unsigned int x0 = 0, y0 = 0, x1 = 0, y1 = 0;
4052 * Filter_Envelope = 0 for NND/LUT
4053 * Filter_Envelope = 1 for BCI
4054 * Filter_Envelope = 3 for BLI
4055 * Currently, not considering this filter envelope because, In uds.sp.c is recalculating
4056 * the dx/dy based on filter envelope and other information (ia_css_uds_sp_scale_params)
4057 * Ideally, That should be done on host side not on sp side.
4059 unsigned int filter_envelope = 0;
4061 IA_CSS_ENTER_PRIVATE("void");
4064 assert(in_frame_info);
4065 assert(out_frame_info);
4068 assert(motion_vector);
4070 assert(sp_out_crop_pos);
4071 x0 = zoom->zoom_region.origin.x;
4072 y0 = zoom->zoom_region.origin.y;
4073 x1 = zoom->zoom_region.resolution.width + x0;
4074 y1 = zoom->zoom_region.resolution.height + y0;
4076 if ((x0 > x1) || (y0 > y1) || (x1 > pipe_in_res.width) || (y1 > pipe_in_res.height))
4080 uds->curr_dx = HRT_GDC_N;
4081 uds->curr_dy = HRT_GDC_N;
4084 if (info->enable.dvs_envelope) {
4085 /* Zoom region is only supported by the UDS module on ISP
4086 * 2 and higher. It is not supported in video mode on ISP 1 */
4090 /* A. Calculate dx/dy based on crop region using in_frame_info
4091 * Scale the crop region if in_frame_info to the stage is not same as
4092 * actual effective input of the pipeline
4094 if (in_frame_info->res.width != pipe_in_res.width ||
4095 in_frame_info->res.height != pipe_in_res.height) {
4096 x0 = (x0 * in_frame_info->res.width) / (pipe_in_res.width);
4097 y0 = (y0 * in_frame_info->res.height) / (pipe_in_res.height);
4098 x1 = (x1 * in_frame_info->res.width) / (pipe_in_res.width);
4099 y1 = (y1 * in_frame_info->res.height) / (pipe_in_res.height);
4102 ((x1 - x0 - filter_envelope) * HRT_GDC_N) / in_frame_info->res.width;
4104 ((y1 - y0 - filter_envelope) * HRT_GDC_N) / in_frame_info->res.height;
4106 /* B. Calculate xc/yc based on crop region */
4107 uds->xc = (uint16_t)x0 + (((x1) - (x0)) / 2);
4108 uds->yc = (uint16_t)y0 + (((y1) - (y0)) / 2);
4110 uds->xc = (uint16_t)in_frame_info->res.width / 2;
4111 uds->yc = (uint16_t)in_frame_info->res.height / 2;
4114 ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE,
4115 "uds->curr_dx=%d, uds->xc=%d, uds->yc=%d\n",
4116 uds->curr_dx, uds->xc, uds->yc);
4117 ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "x0=%d, y0=%d, x1=%d, y1=%d\n",
4119 sp_out_crop_pos->x = (uint16_t)info->pipeline.left_cropping;
4120 sp_out_crop_pos->y = (uint16_t)info->pipeline.top_cropping;
4122 IA_CSS_LEAVE_PRIVATE("void");
4126 struct ia_css_3a_statistics *
4127 ia_css_3a_statistics_allocate(const struct ia_css_3a_grid_info *grid)
4129 struct ia_css_3a_statistics *me;
4132 IA_CSS_ENTER("grid=%p", grid);
4136 me = kvcalloc(1, sizeof(*me), GFP_KERNEL);
4141 grid_size = grid->width * grid->height;
4142 me->data = kvmalloc(grid_size * sizeof(*me->data), GFP_KERNEL);
4145 /* No weighted histogram, no structure, treat the histogram data as a byte dump in a byte array */
4146 me->rgby_data = kvmalloc(sizeof_hmem(HMEM0_ID), GFP_KERNEL);
4148 IA_CSS_LEAVE("return=%p", me);
4151 ia_css_3a_statistics_free(me);
4153 IA_CSS_LEAVE("return=%p", NULL);
4158 ia_css_3a_statistics_free(struct ia_css_3a_statistics *me)
4161 kvfree(me->rgby_data);
4167 struct ia_css_dvs_statistics *
4168 ia_css_dvs_statistics_allocate(const struct ia_css_dvs_grid_info *grid)
4170 struct ia_css_dvs_statistics *me;
4174 me = kvcalloc(1, sizeof(*me), GFP_KERNEL);
4179 me->hor_proj = kvmalloc(grid->height * IA_CSS_DVS_NUM_COEF_TYPES *
4180 sizeof(*me->hor_proj), GFP_KERNEL);
4184 me->ver_proj = kvmalloc(grid->width * IA_CSS_DVS_NUM_COEF_TYPES *
4185 sizeof(*me->ver_proj), GFP_KERNEL);
4191 ia_css_dvs_statistics_free(me);
4196 ia_css_dvs_statistics_free(struct ia_css_dvs_statistics *me)
4199 kvfree(me->hor_proj);
4200 kvfree(me->ver_proj);
4205 struct ia_css_dvs_coefficients *
4206 ia_css_dvs_coefficients_allocate(const struct ia_css_dvs_grid_info *grid)
4208 struct ia_css_dvs_coefficients *me;
4212 me = kvcalloc(1, sizeof(*me), GFP_KERNEL);
4218 me->hor_coefs = kvmalloc(grid->num_hor_coefs *
4219 IA_CSS_DVS_NUM_COEF_TYPES *
4220 sizeof(*me->hor_coefs), GFP_KERNEL);
4224 me->ver_coefs = kvmalloc(grid->num_ver_coefs *
4225 IA_CSS_DVS_NUM_COEF_TYPES *
4226 sizeof(*me->ver_coefs), GFP_KERNEL);
4232 ia_css_dvs_coefficients_free(me);
4237 ia_css_dvs_coefficients_free(struct ia_css_dvs_coefficients *me)
4240 kvfree(me->hor_coefs);
4241 kvfree(me->ver_coefs);
4246 struct ia_css_dvs2_statistics *
4247 ia_css_dvs2_statistics_allocate(const struct ia_css_dvs_grid_info *grid)
4249 struct ia_css_dvs2_statistics *me;
4253 me = kvcalloc(1, sizeof(*me), GFP_KERNEL);
4259 me->hor_prod.odd_real = kvmalloc(grid->aligned_width *
4260 grid->aligned_height *
4261 sizeof(*me->hor_prod.odd_real),
4263 if (!me->hor_prod.odd_real)
4266 me->hor_prod.odd_imag = kvmalloc(grid->aligned_width *
4267 grid->aligned_height *
4268 sizeof(*me->hor_prod.odd_imag),
4270 if (!me->hor_prod.odd_imag)
4273 me->hor_prod.even_real = kvmalloc(grid->aligned_width *
4274 grid->aligned_height *
4275 sizeof(*me->hor_prod.even_real),
4277 if (!me->hor_prod.even_real)
4280 me->hor_prod.even_imag = kvmalloc(grid->aligned_width *
4281 grid->aligned_height *
4282 sizeof(*me->hor_prod.even_imag),
4284 if (!me->hor_prod.even_imag)
4287 me->ver_prod.odd_real = kvmalloc(grid->aligned_width *
4288 grid->aligned_height *
4289 sizeof(*me->ver_prod.odd_real),
4291 if (!me->ver_prod.odd_real)
4294 me->ver_prod.odd_imag = kvmalloc(grid->aligned_width *
4295 grid->aligned_height *
4296 sizeof(*me->ver_prod.odd_imag),
4298 if (!me->ver_prod.odd_imag)
4301 me->ver_prod.even_real = kvmalloc(grid->aligned_width *
4302 grid->aligned_height *
4303 sizeof(*me->ver_prod.even_real),
4305 if (!me->ver_prod.even_real)
4308 me->ver_prod.even_imag = kvmalloc(grid->aligned_width *
4309 grid->aligned_height *
4310 sizeof(*me->ver_prod.even_imag),
4312 if (!me->ver_prod.even_imag)
4317 ia_css_dvs2_statistics_free(me);
4322 ia_css_dvs2_statistics_free(struct ia_css_dvs2_statistics *me)
4325 kvfree(me->hor_prod.odd_real);
4326 kvfree(me->hor_prod.odd_imag);
4327 kvfree(me->hor_prod.even_real);
4328 kvfree(me->hor_prod.even_imag);
4329 kvfree(me->ver_prod.odd_real);
4330 kvfree(me->ver_prod.odd_imag);
4331 kvfree(me->ver_prod.even_real);
4332 kvfree(me->ver_prod.even_imag);
4337 struct ia_css_dvs2_coefficients *
4338 ia_css_dvs2_coefficients_allocate(const struct ia_css_dvs_grid_info *grid)
4340 struct ia_css_dvs2_coefficients *me;
4344 me = kvcalloc(1, sizeof(*me), GFP_KERNEL);
4350 me->hor_coefs.odd_real = kvmalloc(grid->num_hor_coefs *
4351 sizeof(*me->hor_coefs.odd_real),
4353 if (!me->hor_coefs.odd_real)
4356 me->hor_coefs.odd_imag = kvmalloc(grid->num_hor_coefs *
4357 sizeof(*me->hor_coefs.odd_imag),
4359 if (!me->hor_coefs.odd_imag)
4362 me->hor_coefs.even_real = kvmalloc(grid->num_hor_coefs *
4363 sizeof(*me->hor_coefs.even_real),
4365 if (!me->hor_coefs.even_real)
4368 me->hor_coefs.even_imag = kvmalloc(grid->num_hor_coefs *
4369 sizeof(*me->hor_coefs.even_imag),
4371 if (!me->hor_coefs.even_imag)
4374 me->ver_coefs.odd_real = kvmalloc(grid->num_ver_coefs *
4375 sizeof(*me->ver_coefs.odd_real),
4377 if (!me->ver_coefs.odd_real)
4380 me->ver_coefs.odd_imag = kvmalloc(grid->num_ver_coefs *
4381 sizeof(*me->ver_coefs.odd_imag),
4383 if (!me->ver_coefs.odd_imag)
4386 me->ver_coefs.even_real = kvmalloc(grid->num_ver_coefs *
4387 sizeof(*me->ver_coefs.even_real),
4389 if (!me->ver_coefs.even_real)
4392 me->ver_coefs.even_imag = kvmalloc(grid->num_ver_coefs *
4393 sizeof(*me->ver_coefs.even_imag),
4395 if (!me->ver_coefs.even_imag)
4400 ia_css_dvs2_coefficients_free(me);
4405 ia_css_dvs2_coefficients_free(struct ia_css_dvs2_coefficients *me)
4408 kvfree(me->hor_coefs.odd_real);
4409 kvfree(me->hor_coefs.odd_imag);
4410 kvfree(me->hor_coefs.even_real);
4411 kvfree(me->hor_coefs.even_imag);
4412 kvfree(me->ver_coefs.odd_real);
4413 kvfree(me->ver_coefs.odd_imag);
4414 kvfree(me->ver_coefs.even_real);
4415 kvfree(me->ver_coefs.even_imag);
4420 struct ia_css_dvs_6axis_config *
4421 ia_css_dvs2_6axis_config_allocate(const struct ia_css_stream *stream)
4423 struct ia_css_dvs_6axis_config *dvs_config = NULL;
4424 struct ia_css_isp_parameters *params = NULL;
4425 unsigned int width_y;
4426 unsigned int height_y;
4427 unsigned int width_uv;
4428 unsigned int height_uv;
4431 params = stream->isp_params_configs;
4433 /* Backward compatibility by default consider pipe as Video*/
4434 if (!params || !params->pipe_dvs_6axis_config[IA_CSS_PIPE_ID_VIDEO])
4437 dvs_config = kvcalloc(1, sizeof(struct ia_css_dvs_6axis_config),
4442 dvs_config->width_y = width_y =
4443 params->pipe_dvs_6axis_config[IA_CSS_PIPE_ID_VIDEO]->width_y;
4444 dvs_config->height_y = height_y =
4445 params->pipe_dvs_6axis_config[IA_CSS_PIPE_ID_VIDEO]->height_y;
4446 dvs_config->width_uv = width_uv =
4447 params->pipe_dvs_6axis_config[IA_CSS_PIPE_ID_VIDEO]->width_uv;
4448 dvs_config->height_uv = height_uv =
4449 params->pipe_dvs_6axis_config[IA_CSS_PIPE_ID_VIDEO]->height_uv;
4450 IA_CSS_LOG("table Y: W %d H %d", width_y, height_y);
4451 IA_CSS_LOG("table UV: W %d H %d", width_uv, height_uv);
4452 dvs_config->xcoords_y = kvmalloc(width_y * height_y * sizeof(uint32_t),
4454 if (!dvs_config->xcoords_y)
4457 dvs_config->ycoords_y = kvmalloc(width_y * height_y * sizeof(uint32_t),
4459 if (!dvs_config->ycoords_y)
4462 dvs_config->xcoords_uv = kvmalloc(width_uv * height_uv *
4465 if (!dvs_config->xcoords_uv)
4468 dvs_config->ycoords_uv = kvmalloc(width_uv * height_uv *
4471 if (!dvs_config->ycoords_uv)
4476 ia_css_dvs2_6axis_config_free(dvs_config);
4481 ia_css_dvs2_6axis_config_free(struct ia_css_dvs_6axis_config *dvs_6axis_config)
4483 if (dvs_6axis_config) {
4484 kvfree(dvs_6axis_config->xcoords_y);
4485 kvfree(dvs_6axis_config->ycoords_y);
4486 kvfree(dvs_6axis_config->xcoords_uv);
4487 kvfree(dvs_6axis_config->ycoords_uv);
4488 kvfree(dvs_6axis_config);
4493 ia_css_en_dz_capt_pipe(struct ia_css_stream *stream, bool enable)
4495 struct ia_css_pipe *pipe;
4496 struct ia_css_pipeline *pipeline;
4497 struct ia_css_pipeline_stage *stage;
4498 enum ia_css_pipe_id pipe_id;
4505 for (i = 0; i < stream->num_pipes; i++) {
4506 pipe = stream->pipes[i];
4507 pipeline = ia_css_pipe_get_pipeline(pipe);
4508 pipe_id = pipeline->pipe_id;
4510 if (pipe_id == IA_CSS_PIPE_ID_CAPTURE) {
4511 err = ia_css_pipeline_get_stage(pipeline, IA_CSS_BINARY_MODE_CAPTURE_PP,
4514 stage->enable_zoom = enable;