1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Support for Intel Camera Imaging ISP subsystem.
4 * Copyright (c) 2015, Intel Corporation.
5 */
6
7 #include "gdc_device.h" /* gdc_lut_store(), ... */
8 #include "isp.h" /* ISP_VEC_ELEMBITS */
9 #include "vamem.h"
10 #ifndef __INLINE_HMEM__
11 #define __INLINE_HMEM__
12 #endif
13 #include "hmem.h"
14 #define IA_CSS_INCLUDE_PARAMETERS
15 #define IA_CSS_INCLUDE_ACC_PARAMETERS
16
17 #include "hmm.h"
18 #include "sh_css_params.h"
19 #include "ia_css_queue.h"
20 #include "sw_event_global.h" /* Event IDs */
21
22 #include "platform_support.h"
23 #include "assert_support.h"
24 #include "misc_support.h" /* NOT_USED */
25 #include "math_support.h" /* max(), min() EVEN_FLOOR()*/
26
27 #include "ia_css_stream.h"
28 #include "sh_css_params_internal.h"
29 #include "sh_css_param_shading.h"
30 #include "sh_css_param_dvs.h"
31 #include "ia_css_refcount.h"
32 #include "sh_css_internal.h"
33 #include "ia_css_control.h"
34 #include "ia_css_shading.h"
35 #include "sh_css_defs.h"
36 #include "sh_css_sp.h"
37 #include "ia_css_pipeline.h"
38 #include "ia_css_debug.h"
39
40 #include "ia_css_isp_param.h"
41 #include "ia_css_isp_params.h"
42 #include "ia_css_mipi.h"
43 #include "ia_css_morph.h"
44 #include "ia_css_host_data.h"
45 #include "ia_css_pipe.h"
46 #include "ia_css_pipe_binarydesc.h"
47
48 /* Include all kernel host interfaces for ISP1 */
49
50 #include "anr/anr_1.0/ia_css_anr.host.h"
51 #include "cnr/cnr_1.0/ia_css_cnr.host.h"
52 #include "csc/csc_1.0/ia_css_csc.host.h"
53 #include "de/de_1.0/ia_css_de.host.h"
54 #include "dp/dp_1.0/ia_css_dp.host.h"
55 #include "bnr/bnr_1.0/ia_css_bnr.host.h"
56 #include "dvs/dvs_1.0/ia_css_dvs.host.h"
57 #include "fpn/fpn_1.0/ia_css_fpn.host.h"
58 #include "gc/gc_1.0/ia_css_gc.host.h"
59 #include "macc/macc_1.0/ia_css_macc.host.h"
60 #include "ctc/ctc_1.0/ia_css_ctc.host.h"
61 #include "ob/ob_1.0/ia_css_ob.host.h"
62 #include "raw/raw_1.0/ia_css_raw.host.h"
63 #include "fixedbds/fixedbds_1.0/ia_css_fixedbds_param.h"
64 #include "s3a/s3a_1.0/ia_css_s3a.host.h"
65 #include "sc/sc_1.0/ia_css_sc.host.h"
66 #include "sdis/sdis_1.0/ia_css_sdis.host.h"
67 #include "tnr/tnr_1.0/ia_css_tnr.host.h"
68 #include "uds/uds_1.0/ia_css_uds_param.h"
69 #include "wb/wb_1.0/ia_css_wb.host.h"
70 #include "ynr/ynr_1.0/ia_css_ynr.host.h"
71 #include "xnr/xnr_1.0/ia_css_xnr.host.h"
72
73 /* Include additional kernel host interfaces for ISP2 */
74
75 #include "aa/aa_2/ia_css_aa2.host.h"
76 #include "anr/anr_2/ia_css_anr2.host.h"
77 #include "bh/bh_2/ia_css_bh.host.h"
78 #include "cnr/cnr_2/ia_css_cnr2.host.h"
79 #include "ctc/ctc1_5/ia_css_ctc1_5.host.h"
80 #include "de/de_2/ia_css_de2.host.h"
81 #include "gc/gc_2/ia_css_gc2.host.h"
82 #include "sdis/sdis_2/ia_css_sdis2.host.h"
83 #include "ynr/ynr_2/ia_css_ynr2.host.h"
84 #include "fc/fc_1.0/ia_css_formats.host.h"
85
86 #include "xnr/xnr_3.0/ia_css_xnr3.host.h"
87
88
89 #include "sh_css_frac.h"
90 #include "ia_css_bufq.h"
91
fpntbl_bytes(const struct ia_css_binary * binary)92 static size_t fpntbl_bytes(const struct ia_css_binary *binary)
93 {
94 return array3_size(sizeof(char),
95 binary->in_frame_info.res.height,
96 binary->in_frame_info.padded_width);
97 }
98
sctbl_bytes(const struct ia_css_binary * binary)99 static size_t sctbl_bytes(const struct ia_css_binary *binary)
100 {
101 return size_mul(sizeof(unsigned short),
102 array3_size(binary->sctbl_height,
103 binary->sctbl_aligned_width_per_color,
104 IA_CSS_SC_NUM_COLORS));
105 }
106
morph_plane_bytes(const struct ia_css_binary * binary)107 static size_t morph_plane_bytes(const struct ia_css_binary *binary)
108 {
109 return array3_size(SH_CSS_MORPH_TABLE_ELEM_BYTES,
110 binary->morph_tbl_aligned_width,
111 binary->morph_tbl_height);
112 }
113
114 /* We keep a second copy of the ptr struct for the SP to access.
115 Again, this would not be necessary on the chip. */
116 static ia_css_ptr sp_ddr_ptrs;
117
118 /* sp group address on DDR */
119 static ia_css_ptr xmem_sp_group_ptrs;
120
121 static ia_css_ptr xmem_sp_stage_ptrs[IA_CSS_PIPE_ID_NUM]
122 [SH_CSS_MAX_STAGES];
123 static ia_css_ptr xmem_isp_stage_ptrs[IA_CSS_PIPE_ID_NUM]
124 [SH_CSS_MAX_STAGES];
125
126 static ia_css_ptr default_gdc_lut;
127 static int interleaved_lut_temp[4][HRT_GDC_N];
128
129 /* END DO NOT MOVE INTO VIMALS_WORLD */
130
131 /* Digital Zoom lookup table. See documentation for more details about the
132 * contents of this table.
133 */
134 static const int zoom_table[4][HRT_GDC_N] = {
135 {
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 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 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 -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 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 -2 << 4, -2 << 4, -2 << 4, -2 << 4, -2 << 4, -2 << 4, -2 << 4, -2 << 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 -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 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 -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4,
166 -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4,
167 -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 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 -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 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 -7 << 4, -7 << 4, -7 << 4, -7 << 4, -7 << 4, -7 << 4, -7 << 4, -7 << 4,
176 -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4,
177 -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 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 -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4,
182 -10 << 4, -10 << 4, -10 << 4, -10 << 4, -10 << 4, -10 << 4, -10 << 4, -10 << 4,
183 -10 << 4, -10 << 4, -10 << 4, -10 << 4, -10 << 4, -10 << 4, -10 << 4, -10 << 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 -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4,
188 -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4,
189 -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 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 -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 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 -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4,
198 -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4,
199 -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 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 -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 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 -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 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 -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 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 -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4,
238 -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4,
239 -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 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 -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4,
244 -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4,
245 -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4,
246 -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4,
247 -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4,
248 -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4,
249 -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4,
250 -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4,
251 -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4,
252 -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4,
253 -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4,
254 -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4,
255 -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4,
256 -7 << 4, -7 << 4, -7 << 4, -7 << 4, -7 << 4, -7 << 4, -7 << 4, -7 << 4,
257 -7 << 4, -7 << 4, -7 << 4, -7 << 4, -7 << 4, -7 << 4, -7 << 4, -7 << 4,
258 -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4,
259 -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4,
260 -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4,
261 -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4,
262 -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4,
263 -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4
264 },
265 {
266 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4,
267 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4,
268 2 << 4, 2 << 4, 2 << 4, 2 << 4, 2 << 4, 2 << 4, 2 << 4, 2 << 4,
269 2 << 4, 2 << 4, 2 << 4, 2 << 4, 2 << 4, 2 << 4, 2 << 4, 2 << 4,
270 4 << 4, 4 << 4, 4 << 4, 4 << 4, 4 << 4, 4 << 4, 4 << 4, 4 << 4,
271 4 << 4, 4 << 4, 4 << 4, 4 << 4, 4 << 4, 4 << 4, 4 << 4, 4 << 4,
272 7 << 4, 7 << 4, 7 << 4, 7 << 4, 7 << 4, 7 << 4, 7 << 4, 7 << 4,
273 7 << 4, 7 << 4, 7 << 4, 7 << 4, 7 << 4, 7 << 4, 7 << 4, 7 << 4,
274 9 << 4, 9 << 4, 9 << 4, 9 << 4, 9 << 4, 9 << 4, 9 << 4, 9 << 4,
275 9 << 4, 9 << 4, 9 << 4, 9 << 4, 9 << 4, 9 << 4, 9 << 4, 9 << 4,
276 12 << 4, 12 << 4, 12 << 4, 12 << 4, 12 << 4, 12 << 4, 12 << 4, 12 << 4,
277 12 << 4, 12 << 4, 12 << 4, 12 << 4, 12 << 4, 12 << 4, 12 << 4, 12 << 4,
278 16 << 4, 16 << 4, 16 << 4, 16 << 4, 16 << 4, 16 << 4, 16 << 4, 16 << 4,
279 16 << 4, 16 << 4, 16 << 4, 16 << 4, 16 << 4, 16 << 4, 16 << 4, 16 << 4,
280 19 << 4, 19 << 4, 19 << 4, 19 << 4, 19 << 4, 19 << 4, 19 << 4, 19 << 4,
281 19 << 4, 19 << 4, 19 << 4, 19 << 4, 19 << 4, 19 << 4, 19 << 4, 19 << 4,
282 23 << 4, 23 << 4, 23 << 4, 23 << 4, 23 << 4, 23 << 4, 23 << 4, 23 << 4,
283 23 << 4, 23 << 4, 23 << 4, 23 << 4, 23 << 4, 23 << 4, 23 << 4, 23 << 4,
284 27 << 4, 27 << 4, 27 << 4, 27 << 4, 27 << 4, 27 << 4, 27 << 4, 27 << 4,
285 27 << 4, 27 << 4, 27 << 4, 27 << 4, 27 << 4, 27 << 4, 27 << 4, 27 << 4,
286 31 << 4, 31 << 4, 31 << 4, 31 << 4, 31 << 4, 31 << 4, 31 << 4, 31 << 4,
287 31 << 4, 31 << 4, 31 << 4, 31 << 4, 31 << 4, 31 << 4, 31 << 4, 31 << 4,
288 35 << 4, 35 << 4, 35 << 4, 35 << 4, 35 << 4, 35 << 4, 35 << 4, 35 << 4,
289 35 << 4, 35 << 4, 35 << 4, 35 << 4, 35 << 4, 35 << 4, 35 << 4, 35 << 4,
290 39 << 4, 39 << 4, 39 << 4, 39 << 4, 39 << 4, 39 << 4, 39 << 4, 39 << 4,
291 39 << 4, 39 << 4, 39 << 4, 39 << 4, 39 << 4, 39 << 4, 39 << 4, 39 << 4,
292 43 << 4, 43 << 4, 43 << 4, 43 << 4, 43 << 4, 43 << 4, 43 << 4, 43 << 4,
293 43 << 4, 43 << 4, 43 << 4, 43 << 4, 43 << 4, 43 << 4, 43 << 4, 43 << 4,
294 48 << 4, 48 << 4, 48 << 4, 48 << 4, 48 << 4, 48 << 4, 48 << 4, 48 << 4,
295 48 << 4, 48 << 4, 48 << 4, 48 << 4, 48 << 4, 48 << 4, 48 << 4, 48 << 4,
296 53 << 4, 53 << 4, 53 << 4, 53 << 4, 53 << 4, 53 << 4, 53 << 4, 53 << 4,
297 53 << 4, 53 << 4, 53 << 4, 53 << 4, 53 << 4, 53 << 4, 53 << 4, 53 << 4,
298 58 << 4, 58 << 4, 58 << 4, 58 << 4, 58 << 4, 58 << 4, 58 << 4, 58 << 4,
299 58 << 4, 58 << 4, 58 << 4, 58 << 4, 58 << 4, 58 << 4, 58 << 4, 58 << 4,
300 62 << 4, 62 << 4, 62 << 4, 62 << 4, 62 << 4, 62 << 4, 62 << 4, 62 << 4,
301 62 << 4, 62 << 4, 62 << 4, 62 << 4, 62 << 4, 62 << 4, 62 << 4, 62 << 4,
302 67 << 4, 67 << 4, 67 << 4, 67 << 4, 67 << 4, 67 << 4, 67 << 4, 67 << 4,
303 67 << 4, 67 << 4, 67 << 4, 67 << 4, 67 << 4, 67 << 4, 67 << 4, 67 << 4,
304 73 << 4, 73 << 4, 73 << 4, 73 << 4, 73 << 4, 73 << 4, 73 << 4, 73 << 4,
305 73 << 4, 73 << 4, 73 << 4, 73 << 4, 73 << 4, 73 << 4, 73 << 4, 73 << 4,
306 78 << 4, 78 << 4, 78 << 4, 78 << 4, 78 << 4, 78 << 4, 78 << 4, 78 << 4,
307 78 << 4, 78 << 4, 78 << 4, 78 << 4, 78 << 4, 78 << 4, 78 << 4, 78 << 4,
308 83 << 4, 83 << 4, 83 << 4, 83 << 4, 83 << 4, 83 << 4, 83 << 4, 83 << 4,
309 83 << 4, 83 << 4, 83 << 4, 83 << 4, 83 << 4, 83 << 4, 83 << 4, 83 << 4,
310 88 << 4, 88 << 4, 88 << 4, 88 << 4, 88 << 4, 88 << 4, 88 << 4, 88 << 4,
311 88 << 4, 88 << 4, 88 << 4, 88 << 4, 88 << 4, 88 << 4, 88 << 4, 88 << 4,
312 94 << 4, 94 << 4, 94 << 4, 94 << 4, 94 << 4, 94 << 4, 94 << 4, 94 << 4,
313 94 << 4, 94 << 4, 94 << 4, 94 << 4, 94 << 4, 94 << 4, 94 << 4, 94 << 4,
314 99 << 4, 99 << 4, 99 << 4, 99 << 4, 99 << 4, 99 << 4, 99 << 4, 99 << 4,
315 99 << 4, 99 << 4, 99 << 4, 99 << 4, 99 << 4, 99 << 4, 99 << 4, 99 << 4,
316 105 << 4, 105 << 4, 105 << 4, 105 << 4, 105 << 4, 105 << 4, 105 << 4, 105 << 4,
317 105 << 4, 105 << 4, 105 << 4, 105 << 4, 105 << 4, 105 << 4, 105 << 4, 105 << 4,
318 110 << 4, 110 << 4, 110 << 4, 110 << 4, 110 << 4, 110 << 4, 110 << 4, 110 << 4,
319 110 << 4, 110 << 4, 110 << 4, 110 << 4, 110 << 4, 110 << 4, 110 << 4, 110 << 4,
320 116 << 4, 116 << 4, 116 << 4, 116 << 4, 116 << 4, 116 << 4, 116 << 4, 116 << 4,
321 116 << 4, 116 << 4, 116 << 4, 116 << 4, 116 << 4, 116 << 4, 116 << 4, 116 << 4,
322 121 << 4, 121 << 4, 121 << 4, 121 << 4, 121 << 4, 121 << 4, 121 << 4, 121 << 4,
323 121 << 4, 121 << 4, 121 << 4, 121 << 4, 121 << 4, 121 << 4, 121 << 4, 121 << 4,
324 127 << 4, 127 << 4, 127 << 4, 127 << 4, 127 << 4, 127 << 4, 127 << 4, 127 << 4,
325 127 << 4, 127 << 4, 127 << 4, 127 << 4, 127 << 4, 127 << 4, 127 << 4, 127 << 4,
326 132 << 4, 132 << 4, 132 << 4, 132 << 4, 132 << 4, 132 << 4, 132 << 4, 132 << 4,
327 132 << 4, 132 << 4, 132 << 4, 132 << 4, 132 << 4, 132 << 4, 132 << 4, 132 << 4,
328 138 << 4, 138 << 4, 138 << 4, 138 << 4, 138 << 4, 138 << 4, 138 << 4, 138 << 4,
329 138 << 4, 138 << 4, 138 << 4, 138 << 4, 138 << 4, 138 << 4, 138 << 4, 138 << 4,
330 144 << 4, 144 << 4, 144 << 4, 144 << 4, 144 << 4, 144 << 4, 144 << 4, 144 << 4,
331 144 << 4, 144 << 4, 144 << 4, 144 << 4, 144 << 4, 144 << 4, 144 << 4, 144 << 4,
332 149 << 4, 149 << 4, 149 << 4, 149 << 4, 149 << 4, 149 << 4, 149 << 4, 149 << 4,
333 149 << 4, 149 << 4, 149 << 4, 149 << 4, 149 << 4, 149 << 4, 149 << 4, 149 << 4,
334 154 << 4, 154 << 4, 154 << 4, 154 << 4, 154 << 4, 154 << 4, 154 << 4, 154 << 4,
335 154 << 4, 154 << 4, 154 << 4, 154 << 4, 154 << 4, 154 << 4, 154 << 4, 154 << 4,
336 160 << 4, 160 << 4, 160 << 4, 160 << 4, 160 << 4, 160 << 4, 160 << 4, 160 << 4,
337 160 << 4, 160 << 4, 160 << 4, 160 << 4, 160 << 4, 160 << 4, 160 << 4, 160 << 4,
338 165 << 4, 165 << 4, 165 << 4, 165 << 4, 165 << 4, 165 << 4, 165 << 4, 165 << 4,
339 165 << 4, 165 << 4, 165 << 4, 165 << 4, 165 << 4, 165 << 4, 165 << 4, 165 << 4,
340 170 << 4, 170 << 4, 170 << 4, 170 << 4, 170 << 4, 170 << 4, 170 << 4, 170 << 4,
341 170 << 4, 170 << 4, 170 << 4, 170 << 4, 170 << 4, 170 << 4, 170 << 4, 170 << 4,
342 176 << 4, 176 << 4, 176 << 4, 176 << 4, 176 << 4, 176 << 4, 176 << 4, 176 << 4,
343 176 << 4, 176 << 4, 176 << 4, 176 << 4, 176 << 4, 176 << 4, 176 << 4, 176 << 4,
344 181 << 4, 181 << 4, 181 << 4, 181 << 4, 181 << 4, 181 << 4, 181 << 4, 181 << 4,
345 181 << 4, 181 << 4, 181 << 4, 181 << 4, 181 << 4, 181 << 4, 181 << 4, 181 << 4,
346 186 << 4, 186 << 4, 186 << 4, 186 << 4, 186 << 4, 186 << 4, 186 << 4, 186 << 4,
347 186 << 4, 186 << 4, 186 << 4, 186 << 4, 186 << 4, 186 << 4, 186 << 4, 186 << 4,
348 191 << 4, 191 << 4, 191 << 4, 191 << 4, 191 << 4, 191 << 4, 191 << 4, 191 << 4,
349 191 << 4, 191 << 4, 191 << 4, 191 << 4, 191 << 4, 191 << 4, 191 << 4, 191 << 4,
350 195 << 4, 195 << 4, 195 << 4, 195 << 4, 195 << 4, 195 << 4, 195 << 4, 195 << 4,
351 195 << 4, 195 << 4, 195 << 4, 195 << 4, 195 << 4, 195 << 4, 195 << 4, 195 << 4,
352 200 << 4, 200 << 4, 200 << 4, 200 << 4, 200 << 4, 200 << 4, 200 << 4, 200 << 4,
353 200 << 4, 200 << 4, 200 << 4, 200 << 4, 200 << 4, 200 << 4, 200 << 4, 200 << 4,
354 205 << 4, 205 << 4, 205 << 4, 205 << 4, 205 << 4, 205 << 4, 205 << 4, 205 << 4,
355 205 << 4, 205 << 4, 205 << 4, 205 << 4, 205 << 4, 205 << 4, 205 << 4, 205 << 4,
356 209 << 4, 209 << 4, 209 << 4, 209 << 4, 209 << 4, 209 << 4, 209 << 4, 209 << 4,
357 209 << 4, 209 << 4, 209 << 4, 209 << 4, 209 << 4, 209 << 4, 209 << 4, 209 << 4,
358 213 << 4, 213 << 4, 213 << 4, 213 << 4, 213 << 4, 213 << 4, 213 << 4, 213 << 4,
359 213 << 4, 213 << 4, 213 << 4, 213 << 4, 213 << 4, 213 << 4, 213 << 4, 213 << 4,
360 218 << 4, 218 << 4, 218 << 4, 218 << 4, 218 << 4, 218 << 4, 218 << 4, 218 << 4,
361 218 << 4, 218 << 4, 218 << 4, 218 << 4, 218 << 4, 218 << 4, 218 << 4, 218 << 4,
362 222 << 4, 222 << 4, 222 << 4, 222 << 4, 222 << 4, 222 << 4, 222 << 4, 222 << 4,
363 222 << 4, 222 << 4, 222 << 4, 222 << 4, 222 << 4, 222 << 4, 222 << 4, 222 << 4,
364 225 << 4, 225 << 4, 225 << 4, 225 << 4, 225 << 4, 225 << 4, 225 << 4, 225 << 4,
365 225 << 4, 225 << 4, 225 << 4, 225 << 4, 225 << 4, 225 << 4, 225 << 4, 225 << 4,
366 229 << 4, 229 << 4, 229 << 4, 229 << 4, 229 << 4, 229 << 4, 229 << 4, 229 << 4,
367 229 << 4, 229 << 4, 229 << 4, 229 << 4, 229 << 4, 229 << 4, 229 << 4, 229 << 4,
368 232 << 4, 232 << 4, 232 << 4, 232 << 4, 232 << 4, 232 << 4, 232 << 4, 232 << 4,
369 232 << 4, 232 << 4, 232 << 4, 232 << 4, 232 << 4, 232 << 4, 232 << 4, 232 << 4,
370 236 << 4, 236 << 4, 236 << 4, 236 << 4, 236 << 4, 236 << 4, 236 << 4, 236 << 4,
371 236 << 4, 236 << 4, 236 << 4, 236 << 4, 236 << 4, 236 << 4, 236 << 4, 236 << 4,
372 239 << 4, 239 << 4, 239 << 4, 239 << 4, 239 << 4, 239 << 4, 239 << 4, 239 << 4,
373 239 << 4, 239 << 4, 239 << 4, 239 << 4, 239 << 4, 239 << 4, 239 << 4, 239 << 4,
374 241 << 4, 241 << 4, 241 << 4, 241 << 4, 241 << 4, 241 << 4, 241 << 4, 241 << 4,
375 241 << 4, 241 << 4, 241 << 4, 241 << 4, 241 << 4, 241 << 4, 241 << 4, 241 << 4,
376 244 << 4, 244 << 4, 244 << 4, 244 << 4, 244 << 4, 244 << 4, 244 << 4, 244 << 4,
377 244 << 4, 244 << 4, 244 << 4, 244 << 4, 244 << 4, 244 << 4, 244 << 4, 244 << 4,
378 246 << 4, 246 << 4, 246 << 4, 246 << 4, 246 << 4, 246 << 4, 246 << 4, 246 << 4,
379 246 << 4, 246 << 4, 246 << 4, 246 << 4, 246 << 4, 246 << 4, 246 << 4, 246 << 4,
380 248 << 4, 248 << 4, 248 << 4, 248 << 4, 248 << 4, 248 << 4, 248 << 4, 248 << 4,
381 248 << 4, 248 << 4, 248 << 4, 248 << 4, 248 << 4, 248 << 4, 248 << 4, 248 << 4,
382 250 << 4, 250 << 4, 250 << 4, 250 << 4, 250 << 4, 250 << 4, 250 << 4, 250 << 4,
383 250 << 4, 250 << 4, 250 << 4, 250 << 4, 250 << 4, 250 << 4, 250 << 4, 250 << 4,
384 252 << 4, 252 << 4, 252 << 4, 252 << 4, 252 << 4, 252 << 4, 252 << 4, 252 << 4,
385 252 << 4, 252 << 4, 252 << 4, 252 << 4, 252 << 4, 252 << 4, 252 << 4, 252 << 4,
386 253 << 4, 253 << 4, 253 << 4, 253 << 4, 253 << 4, 253 << 4, 253 << 4, 253 << 4,
387 253 << 4, 253 << 4, 253 << 4, 253 << 4, 253 << 4, 253 << 4, 253 << 4, 253 << 4,
388 254 << 4, 254 << 4, 254 << 4, 254 << 4, 254 << 4, 254 << 4, 254 << 4, 254 << 4,
389 254 << 4, 254 << 4, 254 << 4, 254 << 4, 254 << 4, 254 << 4, 254 << 4, 254 << 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,
393 255 << 4, 255 << 4, 255 << 4, 255 << 4, 255 << 4, 255 << 4, 255 << 4, 255 << 4
394 },
395 {
396 256 << 4, 256 << 4, 256 << 4, 256 << 4, 256 << 4, 256 << 4, 256 << 4, 256 << 4,
397 256 << 4, 256 << 4, 256 << 4, 256 << 4, 256 << 4, 256 << 4, 256 << 4, 256 << 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 255 << 4, 255 << 4, 255 << 4, 255 << 4, 255 << 4, 255 << 4, 255 << 4, 255 << 4,
402 254 << 4, 254 << 4, 254 << 4, 254 << 4, 254 << 4, 254 << 4, 254 << 4, 254 << 4,
403 254 << 4, 254 << 4, 254 << 4, 254 << 4, 254 << 4, 254 << 4, 254 << 4, 254 << 4,
404 253 << 4, 253 << 4, 253 << 4, 253 << 4, 253 << 4, 253 << 4, 253 << 4, 253 << 4,
405 253 << 4, 253 << 4, 253 << 4, 253 << 4, 253 << 4, 253 << 4, 253 << 4, 253 << 4,
406 252 << 4, 252 << 4, 252 << 4, 252 << 4, 252 << 4, 252 << 4, 252 << 4, 252 << 4,
407 252 << 4, 252 << 4, 252 << 4, 252 << 4, 252 << 4, 252 << 4, 252 << 4, 252 << 4,
408 250 << 4, 250 << 4, 250 << 4, 250 << 4, 250 << 4, 250 << 4, 250 << 4, 250 << 4,
409 250 << 4, 250 << 4, 250 << 4, 250 << 4, 250 << 4, 250 << 4, 250 << 4, 250 << 4,
410 248 << 4, 248 << 4, 248 << 4, 248 << 4, 248 << 4, 248 << 4, 248 << 4, 248 << 4,
411 248 << 4, 248 << 4, 248 << 4, 248 << 4, 248 << 4, 248 << 4, 248 << 4, 248 << 4,
412 246 << 4, 246 << 4, 246 << 4, 246 << 4, 246 << 4, 246 << 4, 246 << 4, 246 << 4,
413 246 << 4, 246 << 4, 246 << 4, 246 << 4, 246 << 4, 246 << 4, 246 << 4, 246 << 4,
414 244 << 4, 244 << 4, 244 << 4, 244 << 4, 244 << 4, 244 << 4, 244 << 4, 244 << 4,
415 244 << 4, 244 << 4, 244 << 4, 244 << 4, 244 << 4, 244 << 4, 244 << 4, 244 << 4,
416 241 << 4, 241 << 4, 241 << 4, 241 << 4, 241 << 4, 241 << 4, 241 << 4, 241 << 4,
417 241 << 4, 241 << 4, 241 << 4, 241 << 4, 241 << 4, 241 << 4, 241 << 4, 241 << 4,
418 239 << 4, 239 << 4, 239 << 4, 239 << 4, 239 << 4, 239 << 4, 239 << 4, 239 << 4,
419 239 << 4, 239 << 4, 239 << 4, 239 << 4, 239 << 4, 239 << 4, 239 << 4, 239 << 4,
420 236 << 4, 236 << 4, 236 << 4, 236 << 4, 236 << 4, 236 << 4, 236 << 4, 236 << 4,
421 236 << 4, 236 << 4, 236 << 4, 236 << 4, 236 << 4, 236 << 4, 236 << 4, 236 << 4,
422 232 << 4, 232 << 4, 232 << 4, 232 << 4, 232 << 4, 232 << 4, 232 << 4, 232 << 4,
423 232 << 4, 232 << 4, 232 << 4, 232 << 4, 232 << 4, 232 << 4, 232 << 4, 232 << 4,
424 229 << 4, 229 << 4, 229 << 4, 229 << 4, 229 << 4, 229 << 4, 229 << 4, 229 << 4,
425 229 << 4, 229 << 4, 229 << 4, 229 << 4, 229 << 4, 229 << 4, 229 << 4, 229 << 4,
426 225 << 4, 225 << 4, 225 << 4, 225 << 4, 225 << 4, 225 << 4, 225 << 4, 225 << 4,
427 225 << 4, 225 << 4, 225 << 4, 225 << 4, 225 << 4, 225 << 4, 225 << 4, 225 << 4,
428 222 << 4, 222 << 4, 222 << 4, 222 << 4, 222 << 4, 222 << 4, 222 << 4, 222 << 4,
429 222 << 4, 222 << 4, 222 << 4, 222 << 4, 222 << 4, 222 << 4, 222 << 4, 222 << 4,
430 218 << 4, 218 << 4, 218 << 4, 218 << 4, 218 << 4, 218 << 4, 218 << 4, 218 << 4,
431 218 << 4, 218 << 4, 218 << 4, 218 << 4, 218 << 4, 218 << 4, 218 << 4, 218 << 4,
432 213 << 4, 213 << 4, 213 << 4, 213 << 4, 213 << 4, 213 << 4, 213 << 4, 213 << 4,
433 213 << 4, 213 << 4, 213 << 4, 213 << 4, 213 << 4, 213 << 4, 213 << 4, 213 << 4,
434 209 << 4, 209 << 4, 209 << 4, 209 << 4, 209 << 4, 209 << 4, 209 << 4, 209 << 4,
435 209 << 4, 209 << 4, 209 << 4, 209 << 4, 209 << 4, 209 << 4, 209 << 4, 209 << 4,
436 205 << 4, 205 << 4, 205 << 4, 205 << 4, 205 << 4, 205 << 4, 205 << 4, 205 << 4,
437 205 << 4, 205 << 4, 205 << 4, 205 << 4, 205 << 4, 205 << 4, 205 << 4, 205 << 4,
438 200 << 4, 200 << 4, 200 << 4, 200 << 4, 200 << 4, 200 << 4, 200 << 4, 200 << 4,
439 200 << 4, 200 << 4, 200 << 4, 200 << 4, 200 << 4, 200 << 4, 200 << 4, 200 << 4,
440 195 << 4, 195 << 4, 195 << 4, 195 << 4, 195 << 4, 195 << 4, 195 << 4, 195 << 4,
441 195 << 4, 195 << 4, 195 << 4, 195 << 4, 195 << 4, 195 << 4, 195 << 4, 195 << 4,
442 191 << 4, 191 << 4, 191 << 4, 191 << 4, 191 << 4, 191 << 4, 191 << 4, 191 << 4,
443 191 << 4, 191 << 4, 191 << 4, 191 << 4, 191 << 4, 191 << 4, 191 << 4, 191 << 4,
444 186 << 4, 186 << 4, 186 << 4, 186 << 4, 186 << 4, 186 << 4, 186 << 4, 186 << 4,
445 186 << 4, 186 << 4, 186 << 4, 186 << 4, 186 << 4, 186 << 4, 186 << 4, 186 << 4,
446 181 << 4, 181 << 4, 181 << 4, 181 << 4, 181 << 4, 181 << 4, 181 << 4, 181 << 4,
447 181 << 4, 181 << 4, 181 << 4, 181 << 4, 181 << 4, 181 << 4, 181 << 4, 181 << 4,
448 176 << 4, 176 << 4, 176 << 4, 176 << 4, 176 << 4, 176 << 4, 176 << 4, 176 << 4,
449 176 << 4, 176 << 4, 176 << 4, 176 << 4, 176 << 4, 176 << 4, 176 << 4, 176 << 4,
450 170 << 4, 170 << 4, 170 << 4, 170 << 4, 170 << 4, 170 << 4, 170 << 4, 170 << 4,
451 170 << 4, 170 << 4, 170 << 4, 170 << 4, 170 << 4, 170 << 4, 170 << 4, 170 << 4,
452 165 << 4, 165 << 4, 165 << 4, 165 << 4, 165 << 4, 165 << 4, 165 << 4, 165 << 4,
453 165 << 4, 165 << 4, 165 << 4, 165 << 4, 165 << 4, 165 << 4, 165 << 4, 165 << 4,
454 160 << 4, 160 << 4, 160 << 4, 160 << 4, 160 << 4, 160 << 4, 160 << 4, 160 << 4,
455 160 << 4, 160 << 4, 160 << 4, 160 << 4, 160 << 4, 160 << 4, 160 << 4, 160 << 4,
456 154 << 4, 154 << 4, 154 << 4, 154 << 4, 154 << 4, 154 << 4, 154 << 4, 154 << 4,
457 154 << 4, 154 << 4, 154 << 4, 154 << 4, 154 << 4, 154 << 4, 154 << 4, 154 << 4,
458 149 << 4, 149 << 4, 149 << 4, 149 << 4, 149 << 4, 149 << 4, 149 << 4, 149 << 4,
459 149 << 4, 149 << 4, 149 << 4, 149 << 4, 149 << 4, 149 << 4, 149 << 4, 149 << 4,
460 144 << 4, 144 << 4, 144 << 4, 144 << 4, 144 << 4, 144 << 4, 144 << 4, 144 << 4,
461 144 << 4, 144 << 4, 144 << 4, 144 << 4, 144 << 4, 144 << 4, 144 << 4, 144 << 4,
462 138 << 4, 138 << 4, 138 << 4, 138 << 4, 138 << 4, 138 << 4, 138 << 4, 138 << 4,
463 138 << 4, 138 << 4, 138 << 4, 138 << 4, 138 << 4, 138 << 4, 138 << 4, 138 << 4,
464 132 << 4, 132 << 4, 132 << 4, 132 << 4, 132 << 4, 132 << 4, 132 << 4, 132 << 4,
465 132 << 4, 132 << 4, 132 << 4, 132 << 4, 132 << 4, 132 << 4, 132 << 4, 132 << 4,
466 127 << 4, 127 << 4, 127 << 4, 127 << 4, 127 << 4, 127 << 4, 127 << 4, 127 << 4,
467 127 << 4, 127 << 4, 127 << 4, 127 << 4, 127 << 4, 127 << 4, 127 << 4, 127 << 4,
468 121 << 4, 121 << 4, 121 << 4, 121 << 4, 121 << 4, 121 << 4, 121 << 4, 121 << 4,
469 121 << 4, 121 << 4, 121 << 4, 121 << 4, 121 << 4, 121 << 4, 121 << 4, 121 << 4,
470 116 << 4, 116 << 4, 116 << 4, 116 << 4, 116 << 4, 116 << 4, 116 << 4, 116 << 4,
471 116 << 4, 116 << 4, 116 << 4, 116 << 4, 116 << 4, 116 << 4, 116 << 4, 116 << 4,
472 110 << 4, 110 << 4, 110 << 4, 110 << 4, 110 << 4, 110 << 4, 110 << 4, 110 << 4,
473 110 << 4, 110 << 4, 110 << 4, 110 << 4, 110 << 4, 110 << 4, 110 << 4, 110 << 4,
474 105 << 4, 105 << 4, 105 << 4, 105 << 4, 105 << 4, 105 << 4, 105 << 4, 105 << 4,
475 105 << 4, 105 << 4, 105 << 4, 105 << 4, 105 << 4, 105 << 4, 105 << 4, 105 << 4,
476 99 << 4, 99 << 4, 99 << 4, 99 << 4, 99 << 4, 99 << 4, 99 << 4, 99 << 4,
477 99 << 4, 99 << 4, 99 << 4, 99 << 4, 99 << 4, 99 << 4, 99 << 4, 99 << 4,
478 94 << 4, 94 << 4, 94 << 4, 94 << 4, 94 << 4, 94 << 4, 94 << 4, 94 << 4,
479 94 << 4, 94 << 4, 94 << 4, 94 << 4, 94 << 4, 94 << 4, 94 << 4, 94 << 4,
480 88 << 4, 88 << 4, 88 << 4, 88 << 4, 88 << 4, 88 << 4, 88 << 4, 88 << 4,
481 88 << 4, 88 << 4, 88 << 4, 88 << 4, 88 << 4, 88 << 4, 88 << 4, 88 << 4,
482 83 << 4, 83 << 4, 83 << 4, 83 << 4, 83 << 4, 83 << 4, 83 << 4, 83 << 4,
483 83 << 4, 83 << 4, 83 << 4, 83 << 4, 83 << 4, 83 << 4, 83 << 4, 83 << 4,
484 78 << 4, 78 << 4, 78 << 4, 78 << 4, 78 << 4, 78 << 4, 78 << 4, 78 << 4,
485 78 << 4, 78 << 4, 78 << 4, 78 << 4, 78 << 4, 78 << 4, 78 << 4, 78 << 4,
486 73 << 4, 73 << 4, 73 << 4, 73 << 4, 73 << 4, 73 << 4, 73 << 4, 73 << 4,
487 73 << 4, 73 << 4, 73 << 4, 73 << 4, 73 << 4, 73 << 4, 73 << 4, 73 << 4,
488 67 << 4, 67 << 4, 67 << 4, 67 << 4, 67 << 4, 67 << 4, 67 << 4, 67 << 4,
489 67 << 4, 67 << 4, 67 << 4, 67 << 4, 67 << 4, 67 << 4, 67 << 4, 67 << 4,
490 62 << 4, 62 << 4, 62 << 4, 62 << 4, 62 << 4, 62 << 4, 62 << 4, 62 << 4,
491 62 << 4, 62 << 4, 62 << 4, 62 << 4, 62 << 4, 62 << 4, 62 << 4, 62 << 4,
492 58 << 4, 58 << 4, 58 << 4, 58 << 4, 58 << 4, 58 << 4, 58 << 4, 58 << 4,
493 58 << 4, 58 << 4, 58 << 4, 58 << 4, 58 << 4, 58 << 4, 58 << 4, 58 << 4,
494 53 << 4, 53 << 4, 53 << 4, 53 << 4, 53 << 4, 53 << 4, 53 << 4, 53 << 4,
495 53 << 4, 53 << 4, 53 << 4, 53 << 4, 53 << 4, 53 << 4, 53 << 4, 53 << 4,
496 48 << 4, 48 << 4, 48 << 4, 48 << 4, 48 << 4, 48 << 4, 48 << 4, 48 << 4,
497 48 << 4, 48 << 4, 48 << 4, 48 << 4, 48 << 4, 48 << 4, 48 << 4, 48 << 4,
498 43 << 4, 43 << 4, 43 << 4, 43 << 4, 43 << 4, 43 << 4, 43 << 4, 43 << 4,
499 43 << 4, 43 << 4, 43 << 4, 43 << 4, 43 << 4, 43 << 4, 43 << 4, 43 << 4,
500 39 << 4, 39 << 4, 39 << 4, 39 << 4, 39 << 4, 39 << 4, 39 << 4, 39 << 4,
501 39 << 4, 39 << 4, 39 << 4, 39 << 4, 39 << 4, 39 << 4, 39 << 4, 39 << 4,
502 35 << 4, 35 << 4, 35 << 4, 35 << 4, 35 << 4, 35 << 4, 35 << 4, 35 << 4,
503 35 << 4, 35 << 4, 35 << 4, 35 << 4, 35 << 4, 35 << 4, 35 << 4, 35 << 4,
504 31 << 4, 31 << 4, 31 << 4, 31 << 4, 31 << 4, 31 << 4, 31 << 4, 31 << 4,
505 31 << 4, 31 << 4, 31 << 4, 31 << 4, 31 << 4, 31 << 4, 31 << 4, 31 << 4,
506 27 << 4, 27 << 4, 27 << 4, 27 << 4, 27 << 4, 27 << 4, 27 << 4, 27 << 4,
507 27 << 4, 27 << 4, 27 << 4, 27 << 4, 27 << 4, 27 << 4, 27 << 4, 27 << 4,
508 23 << 4, 23 << 4, 23 << 4, 23 << 4, 23 << 4, 23 << 4, 23 << 4, 23 << 4,
509 23 << 4, 23 << 4, 23 << 4, 23 << 4, 23 << 4, 23 << 4, 23 << 4, 23 << 4,
510 19 << 4, 19 << 4, 19 << 4, 19 << 4, 19 << 4, 19 << 4, 19 << 4, 19 << 4,
511 19 << 4, 19 << 4, 19 << 4, 19 << 4, 19 << 4, 19 << 4, 19 << 4, 19 << 4,
512 16 << 4, 16 << 4, 16 << 4, 16 << 4, 16 << 4, 16 << 4, 16 << 4, 16 << 4,
513 16 << 4, 16 << 4, 16 << 4, 16 << 4, 16 << 4, 16 << 4, 16 << 4, 16 << 4,
514 12 << 4, 12 << 4, 12 << 4, 12 << 4, 12 << 4, 12 << 4, 12 << 4, 12 << 4,
515 12 << 4, 12 << 4, 12 << 4, 12 << 4, 12 << 4, 12 << 4, 12 << 4, 12 << 4,
516 9 << 4, 9 << 4, 9 << 4, 9 << 4, 9 << 4, 9 << 4, 9 << 4, 9 << 4,
517 9 << 4, 9 << 4, 9 << 4, 9 << 4, 9 << 4, 9 << 4, 9 << 4, 9 << 4,
518 7 << 4, 7 << 4, 7 << 4, 7 << 4, 7 << 4, 7 << 4, 7 << 4, 7 << 4,
519 7 << 4, 7 << 4, 7 << 4, 7 << 4, 7 << 4, 7 << 4, 7 << 4, 7 << 4,
520 4 << 4, 4 << 4, 4 << 4, 4 << 4, 4 << 4, 4 << 4, 4 << 4, 4 << 4,
521 4 << 4, 4 << 4, 4 << 4, 4 << 4, 4 << 4, 4 << 4, 4 << 4, 4 << 4,
522 2 << 4, 2 << 4, 2 << 4, 2 << 4, 2 << 4, 2 << 4, 2 << 4, 2 << 4,
523 2 << 4, 2 << 4, 2 << 4, 2 << 4, 2 << 4, 2 << 4, 2 << 4, 2 << 4
524 },
525 {
526 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4,
527 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4,
528 -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4,
529 -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4,
530 -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4,
531 -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4,
532 -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4,
533 -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4,
534 -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4,
535 -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4,
536 -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4,
537 -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4,
538 -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4,
539 -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4,
540 -10 << 4, -10 << 4, -10 << 4, -10 << 4, -10 << 4, -10 << 4, -10 << 4, -10 << 4,
541 -10 << 4, -10 << 4, -10 << 4, -10 << 4, -10 << 4, -10 << 4, -10 << 4, -10 << 4,
542 -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4,
543 -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4,
544 -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4,
545 -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4,
546 -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4,
547 -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4,
548 -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4,
549 -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4,
550 -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4,
551 -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4,
552 -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4,
553 -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 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 -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 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 -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4,
562 -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4,
563 -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 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 -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 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 -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4,
572 -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4,
573 -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4,
574 -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4,
575 -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4,
576 -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4,
577 -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4, -19 << 4,
578 -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4,
579 -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 4, -18 << 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 -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 4, -17 << 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 -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4, -16 << 4,
592 -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4,
593 -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 4, -15 << 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 -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4, -14 << 4,
598 -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4,
599 -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 4, -13 << 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 -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 4, -12 << 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 -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 4, -11 << 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 -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4, -9 << 4,
616 -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4,
617 -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 4, -8 << 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 -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4, -6 << 4,
624 -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4,
625 -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4, -5 << 4,
626 -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4,
627 -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4,
628 -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4,
629 -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4,
630 -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4,
631 -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4, -4 << 4,
632 -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4,
633 -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 4, -3 << 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 -2 << 4, -2 << 4, -2 << 4, -2 << 4, -2 << 4, -2 << 4, -2 << 4, -2 << 4,
638 -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4,
639 -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4,
640 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4,
641 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4,
642 -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4,
643 -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4, -1 << 4,
644 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4,
645 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4,
646 1 << 4, 1 << 4, 1 << 4, 1 << 4, 1 << 4, 1 << 4, 1 << 4, 1 << 4,
647 1 << 4, 1 << 4, 1 << 4, 1 << 4, 1 << 4, 1 << 4, 1 << 4, 1 << 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,
653 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4, 0 << 4
654 }
655 };
656
657 static const struct ia_css_dz_config default_dz_config = {
658 HRT_GDC_N,
659 HRT_GDC_N,
660 {
661 \
662 {0, 0}, \
663 {0, 0}, \
664 }
665 };
666
667 static const struct ia_css_vector default_motion_config = {
668 0,
669 0
670 };
671
672 /* ------ deprecated(bz675) : from ------ */
673 static const struct ia_css_shading_settings default_shading_settings = {
674 1 /* enable shading table conversion in the css
675 (This matches the legacy way.) */
676 };
677
678 /* ------ deprecated(bz675) : to ------ */
679
680 struct ia_css_isp_skc_dvs_statistics {
681 ia_css_ptr p_data;
682 };
683
684 static int
685 ref_sh_css_ddr_address_map(
686 struct sh_css_ddr_address_map *map,
687 struct sh_css_ddr_address_map *out);
688
689 static int
690 write_ia_css_isp_parameter_set_info_to_ddr(
691 struct ia_css_isp_parameter_set_info *me,
692 ia_css_ptr *out);
693
694 static int
695 free_ia_css_isp_parameter_set_info(ia_css_ptr ptr);
696
697 static int
698 sh_css_params_write_to_ddr_internal(
699 struct ia_css_pipe *pipe,
700 unsigned int pipe_id,
701 struct ia_css_isp_parameters *params,
702 const struct ia_css_pipeline_stage *stage,
703 struct sh_css_ddr_address_map *ddr_map,
704 struct sh_css_ddr_address_map_size *ddr_map_size);
705
706 static int
707 sh_css_create_isp_params(struct ia_css_stream *stream,
708 struct ia_css_isp_parameters **isp_params_out);
709
710 static bool
711 sh_css_init_isp_params_from_global(struct ia_css_stream *stream,
712 struct ia_css_isp_parameters *params,
713 bool use_default_config,
714 struct ia_css_pipe *pipe_in);
715
716 static int
717 sh_css_init_isp_params_from_config(struct ia_css_pipe *pipe,
718 struct ia_css_isp_parameters *params,
719 const struct ia_css_isp_config *config,
720 struct ia_css_pipe *pipe_in);
721
722 static int
723 sh_css_set_global_isp_config_on_pipe(
724 struct ia_css_pipe *curr_pipe,
725 const struct ia_css_isp_config *config,
726 struct ia_css_pipe *pipe);
727
728 static int
729 sh_css_set_per_frame_isp_config_on_pipe(
730 struct ia_css_stream *stream,
731 const struct ia_css_isp_config *config,
732 struct ia_css_pipe *pipe);
733
734 static int
735 sh_css_update_uds_and_crop_info_based_on_zoom_region(
736 const struct ia_css_binary_info *info,
737 const struct ia_css_frame_info *in_frame_info,
738 const struct ia_css_frame_info *out_frame_info,
739 const struct ia_css_resolution *dvs_env,
740 const struct ia_css_dz_config *zoom,
741 const struct ia_css_vector *motion_vector,
742 struct sh_css_uds_info *uds, /* out */
743 struct sh_css_crop_pos *sp_out_crop_pos, /* out */
744 struct ia_css_resolution pipe_in_res,
745 bool enable_zoom);
746
747 ia_css_ptr
sh_css_params_ddr_address_map(void)748 sh_css_params_ddr_address_map(void)
749 {
750 return sp_ddr_ptrs;
751 }
752
753 /* ****************************************************
754 * Each coefficient is stored as 7bits to fit 2 of them into one
755 * ISP vector element, so we will store 4 coefficents on every
756 * memory word (32bits)
757 *
758 * 0: Coefficient 0 used bits
759 * 1: Coefficient 1 used bits
760 * 2: Coefficient 2 used bits
761 * 3: Coefficient 3 used bits
762 * x: not used
763 *
764 * xx33333332222222 | xx11111110000000
765 *
766 * ***************************************************
767 */
768 static struct ia_css_host_data *
convert_allocate_fpntbl(struct ia_css_isp_parameters * params)769 convert_allocate_fpntbl(struct ia_css_isp_parameters *params)
770 {
771 unsigned int i, j;
772 short *data_ptr;
773 struct ia_css_host_data *me;
774 unsigned int isp_format_data_size;
775 u32 *isp_format_data_ptr;
776
777 assert(params);
778
779 data_ptr = params->fpn_config.data;
780 isp_format_data_size = params->fpn_config.height * params->fpn_config.width *
781 sizeof(uint32_t);
782
783 me = ia_css_host_data_allocate(isp_format_data_size);
784
785 if (!me)
786 return NULL;
787
788 isp_format_data_ptr = (uint32_t *)me->address;
789
790 for (i = 0; i < params->fpn_config.height; i++) {
791 for (j = 0;
792 j < params->fpn_config.width;
793 j += 4, data_ptr += 4, isp_format_data_ptr++) {
794 int data = data_ptr[0] << 0 |
795 data_ptr[1] << 7 |
796 data_ptr[2] << 16 |
797 data_ptr[3] << 23;
798 *isp_format_data_ptr = data;
799 }
800 }
801 return me;
802 }
803
804 static int
store_fpntbl(struct ia_css_isp_parameters * params,ia_css_ptr ptr)805 store_fpntbl(struct ia_css_isp_parameters *params, ia_css_ptr ptr)
806 {
807 struct ia_css_host_data *isp_data;
808
809 assert(params);
810 assert(ptr != mmgr_NULL);
811
812 isp_data = convert_allocate_fpntbl(params);
813 if (!isp_data) {
814 IA_CSS_LEAVE_ERR_PRIVATE(-ENOMEM);
815 return -ENOMEM;
816 }
817 ia_css_params_store_ia_css_host_data(ptr, isp_data);
818
819 ia_css_host_data_free(isp_data);
820 return 0;
821 }
822
823 static void
convert_raw_to_fpn(struct ia_css_isp_parameters * params)824 convert_raw_to_fpn(struct ia_css_isp_parameters *params)
825 {
826 int maxval = 0;
827 unsigned int i;
828
829 assert(params);
830
831 /* Find the maximum value in the table */
832 for (i = 0; i < params->fpn_config.height * params->fpn_config.width; i++) {
833 int val = params->fpn_config.data[i];
834 /* Make sure FPN value can be represented in 13-bit unsigned
835 * number (ISP precision - 1), but note that actual input range
836 * depends on precision of input frame data.
837 */
838 if (val < 0) {
839 /* Checkpatch patch */
840 val = 0;
841 } else if (val >= (1 << 13)) {
842 /* Checkpatch patch */
843 /* MW: BUG, is "13" a system or application property */
844 val = (1 << 13) - 1;
845 }
846 maxval = max(maxval, val);
847 }
848 /* Find the lowest shift value to remap the values in the range
849 * 0..maxval to 0..2^shiftval*63.
850 */
851 params->fpn_config.shift = 0;
852 while (maxval > 63) {
853 /* MW: BUG, is "63" a system or application property */
854 maxval >>= 1;
855 params->fpn_config.shift++;
856 }
857 /* Adjust the values in the table for the shift value */
858 for (i = 0; i < params->fpn_config.height * params->fpn_config.width; i++)
859 ((unsigned short *)params->fpn_config.data)[i] >>= params->fpn_config.shift;
860 }
861
862 static void
ia_css_process_kernel(struct ia_css_stream * stream,struct ia_css_isp_parameters * params,void (* process)(unsigned int pipe_id,const struct ia_css_pipeline_stage * stage,struct ia_css_isp_parameters * params))863 ia_css_process_kernel(struct ia_css_stream *stream,
864 struct ia_css_isp_parameters *params,
865 void (*process)(unsigned int pipe_id,
866 const struct ia_css_pipeline_stage *stage,
867 struct ia_css_isp_parameters *params))
868 {
869 int i;
870
871 for (i = 0; i < stream->num_pipes; i++) {
872 struct ia_css_pipe *pipe = stream->pipes[i];
873 struct ia_css_pipeline *pipeline = ia_css_pipe_get_pipeline(pipe);
874 struct ia_css_pipeline_stage *stage;
875
876 /* update the other buffers to the pipe specific copies */
877 for (stage = pipeline->stages; stage; stage = stage->next) {
878 if (!stage || !stage->binary) continue;
879 process(pipeline->pipe_id, stage, params);
880 }
881 }
882 }
883
884 static int
sh_css_select_dp_10bpp_config(const struct ia_css_pipe * pipe,bool * is_dp_10bpp)885 sh_css_select_dp_10bpp_config(const struct ia_css_pipe *pipe,
886 bool *is_dp_10bpp)
887 {
888 int err = 0;
889 /* Currently we check if 10bpp DPC configuration is required based
890 * on the use case,i.e. if BDS and DPC is both enabled. The more cleaner
891 * design choice would be to expose the type of DPC (either 10bpp or 13bpp)
892 * using the binary info, but the current control flow does not allow this
893 * implementation. (This is because the configuration is set before a
894 * binary is selected, and the binary info is not available)
895 */
896 if ((!pipe) || (!is_dp_10bpp)) {
897 IA_CSS_LEAVE_ERR_PRIVATE(-EINVAL);
898 err = -EINVAL;
899 } else {
900 *is_dp_10bpp = false;
901
902 /* check if DPC is enabled from the host */
903 if (pipe->config.enable_dpc) {
904 /*check if BDS is enabled*/
905 unsigned int required_bds_factor = SH_CSS_BDS_FACTOR_1_00;
906
907 if ((pipe->config.bayer_ds_out_res.width != 0) &&
908 (pipe->config.bayer_ds_out_res.height != 0)) {
909 if (0 == binarydesc_calculate_bds_factor(
910 pipe->config.input_effective_res,
911 pipe->config.bayer_ds_out_res,
912 &required_bds_factor)) {
913 if (required_bds_factor != SH_CSS_BDS_FACTOR_1_00) {
914 /*we use 10bpp BDS configuration*/
915 *is_dp_10bpp = true;
916 }
917 }
918 }
919 }
920 }
921
922 return err;
923 }
924
925 int
sh_css_set_black_frame(struct ia_css_stream * stream,const struct ia_css_frame * raw_black_frame)926 sh_css_set_black_frame(struct ia_css_stream *stream,
927 const struct ia_css_frame *raw_black_frame)
928 {
929 struct ia_css_isp_parameters *params;
930 /* this function desperately needs to be moved to the ISP or SP such
931 * that it can use the DMA.
932 */
933 unsigned int height, width, y, x, k, data;
934 ia_css_ptr ptr;
935
936 assert(stream);
937 assert(raw_black_frame);
938
939 params = stream->isp_params_configs;
940 height = raw_black_frame->frame_info.res.height;
941 width = raw_black_frame->frame_info.padded_width;
942
943 ptr = raw_black_frame->data
944 + raw_black_frame->planes.raw.offset;
945
946 IA_CSS_ENTER_PRIVATE("black_frame=%p", raw_black_frame);
947
948 if (params->fpn_config.data &&
949 (params->fpn_config.width != width || params->fpn_config.height != height)) {
950 kvfree(params->fpn_config.data);
951 params->fpn_config.data = NULL;
952 }
953 if (!params->fpn_config.data) {
954 params->fpn_config.data = kvmalloc(array3_size(height, width, sizeof(short)),
955 GFP_KERNEL);
956 if (!params->fpn_config.data) {
957 IA_CSS_ERROR("out of memory");
958 IA_CSS_LEAVE_ERR_PRIVATE(-ENOMEM);
959 return -ENOMEM;
960 }
961 params->fpn_config.width = width;
962 params->fpn_config.height = height;
963 params->fpn_config.shift = 0;
964 }
965
966 /* store raw to fpntbl */
967 for (y = 0; y < height; y++) {
968 for (x = 0; x < width; x += (ISP_VEC_NELEMS * 2)) {
969 int ofs = y * width + x;
970
971 for (k = 0; k < ISP_VEC_NELEMS; k += 2) {
972 hmm_load(ptr, (void *)(&data), sizeof(int));
973 params->fpn_config.data[ofs + 2 * k] =
974 (short)(data & 0xFFFF);
975 params->fpn_config.data[ofs + 2 * k + 2] =
976 (short)((data >> 16) & 0xFFFF);
977 ptr += sizeof(int); /* byte system address */
978 }
979 for (k = 0; k < ISP_VEC_NELEMS; k += 2) {
980 hmm_load(ptr, (void *)(&data), sizeof(int));
981 params->fpn_config.data[ofs + 2 * k + 1] =
982 (short)(data & 0xFFFF);
983 params->fpn_config.data[ofs + 2 * k + 3] =
984 (short)((data >> 16) & 0xFFFF);
985 ptr += sizeof(int); /* byte system address */
986 }
987 }
988 }
989
990 /* raw -> fpn */
991 convert_raw_to_fpn(params);
992
993 /* overwrite isp parameter */
994 ia_css_process_kernel(stream, params, ia_css_kernel_process_param[IA_CSS_FPN_ID]);
995
996 IA_CSS_LEAVE_ERR_PRIVATE(0);
997
998 return 0;
999 }
1000
1001 bool
sh_css_params_set_binning_factor(struct ia_css_stream * stream,unsigned int binning_fact)1002 sh_css_params_set_binning_factor(struct ia_css_stream *stream,
1003 unsigned int binning_fact)
1004 {
1005 struct ia_css_isp_parameters *params;
1006
1007 IA_CSS_ENTER_PRIVATE("void");
1008 assert(stream);
1009
1010 params = stream->isp_params_configs;
1011
1012 if (params->sensor_binning != binning_fact) {
1013 params->sensor_binning = binning_fact;
1014 params->sc_table_changed = true;
1015 }
1016
1017 IA_CSS_LEAVE_PRIVATE("void");
1018
1019 return params->sc_table_changed;
1020 }
1021
1022 static void
sh_css_set_shading_table(struct ia_css_stream * stream,struct ia_css_isp_parameters * params,const struct ia_css_shading_table * table)1023 sh_css_set_shading_table(struct ia_css_stream *stream,
1024 struct ia_css_isp_parameters *params,
1025 const struct ia_css_shading_table *table)
1026 {
1027 IA_CSS_ENTER_PRIVATE("");
1028 if (!table)
1029 return;
1030 assert(stream);
1031
1032 if (!table->enable)
1033 table = NULL;
1034
1035 if (table != params->sc_table) {
1036 params->sc_table = table;
1037 params->sc_table_changed = true;
1038 /* Not very clean, this goes to sh_css.c to invalidate the
1039 * shading table for all pipes. Should replaced by a loop
1040 * and a pipe-specific call.
1041 */
1042 if (!params->output_frame)
1043 sh_css_invalidate_shading_tables(stream);
1044 }
1045
1046 IA_CSS_LEAVE_PRIVATE("void");
1047 }
1048
1049 void
ia_css_params_store_ia_css_host_data(ia_css_ptr ddr_addr,struct ia_css_host_data * data)1050 ia_css_params_store_ia_css_host_data(
1051 ia_css_ptr ddr_addr,
1052 struct ia_css_host_data *data)
1053 {
1054 assert(data);
1055 assert(data->address);
1056 assert(ddr_addr != mmgr_NULL);
1057
1058 IA_CSS_ENTER_PRIVATE("");
1059
1060 hmm_store(ddr_addr,
1061 (void *)(data->address),
1062 (size_t)data->size);
1063
1064 IA_CSS_LEAVE_PRIVATE("void");
1065 }
1066
1067 struct ia_css_host_data *
ia_css_params_alloc_convert_sctbl(const struct ia_css_pipeline_stage * stage,const struct ia_css_shading_table * shading_table)1068 ia_css_params_alloc_convert_sctbl(
1069 const struct ia_css_pipeline_stage *stage,
1070 const struct ia_css_shading_table *shading_table)
1071 {
1072 const struct ia_css_binary *binary = stage->binary;
1073 struct ia_css_host_data *sctbl;
1074 unsigned int i, j, aligned_width;
1075 unsigned int sctbl_size;
1076 short int *ptr;
1077
1078 assert(binary);
1079 assert(shading_table);
1080
1081 IA_CSS_ENTER_PRIVATE("");
1082
1083 if (!shading_table) {
1084 IA_CSS_LEAVE_PRIVATE("void");
1085 return NULL;
1086 }
1087
1088 aligned_width = binary->sctbl_aligned_width_per_color;
1089 sctbl_size = shading_table->height * IA_CSS_SC_NUM_COLORS * aligned_width *
1090 sizeof(short);
1091
1092 sctbl = ia_css_host_data_allocate((size_t)sctbl_size);
1093
1094 if (!sctbl)
1095 return NULL;
1096 ptr = (short int *)sctbl->address;
1097 memset(ptr,
1098 0,
1099 sctbl_size);
1100
1101 for (i = 0; i < shading_table->height; i++) {
1102 for (j = 0; j < IA_CSS_SC_NUM_COLORS; j++) {
1103 memcpy(ptr,
1104 &shading_table->data[j]
1105 [i * shading_table->width],
1106 shading_table->width * sizeof(short));
1107 ptr += aligned_width;
1108 }
1109 }
1110
1111 IA_CSS_LEAVE_PRIVATE("void");
1112 return sctbl;
1113 }
1114
ia_css_params_store_sctbl(const struct ia_css_pipeline_stage * stage,ia_css_ptr sc_tbl,const struct ia_css_shading_table * sc_config)1115 int ia_css_params_store_sctbl(
1116 const struct ia_css_pipeline_stage *stage,
1117 ia_css_ptr sc_tbl,
1118 const struct ia_css_shading_table *sc_config)
1119 {
1120 struct ia_css_host_data *isp_sc_tbl;
1121
1122 IA_CSS_ENTER_PRIVATE("");
1123
1124 if (!sc_config) {
1125 IA_CSS_LEAVE_PRIVATE("void");
1126 return 0;
1127 }
1128
1129 isp_sc_tbl = ia_css_params_alloc_convert_sctbl(stage, sc_config);
1130 if (!isp_sc_tbl) {
1131 IA_CSS_LEAVE_ERR_PRIVATE(-ENOMEM);
1132 return -ENOMEM;
1133 }
1134 /* store the shading table to ddr */
1135 ia_css_params_store_ia_css_host_data(sc_tbl, isp_sc_tbl);
1136 ia_css_host_data_free(isp_sc_tbl);
1137
1138 IA_CSS_LEAVE_PRIVATE("void");
1139
1140 return 0;
1141 }
1142
1143 static void
sh_css_enable_pipeline(const struct ia_css_binary * binary)1144 sh_css_enable_pipeline(const struct ia_css_binary *binary)
1145 {
1146 if (!binary)
1147 return;
1148
1149 IA_CSS_ENTER_PRIVATE("");
1150
1151 ia_css_isp_param_enable_pipeline(&binary->mem_params);
1152
1153 IA_CSS_LEAVE_PRIVATE("void");
1154 }
1155
1156 static int
ia_css_process_zoom_and_motion(struct ia_css_isp_parameters * params,const struct ia_css_pipeline_stage * first_stage)1157 ia_css_process_zoom_and_motion(
1158 struct ia_css_isp_parameters *params,
1159 const struct ia_css_pipeline_stage *first_stage)
1160 {
1161 /* first_stage can be NULL */
1162 const struct ia_css_pipeline_stage *stage;
1163 int err = 0;
1164 struct ia_css_resolution pipe_in_res;
1165
1166 pipe_in_res.width = 0;
1167 pipe_in_res.height = 0;
1168
1169 assert(params);
1170
1171 IA_CSS_ENTER_PRIVATE("");
1172
1173 /* Go through all stages to udate uds and cropping */
1174 for (stage = first_stage; stage; stage = stage->next) {
1175 struct ia_css_binary *binary;
1176 /* note: the var below is made static as it is quite large;
1177 if it is not static it ends up on the stack which could
1178 cause issues for drivers
1179 */
1180 static struct ia_css_binary tmp_binary;
1181
1182 const struct ia_css_binary_xinfo *info = NULL;
1183
1184 binary = stage->binary;
1185 if (binary) {
1186 info = binary->info;
1187 } else {
1188 const struct sh_css_binary_args *args = &stage->args;
1189 const struct ia_css_frame_info *out_infos[IA_CSS_BINARY_MAX_OUTPUT_PORTS] = {NULL};
1190
1191 out_infos[0] = ia_css_frame_get_info(args->out_frame[0]);
1192
1193 info = &stage->firmware->info.isp;
1194 ia_css_binary_fill_info(info, false, false,
1195 ATOMISP_INPUT_FORMAT_RAW_10,
1196 ia_css_frame_get_info(args->in_frame),
1197 NULL,
1198 out_infos,
1199 ia_css_frame_get_info(args->out_vf_frame),
1200 &tmp_binary,
1201 NULL,
1202 -1, true);
1203 binary = &tmp_binary;
1204 binary->info = info;
1205 }
1206
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;
1210 }
1211
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(
1216 &info->sp,
1217 &binary->in_frame_info,
1218 &binary->out_frame_info[0],
1219 &binary->dvs_envelope,
1220 ¶ms->dz_config,
1221 ¶ms->motion_config,
1222 ¶ms->uds[stage->stage_num].uds,
1223 ¶ms->uds[stage->stage_num].crop_pos,
1224 stage->enable_zoom);
1225 } else {
1226 err = sh_css_update_uds_and_crop_info_based_on_zoom_region(
1227 &info->sp,
1228 &binary->in_frame_info,
1229 &binary->out_frame_info[0],
1230 &binary->dvs_envelope,
1231 ¶ms->dz_config,
1232 ¶ms->motion_config,
1233 ¶ms->uds[stage->stage_num].uds,
1234 ¶ms->uds[stage->stage_num].crop_pos,
1235 pipe_in_res,
1236 stage->enable_zoom);
1237 if (err)
1238 return err;
1239 }
1240 }
1241 params->isp_params_changed = true;
1242
1243 IA_CSS_LEAVE_PRIVATE("void");
1244 return err;
1245 }
1246
1247 static void
sh_css_set_gamma_table(struct ia_css_isp_parameters * params,const struct ia_css_gamma_table * table)1248 sh_css_set_gamma_table(struct ia_css_isp_parameters *params,
1249 const struct ia_css_gamma_table *table)
1250 {
1251 if (!table)
1252 return;
1253 IA_CSS_ENTER_PRIVATE("table=%p", table);
1254
1255 assert(params);
1256 params->gc_table = *table;
1257 params->config_changed[IA_CSS_GC_ID] = true;
1258
1259 IA_CSS_LEAVE_PRIVATE("void");
1260 }
1261
1262 static void
sh_css_get_gamma_table(const struct ia_css_isp_parameters * params,struct ia_css_gamma_table * table)1263 sh_css_get_gamma_table(const struct ia_css_isp_parameters *params,
1264 struct ia_css_gamma_table *table)
1265 {
1266 if (!table)
1267 return;
1268 IA_CSS_ENTER_PRIVATE("table=%p", table);
1269
1270 assert(params);
1271 *table = params->gc_table;
1272
1273 IA_CSS_LEAVE_PRIVATE("void");
1274 }
1275
1276 static void
sh_css_set_ctc_table(struct ia_css_isp_parameters * params,const struct ia_css_ctc_table * table)1277 sh_css_set_ctc_table(struct ia_css_isp_parameters *params,
1278 const struct ia_css_ctc_table *table)
1279 {
1280 if (!table)
1281 return;
1282
1283 IA_CSS_ENTER_PRIVATE("table=%p", table);
1284
1285 assert(params);
1286 params->ctc_table = *table;
1287 params->config_changed[IA_CSS_CTC_ID] = true;
1288
1289 IA_CSS_LEAVE_PRIVATE("void");
1290 }
1291
1292 static void
sh_css_get_ctc_table(const struct ia_css_isp_parameters * params,struct ia_css_ctc_table * table)1293 sh_css_get_ctc_table(const struct ia_css_isp_parameters *params,
1294 struct ia_css_ctc_table *table)
1295 {
1296 if (!table)
1297 return;
1298
1299 IA_CSS_ENTER_PRIVATE("table=%p", table);
1300
1301 assert(params);
1302 *table = params->ctc_table;
1303
1304 IA_CSS_LEAVE_PRIVATE("void");
1305 }
1306
1307 static void
sh_css_set_macc_table(struct ia_css_isp_parameters * params,const struct ia_css_macc_table * table)1308 sh_css_set_macc_table(struct ia_css_isp_parameters *params,
1309 const struct ia_css_macc_table *table)
1310 {
1311 if (!table)
1312 return;
1313
1314 IA_CSS_ENTER_PRIVATE("table=%p", table);
1315
1316 assert(params);
1317 params->macc_table = *table;
1318 params->config_changed[IA_CSS_MACC_ID] = true;
1319
1320 IA_CSS_LEAVE_PRIVATE("void");
1321 }
1322
1323 static void
sh_css_get_macc_table(const struct ia_css_isp_parameters * params,struct ia_css_macc_table * table)1324 sh_css_get_macc_table(const struct ia_css_isp_parameters *params,
1325 struct ia_css_macc_table *table)
1326 {
1327 if (!table)
1328 return;
1329
1330 IA_CSS_ENTER_PRIVATE("table=%p", table);
1331
1332 assert(params);
1333 *table = params->macc_table;
1334
1335 IA_CSS_LEAVE_PRIVATE("void");
1336 }
1337
ia_css_morph_table_free(struct ia_css_morph_table * me)1338 void ia_css_morph_table_free(
1339 struct ia_css_morph_table *me)
1340 {
1341 unsigned int i;
1342
1343 if (!me)
1344 return;
1345
1346 IA_CSS_ENTER("");
1347
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;
1352 }
1353 if (me->coordinates_y[i]) {
1354 kvfree(me->coordinates_y[i]);
1355 me->coordinates_y[i] = NULL;
1356 }
1357 }
1358
1359 kvfree(me);
1360 IA_CSS_LEAVE("void");
1361 }
1362
ia_css_morph_table_allocate(unsigned int width,unsigned int height)1363 struct ia_css_morph_table *ia_css_morph_table_allocate(
1364 unsigned int width,
1365 unsigned int height)
1366 {
1367 unsigned int i;
1368 struct ia_css_morph_table *me;
1369
1370 IA_CSS_ENTER("");
1371
1372 me = kvmalloc(sizeof(*me), GFP_KERNEL);
1373 if (!me) {
1374 IA_CSS_ERROR("out of memory");
1375 return me;
1376 }
1377
1378 for (i = 0; i < IA_CSS_MORPH_TABLE_NUM_PLANES; i++) {
1379 me->coordinates_x[i] = NULL;
1380 me->coordinates_y[i] = NULL;
1381 }
1382
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]),
1386 GFP_KERNEL);
1387 me->coordinates_y[i] = kvmalloc(height * width *
1388 sizeof(*me->coordinates_y[i]),
1389 GFP_KERNEL);
1390
1391 if ((!me->coordinates_x[i]) ||
1392 (!me->coordinates_y[i])) {
1393 ia_css_morph_table_free(me);
1394 me = NULL;
1395 return me;
1396 }
1397 }
1398 me->width = width;
1399 me->height = height;
1400 IA_CSS_LEAVE("");
1401 return me;
1402 }
1403
sh_css_params_default_morph_table(struct ia_css_morph_table ** table,const struct ia_css_binary * binary)1404 static int sh_css_params_default_morph_table(
1405 struct ia_css_morph_table **table,
1406 const struct ia_css_binary *binary)
1407 {
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;
1413
1414 assert(table);
1415 assert(binary);
1416
1417 IA_CSS_ENTER_PRIVATE("");
1418
1419 step = (ISP_VEC_NELEMS / 16) * 128;
1420 width = binary->morph_tbl_width;
1421 height = binary->morph_tbl_height;
1422
1423 tab = ia_css_morph_table_allocate(width, height);
1424 if (!tab)
1425 return -ENOMEM;
1426
1427 for (i = 0; i < IA_CSS_MORPH_TABLE_NUM_PLANES; i++) {
1428 short val_y = start_y[i];
1429
1430 for (j = 0; j < height; j++) {
1431 short val_x = start_x[i];
1432 unsigned short *x_ptr, *y_ptr;
1433
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) {
1438 if (k == 0)
1439 *x_ptr = 0;
1440 else if (k == width - 1)
1441 *x_ptr = val_x + 2 * start_x[i];
1442 else
1443 *x_ptr = val_x;
1444 if (j == 0)
1445 *y_ptr = 0;
1446 else
1447 *y_ptr = val_y;
1448 }
1449 val_y += (short)step;
1450 }
1451 }
1452 *table = tab;
1453
1454 IA_CSS_LEAVE_ERR_PRIVATE(0);
1455
1456 return 0;
1457 }
1458
1459 static void
sh_css_set_morph_table(struct ia_css_isp_parameters * params,const struct ia_css_morph_table * table)1460 sh_css_set_morph_table(struct ia_css_isp_parameters *params,
1461 const struct ia_css_morph_table *table)
1462 {
1463 if (!table)
1464 return;
1465
1466 IA_CSS_ENTER_PRIVATE("table=%p", table);
1467
1468 assert(params);
1469 if (table->enable == false)
1470 table = NULL;
1471 params->morph_table = table;
1472 params->morph_table_changed = true;
1473 IA_CSS_LEAVE_PRIVATE("void");
1474 }
1475
1476 void
ia_css_translate_3a_statistics(struct ia_css_3a_statistics * host_stats,const struct ia_css_isp_3a_statistics_map * isp_stats)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)
1480 {
1481 IA_CSS_ENTER("");
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);
1485 } else {
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);
1489 }
1490 IA_CSS_LOG("3A: HMEM");
1491 ia_css_s3a_hmem_decode(host_stats, isp_stats->hmem_stats);
1492
1493 IA_CSS_LEAVE("void");
1494 }
1495
1496 void
ia_css_isp_3a_statistics_map_free(struct ia_css_isp_3a_statistics_map * me)1497 ia_css_isp_3a_statistics_map_free(struct ia_css_isp_3a_statistics_map *me)
1498 {
1499 if (me) {
1500 if (me->data_allocated) {
1501 kvfree(me->data_ptr);
1502 me->data_ptr = NULL;
1503 me->data_allocated = false;
1504 }
1505 kvfree(me);
1506 }
1507 }
1508
1509 struct ia_css_isp_3a_statistics_map *
ia_css_isp_3a_statistics_map_allocate(const struct ia_css_isp_3a_statistics * isp_stats,void * data_ptr)1510 ia_css_isp_3a_statistics_map_allocate(
1511 const struct ia_css_isp_3a_statistics *isp_stats,
1512 void *data_ptr)
1513 {
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. */
1517 char *base_ptr;
1518
1519 me = kvmalloc(sizeof(*me), GFP_KERNEL);
1520 if (!me) {
1521 IA_CSS_LEAVE("cannot allocate memory");
1522 goto err;
1523 }
1524
1525 me->data_ptr = data_ptr;
1526 me->data_allocated = !data_ptr;
1527 if (!data_ptr) {
1528 me->data_ptr = kvmalloc(isp_stats->size, GFP_KERNEL);
1529 if (!me->data_ptr) {
1530 IA_CSS_LEAVE("cannot allocate memory");
1531 goto err;
1532 }
1533 }
1534 base_ptr = me->data_ptr;
1535
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);
1545
1546 IA_CSS_LEAVE("map=%p", me);
1547 return me;
1548
1549 err:
1550 kvfree(me);
1551 return NULL;
1552 }
1553
1554 int
ia_css_get_3a_statistics(struct ia_css_3a_statistics * host_stats,const struct ia_css_isp_3a_statistics * isp_stats)1555 ia_css_get_3a_statistics(struct ia_css_3a_statistics *host_stats,
1556 const struct ia_css_isp_3a_statistics *isp_stats)
1557 {
1558 struct ia_css_isp_3a_statistics_map *map;
1559 int ret = 0;
1560
1561 IA_CSS_ENTER("host_stats=%p, isp_stats=%p", host_stats, isp_stats);
1562
1563 assert(host_stats);
1564 assert(isp_stats);
1565
1566 map = ia_css_isp_3a_statistics_map_allocate(isp_stats, NULL);
1567 if (map) {
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);
1571 } else {
1572 IA_CSS_ERROR("out of memory");
1573 ret = -ENOMEM;
1574 }
1575
1576 IA_CSS_LEAVE_ERR(ret);
1577 return ret;
1578 }
1579
1580 /* Parameter encoding is not yet orthogonal.
1581 This function hnadles some of the exceptions.
1582 */
1583 static void
ia_css_set_param_exceptions(const struct ia_css_pipe * pipe,struct ia_css_isp_parameters * params)1584 ia_css_set_param_exceptions(const struct ia_css_pipe *pipe,
1585 struct ia_css_isp_parameters *params)
1586 {
1587 assert(params);
1588
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;
1594 }
1595
1596 static void
sh_css_set_nr_config(struct ia_css_isp_parameters * params,const struct ia_css_nr_config * config)1597 sh_css_set_nr_config(struct ia_css_isp_parameters *params,
1598 const struct ia_css_nr_config *config)
1599 {
1600 if (!config)
1601 return;
1602 assert(params);
1603
1604 IA_CSS_ENTER_PRIVATE("config=%p", config);
1605
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;
1612
1613 IA_CSS_LEAVE_PRIVATE("void");
1614 }
1615
1616 static void
sh_css_set_ee_config(struct ia_css_isp_parameters * params,const struct ia_css_ee_config * config)1617 sh_css_set_ee_config(struct ia_css_isp_parameters *params,
1618 const struct ia_css_ee_config *config)
1619 {
1620 if (!config)
1621 return;
1622 assert(params);
1623
1624 IA_CSS_ENTER_PRIVATE("config=%p", config);
1625 ia_css_ee_debug_dtrace(config, IA_CSS_DEBUG_TRACE_PRIVATE);
1626
1627 params->ee_config = *config;
1628 params->yee_config.ee = *config;
1629 params->config_changed[IA_CSS_YEE_ID] = true;
1630
1631 IA_CSS_LEAVE_PRIVATE("void");
1632 }
1633
1634 static void
sh_css_get_ee_config(const struct ia_css_isp_parameters * params,struct ia_css_ee_config * config)1635 sh_css_get_ee_config(const struct ia_css_isp_parameters *params,
1636 struct ia_css_ee_config *config)
1637 {
1638 if (!config)
1639 return;
1640
1641 IA_CSS_ENTER_PRIVATE("config=%p", config);
1642
1643 assert(params);
1644 *config = params->ee_config;
1645
1646 ia_css_ee_debug_dtrace(config, IA_CSS_DEBUG_TRACE_PRIVATE);
1647 IA_CSS_LEAVE_PRIVATE("void");
1648 }
1649
1650 static void
sh_css_set_pipe_dvs_6axis_config(const struct ia_css_pipe * pipe,struct ia_css_isp_parameters * params,const struct ia_css_dvs_6axis_config * dvs_config)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)
1654 {
1655 if (!dvs_config)
1656 return;
1657 assert(params);
1658 assert(pipe);
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);
1662
1663 IA_CSS_ENTER_PRIVATE("dvs_config=%p", dvs_config);
1664
1665 copy_dvs_6axis_table(params->pipe_dvs_6axis_config[pipe->mode], dvs_config);
1666
1667 params->pipe_dvs_6axis_config_changed[pipe->mode] = true;
1668
1669 IA_CSS_LEAVE_PRIVATE("void");
1670 }
1671
1672 static void
sh_css_get_pipe_dvs_6axis_config(const struct ia_css_pipe * pipe,const struct ia_css_isp_parameters * params,struct ia_css_dvs_6axis_config * dvs_config)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)
1676 {
1677 if (!dvs_config)
1678 return;
1679 assert(params);
1680 assert(pipe);
1681 assert(dvs_config->height_y == dvs_config->height_uv);
1682 assert((dvs_config->width_y - 1) == 2 * dvs_config->width_uv - 1);
1683
1684 IA_CSS_ENTER_PRIVATE("dvs_config=%p", dvs_config);
1685
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)
1691 &&
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]);
1697 }
1698
1699 IA_CSS_LEAVE_PRIVATE("void");
1700 }
1701
1702 static void
sh_css_set_baa_config(struct ia_css_isp_parameters * params,const struct ia_css_aa_config * config)1703 sh_css_set_baa_config(struct ia_css_isp_parameters *params,
1704 const struct ia_css_aa_config *config)
1705 {
1706 if (!config)
1707 return;
1708 assert(params);
1709
1710 IA_CSS_ENTER_PRIVATE("config=%p", config);
1711
1712 params->bds_config = *config;
1713 params->config_changed[IA_CSS_BDS_ID] = true;
1714
1715 IA_CSS_LEAVE_PRIVATE("void");
1716 }
1717
1718 static void
sh_css_get_baa_config(const struct ia_css_isp_parameters * params,struct ia_css_aa_config * config)1719 sh_css_get_baa_config(const struct ia_css_isp_parameters *params,
1720 struct ia_css_aa_config *config)
1721 {
1722 if (!config)
1723 return;
1724 assert(params);
1725
1726 IA_CSS_ENTER_PRIVATE("config=%p", config);
1727
1728 *config = params->bds_config;
1729
1730 IA_CSS_LEAVE_PRIVATE("void");
1731 }
1732
1733 static void
sh_css_set_dz_config(struct ia_css_isp_parameters * params,const struct ia_css_dz_config * config)1734 sh_css_set_dz_config(struct ia_css_isp_parameters *params,
1735 const struct ia_css_dz_config *config)
1736 {
1737 if (!config)
1738 return;
1739 assert(params);
1740
1741 IA_CSS_ENTER_PRIVATE("dx=%d, dy=%d", config->dx, config->dy);
1742
1743 assert(config->dx <= HRT_GDC_N);
1744 assert(config->dy <= HRT_GDC_N);
1745
1746 params->dz_config = *config;
1747 params->dz_config_changed = true;
1748 /* JK: Why isp params changed?? */
1749 params->isp_params_changed = true;
1750
1751 IA_CSS_LEAVE_PRIVATE("void");
1752 }
1753
1754 static void
sh_css_get_dz_config(const struct ia_css_isp_parameters * params,struct ia_css_dz_config * config)1755 sh_css_get_dz_config(const struct ia_css_isp_parameters *params,
1756 struct ia_css_dz_config *config)
1757 {
1758 if (!config)
1759 return;
1760 assert(params);
1761
1762 IA_CSS_ENTER_PRIVATE("config=%p", config);
1763
1764 *config = params->dz_config;
1765
1766 IA_CSS_LEAVE_PRIVATE("dx=%d, dy=%d", config->dx, config->dy);
1767 }
1768
1769 static void
sh_css_set_motion_vector(struct ia_css_isp_parameters * params,const struct ia_css_vector * motion)1770 sh_css_set_motion_vector(struct ia_css_isp_parameters *params,
1771 const struct ia_css_vector *motion)
1772 {
1773 if (!motion)
1774 return;
1775 assert(params);
1776
1777 IA_CSS_ENTER_PRIVATE("x=%d, y=%d", motion->x, motion->y);
1778
1779 params->motion_config = *motion;
1780 /* JK: Why do isp params change? */
1781 params->motion_config_changed = true;
1782 params->isp_params_changed = true;
1783
1784 IA_CSS_LEAVE_PRIVATE("void");
1785 }
1786
1787 static void
sh_css_get_motion_vector(const struct ia_css_isp_parameters * params,struct ia_css_vector * motion)1788 sh_css_get_motion_vector(const struct ia_css_isp_parameters *params,
1789 struct ia_css_vector *motion)
1790 {
1791 if (!motion)
1792 return;
1793 assert(params);
1794
1795 IA_CSS_ENTER_PRIVATE("motion=%p", motion);
1796
1797 *motion = params->motion_config;
1798
1799 IA_CSS_LEAVE_PRIVATE("x=%d, y=%d", motion->x, motion->y);
1800 }
1801
1802 struct ia_css_isp_config *
sh_css_pipe_isp_config_get(struct ia_css_pipe * pipe)1803 sh_css_pipe_isp_config_get(struct ia_css_pipe *pipe)
1804 {
1805 if (!pipe) {
1806 IA_CSS_ERROR("pipe=%p", NULL);
1807 return NULL;
1808 }
1809 return pipe->config.p_isp_config;
1810 }
1811
1812 int
ia_css_stream_set_isp_config(struct ia_css_stream * stream,const struct ia_css_isp_config * config)1813 ia_css_stream_set_isp_config(
1814 struct ia_css_stream *stream,
1815 const struct ia_css_isp_config *config)
1816 {
1817 return ia_css_stream_set_isp_config_on_pipe(stream, config, NULL);
1818 }
1819
1820 int
ia_css_stream_set_isp_config_on_pipe(struct ia_css_stream * stream,const struct ia_css_isp_config * config,struct ia_css_pipe * pipe)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)
1825 {
1826 int err = 0;
1827
1828 if ((!stream) || (!config))
1829 return -EINVAL;
1830
1831 IA_CSS_ENTER("stream=%p, config=%p, pipe=%p", stream, config, pipe);
1832
1833 if (config->output_frame)
1834 err = sh_css_set_per_frame_isp_config_on_pipe(stream, config, pipe);
1835 else
1836 err = sh_css_set_global_isp_config_on_pipe(stream->pipes[0], config, pipe);
1837
1838 IA_CSS_LEAVE_ERR(err);
1839 return err;
1840 }
1841
1842 int
ia_css_pipe_set_isp_config(struct ia_css_pipe * pipe,struct ia_css_isp_config * config)1843 ia_css_pipe_set_isp_config(struct ia_css_pipe *pipe,
1844 struct ia_css_isp_config *config)
1845 {
1846 struct ia_css_pipe *pipe_in = pipe;
1847 int err = 0;
1848
1849 IA_CSS_ENTER("pipe=%p", pipe);
1850
1851 if ((!pipe) || (!pipe->stream))
1852 return -EINVAL;
1853
1854 ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "config=%p\n", config);
1855
1856 if (config->output_frame)
1857 err = sh_css_set_per_frame_isp_config_on_pipe(pipe->stream, config, pipe);
1858 else
1859 err = sh_css_set_global_isp_config_on_pipe(pipe, config, pipe_in);
1860 IA_CSS_LEAVE_ERR(err);
1861 return err;
1862 }
1863
1864 static int
sh_css_set_global_isp_config_on_pipe(struct ia_css_pipe * curr_pipe,const struct ia_css_isp_config * config,struct ia_css_pipe * pipe)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)
1869 {
1870 int err = 0;
1871 int err1 = 0;
1872 int err2 = 0;
1873
1874 IA_CSS_ENTER_PRIVATE("stream=%p, config=%p, pipe=%p", curr_pipe, config, pipe);
1875
1876 err1 = sh_css_init_isp_params_from_config(curr_pipe, curr_pipe->stream->isp_params_configs, config, pipe);
1877
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);
1880
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. */
1886
1887 err = (err1 != 0) ? err1 : ((err2 != 0) ? err2 : err);
1888
1889 IA_CSS_LEAVE_ERR_PRIVATE(err);
1890 return err;
1891 }
1892
1893 static int
sh_css_set_per_frame_isp_config_on_pipe(struct ia_css_stream * stream,const struct ia_css_isp_config * config,struct ia_css_pipe * pipe)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)
1898 {
1899 unsigned int i;
1900 bool per_frame_config_created = false;
1901 int err = 0;
1902 int err1 = 0;
1903 int err2 = 0;
1904 int err3 = 0;
1905
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;
1909
1910 IA_CSS_ENTER_PRIVATE("stream=%p, config=%p, pipe=%p", stream, config, pipe);
1911
1912 if (!pipe) {
1913 err = -EINVAL;
1914 goto exit;
1915 }
1916
1917 /* create per-frame ISP params object with default values
1918 * from stream->isp_params_configs if one doesn't already exist
1919 */
1920 if (!stream->per_frame_isp_params_configs) {
1921 err = sh_css_create_isp_params(stream,
1922 &stream->per_frame_isp_params_configs);
1923 if (err)
1924 goto exit;
1925 per_frame_config_created = true;
1926 }
1927
1928 params = stream->per_frame_isp_params_configs;
1929
1930 /* update new ISP params object with the new config */
1931 if (!sh_css_init_isp_params_from_global(stream, params, false, pipe)) {
1932 err1 = -EINVAL;
1933 }
1934
1935 err2 = sh_css_init_isp_params_from_config(stream->pipes[0], params, config, pipe);
1936
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;
1944 }
1945 }
1946
1947 /* now commit to ddr */
1948 err3 = sh_css_param_update_isp_params(stream->pipes[0], params, sh_css_sp_is_running(), pipe);
1949
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;
1958 exit:
1959 IA_CSS_LEAVE_ERR_PRIVATE(err);
1960 return err;
1961 }
1962
1963 static int
sh_css_init_isp_params_from_config(struct ia_css_pipe * pipe,struct ia_css_isp_parameters * params,const struct ia_css_isp_config * config,struct ia_css_pipe * pipe_in)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)
1968 {
1969 int err = 0;
1970 bool is_dp_10bpp = true;
1971
1972 assert(pipe);
1973
1974 IA_CSS_ENTER_PRIVATE("pipe=%p, config=%p, params=%p", pipe, config, params);
1975
1976 ia_css_set_configs(params, config);
1977
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 ------ */
1994
1995 params->dis_coef_table_changed = (config->dvs_coefs);
1996 params->dvs2_coef_table_changed = (config->dvs2_coefs);
1997
1998 params->output_frame = config->output_frame;
1999 params->isp_parameters_id = config->isp_config_id;
2000
2001 if (0 ==
2002 sh_css_select_dp_10bpp_config(pipe, &is_dp_10bpp)) {
2003 /* return an error when both DPC and BDS is enabled by the
2004 * user. */
2005 /* we do not exit from this point immediately to allow internal
2006 * firmware feature testing. */
2007 if (is_dp_10bpp) {
2008 err = -EINVAL;
2009 }
2010 } else {
2011 err = -EINVAL;
2012 goto exit;
2013 }
2014
2015 ia_css_set_param_exceptions(pipe, params);
2016
2017 exit:
2018 IA_CSS_LEAVE_ERR_PRIVATE(err);
2019 return err;
2020 }
2021
2022 void
ia_css_stream_get_isp_config(const struct ia_css_stream * stream,struct ia_css_isp_config * config)2023 ia_css_stream_get_isp_config(
2024 const struct ia_css_stream *stream,
2025 struct ia_css_isp_config *config)
2026 {
2027 IA_CSS_ENTER("void");
2028 ia_css_pipe_get_isp_config(stream->pipes[0], config);
2029 IA_CSS_LEAVE("void");
2030 }
2031
2032 void
ia_css_pipe_get_isp_config(struct ia_css_pipe * pipe,struct ia_css_isp_config * config)2033 ia_css_pipe_get_isp_config(struct ia_css_pipe *pipe,
2034 struct ia_css_isp_config *config)
2035 {
2036 struct ia_css_isp_parameters *params = NULL;
2037
2038 assert(config);
2039
2040 IA_CSS_ENTER("config=%p", config);
2041
2042 params = pipe->stream->isp_params_configs;
2043 assert(params);
2044
2045 ia_css_get_configs(params, config);
2046
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 ------ */
2058
2059 config->output_frame = params->output_frame;
2060 config->isp_config_id = params->isp_parameters_id;
2061
2062 IA_CSS_LEAVE("void");
2063 }
2064
2065 /*
2066 * coding style says the return of "mmgr_NULL" is the error signal
2067 *
2068 * Deprecated: Implement mmgr_realloc()
2069 */
realloc_isp_css_mm_buf(ia_css_ptr * curr_buf,size_t * curr_size,size_t needed_size,bool force,int * err)2070 static bool realloc_isp_css_mm_buf(
2071 ia_css_ptr *curr_buf,
2072 size_t *curr_size,
2073 size_t needed_size,
2074 bool force,
2075 int *err)
2076 {
2077 s32 id;
2078
2079 *err = 0;
2080 /* Possible optimization: add a function sh_css_isp_css_mm_realloc()
2081 * and implement on top of hmm. */
2082
2083 IA_CSS_ENTER_PRIVATE("void");
2084
2085 if (!force && *curr_size >= needed_size) {
2086 IA_CSS_LEAVE_PRIVATE("false");
2087 return false;
2088 }
2089 /* don't reallocate if single ref to buffer and same size */
2090 if (*curr_size == needed_size && ia_css_refcount_is_single(*curr_buf)) {
2091 IA_CSS_LEAVE_PRIVATE("false");
2092 return false;
2093 }
2094
2095 id = IA_CSS_REFCOUNT_PARAM_BUFFER;
2096 ia_css_refcount_decrement(id, *curr_buf);
2097 *curr_buf = ia_css_refcount_increment(id, hmm_alloc(needed_size));
2098 if (!*curr_buf) {
2099 *err = -ENOMEM;
2100 *curr_size = 0;
2101 } else {
2102 *curr_size = needed_size;
2103 }
2104 IA_CSS_LEAVE_PRIVATE("true");
2105 return true;
2106 }
2107
reallocate_buffer(ia_css_ptr * curr_buf,size_t * curr_size,size_t needed_size,bool force,int * err)2108 static bool reallocate_buffer(
2109 ia_css_ptr *curr_buf,
2110 size_t *curr_size,
2111 size_t needed_size,
2112 bool force,
2113 int *err)
2114 {
2115 bool ret;
2116
2117 IA_CSS_ENTER_PRIVATE("void");
2118
2119 ret = realloc_isp_css_mm_buf(curr_buf,
2120 curr_size, needed_size, force, err);
2121
2122 IA_CSS_LEAVE_PRIVATE("ret=%d", ret);
2123 return ret;
2124 }
2125
2126 struct ia_css_isp_3a_statistics *
ia_css_isp_3a_statistics_allocate(const struct ia_css_3a_grid_info * grid)2127 ia_css_isp_3a_statistics_allocate(const struct ia_css_3a_grid_info *grid)
2128 {
2129 struct ia_css_isp_3a_statistics *me;
2130
2131 IA_CSS_ENTER("grid=%p", grid);
2132
2133 assert(grid);
2134
2135 /* MW: Does "grid->enable" also control the histogram output ?? */
2136 if (!grid->enable)
2137 return NULL;
2138
2139 me = kvcalloc(1, sizeof(*me), GFP_KERNEL);
2140 if (!me)
2141 goto err;
2142
2143 if (grid->use_dmem) {
2144 me->dmem_size = sizeof(struct ia_css_3a_output) *
2145 grid->aligned_width *
2146 grid->aligned_height;
2147 } else {
2148 me->vmem_size = ISP_S3ATBL_HI_LO_STRIDE_BYTES *
2149 grid->aligned_height;
2150 }
2151 me->hmem_size = sizeof_hmem(HMEM0_ID);
2152
2153 /* All subsections need to be aligned to the system bus width */
2154 me->dmem_size = CEIL_MUL(me->dmem_size, HIVE_ISP_DDR_WORD_BYTES);
2155 me->vmem_size = CEIL_MUL(me->vmem_size, HIVE_ISP_DDR_WORD_BYTES);
2156 me->hmem_size = CEIL_MUL(me->hmem_size, HIVE_ISP_DDR_WORD_BYTES);
2157
2158 me->size = me->dmem_size + me->vmem_size * 2 + me->hmem_size;
2159 me->data_ptr = hmm_alloc(me->size);
2160 if (me->data_ptr == mmgr_NULL) {
2161 kvfree(me);
2162 me = NULL;
2163 goto err;
2164 }
2165 if (me->dmem_size)
2166 me->data.dmem.s3a_tbl = me->data_ptr;
2167 if (me->vmem_size) {
2168 me->data.vmem.s3a_tbl_hi = me->data_ptr + me->dmem_size;
2169 me->data.vmem.s3a_tbl_lo = me->data_ptr + me->dmem_size + me->vmem_size;
2170 }
2171 if (me->hmem_size)
2172 me->data_hmem.rgby_tbl = me->data_ptr + me->dmem_size + 2 * me->vmem_size;
2173
2174 err:
2175 IA_CSS_LEAVE("return=%p", me);
2176 return me;
2177 }
2178
2179 void
ia_css_isp_3a_statistics_free(struct ia_css_isp_3a_statistics * me)2180 ia_css_isp_3a_statistics_free(struct ia_css_isp_3a_statistics *me)
2181 {
2182 if (me) {
2183 hmm_free(me->data_ptr);
2184 kvfree(me);
2185 }
2186 }
2187
ia_css_skc_dvs_statistics_allocate(void)2188 struct ia_css_isp_skc_dvs_statistics *ia_css_skc_dvs_statistics_allocate(void)
2189 {
2190 return NULL;
2191 }
2192
2193 struct ia_css_metadata *
ia_css_metadata_allocate(const struct ia_css_metadata_info * metadata_info)2194 ia_css_metadata_allocate(const struct ia_css_metadata_info *metadata_info)
2195 {
2196 struct ia_css_metadata *md = NULL;
2197
2198 IA_CSS_ENTER("");
2199
2200 if (metadata_info->size == 0)
2201 return NULL;
2202
2203 md = kvmalloc(sizeof(*md), GFP_KERNEL);
2204 if (!md)
2205 goto error;
2206
2207 md->info = *metadata_info;
2208 md->exp_id = 0;
2209 md->address = hmm_alloc(metadata_info->size);
2210 if (md->address == mmgr_NULL)
2211 goto error;
2212
2213 IA_CSS_LEAVE("return=%p", md);
2214 return md;
2215
2216 error:
2217 ia_css_metadata_free(md);
2218 IA_CSS_LEAVE("return=%p", NULL);
2219 return NULL;
2220 }
2221
2222 void
ia_css_metadata_free(struct ia_css_metadata * me)2223 ia_css_metadata_free(struct ia_css_metadata *me)
2224 {
2225 if (me) {
2226 /* The enter and leave macros are placed inside
2227 * the condition to avoid false logging of metadata
2228 * free events when metadata is disabled.
2229 * We found this to be confusing during development
2230 * and debugging. */
2231 IA_CSS_ENTER("me=%p", me);
2232 hmm_free(me->address);
2233 kvfree(me);
2234 IA_CSS_LEAVE("void");
2235 }
2236 }
2237
2238 void
ia_css_metadata_free_multiple(unsigned int num_bufs,struct ia_css_metadata ** bufs)2239 ia_css_metadata_free_multiple(unsigned int num_bufs,
2240 struct ia_css_metadata **bufs)
2241 {
2242 unsigned int i;
2243
2244 if (bufs) {
2245 for (i = 0; i < num_bufs; i++)
2246 ia_css_metadata_free(bufs[i]);
2247 }
2248 }
2249
2250 static unsigned int g_param_buffer_dequeue_count;
2251 static unsigned int g_param_buffer_enqueue_count;
2252
2253 int
ia_css_stream_isp_parameters_init(struct ia_css_stream * stream)2254 ia_css_stream_isp_parameters_init(struct ia_css_stream *stream)
2255 {
2256 int err = 0;
2257 unsigned int i;
2258 struct sh_css_ddr_address_map *ddr_ptrs;
2259 struct sh_css_ddr_address_map_size *ddr_ptrs_size;
2260 struct ia_css_isp_parameters *params;
2261
2262 assert(stream);
2263 IA_CSS_ENTER_PRIVATE("void");
2264
2265 if (!stream) {
2266 IA_CSS_LEAVE_ERR_PRIVATE(-EINVAL);
2267 return -EINVAL;
2268 }
2269 /* TMP: tracking of paramsets */
2270 g_param_buffer_dequeue_count = 0;
2271 g_param_buffer_enqueue_count = 0;
2272
2273 stream->per_frame_isp_params_configs = NULL;
2274 err = sh_css_create_isp_params(stream,
2275 &stream->isp_params_configs);
2276 if (err)
2277 goto ERR;
2278
2279 params = stream->isp_params_configs;
2280 if (!sh_css_init_isp_params_from_global(stream, params, true, NULL)) {
2281 /* we do not return the error immediately to enable internal
2282 * firmware feature testing */
2283 err = -EINVAL;
2284 }
2285
2286 ddr_ptrs = ¶ms->ddr_ptrs;
2287 ddr_ptrs_size = ¶ms->ddr_ptrs_size;
2288
2289 /* create per pipe reference to general ddr_ptrs */
2290 for (i = 0; i < IA_CSS_PIPE_ID_NUM; i++) {
2291 ref_sh_css_ddr_address_map(ddr_ptrs, ¶ms->pipe_ddr_ptrs[i]);
2292 params->pipe_ddr_ptrs_size[i] = *ddr_ptrs_size;
2293 }
2294
2295 ERR:
2296 IA_CSS_LEAVE_ERR_PRIVATE(err);
2297 return err;
2298 }
2299
2300 static void
ia_css_set_sdis_config(struct ia_css_isp_parameters * params,const struct ia_css_dvs_coefficients * dvs_coefs)2301 ia_css_set_sdis_config(
2302 struct ia_css_isp_parameters *params,
2303 const struct ia_css_dvs_coefficients *dvs_coefs)
2304 {
2305 ia_css_set_sdis_horicoef_config(params, dvs_coefs);
2306 ia_css_set_sdis_vertcoef_config(params, dvs_coefs);
2307 ia_css_set_sdis_horiproj_config(params, dvs_coefs);
2308 ia_css_set_sdis_vertproj_config(params, dvs_coefs);
2309 }
2310
2311 static void
ia_css_set_sdis2_config(struct ia_css_isp_parameters * params,const struct ia_css_dvs2_coefficients * dvs2_coefs)2312 ia_css_set_sdis2_config(
2313 struct ia_css_isp_parameters *params,
2314 const struct ia_css_dvs2_coefficients *dvs2_coefs)
2315 {
2316 ia_css_set_sdis2_horicoef_config(params, dvs2_coefs);
2317 ia_css_set_sdis2_vertcoef_config(params, dvs2_coefs);
2318 ia_css_set_sdis2_horiproj_config(params, dvs2_coefs);
2319 ia_css_set_sdis2_vertproj_config(params, dvs2_coefs);
2320 }
2321
2322 static int
sh_css_create_isp_params(struct ia_css_stream * stream,struct ia_css_isp_parameters ** isp_params_out)2323 sh_css_create_isp_params(struct ia_css_stream *stream,
2324 struct ia_css_isp_parameters **isp_params_out)
2325 {
2326 bool succ = true;
2327 unsigned int i;
2328 struct sh_css_ddr_address_map *ddr_ptrs;
2329 struct sh_css_ddr_address_map_size *ddr_ptrs_size;
2330 int err;
2331 size_t params_size;
2332 struct ia_css_isp_parameters *params =
2333 kvmalloc(sizeof(struct ia_css_isp_parameters), GFP_KERNEL);
2334
2335 if (!params) {
2336 *isp_params_out = NULL;
2337 err = -ENOMEM;
2338 IA_CSS_ERROR("%s:%d error: cannot allocate memory", __FILE__, __LINE__);
2339 IA_CSS_LEAVE_ERR_PRIVATE(err);
2340 return err;
2341 } else {
2342 memset(params, 0, sizeof(struct ia_css_isp_parameters));
2343 }
2344
2345 ddr_ptrs = ¶ms->ddr_ptrs;
2346 ddr_ptrs_size = ¶ms->ddr_ptrs_size;
2347
2348 for (i = 0; i < IA_CSS_PIPE_ID_NUM; i++) {
2349 memset(¶ms->pipe_ddr_ptrs[i], 0,
2350 sizeof(params->pipe_ddr_ptrs[i]));
2351 memset(¶ms->pipe_ddr_ptrs_size[i], 0,
2352 sizeof(params->pipe_ddr_ptrs_size[i]));
2353 }
2354
2355 memset(ddr_ptrs, 0, sizeof(*ddr_ptrs));
2356 memset(ddr_ptrs_size, 0, sizeof(*ddr_ptrs_size));
2357
2358 params_size = sizeof(params->uds);
2359 ddr_ptrs_size->isp_param = params_size;
2360 ddr_ptrs->isp_param =
2361 ia_css_refcount_increment(IA_CSS_REFCOUNT_PARAM_BUFFER,
2362 hmm_alloc(params_size));
2363 succ &= (ddr_ptrs->isp_param != mmgr_NULL);
2364
2365 ddr_ptrs_size->macc_tbl = sizeof(struct ia_css_macc_table);
2366 ddr_ptrs->macc_tbl =
2367 ia_css_refcount_increment(IA_CSS_REFCOUNT_PARAM_BUFFER,
2368 hmm_alloc(sizeof(struct ia_css_macc_table)));
2369 succ &= (ddr_ptrs->macc_tbl != mmgr_NULL);
2370
2371 *isp_params_out = params;
2372
2373 if (!succ)
2374 return -ENOMEM;
2375
2376 return 0;
2377 }
2378
2379 static bool
sh_css_init_isp_params_from_global(struct ia_css_stream * stream,struct ia_css_isp_parameters * params,bool use_default_config,struct ia_css_pipe * pipe_in)2380 sh_css_init_isp_params_from_global(struct ia_css_stream *stream,
2381 struct ia_css_isp_parameters *params,
2382 bool use_default_config,
2383 struct ia_css_pipe *pipe_in)
2384 {
2385 bool retval = true;
2386 int i = 0;
2387 bool is_dp_10bpp = true;
2388 unsigned int isp_pipe_version = ia_css_pipe_get_isp_pipe_version(
2389 stream->pipes[0]);
2390 struct ia_css_isp_parameters *stream_params = stream->isp_params_configs;
2391
2392 if (!use_default_config && !stream_params) {
2393 retval = false;
2394 goto exit;
2395 }
2396
2397 params->output_frame = NULL;
2398 params->isp_parameters_id = 0;
2399
2400 if (use_default_config) {
2401 ia_css_set_xnr3_config(params, &default_xnr3_config);
2402
2403 sh_css_set_nr_config(params, &default_nr_config);
2404 sh_css_set_ee_config(params, &default_ee_config);
2405 if (isp_pipe_version == SH_CSS_ISP_PIPE_VERSION_1)
2406 sh_css_set_macc_table(params, &default_macc_table);
2407 else if (isp_pipe_version == SH_CSS_ISP_PIPE_VERSION_2_2)
2408 sh_css_set_macc_table(params, &default_macc2_table);
2409 sh_css_set_gamma_table(params, &default_gamma_table);
2410 sh_css_set_ctc_table(params, &default_ctc_table);
2411 sh_css_set_baa_config(params, &default_baa_config);
2412 sh_css_set_dz_config(params, &default_dz_config);
2413 /* ------ deprecated(bz675) : from ------ */
2414 sh_css_set_shading_settings(params, &default_shading_settings);
2415 /* ------ deprecated(bz675) : to ------ */
2416
2417 ia_css_set_s3a_config(params, &default_3a_config);
2418 ia_css_set_wb_config(params, &default_wb_config);
2419 ia_css_set_csc_config(params, &default_cc_config);
2420 ia_css_set_tnr_config(params, &default_tnr_config);
2421 ia_css_set_ob_config(params, &default_ob_config);
2422 ia_css_set_dp_config(params, &default_dp_config);
2423
2424 ia_css_set_param_exceptions(pipe_in, params);
2425
2426 ia_css_set_de_config(params, &default_de_config);
2427 ia_css_set_gc_config(params, &default_gc_config);
2428 ia_css_set_anr_config(params, &default_anr_config);
2429 ia_css_set_anr2_config(params, &default_anr_thres);
2430 ia_css_set_ce_config(params, &default_ce_config);
2431 ia_css_set_xnr_table_config(params, &default_xnr_table);
2432 ia_css_set_ecd_config(params, &default_ecd_config);
2433 ia_css_set_ynr_config(params, &default_ynr_config);
2434 ia_css_set_fc_config(params, &default_fc_config);
2435 ia_css_set_cnr_config(params, &default_cnr_config);
2436 ia_css_set_macc_config(params, &default_macc_config);
2437 ia_css_set_ctc_config(params, &default_ctc_config);
2438 ia_css_set_aa_config(params, &default_aa_config);
2439 ia_css_set_r_gamma_config(params, &default_r_gamma_table);
2440 ia_css_set_g_gamma_config(params, &default_g_gamma_table);
2441 ia_css_set_b_gamma_config(params, &default_b_gamma_table);
2442 ia_css_set_yuv2rgb_config(params, &default_yuv2rgb_cc_config);
2443 ia_css_set_rgb2yuv_config(params, &default_rgb2yuv_cc_config);
2444 ia_css_set_xnr_config(params, &default_xnr_config);
2445 ia_css_set_sdis_config(params, &default_sdis_config);
2446 ia_css_set_sdis2_config(params, &default_sdis2_config);
2447 ia_css_set_formats_config(params, &default_formats_config);
2448
2449 params->fpn_config.data = NULL;
2450 params->config_changed[IA_CSS_FPN_ID] = true;
2451 params->fpn_config.enabled = 0;
2452
2453 params->motion_config = default_motion_config;
2454 params->motion_config_changed = true;
2455
2456 params->morph_table = NULL;
2457 params->morph_table_changed = true;
2458
2459 params->sc_table = NULL;
2460 params->sc_table_changed = true;
2461
2462 ia_css_sdis2_clear_coefficients(¶ms->dvs2_coefs);
2463 params->dvs2_coef_table_changed = true;
2464
2465 ia_css_sdis_clear_coefficients(¶ms->dvs_coefs);
2466 params->dis_coef_table_changed = true;
2467 } else {
2468 ia_css_set_xnr3_config(params, &stream_params->xnr3_config);
2469
2470 sh_css_set_nr_config(params, &stream_params->nr_config);
2471 sh_css_set_ee_config(params, &stream_params->ee_config);
2472 if (isp_pipe_version == SH_CSS_ISP_PIPE_VERSION_1)
2473 sh_css_set_macc_table(params, &stream_params->macc_table);
2474 else if (isp_pipe_version == SH_CSS_ISP_PIPE_VERSION_2_2)
2475 sh_css_set_macc_table(params, &stream_params->macc_table);
2476 sh_css_set_gamma_table(params, &stream_params->gc_table);
2477 sh_css_set_ctc_table(params, &stream_params->ctc_table);
2478 sh_css_set_baa_config(params, &stream_params->bds_config);
2479 sh_css_set_dz_config(params, &stream_params->dz_config);
2480 /* ------ deprecated(bz675) : from ------ */
2481 sh_css_set_shading_settings(params, &stream_params->shading_settings);
2482 /* ------ deprecated(bz675) : to ------ */
2483
2484 ia_css_set_s3a_config(params, &stream_params->s3a_config);
2485 ia_css_set_wb_config(params, &stream_params->wb_config);
2486 ia_css_set_csc_config(params, &stream_params->cc_config);
2487 ia_css_set_tnr_config(params, &stream_params->tnr_config);
2488 ia_css_set_ob_config(params, &stream_params->ob_config);
2489 ia_css_set_dp_config(params, &stream_params->dp_config);
2490 ia_css_set_de_config(params, &stream_params->de_config);
2491 ia_css_set_gc_config(params, &stream_params->gc_config);
2492 ia_css_set_anr_config(params, &stream_params->anr_config);
2493 ia_css_set_anr2_config(params, &stream_params->anr_thres);
2494 ia_css_set_ce_config(params, &stream_params->ce_config);
2495 ia_css_set_xnr_table_config(params, &stream_params->xnr_table);
2496 ia_css_set_ecd_config(params, &stream_params->ecd_config);
2497 ia_css_set_ynr_config(params, &stream_params->ynr_config);
2498 ia_css_set_fc_config(params, &stream_params->fc_config);
2499 ia_css_set_cnr_config(params, &stream_params->cnr_config);
2500 ia_css_set_macc_config(params, &stream_params->macc_config);
2501 ia_css_set_ctc_config(params, &stream_params->ctc_config);
2502 ia_css_set_aa_config(params, &stream_params->aa_config);
2503 ia_css_set_r_gamma_config(params, &stream_params->r_gamma_table);
2504 ia_css_set_g_gamma_config(params, &stream_params->g_gamma_table);
2505 ia_css_set_b_gamma_config(params, &stream_params->b_gamma_table);
2506 ia_css_set_yuv2rgb_config(params, &stream_params->yuv2rgb_cc_config);
2507 ia_css_set_rgb2yuv_config(params, &stream_params->rgb2yuv_cc_config);
2508 ia_css_set_xnr_config(params, &stream_params->xnr_config);
2509 ia_css_set_formats_config(params, &stream_params->formats_config);
2510
2511 for (i = 0; i < stream->num_pipes; i++) {
2512 if (0 ==
2513 sh_css_select_dp_10bpp_config(stream->pipes[i], &is_dp_10bpp)) {
2514 /* set the return value as false if both DPC and
2515 * BDS is enabled by the user. But we do not return
2516 * the value immediately to enable internal firmware
2517 * feature testing. */
2518 retval = !is_dp_10bpp;
2519 /* FIXME: should it ignore this error? */
2520 } else {
2521 retval = false;
2522 goto exit;
2523 }
2524 }
2525
2526 ia_css_set_param_exceptions(pipe_in, params);
2527
2528 params->fpn_config.data = stream_params->fpn_config.data;
2529 params->config_changed[IA_CSS_FPN_ID] =
2530 stream_params->config_changed[IA_CSS_FPN_ID];
2531 params->fpn_config.enabled = stream_params->fpn_config.enabled;
2532
2533 sh_css_set_motion_vector(params, &stream_params->motion_config);
2534 sh_css_set_morph_table(params, stream_params->morph_table);
2535
2536 if (stream_params->sc_table) {
2537 sh_css_set_shading_table(stream, params, stream_params->sc_table);
2538 } else {
2539 params->sc_table = NULL;
2540 params->sc_table_changed = true;
2541 }
2542
2543 /* Only IA_CSS_PIPE_ID_VIDEO & IA_CSS_PIPE_ID_CAPTURE will support dvs_6axis_config*/
2544 for (i = 0; i < IA_CSS_PIPE_ID_NUM; i++) {
2545 if (stream_params->pipe_dvs_6axis_config[i]) {
2546 if (params->pipe_dvs_6axis_config[i]) {
2547 copy_dvs_6axis_table(params->pipe_dvs_6axis_config[i],
2548 stream_params->pipe_dvs_6axis_config[i]);
2549 } else {
2550 params->pipe_dvs_6axis_config[i] =
2551 generate_dvs_6axis_table_from_config(stream_params->pipe_dvs_6axis_config[i]);
2552 }
2553 }
2554 }
2555 ia_css_set_sdis_config(params, &stream_params->dvs_coefs);
2556 params->dis_coef_table_changed = stream_params->dis_coef_table_changed;
2557
2558 ia_css_set_sdis2_config(params, &stream_params->dvs2_coefs);
2559 params->dvs2_coef_table_changed = stream_params->dvs2_coef_table_changed;
2560 params->sensor_binning = stream_params->sensor_binning;
2561 }
2562
2563 exit:
2564 return retval;
2565 }
2566
2567 int
sh_css_params_init(void)2568 sh_css_params_init(void)
2569 {
2570 int i, p;
2571
2572 IA_CSS_ENTER_PRIVATE("void");
2573
2574 /* TMP: tracking of paramsets */
2575 g_param_buffer_dequeue_count = 0;
2576 g_param_buffer_enqueue_count = 0;
2577
2578 for (p = 0; p < IA_CSS_PIPE_ID_NUM; p++) {
2579 for (i = 0; i < SH_CSS_MAX_STAGES; i++) {
2580 xmem_sp_stage_ptrs[p][i] =
2581 ia_css_refcount_increment(-1,
2582 hmm_alloc(sizeof(struct sh_css_sp_stage)));
2583 xmem_isp_stage_ptrs[p][i] =
2584 ia_css_refcount_increment(-1,
2585 hmm_alloc(sizeof(struct sh_css_sp_stage)));
2586
2587 if ((xmem_sp_stage_ptrs[p][i] == mmgr_NULL) ||
2588 (xmem_isp_stage_ptrs[p][i] == mmgr_NULL)) {
2589 sh_css_params_uninit();
2590 IA_CSS_LEAVE_ERR_PRIVATE(-ENOMEM);
2591 return -ENOMEM;
2592 }
2593
2594 hmm_set(xmem_sp_stage_ptrs[p][i], 0, sizeof(struct sh_css_sp_stage));
2595 hmm_set(xmem_isp_stage_ptrs[p][i], 0, sizeof(struct sh_css_sp_stage));
2596 }
2597 }
2598
2599 ia_css_config_gamma_table();
2600 ia_css_config_ctc_table();
2601 ia_css_config_rgb_gamma_tables();
2602 ia_css_config_xnr_table();
2603
2604 sp_ddr_ptrs = ia_css_refcount_increment(-1,
2605 hmm_alloc(CEIL_MUL(sizeof(struct sh_css_ddr_address_map),
2606 HIVE_ISP_DDR_WORD_BYTES)));
2607 xmem_sp_group_ptrs = ia_css_refcount_increment(-1,
2608 hmm_alloc(sizeof(struct sh_css_sp_group)));
2609
2610 if ((sp_ddr_ptrs == mmgr_NULL) ||
2611 (xmem_sp_group_ptrs == mmgr_NULL)) {
2612 ia_css_uninit();
2613 IA_CSS_LEAVE_ERR_PRIVATE(-ENOMEM);
2614 return -ENOMEM;
2615 }
2616 hmm_set(sp_ddr_ptrs, 0, CEIL_MUL(sizeof(struct sh_css_ddr_address_map),
2617 HIVE_ISP_DDR_WORD_BYTES));
2618 hmm_set(xmem_sp_group_ptrs, 0, sizeof(struct sh_css_sp_group));
2619 IA_CSS_LEAVE_ERR_PRIVATE(0);
2620 return 0;
2621 }
2622
host_lut_store(const void * lut)2623 static void host_lut_store(const void *lut)
2624 {
2625 unsigned int i;
2626
2627 for (i = 0; i < N_GDC_ID; i++)
2628 gdc_lut_store((gdc_ID_t)i, (const int (*)[HRT_GDC_N]) lut);
2629 }
2630
ia_css_pipe_set_bci_scaler_lut(struct ia_css_pipe * pipe,const void * lut)2631 int ia_css_pipe_set_bci_scaler_lut(struct ia_css_pipe *pipe,
2632 const void *lut)
2633 {
2634 int err = 0;
2635 bool stream_started = false;
2636
2637 IA_CSS_ENTER("pipe=%p lut=%p", pipe, lut);
2638
2639 if (!lut || !pipe) {
2640 err = -EINVAL;
2641 IA_CSS_LEAVE("err=%d", err);
2642 return err;
2643 }
2644
2645 /* If the pipe belongs to a stream and the stream has started, it is not
2646 * safe to store lut to gdc HW. If pipe->stream is NULL, then no stream is
2647 * created with this pipe, so it is safe to do this operation as long as
2648 * ia_css_init() has been called. */
2649 if (pipe->stream && pipe->stream->started) {
2650 ia_css_debug_dtrace(IA_CSS_DEBUG_ERROR,
2651 "unable to set scaler lut since stream has started\n");
2652 stream_started = true;
2653 err = -ENOTSUPP;
2654 }
2655
2656 /* Free any existing tables. */
2657 if (pipe->scaler_pp_lut != mmgr_NULL) {
2658 hmm_free(pipe->scaler_pp_lut);
2659 pipe->scaler_pp_lut = mmgr_NULL;
2660 }
2661
2662 if (!stream_started) {
2663 pipe->scaler_pp_lut = hmm_alloc(sizeof(zoom_table));
2664
2665 if (pipe->scaler_pp_lut == mmgr_NULL) {
2666 ia_css_debug_dtrace(IA_CSS_DEBUG_ERROR,
2667 "unable to allocate scaler_pp_lut\n");
2668 err = -ENOMEM;
2669 } else {
2670 gdc_lut_convert_to_isp_format((const int(*)[HRT_GDC_N])lut,
2671 interleaved_lut_temp);
2672 hmm_store(pipe->scaler_pp_lut,
2673 (int *)interleaved_lut_temp,
2674 sizeof(zoom_table));
2675 }
2676 }
2677
2678 IA_CSS_LEAVE("lut(%u) err=%d", pipe->scaler_pp_lut, err);
2679 return err;
2680 }
2681
2682 /* if pipe is NULL, returns default lut addr. */
sh_css_pipe_get_pp_gdc_lut(const struct ia_css_pipe * pipe)2683 ia_css_ptr sh_css_pipe_get_pp_gdc_lut(const struct ia_css_pipe *pipe)
2684 {
2685 assert(pipe);
2686
2687 if (pipe->scaler_pp_lut != mmgr_NULL)
2688 return pipe->scaler_pp_lut;
2689 else
2690 return sh_css_params_get_default_gdc_lut();
2691 }
2692
sh_css_params_map_and_store_default_gdc_lut(void)2693 int sh_css_params_map_and_store_default_gdc_lut(void)
2694 {
2695 int err = 0;
2696
2697 IA_CSS_ENTER_PRIVATE("void");
2698
2699 /* Is table already mapped? Nothing to do if it is mapped. */
2700 if (default_gdc_lut != mmgr_NULL)
2701 return err;
2702
2703 host_lut_store((void *)zoom_table);
2704
2705 default_gdc_lut = hmm_alloc(sizeof(zoom_table));
2706
2707 if (default_gdc_lut == mmgr_NULL)
2708 return -ENOMEM;
2709
2710 gdc_lut_convert_to_isp_format((const int(*)[HRT_GDC_N])zoom_table,
2711 interleaved_lut_temp);
2712 hmm_store(default_gdc_lut, (int *)interleaved_lut_temp,
2713 sizeof(zoom_table));
2714
2715 IA_CSS_LEAVE_PRIVATE("lut(%u) err=%d", default_gdc_lut, err);
2716 return err;
2717 }
2718
sh_css_params_free_default_gdc_lut(void)2719 void sh_css_params_free_default_gdc_lut(void)
2720 {
2721 IA_CSS_ENTER_PRIVATE("void");
2722
2723 if (default_gdc_lut != mmgr_NULL) {
2724 hmm_free(default_gdc_lut);
2725 default_gdc_lut = mmgr_NULL;
2726 }
2727
2728 IA_CSS_LEAVE_PRIVATE("void");
2729 }
2730
sh_css_params_get_default_gdc_lut(void)2731 ia_css_ptr sh_css_params_get_default_gdc_lut(void)
2732 {
2733 return default_gdc_lut;
2734 }
2735
free_param_set_callback(ia_css_ptr ptr)2736 static void free_param_set_callback(
2737 ia_css_ptr ptr)
2738 {
2739 IA_CSS_ENTER_PRIVATE("void");
2740
2741 free_ia_css_isp_parameter_set_info(ptr);
2742
2743 IA_CSS_LEAVE_PRIVATE("void");
2744 }
2745
free_buffer_callback(ia_css_ptr ptr)2746 static void free_buffer_callback(
2747 ia_css_ptr ptr)
2748 {
2749 IA_CSS_ENTER_PRIVATE("void");
2750
2751 hmm_free(ptr);
2752
2753 IA_CSS_LEAVE_PRIVATE("void");
2754 }
2755
2756 void
sh_css_param_clear_param_sets(void)2757 sh_css_param_clear_param_sets(void)
2758 {
2759 IA_CSS_ENTER_PRIVATE("void");
2760
2761 ia_css_refcount_clear(IA_CSS_REFCOUNT_PARAM_SET_POOL, &free_param_set_callback);
2762
2763 IA_CSS_LEAVE_PRIVATE("void");
2764 }
2765
2766 /*
2767 * MW: we can define hmm_free() to return a NULL
2768 * then you can write ptr = hmm_free(ptr);
2769 */
2770 #define safe_free(id, x) \
2771 do { \
2772 ia_css_refcount_decrement(id, x); \
2773 (x) = mmgr_NULL; \
2774 } while (0)
2775
free_map(struct sh_css_ddr_address_map * map)2776 static void free_map(struct sh_css_ddr_address_map *map)
2777 {
2778 unsigned int i;
2779
2780 ia_css_ptr *addrs = (ia_css_ptr *)map;
2781
2782 IA_CSS_ENTER_PRIVATE("void");
2783
2784 /* free buffers */
2785 for (i = 0; i < (sizeof(struct sh_css_ddr_address_map_size) /
2786 sizeof(size_t)); i++) {
2787 if (addrs[i] == mmgr_NULL)
2788 continue;
2789 safe_free(IA_CSS_REFCOUNT_PARAM_BUFFER, addrs[i]);
2790 }
2791
2792 IA_CSS_LEAVE_PRIVATE("void");
2793 }
2794
2795 void
ia_css_stream_isp_parameters_uninit(struct ia_css_stream * stream)2796 ia_css_stream_isp_parameters_uninit(struct ia_css_stream *stream)
2797 {
2798 int i;
2799 struct ia_css_isp_parameters *params = stream->isp_params_configs;
2800 struct ia_css_isp_parameters *per_frame_params =
2801 stream->per_frame_isp_params_configs;
2802
2803 IA_CSS_ENTER_PRIVATE("void");
2804 if (!params) {
2805 IA_CSS_LEAVE_PRIVATE("isp_param_configs is NULL");
2806 return;
2807 }
2808
2809 /* free existing ddr_ptr maps */
2810 for (i = 0; i < IA_CSS_PIPE_ID_NUM; i++) {
2811 free_map(¶ms->pipe_ddr_ptrs[i]);
2812 if (per_frame_params)
2813 free_map(&per_frame_params->pipe_ddr_ptrs[i]);
2814 /* Free up theDVS table memory blocks before recomputing new table */
2815 if (params->pipe_dvs_6axis_config[i])
2816 free_dvs_6axis_table(¶ms->pipe_dvs_6axis_config[i]);
2817 if (per_frame_params && per_frame_params->pipe_dvs_6axis_config[i])
2818 free_dvs_6axis_table(&per_frame_params->pipe_dvs_6axis_config[i]);
2819 }
2820 free_map(¶ms->ddr_ptrs);
2821 if (per_frame_params)
2822 free_map(&per_frame_params->ddr_ptrs);
2823
2824 if (params->fpn_config.data) {
2825 kvfree(params->fpn_config.data);
2826 params->fpn_config.data = NULL;
2827 }
2828
2829 /* Free up sc_config (temporal shading table) if it is allocated. */
2830 if (params->sc_config) {
2831 ia_css_shading_table_free(params->sc_config);
2832 params->sc_config = NULL;
2833 }
2834 if (per_frame_params) {
2835 if (per_frame_params->sc_config) {
2836 ia_css_shading_table_free(per_frame_params->sc_config);
2837 per_frame_params->sc_config = NULL;
2838 }
2839 }
2840
2841 kvfree(params);
2842 kvfree(per_frame_params);
2843 stream->isp_params_configs = NULL;
2844 stream->per_frame_isp_params_configs = NULL;
2845
2846 IA_CSS_LEAVE_PRIVATE("void");
2847 }
2848
2849 void
sh_css_params_uninit(void)2850 sh_css_params_uninit(void)
2851 {
2852 unsigned int p, i;
2853
2854 IA_CSS_ENTER_PRIVATE("void");
2855
2856 ia_css_refcount_decrement(-1, sp_ddr_ptrs);
2857 sp_ddr_ptrs = mmgr_NULL;
2858 ia_css_refcount_decrement(-1, xmem_sp_group_ptrs);
2859 xmem_sp_group_ptrs = mmgr_NULL;
2860
2861 for (p = 0; p < IA_CSS_PIPE_ID_NUM; p++)
2862 for (i = 0; i < SH_CSS_MAX_STAGES; i++) {
2863 ia_css_refcount_decrement(-1, xmem_sp_stage_ptrs[p][i]);
2864 xmem_sp_stage_ptrs[p][i] = mmgr_NULL;
2865 ia_css_refcount_decrement(-1, xmem_isp_stage_ptrs[p][i]);
2866 xmem_isp_stage_ptrs[p][i] = mmgr_NULL;
2867 }
2868
2869 /* go through the pools to clear references */
2870 ia_css_refcount_clear(IA_CSS_REFCOUNT_PARAM_SET_POOL, &free_param_set_callback);
2871 ia_css_refcount_clear(IA_CSS_REFCOUNT_PARAM_BUFFER, &free_buffer_callback);
2872 ia_css_refcount_clear(-1, &free_buffer_callback);
2873
2874 IA_CSS_LEAVE_PRIVATE("void");
2875 }
2876
2877 static struct ia_css_host_data *
convert_allocate_morph_plane(unsigned short * data,unsigned int width,unsigned int height,unsigned int aligned_width)2878 convert_allocate_morph_plane(
2879 unsigned short *data,
2880 unsigned int width,
2881 unsigned int height,
2882 unsigned int aligned_width)
2883 {
2884 unsigned int i, j, padding, w;
2885 struct ia_css_host_data *me;
2886 unsigned int isp_data_size;
2887 u16 *isp_data_ptr;
2888
2889 IA_CSS_ENTER_PRIVATE("void");
2890
2891 /* currently we don't have morph table interpolation yet,
2892 * so we allow a wider table to be used. This will be removed
2893 * in the future. */
2894 if (width > aligned_width) {
2895 padding = 0;
2896 w = aligned_width;
2897 } else {
2898 padding = aligned_width - width;
2899 w = width;
2900 }
2901 isp_data_size = height * (w + padding) * sizeof(uint16_t);
2902
2903 me = ia_css_host_data_allocate((size_t)isp_data_size);
2904
2905 if (!me) {
2906 IA_CSS_LEAVE_ERR_PRIVATE(-ENOMEM);
2907 return NULL;
2908 }
2909
2910 isp_data_ptr = (uint16_t *)me->address;
2911
2912 memset(isp_data_ptr, 0, (size_t)isp_data_size);
2913
2914 for (i = 0; i < height; i++) {
2915 for (j = 0; j < w; j++)
2916 *isp_data_ptr++ = (uint16_t)data[j];
2917 isp_data_ptr += padding;
2918 data += width;
2919 }
2920
2921 IA_CSS_LEAVE_PRIVATE("void");
2922 return me;
2923 }
2924
2925 static int
store_morph_plane(unsigned short * data,unsigned int width,unsigned int height,ia_css_ptr dest,unsigned int aligned_width)2926 store_morph_plane(
2927 unsigned short *data,
2928 unsigned int width,
2929 unsigned int height,
2930 ia_css_ptr dest,
2931 unsigned int aligned_width)
2932 {
2933 struct ia_css_host_data *isp_data;
2934
2935 assert(dest != mmgr_NULL);
2936
2937 isp_data = convert_allocate_morph_plane(data, width, height, aligned_width);
2938 if (!isp_data) {
2939 IA_CSS_LEAVE_ERR_PRIVATE(-ENOMEM);
2940 return -ENOMEM;
2941 }
2942 ia_css_params_store_ia_css_host_data(dest, isp_data);
2943
2944 ia_css_host_data_free(isp_data);
2945 return 0;
2946 }
2947
sh_css_update_isp_params_to_ddr(struct ia_css_isp_parameters * params,ia_css_ptr ddr_ptr)2948 static void sh_css_update_isp_params_to_ddr(
2949 struct ia_css_isp_parameters *params,
2950 ia_css_ptr ddr_ptr)
2951 {
2952 size_t size = sizeof(params->uds);
2953
2954 IA_CSS_ENTER_PRIVATE("void");
2955
2956 assert(params);
2957
2958 hmm_store(ddr_ptr, ¶ms->uds, size);
2959 IA_CSS_LEAVE_PRIVATE("void");
2960 }
2961
sh_css_update_isp_mem_params_to_ddr(const struct ia_css_binary * binary,ia_css_ptr ddr_mem_ptr,size_t size,enum ia_css_isp_memories mem)2962 static void sh_css_update_isp_mem_params_to_ddr(
2963 const struct ia_css_binary *binary,
2964 ia_css_ptr ddr_mem_ptr,
2965 size_t size,
2966 enum ia_css_isp_memories mem)
2967 {
2968 const struct ia_css_host_data *params;
2969
2970 IA_CSS_ENTER_PRIVATE("void");
2971
2972 params = ia_css_isp_param_get_mem_init(&binary->mem_params,
2973 IA_CSS_PARAM_CLASS_PARAM, mem);
2974 hmm_store(ddr_mem_ptr, params->address, size);
2975
2976 IA_CSS_LEAVE_PRIVATE("void");
2977 }
2978
ia_css_dequeue_param_buffers(void)2979 void ia_css_dequeue_param_buffers(/*unsigned int pipe_num*/ void)
2980 {
2981 unsigned int i;
2982 ia_css_ptr cpy;
2983 enum sh_css_queue_id param_queue_ids[3] = { IA_CSS_PARAMETER_SET_QUEUE_ID,
2984 IA_CSS_PER_FRAME_PARAMETER_SET_QUEUE_ID,
2985 SH_CSS_INVALID_QUEUE_ID
2986 };
2987
2988 IA_CSS_ENTER_PRIVATE("void");
2989
2990 if (!sh_css_sp_is_running()) {
2991 IA_CSS_LEAVE_PRIVATE("sp is not running");
2992 /* SP is not running. The queues are not valid */
2993 return;
2994 }
2995
2996 for (i = 0; SH_CSS_INVALID_QUEUE_ID != param_queue_ids[i]; i++) {
2997 cpy = (ia_css_ptr)0;
2998 /* clean-up old copy */
2999 while (ia_css_bufq_dequeue_buffer(param_queue_ids[i],
3000 (uint32_t *)&cpy) == 0) {
3001 /* TMP: keep track of dequeued param set count
3002 */
3003 g_param_buffer_dequeue_count++;
3004 ia_css_bufq_enqueue_psys_event(
3005 IA_CSS_PSYS_SW_EVENT_BUFFER_DEQUEUED,
3006 0,
3007 param_queue_ids[i],
3008 0);
3009
3010 IA_CSS_LOG("dequeued param set %x from %d, release ref", cpy, 0);
3011 free_ia_css_isp_parameter_set_info(cpy);
3012 cpy = (ia_css_ptr)0;
3013 }
3014 }
3015
3016 IA_CSS_LEAVE_PRIVATE("void");
3017 }
3018
3019 static void
process_kernel_parameters(unsigned int pipe_id,struct ia_css_pipeline_stage * stage,struct ia_css_isp_parameters * params,unsigned int isp_pipe_version,unsigned int raw_bit_depth)3020 process_kernel_parameters(unsigned int pipe_id,
3021 struct ia_css_pipeline_stage *stage,
3022 struct ia_css_isp_parameters *params,
3023 unsigned int isp_pipe_version,
3024 unsigned int raw_bit_depth)
3025 {
3026 unsigned int param_id;
3027
3028 (void)isp_pipe_version;
3029 (void)raw_bit_depth;
3030
3031 sh_css_enable_pipeline(stage->binary);
3032
3033 if (params->config_changed[IA_CSS_OB_ID]) {
3034 ia_css_ob_configure(¶ms->stream_configs.ob,
3035 isp_pipe_version, raw_bit_depth);
3036 }
3037 if (params->config_changed[IA_CSS_S3A_ID]) {
3038 ia_css_s3a_configure(raw_bit_depth);
3039 }
3040 /* Copy stage uds parameters to config, since they can differ per stage.
3041 */
3042 params->crop_config.crop_pos = params->uds[stage->stage_num].crop_pos;
3043 params->uds_config.crop_pos = params->uds[stage->stage_num].crop_pos;
3044 params->uds_config.uds = params->uds[stage->stage_num].uds;
3045 /* Call parameter process functions for all kernels */
3046 /* Skip SC, since that is called on a temp sc table */
3047 for (param_id = 0; param_id < IA_CSS_NUM_PARAMETER_IDS; param_id++) {
3048 if (param_id == IA_CSS_SC_ID) continue;
3049 if (params->config_changed[param_id])
3050 ia_css_kernel_process_param[param_id](pipe_id, stage, params);
3051 }
3052 }
3053
3054 int
sh_css_param_update_isp_params(struct ia_css_pipe * curr_pipe,struct ia_css_isp_parameters * params,bool commit,struct ia_css_pipe * pipe_in)3055 sh_css_param_update_isp_params(struct ia_css_pipe *curr_pipe,
3056 struct ia_css_isp_parameters *params,
3057 bool commit,
3058 struct ia_css_pipe *pipe_in)
3059 {
3060 int err = 0;
3061 ia_css_ptr cpy;
3062 int i;
3063 unsigned int raw_bit_depth = 10;
3064 unsigned int isp_pipe_version = SH_CSS_ISP_PIPE_VERSION_1;
3065 bool acc_cluster_params_changed = false;
3066 unsigned int thread_id, pipe_num;
3067
3068 (void)acc_cluster_params_changed;
3069
3070 assert(curr_pipe);
3071
3072 IA_CSS_ENTER_PRIVATE("pipe=%p, isp_parameters_id=%d", pipe_in, params->isp_parameters_id);
3073 raw_bit_depth = ia_css_stream_input_format_bits_per_pixel(curr_pipe->stream);
3074
3075 /* now make the map available to the sp */
3076 if (!commit) {
3077 IA_CSS_LEAVE_ERR_PRIVATE(err);
3078 return err;
3079 }
3080 /* enqueue a copies of the mem_map to
3081 the designated pipelines */
3082 for (i = 0; i < curr_pipe->stream->num_pipes; i++) {
3083 struct ia_css_pipe *pipe;
3084 struct sh_css_ddr_address_map *cur_map;
3085 struct sh_css_ddr_address_map_size *cur_map_size;
3086 struct ia_css_isp_parameter_set_info isp_params_info;
3087 struct ia_css_pipeline *pipeline;
3088 struct ia_css_pipeline_stage *stage;
3089
3090 enum sh_css_queue_id queue_id;
3091
3092 pipe = curr_pipe->stream->pipes[i];
3093 pipeline = ia_css_pipe_get_pipeline(pipe);
3094 pipe_num = ia_css_pipe_get_pipe_num(pipe);
3095 isp_pipe_version = ia_css_pipe_get_isp_pipe_version(pipe);
3096 ia_css_pipeline_get_sp_thread_id(pipe_num, &thread_id);
3097
3098 ia_css_query_internal_queue_id(params->output_frame
3099 ? IA_CSS_BUFFER_TYPE_PER_FRAME_PARAMETER_SET
3100 : IA_CSS_BUFFER_TYPE_PARAMETER_SET,
3101 thread_id, &queue_id);
3102 if (!sh_css_sp_is_running()) {
3103 /* SP is not running. The queues are not valid */
3104 err = -EBUSY;
3105 break;
3106 }
3107 cur_map = ¶ms->pipe_ddr_ptrs[pipeline->pipe_id];
3108 cur_map_size = ¶ms->pipe_ddr_ptrs_size[pipeline->pipe_id];
3109
3110 /* TODO: Normally, zoom and motion parameters shouldn't
3111 * be part of "isp_params" as it is resolution/pipe dependent
3112 * Therefore, move the zoom config elsewhere (e.g. shading
3113 * table can be taken as an example! @GC
3114 * */
3115 {
3116 /* we have to do this per pipeline because */
3117 /* the processing is a.o. resolution dependent */
3118 err = ia_css_process_zoom_and_motion(params,
3119 pipeline->stages);
3120 if (err)
3121 return err;
3122 }
3123 /* check if to actually update the parameters for this pipe */
3124 /* When API change is implemented making good distinction between
3125 * stream config and pipe config this skipping code can be moved out of the #ifdef */
3126 if (pipe_in && (pipe != pipe_in)) {
3127 IA_CSS_LOG("skipping pipe %p", pipe);
3128 continue;
3129 }
3130
3131 /* BZ 125915, should be moved till after "update other buff" */
3132 /* update the other buffers to the pipe specific copies */
3133 for (stage = pipeline->stages; stage; stage = stage->next) {
3134 unsigned int mem;
3135
3136 if (!stage || !stage->binary)
3137 continue;
3138
3139 process_kernel_parameters(pipeline->pipe_id,
3140 stage, params,
3141 isp_pipe_version, raw_bit_depth);
3142
3143 err = sh_css_params_write_to_ddr_internal(
3144 pipe,
3145 pipeline->pipe_id,
3146 params,
3147 stage,
3148 cur_map,
3149 cur_map_size);
3150
3151 if (err)
3152 break;
3153 for (mem = 0; mem < IA_CSS_NUM_MEMORIES; mem++) {
3154 params->isp_mem_params_changed
3155 [pipeline->pipe_id][stage->stage_num][mem] = false;
3156 }
3157 } /* for */
3158 if (err)
3159 break;
3160 /* update isp_params to pipe specific copies */
3161 if (params->isp_params_changed) {
3162 reallocate_buffer(&cur_map->isp_param,
3163 &cur_map_size->isp_param,
3164 cur_map_size->isp_param,
3165 true,
3166 &err);
3167 if (err)
3168 break;
3169 sh_css_update_isp_params_to_ddr(params, cur_map->isp_param);
3170 }
3171
3172 /* last make referenced copy */
3173 err = ref_sh_css_ddr_address_map(
3174 cur_map,
3175 &isp_params_info.mem_map);
3176 if (err)
3177 break;
3178
3179 /* Update Parameters ID */
3180 isp_params_info.isp_parameters_id = params->isp_parameters_id;
3181
3182 /* Update output frame pointer */
3183 isp_params_info.output_frame_ptr =
3184 (params->output_frame) ? params->output_frame->data : mmgr_NULL;
3185
3186 /* now write the copy to ddr */
3187 err = write_ia_css_isp_parameter_set_info_to_ddr(&isp_params_info, &cpy);
3188 if (err)
3189 break;
3190
3191 /* enqueue the set to sp */
3192 IA_CSS_LOG("queue param set %x to %d", cpy, thread_id);
3193
3194 err = ia_css_bufq_enqueue_buffer(thread_id, queue_id, (uint32_t)cpy);
3195 if (err) {
3196 free_ia_css_isp_parameter_set_info(cpy);
3197 IA_CSS_LOG("pfp: FAILED to add config id %d for OF %d to q %d on thread %d",
3198 isp_params_info.isp_parameters_id,
3199 isp_params_info.output_frame_ptr,
3200 queue_id, thread_id);
3201 break;
3202 } else {
3203 /* TMP: check discrepancy between nr of enqueued
3204 * parameter sets and dequeued sets
3205 */
3206 g_param_buffer_enqueue_count++;
3207 assert(g_param_buffer_enqueue_count < g_param_buffer_dequeue_count + 50);
3208 /*
3209 * Tell the SP which queues are not empty,
3210 * by sending the software event.
3211 */
3212 if (!sh_css_sp_is_running()) {
3213 /* SP is not running. The queues are not valid */
3214 IA_CSS_LEAVE_ERR_PRIVATE(-EBUSY);
3215 return -EBUSY;
3216 }
3217 ia_css_bufq_enqueue_psys_event(
3218 IA_CSS_PSYS_SW_EVENT_BUFFER_ENQUEUED,
3219 (uint8_t)thread_id,
3220 (uint8_t)queue_id,
3221 0);
3222 IA_CSS_LOG("pfp: added config id %d for OF %d to q %d on thread %d",
3223 isp_params_info.isp_parameters_id,
3224 isp_params_info.output_frame_ptr,
3225 queue_id, thread_id);
3226 }
3227 /* clean-up old copy */
3228 ia_css_dequeue_param_buffers(/*pipe_num*/);
3229 params->pipe_dvs_6axis_config_changed[pipeline->pipe_id] = false;
3230 } /* end for each 'active' pipeline */
3231 /* clear the changed flags after all params
3232 for all pipelines have been updated */
3233 params->isp_params_changed = false;
3234 params->sc_table_changed = false;
3235 params->dis_coef_table_changed = false;
3236 params->dvs2_coef_table_changed = false;
3237 params->morph_table_changed = false;
3238 params->dz_config_changed = false;
3239 params->motion_config_changed = false;
3240 /* ------ deprecated(bz675) : from ------ */
3241 params->shading_settings_changed = false;
3242 /* ------ deprecated(bz675) : to ------ */
3243
3244 memset(¶ms->config_changed[0], 0, sizeof(params->config_changed));
3245
3246 IA_CSS_LEAVE_ERR_PRIVATE(err);
3247 return err;
3248 }
3249
3250 static int
sh_css_params_write_to_ddr_internal(struct ia_css_pipe * pipe,unsigned int pipe_id,struct ia_css_isp_parameters * params,const struct ia_css_pipeline_stage * stage,struct sh_css_ddr_address_map * ddr_map,struct sh_css_ddr_address_map_size * ddr_map_size)3251 sh_css_params_write_to_ddr_internal(
3252 struct ia_css_pipe *pipe,
3253 unsigned int pipe_id,
3254 struct ia_css_isp_parameters *params,
3255 const struct ia_css_pipeline_stage *stage,
3256 struct sh_css_ddr_address_map *ddr_map,
3257 struct sh_css_ddr_address_map_size *ddr_map_size)
3258 {
3259 int err;
3260 const struct ia_css_binary *binary;
3261
3262 unsigned int stage_num;
3263 unsigned int mem;
3264 bool buff_realloced;
3265
3266 /* struct is > 128 bytes so it should not be on stack (see checkpatch) */
3267 static struct ia_css_macc_table converted_macc_table;
3268
3269 IA_CSS_ENTER_PRIVATE("void");
3270 assert(params);
3271 assert(ddr_map);
3272 assert(ddr_map_size);
3273 assert(stage);
3274
3275 binary = stage->binary;
3276 assert(binary);
3277
3278 stage_num = stage->stage_num;
3279
3280 if (binary->info->sp.enable.fpnr) {
3281 buff_realloced = reallocate_buffer(&ddr_map->fpn_tbl,
3282 &ddr_map_size->fpn_tbl,
3283 fpntbl_bytes(binary),
3284 params->config_changed[IA_CSS_FPN_ID],
3285 &err);
3286 if (err) {
3287 IA_CSS_LEAVE_ERR_PRIVATE(err);
3288 return err;
3289 }
3290 if (params->config_changed[IA_CSS_FPN_ID] || buff_realloced) {
3291 if (params->fpn_config.enabled) {
3292 err = store_fpntbl(params, ddr_map->fpn_tbl);
3293 if (err) {
3294 IA_CSS_LEAVE_ERR_PRIVATE(err);
3295 return err;
3296 }
3297 }
3298 }
3299 }
3300
3301 if (binary->info->sp.enable.sc) {
3302 u32 enable_conv;
3303
3304 enable_conv = params->shading_settings.enable_shading_table_conversion;
3305
3306 buff_realloced = reallocate_buffer(&ddr_map->sc_tbl,
3307 &ddr_map_size->sc_tbl,
3308 sctbl_bytes(binary),
3309 params->sc_table_changed,
3310 &err);
3311 if (err) {
3312 IA_CSS_LEAVE_ERR_PRIVATE(err);
3313 return err;
3314 }
3315
3316 if (params->shading_settings_changed ||
3317 params->sc_table_changed || buff_realloced) {
3318 if (enable_conv == 0) {
3319 if (params->sc_table) {
3320 /* store the shading table to ddr */
3321 err = ia_css_params_store_sctbl(stage, ddr_map->sc_tbl, params->sc_table);
3322 if (err) {
3323 IA_CSS_LEAVE_ERR_PRIVATE(err);
3324 return err;
3325 }
3326 /* set sc_config to isp */
3327 params->sc_config = (struct ia_css_shading_table *)params->sc_table;
3328 ia_css_kernel_process_param[IA_CSS_SC_ID](pipe_id, stage, params);
3329 params->sc_config = NULL;
3330 } else {
3331 /* generate the identical shading table */
3332 if (params->sc_config) {
3333 ia_css_shading_table_free(params->sc_config);
3334 params->sc_config = NULL;
3335 }
3336 sh_css_params_shading_id_table_generate(¶ms->sc_config,
3337 binary->sctbl_width_per_color,
3338 binary->sctbl_height);
3339 if (!params->sc_config) {
3340 IA_CSS_LEAVE_ERR_PRIVATE(-ENOMEM);
3341 return -ENOMEM;
3342 }
3343
3344 /* store the shading table to ddr */
3345 err = ia_css_params_store_sctbl(stage, ddr_map->sc_tbl, params->sc_config);
3346 if (err) {
3347 IA_CSS_LEAVE_ERR_PRIVATE(err);
3348 return err;
3349 }
3350
3351 /* set sc_config to isp */
3352 ia_css_kernel_process_param[IA_CSS_SC_ID](pipe_id, stage, params);
3353
3354 /* free the shading table */
3355 ia_css_shading_table_free(params->sc_config);
3356 params->sc_config = NULL;
3357 }
3358 } else { /* legacy */
3359 /* ------ deprecated(bz675) : from ------ */
3360 /* shading table is full resolution, reduce */
3361 if (params->sc_config) {
3362 ia_css_shading_table_free(params->sc_config);
3363 params->sc_config = NULL;
3364 }
3365 prepare_shading_table(
3366 (const struct ia_css_shading_table *)params->sc_table,
3367 params->sensor_binning,
3368 ¶ms->sc_config,
3369 binary, pipe->required_bds_factor);
3370 if (!params->sc_config) {
3371 IA_CSS_LEAVE_ERR_PRIVATE(-ENOMEM);
3372 return -ENOMEM;
3373 }
3374
3375 /* store the shading table to ddr */
3376 err = ia_css_params_store_sctbl(stage, ddr_map->sc_tbl, params->sc_config);
3377 if (err) {
3378 IA_CSS_LEAVE_ERR_PRIVATE(err);
3379 return err;
3380 }
3381
3382 /* set sc_config to isp */
3383 ia_css_kernel_process_param[IA_CSS_SC_ID](pipe_id, stage, params);
3384
3385 /* free the shading table */
3386 ia_css_shading_table_free(params->sc_config);
3387 params->sc_config = NULL;
3388 /* ------ deprecated(bz675) : to ------ */
3389 }
3390 }
3391 }
3392
3393 if (params->config_changed[IA_CSS_MACC_ID] && binary->info->sp.enable.macc) {
3394 unsigned int i, j, idx;
3395 static const unsigned int idx_map[] = {
3396 0, 1, 3, 2, 6, 7, 5, 4, 12, 13, 15, 14, 10, 11, 9, 8
3397 };
3398
3399 for (i = 0; i < IA_CSS_MACC_NUM_AXES; i++) {
3400 idx = 4 * idx_map[i];
3401 j = 4 * i;
3402
3403 if (binary->info->sp.pipeline.isp_pipe_version == SH_CSS_ISP_PIPE_VERSION_1) {
3404 converted_macc_table.data[idx] =
3405 (int16_t)sDIGIT_FITTING(params->macc_table.data[j],
3406 13, SH_CSS_MACC_COEF_SHIFT);
3407 converted_macc_table.data[idx + 1] =
3408 (int16_t)sDIGIT_FITTING(params->macc_table.data[j + 1],
3409 13, SH_CSS_MACC_COEF_SHIFT);
3410 converted_macc_table.data[idx + 2] =
3411 (int16_t)sDIGIT_FITTING(params->macc_table.data[j + 2],
3412 13, SH_CSS_MACC_COEF_SHIFT);
3413 converted_macc_table.data[idx + 3] =
3414 (int16_t)sDIGIT_FITTING(params->macc_table.data[j + 3],
3415 13, SH_CSS_MACC_COEF_SHIFT);
3416 } else if (binary->info->sp.pipeline.isp_pipe_version ==
3417 SH_CSS_ISP_PIPE_VERSION_2_2) {
3418 converted_macc_table.data[idx] =
3419 params->macc_table.data[j];
3420 converted_macc_table.data[idx + 1] =
3421 params->macc_table.data[j + 1];
3422 converted_macc_table.data[idx + 2] =
3423 params->macc_table.data[j + 2];
3424 converted_macc_table.data[idx + 3] =
3425 params->macc_table.data[j + 3];
3426 }
3427 }
3428 reallocate_buffer(&ddr_map->macc_tbl,
3429 &ddr_map_size->macc_tbl,
3430 ddr_map_size->macc_tbl,
3431 true,
3432 &err);
3433 if (err) {
3434 IA_CSS_LEAVE_ERR_PRIVATE(err);
3435 return err;
3436 }
3437 hmm_store(ddr_map->macc_tbl,
3438 converted_macc_table.data,
3439 sizeof(converted_macc_table.data));
3440 }
3441
3442 if (binary->info->sp.enable.dvs_6axis) {
3443 /* because UV is packed into the Y plane, calc total
3444 * YYU size = /2 gives size of UV-only,
3445 * total YYU size = UV-only * 3.
3446 */
3447 buff_realloced = reallocate_buffer(
3448 &ddr_map->dvs_6axis_params_y,
3449 &ddr_map_size->dvs_6axis_params_y,
3450 (size_t)((DVS_6AXIS_BYTES(binary) / 2) * 3),
3451 params->pipe_dvs_6axis_config_changed[pipe_id],
3452 &err);
3453 if (err) {
3454 IA_CSS_LEAVE_ERR_PRIVATE(err);
3455 return err;
3456 }
3457
3458 if (params->pipe_dvs_6axis_config_changed[pipe_id] || buff_realloced) {
3459 const struct ia_css_frame_info *dvs_in_frame_info;
3460
3461 if (stage->args.delay_frames[0]) {
3462 /*When delay frames are present(as in case of video),
3463 they are used for dvs. Configure DVS using those params*/
3464 dvs_in_frame_info = &stage->args.delay_frames[0]->frame_info;
3465 } else {
3466 /*Otherwise, use input frame to configure DVS*/
3467 dvs_in_frame_info = &stage->args.in_frame->frame_info;
3468 }
3469
3470 /* Generate default DVS unity table on start up*/
3471 if (!params->pipe_dvs_6axis_config[pipe_id]) {
3472 struct ia_css_resolution dvs_offset = {0};
3473
3474 dvs_offset.width = (PIX_SHIFT_FILTER_RUN_IN_X + binary->dvs_envelope.width) / 2;
3475 dvs_offset.height = (PIX_SHIFT_FILTER_RUN_IN_Y + binary->dvs_envelope.height) / 2;
3476
3477 params->pipe_dvs_6axis_config[pipe_id] =
3478 generate_dvs_6axis_table(&binary->out_frame_info[0].res, &dvs_offset);
3479 if (!params->pipe_dvs_6axis_config[pipe_id]) {
3480 IA_CSS_LEAVE_ERR_PRIVATE(-ENOMEM);
3481 return -ENOMEM;
3482 }
3483 params->pipe_dvs_6axis_config_changed[pipe_id] = true;
3484
3485 store_dvs_6axis_config(params->pipe_dvs_6axis_config[pipe_id],
3486 binary,
3487 dvs_in_frame_info,
3488 ddr_map->dvs_6axis_params_y);
3489 params->isp_params_changed = true;
3490 }
3491 }
3492 }
3493
3494 if (binary->info->sp.enable.ca_gdc) {
3495 unsigned int i;
3496 ia_css_ptr *virt_addr_tetra_x[
3497
3498 IA_CSS_MORPH_TABLE_NUM_PLANES];
3499 size_t *virt_size_tetra_x[
3500
3501 IA_CSS_MORPH_TABLE_NUM_PLANES];
3502 ia_css_ptr *virt_addr_tetra_y[
3503
3504 IA_CSS_MORPH_TABLE_NUM_PLANES];
3505 size_t *virt_size_tetra_y[
3506
3507 IA_CSS_MORPH_TABLE_NUM_PLANES];
3508
3509 virt_addr_tetra_x[0] = &ddr_map->tetra_r_x;
3510 virt_addr_tetra_x[1] = &ddr_map->tetra_gr_x;
3511 virt_addr_tetra_x[2] = &ddr_map->tetra_gb_x;
3512 virt_addr_tetra_x[3] = &ddr_map->tetra_b_x;
3513 virt_addr_tetra_x[4] = &ddr_map->tetra_ratb_x;
3514 virt_addr_tetra_x[5] = &ddr_map->tetra_batr_x;
3515
3516 virt_size_tetra_x[0] = &ddr_map_size->tetra_r_x;
3517 virt_size_tetra_x[1] = &ddr_map_size->tetra_gr_x;
3518 virt_size_tetra_x[2] = &ddr_map_size->tetra_gb_x;
3519 virt_size_tetra_x[3] = &ddr_map_size->tetra_b_x;
3520 virt_size_tetra_x[4] = &ddr_map_size->tetra_ratb_x;
3521 virt_size_tetra_x[5] = &ddr_map_size->tetra_batr_x;
3522
3523 virt_addr_tetra_y[0] = &ddr_map->tetra_r_y;
3524 virt_addr_tetra_y[1] = &ddr_map->tetra_gr_y;
3525 virt_addr_tetra_y[2] = &ddr_map->tetra_gb_y;
3526 virt_addr_tetra_y[3] = &ddr_map->tetra_b_y;
3527 virt_addr_tetra_y[4] = &ddr_map->tetra_ratb_y;
3528 virt_addr_tetra_y[5] = &ddr_map->tetra_batr_y;
3529
3530 virt_size_tetra_y[0] = &ddr_map_size->tetra_r_y;
3531 virt_size_tetra_y[1] = &ddr_map_size->tetra_gr_y;
3532 virt_size_tetra_y[2] = &ddr_map_size->tetra_gb_y;
3533 virt_size_tetra_y[3] = &ddr_map_size->tetra_b_y;
3534 virt_size_tetra_y[4] = &ddr_map_size->tetra_ratb_y;
3535 virt_size_tetra_y[5] = &ddr_map_size->tetra_batr_y;
3536
3537 buff_realloced = false;
3538 for (i = 0; i < IA_CSS_MORPH_TABLE_NUM_PLANES; i++) {
3539 buff_realloced |=
3540 reallocate_buffer(virt_addr_tetra_x[i],
3541 virt_size_tetra_x[i],
3542 morph_plane_bytes(binary),
3543 params->morph_table_changed,
3544 &err);
3545 if (err) {
3546 IA_CSS_LEAVE_ERR_PRIVATE(err);
3547 return err;
3548 }
3549 buff_realloced |=
3550 reallocate_buffer(virt_addr_tetra_y[i],
3551 virt_size_tetra_y[i],
3552 morph_plane_bytes(binary),
3553 params->morph_table_changed,
3554 &err);
3555 if (err) {
3556 IA_CSS_LEAVE_ERR_PRIVATE(err);
3557 return err;
3558 }
3559 }
3560 if (params->morph_table_changed || buff_realloced) {
3561 const struct ia_css_morph_table *table = params->morph_table;
3562 struct ia_css_morph_table *id_table = NULL;
3563
3564 if ((table) &&
3565 (table->width < binary->morph_tbl_width ||
3566 table->height < binary->morph_tbl_height)) {
3567 table = NULL;
3568 }
3569 if (!table) {
3570 err = sh_css_params_default_morph_table(&id_table,
3571 binary);
3572 if (err) {
3573 IA_CSS_LEAVE_ERR_PRIVATE(err);
3574 return err;
3575 }
3576 table = id_table;
3577 }
3578
3579 for (i = 0; i < IA_CSS_MORPH_TABLE_NUM_PLANES; i++) {
3580 store_morph_plane(table->coordinates_x[i],
3581 table->width,
3582 table->height,
3583 *virt_addr_tetra_x[i],
3584 binary->morph_tbl_aligned_width);
3585 store_morph_plane(table->coordinates_y[i],
3586 table->width,
3587 table->height,
3588 *virt_addr_tetra_y[i],
3589 binary->morph_tbl_aligned_width);
3590 }
3591 if (id_table)
3592 ia_css_morph_table_free(id_table);
3593 }
3594 }
3595
3596 /* After special cases like SC, FPN since they may change parameters */
3597 for (mem = 0; mem < N_IA_CSS_MEMORIES; mem++) {
3598 const struct ia_css_isp_data *isp_data =
3599 ia_css_isp_param_get_isp_mem_init(&binary->info->sp.mem_initializers,
3600 IA_CSS_PARAM_CLASS_PARAM, mem);
3601 size_t size = isp_data->size;
3602
3603 if (!size) continue;
3604 buff_realloced = reallocate_buffer(&ddr_map->isp_mem_param[stage_num][mem],
3605 &ddr_map_size->isp_mem_param[stage_num][mem],
3606 size,
3607 params->isp_mem_params_changed[pipe_id][stage_num][mem],
3608 &err);
3609 if (err) {
3610 IA_CSS_LEAVE_ERR_PRIVATE(err);
3611 return err;
3612 }
3613 if (params->isp_mem_params_changed[pipe_id][stage_num][mem] || buff_realloced) {
3614 sh_css_update_isp_mem_params_to_ddr(binary,
3615 ddr_map->isp_mem_param[stage_num][mem],
3616 ddr_map_size->isp_mem_param[stage_num][mem], mem);
3617 }
3618 }
3619
3620 IA_CSS_LEAVE_ERR_PRIVATE(0);
3621 return 0;
3622 }
3623
ia_css_get_fpn_table(struct ia_css_stream * stream)3624 const struct ia_css_fpn_table *ia_css_get_fpn_table(struct ia_css_stream
3625 *stream)
3626 {
3627 struct ia_css_isp_parameters *params;
3628
3629 IA_CSS_ENTER_LEAVE("void");
3630 assert(stream);
3631
3632 params = stream->isp_params_configs;
3633
3634 return ¶ms->fpn_config;
3635 }
3636
ia_css_get_shading_table(struct ia_css_stream * stream)3637 struct ia_css_shading_table *ia_css_get_shading_table(struct ia_css_stream
3638 *stream)
3639 {
3640 struct ia_css_shading_table *table = NULL;
3641 struct ia_css_isp_parameters *params;
3642
3643 IA_CSS_ENTER("void");
3644
3645 assert(stream);
3646
3647 params = stream->isp_params_configs;
3648 if (!params)
3649 return NULL;
3650
3651 if (params->shading_settings.enable_shading_table_conversion == 0) {
3652 if (params->sc_table) {
3653 table = (struct ia_css_shading_table *)params->sc_table;
3654 } else {
3655 const struct ia_css_binary *binary
3656 = ia_css_stream_get_shading_correction_binary(stream);
3657 if (binary) {
3658 /* generate the identical shading table */
3659 if (params->sc_config) {
3660 ia_css_shading_table_free(params->sc_config);
3661 params->sc_config = NULL;
3662 }
3663 sh_css_params_shading_id_table_generate(¶ms->sc_config,
3664 binary->sctbl_width_per_color,
3665 binary->sctbl_height);
3666 table = params->sc_config;
3667 /* The sc_config will be freed in the
3668 * ia_css_stream_isp_parameters_uninit function. */
3669 }
3670 }
3671 } else {
3672 /* ------ deprecated(bz675) : from ------ */
3673 const struct ia_css_binary *binary
3674 = ia_css_stream_get_shading_correction_binary(stream);
3675 struct ia_css_pipe *pipe;
3676
3677 /**********************************************************************/
3678 /* following code is copied from function ia_css_stream_get_shading_correction_binary()
3679 * to match with the binary */
3680 pipe = stream->pipes[0];
3681
3682 if (stream->num_pipes == 2) {
3683 assert(stream->pipes[1]);
3684 if (stream->pipes[1]->config.mode == IA_CSS_PIPE_MODE_VIDEO ||
3685 stream->pipes[1]->config.mode == IA_CSS_PIPE_MODE_PREVIEW)
3686 pipe = stream->pipes[1];
3687 }
3688 /**********************************************************************/
3689 if (binary) {
3690 if (params->sc_config) {
3691 ia_css_shading_table_free(params->sc_config);
3692 params->sc_config = NULL;
3693 }
3694 prepare_shading_table(
3695 (const struct ia_css_shading_table *)params->sc_table,
3696 params->sensor_binning,
3697 ¶ms->sc_config,
3698 binary, pipe->required_bds_factor);
3699
3700 table = params->sc_config;
3701 /* The sc_config will be freed in the
3702 * ia_css_stream_isp_parameters_uninit function. */
3703 }
3704 /* ------ deprecated(bz675) : to ------ */
3705 }
3706
3707 IA_CSS_LEAVE("table=%p", table);
3708
3709 return table;
3710 }
3711
sh_css_store_sp_group_to_ddr(void)3712 ia_css_ptr sh_css_store_sp_group_to_ddr(void)
3713 {
3714 u8 *write_buf;
3715 u8 *buf_ptr;
3716
3717 IA_CSS_ENTER_LEAVE_PRIVATE("void");
3718
3719 write_buf = kzalloc(sizeof(u8) * 8192, GFP_KERNEL);
3720 if (!write_buf)
3721 return 0;
3722
3723 buf_ptr = write_buf;
3724 if (IS_ISP2401) {
3725 memcpy(buf_ptr, &sh_css_sp_group.config, 3);
3726 buf_ptr += 3;
3727 *buf_ptr++ = sh_css_sp_group.config.enable_isys_event_queue;
3728 *buf_ptr++ = sh_css_sp_group.config.disable_cont_vf;
3729 memset(buf_ptr, 0, 3);
3730 buf_ptr += 3; /* Padding 3 bytes for struct sh_css_sp_config*/
3731 } else {
3732 memcpy(buf_ptr, &sh_css_sp_group.config, sizeof(sh_css_sp_group.config));
3733 buf_ptr += sizeof(sh_css_sp_group.config);
3734 }
3735
3736 memcpy(buf_ptr, &sh_css_sp_group.pipe, sizeof(sh_css_sp_group.pipe));
3737 buf_ptr += sizeof(sh_css_sp_group.pipe);
3738
3739 if (IS_ISP2401) {
3740 memcpy(buf_ptr, &sh_css_sp_group.pipe_io, sizeof(sh_css_sp_group.pipe_io));
3741 buf_ptr += sizeof(sh_css_sp_group.pipe_io);
3742 memcpy(buf_ptr, &sh_css_sp_group.pipe_io_status,
3743 sizeof(sh_css_sp_group.pipe_io_status));
3744 buf_ptr += sizeof(sh_css_sp_group.pipe_io_status);
3745 }
3746
3747 memcpy(buf_ptr, &sh_css_sp_group.debug, sizeof(sh_css_sp_group.debug));
3748 buf_ptr += sizeof(sh_css_sp_group.debug);
3749
3750 hmm_store(xmem_sp_group_ptrs,
3751 write_buf,
3752 buf_ptr - write_buf);
3753
3754 kfree(write_buf);
3755 return xmem_sp_group_ptrs;
3756 }
3757
sh_css_store_sp_stage_to_ddr(unsigned int pipe,unsigned int stage)3758 ia_css_ptr sh_css_store_sp_stage_to_ddr(
3759 unsigned int pipe,
3760 unsigned int stage)
3761 {
3762 IA_CSS_ENTER_LEAVE_PRIVATE("void");
3763 hmm_store(xmem_sp_stage_ptrs[pipe][stage],
3764 &sh_css_sp_stage,
3765 sizeof(struct sh_css_sp_stage));
3766 return xmem_sp_stage_ptrs[pipe][stage];
3767 }
3768
sh_css_store_isp_stage_to_ddr(unsigned int pipe,unsigned int stage)3769 ia_css_ptr sh_css_store_isp_stage_to_ddr(
3770 unsigned int pipe,
3771 unsigned int stage)
3772 {
3773 IA_CSS_ENTER_LEAVE_PRIVATE("void");
3774 hmm_store(xmem_isp_stage_ptrs[pipe][stage],
3775 &sh_css_isp_stage,
3776 sizeof(struct sh_css_isp_stage));
3777 return xmem_isp_stage_ptrs[pipe][stage];
3778 }
3779
ref_sh_css_ddr_address_map(struct sh_css_ddr_address_map * map,struct sh_css_ddr_address_map * out)3780 static int ref_sh_css_ddr_address_map(
3781 struct sh_css_ddr_address_map *map,
3782 struct sh_css_ddr_address_map *out)
3783 {
3784 int err = 0;
3785 unsigned int i;
3786
3787 /* we will use a union to copy things; overlaying an array
3788 with the struct; that way adding fields in the struct
3789 will keep things working, and we will not get type errors.
3790 */
3791 union {
3792 struct sh_css_ddr_address_map *map;
3793 ia_css_ptr *addrs;
3794 } in_addrs, to_addrs;
3795
3796 IA_CSS_ENTER_PRIVATE("void");
3797 assert(map);
3798 assert(out);
3799
3800 in_addrs.map = map;
3801 to_addrs.map = out;
3802
3803 assert(sizeof(struct sh_css_ddr_address_map_size) / sizeof(size_t) ==
3804 sizeof(struct sh_css_ddr_address_map) / sizeof(ia_css_ptr));
3805
3806 /* copy map using size info */
3807 for (i = 0; i < (sizeof(struct sh_css_ddr_address_map_size) /
3808 sizeof(size_t)); i++) {
3809 if (in_addrs.addrs[i] == mmgr_NULL)
3810 to_addrs.addrs[i] = mmgr_NULL;
3811 else
3812 to_addrs.addrs[i] = ia_css_refcount_increment(IA_CSS_REFCOUNT_PARAM_BUFFER,
3813 in_addrs.addrs[i]);
3814 }
3815
3816 IA_CSS_LEAVE_ERR_PRIVATE(err);
3817 return err;
3818 }
3819
write_ia_css_isp_parameter_set_info_to_ddr(struct ia_css_isp_parameter_set_info * me,ia_css_ptr * out)3820 static int write_ia_css_isp_parameter_set_info_to_ddr(
3821 struct ia_css_isp_parameter_set_info *me,
3822 ia_css_ptr *out)
3823 {
3824 int err = 0;
3825 bool succ;
3826
3827 IA_CSS_ENTER_PRIVATE("void");
3828
3829 assert(me);
3830 assert(out);
3831
3832 *out = ia_css_refcount_increment(IA_CSS_REFCOUNT_PARAM_SET_POOL,
3833 hmm_alloc(sizeof(struct ia_css_isp_parameter_set_info)));
3834 succ = (*out != mmgr_NULL);
3835 if (succ)
3836 hmm_store(*out,
3837 me, sizeof(struct ia_css_isp_parameter_set_info));
3838 else
3839 err = -ENOMEM;
3840
3841 IA_CSS_LEAVE_ERR_PRIVATE(err);
3842 return err;
3843 }
3844
3845 static int
free_ia_css_isp_parameter_set_info(ia_css_ptr ptr)3846 free_ia_css_isp_parameter_set_info(
3847 ia_css_ptr ptr)
3848 {
3849 int err = 0;
3850 struct ia_css_isp_parameter_set_info isp_params_info;
3851 unsigned int i;
3852 ia_css_ptr *addrs = (ia_css_ptr *)&isp_params_info.mem_map;
3853
3854 IA_CSS_ENTER_PRIVATE("ptr = %u", ptr);
3855
3856 /* sanity check - ptr must be valid */
3857 if (!ia_css_refcount_is_valid(ptr)) {
3858 IA_CSS_ERROR("%s: IA_CSS_REFCOUNT_PARAM_SET_POOL(0x%x) invalid arg", __func__,
3859 ptr);
3860 err = -EINVAL;
3861 IA_CSS_LEAVE_ERR_PRIVATE(err);
3862 return err;
3863 }
3864
3865 hmm_load(ptr, &isp_params_info.mem_map, sizeof(struct sh_css_ddr_address_map));
3866 /* copy map using size info */
3867 for (i = 0; i < (sizeof(struct sh_css_ddr_address_map_size) /
3868 sizeof(size_t)); i++) {
3869 if (addrs[i] == mmgr_NULL)
3870 continue;
3871
3872 /* sanity check - ptr must be valid */
3873 if (!ia_css_refcount_is_valid(addrs[i])) {
3874 IA_CSS_ERROR("%s: IA_CSS_REFCOUNT_PARAM_BUFFER(0x%x) invalid arg", __func__,
3875 ptr);
3876 err = -EINVAL;
3877 continue;
3878 }
3879
3880 ia_css_refcount_decrement(IA_CSS_REFCOUNT_PARAM_BUFFER, addrs[i]);
3881 }
3882 ia_css_refcount_decrement(IA_CSS_REFCOUNT_PARAM_SET_POOL, ptr);
3883
3884 IA_CSS_LEAVE_ERR_PRIVATE(err);
3885 return err;
3886 }
3887
3888 /* Mark all parameters as changed to force recomputing the derived ISP parameters */
3889 void
sh_css_invalidate_params(struct ia_css_stream * stream)3890 sh_css_invalidate_params(struct ia_css_stream *stream)
3891 {
3892 struct ia_css_isp_parameters *params;
3893 unsigned int i, j, mem;
3894
3895 IA_CSS_ENTER_PRIVATE("void");
3896 assert(stream);
3897
3898 params = stream->isp_params_configs;
3899 params->isp_params_changed = true;
3900 for (i = 0; i < IA_CSS_PIPE_ID_NUM; i++) {
3901 for (j = 0; j < SH_CSS_MAX_STAGES; j++) {
3902 for (mem = 0; mem < N_IA_CSS_MEMORIES; mem++) {
3903 params->isp_mem_params_changed[i][j][mem] = true;
3904 }
3905 }
3906 }
3907
3908 memset(¶ms->config_changed[0], 1, sizeof(params->config_changed));
3909 params->dis_coef_table_changed = true;
3910 params->dvs2_coef_table_changed = true;
3911 params->morph_table_changed = true;
3912 params->sc_table_changed = true;
3913 params->dz_config_changed = true;
3914 params->motion_config_changed = true;
3915
3916 /*Free up theDVS table memory blocks before recomputing new table */
3917 for (i = 0; i < IA_CSS_PIPE_ID_NUM; i++) {
3918 if (params->pipe_dvs_6axis_config[i]) {
3919 free_dvs_6axis_table(¶ms->pipe_dvs_6axis_config[i]);
3920 params->pipe_dvs_6axis_config_changed[i] = true;
3921 }
3922 }
3923
3924 IA_CSS_LEAVE_PRIVATE("void");
3925 }
3926
3927 void
sh_css_update_uds_and_crop_info(const struct ia_css_binary_info * info,const struct ia_css_frame_info * in_frame_info,const struct ia_css_frame_info * out_frame_info,const struct ia_css_resolution * dvs_env,const struct ia_css_dz_config * zoom,const struct ia_css_vector * motion_vector,struct sh_css_uds_info * uds,struct sh_css_crop_pos * sp_out_crop_pos,bool enable_zoom)3928 sh_css_update_uds_and_crop_info(
3929 const struct ia_css_binary_info *info,
3930 const struct ia_css_frame_info *in_frame_info,
3931 const struct ia_css_frame_info *out_frame_info,
3932 const struct ia_css_resolution *dvs_env,
3933 const struct ia_css_dz_config *zoom,
3934 const struct ia_css_vector *motion_vector,
3935 struct sh_css_uds_info *uds, /* out */
3936 struct sh_css_crop_pos *sp_out_crop_pos, /* out */
3937
3938 bool enable_zoom)
3939 {
3940 IA_CSS_ENTER_PRIVATE("void");
3941
3942 assert(info);
3943 assert(in_frame_info);
3944 assert(out_frame_info);
3945 assert(dvs_env);
3946 assert(zoom);
3947 assert(motion_vector);
3948 assert(uds);
3949 assert(sp_out_crop_pos);
3950
3951 uds->curr_dx = enable_zoom ? (uint16_t)zoom->dx : HRT_GDC_N;
3952 uds->curr_dy = enable_zoom ? (uint16_t)zoom->dy : HRT_GDC_N;
3953
3954 if (info->enable.dvs_envelope) {
3955 unsigned int crop_x = 0,
3956 crop_y = 0,
3957 uds_xc = 0,
3958 uds_yc = 0,
3959 env_width, env_height;
3960 int half_env_x, half_env_y;
3961 int motion_x = motion_vector->x;
3962 int motion_y = motion_vector->y;
3963 bool upscale_x = in_frame_info->res.width < out_frame_info->res.width;
3964 bool upscale_y = in_frame_info->res.height < out_frame_info->res.height;
3965
3966 if (info->enable.uds && !info->enable.ds) {
3967 /**
3968 * we calculate with the envelope that we can actually
3969 * use, the min dvs envelope is for the filter
3970 * initialization.
3971 */
3972 env_width = dvs_env->width -
3973 SH_CSS_MIN_DVS_ENVELOPE;
3974 env_height = dvs_env->height -
3975 SH_CSS_MIN_DVS_ENVELOPE;
3976 half_env_x = env_width / 2;
3977 half_env_y = env_height / 2;
3978 /**
3979 * for digital zoom, we use the dvs envelope and make
3980 * sure that we don't include the 8 leftmost pixels or
3981 * 8 topmost rows.
3982 */
3983 if (upscale_x) {
3984 uds_xc = (in_frame_info->res.width
3985 + env_width
3986 + SH_CSS_MIN_DVS_ENVELOPE) / 2;
3987 } else {
3988 uds_xc = (out_frame_info->res.width
3989 + env_width) / 2
3990 + SH_CSS_MIN_DVS_ENVELOPE;
3991 }
3992 if (upscale_y) {
3993 uds_yc = (in_frame_info->res.height
3994 + env_height
3995 + SH_CSS_MIN_DVS_ENVELOPE) / 2;
3996 } else {
3997 uds_yc = (out_frame_info->res.height
3998 + env_height) / 2
3999 + SH_CSS_MIN_DVS_ENVELOPE;
4000 }
4001 /* clip the motion vector to +/- half the envelope */
4002 motion_x = clamp(motion_x, -half_env_x, half_env_x);
4003 motion_y = clamp(motion_y, -half_env_y, half_env_y);
4004 uds_xc += motion_x;
4005 uds_yc += motion_y;
4006 /* uds can be pipelined, remove top lines */
4007 crop_y = 2;
4008 } else if (info->enable.ds) {
4009 env_width = dvs_env->width;
4010 env_height = dvs_env->height;
4011 half_env_x = env_width / 2;
4012 half_env_y = env_height / 2;
4013 /* clip the motion vector to +/- half the envelope */
4014 motion_x = clamp(motion_x, -half_env_x, half_env_x);
4015 motion_y = clamp(motion_y, -half_env_y, half_env_y);
4016 /* for video with downscaling, the envelope is included
4017 in the input resolution. */
4018 uds_xc = in_frame_info->res.width / 2 + motion_x;
4019 uds_yc = in_frame_info->res.height / 2 + motion_y;
4020 crop_x = info->pipeline.left_cropping;
4021 /* ds == 2 (yuv_ds) can be pipelined, remove top
4022 lines */
4023 if (info->enable.ds & 1)
4024 crop_y = info->pipeline.top_cropping;
4025 else
4026 crop_y = 2;
4027 } else {
4028 /* video nodz: here we can only crop. We make sure we
4029 crop at least the first 8x8 pixels away. */
4030 env_width = dvs_env->width -
4031 SH_CSS_MIN_DVS_ENVELOPE;
4032 env_height = dvs_env->height -
4033 SH_CSS_MIN_DVS_ENVELOPE;
4034 half_env_x = env_width / 2;
4035 half_env_y = env_height / 2;
4036 motion_x = clamp(motion_x, -half_env_x, half_env_x);
4037 motion_y = clamp(motion_y, -half_env_y, half_env_y);
4038 crop_x = SH_CSS_MIN_DVS_ENVELOPE
4039 + half_env_x + motion_x;
4040 crop_y = SH_CSS_MIN_DVS_ENVELOPE
4041 + half_env_y + motion_y;
4042 }
4043
4044 /* Must enforce that the crop position is even */
4045 crop_x = EVEN_FLOOR(crop_x);
4046 crop_y = EVEN_FLOOR(crop_y);
4047 uds_xc = EVEN_FLOOR(uds_xc);
4048 uds_yc = EVEN_FLOOR(uds_yc);
4049
4050 uds->xc = (uint16_t)uds_xc;
4051 uds->yc = (uint16_t)uds_yc;
4052 sp_out_crop_pos->x = (uint16_t)crop_x;
4053 sp_out_crop_pos->y = (uint16_t)crop_y;
4054 } else {
4055 /* for down scaling, we always use the center of the image */
4056 uds->xc = (uint16_t)in_frame_info->res.width / 2;
4057 uds->yc = (uint16_t)in_frame_info->res.height / 2;
4058 sp_out_crop_pos->x = (uint16_t)info->pipeline.left_cropping;
4059 sp_out_crop_pos->y = (uint16_t)info->pipeline.top_cropping;
4060 }
4061 IA_CSS_LEAVE_PRIVATE("void");
4062 }
4063
4064 static int
sh_css_update_uds_and_crop_info_based_on_zoom_region(const struct ia_css_binary_info * info,const struct ia_css_frame_info * in_frame_info,const struct ia_css_frame_info * out_frame_info,const struct ia_css_resolution * dvs_env,const struct ia_css_dz_config * zoom,const struct ia_css_vector * motion_vector,struct sh_css_uds_info * uds,struct sh_css_crop_pos * sp_out_crop_pos,struct ia_css_resolution pipe_in_res,bool enable_zoom)4065 sh_css_update_uds_and_crop_info_based_on_zoom_region(
4066 const struct ia_css_binary_info *info,
4067 const struct ia_css_frame_info *in_frame_info,
4068 const struct ia_css_frame_info *out_frame_info,
4069 const struct ia_css_resolution *dvs_env,
4070 const struct ia_css_dz_config *zoom,
4071 const struct ia_css_vector *motion_vector,
4072 struct sh_css_uds_info *uds, /* out */
4073 struct sh_css_crop_pos *sp_out_crop_pos, /* out */
4074 struct ia_css_resolution pipe_in_res,
4075 bool enable_zoom)
4076 {
4077 unsigned int x0 = 0, y0 = 0, x1 = 0, y1 = 0;
4078 int err = 0;
4079 /* Note:
4080 * Filter_Envelope = 0 for NND/LUT
4081 * Filter_Envelope = 1 for BCI
4082 * Filter_Envelope = 3 for BLI
4083 * Currently, not considering this filter envelope because, In uds.sp.c is recalculating
4084 * the dx/dy based on filter envelope and other information (ia_css_uds_sp_scale_params)
4085 * Ideally, That should be done on host side not on sp side.
4086 */
4087 unsigned int filter_envelope = 0;
4088
4089 IA_CSS_ENTER_PRIVATE("void");
4090
4091 assert(info);
4092 assert(in_frame_info);
4093 assert(out_frame_info);
4094 assert(dvs_env);
4095 assert(zoom);
4096 assert(motion_vector);
4097 assert(uds);
4098 assert(sp_out_crop_pos);
4099 x0 = zoom->zoom_region.origin.x;
4100 y0 = zoom->zoom_region.origin.y;
4101 x1 = zoom->zoom_region.resolution.width + x0;
4102 y1 = zoom->zoom_region.resolution.height + y0;
4103
4104 if ((x0 > x1) || (y0 > y1) || (x1 > pipe_in_res.width) || (y1 > pipe_in_res.height))
4105 return -EINVAL;
4106
4107 if (!enable_zoom) {
4108 uds->curr_dx = HRT_GDC_N;
4109 uds->curr_dy = HRT_GDC_N;
4110 }
4111
4112 if (info->enable.dvs_envelope) {
4113 /* Zoom region is only supported by the UDS module on ISP
4114 * 2 and higher. It is not supported in video mode on ISP 1 */
4115 return -EINVAL;
4116 } else {
4117 if (enable_zoom) {
4118 /* A. Calculate dx/dy based on crop region using in_frame_info
4119 * Scale the crop region if in_frame_info to the stage is not same as
4120 * actual effective input of the pipeline
4121 */
4122 if (in_frame_info->res.width != pipe_in_res.width ||
4123 in_frame_info->res.height != pipe_in_res.height) {
4124 x0 = (x0 * in_frame_info->res.width) / (pipe_in_res.width);
4125 y0 = (y0 * in_frame_info->res.height) / (pipe_in_res.height);
4126 x1 = (x1 * in_frame_info->res.width) / (pipe_in_res.width);
4127 y1 = (y1 * in_frame_info->res.height) / (pipe_in_res.height);
4128 }
4129 uds->curr_dx =
4130 ((x1 - x0 - filter_envelope) * HRT_GDC_N) / in_frame_info->res.width;
4131 uds->curr_dy =
4132 ((y1 - y0 - filter_envelope) * HRT_GDC_N) / in_frame_info->res.height;
4133
4134 /* B. Calculate xc/yc based on crop region */
4135 uds->xc = (uint16_t)x0 + (((x1) - (x0)) / 2);
4136 uds->yc = (uint16_t)y0 + (((y1) - (y0)) / 2);
4137 } else {
4138 uds->xc = (uint16_t)in_frame_info->res.width / 2;
4139 uds->yc = (uint16_t)in_frame_info->res.height / 2;
4140 }
4141
4142 ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE,
4143 "uds->curr_dx=%d, uds->xc=%d, uds->yc=%d\n",
4144 uds->curr_dx, uds->xc, uds->yc);
4145 ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "x0=%d, y0=%d, x1=%d, y1=%d\n",
4146 x0, y0, x1, y1);
4147 sp_out_crop_pos->x = (uint16_t)info->pipeline.left_cropping;
4148 sp_out_crop_pos->y = (uint16_t)info->pipeline.top_cropping;
4149 }
4150 IA_CSS_LEAVE_PRIVATE("void");
4151 return err;
4152 }
4153
4154 struct ia_css_3a_statistics *
ia_css_3a_statistics_allocate(const struct ia_css_3a_grid_info * grid)4155 ia_css_3a_statistics_allocate(const struct ia_css_3a_grid_info *grid)
4156 {
4157 struct ia_css_3a_statistics *me;
4158 int grid_size;
4159
4160 IA_CSS_ENTER("grid=%p", grid);
4161
4162 assert(grid);
4163
4164 me = kvcalloc(1, sizeof(*me), GFP_KERNEL);
4165 if (!me)
4166 goto err;
4167
4168 me->grid = *grid;
4169 grid_size = grid->width * grid->height;
4170 me->data = kvmalloc(grid_size * sizeof(*me->data), GFP_KERNEL);
4171 if (!me->data)
4172 goto err;
4173 /* No weighted histogram, no structure, treat the histogram data as a byte dump in a byte array */
4174 me->rgby_data = kvmalloc(sizeof_hmem(HMEM0_ID), GFP_KERNEL);
4175 if (!me->rgby_data)
4176 goto err;
4177
4178 IA_CSS_LEAVE("return=%p", me);
4179 return me;
4180 err:
4181 ia_css_3a_statistics_free(me);
4182
4183 IA_CSS_LEAVE("return=%p", NULL);
4184 return NULL;
4185 }
4186
4187 void
ia_css_3a_statistics_free(struct ia_css_3a_statistics * me)4188 ia_css_3a_statistics_free(struct ia_css_3a_statistics *me)
4189 {
4190 if (me) {
4191 kvfree(me->rgby_data);
4192 kvfree(me->data);
4193 kvfree(me);
4194 }
4195 }
4196
4197 struct ia_css_dvs_statistics *
ia_css_dvs_statistics_allocate(const struct ia_css_dvs_grid_info * grid)4198 ia_css_dvs_statistics_allocate(const struct ia_css_dvs_grid_info *grid)
4199 {
4200 struct ia_css_dvs_statistics *me;
4201
4202 assert(grid);
4203
4204 me = kvcalloc(1, sizeof(*me), GFP_KERNEL);
4205 if (!me)
4206 goto err;
4207
4208 me->grid = *grid;
4209 me->hor_proj = kvmalloc(grid->height * IA_CSS_DVS_NUM_COEF_TYPES *
4210 sizeof(*me->hor_proj), GFP_KERNEL);
4211 if (!me->hor_proj)
4212 goto err;
4213
4214 me->ver_proj = kvmalloc(grid->width * IA_CSS_DVS_NUM_COEF_TYPES *
4215 sizeof(*me->ver_proj), GFP_KERNEL);
4216 if (!me->ver_proj)
4217 goto err;
4218
4219 return me;
4220 err:
4221 ia_css_dvs_statistics_free(me);
4222 return NULL;
4223 }
4224
4225 void
ia_css_dvs_statistics_free(struct ia_css_dvs_statistics * me)4226 ia_css_dvs_statistics_free(struct ia_css_dvs_statistics *me)
4227 {
4228 if (me) {
4229 kvfree(me->hor_proj);
4230 kvfree(me->ver_proj);
4231 kvfree(me);
4232 }
4233 }
4234
4235 struct ia_css_dvs_coefficients *
ia_css_dvs_coefficients_allocate(const struct ia_css_dvs_grid_info * grid)4236 ia_css_dvs_coefficients_allocate(const struct ia_css_dvs_grid_info *grid)
4237 {
4238 struct ia_css_dvs_coefficients *me;
4239
4240 assert(grid);
4241
4242 me = kvcalloc(1, sizeof(*me), GFP_KERNEL);
4243 if (!me)
4244 goto err;
4245
4246 me->grid = *grid;
4247
4248 me->hor_coefs = kvmalloc(grid->num_hor_coefs *
4249 IA_CSS_DVS_NUM_COEF_TYPES *
4250 sizeof(*me->hor_coefs), GFP_KERNEL);
4251 if (!me->hor_coefs)
4252 goto err;
4253
4254 me->ver_coefs = kvmalloc(grid->num_ver_coefs *
4255 IA_CSS_DVS_NUM_COEF_TYPES *
4256 sizeof(*me->ver_coefs), GFP_KERNEL);
4257 if (!me->ver_coefs)
4258 goto err;
4259
4260 return me;
4261 err:
4262 ia_css_dvs_coefficients_free(me);
4263 return NULL;
4264 }
4265
4266 void
ia_css_dvs_coefficients_free(struct ia_css_dvs_coefficients * me)4267 ia_css_dvs_coefficients_free(struct ia_css_dvs_coefficients *me)
4268 {
4269 if (me) {
4270 kvfree(me->hor_coefs);
4271 kvfree(me->ver_coefs);
4272 kvfree(me);
4273 }
4274 }
4275
4276 struct ia_css_dvs2_statistics *
ia_css_dvs2_statistics_allocate(const struct ia_css_dvs_grid_info * grid)4277 ia_css_dvs2_statistics_allocate(const struct ia_css_dvs_grid_info *grid)
4278 {
4279 struct ia_css_dvs2_statistics *me;
4280
4281 assert(grid);
4282
4283 me = kvcalloc(1, sizeof(*me), GFP_KERNEL);
4284 if (!me)
4285 goto err;
4286
4287 me->grid = *grid;
4288
4289 me->hor_prod.odd_real = kvmalloc(grid->aligned_width *
4290 grid->aligned_height *
4291 sizeof(*me->hor_prod.odd_real),
4292 GFP_KERNEL);
4293 if (!me->hor_prod.odd_real)
4294 goto err;
4295
4296 me->hor_prod.odd_imag = kvmalloc(grid->aligned_width *
4297 grid->aligned_height *
4298 sizeof(*me->hor_prod.odd_imag),
4299 GFP_KERNEL);
4300 if (!me->hor_prod.odd_imag)
4301 goto err;
4302
4303 me->hor_prod.even_real = kvmalloc(grid->aligned_width *
4304 grid->aligned_height *
4305 sizeof(*me->hor_prod.even_real),
4306 GFP_KERNEL);
4307 if (!me->hor_prod.even_real)
4308 goto err;
4309
4310 me->hor_prod.even_imag = kvmalloc(grid->aligned_width *
4311 grid->aligned_height *
4312 sizeof(*me->hor_prod.even_imag),
4313 GFP_KERNEL);
4314 if (!me->hor_prod.even_imag)
4315 goto err;
4316
4317 me->ver_prod.odd_real = kvmalloc(grid->aligned_width *
4318 grid->aligned_height *
4319 sizeof(*me->ver_prod.odd_real),
4320 GFP_KERNEL);
4321 if (!me->ver_prod.odd_real)
4322 goto err;
4323
4324 me->ver_prod.odd_imag = kvmalloc(grid->aligned_width *
4325 grid->aligned_height *
4326 sizeof(*me->ver_prod.odd_imag),
4327 GFP_KERNEL);
4328 if (!me->ver_prod.odd_imag)
4329 goto err;
4330
4331 me->ver_prod.even_real = kvmalloc(grid->aligned_width *
4332 grid->aligned_height *
4333 sizeof(*me->ver_prod.even_real),
4334 GFP_KERNEL);
4335 if (!me->ver_prod.even_real)
4336 goto err;
4337
4338 me->ver_prod.even_imag = kvmalloc(grid->aligned_width *
4339 grid->aligned_height *
4340 sizeof(*me->ver_prod.even_imag),
4341 GFP_KERNEL);
4342 if (!me->ver_prod.even_imag)
4343 goto err;
4344
4345 return me;
4346 err:
4347 ia_css_dvs2_statistics_free(me);
4348 return NULL;
4349 }
4350
4351 void
ia_css_dvs2_statistics_free(struct ia_css_dvs2_statistics * me)4352 ia_css_dvs2_statistics_free(struct ia_css_dvs2_statistics *me)
4353 {
4354 if (me) {
4355 kvfree(me->hor_prod.odd_real);
4356 kvfree(me->hor_prod.odd_imag);
4357 kvfree(me->hor_prod.even_real);
4358 kvfree(me->hor_prod.even_imag);
4359 kvfree(me->ver_prod.odd_real);
4360 kvfree(me->ver_prod.odd_imag);
4361 kvfree(me->ver_prod.even_real);
4362 kvfree(me->ver_prod.even_imag);
4363 kvfree(me);
4364 }
4365 }
4366
4367 struct ia_css_dvs2_coefficients *
ia_css_dvs2_coefficients_allocate(const struct ia_css_dvs_grid_info * grid)4368 ia_css_dvs2_coefficients_allocate(const struct ia_css_dvs_grid_info *grid)
4369 {
4370 struct ia_css_dvs2_coefficients *me;
4371
4372 assert(grid);
4373
4374 me = kvcalloc(1, sizeof(*me), GFP_KERNEL);
4375 if (!me)
4376 goto err;
4377
4378 me->grid = *grid;
4379
4380 me->hor_coefs.odd_real = kvmalloc(grid->num_hor_coefs *
4381 sizeof(*me->hor_coefs.odd_real),
4382 GFP_KERNEL);
4383 if (!me->hor_coefs.odd_real)
4384 goto err;
4385
4386 me->hor_coefs.odd_imag = kvmalloc(grid->num_hor_coefs *
4387 sizeof(*me->hor_coefs.odd_imag),
4388 GFP_KERNEL);
4389 if (!me->hor_coefs.odd_imag)
4390 goto err;
4391
4392 me->hor_coefs.even_real = kvmalloc(grid->num_hor_coefs *
4393 sizeof(*me->hor_coefs.even_real),
4394 GFP_KERNEL);
4395 if (!me->hor_coefs.even_real)
4396 goto err;
4397
4398 me->hor_coefs.even_imag = kvmalloc(grid->num_hor_coefs *
4399 sizeof(*me->hor_coefs.even_imag),
4400 GFP_KERNEL);
4401 if (!me->hor_coefs.even_imag)
4402 goto err;
4403
4404 me->ver_coefs.odd_real = kvmalloc(grid->num_ver_coefs *
4405 sizeof(*me->ver_coefs.odd_real),
4406 GFP_KERNEL);
4407 if (!me->ver_coefs.odd_real)
4408 goto err;
4409
4410 me->ver_coefs.odd_imag = kvmalloc(grid->num_ver_coefs *
4411 sizeof(*me->ver_coefs.odd_imag),
4412 GFP_KERNEL);
4413 if (!me->ver_coefs.odd_imag)
4414 goto err;
4415
4416 me->ver_coefs.even_real = kvmalloc(grid->num_ver_coefs *
4417 sizeof(*me->ver_coefs.even_real),
4418 GFP_KERNEL);
4419 if (!me->ver_coefs.even_real)
4420 goto err;
4421
4422 me->ver_coefs.even_imag = kvmalloc(grid->num_ver_coefs *
4423 sizeof(*me->ver_coefs.even_imag),
4424 GFP_KERNEL);
4425 if (!me->ver_coefs.even_imag)
4426 goto err;
4427
4428 return me;
4429 err:
4430 ia_css_dvs2_coefficients_free(me);
4431 return NULL;
4432 }
4433
4434 void
ia_css_dvs2_coefficients_free(struct ia_css_dvs2_coefficients * me)4435 ia_css_dvs2_coefficients_free(struct ia_css_dvs2_coefficients *me)
4436 {
4437 if (me) {
4438 kvfree(me->hor_coefs.odd_real);
4439 kvfree(me->hor_coefs.odd_imag);
4440 kvfree(me->hor_coefs.even_real);
4441 kvfree(me->hor_coefs.even_imag);
4442 kvfree(me->ver_coefs.odd_real);
4443 kvfree(me->ver_coefs.odd_imag);
4444 kvfree(me->ver_coefs.even_real);
4445 kvfree(me->ver_coefs.even_imag);
4446 kvfree(me);
4447 }
4448 }
4449
4450 struct ia_css_dvs_6axis_config *
ia_css_dvs2_6axis_config_allocate(const struct ia_css_stream * stream)4451 ia_css_dvs2_6axis_config_allocate(const struct ia_css_stream *stream)
4452 {
4453 struct ia_css_dvs_6axis_config *dvs_config = NULL;
4454 struct ia_css_isp_parameters *params = NULL;
4455 unsigned int width_y;
4456 unsigned int height_y;
4457 unsigned int width_uv;
4458 unsigned int height_uv;
4459
4460 assert(stream);
4461 params = stream->isp_params_configs;
4462
4463 /* Backward compatibility by default consider pipe as Video*/
4464 if (!params || !params->pipe_dvs_6axis_config[IA_CSS_PIPE_ID_VIDEO])
4465 goto err;
4466
4467 dvs_config = kvcalloc(1, sizeof(struct ia_css_dvs_6axis_config),
4468 GFP_KERNEL);
4469 if (!dvs_config)
4470 goto err;
4471
4472 dvs_config->width_y = width_y =
4473 params->pipe_dvs_6axis_config[IA_CSS_PIPE_ID_VIDEO]->width_y;
4474 dvs_config->height_y = height_y =
4475 params->pipe_dvs_6axis_config[IA_CSS_PIPE_ID_VIDEO]->height_y;
4476 dvs_config->width_uv = width_uv =
4477 params->pipe_dvs_6axis_config[IA_CSS_PIPE_ID_VIDEO]->width_uv;
4478 dvs_config->height_uv = height_uv =
4479 params->pipe_dvs_6axis_config[IA_CSS_PIPE_ID_VIDEO]->height_uv;
4480 IA_CSS_LOG("table Y: W %d H %d", width_y, height_y);
4481 IA_CSS_LOG("table UV: W %d H %d", width_uv, height_uv);
4482 dvs_config->xcoords_y = kvmalloc(width_y * height_y * sizeof(uint32_t),
4483 GFP_KERNEL);
4484 if (!dvs_config->xcoords_y)
4485 goto err;
4486
4487 dvs_config->ycoords_y = kvmalloc(width_y * height_y * sizeof(uint32_t),
4488 GFP_KERNEL);
4489 if (!dvs_config->ycoords_y)
4490 goto err;
4491
4492 dvs_config->xcoords_uv = kvmalloc(width_uv * height_uv *
4493 sizeof(uint32_t),
4494 GFP_KERNEL);
4495 if (!dvs_config->xcoords_uv)
4496 goto err;
4497
4498 dvs_config->ycoords_uv = kvmalloc(width_uv * height_uv *
4499 sizeof(uint32_t),
4500 GFP_KERNEL);
4501 if (!dvs_config->ycoords_uv)
4502 goto err;
4503
4504 return dvs_config;
4505 err:
4506 ia_css_dvs2_6axis_config_free(dvs_config);
4507 return NULL;
4508 }
4509
4510 void
ia_css_dvs2_6axis_config_free(struct ia_css_dvs_6axis_config * dvs_6axis_config)4511 ia_css_dvs2_6axis_config_free(struct ia_css_dvs_6axis_config *dvs_6axis_config)
4512 {
4513 if (dvs_6axis_config) {
4514 kvfree(dvs_6axis_config->xcoords_y);
4515 kvfree(dvs_6axis_config->ycoords_y);
4516 kvfree(dvs_6axis_config->xcoords_uv);
4517 kvfree(dvs_6axis_config->ycoords_uv);
4518 kvfree(dvs_6axis_config);
4519 }
4520 }
4521
4522 void
ia_css_en_dz_capt_pipe(struct ia_css_stream * stream,bool enable)4523 ia_css_en_dz_capt_pipe(struct ia_css_stream *stream, bool enable)
4524 {
4525 struct ia_css_pipe *pipe;
4526 struct ia_css_pipeline *pipeline;
4527 struct ia_css_pipeline_stage *stage;
4528 enum ia_css_pipe_id pipe_id;
4529 int err;
4530 int i;
4531
4532 if (!stream)
4533 return;
4534
4535 for (i = 0; i < stream->num_pipes; i++) {
4536 pipe = stream->pipes[i];
4537 pipeline = ia_css_pipe_get_pipeline(pipe);
4538 pipe_id = pipeline->pipe_id;
4539
4540 if (pipe_id == IA_CSS_PIPE_ID_CAPTURE) {
4541 err = ia_css_pipeline_get_stage(pipeline, IA_CSS_BINARY_MODE_CAPTURE_PP,
4542 &stage);
4543 if (!err)
4544 stage->enable_zoom = enable;
4545 break;
4546 }
4547 }
4548 }
4549