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 */ 51extern 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 */ 56enum 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 */ 133static 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 145/*! @brief Function to set the global dtrace verbosity level. 146 * @param[in] trace_level Maximum level of the messages to be traced. 147 * @return None 148 */ 149void ia_css_debug_set_dtrace_level( 150 const unsigned int trace_level); 151 152/*! @brief Function to get the global dtrace verbosity level. 153 * @return global dtrace verbosity level 154 */ 155unsigned int ia_css_debug_get_dtrace_level(void); 156 157/* ISP2401 */ 158/*! @brief Dump GAC hardware state. 159 * Dumps the GAC ACB hardware registers. may be useful for 160 * detecting a GAC which got hang. 161 * @return None 162 */ 163void ia_css_debug_dump_gac_state(void); 164 165/*! @brief Dump internal sp software state. 166 * Dumps the sp software state to tracing output. 167 * @return None 168 */ 169void ia_css_debug_dump_sp_sw_debug_info(void); 170 171#if SP_DEBUG != SP_DEBUG_NONE 172void ia_css_debug_print_sp_debug_state( 173 const struct sh_css_sp_debug_state *state); 174#endif 175 176/*! @brief Dump all related binary info data 177 * @param[in] bi Binary info struct. 178 * @return None 179 */ 180void ia_css_debug_binary_print( 181 const struct ia_css_binary *bi); 182 183void ia_css_debug_sp_dump_mipi_fifo_high_water(void); 184 185/*! \brief Dump pif A isp fifo state 186 * Dumps the primary input formatter state to tracing output. 187 * @return None 188 */ 189void ia_css_debug_dump_pif_a_isp_fifo_state(void); 190 191/*! \brief Dump pif B isp fifo state 192 * Dumps the primary input formatter state to tracing output. 193 * \return None 194 */ 195void ia_css_debug_dump_pif_b_isp_fifo_state(void); 196 197/*! @brief Dump stream-to-memory sp fifo state 198 * Dumps the stream-to-memory block state to tracing output. 199 * @return None 200 */ 201void ia_css_debug_dump_str2mem_sp_fifo_state(void); 202 203/*! @brief Dump all fifo state info to the output 204 * Dumps all fifo state to tracing output. 205 * @return None 206 */ 207void ia_css_debug_dump_all_fifo_state(void); 208 209/*! @brief Dump the frame info to the trace output 210 * Dumps the frame info to tracing output. 211 * @param[in] frame pointer to struct ia_css_frame 212 * @param[in] descr description output along with the frame info 213 * @return None 214 */ 215void ia_css_debug_frame_print( 216 const struct ia_css_frame *frame, 217 const char *descr); 218 219/*! @brief Function to enable sp sleep mode. 220 * Function that enables sp sleep mode 221 * @param[in] mode indicates when to put sp to sleep 222 * @return None 223 */ 224void ia_css_debug_enable_sp_sleep_mode(enum ia_css_sp_sleep_mode mode); 225 226/*! @brief Function to wake up sp when in sleep mode. 227 * After sp has been put to sleep, use this function to let it continue 228 * to run again. 229 * @return None 230 */ 231void ia_css_debug_wake_up_sp(void); 232 233/*! @brief Function to dump isp parameters. 234 * Dump isp parameters to tracing output 235 * @param[in] stream pointer to ia_css_stream struct 236 * @param[in] enable flag indicating which parameters to dump. 237 * @return None 238 */ 239void ia_css_debug_dump_isp_params(struct ia_css_stream *stream, 240 unsigned int enable); 241 242void ia_css_debug_dump_isp_binary(void); 243 244void sh_css_dump_sp_raw_copy_linecount(bool reduced); 245 246/*! @brief Dump the resolution info to the trace output 247 * Dumps the resolution info to the trace output. 248 * @param[in] res pointer to struct ia_css_resolution 249 * @param[in] label description of resolution output 250 * @return None 251 */ 252void ia_css_debug_dump_resolution( 253 const struct ia_css_resolution *res, 254 const char *label); 255 256/*! @brief Dump the frame info to the trace output 257 * Dumps the frame info to the trace output. 258 * @param[in] info pointer to struct ia_css_frame_info 259 * @param[in] label description of frame_info output 260 * @return None 261 */ 262void ia_css_debug_dump_frame_info( 263 const struct ia_css_frame_info *info, 264 const char *label); 265 266/*! @brief Dump the capture config info to the trace output 267 * Dumps the capture config info to the trace output. 268 * @param[in] config pointer to struct ia_css_capture_config 269 * @return None 270 */ 271void ia_css_debug_dump_capture_config( 272 const struct ia_css_capture_config *config); 273 274/*! @brief Dump the pipe extra config info to the trace output 275 * Dumps the pipe extra config info to the trace output. 276 * @param[in] extra_config pointer to struct ia_css_pipe_extra_config 277 * @return None 278 */ 279void ia_css_debug_dump_pipe_extra_config( 280 const struct ia_css_pipe_extra_config *extra_config); 281 282/*! @brief Dump the pipe config info to the trace output 283 * Dumps the pipe config info to the trace output. 284 * @param[in] config pointer to struct ia_css_pipe_config 285 * @return None 286 */ 287void ia_css_debug_dump_pipe_config( 288 const struct ia_css_pipe_config *config); 289 290/*! @brief Dump the stream config source info to the trace output 291 * Dumps the stream config source info to the trace output. 292 * @param[in] config pointer to struct ia_css_stream_config 293 * @return None 294 */ 295void ia_css_debug_dump_stream_config_source( 296 const struct ia_css_stream_config *config); 297 298/*! @brief Dump the mipi buffer config info to the trace output 299 * Dumps the mipi buffer config info to the trace output. 300 * @param[in] config pointer to struct ia_css_mipi_buffer_config 301 * @return None 302 */ 303void ia_css_debug_dump_mipi_buffer_config( 304 const struct ia_css_mipi_buffer_config *config); 305 306/*! @brief Dump the metadata config info to the trace output 307 * Dumps the metadata config info to the trace output. 308 * @param[in] config pointer to struct ia_css_metadata_config 309 * @return None 310 */ 311void ia_css_debug_dump_metadata_config( 312 const struct ia_css_metadata_config *config); 313 314/*! @brief Dump the stream config info to the trace output 315 * Dumps the stream config info to the trace output. 316 * @param[in] config pointer to struct ia_css_stream_config 317 * @param[in] num_pipes number of pipes for the stream 318 * @return None 319 */ 320void ia_css_debug_dump_stream_config( 321 const struct ia_css_stream_config *config, 322 int num_pipes); 323 324/** 325 * @brief Initialize the debug mode. 326 * 327 * WARNING: 328 * This API should be called ONLY once in the debug mode. 329 * 330 * @return 331 * - true, if it is successful. 332 * - false, otherwise. 333 */ 334bool ia_css_debug_mode_init(void); 335 336/** 337 * @brief Disable the DMA channel. 338 * 339 * @param[in] dma_ID The ID of the target DMA. 340 * @param[in] channel_id The ID of the target DMA channel. 341 * @param[in] request_type The type of the DMA request. 342 * For example: 343 * - "0" indicates the writing request. 344 * - "1" indicates the reading request. 345 * 346 * This is part of the DMA API -> dma.h 347 * 348 * @return 349 * - true, if it is successful. 350 * - false, otherwise. 351 */ 352bool ia_css_debug_mode_disable_dma_channel( 353 int dma_ID, 354 int channel_id, 355 int request_type); 356/** 357 * @brief Enable the DMA channel. 358 * 359 * @param[in] dma_ID The ID of the target DMA. 360 * @param[in] channel_id The ID of the target DMA channel. 361 * @param[in] request_type The type of the DMA request. 362 * For example: 363 * - "0" indicates the writing request. 364 * - "1" indicates the reading request. 365 * 366 * @return 367 * - true, if it is successful. 368 * - false, otherwise. 369 */ 370bool ia_css_debug_mode_enable_dma_channel( 371 int dma_ID, 372 int channel_id, 373 int request_type); 374 375/** 376 * @brief Dump tracer data. 377 * [Currently support is only for SKC] 378 * 379 * @return 380 * - none. 381 */ 382void ia_css_debug_dump_trace(void); 383 384/* ISP2401 */ 385/** 386 * @brief Program counter dumping (in loop) 387 * 388 * @param[in] id The ID of the SP 389 * @param[in] num_of_dumps The number of dumps 390 * 391 * @return 392 * - none 393 */ 394void ia_css_debug_pc_dump(sp_ID_t id, unsigned int num_of_dumps); 395 396/* ISP2500 */ 397/*! @brief Dump all states for ISP hang case. 398 * Dumps the ISP previous and current configurations 399 * GACs status, SP0/1 statuses. 400 * 401 * @param[in] pipe The current pipe 402 * 403 * @return None 404 */ 405void ia_css_debug_dump_hang_status( 406 struct ia_css_pipe *pipe); 407 408/*! @brief External command handler 409 * External command handler 410 * 411 * @return None 412 */ 413void ia_css_debug_ext_command_handler(void); 414 415#endif /* _IA_CSS_DEBUG_H_ */ 416