xref: /rk3399_ARM-atf/include/common/debug.h (revision 7e619ecc89355136c27d0295858e08c808aa6373)
14ecca339SDan Handley /*
2*7e619eccSGovindraj Raja  * Copyright (c) 2013-2023, Arm Limited and Contributors. All rights reserved.
34ecca339SDan Handley  *
482cb2c1aSdp-arm  * SPDX-License-Identifier: BSD-3-Clause
54ecca339SDan Handley  */
64ecca339SDan Handley 
7870ce3ddSAntonio Nino Diaz #ifndef DEBUG_H
8870ce3ddSAntonio Nino Diaz #define DEBUG_H
94ecca339SDan Handley 
1009d40e0eSAntonio Nino Diaz #include <lib/utils_def.h>
115a22e461SAntonio Nino Diaz 
12cf24229eSSandrine Bailleux /*
13cf24229eSSandrine Bailleux  * The log output macros print output to the console. These macros produce
14289c28a8SDan Handley  * compiled log output only if the LOG_LEVEL defined in the makefile (or the
15289c28a8SDan Handley  * make command line) is greater or equal than the level required for that
16289c28a8SDan Handley  * type of log output.
17cf24229eSSandrine Bailleux  *
18289c28a8SDan Handley  * The format expected is the same as for printf(). For example:
194ecca339SDan Handley  * INFO("Info %s.\n", "message")    -> INFO:    Info message.
20289c28a8SDan Handley  * WARN("Warning %s.\n", "message") -> WARNING: Warning message.
214ecca339SDan Handley  */
22289c28a8SDan Handley 
235a22e461SAntonio Nino Diaz #define LOG_LEVEL_NONE			U(0)
245a22e461SAntonio Nino Diaz #define LOG_LEVEL_ERROR			U(10)
255a22e461SAntonio Nino Diaz #define LOG_LEVEL_NOTICE		U(20)
265a22e461SAntonio Nino Diaz #define LOG_LEVEL_WARNING		U(30)
275a22e461SAntonio Nino Diaz #define LOG_LEVEL_INFO			U(40)
285a22e461SAntonio Nino Diaz #define LOG_LEVEL_VERBOSE		U(50)
29289c28a8SDan Handley 
30d5dfdeb6SJulius Werner #ifndef __ASSEMBLER__
3109d40e0eSAntonio Nino Diaz 
3293c78ed2SAntonio Nino Diaz #include <cdefs.h>
332d7e8282SSoby Mathew #include <stdarg.h>
343e530d8eSAntonio Nino Diaz #include <stdbool.h>
351319e7b1SSoby Mathew #include <stdio.h>
36289c28a8SDan Handley 
3709d40e0eSAntonio Nino Diaz #include <drivers/console.h>
3809d40e0eSAntonio Nino Diaz 
397f56e9a3SSoby Mathew /*
407f56e9a3SSoby Mathew  * Define Log Markers corresponding to each log level which will
417f56e9a3SSoby Mathew  * be embedded in the format string and is expected by tf_log() to determine
427f56e9a3SSoby Mathew  * the log level.
437f56e9a3SSoby Mathew  */
447f56e9a3SSoby Mathew #define LOG_MARKER_ERROR		"\xa"	/* 10 */
457f56e9a3SSoby Mathew #define LOG_MARKER_NOTICE		"\x14"	/* 20 */
467f56e9a3SSoby Mathew #define LOG_MARKER_WARNING		"\x1e"	/* 30 */
477f56e9a3SSoby Mathew #define LOG_MARKER_INFO			"\x28"	/* 40 */
487f56e9a3SSoby Mathew #define LOG_MARKER_VERBOSE		"\x32"	/* 50 */
497f56e9a3SSoby Mathew 
50cf24229eSSandrine Bailleux /*
51cf24229eSSandrine Bailleux  * If the log output is too low then this macro is used in place of tf_log()
52cf24229eSSandrine Bailleux  * below. The intent is to get the compiler to evaluate the function call for
53cf24229eSSandrine Bailleux  * type checking and format specifier correctness but let it optimize it out.
54cf24229eSSandrine Bailleux  */
55cf24229eSSandrine Bailleux #define no_tf_log(fmt, ...)				\
56cf24229eSSandrine Bailleux 	do {						\
575a22e461SAntonio Nino Diaz 		if (false) {				\
58cf24229eSSandrine Bailleux 			tf_log(fmt, ##__VA_ARGS__);	\
59cf24229eSSandrine Bailleux 		}					\
605a22e461SAntonio Nino Diaz 	} while (false)
61cf24229eSSandrine Bailleux 
62289c28a8SDan Handley #if LOG_LEVEL >= LOG_LEVEL_ERROR
637f56e9a3SSoby Mathew # define ERROR(...)	tf_log(LOG_MARKER_ERROR __VA_ARGS__)
64fd1360a3SPali Rohár # define ERROR_NL()	tf_log_newline(LOG_MARKER_ERROR)
65289c28a8SDan Handley #else
66cf24229eSSandrine Bailleux # define ERROR(...)	no_tf_log(LOG_MARKER_ERROR __VA_ARGS__)
67fd1360a3SPali Rohár # define ERROR_NL()
68289c28a8SDan Handley #endif
69289c28a8SDan Handley 
70701b498cSJohn Tsichritzis #if LOG_LEVEL >= LOG_LEVEL_NOTICE
71701b498cSJohn Tsichritzis # define NOTICE(...)	tf_log(LOG_MARKER_NOTICE __VA_ARGS__)
72701b498cSJohn Tsichritzis #else
73701b498cSJohn Tsichritzis # define NOTICE(...)	no_tf_log(LOG_MARKER_NOTICE __VA_ARGS__)
74701b498cSJohn Tsichritzis #endif
75701b498cSJohn Tsichritzis 
76289c28a8SDan Handley #if LOG_LEVEL >= LOG_LEVEL_WARNING
777f56e9a3SSoby Mathew # define WARN(...)	tf_log(LOG_MARKER_WARNING __VA_ARGS__)
78289c28a8SDan Handley #else
79cf24229eSSandrine Bailleux # define WARN(...)	no_tf_log(LOG_MARKER_WARNING __VA_ARGS__)
804ecca339SDan Handley #endif
814ecca339SDan Handley 
82289c28a8SDan Handley #if LOG_LEVEL >= LOG_LEVEL_INFO
837f56e9a3SSoby Mathew # define INFO(...)	tf_log(LOG_MARKER_INFO __VA_ARGS__)
84289c28a8SDan Handley #else
85cf24229eSSandrine Bailleux # define INFO(...)	no_tf_log(LOG_MARKER_INFO __VA_ARGS__)
86289c28a8SDan Handley #endif
87289c28a8SDan Handley 
88289c28a8SDan Handley #if LOG_LEVEL >= LOG_LEVEL_VERBOSE
897f56e9a3SSoby Mathew # define VERBOSE(...)	tf_log(LOG_MARKER_VERBOSE __VA_ARGS__)
90289c28a8SDan Handley #else
91cf24229eSSandrine Bailleux # define VERBOSE(...)	no_tf_log(LOG_MARKER_VERBOSE __VA_ARGS__)
92289c28a8SDan Handley #endif
93289c28a8SDan Handley 
940ae4a3a3SManish Pandey const char *get_el_str(unsigned int el);
950ae4a3a3SManish Pandey 
960c62883fSDouglas Raillard #if ENABLE_BACKTRACE
970c62883fSDouglas Raillard void backtrace(const char *cookie);
980c62883fSDouglas Raillard #else
990c62883fSDouglas Raillard #define backtrace(x)
1000c62883fSDouglas Raillard #endif
1010c62883fSDouglas Raillard 
102c6bc0710SDan Handley void __dead2 do_panic(void);
103*7e619eccSGovindraj Raja void __dead2 report_elx_panic(void);
1043e530d8eSAntonio Nino Diaz 
1053e530d8eSAntonio Nino Diaz #define panic()				\
1063e530d8eSAntonio Nino Diaz 	do {				\
1073e530d8eSAntonio Nino Diaz 		backtrace(__func__);	\
108831b0e98SJimmy Brisson 		console_flush();	\
1093e530d8eSAntonio Nino Diaz 		do_panic();		\
1103e530d8eSAntonio Nino Diaz 	} while (false)
111a43d431bSSoby Mathew 
112*7e619eccSGovindraj Raja #if CRASH_REPORTING
113*7e619eccSGovindraj Raja /* --------------------------------------------------------------------
114*7e619eccSGovindraj Raja  * do_lower_el_panic assumes it's called due to a panic from a lower EL
115*7e619eccSGovindraj Raja  * This call will not return.
116*7e619eccSGovindraj Raja  * --------------------------------------------------------------------
117*7e619eccSGovindraj Raja  */
118*7e619eccSGovindraj Raja #define	lower_el_panic()		\
119*7e619eccSGovindraj Raja 	do {				\
120*7e619eccSGovindraj Raja 		console_flush();	\
121*7e619eccSGovindraj Raja 		report_elx_panic();	\
122*7e619eccSGovindraj Raja 	} while (false)
123*7e619eccSGovindraj Raja #else
124*7e619eccSGovindraj Raja #define	lower_el_panic()
125*7e619eccSGovindraj Raja #endif
126*7e619eccSGovindraj Raja 
12751faada7SDouglas Raillard /* Function called when stack protection check code detects a corrupted stack */
12851faada7SDouglas Raillard void __dead2 __stack_chk_fail(void);
12951faada7SDouglas Raillard 
1307f56e9a3SSoby Mathew void tf_log(const char *fmt, ...) __printflike(1, 2);
131fd1360a3SPali Rohár void tf_log_newline(const char log_fmt[2]);
1327f56e9a3SSoby Mathew void tf_log_set_max_level(unsigned int log_level);
133b79af934SSoby Mathew 
134d5dfdeb6SJulius Werner #endif /* __ASSEMBLER__ */
135870ce3ddSAntonio Nino Diaz #endif /* DEBUG_H */
136