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