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