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