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