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