1 /*
2  * Support for Intel Camera Imaging ISP subsystem.
3  * Copyright (c) 2015, Intel Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms and conditions of the GNU General Public License,
7  * version 2, as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12  * more details.
13  */
14 
15 #ifndef _IA_CSS_DEBUG_H_
16 #define _IA_CSS_DEBUG_H_
17 
18 /*! \file */
19 
20 #include <type_support.h>
21 #include <stdarg.h>
22 #include "ia_css_types.h"
23 #include "ia_css_binary.h"
24 #include "ia_css_frame_public.h"
25 #include "ia_css_pipe_public.h"
26 #include "ia_css_stream_public.h"
27 #include "ia_css_metadata.h"
28 #include "sh_css_internal.h"
29 /* ISP2500 */
30 #include "ia_css_pipe.h"
31 
32 /* available levels */
33 /*! Level for tracing errors */
34 #define IA_CSS_DEBUG_ERROR   1
35 /*! Level for tracing warnings */
36 #define IA_CSS_DEBUG_WARNING 3
37 /*! Level for tracing debug messages */
38 #define IA_CSS_DEBUG_VERBOSE   5
39 /*! Level for tracing trace messages a.o. ia_css public function calls */
40 #define IA_CSS_DEBUG_TRACE   6
41 /*! Level for tracing trace messages a.o. ia_css private function calls */
42 #define IA_CSS_DEBUG_TRACE_PRIVATE   7
43 /*! Level for tracing parameter messages e.g. in and out params of functions */
44 #define IA_CSS_DEBUG_PARAM   8
45 /*! Level for tracing info messages */
46 #define IA_CSS_DEBUG_INFO    9
47 
48 /* Global variable which controls the verbosity levels of the debug tracing */
49 extern int dbg_level;
50 
51 /*! @brief Enum defining the different isp parameters to dump.
52  *  Values can be combined to dump a combination of sets.
53  */
54 enum ia_css_debug_enable_param_dump {
55 	IA_CSS_DEBUG_DUMP_FPN = 1 << 0, /** FPN table */
56 	IA_CSS_DEBUG_DUMP_OB = 1 << 1,  /** OB table */
57 	IA_CSS_DEBUG_DUMP_SC = 1 << 2,  /** Shading table */
58 	IA_CSS_DEBUG_DUMP_WB = 1 << 3,  /** White balance */
59 	IA_CSS_DEBUG_DUMP_DP = 1 << 4,  /** Defect Pixel */
60 	IA_CSS_DEBUG_DUMP_BNR = 1 << 5,  /** Bayer Noise Reductions */
61 	IA_CSS_DEBUG_DUMP_S3A = 1 << 6,  /** 3A Statistics */
62 	IA_CSS_DEBUG_DUMP_DE = 1 << 7,  /** De Mosaicing */
63 	IA_CSS_DEBUG_DUMP_YNR = 1 << 8,  /** Luma Noise Reduction */
64 	IA_CSS_DEBUG_DUMP_CSC = 1 << 9,  /** Color Space Conversion */
65 	IA_CSS_DEBUG_DUMP_GC = 1 << 10,  /** Gamma Correction */
66 	IA_CSS_DEBUG_DUMP_TNR = 1 << 11,  /** Temporal Noise Reduction */
67 	IA_CSS_DEBUG_DUMP_ANR = 1 << 12,  /** Advanced Noise Reduction */
68 	IA_CSS_DEBUG_DUMP_CE = 1 << 13,  /** Chroma Enhancement */
69 	IA_CSS_DEBUG_DUMP_ALL = 1 << 14  /** Dump all device parameters */
70 };
71 
72 #define IA_CSS_ERROR(fmt, ...) \
73 	ia_css_debug_dtrace(IA_CSS_DEBUG_ERROR, \
74 		"%s() %d: error: " fmt "\n", __func__, __LINE__, ##__VA_ARGS__)
75 
76 #define IA_CSS_WARNING(fmt, ...) \
77 	ia_css_debug_dtrace(IA_CSS_DEBUG_WARNING, \
78 		"%s() %d: warning: " fmt "\n", __func__, __LINE__, ##__VA_ARGS__)
79 
80 /* Logging macros for public functions (API functions) */
81 #define IA_CSS_ENTER(fmt, ...) \
82 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, \
83 		"%s(): enter: " fmt "\n", __func__, ##__VA_ARGS__)
84 
85 /* Use this macro for small functions that do not call other functions. */
86 #define IA_CSS_ENTER_LEAVE(fmt, ...) \
87 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, \
88 		"%s(): enter: leave: " fmt "\n", __func__, ##__VA_ARGS__)
89 
90 #define IA_CSS_LEAVE(fmt, ...) \
91 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, \
92 		"%s(): leave: " fmt "\n", __func__, ##__VA_ARGS__)
93 
94 /* Shorthand for returning an int return value */
95 #define IA_CSS_LEAVE_ERR(__err) \
96 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, \
97 		"%s() %d: leave: return_err=%d\n", __func__, __LINE__, __err)
98 
99 /* Use this macro for logging other than enter/leave.
100  * Note that this macro always uses the PRIVATE logging level.
101  */
102 #define IA_CSS_LOG(fmt, ...) \
103 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE_PRIVATE, \
104 		"%s(): " fmt "\n", __func__, ##__VA_ARGS__)
105 
106 /* Logging macros for non-API functions. These have a lower trace level */
107 #define IA_CSS_ENTER_PRIVATE(fmt, ...) \
108 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE_PRIVATE, \
109 		"%s(): enter: " fmt "\n", __func__, ##__VA_ARGS__)
110 
111 #define IA_CSS_LEAVE_PRIVATE(fmt, ...) \
112 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE_PRIVATE, \
113 		"%s(): leave: " fmt "\n", __func__, ##__VA_ARGS__)
114 
115 /* Shorthand for returning an int return value */
116 #define IA_CSS_LEAVE_ERR_PRIVATE(__err) \
117 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE_PRIVATE, \
118 		"%s() %d: leave: return_err=%d\n", __func__, __LINE__, __err)
119 
120 /* Use this macro for small functions that do not call other functions. */
121 #define IA_CSS_ENTER_LEAVE_PRIVATE(fmt, ...) \
122 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE_PRIVATE, \
123 		"%s(): enter: leave: " fmt "\n", __func__, ##__VA_ARGS__)
124 
125 /*! @brief Function for tracing to the provided printf function in the
126  *	environment.
127  * @param[in]	level		Level of the message.
128  * @param[in]	fmt		printf like format string
129  * @param[in]	args		arguments for the format string
130  */
131 static inline void
132 ia_css_debug_vdtrace(unsigned int level, const char *fmt, va_list args)
133 {
134 	if (dbg_level >= level)
135 		sh_css_vprint(fmt, args);
136 }
137 
138 __printf(2, 3)
139 void ia_css_debug_dtrace(unsigned int level, const char *fmt, ...);
140 
141 /*! @brief Dump sp thread's stack contents
142  * SP thread's stack contents are set to 0xcafecafe. This function dumps the
143  * stack to inspect if the stack's boundaries are compromised.
144  * @return	None
145  */
146 void ia_css_debug_dump_sp_stack_info(void);
147 
148 /*! @brief Function to set the global dtrace verbosity level.
149  * @param[in]	trace_level	Maximum level of the messages to be traced.
150  * @return	None
151  */
152 void ia_css_debug_set_dtrace_level(
153     const unsigned int	trace_level);
154 
155 /*! @brief Function to get the global dtrace verbosity level.
156  * @return	global dtrace verbosity level
157  */
158 unsigned int ia_css_debug_get_dtrace_level(void);
159 
160 /*! @brief Dump input formatter state.
161  * Dumps the input formatter state to tracing output.
162  * @return	None
163  */
164 void ia_css_debug_dump_if_state(void);
165 
166 /*! @brief Dump isp hardware state.
167  * Dumps the isp hardware state to tracing output.
168  * @return	None
169  */
170 void ia_css_debug_dump_isp_state(void);
171 
172 /*! @brief Dump sp hardware state.
173  * Dumps the sp hardware state to tracing output.
174  * @return	None
175  */
176 void ia_css_debug_dump_sp_state(void);
177 
178 /* ISP2401 */
179 /*! @brief Dump GAC hardware state.
180  * Dumps the GAC ACB hardware registers. may be useful for
181  * detecting a GAC which got hang.
182  * @return	None
183  */
184 void ia_css_debug_dump_gac_state(void);
185 
186 /*! @brief Dump dma controller state.
187  * Dumps the dma controller state to tracing output.
188  * @return	None
189  */
190 void ia_css_debug_dump_dma_state(void);
191 
192 /*! @brief Dump internal sp software state.
193  * Dumps the sp software state to tracing output.
194  * @return	None
195  */
196 void ia_css_debug_dump_sp_sw_debug_info(void);
197 
198 /*! @brief Dump all related hardware state to the trace output
199  * @param[in]  context	String to identify context in output.
200  * @return	None
201  */
202 void ia_css_debug_dump_debug_info(
203     const char	*context);
204 
205 #if SP_DEBUG != SP_DEBUG_NONE
206 void ia_css_debug_print_sp_debug_state(
207     const struct sh_css_sp_debug_state *state);
208 #endif
209 
210 /*! @brief Dump all related binary info data
211  * @param[in]  bi	Binary info struct.
212  * @return	None
213  */
214 void ia_css_debug_binary_print(
215     const struct ia_css_binary *bi);
216 
217 void ia_css_debug_sp_dump_mipi_fifo_high_water(void);
218 
219 /*! @brief Dump isp gdc fifo state to the trace output
220  * Dumps the isp gdc fifo state to tracing output.
221  * @return	None
222  */
223 void ia_css_debug_dump_isp_gdc_fifo_state(void);
224 
225 /*! @brief Dump dma isp fifo state
226  * Dumps the dma isp fifo state to tracing output.
227  * @return	None
228  */
229 void ia_css_debug_dump_dma_isp_fifo_state(void);
230 
231 /*! @brief Dump dma sp fifo state
232  * Dumps the dma sp fifo state to tracing output.
233  * @return	None
234  */
235 void ia_css_debug_dump_dma_sp_fifo_state(void);
236 
237 /*! \brief Dump pif A isp fifo state
238  * Dumps the primary input formatter state to tracing output.
239  * @return	None
240  */
241 void ia_css_debug_dump_pif_a_isp_fifo_state(void);
242 
243 /*! \brief Dump pif B isp fifo state
244  * Dumps the primary input formatter state to tracing output.
245  * \return	None
246  */
247 void ia_css_debug_dump_pif_b_isp_fifo_state(void);
248 
249 /*! @brief Dump stream-to-memory sp fifo state
250  * Dumps the stream-to-memory block state to tracing output.
251  * @return	None
252  */
253 void ia_css_debug_dump_str2mem_sp_fifo_state(void);
254 
255 /*! @brief Dump isp sp fifo state
256  * Dumps the isp sp fifo state to tracing output.
257  * @return	None
258  */
259 void ia_css_debug_dump_isp_sp_fifo_state(void);
260 
261 /*! @brief Dump all fifo state info to the output
262  * Dumps all fifo state to tracing output.
263  * @return	None
264  */
265 void ia_css_debug_dump_all_fifo_state(void);
266 
267 /*! @brief Dump the rx state to the output
268  * Dumps the rx state to tracing output.
269  * @return	None
270  */
271 void ia_css_debug_dump_rx_state(void);
272 
273 /*! @brief Dump the input system state to the output
274  * Dumps the input system state to tracing output.
275  * @return	None
276  */
277 void ia_css_debug_dump_isys_state(void);
278 
279 /*! @brief Dump the frame info to the trace output
280  * Dumps the frame info to tracing output.
281  * @param[in]	frame		pointer to struct ia_css_frame
282  * @param[in]	descr		description output along with the frame info
283  * @return	None
284  */
285 void ia_css_debug_frame_print(
286     const struct ia_css_frame	*frame,
287     const char	*descr);
288 
289 /*! @brief Function to enable sp sleep mode.
290  * Function that enables sp sleep mode
291  * @param[in]	mode		indicates when to put sp to sleep
292  * @return	None
293  */
294 void ia_css_debug_enable_sp_sleep_mode(enum ia_css_sp_sleep_mode mode);
295 
296 /*! @brief Function to wake up sp when in sleep mode.
297  * After sp has been put to sleep, use this function to let it continue
298  * to run again.
299  * @return	None
300  */
301 void ia_css_debug_wake_up_sp(void);
302 
303 /*! @brief Function to dump isp parameters.
304  * Dump isp parameters to tracing output
305  * @param[in]	stream		pointer to ia_css_stream struct
306  * @param[in]	enable		flag indicating which parameters to dump.
307  * @return	None
308  */
309 void ia_css_debug_dump_isp_params(struct ia_css_stream *stream,
310 				  unsigned int enable);
311 
312 /*! @brief Function to dump some sp performance counters.
313  * Dump sp performance counters, currently input system errors.
314  * @return	None
315  */
316 void ia_css_debug_dump_perf_counters(void);
317 
318 #ifdef HAS_WATCHDOG_SP_THREAD_DEBUG
319 void sh_css_dump_thread_wait_info(void);
320 void sh_css_dump_pipe_stage_info(void);
321 void sh_css_dump_pipe_stripe_info(void);
322 #endif
323 
324 void ia_css_debug_dump_isp_binary(void);
325 
326 void sh_css_dump_sp_raw_copy_linecount(bool reduced);
327 
328 /*! @brief Dump the resolution info to the trace output
329  * Dumps the resolution info to the trace output.
330  * @param[in]	res	pointer to struct ia_css_resolution
331  * @param[in]	label	description of resolution output
332  * @return	None
333  */
334 void ia_css_debug_dump_resolution(
335     const struct ia_css_resolution *res,
336     const char *label);
337 
338 /*! @brief Dump the frame info to the trace output
339  * Dumps the frame info to the trace output.
340  * @param[in]	info	pointer to struct ia_css_frame_info
341  * @param[in]	label	description of frame_info output
342  * @return	None
343  */
344 void ia_css_debug_dump_frame_info(
345     const struct ia_css_frame_info *info,
346     const char *label);
347 
348 /*! @brief Dump the capture config info to the trace output
349  * Dumps the capture config info to the trace output.
350  * @param[in]	config	pointer to struct ia_css_capture_config
351  * @return	None
352  */
353 void ia_css_debug_dump_capture_config(
354     const struct ia_css_capture_config *config);
355 
356 /*! @brief Dump the pipe extra config info to the trace output
357  * Dumps the pipe extra config info to the trace output.
358  * @param[in]	extra_config	pointer to struct ia_css_pipe_extra_config
359  * @return	None
360  */
361 void ia_css_debug_dump_pipe_extra_config(
362     const struct ia_css_pipe_extra_config *extra_config);
363 
364 /*! @brief Dump the pipe config info to the trace output
365  * Dumps the pipe config info to the trace output.
366  * @param[in]	config	pointer to struct ia_css_pipe_config
367  * @return	None
368  */
369 void ia_css_debug_dump_pipe_config(
370     const struct ia_css_pipe_config *config);
371 
372 /*! @brief Dump the stream config source info to the trace output
373  * Dumps the stream config source info to the trace output.
374  * @param[in]	config	pointer to struct ia_css_stream_config
375  * @return	None
376  */
377 void ia_css_debug_dump_stream_config_source(
378     const struct ia_css_stream_config *config);
379 
380 /*! @brief Dump the mipi buffer config info to the trace output
381  * Dumps the mipi buffer config info to the trace output.
382  * @param[in]	config	pointer to struct ia_css_mipi_buffer_config
383  * @return	None
384  */
385 void ia_css_debug_dump_mipi_buffer_config(
386     const struct ia_css_mipi_buffer_config *config);
387 
388 /*! @brief Dump the metadata config info to the trace output
389  * Dumps the metadata config info to the trace output.
390  * @param[in]	config	pointer to struct ia_css_metadata_config
391  * @return	None
392  */
393 void ia_css_debug_dump_metadata_config(
394     const struct ia_css_metadata_config *config);
395 
396 /*! @brief Dump the stream config info to the trace output
397  * Dumps the stream config info to the trace output.
398  * @param[in]	config		pointer to struct ia_css_stream_config
399  * @param[in]	num_pipes	number of pipes for the stream
400  * @return	None
401  */
402 void ia_css_debug_dump_stream_config(
403     const struct ia_css_stream_config *config,
404     int num_pipes);
405 
406 /*! @brief Dump the state of the SP tagger
407  * Dumps the internal state of the SP tagger
408  * @return	None
409  */
410 void ia_css_debug_tagger_state(void);
411 
412 /**
413  * @brief Initialize the debug mode.
414  *
415  * WARNING:
416  * This API should be called ONLY once in the debug mode.
417  *
418  * @return
419  *	- true, if it is successful.
420  *	- false, otherwise.
421  */
422 bool ia_css_debug_mode_init(void);
423 
424 /**
425  * @brief Disable the DMA channel.
426  *
427  * @param[in]	dma_ID		The ID of the target DMA.
428  * @param[in]	channel_id	The ID of the target DMA channel.
429  * @param[in]	request_type	The type of the DMA request.
430  *				For example:
431  *				- "0" indicates the writing request.
432  *				- "1" indicates the reading request.
433  *
434  * This is part of the DMA API -> dma.h
435  *
436  * @return
437  *	- true, if it is successful.
438  *	- false, otherwise.
439  */
440 bool ia_css_debug_mode_disable_dma_channel(
441     int dma_ID,
442     int channel_id,
443     int request_type);
444 /**
445  * @brief Enable the DMA channel.
446  *
447  * @param[in]	dma_ID		The ID of the target DMA.
448  * @param[in]	channel_id	The ID of the target DMA channel.
449  * @param[in]	request_type	The type of the DMA request.
450  *				For example:
451  *				- "0" indicates the writing request.
452  *				- "1" indicates the reading request.
453  *
454  * @return
455  *	- true, if it is successful.
456  *	- false, otherwise.
457  */
458 bool ia_css_debug_mode_enable_dma_channel(
459     int dma_ID,
460     int channel_id,
461     int request_type);
462 
463 /**
464  * @brief Dump tracer data.
465  * [Currently support is only for SKC]
466  *
467  * @return
468  *	- none.
469  */
470 void ia_css_debug_dump_trace(void);
471 
472 /* ISP2401 */
473 /**
474  * @brief Program counter dumping (in loop)
475  *
476  * @param[in]	id		The ID of the SP
477  * @param[in]	num_of_dumps	The number of dumps
478  *
479  * @return
480  *	- none
481  */
482 void ia_css_debug_pc_dump(sp_ID_t id, unsigned int num_of_dumps);
483 
484 /* ISP2500 */
485 /*! @brief Dump all states for ISP hang case.
486  * Dumps the ISP previous and current configurations
487  * GACs status, SP0/1 statuses.
488  *
489  * @param[in]	pipe	The current pipe
490  *
491  * @return	None
492  */
493 void ia_css_debug_dump_hang_status(
494     struct ia_css_pipe *pipe);
495 
496 /*! @brief External command handler
497  * External command handler
498  *
499  * @return	None
500  */
501 void ia_css_debug_ext_command_handler(void);
502 
503 #endif /* _IA_CSS_DEBUG_H_ */
504