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 "debug.h"
8 
9 #ifndef __INLINE_INPUT_SYSTEM__
10 #define __INLINE_INPUT_SYSTEM__
11 #endif
12 #ifndef __INLINE_IBUF_CTRL__
13 #define __INLINE_IBUF_CTRL__
14 #endif
15 #ifndef __INLINE_CSI_RX__
16 #define __INLINE_CSI_RX__
17 #endif
18 #ifndef __INLINE_PIXELGEN__
19 #define __INLINE_PIXELGEN__
20 #endif
21 #ifndef __INLINE_STREAM2MMIO__
22 #define __INLINE_STREAM2MMIO__
23 #endif
24 
25 #include <linux/args.h>
26 #include <linux/string.h> /* for strscpy() */
27 
28 #include "ia_css_debug.h"
29 #include "ia_css_debug_pipe.h"
30 #include "ia_css_irq.h"
31 #include "ia_css_stream.h"
32 #include "ia_css_pipeline.h"
33 #include "ia_css_isp_param.h"
34 #include "sh_css_params.h"
35 #include "ia_css_bufq.h"
36 /* ISP2401 */
37 #include "ia_css_queue.h"
38 
39 #include "ia_css_isp_params.h"
40 
41 #include "system_local.h"
42 #include "assert_support.h"
43 #include "print_support.h"
44 
45 #include "fifo_monitor.h"
46 
47 #include "input_formatter.h"
48 #include "dma.h"
49 #include "irq.h"
50 #include "gp_device.h"
51 #include "sp.h"
52 #include "isp.h"
53 #include "type_support.h"
54 #include "math_support.h" /* CEIL_DIV */
55 #include "input_system.h"	/* input_formatter_reg_load */
56 #include "ia_css_tagger_common.h"
57 
58 #include "sh_css_internal.h"
59 #include "ia_css_isys.h"
60 #include "sh_css_sp.h"		/* sh_css_sp_get_debug_state() */
61 
62 #include "css_trace.h"      /* tracer */
63 
64 #include "device_access.h"	/* for ia_css_device_load_uint32 */
65 
66 /* Include all kernel host interfaces for ISP1 */
67 #include "anr/anr_1.0/ia_css_anr.host.h"
68 #include "cnr/cnr_1.0/ia_css_cnr.host.h"
69 #include "csc/csc_1.0/ia_css_csc.host.h"
70 #include "de/de_1.0/ia_css_de.host.h"
71 #include "dp/dp_1.0/ia_css_dp.host.h"
72 #include "bnr/bnr_1.0/ia_css_bnr.host.h"
73 #include "fpn/fpn_1.0/ia_css_fpn.host.h"
74 #include "gc/gc_1.0/ia_css_gc.host.h"
75 #include "ob/ob_1.0/ia_css_ob.host.h"
76 #include "s3a/s3a_1.0/ia_css_s3a.host.h"
77 #include "sc/sc_1.0/ia_css_sc.host.h"
78 #include "tnr/tnr_1.0/ia_css_tnr.host.h"
79 #include "uds/uds_1.0/ia_css_uds_param.h"
80 #include "wb/wb_1.0/ia_css_wb.host.h"
81 #include "ynr/ynr_1.0/ia_css_ynr.host.h"
82 
83 /* Include additional kernel host interfaces for ISP2 */
84 #include "aa/aa_2/ia_css_aa2.host.h"
85 #include "anr/anr_2/ia_css_anr2.host.h"
86 #include "cnr/cnr_2/ia_css_cnr2.host.h"
87 #include "de/de_2/ia_css_de2.host.h"
88 #include "gc/gc_2/ia_css_gc2.host.h"
89 #include "ynr/ynr_2/ia_css_ynr2.host.h"
90 
91 #define DPG_START "ia_css_debug_pipe_graph_dump_start "
92 #define DPG_END   " ia_css_debug_pipe_graph_dump_end\n"
93 
94 #define ENABLE_LINE_MAX_LENGTH (25)
95 
96 static struct pipe_graph_class {
97 	bool do_init;
98 	int height;
99 	int width;
100 	int eff_height;
101 	int eff_width;
102 	enum atomisp_input_format stream_format;
103 } pg_inst = {true, 0, 0, 0, 0, N_ATOMISP_INPUT_FORMAT};
104 
105 static const char *const queue_id_to_str[] = {
106 	/* [SH_CSS_QUEUE_A_ID]     =*/ "queue_A",
107 	/* [SH_CSS_QUEUE_B_ID]     =*/ "queue_B",
108 	/* [SH_CSS_QUEUE_C_ID]     =*/ "queue_C",
109 	/* [SH_CSS_QUEUE_D_ID]     =*/ "queue_D",
110 	/* [SH_CSS_QUEUE_E_ID]     =*/ "queue_E",
111 	/* [SH_CSS_QUEUE_F_ID]     =*/ "queue_F",
112 	/* [SH_CSS_QUEUE_G_ID]     =*/ "queue_G",
113 	/* [SH_CSS_QUEUE_H_ID]     =*/ "queue_H"
114 };
115 
116 static const char *const pipe_id_to_str[] = {
117 	/* [IA_CSS_PIPE_ID_PREVIEW]   =*/ "preview",
118 	/* [IA_CSS_PIPE_ID_COPY]      =*/ "copy",
119 	/* [IA_CSS_PIPE_ID_VIDEO]     =*/ "video",
120 	/* [IA_CSS_PIPE_ID_CAPTURE]   =*/ "capture",
121 	/* [IA_CSS_PIPE_ID_YUVPP]     =*/ "yuvpp",
122 };
123 
124 static char dot_id_input_bin[SH_CSS_MAX_BINARY_NAME + 10];
125 static char ring_buffer[200];
126 
ia_css_debug_dtrace(unsigned int level,const char * fmt,...)127 void ia_css_debug_dtrace(unsigned int level, const char *fmt, ...)
128 {
129 	va_list ap;
130 
131 	va_start(ap, fmt);
132 	ia_css_debug_vdtrace(level, fmt, ap);
133 	va_end(ap);
134 }
135 
ia_css_debug_set_dtrace_level(const unsigned int trace_level)136 void ia_css_debug_set_dtrace_level(const unsigned int trace_level)
137 {
138 	dbg_level = trace_level;
139 	return;
140 }
141 
ia_css_debug_get_dtrace_level(void)142 unsigned int ia_css_debug_get_dtrace_level(void)
143 {
144 	return dbg_level;
145 }
146 
debug_stream_format2str(const enum atomisp_input_format stream_format)147 static const char *debug_stream_format2str(const enum atomisp_input_format
148 	stream_format)
149 {
150 	switch (stream_format) {
151 	case ATOMISP_INPUT_FORMAT_YUV420_8_LEGACY:
152 		return "yuv420-8-legacy";
153 	case ATOMISP_INPUT_FORMAT_YUV420_8:
154 		return "yuv420-8";
155 	case ATOMISP_INPUT_FORMAT_YUV420_10:
156 		return "yuv420-10";
157 	case ATOMISP_INPUT_FORMAT_YUV420_16:
158 		return "yuv420-16";
159 	case ATOMISP_INPUT_FORMAT_YUV422_8:
160 		return "yuv422-8";
161 	case ATOMISP_INPUT_FORMAT_YUV422_10:
162 		return "yuv422-10";
163 	case ATOMISP_INPUT_FORMAT_YUV422_16:
164 		return "yuv422-16";
165 	case ATOMISP_INPUT_FORMAT_RGB_444:
166 		return "rgb444";
167 	case ATOMISP_INPUT_FORMAT_RGB_555:
168 		return "rgb555";
169 	case ATOMISP_INPUT_FORMAT_RGB_565:
170 		return "rgb565";
171 	case ATOMISP_INPUT_FORMAT_RGB_666:
172 		return "rgb666";
173 	case ATOMISP_INPUT_FORMAT_RGB_888:
174 		return "rgb888";
175 	case ATOMISP_INPUT_FORMAT_RAW_6:
176 		return "raw6";
177 	case ATOMISP_INPUT_FORMAT_RAW_7:
178 		return "raw7";
179 	case ATOMISP_INPUT_FORMAT_RAW_8:
180 		return "raw8";
181 	case ATOMISP_INPUT_FORMAT_RAW_10:
182 		return "raw10";
183 	case ATOMISP_INPUT_FORMAT_RAW_12:
184 		return "raw12";
185 	case ATOMISP_INPUT_FORMAT_RAW_14:
186 		return "raw14";
187 	case ATOMISP_INPUT_FORMAT_RAW_16:
188 		return "raw16";
189 	case ATOMISP_INPUT_FORMAT_BINARY_8:
190 		return "binary8";
191 	case ATOMISP_INPUT_FORMAT_GENERIC_SHORT1:
192 		return "generic-short1";
193 	case ATOMISP_INPUT_FORMAT_GENERIC_SHORT2:
194 		return "generic-short2";
195 	case ATOMISP_INPUT_FORMAT_GENERIC_SHORT3:
196 		return "generic-short3";
197 	case ATOMISP_INPUT_FORMAT_GENERIC_SHORT4:
198 		return "generic-short4";
199 	case ATOMISP_INPUT_FORMAT_GENERIC_SHORT5:
200 		return "generic-short5";
201 	case ATOMISP_INPUT_FORMAT_GENERIC_SHORT6:
202 		return "generic-short6";
203 	case ATOMISP_INPUT_FORMAT_GENERIC_SHORT7:
204 		return "generic-short7";
205 	case ATOMISP_INPUT_FORMAT_GENERIC_SHORT8:
206 		return "generic-short8";
207 	case ATOMISP_INPUT_FORMAT_YUV420_8_SHIFT:
208 		return "yuv420-8-shift";
209 	case ATOMISP_INPUT_FORMAT_YUV420_10_SHIFT:
210 		return "yuv420-10-shift";
211 	case ATOMISP_INPUT_FORMAT_EMBEDDED:
212 		return "embedded-8";
213 	case ATOMISP_INPUT_FORMAT_USER_DEF1:
214 		return "user-def-8-type-1";
215 	case ATOMISP_INPUT_FORMAT_USER_DEF2:
216 		return "user-def-8-type-2";
217 	case ATOMISP_INPUT_FORMAT_USER_DEF3:
218 		return "user-def-8-type-3";
219 	case ATOMISP_INPUT_FORMAT_USER_DEF4:
220 		return "user-def-8-type-4";
221 	case ATOMISP_INPUT_FORMAT_USER_DEF5:
222 		return "user-def-8-type-5";
223 	case ATOMISP_INPUT_FORMAT_USER_DEF6:
224 		return "user-def-8-type-6";
225 	case ATOMISP_INPUT_FORMAT_USER_DEF7:
226 		return "user-def-8-type-7";
227 	case ATOMISP_INPUT_FORMAT_USER_DEF8:
228 		return "user-def-8-type-8";
229 
230 	default:
231 		assert(!"Unknown stream format");
232 		return "unknown-stream-format";
233 	}
234 };
235 
debug_frame_format2str(const enum ia_css_frame_format frame_format)236 static const char *debug_frame_format2str(const enum ia_css_frame_format
237 	frame_format)
238 {
239 	switch (frame_format) {
240 	case IA_CSS_FRAME_FORMAT_NV11:
241 		return "NV11";
242 	case IA_CSS_FRAME_FORMAT_NV12:
243 		return "NV12";
244 	case IA_CSS_FRAME_FORMAT_NV12_16:
245 		return "NV12_16";
246 	case IA_CSS_FRAME_FORMAT_NV12_TILEY:
247 		return "NV12_TILEY";
248 	case IA_CSS_FRAME_FORMAT_NV16:
249 		return "NV16";
250 	case IA_CSS_FRAME_FORMAT_NV21:
251 		return "NV21";
252 	case IA_CSS_FRAME_FORMAT_NV61:
253 		return "NV61";
254 	case IA_CSS_FRAME_FORMAT_YV12:
255 		return "YV12";
256 	case IA_CSS_FRAME_FORMAT_YV16:
257 		return "YV16";
258 	case IA_CSS_FRAME_FORMAT_YUV420:
259 		return "YUV420";
260 	case IA_CSS_FRAME_FORMAT_YUV420_16:
261 		return "YUV420_16";
262 	case IA_CSS_FRAME_FORMAT_YUV422:
263 		return "YUV422";
264 	case IA_CSS_FRAME_FORMAT_YUV422_16:
265 		return "YUV422_16";
266 	case IA_CSS_FRAME_FORMAT_UYVY:
267 		return "UYVY";
268 	case IA_CSS_FRAME_FORMAT_YUYV:
269 		return "YUYV";
270 	case IA_CSS_FRAME_FORMAT_YUV444:
271 		return "YUV444";
272 	case IA_CSS_FRAME_FORMAT_YUV_LINE:
273 		return "YUV_LINE";
274 	case IA_CSS_FRAME_FORMAT_RAW:
275 		return "RAW";
276 	case IA_CSS_FRAME_FORMAT_RGB565:
277 		return "RGB565";
278 	case IA_CSS_FRAME_FORMAT_PLANAR_RGB888:
279 		return "PLANAR_RGB888";
280 	case IA_CSS_FRAME_FORMAT_RGBA888:
281 		return "RGBA888";
282 	case IA_CSS_FRAME_FORMAT_QPLANE6:
283 		return "QPLANE6";
284 	case IA_CSS_FRAME_FORMAT_BINARY_8:
285 		return "BINARY_8";
286 	case IA_CSS_FRAME_FORMAT_MIPI:
287 		return "MIPI";
288 	case IA_CSS_FRAME_FORMAT_RAW_PACKED:
289 		return "RAW_PACKED";
290 	case IA_CSS_FRAME_FORMAT_CSI_MIPI_YUV420_8:
291 		return "CSI_MIPI_YUV420_8";
292 	case IA_CSS_FRAME_FORMAT_CSI_MIPI_LEGACY_YUV420_8:
293 		return "CSI_MIPI_LEGACY_YUV420_8";
294 	case IA_CSS_FRAME_FORMAT_CSI_MIPI_YUV420_10:
295 		return "CSI_MIPI_YUV420_10";
296 
297 	default:
298 		assert(!"Unknown frame format");
299 		return "unknown-frame-format";
300 	}
301 }
302 
debug_print_fifo_channel_state(const fifo_channel_state_t * state,const char * descr)303 static void debug_print_fifo_channel_state(const fifo_channel_state_t *state,
304 	const char *descr)
305 {
306 	assert(state);
307 	assert(descr);
308 
309 	ia_css_debug_dtrace(2, "FIFO channel: %s\n", descr);
310 	ia_css_debug_dtrace(2, "\t%-32s: %d\n", "source valid",
311 			    state->src_valid);
312 	ia_css_debug_dtrace(2, "\t%-32s: %d\n", "fifo accept",
313 			    state->fifo_accept);
314 	ia_css_debug_dtrace(2, "\t%-32s: %d\n", "fifo valid",
315 			    state->fifo_valid);
316 	ia_css_debug_dtrace(2, "\t%-32s: %d\n", "sink accept",
317 			    state->sink_accept);
318 	return;
319 }
320 
ia_css_debug_dump_pif_a_isp_fifo_state(void)321 void ia_css_debug_dump_pif_a_isp_fifo_state(void)
322 {
323 	fifo_channel_state_t pif_to_isp, isp_to_pif;
324 
325 	fifo_channel_get_state(FIFO_MONITOR0_ID,
326 			       FIFO_CHANNEL_IF0_TO_ISP0, &pif_to_isp);
327 	fifo_channel_get_state(FIFO_MONITOR0_ID,
328 			       FIFO_CHANNEL_ISP0_TO_IF0, &isp_to_pif);
329 	debug_print_fifo_channel_state(&pif_to_isp, "Primary IF A to ISP");
330 	debug_print_fifo_channel_state(&isp_to_pif, "ISP to Primary IF A");
331 }
332 
ia_css_debug_dump_pif_b_isp_fifo_state(void)333 void ia_css_debug_dump_pif_b_isp_fifo_state(void)
334 {
335 	fifo_channel_state_t pif_to_isp, isp_to_pif;
336 
337 	fifo_channel_get_state(FIFO_MONITOR0_ID,
338 			       FIFO_CHANNEL_IF1_TO_ISP0, &pif_to_isp);
339 	fifo_channel_get_state(FIFO_MONITOR0_ID,
340 			       FIFO_CHANNEL_ISP0_TO_IF1, &isp_to_pif);
341 	debug_print_fifo_channel_state(&pif_to_isp, "Primary IF B to ISP");
342 	debug_print_fifo_channel_state(&isp_to_pif, "ISP to Primary IF B");
343 }
344 
ia_css_debug_dump_str2mem_sp_fifo_state(void)345 void ia_css_debug_dump_str2mem_sp_fifo_state(void)
346 {
347 	fifo_channel_state_t s2m_to_sp, sp_to_s2m;
348 
349 	fifo_channel_get_state(FIFO_MONITOR0_ID,
350 			       FIFO_CHANNEL_STREAM2MEM0_TO_SP0, &s2m_to_sp);
351 	fifo_channel_get_state(FIFO_MONITOR0_ID,
352 			       FIFO_CHANNEL_SP0_TO_STREAM2MEM0, &sp_to_s2m);
353 	debug_print_fifo_channel_state(&s2m_to_sp, "Stream-to-memory to SP");
354 	debug_print_fifo_channel_state(&sp_to_s2m, "SP to stream-to-memory");
355 }
356 
ia_css_debug_dump_all_fifo_state(void)357 void ia_css_debug_dump_all_fifo_state(void)
358 {
359 	int i;
360 	fifo_monitor_state_t state;
361 
362 	fifo_monitor_get_state(FIFO_MONITOR0_ID, &state);
363 
364 	for (i = 0; i < N_FIFO_CHANNEL; i++)
365 		debug_print_fifo_channel_state(&state.fifo_channels[i],
366 					       "squepfstqkt");
367 	return;
368 }
369 
debug_binary_info_print(const struct ia_css_binary_xinfo * info)370 static void debug_binary_info_print(const struct ia_css_binary_xinfo *info)
371 {
372 	assert(info);
373 	ia_css_debug_dtrace(2, "id = %d\n", info->sp.id);
374 	ia_css_debug_dtrace(2, "mode = %d\n", info->sp.pipeline.mode);
375 	ia_css_debug_dtrace(2, "max_input_width = %d\n", info->sp.input.max_width);
376 	ia_css_debug_dtrace(2, "min_output_width = %d\n",
377 			    info->sp.output.min_width);
378 	ia_css_debug_dtrace(2, "max_output_width = %d\n",
379 			    info->sp.output.max_width);
380 	ia_css_debug_dtrace(2, "top_cropping = %d\n", info->sp.pipeline.top_cropping);
381 	ia_css_debug_dtrace(2, "left_cropping = %d\n", info->sp.pipeline.left_cropping);
382 	ia_css_debug_dtrace(2, "xmem_addr = %d\n", info->xmem_addr);
383 	ia_css_debug_dtrace(2, "enable_vf_veceven = %d\n",
384 			    info->sp.enable.vf_veceven);
385 	ia_css_debug_dtrace(2, "enable_dis = %d\n", info->sp.enable.dis);
386 	ia_css_debug_dtrace(2, "enable_uds = %d\n", info->sp.enable.uds);
387 	ia_css_debug_dtrace(2, "enable ds = %d\n", info->sp.enable.ds);
388 	ia_css_debug_dtrace(2, "s3atbl_use_dmem = %d\n", info->sp.s3a.s3atbl_use_dmem);
389 	return;
390 }
391 
ia_css_debug_binary_print(const struct ia_css_binary * bi)392 void ia_css_debug_binary_print(const struct ia_css_binary *bi)
393 {
394 	unsigned int i;
395 
396 	debug_binary_info_print(bi->info);
397 	ia_css_debug_dtrace(2,
398 			    "input:  %dx%d, format = %d, padded width = %d\n",
399 			    bi->in_frame_info.res.width,
400 			    bi->in_frame_info.res.height,
401 			    bi->in_frame_info.format,
402 			    bi->in_frame_info.padded_width);
403 	ia_css_debug_dtrace(2,
404 			    "internal :%dx%d, format = %d, padded width = %d\n",
405 			    bi->internal_frame_info.res.width,
406 			    bi->internal_frame_info.res.height,
407 			    bi->internal_frame_info.format,
408 			    bi->internal_frame_info.padded_width);
409 	for (i = 0; i < IA_CSS_BINARY_MAX_OUTPUT_PORTS; i++) {
410 		if (bi->out_frame_info[i].res.width != 0) {
411 			ia_css_debug_dtrace(2,
412 					    "out%d:    %dx%d, format = %d, padded width = %d\n",
413 					    i,
414 					    bi->out_frame_info[i].res.width,
415 					    bi->out_frame_info[i].res.height,
416 					    bi->out_frame_info[i].format,
417 					    bi->out_frame_info[i].padded_width);
418 		}
419 	}
420 	ia_css_debug_dtrace(2,
421 			    "vf out: %dx%d, format = %d, padded width = %d\n",
422 			    bi->vf_frame_info.res.width,
423 			    bi->vf_frame_info.res.height,
424 			    bi->vf_frame_info.format,
425 			    bi->vf_frame_info.padded_width);
426 	ia_css_debug_dtrace(2, "online = %d\n", bi->online);
427 	ia_css_debug_dtrace(2, "input_buf_vectors = %d\n",
428 			    bi->input_buf_vectors);
429 	ia_css_debug_dtrace(2, "deci_factor_log2 = %d\n", bi->deci_factor_log2);
430 	ia_css_debug_dtrace(2, "vf_downscale_log2 = %d\n",
431 			    bi->vf_downscale_log2);
432 	ia_css_debug_dtrace(2, "dis_deci_factor_log2 = %d\n",
433 			    bi->dis.deci_factor_log2);
434 	ia_css_debug_dtrace(2, "dis hor coef num = %d\n",
435 			    bi->dis.coef.pad.width);
436 	ia_css_debug_dtrace(2, "dis ver coef num = %d\n",
437 			    bi->dis.coef.pad.height);
438 	ia_css_debug_dtrace(2, "dis hor proj num = %d\n",
439 			    bi->dis.proj.pad.height);
440 	ia_css_debug_dtrace(2, "sctbl_width_per_color = %d\n",
441 			    bi->sctbl_width_per_color);
442 	ia_css_debug_dtrace(2, "s3atbl_width = %d\n", bi->s3atbl_width);
443 	ia_css_debug_dtrace(2, "s3atbl_height = %d\n", bi->s3atbl_height);
444 	return;
445 }
446 
ia_css_debug_frame_print(const struct ia_css_frame * frame,const char * descr)447 void ia_css_debug_frame_print(const struct ia_css_frame *frame,
448 			      const char *descr)
449 {
450 	char *data = NULL;
451 
452 	assert(frame);
453 	assert(descr);
454 
455 	data = (char *)HOST_ADDRESS(frame->data);
456 	ia_css_debug_dtrace(2, "frame %s (%p):\n", descr, frame);
457 	ia_css_debug_dtrace(2, "  resolution    = %dx%d\n",
458 			    frame->frame_info.res.width, frame->frame_info.res.height);
459 	ia_css_debug_dtrace(2, "  padded width  = %d\n",
460 			    frame->frame_info.padded_width);
461 	ia_css_debug_dtrace(2, "  format        = %d\n", frame->frame_info.format);
462 	switch (frame->frame_info.format) {
463 	case IA_CSS_FRAME_FORMAT_NV12:
464 	case IA_CSS_FRAME_FORMAT_NV16:
465 	case IA_CSS_FRAME_FORMAT_NV21:
466 	case IA_CSS_FRAME_FORMAT_NV61:
467 		ia_css_debug_dtrace(2, "  Y = %p\n",
468 				    data + frame->planes.nv.y.offset);
469 		ia_css_debug_dtrace(2, "  UV = %p\n",
470 				    data + frame->planes.nv.uv.offset);
471 		break;
472 	case IA_CSS_FRAME_FORMAT_YUYV:
473 	case IA_CSS_FRAME_FORMAT_UYVY:
474 	case IA_CSS_FRAME_FORMAT_CSI_MIPI_YUV420_8:
475 	case IA_CSS_FRAME_FORMAT_CSI_MIPI_LEGACY_YUV420_8:
476 	case IA_CSS_FRAME_FORMAT_YUV_LINE:
477 		ia_css_debug_dtrace(2, "  YUYV = %p\n",
478 				    data + frame->planes.yuyv.offset);
479 		break;
480 	case IA_CSS_FRAME_FORMAT_YUV420:
481 	case IA_CSS_FRAME_FORMAT_YUV422:
482 	case IA_CSS_FRAME_FORMAT_YUV444:
483 	case IA_CSS_FRAME_FORMAT_YV12:
484 	case IA_CSS_FRAME_FORMAT_YV16:
485 	case IA_CSS_FRAME_FORMAT_YUV420_16:
486 	case IA_CSS_FRAME_FORMAT_YUV422_16:
487 		ia_css_debug_dtrace(2, "  Y = %p\n",
488 				    data + frame->planes.yuv.y.offset);
489 		ia_css_debug_dtrace(2, "  U = %p\n",
490 				    data + frame->planes.yuv.u.offset);
491 		ia_css_debug_dtrace(2, "  V = %p\n",
492 				    data + frame->planes.yuv.v.offset);
493 		break;
494 	case IA_CSS_FRAME_FORMAT_RAW_PACKED:
495 		ia_css_debug_dtrace(2, "  RAW PACKED = %p\n",
496 				    data + frame->planes.raw.offset);
497 		break;
498 	case IA_CSS_FRAME_FORMAT_RAW:
499 		ia_css_debug_dtrace(2, "  RAW = %p\n",
500 				    data + frame->planes.raw.offset);
501 		break;
502 	case IA_CSS_FRAME_FORMAT_RGBA888:
503 	case IA_CSS_FRAME_FORMAT_RGB565:
504 		ia_css_debug_dtrace(2, "  RGB = %p\n",
505 				    data + frame->planes.rgb.offset);
506 		break;
507 	case IA_CSS_FRAME_FORMAT_QPLANE6:
508 		ia_css_debug_dtrace(2, "  R    = %p\n",
509 				    data + frame->planes.plane6.r.offset);
510 		ia_css_debug_dtrace(2, "  RatB = %p\n",
511 				    data + frame->planes.plane6.r_at_b.offset);
512 		ia_css_debug_dtrace(2, "  Gr   = %p\n",
513 				    data + frame->planes.plane6.gr.offset);
514 		ia_css_debug_dtrace(2, "  Gb   = %p\n",
515 				    data + frame->planes.plane6.gb.offset);
516 		ia_css_debug_dtrace(2, "  B    = %p\n",
517 				    data + frame->planes.plane6.b.offset);
518 		ia_css_debug_dtrace(2, "  BatR = %p\n",
519 				    data + frame->planes.plane6.b_at_r.offset);
520 		break;
521 	case IA_CSS_FRAME_FORMAT_BINARY_8:
522 		ia_css_debug_dtrace(2, "  Binary data = %p\n",
523 				    data + frame->planes.binary.data.offset);
524 		break;
525 	default:
526 		ia_css_debug_dtrace(2, "  unknown frame type\n");
527 		break;
528 	}
529 	return;
530 }
531 
532 #if SP_DEBUG != SP_DEBUG_NONE
533 
ia_css_debug_print_sp_debug_state(const struct sh_css_sp_debug_state * state)534 void ia_css_debug_print_sp_debug_state(const struct sh_css_sp_debug_state
535 				       *state)
536 {
537 #endif
538 
539 #if SP_DEBUG == SP_DEBUG_DUMP
540 
541 	assert(state);
542 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE,
543 			    "current SP software counter: %d\n",
544 			    state->debug[0]);
545 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE,
546 			    "empty output buffer queue head: 0x%x\n",
547 			    state->debug[1]);
548 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE,
549 			    "empty output buffer queue tail: 0x%x\n",
550 			    state->debug[2]);
551 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE,
552 			    "empty s3a buffer queue head: 0x%x\n",
553 			    state->debug[3]);
554 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE,
555 			    "empty s3a buffer queue tail: 0x%x\n",
556 			    state->debug[4]);
557 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE,
558 			    "full output buffer queue head: 0x%x\n",
559 			    state->debug[5]);
560 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE,
561 			    "full output buffer queue tail: 0x%x\n",
562 			    state->debug[6]);
563 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE,
564 			    "full s3a buffer queue head: 0x%x\n",
565 			    state->debug[7]);
566 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE,
567 			    "full s3a buffer queue tail: 0x%x\n",
568 			    state->debug[8]);
569 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE, "event queue head: 0x%x\n",
570 			    state->debug[9]);
571 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE, "event queue tail: 0x%x\n",
572 			    state->debug[10]);
573 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE,
574 			    "num of stages of current pipeline: 0x%x\n",
575 			    state->debug[11]);
576 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE, "DDR address of stage 1: 0x%x\n",
577 			    state->debug[12]);
578 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE, "DDR address of stage 2: 0x%x\n",
579 			    state->debug[13]);
580 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE,
581 			    "current stage out_vf buffer idx: 0x%x\n",
582 			    state->debug[14]);
583 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE,
584 			    "current stage output buffer idx: 0x%x\n",
585 			    state->debug[15]);
586 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE,
587 			    "current stage s3a buffer idx: 0x%x\n",
588 			    state->debug[16]);
589 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE,
590 			    "first char of current stage name: 0x%x\n",
591 			    state->debug[17]);
592 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE, "current SP thread id: 0x%x\n",
593 			    state->debug[18]);
594 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE,
595 			    "empty output buffer address 1: 0x%x\n",
596 			    state->debug[19]);
597 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE,
598 			    "empty output buffer address 2: 0x%x\n",
599 			    state->debug[20]);
600 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE,
601 			    "empty out_vf buffer address 1: 0x%x\n",
602 			    state->debug[21]);
603 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE,
604 			    "empty out_vf buffer address 2: 0x%x\n",
605 			    state->debug[22]);
606 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE,
607 			    "empty s3a_hi buffer address 1: 0x%x\n",
608 			    state->debug[23]);
609 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE,
610 			    "empty s3a_hi buffer address 2: 0x%x\n",
611 			    state->debug[24]);
612 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE,
613 			    "empty s3a_lo buffer address 1: 0x%x\n",
614 			    state->debug[25]);
615 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE,
616 			    "empty s3a_lo buffer address 2: 0x%x\n",
617 			    state->debug[26]);
618 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE,
619 			    "empty dis_hor buffer address 1: 0x%x\n",
620 			    state->debug[27]);
621 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE,
622 			    "empty dis_hor buffer address 2: 0x%x\n",
623 			    state->debug[28]);
624 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE,
625 			    "empty dis_ver buffer address 1: 0x%x\n",
626 			    state->debug[29]);
627 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE,
628 			    "empty dis_ver buffer address 2: 0x%x\n",
629 			    state->debug[30]);
630 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE,
631 			    "empty param buffer address: 0x%x\n",
632 			    state->debug[31]);
633 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE,
634 			    "first incorrect frame address: 0x%x\n",
635 			    state->debug[32]);
636 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE,
637 			    "first incorrect frame container address: 0x%x\n",
638 			    state->debug[33]);
639 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE,
640 			    "first incorrect frame container payload: 0x%x\n",
641 			    state->debug[34]);
642 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE,
643 			    "first incorrect s3a_hi address: 0x%x\n",
644 			    state->debug[35]);
645 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE,
646 			    "first incorrect s3a_hi container address: 0x%x\n",
647 			    state->debug[36]);
648 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE,
649 			    "first incorrect s3a_hi container payload: 0x%x\n",
650 			    state->debug[37]);
651 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE,
652 			    "first incorrect s3a_lo address: 0x%x\n",
653 			    state->debug[38]);
654 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE,
655 			    "first incorrect s3a_lo container address: 0x%x\n",
656 			    state->debug[39]);
657 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE,
658 			    "first incorrect s3a_lo container payload: 0x%x\n",
659 			    state->debug[40]);
660 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE,
661 			    "number of calling flash start function: 0x%x\n",
662 			    state->debug[41]);
663 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE,
664 			    "number of calling flash close function: 0x%x\n",
665 			    state->debug[42]);
666 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE, "number of flashed frame: 0x%x\n",
667 			    state->debug[43]);
668 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE, "flash in use flag: 0x%x\n",
669 			    state->debug[44]);
670 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE,
671 			    "number of update frame flashed flag: 0x%x\n",
672 			    state->debug[46]);
673 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE,
674 			    "number of active threads: 0x%x\n",
675 			    state->debug[45]);
676 
677 #elif SP_DEBUG == SP_DEBUG_COPY
678 
679 	/* Remember last_index because we only want to print new entries */
680 	static int last_index;
681 	int sp_index = state->index;
682 	int n;
683 
684 	assert(state);
685 	if (sp_index < last_index) {
686 		/* SP has been reset */
687 		last_index = 0;
688 	}
689 
690 	if (last_index == 0) {
691 		ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE,
692 				    "copy-trace init: sp_dbg_if_start_line=%d, sp_dbg_if_start_column=%d, sp_dbg_if_cropped_height=%d, sp_debg_if_cropped_width=%d\n",
693 				    state->if_start_line,
694 				    state->if_start_column,
695 				    state->if_cropped_height,
696 				    state->if_cropped_width);
697 	}
698 
699 	if ((last_index + SH_CSS_SP_DBG_TRACE_DEPTH) < sp_index) {
700 		/* last index can be multiple rounds behind */
701 		/* while trace size is only SH_CSS_SP_DBG_TRACE_DEPTH */
702 		last_index = sp_index - SH_CSS_SP_DBG_TRACE_DEPTH;
703 	}
704 
705 	for (n = last_index; n < sp_index; n++) {
706 		int i = n % SH_CSS_SP_DBG_TRACE_DEPTH;
707 
708 		if (state->trace[i].frame != 0) {
709 			ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE,
710 					    "copy-trace: frame=%d, line=%d, pixel_distance=%d, mipi_used_dword=%d, sp_index=%d\n",
711 					    state->trace[i].frame,
712 					    state->trace[i].line,
713 					    state->trace[i].pixel_distance,
714 					    state->trace[i].mipi_used_dword,
715 					    state->trace[i].sp_index);
716 		}
717 	}
718 
719 	last_index = sp_index;
720 
721 #elif SP_DEBUG == SP_DEBUG_TRACE
722 
723 	/*
724 	 * This is just an example how TRACE_FILE_ID (see ia_css_debug.sp.h) will
725 	 * me mapped on the file name string.
726 	 *
727 	 * Adjust this to your trace case!
728 	 */
729 	static char const *const id2filename[8] = {
730 		"param_buffer.sp.c | tagger.sp.c | pipe_data.sp.c",
731 		"isp_init.sp.c",
732 		"sp_raw_copy.hive.c",
733 		"dma_configure.sp.c",
734 		"sp.hive.c",
735 		"event_proxy_sp.hive.c",
736 		"circular_buffer.sp.c",
737 		"frame_buffer.sp.c"
738 	};
739 
740 	/* Example SH_CSS_SP_DBG_NR_OF_TRACES==1 */
741 	/* Adjust this to your trace case */
742 	static char const *trace_name[SH_CSS_SP_DBG_NR_OF_TRACES] = {
743 		"default"
744 	};
745 
746 	/* Remember host_index_last because we only want to print new entries */
747 	static int host_index_last[SH_CSS_SP_DBG_NR_OF_TRACES] = { 0 };
748 	int t, n;
749 
750 	assert(state);
751 
752 	for (t = 0; t < SH_CSS_SP_DBG_NR_OF_TRACES; t++) {
753 		int sp_index_last = state->index_last[t];
754 
755 		if (sp_index_last < host_index_last[t]) {
756 			/* SP has been reset */
757 			host_index_last[t] = 0;
758 		}
759 
760 		if ((host_index_last[t] + SH_CSS_SP_DBG_TRACE_DEPTH) <
761 		    sp_index_last) {
762 			/* last index can be multiple rounds behind */
763 			/* while trace size is only SH_CSS_SP_DBG_TRACE_DEPTH */
764 			ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE,
765 					    "Warning: trace %s has gap of %d traces\n",
766 					    trace_name[t],
767 					    (sp_index_last -
768 					     (host_index_last[t] +
769 					      SH_CSS_SP_DBG_TRACE_DEPTH)));
770 
771 			host_index_last[t] =
772 			    sp_index_last - SH_CSS_SP_DBG_TRACE_DEPTH;
773 		}
774 
775 		for (n = host_index_last[t]; n < sp_index_last; n++) {
776 			int i = n % SH_CSS_SP_DBG_TRACE_DEPTH;
777 			int l = state->trace[t][i].location &
778 				((1 << SH_CSS_SP_DBG_TRACE_FILE_ID_BIT_POS) - 1);
779 			int fid = state->trace[t][i].location >>
780 				  SH_CSS_SP_DBG_TRACE_FILE_ID_BIT_POS;
781 			int ts = state->trace[t][i].time_stamp;
782 
783 			if (ts) {
784 				ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE,
785 						    "%05d trace=%s, file=%s:%d, data=0x%08x\n",
786 						    ts,
787 						    trace_name[t],
788 						    id2filename[fid], l,
789 						    state->trace[t][i].data);
790 			}
791 		}
792 		host_index_last[t] = sp_index_last;
793 	}
794 
795 #elif SP_DEBUG == SP_DEBUG_MINIMAL
796 	int i;
797 	int base = 0;
798 	int limit = SH_CSS_NUM_SP_DEBUG;
799 	int step = 1;
800 
801 	assert(state);
802 
803 	for (i = base; i < limit; i += step) {
804 		ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE,
805 				    "sp_dbg_trace[%d] = %d\n",
806 				    i, state->debug[i]);
807 	}
808 #endif
809 
810 #if SP_DEBUG != SP_DEBUG_NONE
811 
812 	return;
813 }
814 #endif
815 
ia_css_debug_dump_sp_sw_debug_info(void)816 void ia_css_debug_dump_sp_sw_debug_info(void)
817 {
818 #if SP_DEBUG != SP_DEBUG_NONE
819 	struct sh_css_sp_debug_state state;
820 
821 	sh_css_sp_get_debug_state(&state);
822 	ia_css_debug_print_sp_debug_state(&state);
823 #endif
824 	ia_css_bufq_dump_queue_info();
825 	ia_css_pipeline_dump_thread_map_info();
826 	return;
827 }
828 
829 /* this function is for debug use, it can make SP go to sleep
830   state after each frame, then user can dump the stable SP dmem.
831   this function can be called after ia_css_start_sp()
832   and before sh_css_init_buffer_queues()
833 */
ia_css_debug_enable_sp_sleep_mode(enum ia_css_sp_sleep_mode mode)834 void ia_css_debug_enable_sp_sleep_mode(enum ia_css_sp_sleep_mode mode)
835 {
836 	const struct ia_css_fw_info *fw;
837 	unsigned int HIVE_ADDR_sp_sleep_mode;
838 
839 	fw = &sh_css_sp_fw;
840 	HIVE_ADDR_sp_sleep_mode = fw->info.sp.sleep_mode;
841 
842 	(void)HIVE_ADDR_sp_sleep_mode;	/* Suppress warnings in CRUN */
843 
844 	sp_dmem_store_uint32(SP0_ID,
845 			     (unsigned int)sp_address_of(sp_sleep_mode),
846 			     (uint32_t)mode);
847 }
848 
ia_css_debug_wake_up_sp(void)849 void ia_css_debug_wake_up_sp(void)
850 {
851 	/*hrt_ctl_start(SP); */
852 	sp_ctrl_setbit(SP0_ID, SP_SC_REG, SP_START_BIT);
853 }
854 
855 #define FIND_DMEM_PARAMS_TYPE(stream, kernel, type) \
856 	(struct CONCATENATE(CONCATENATE(sh_css_isp_, type), _params) *) \
857 	findf_dmem_params(stream, offsetof(struct ia_css_memory_offsets, dmem.kernel))
858 
859 #define FIND_DMEM_PARAMS(stream, kernel) FIND_DMEM_PARAMS_TYPE(stream, kernel, kernel)
860 
861 /* Find a stage that support the kernel and return the parameters for that kernel */
862 static char *
findf_dmem_params(struct ia_css_stream * stream,short idx)863 findf_dmem_params(struct ia_css_stream *stream, short idx)
864 {
865 	int i;
866 
867 	for (i = 0; i < stream->num_pipes; i++) {
868 		struct ia_css_pipe *pipe = stream->pipes[i];
869 		struct ia_css_pipeline *pipeline = ia_css_pipe_get_pipeline(pipe);
870 		struct ia_css_pipeline_stage *stage;
871 
872 		for (stage = pipeline->stages; stage; stage = stage->next) {
873 			struct ia_css_binary *binary = stage->binary;
874 			short *offsets = (short *)&binary->info->mem_offsets.offsets.param->dmem;
875 			short dmem_offset = offsets[idx];
876 			const struct ia_css_host_data *isp_data =
877 			    ia_css_isp_param_get_mem_init(&binary->mem_params,
878 							  IA_CSS_PARAM_CLASS_PARAM, IA_CSS_ISP_DMEM0);
879 			if (dmem_offset < 0)
880 				continue;
881 			return &isp_data->address[dmem_offset];
882 		}
883 	}
884 	return NULL;
885 }
886 
ia_css_debug_dump_isp_params(struct ia_css_stream * stream,unsigned int enable)887 void ia_css_debug_dump_isp_params(struct ia_css_stream *stream,
888 				  unsigned int enable)
889 {
890 	ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE, "ISP PARAMETERS:\n");
891 
892 	assert(stream);
893 	if ((enable & IA_CSS_DEBUG_DUMP_FPN)
894 	    || (enable & IA_CSS_DEBUG_DUMP_ALL)) {
895 		ia_css_fpn_dump(FIND_DMEM_PARAMS(stream, fpn), IA_CSS_DEBUG_VERBOSE);
896 	}
897 	if ((enable & IA_CSS_DEBUG_DUMP_OB)
898 	    || (enable & IA_CSS_DEBUG_DUMP_ALL)) {
899 		ia_css_ob_dump(FIND_DMEM_PARAMS(stream, ob), IA_CSS_DEBUG_VERBOSE);
900 	}
901 	if ((enable & IA_CSS_DEBUG_DUMP_SC)
902 	    || (enable & IA_CSS_DEBUG_DUMP_ALL)) {
903 		ia_css_sc_dump(FIND_DMEM_PARAMS(stream, sc), IA_CSS_DEBUG_VERBOSE);
904 	}
905 	if ((enable & IA_CSS_DEBUG_DUMP_WB)
906 	    || (enable & IA_CSS_DEBUG_DUMP_ALL)) {
907 		ia_css_wb_dump(FIND_DMEM_PARAMS(stream, wb), IA_CSS_DEBUG_VERBOSE);
908 	}
909 	if ((enable & IA_CSS_DEBUG_DUMP_DP)
910 	    || (enable & IA_CSS_DEBUG_DUMP_ALL)) {
911 		ia_css_dp_dump(FIND_DMEM_PARAMS(stream, dp), IA_CSS_DEBUG_VERBOSE);
912 	}
913 	if ((enable & IA_CSS_DEBUG_DUMP_BNR)
914 	    || (enable & IA_CSS_DEBUG_DUMP_ALL)) {
915 		ia_css_bnr_dump(FIND_DMEM_PARAMS(stream, bnr), IA_CSS_DEBUG_VERBOSE);
916 	}
917 	if ((enable & IA_CSS_DEBUG_DUMP_S3A)
918 	    || (enable & IA_CSS_DEBUG_DUMP_ALL)) {
919 		ia_css_s3a_dump(FIND_DMEM_PARAMS(stream, s3a), IA_CSS_DEBUG_VERBOSE);
920 	}
921 	if ((enable & IA_CSS_DEBUG_DUMP_DE)
922 	    || (enable & IA_CSS_DEBUG_DUMP_ALL)) {
923 		ia_css_de_dump(FIND_DMEM_PARAMS(stream, de), IA_CSS_DEBUG_VERBOSE);
924 	}
925 	if ((enable & IA_CSS_DEBUG_DUMP_YNR)
926 	    || (enable & IA_CSS_DEBUG_DUMP_ALL)) {
927 		ia_css_nr_dump(FIND_DMEM_PARAMS_TYPE(stream, nr, ynr),  IA_CSS_DEBUG_VERBOSE);
928 		ia_css_yee_dump(FIND_DMEM_PARAMS(stream, yee), IA_CSS_DEBUG_VERBOSE);
929 	}
930 	if ((enable & IA_CSS_DEBUG_DUMP_CSC)
931 	    || (enable & IA_CSS_DEBUG_DUMP_ALL)) {
932 		ia_css_csc_dump(FIND_DMEM_PARAMS(stream, csc), IA_CSS_DEBUG_VERBOSE);
933 		ia_css_yuv2rgb_dump(FIND_DMEM_PARAMS_TYPE(stream, yuv2rgb, csc),
934 				    IA_CSS_DEBUG_VERBOSE);
935 		ia_css_rgb2yuv_dump(FIND_DMEM_PARAMS_TYPE(stream, rgb2yuv, csc),
936 				    IA_CSS_DEBUG_VERBOSE);
937 	}
938 	if ((enable & IA_CSS_DEBUG_DUMP_GC)
939 	    || (enable & IA_CSS_DEBUG_DUMP_ALL)) {
940 		ia_css_gc_dump(FIND_DMEM_PARAMS(stream, gc), IA_CSS_DEBUG_VERBOSE);
941 	}
942 	if ((enable & IA_CSS_DEBUG_DUMP_TNR)
943 	    || (enable & IA_CSS_DEBUG_DUMP_ALL)) {
944 		ia_css_tnr_dump(FIND_DMEM_PARAMS(stream, tnr), IA_CSS_DEBUG_VERBOSE);
945 	}
946 	if ((enable & IA_CSS_DEBUG_DUMP_ANR)
947 	    || (enable & IA_CSS_DEBUG_DUMP_ALL)) {
948 		ia_css_anr_dump(FIND_DMEM_PARAMS(stream, anr), IA_CSS_DEBUG_VERBOSE);
949 	}
950 	if ((enable & IA_CSS_DEBUG_DUMP_CE)
951 	    || (enable & IA_CSS_DEBUG_DUMP_ALL)) {
952 		ia_css_ce_dump(FIND_DMEM_PARAMS(stream, ce), IA_CSS_DEBUG_VERBOSE);
953 	}
954 }
955 
sh_css_dump_sp_raw_copy_linecount(bool reduced)956 void sh_css_dump_sp_raw_copy_linecount(bool reduced)
957 {
958 	const struct ia_css_fw_info *fw;
959 	unsigned int HIVE_ADDR_raw_copy_line_count;
960 	s32 raw_copy_line_count;
961 	static s32 prev_raw_copy_line_count = -1;
962 
963 	fw = &sh_css_sp_fw;
964 	HIVE_ADDR_raw_copy_line_count =
965 	    fw->info.sp.raw_copy_line_count;
966 
967 	(void)HIVE_ADDR_raw_copy_line_count;
968 
969 	sp_dmem_load(SP0_ID,
970 		     (unsigned int)sp_address_of(raw_copy_line_count),
971 		     &raw_copy_line_count,
972 		     sizeof(raw_copy_line_count));
973 
974 	/* only indicate if copy loop is active */
975 	if (reduced)
976 		raw_copy_line_count = (raw_copy_line_count < 0) ? raw_copy_line_count : 1;
977 	/* do the handling */
978 	if (prev_raw_copy_line_count != raw_copy_line_count) {
979 		ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE,
980 				    "sh_css_dump_sp_raw_copy_linecount() line_count=%d\n",
981 				    raw_copy_line_count);
982 		prev_raw_copy_line_count = raw_copy_line_count;
983 	}
984 }
985 
ia_css_debug_dump_isp_binary(void)986 void ia_css_debug_dump_isp_binary(void)
987 {
988 	const struct ia_css_fw_info *fw;
989 	unsigned int HIVE_ADDR_pipeline_sp_curr_binary_id;
990 	u32 curr_binary_id;
991 	static u32 prev_binary_id = 0xFFFFFFFF;
992 	static u32 sample_count;
993 
994 	fw = &sh_css_sp_fw;
995 	HIVE_ADDR_pipeline_sp_curr_binary_id = fw->info.sp.curr_binary_id;
996 
997 	(void)HIVE_ADDR_pipeline_sp_curr_binary_id;
998 
999 	sp_dmem_load(SP0_ID,
1000 		     (unsigned int)sp_address_of(pipeline_sp_curr_binary_id),
1001 		     &curr_binary_id,
1002 		     sizeof(curr_binary_id));
1003 
1004 	/* do the handling */
1005 	sample_count++;
1006 	if (prev_binary_id != curr_binary_id) {
1007 		ia_css_debug_dtrace(IA_CSS_DEBUG_VERBOSE,
1008 				    "sh_css_dump_isp_binary() pipe_id=%d, binary_id=%d, sample_count=%d\n",
1009 				    (curr_binary_id >> 16),
1010 				    (curr_binary_id & 0x0ffff),
1011 				    sample_count);
1012 		sample_count = 0;
1013 		prev_binary_id = curr_binary_id;
1014 	}
1015 }
1016 
1017 /*
1018  * @brief Initialize the debug mode.
1019  * Refer to "ia_css_debug.h" for more details.
1020  */
ia_css_debug_mode_init(void)1021 bool ia_css_debug_mode_init(void)
1022 {
1023 	bool rc;
1024 
1025 	rc = sh_css_sp_init_dma_sw_reg(0);
1026 	return rc;
1027 }
1028 
1029 /*
1030  * @brief Disable the DMA channel.
1031  * Refer to "ia_css_debug.h" for more details.
1032  */
1033 bool
ia_css_debug_mode_disable_dma_channel(int dma_id,int channel_id,int request_type)1034 ia_css_debug_mode_disable_dma_channel(int dma_id,
1035 				      int channel_id, int request_type)
1036 {
1037 	bool rc;
1038 
1039 	rc = sh_css_sp_set_dma_sw_reg(dma_id, channel_id, request_type, false);
1040 
1041 	return rc;
1042 }
1043 
1044 /*
1045  * @brief Enable the DMA channel.
1046  * Refer to "ia_css_debug.h" for more details.
1047  */
1048 bool
ia_css_debug_mode_enable_dma_channel(int dma_id,int channel_id,int request_type)1049 ia_css_debug_mode_enable_dma_channel(int dma_id,
1050 				     int channel_id, int request_type)
1051 {
1052 	bool rc;
1053 
1054 	rc = sh_css_sp_set_dma_sw_reg(dma_id, channel_id, request_type, true);
1055 
1056 	return rc;
1057 }
1058 
dtrace_dot(const char * fmt,...)1059 static void __printf(1, 2) dtrace_dot(const char *fmt, ...)
1060 {
1061 	va_list ap;
1062 
1063 	assert(fmt);
1064 	va_start(ap, fmt);
1065 
1066 	ia_css_debug_dtrace(IA_CSS_DEBUG_INFO, "%s", DPG_START);
1067 	ia_css_debug_vdtrace(IA_CSS_DEBUG_INFO, fmt, ap);
1068 	ia_css_debug_dtrace(IA_CSS_DEBUG_INFO, "%s", DPG_END);
1069 	va_end(ap);
1070 }
1071 
1072 static void
ia_css_debug_pipe_graph_dump_frame(const struct ia_css_frame * frame,enum ia_css_pipe_id id,char const * blob_name,char const * frame_name,bool in_frame)1073 ia_css_debug_pipe_graph_dump_frame(
1074     const struct ia_css_frame *frame,
1075     enum ia_css_pipe_id id,
1076     char const *blob_name,
1077     char const *frame_name,
1078     bool in_frame)
1079 {
1080 	char bufinfo[100];
1081 
1082 	if (frame->dynamic_queue_id == SH_CSS_INVALID_QUEUE_ID) {
1083 		snprintf(bufinfo, sizeof(bufinfo), "Internal");
1084 	} else {
1085 		snprintf(bufinfo, sizeof(bufinfo), "Queue: %s %s",
1086 			 pipe_id_to_str[id],
1087 			 queue_id_to_str[frame->dynamic_queue_id]);
1088 	}
1089 	dtrace_dot(
1090 	    "node [shape = box, fixedsize=true, width=2, height=0.7]; \"%p\" [label = \"%s\\n%d(%d) x %d, %dbpp\\n%s\"];",
1091 	    frame,
1092 	    debug_frame_format2str(frame->frame_info.format),
1093 	    frame->frame_info.res.width,
1094 	    frame->frame_info.padded_width,
1095 	    frame->frame_info.res.height,
1096 	    frame->frame_info.raw_bit_depth,
1097 	    bufinfo);
1098 
1099 	if (in_frame) {
1100 		dtrace_dot(
1101 		    "\"%p\"->\"%s(pipe%d)\" [label = %s_frame];",
1102 		    frame,
1103 		    blob_name, id, frame_name);
1104 	} else {
1105 		dtrace_dot(
1106 		    "\"%s(pipe%d)\"->\"%p\" [label = %s_frame];",
1107 		    blob_name, id,
1108 		    frame,
1109 		    frame_name);
1110 	}
1111 }
1112 
1113 void
ia_css_debug_pipe_graph_dump_prologue(void)1114 ia_css_debug_pipe_graph_dump_prologue(void)
1115 {
1116 	dtrace_dot("digraph sh_css_pipe_graph {");
1117 	dtrace_dot("rankdir=LR;");
1118 
1119 	dtrace_dot("fontsize=9;");
1120 	dtrace_dot("label = \"\\nEnable options: rp=reduced pipe, vfve=vf_veceven, dvse=dvs_envelope, dvs6=dvs_6axis, bo=block_out, fbds=fixed_bayer_ds, bf6=bayer_fir_6db, rawb=raw_binning, cont=continuous, disc=dis_crop\\n"
1121 		   "dp2a=dp_2adjacent, outp=output, outt=out_table, reff=ref_frame, par=params, gam=gamma, cagdc=ca_gdc, ispa=isp_addresses, inf=in_frame, outf=out_frame, hs=high_speed, inpc=input_chunking\"");
1122 }
1123 
ia_css_debug_pipe_graph_dump_epilogue(void)1124 void ia_css_debug_pipe_graph_dump_epilogue(void)
1125 {
1126 	if (strlen(ring_buffer) > 0) {
1127 		dtrace_dot(ring_buffer);
1128 	}
1129 
1130 	if (pg_inst.stream_format != N_ATOMISP_INPUT_FORMAT) {
1131 		/* An input stream format has been set so assume we have
1132 		 * an input system and sensor
1133 		 */
1134 
1135 		dtrace_dot(
1136 		    "node [shape = doublecircle, fixedsize=true, width=2.5]; \"input_system\" [label = \"Input system\"];");
1137 
1138 		dtrace_dot(
1139 		    "\"input_system\"->\"%s\" [label = \"%s\"];",
1140 		    dot_id_input_bin, debug_stream_format2str(pg_inst.stream_format));
1141 
1142 		dtrace_dot(
1143 		    "node [shape = doublecircle, fixedsize=true, width=2.5]; \"sensor\" [label = \"Sensor\"];");
1144 
1145 		dtrace_dot(
1146 		    "\"sensor\"->\"input_system\" [label = \"%s\\n%d x %d\\n(%d x %d)\"];",
1147 		    debug_stream_format2str(pg_inst.stream_format),
1148 		    pg_inst.width, pg_inst.height,
1149 		    pg_inst.eff_width, pg_inst.eff_height);
1150 	}
1151 
1152 	dtrace_dot("}");
1153 
1154 	/* Reset temp strings */
1155 	memset(dot_id_input_bin, 0, sizeof(dot_id_input_bin));
1156 	memset(ring_buffer, 0, sizeof(ring_buffer));
1157 
1158 	pg_inst.do_init = true;
1159 	pg_inst.width = 0;
1160 	pg_inst.height = 0;
1161 	pg_inst.eff_width = 0;
1162 	pg_inst.eff_height = 0;
1163 	pg_inst.stream_format = N_ATOMISP_INPUT_FORMAT;
1164 }
1165 
1166 void
ia_css_debug_pipe_graph_dump_stage(struct ia_css_pipeline_stage * stage,enum ia_css_pipe_id id)1167 ia_css_debug_pipe_graph_dump_stage(
1168     struct ia_css_pipeline_stage *stage,
1169     enum ia_css_pipe_id id)
1170 {
1171 	char blob_name[SH_CSS_MAX_BINARY_NAME + 10] = "<unknown type>";
1172 	char const *bin_type = "<unknown type>";
1173 	int i;
1174 
1175 	assert(stage);
1176 	if (stage->sp_func != IA_CSS_PIPELINE_NO_FUNC)
1177 		return;
1178 
1179 	if (pg_inst.do_init) {
1180 		ia_css_debug_pipe_graph_dump_prologue();
1181 		pg_inst.do_init = false;
1182 	}
1183 
1184 	if (stage->binary) {
1185 		bin_type = "binary";
1186 		if (stage->binary->info->blob)
1187 			snprintf(blob_name, sizeof(blob_name), "%s_stage%d",
1188 				 stage->binary->info->blob->name, stage->stage_num);
1189 	} else if (stage->firmware) {
1190 		bin_type = "firmware";
1191 
1192 		strscpy(blob_name, IA_CSS_EXT_ISP_PROG_NAME(stage->firmware),
1193 			sizeof(blob_name));
1194 	}
1195 
1196 	/* Guard in case of binaries that don't have any binary_info */
1197 	if (stage->binary_info) {
1198 		char enable_info1[100];
1199 		char enable_info2[100];
1200 		char enable_info3[100];
1201 		char enable_info[302];
1202 		struct ia_css_binary_info *bi = stage->binary_info;
1203 
1204 		/* Split it in 2 function-calls to keep the amount of
1205 		 * parameters per call "reasonable"
1206 		 */
1207 		snprintf(enable_info1, sizeof(enable_info1),
1208 			 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
1209 			 bi->enable.reduced_pipe ?	"rp," : "",
1210 			 bi->enable.vf_veceven ?		"vfve," : "",
1211 			 bi->enable.dis ?		"dis," : "",
1212 			 bi->enable.dvs_envelope ?	"dvse," : "",
1213 			 bi->enable.uds ?		"uds," : "",
1214 			 bi->enable.dvs_6axis ?		"dvs6," : "",
1215 			 bi->enable.block_output ?	"bo," : "",
1216 			 bi->enable.ds ?			"ds," : "",
1217 			 bi->enable.bayer_fir_6db ?	"bf6," : "",
1218 			 bi->enable.raw_binning ?	"rawb," : "",
1219 			 bi->enable.continuous ?		"cont," : "",
1220 			 bi->enable.s3a ?		"s3a," : "",
1221 			 bi->enable.fpnr ?		"fpnr," : "",
1222 			 bi->enable.sc ?			"sc," : ""
1223 			);
1224 
1225 		snprintf(enable_info2, sizeof(enable_info2),
1226 			 "%s%s%s%s%s%s%s%s%s%s%s",
1227 			 bi->enable.macc ?		"macc," : "",
1228 			 bi->enable.output ?		"outp," : "",
1229 			 bi->enable.ref_frame ?		"reff," : "",
1230 			 bi->enable.tnr ?		"tnr," : "",
1231 			 bi->enable.xnr ?		"xnr," : "",
1232 			 bi->enable.params ?		"par," : "",
1233 			 bi->enable.ca_gdc ?		"cagdc," : "",
1234 			 bi->enable.isp_addresses ?	"ispa," : "",
1235 			 bi->enable.in_frame ?		"inf," : "",
1236 			 bi->enable.out_frame ?		"outf," : "",
1237 			 bi->enable.high_speed ?		"hs," : ""
1238 			);
1239 
1240 		/* And merge them into one string */
1241 		snprintf(enable_info, sizeof(enable_info), "%s%s",
1242 			 enable_info1, enable_info2);
1243 		{
1244 			int l, p;
1245 			char *ei = enable_info;
1246 
1247 			l = strlen(ei);
1248 
1249 			/* Replace last ',' with \0 if present */
1250 			if (l && enable_info[l - 1] == ',')
1251 				enable_info[--l] = '\0';
1252 
1253 			if (l > ENABLE_LINE_MAX_LENGTH) {
1254 				/* Too big for one line, find last comma */
1255 				p = ENABLE_LINE_MAX_LENGTH;
1256 				while (ei[p] != ',')
1257 					p--;
1258 				/* Last comma found, copy till that comma */
1259 				strscpy(enable_info1, ei,
1260                                         p > sizeof(enable_info1) ? sizeof(enable_info1) : p);
1261 
1262 				ei += p + 1;
1263 				l = strlen(ei);
1264 
1265 				if (l <= ENABLE_LINE_MAX_LENGTH) {
1266 					/* The 2nd line fits */
1267 					/* we cannot use ei as argument because
1268 					 * it is not guaranteed dword aligned
1269 					 */
1270 
1271 					strscpy(enable_info2, ei,
1272 						l > sizeof(enable_info2) ? sizeof(enable_info2) : l);
1273 
1274 					snprintf(enable_info, sizeof(enable_info), "%s\\n%s",
1275 						 enable_info1, enable_info2);
1276 
1277 				} else {
1278 					/* 2nd line is still too long */
1279 					p = ENABLE_LINE_MAX_LENGTH;
1280 					while (ei[p] != ',')
1281 						p--;
1282 
1283 					strscpy(enable_info2, ei,
1284 						p > sizeof(enable_info2) ? sizeof(enable_info2) : p);
1285 
1286 					ei += p + 1;
1287 					l = strlen(ei);
1288 
1289 					if (l <= ENABLE_LINE_MAX_LENGTH) {
1290 						/* The 3rd line fits */
1291 						/* we cannot use ei as argument because
1292 						* it is not guaranteed dword aligned
1293 						*/
1294 						strscpy(enable_info3, ei,
1295 							sizeof(enable_info3));
1296 						snprintf(enable_info, sizeof(enable_info),
1297 							 "%s\\n%s\\n%s",
1298 							 enable_info1, enable_info2,
1299 							 enable_info3);
1300 					} else {
1301 						/* 3rd line is still too long */
1302 						p = ENABLE_LINE_MAX_LENGTH;
1303 						while (ei[p] != ',')
1304 							p--;
1305 						strscpy(enable_info3, ei,
1306 							p > sizeof(enable_info3) ? sizeof(enable_info3) : p);
1307 						ei += p + 1;
1308 						strscpy(enable_info3, ei,
1309 							sizeof(enable_info3));
1310 						snprintf(enable_info, sizeof(enable_info),
1311 							 "%s\\n%s\\n%s",
1312 							 enable_info1, enable_info2,
1313 							 enable_info3);
1314 					}
1315 				}
1316 			}
1317 		}
1318 
1319 		dtrace_dot("node [shape = circle, fixedsize=true, width=2.5, label=\"%s\\n%s\\n\\n%s\"]; \"%s(pipe%d)\"",
1320 			   bin_type, blob_name, enable_info, blob_name, id);
1321 	} else {
1322 		dtrace_dot("node [shape = circle, fixedsize=true, width=2.5, label=\"%s\\n%s\\n\"]; \"%s(pipe%d)\"",
1323 			   bin_type, blob_name, blob_name, id);
1324 	}
1325 
1326 	if (stage->stage_num == 0) {
1327 		/*
1328 		 * There are some implicit assumptions about which bin is the
1329 		 * input binary e.g. which one is connected to the input system
1330 		 * Priority:
1331 		 * 1) sp_raw_copy bin has highest priority
1332 		 * 2) First stage==0 binary of preview, video or capture
1333 		 */
1334 		if (strlen(dot_id_input_bin) == 0) {
1335 			snprintf(dot_id_input_bin, sizeof(dot_id_input_bin),
1336 				 "%s(pipe%d)", blob_name, id);
1337 		}
1338 	}
1339 
1340 	if (stage->args.in_frame) {
1341 		ia_css_debug_pipe_graph_dump_frame(
1342 		    stage->args.in_frame, id, blob_name,
1343 		    "in", true);
1344 	}
1345 
1346 	for (i = 0; i < NUM_VIDEO_TNR_FRAMES; i++) {
1347 		if (stage->args.tnr_frames[i]) {
1348 			ia_css_debug_pipe_graph_dump_frame(
1349 			    stage->args.tnr_frames[i], id,
1350 			    blob_name, "tnr_frame", true);
1351 		}
1352 	}
1353 
1354 	for (i = 0; i < MAX_NUM_VIDEO_DELAY_FRAMES; i++) {
1355 		if (stage->args.delay_frames[i]) {
1356 			ia_css_debug_pipe_graph_dump_frame(
1357 			    stage->args.delay_frames[i], id,
1358 			    blob_name, "delay_frame", true);
1359 		}
1360 	}
1361 
1362 	for (i = 0; i < IA_CSS_BINARY_MAX_OUTPUT_PORTS; i++) {
1363 		if (stage->args.out_frame[i]) {
1364 			ia_css_debug_pipe_graph_dump_frame(
1365 			    stage->args.out_frame[i], id, blob_name,
1366 			    "out", false);
1367 		}
1368 	}
1369 
1370 	if (stage->args.out_vf_frame) {
1371 		ia_css_debug_pipe_graph_dump_frame(
1372 		    stage->args.out_vf_frame, id, blob_name,
1373 		    "out_vf", false);
1374 	}
1375 }
1376 
1377 void
ia_css_debug_pipe_graph_dump_sp_raw_copy(struct ia_css_frame * out_frame)1378 ia_css_debug_pipe_graph_dump_sp_raw_copy(
1379     struct ia_css_frame *out_frame)
1380 {
1381 	assert(out_frame);
1382 	if (pg_inst.do_init) {
1383 		ia_css_debug_pipe_graph_dump_prologue();
1384 		pg_inst.do_init = false;
1385 	}
1386 
1387 	dtrace_dot("node [shape = circle, fixedsize=true, width=2.5, label=\"%s\\n%s\"]; \"%s(pipe%d)\"",
1388 		   "sp-binary", "sp_raw_copy", "sp_raw_copy", 1);
1389 
1390 	snprintf(ring_buffer, sizeof(ring_buffer),
1391 		 "node [shape = box, fixedsize=true, width=2, height=0.7]; \"%p\" [label = \"%s\\n%d(%d) x %d\\nRingbuffer\"];",
1392 		 out_frame,
1393 		 debug_frame_format2str(out_frame->frame_info.format),
1394 		 out_frame->frame_info.res.width,
1395 		 out_frame->frame_info.padded_width,
1396 		 out_frame->frame_info.res.height);
1397 
1398 	dtrace_dot(ring_buffer);
1399 
1400 	dtrace_dot(
1401 	    "\"%s(pipe%d)\"->\"%p\" [label = out_frame];",
1402 	    "sp_raw_copy", 1, out_frame);
1403 
1404 	snprintf(dot_id_input_bin, sizeof(dot_id_input_bin), "%s(pipe%d)",
1405 		 "sp_raw_copy", 1);
1406 }
1407 
1408 void
ia_css_debug_pipe_graph_dump_stream_config(const struct ia_css_stream_config * stream_config)1409 ia_css_debug_pipe_graph_dump_stream_config(
1410     const struct ia_css_stream_config *stream_config)
1411 {
1412 	pg_inst.width = stream_config->input_config.input_res.width;
1413 	pg_inst.height = stream_config->input_config.input_res.height;
1414 	pg_inst.eff_width = stream_config->input_config.effective_res.width;
1415 	pg_inst.eff_height = stream_config->input_config.effective_res.height;
1416 	pg_inst.stream_format = stream_config->input_config.format;
1417 }
1418 
1419 void
ia_css_debug_dump_resolution(const struct ia_css_resolution * res,const char * label)1420 ia_css_debug_dump_resolution(
1421     const struct ia_css_resolution *res,
1422     const char *label)
1423 {
1424 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "%s: =%d x =%d\n",
1425 			    label, res->width, res->height);
1426 }
1427 
1428 void
ia_css_debug_dump_frame_info(const struct ia_css_frame_info * info,const char * label)1429 ia_css_debug_dump_frame_info(
1430     const struct ia_css_frame_info *info,
1431     const char *label)
1432 {
1433 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "%s\n", label);
1434 	ia_css_debug_dump_resolution(&info->res, "res");
1435 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "padded_width: %d\n",
1436 			    info->padded_width);
1437 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "format: %d\n", info->format);
1438 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "raw_bit_depth: %d\n",
1439 			    info->raw_bit_depth);
1440 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "raw_bayer_order: %d\n",
1441 			    info->raw_bayer_order);
1442 }
1443 
1444 void
ia_css_debug_dump_capture_config(const struct ia_css_capture_config * config)1445 ia_css_debug_dump_capture_config(
1446     const struct ia_css_capture_config *config)
1447 {
1448 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "%s\n", __func__);
1449 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "mode: %d\n", config->mode);
1450 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "enable_xnr:  %d\n",
1451 			    config->enable_xnr);
1452 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "enable_raw_output: %d\n",
1453 			    config->enable_raw_output);
1454 }
1455 
1456 void
ia_css_debug_dump_pipe_extra_config(const struct ia_css_pipe_extra_config * extra_config)1457 ia_css_debug_dump_pipe_extra_config(
1458     const struct ia_css_pipe_extra_config *extra_config)
1459 {
1460 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "%s\n", __func__);
1461 	if (extra_config) {
1462 		ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE,
1463 				    "enable_raw_binning: %d\n",
1464 				    extra_config->enable_raw_binning);
1465 		ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "enable_yuv_ds: %d\n",
1466 				    extra_config->enable_yuv_ds);
1467 		ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE,
1468 				    "enable_high_speed:  %d\n",
1469 				    extra_config->enable_high_speed);
1470 		ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE,
1471 				    "enable_dvs_6axis: %d\n",
1472 				    extra_config->enable_dvs_6axis);
1473 		ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE,
1474 				    "enable_reduced_pipe: %d\n",
1475 				    extra_config->enable_reduced_pipe);
1476 		ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE,
1477 				    "enable_fractional_ds: %d\n",
1478 				    extra_config->enable_fractional_ds);
1479 		ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "disable_vf_pp: %d\n",
1480 				    extra_config->disable_vf_pp);
1481 	}
1482 }
1483 
1484 void
ia_css_debug_dump_pipe_config(const struct ia_css_pipe_config * config)1485 ia_css_debug_dump_pipe_config(
1486     const struct ia_css_pipe_config *config)
1487 {
1488 	unsigned int i;
1489 
1490 	IA_CSS_ENTER_PRIVATE("config = %p", config);
1491 	if (!config) {
1492 		IA_CSS_ERROR("NULL input parameter");
1493 		IA_CSS_LEAVE_PRIVATE("");
1494 		return;
1495 	}
1496 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "mode: %d\n", config->mode);
1497 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "isp_pipe_version: %d\n",
1498 			    config->isp_pipe_version);
1499 	ia_css_debug_dump_resolution(&config->bayer_ds_out_res,
1500 				     "bayer_ds_out_res");
1501 	ia_css_debug_dump_resolution(&config->capt_pp_in_res,
1502 				     "capt_pp_in_res");
1503 	ia_css_debug_dump_resolution(&config->vf_pp_in_res, "vf_pp_in_res");
1504 
1505 	if (IS_ISP2401) {
1506 		ia_css_debug_dump_resolution(&config->output_system_in_res,
1507 					    "output_system_in_res");
1508 	}
1509 	ia_css_debug_dump_resolution(&config->dvs_crop_out_res,
1510 				     "dvs_crop_out_res");
1511 	for (i = 0; i < IA_CSS_PIPE_MAX_OUTPUT_STAGE; i++) {
1512 		ia_css_debug_dump_frame_info(&config->output_info[i], "output_info");
1513 		ia_css_debug_dump_frame_info(&config->vf_output_info[i],
1514 					     "vf_output_info");
1515 	}
1516 	ia_css_debug_dump_capture_config(&config->default_capture_config);
1517 	ia_css_debug_dump_resolution(&config->dvs_envelope, "dvs_envelope");
1518 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "dvs_frame_delay: %d\n",
1519 			    config->dvs_frame_delay);
1520 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "enable_dz: %d\n",
1521 			    config->enable_dz);
1522 	IA_CSS_LEAVE_PRIVATE("");
1523 }
1524 
1525 void
ia_css_debug_dump_stream_config_source(const struct ia_css_stream_config * config)1526 ia_css_debug_dump_stream_config_source(
1527     const struct ia_css_stream_config *config)
1528 {
1529 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "%s()\n", __func__);
1530 	switch (config->mode) {
1531 	case IA_CSS_INPUT_MODE_SENSOR:
1532 	case IA_CSS_INPUT_MODE_BUFFERED_SENSOR:
1533 		ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "source.port\n");
1534 		ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "port: %d\n",
1535 				    config->source.port.port);
1536 		ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "num_lanes: %d\n",
1537 				    config->source.port.num_lanes);
1538 		ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "timeout: %d\n",
1539 				    config->source.port.timeout);
1540 		ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "compression: %d\n",
1541 				    config->source.port.compression.type);
1542 		break;
1543 	case IA_CSS_INPUT_MODE_PRBS:
1544 		ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "source.prbs\n");
1545 		ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "id: %d\n",
1546 				    config->source.prbs.id);
1547 		ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "h_blank: %d\n",
1548 				    config->source.prbs.h_blank);
1549 		ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "v_blank: %d\n",
1550 				    config->source.prbs.v_blank);
1551 		ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "seed: 0x%x\n",
1552 				    config->source.prbs.seed);
1553 		ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "seed1: 0x%x\n",
1554 				    config->source.prbs.seed1);
1555 		break;
1556 	default:
1557 	case IA_CSS_INPUT_MODE_FIFO:
1558 	case IA_CSS_INPUT_MODE_MEMORY:
1559 		break;
1560 	}
1561 }
1562 
1563 void
ia_css_debug_dump_mipi_buffer_config(const struct ia_css_mipi_buffer_config * config)1564 ia_css_debug_dump_mipi_buffer_config(
1565     const struct ia_css_mipi_buffer_config *config)
1566 {
1567 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "%s()\n", __func__);
1568 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "size_mem_words: %d\n",
1569 			    config->size_mem_words);
1570 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "nof_mipi_buffers: %d\n",
1571 			    config->nof_mipi_buffers);
1572 }
1573 
1574 void
ia_css_debug_dump_metadata_config(const struct ia_css_metadata_config * config)1575 ia_css_debug_dump_metadata_config(
1576     const struct ia_css_metadata_config *config)
1577 {
1578 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "%s()\n", __func__);
1579 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "data_type: %d\n",
1580 			    config->data_type);
1581 	ia_css_debug_dump_resolution(&config->resolution, "resolution");
1582 }
1583 
1584 void
ia_css_debug_dump_stream_config(const struct ia_css_stream_config * config,int num_pipes)1585 ia_css_debug_dump_stream_config(
1586     const struct ia_css_stream_config *config,
1587     int num_pipes)
1588 {
1589 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "%s()\n", __func__);
1590 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "num_pipes: %d\n", num_pipes);
1591 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "mode: %d\n", config->mode);
1592 	ia_css_debug_dump_stream_config_source(config);
1593 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "channel_id: %d\n",
1594 			    config->channel_id);
1595 	ia_css_debug_dump_resolution(&config->input_config.input_res, "input_res");
1596 	ia_css_debug_dump_resolution(&config->input_config.effective_res,
1597 				     "effective_res");
1598 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "format: %d\n",
1599 			    config->input_config.format);
1600 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "bayer_order: %d\n",
1601 			    config->input_config.bayer_order);
1602 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "sensor_binning_factor: %d\n",
1603 			    config->sensor_binning_factor);
1604 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "pixels_per_clock: %d\n",
1605 			    config->pixels_per_clock);
1606 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "online: %d\n",
1607 			    config->online);
1608 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "init_num_cont_raw_buf: %d\n",
1609 			    config->init_num_cont_raw_buf);
1610 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE,
1611 			    "target_num_cont_raw_buf: %d\n",
1612 			    config->target_num_cont_raw_buf);
1613 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "pack_raw_pixels: %d\n",
1614 			    config->pack_raw_pixels);
1615 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "continuous: %d\n",
1616 			    config->continuous);
1617 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "flash_gpio_pin: %d\n",
1618 			    config->flash_gpio_pin);
1619 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "left_padding: %d\n",
1620 			    config->left_padding);
1621 	ia_css_debug_dump_mipi_buffer_config(&config->mipi_buffer_config);
1622 	ia_css_debug_dump_metadata_config(&config->metadata_config);
1623 }
1624 
1625 /*
1626     Trace support.
1627 
1628     This tracer is using a buffer to trace the flow of the FW and dump misc values (see below for details).
1629     Currently, support is only for SKC.
1630     To enable support for other platforms:
1631      - Allocate a buffer for tracing in DMEM. The longer the better.
1632      - Use the DBG_init routine in sp.hive.c to initiatilize the tracer with the address and size selected.
1633      - Add trace points in the SP code wherever needed.
1634      - Enable the dump below with the required address and required adjustments.
1635 	   Dump is called at the end of ia_css_debug_dump_sp_state().
1636 */
1637 
1638 /*
1639  dump_trace() : dump the trace points from DMEM2.
1640  for every trace point, the following are printed: index, major:minor and the 16-bit attached value.
1641  The routine looks for the first 0, and then prints from it cyclically.
1642  Data forma in DMEM2:
1643   first 4 DWORDS: header
1644    DWORD 0: data description
1645     byte 0: version
1646     byte 1: number of threads (for future use)
1647     byte 2+3: number ot TPs
1648    DWORD 1: command byte + data (for future use)
1649     byte 0: command
1650     byte 1-3: command signature
1651    DWORD 2-3: additional data (for future use)
1652   Following data is 4-byte oriented:
1653     byte 0:   major
1654 	byte 1:   minor
1655 	byte 2-3: data
1656 */
1657 #if TRACE_ENABLE_SP0 || TRACE_ENABLE_SP1 || TRACE_ENABLE_ISP
debug_dump_one_trace(enum TRACE_CORE_ID proc_id)1658 static void debug_dump_one_trace(enum TRACE_CORE_ID proc_id)
1659 {
1660 #if defined(HAS_TRACER_V2)
1661 	u32 start_addr;
1662 	u32 start_addr_data;
1663 	u32 item_size;
1664 	u32 tmp;
1665 	u8 tid_val;
1666 	enum TRACE_DUMP_FORMAT dump_format;
1667 
1668 	int i, j, max_trace_points, point_num, limit = -1;
1669 	/* using a static buffer here as the driver has issues allocating memory */
1670 	static u32 trace_read_buf[TRACE_BUFF_SIZE] = {0};
1671 	static struct trace_header_t header;
1672 	u8 *header_arr;
1673 
1674 	/* read the header and parse it */
1675 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "~~~ Tracer ");
1676 	switch (proc_id) {
1677 	case TRACE_SP0_ID:
1678 		ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "SP0");
1679 		start_addr = TRACE_SP0_ADDR;
1680 		start_addr_data = TRACE_SP0_DATA_ADDR;
1681 		item_size = TRACE_SP0_ITEM_SIZE;
1682 		max_trace_points = TRACE_SP0_MAX_POINTS;
1683 		break;
1684 	case TRACE_SP1_ID:
1685 		ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "SP1");
1686 		start_addr = TRACE_SP1_ADDR;
1687 		start_addr_data = TRACE_SP1_DATA_ADDR;
1688 		item_size = TRACE_SP1_ITEM_SIZE;
1689 		max_trace_points = TRACE_SP1_MAX_POINTS;
1690 		break;
1691 	case TRACE_ISP_ID:
1692 		ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "ISP");
1693 		start_addr = TRACE_ISP_ADDR;
1694 		start_addr_data = TRACE_ISP_DATA_ADDR;
1695 		item_size = TRACE_ISP_ITEM_SIZE;
1696 		max_trace_points = TRACE_ISP_MAX_POINTS;
1697 		break;
1698 	default:
1699 		ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE,
1700 				    "\t\ttraces are not supported for this processor ID - exiting\n");
1701 		return;
1702 	}
1703 
1704 	if (!IS_ISP2401) {
1705 		tmp = ia_css_device_load_uint32(start_addr);
1706 		point_num = (tmp >> 16) & 0xFFFF;
1707 
1708 		ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, " ver %d %d points\n", tmp & 0xFF,
1709 				    point_num);
1710 	} else {
1711 		/* Loading byte-by-byte as using the master routine had issues */
1712 		header_arr = (uint8_t *)&header;
1713 		for (i = 0; i < (int)sizeof(struct trace_header_t); i++)
1714 			header_arr[i] = ia_css_device_load_uint8(start_addr + (i));
1715 
1716 		point_num = header.max_tracer_points;
1717 
1718 		ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, " ver %d %d points\n", header.version,
1719 				    point_num);
1720 
1721 		tmp = header.version;
1722 	}
1723 	if ((tmp & 0xFF) != TRACER_VER) {
1724 		ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "\t\tUnknown version - exiting\n");
1725 		return;
1726 	}
1727 	if (point_num > max_trace_points) {
1728 		ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "\t\tToo many points - exiting\n");
1729 		return;
1730 	}
1731 	/* copy the TPs and find the first 0 */
1732 	for (i = 0; i < point_num; i++) {
1733 		trace_read_buf[i] = ia_css_device_load_uint32(start_addr_data +
1734 				    (i * item_size));
1735 		if ((limit == (-1)) && (trace_read_buf[i] == 0))
1736 			limit = i;
1737 	}
1738 	if (IS_ISP2401) {
1739 		ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "Status:\n");
1740 		for (i = 0; i < SH_CSS_MAX_SP_THREADS; i++)
1741 			ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE,
1742 					    "\tT%d: %3d (%02x)  %6d (%04x)  %10d (%08x)\n", i,
1743 					    header.thr_status_byte[i], header.thr_status_byte[i],
1744 					    header.thr_status_word[i], header.thr_status_word[i],
1745 					    header.thr_status_dword[i], header.thr_status_dword[i]);
1746 		ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "Scratch:\n");
1747 		for (i = 0; i < MAX_SCRATCH_DATA; i++)
1748 			ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "%10d (%08x)  ",
1749 					    header.scratch_debug[i], header.scratch_debug[i]);
1750 		ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "\n");
1751 	}
1752 	/* two 0s in the beginning: empty buffer */
1753 	if ((trace_read_buf[0] == 0) && (trace_read_buf[1] == 0)) {
1754 		ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "\t\tEmpty tracer - exiting\n");
1755 		return;
1756 	}
1757 	/* no overrun: start from 0 */
1758 	if ((limit == point_num - 1) ||
1759 	    /* first 0 is at the end - border case */
1760 	    (trace_read_buf[limit + 1] ==
1761 	     0))   /* did not make a full cycle after the memset */
1762 		limit = 0;
1763 	/* overrun: limit is the first non-zero after the first zero */
1764 	else
1765 		limit++;
1766 
1767 	/* print the TPs */
1768 	for (i = 0; i < point_num; i++) {
1769 		j = (limit + i) % point_num;
1770 		if (trace_read_buf[j]) {
1771 			if (!IS_ISP2401) {
1772 				TRACE_DUMP_FORMAT dump_format = FIELD_FORMAT_UNPACK(trace_read_buf[j]);
1773 			} else {
1774 				tid_val = FIELD_TID_UNPACK(trace_read_buf[j]);
1775 				dump_format = TRACE_DUMP_FORMAT_POINT;
1776 
1777 				/*
1778 				* When tid value is 111b, the data will be interpreted differently:
1779 				* tid val is ignored, major field contains 2 bits (msb) for format type
1780 				*/
1781 				if (tid_val == FIELD_TID_SEL_FORMAT_PAT) {
1782 					dump_format = FIELD_FORMAT_UNPACK(trace_read_buf[j]);
1783 				}
1784 			}
1785 			switch (dump_format) {
1786 			case TRACE_DUMP_FORMAT_POINT:
1787 				ia_css_debug_dtrace(
1788 				    IA_CSS_DEBUG_TRACE,	"\t\t%d %d:%d value - %d\n",
1789 				    j, FIELD_MAJOR_UNPACK(trace_read_buf[j]),
1790 				    FIELD_MINOR_UNPACK(trace_read_buf[j]),
1791 				    FIELD_VALUE_UNPACK(trace_read_buf[j]));
1792 				break;
1793 			/* ISP2400 */
1794 			case TRACE_DUMP_FORMAT_VALUE24_HEX:
1795 				ia_css_debug_dtrace(
1796 				    IA_CSS_DEBUG_TRACE,	"\t\t%d, %d, 24bit value %x H\n",
1797 				    j,
1798 				    FIELD_MAJOR_UNPACK(trace_read_buf[j]),
1799 				    FIELD_VALUE_24_UNPACK(trace_read_buf[j]));
1800 				break;
1801 			/* ISP2400 */
1802 			case TRACE_DUMP_FORMAT_VALUE24_DEC:
1803 				ia_css_debug_dtrace(
1804 				    IA_CSS_DEBUG_TRACE,	"\t\t%d, %d, 24bit value %d D\n",
1805 				    j,
1806 				    FIELD_MAJOR_UNPACK(trace_read_buf[j]),
1807 				    FIELD_VALUE_24_UNPACK(trace_read_buf[j]));
1808 				break;
1809 			/* ISP2401 */
1810 			case TRACE_DUMP_FORMAT_POINT_NO_TID:
1811 				ia_css_debug_dtrace(
1812 				    IA_CSS_DEBUG_TRACE,	"\t\t%d %d:%d value - %x (%d)\n",
1813 				    j,
1814 				    FIELD_MAJOR_W_FMT_UNPACK(trace_read_buf[j]),
1815 				    FIELD_MINOR_UNPACK(trace_read_buf[j]),
1816 				    FIELD_VALUE_UNPACK(trace_read_buf[j]),
1817 				    FIELD_VALUE_UNPACK(trace_read_buf[j]));
1818 				break;
1819 			/* ISP2401 */
1820 			case TRACE_DUMP_FORMAT_VALUE24:
1821 				ia_css_debug_dtrace(
1822 				    IA_CSS_DEBUG_TRACE,	"\t\t%d, %d, 24bit value %x (%d)\n",
1823 				    j,
1824 				    FIELD_MAJOR_UNPACK(trace_read_buf[j]),
1825 				    FIELD_MAJOR_W_FMT_UNPACK(trace_read_buf[j]),
1826 				    FIELD_VALUE_24_UNPACK(trace_read_buf[j]),
1827 				    FIELD_VALUE_24_UNPACK(trace_read_buf[j]));
1828 				break;
1829 			case TRACE_DUMP_FORMAT_VALUE24_TIMING:
1830 				ia_css_debug_dtrace(
1831 				    IA_CSS_DEBUG_TRACE,	"\t\t%d, %d, timing %x\n",
1832 				    j,
1833 				    FIELD_MAJOR_UNPACK(trace_read_buf[j]),
1834 				    FIELD_VALUE_24_UNPACK(trace_read_buf[j]));
1835 				break;
1836 			case TRACE_DUMP_FORMAT_VALUE24_TIMING_DELTA:
1837 				ia_css_debug_dtrace(
1838 				    IA_CSS_DEBUG_TRACE,	"\t\t%d, %d, timing delta %x\n",
1839 				    j,
1840 				    FIELD_MAJOR_UNPACK(trace_read_buf[j]),
1841 				    FIELD_VALUE_24_UNPACK(trace_read_buf[j]));
1842 				break;
1843 			default:
1844 				ia_css_debug_dtrace(
1845 				    IA_CSS_DEBUG_TRACE,
1846 				    "no such trace dump format %d",
1847 				    dump_format);
1848 				break;
1849 			}
1850 		}
1851 	}
1852 #else
1853 	(void)proc_id;
1854 #endif /* HAS_TRACER_V2 */
1855 }
1856 #endif /* TRACE_ENABLE_SP0 || TRACE_ENABLE_SP1 || TRACE_ENABLE_ISP */
1857 
ia_css_debug_dump_trace(void)1858 void ia_css_debug_dump_trace(void)
1859 {
1860 #if TRACE_ENABLE_SP0
1861 	debug_dump_one_trace(TRACE_SP0_ID);
1862 #endif
1863 #if TRACE_ENABLE_SP1
1864 	debug_dump_one_trace(TRACE_SP1_ID);
1865 #endif
1866 #if TRACE_ENABLE_ISP
1867 	debug_dump_one_trace(TRACE_ISP_ID);
1868 #endif
1869 }
1870 
1871 /* ISP2401 */
ia_css_debug_pc_dump(sp_ID_t id,unsigned int num_of_dumps)1872 void ia_css_debug_pc_dump(sp_ID_t id, unsigned int num_of_dumps)
1873 {
1874 	unsigned int pc;
1875 	unsigned int i;
1876 	hrt_data sc = sp_ctrl_load(id, SP_SC_REG);
1877 
1878 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "SP%-1d Status reg: 0x%X\n", id, sc);
1879 	sc = sp_ctrl_load(id, SP_CTRL_SINK_REG);
1880 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "SP%-1d Stall reg: 0x%X\n", id, sc);
1881 	for (i = 0; i < num_of_dumps; i++) {
1882 		pc = sp_ctrl_load(id, SP_PC_REG);
1883 		ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "SP%-1d PC: 0x%X\n", id, pc);
1884 	}
1885 }
1886