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 <linux/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 __printf(2, 0) ia_css_debug_vdtrace(unsigned int level, 133 const char *fmt, 134 va_list args) 135 { 136 if (dbg_level >= level) 137 sh_css_vprint(fmt, args); 138 } 139 140 __printf(2, 3) void ia_css_debug_dtrace(unsigned int level, 141 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 isp hardware state. 163 * Dumps the isp hardware state to tracing output. 164 * @return None 165 */ 166 void ia_css_debug_dump_isp_state(void); 167 168 /*! @brief Dump sp hardware state. 169 * Dumps the sp hardware state to tracing output. 170 * @return None 171 */ 172 void ia_css_debug_dump_sp_state(void); 173 174 /* ISP2401 */ 175 /*! @brief Dump GAC hardware state. 176 * Dumps the GAC ACB hardware registers. may be useful for 177 * detecting a GAC which got hang. 178 * @return None 179 */ 180 void ia_css_debug_dump_gac_state(void); 181 182 /*! @brief Dump dma controller state. 183 * Dumps the dma controller state to tracing output. 184 * @return None 185 */ 186 void ia_css_debug_dump_dma_state(void); 187 188 /*! @brief Dump internal sp software state. 189 * Dumps the sp software state to tracing output. 190 * @return None 191 */ 192 void ia_css_debug_dump_sp_sw_debug_info(void); 193 194 /*! @brief Dump all related hardware state to the trace output 195 * @param[in] context String to identify context in output. 196 * @return None 197 */ 198 void ia_css_debug_dump_debug_info( 199 const char *context); 200 201 #if SP_DEBUG != SP_DEBUG_NONE 202 void ia_css_debug_print_sp_debug_state( 203 const struct sh_css_sp_debug_state *state); 204 #endif 205 206 /*! @brief Dump all related binary info data 207 * @param[in] bi Binary info struct. 208 * @return None 209 */ 210 void ia_css_debug_binary_print( 211 const struct ia_css_binary *bi); 212 213 void ia_css_debug_sp_dump_mipi_fifo_high_water(void); 214 215 /*! @brief Dump isp gdc fifo state to the trace output 216 * Dumps the isp gdc fifo state to tracing output. 217 * @return None 218 */ 219 void ia_css_debug_dump_isp_gdc_fifo_state(void); 220 221 /*! @brief Dump dma isp fifo state 222 * Dumps the dma isp fifo state to tracing output. 223 * @return None 224 */ 225 void ia_css_debug_dump_dma_isp_fifo_state(void); 226 227 /*! @brief Dump dma sp fifo state 228 * Dumps the dma sp fifo state to tracing output. 229 * @return None 230 */ 231 void ia_css_debug_dump_dma_sp_fifo_state(void); 232 233 /*! \brief Dump pif A isp fifo state 234 * Dumps the primary input formatter state to tracing output. 235 * @return None 236 */ 237 void ia_css_debug_dump_pif_a_isp_fifo_state(void); 238 239 /*! \brief Dump pif B isp fifo state 240 * Dumps the primary input formatter state to tracing output. 241 * \return None 242 */ 243 void ia_css_debug_dump_pif_b_isp_fifo_state(void); 244 245 /*! @brief Dump stream-to-memory sp fifo state 246 * Dumps the stream-to-memory block state to tracing output. 247 * @return None 248 */ 249 void ia_css_debug_dump_str2mem_sp_fifo_state(void); 250 251 /*! @brief Dump isp sp fifo state 252 * Dumps the isp sp fifo state to tracing output. 253 * @return None 254 */ 255 void ia_css_debug_dump_isp_sp_fifo_state(void); 256 257 /*! @brief Dump all fifo state info to the output 258 * Dumps all fifo state to tracing output. 259 * @return None 260 */ 261 void ia_css_debug_dump_all_fifo_state(void); 262 263 /*! @brief Dump the rx state to the output 264 * Dumps the rx state to tracing output. 265 * @return None 266 */ 267 void ia_css_debug_dump_rx_state(void); 268 269 /*! @brief Dump the input system state to the output 270 * Dumps the input system state to tracing output. 271 * @return None 272 */ 273 void ia_css_debug_dump_isys_state(void); 274 275 /*! @brief Dump the frame info to the trace output 276 * Dumps the frame info to tracing output. 277 * @param[in] frame pointer to struct ia_css_frame 278 * @param[in] descr description output along with the frame info 279 * @return None 280 */ 281 void ia_css_debug_frame_print( 282 const struct ia_css_frame *frame, 283 const char *descr); 284 285 /*! @brief Function to enable sp sleep mode. 286 * Function that enables sp sleep mode 287 * @param[in] mode indicates when to put sp to sleep 288 * @return None 289 */ 290 void ia_css_debug_enable_sp_sleep_mode(enum ia_css_sp_sleep_mode mode); 291 292 /*! @brief Function to wake up sp when in sleep mode. 293 * After sp has been put to sleep, use this function to let it continue 294 * to run again. 295 * @return None 296 */ 297 void ia_css_debug_wake_up_sp(void); 298 299 /*! @brief Function to dump isp parameters. 300 * Dump isp parameters to tracing output 301 * @param[in] stream pointer to ia_css_stream struct 302 * @param[in] enable flag indicating which parameters to dump. 303 * @return None 304 */ 305 void ia_css_debug_dump_isp_params(struct ia_css_stream *stream, 306 unsigned int enable); 307 308 /*! @brief Function to dump some sp performance counters. 309 * Dump sp performance counters, currently input system errors. 310 * @return None 311 */ 312 void ia_css_debug_dump_perf_counters(void); 313 314 #ifdef HAS_WATCHDOG_SP_THREAD_DEBUG 315 void sh_css_dump_thread_wait_info(void); 316 void sh_css_dump_pipe_stage_info(void); 317 void sh_css_dump_pipe_stripe_info(void); 318 #endif 319 320 void ia_css_debug_dump_isp_binary(void); 321 322 void sh_css_dump_sp_raw_copy_linecount(bool reduced); 323 324 /*! @brief Dump the resolution info to the trace output 325 * Dumps the resolution info to the trace output. 326 * @param[in] res pointer to struct ia_css_resolution 327 * @param[in] label description of resolution output 328 * @return None 329 */ 330 void ia_css_debug_dump_resolution( 331 const struct ia_css_resolution *res, 332 const char *label); 333 334 /*! @brief Dump the frame info to the trace output 335 * Dumps the frame info to the trace output. 336 * @param[in] info pointer to struct ia_css_frame_info 337 * @param[in] label description of frame_info output 338 * @return None 339 */ 340 void ia_css_debug_dump_frame_info( 341 const struct ia_css_frame_info *info, 342 const char *label); 343 344 /*! @brief Dump the capture config info to the trace output 345 * Dumps the capture config info to the trace output. 346 * @param[in] config pointer to struct ia_css_capture_config 347 * @return None 348 */ 349 void ia_css_debug_dump_capture_config( 350 const struct ia_css_capture_config *config); 351 352 /*! @brief Dump the pipe extra config info to the trace output 353 * Dumps the pipe extra config info to the trace output. 354 * @param[in] extra_config pointer to struct ia_css_pipe_extra_config 355 * @return None 356 */ 357 void ia_css_debug_dump_pipe_extra_config( 358 const struct ia_css_pipe_extra_config *extra_config); 359 360 /*! @brief Dump the pipe config info to the trace output 361 * Dumps the pipe config info to the trace output. 362 * @param[in] config pointer to struct ia_css_pipe_config 363 * @return None 364 */ 365 void ia_css_debug_dump_pipe_config( 366 const struct ia_css_pipe_config *config); 367 368 /*! @brief Dump the stream config source info to the trace output 369 * Dumps the stream config source info to the trace output. 370 * @param[in] config pointer to struct ia_css_stream_config 371 * @return None 372 */ 373 void ia_css_debug_dump_stream_config_source( 374 const struct ia_css_stream_config *config); 375 376 /*! @brief Dump the mipi buffer config info to the trace output 377 * Dumps the mipi buffer config info to the trace output. 378 * @param[in] config pointer to struct ia_css_mipi_buffer_config 379 * @return None 380 */ 381 void ia_css_debug_dump_mipi_buffer_config( 382 const struct ia_css_mipi_buffer_config *config); 383 384 /*! @brief Dump the metadata config info to the trace output 385 * Dumps the metadata config info to the trace output. 386 * @param[in] config pointer to struct ia_css_metadata_config 387 * @return None 388 */ 389 void ia_css_debug_dump_metadata_config( 390 const struct ia_css_metadata_config *config); 391 392 /*! @brief Dump the stream config info to the trace output 393 * Dumps the stream config info to the trace output. 394 * @param[in] config pointer to struct ia_css_stream_config 395 * @param[in] num_pipes number of pipes for the stream 396 * @return None 397 */ 398 void ia_css_debug_dump_stream_config( 399 const struct ia_css_stream_config *config, 400 int num_pipes); 401 402 /*! @brief Dump the state of the SP tagger 403 * Dumps the internal state of the SP tagger 404 * @return None 405 */ 406 void ia_css_debug_tagger_state(void); 407 408 /** 409 * @brief Initialize the debug mode. 410 * 411 * WARNING: 412 * This API should be called ONLY once in the debug mode. 413 * 414 * @return 415 * - true, if it is successful. 416 * - false, otherwise. 417 */ 418 bool ia_css_debug_mode_init(void); 419 420 /** 421 * @brief Disable the DMA channel. 422 * 423 * @param[in] dma_ID The ID of the target DMA. 424 * @param[in] channel_id The ID of the target DMA channel. 425 * @param[in] request_type The type of the DMA request. 426 * For example: 427 * - "0" indicates the writing request. 428 * - "1" indicates the reading request. 429 * 430 * This is part of the DMA API -> dma.h 431 * 432 * @return 433 * - true, if it is successful. 434 * - false, otherwise. 435 */ 436 bool ia_css_debug_mode_disable_dma_channel( 437 int dma_ID, 438 int channel_id, 439 int request_type); 440 /** 441 * @brief Enable the DMA channel. 442 * 443 * @param[in] dma_ID The ID of the target DMA. 444 * @param[in] channel_id The ID of the target DMA channel. 445 * @param[in] request_type The type of the DMA request. 446 * For example: 447 * - "0" indicates the writing request. 448 * - "1" indicates the reading request. 449 * 450 * @return 451 * - true, if it is successful. 452 * - false, otherwise. 453 */ 454 bool ia_css_debug_mode_enable_dma_channel( 455 int dma_ID, 456 int channel_id, 457 int request_type); 458 459 /** 460 * @brief Dump tracer data. 461 * [Currently support is only for SKC] 462 * 463 * @return 464 * - none. 465 */ 466 void ia_css_debug_dump_trace(void); 467 468 /* ISP2401 */ 469 /** 470 * @brief Program counter dumping (in loop) 471 * 472 * @param[in] id The ID of the SP 473 * @param[in] num_of_dumps The number of dumps 474 * 475 * @return 476 * - none 477 */ 478 void ia_css_debug_pc_dump(sp_ID_t id, unsigned int num_of_dumps); 479 480 /* ISP2500 */ 481 /*! @brief Dump all states for ISP hang case. 482 * Dumps the ISP previous and current configurations 483 * GACs status, SP0/1 statuses. 484 * 485 * @param[in] pipe The current pipe 486 * 487 * @return None 488 */ 489 void ia_css_debug_dump_hang_status( 490 struct ia_css_pipe *pipe); 491 492 /*! @brief External command handler 493 * External command handler 494 * 495 * @return None 496 */ 497 void ia_css_debug_ext_command_handler(void); 498 499 #endif /* _IA_CSS_DEBUG_H_ */ 500