xref: /rk3399_ARM-atf/include/common/debug.h (revision 5a22e461b5841795c592a08b14c949c46c74e261)
14ecca339SDan Handley /*
2cf24229eSSandrine Bailleux  * Copyright (c) 2013-2018, 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 
10*5a22e461SAntonio Nino Diaz #include <utils_def.h>
11*5a22e461SAntonio 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 
23*5a22e461SAntonio Nino Diaz #define LOG_LEVEL_NONE			U(0)
24*5a22e461SAntonio Nino Diaz #define LOG_LEVEL_ERROR			U(10)
25*5a22e461SAntonio Nino Diaz #define LOG_LEVEL_NOTICE		U(20)
26*5a22e461SAntonio Nino Diaz #define LOG_LEVEL_WARNING		U(30)
27*5a22e461SAntonio Nino Diaz #define LOG_LEVEL_INFO			U(40)
28*5a22e461SAntonio Nino Diaz #define LOG_LEVEL_VERBOSE		U(50)
29289c28a8SDan Handley 
301319e7b1SSoby Mathew #ifndef __ASSEMBLY__
3193c78ed2SAntonio Nino Diaz #include <cdefs.h>
323e530d8eSAntonio Nino Diaz #include <console.h>
332d7e8282SSoby Mathew #include <stdarg.h>
343e530d8eSAntonio Nino Diaz #include <stdbool.h>
351319e7b1SSoby Mathew #include <stdio.h>
36289c28a8SDan Handley 
377f56e9a3SSoby Mathew /*
387f56e9a3SSoby Mathew  * Define Log Markers corresponding to each log level which will
397f56e9a3SSoby Mathew  * be embedded in the format string and is expected by tf_log() to determine
407f56e9a3SSoby Mathew  * the log level.
417f56e9a3SSoby Mathew  */
427f56e9a3SSoby Mathew #define LOG_MARKER_ERROR		"\xa"	/* 10 */
437f56e9a3SSoby Mathew #define LOG_MARKER_NOTICE		"\x14"	/* 20 */
447f56e9a3SSoby Mathew #define LOG_MARKER_WARNING		"\x1e"	/* 30 */
457f56e9a3SSoby Mathew #define LOG_MARKER_INFO			"\x28"	/* 40 */
467f56e9a3SSoby Mathew #define LOG_MARKER_VERBOSE		"\x32"	/* 50 */
477f56e9a3SSoby Mathew 
48cf24229eSSandrine Bailleux /*
49cf24229eSSandrine Bailleux  * If the log output is too low then this macro is used in place of tf_log()
50cf24229eSSandrine Bailleux  * below. The intent is to get the compiler to evaluate the function call for
51cf24229eSSandrine Bailleux  * type checking and format specifier correctness but let it optimize it out.
52cf24229eSSandrine Bailleux  */
53cf24229eSSandrine Bailleux #define no_tf_log(fmt, ...)				\
54cf24229eSSandrine Bailleux 	do {						\
55*5a22e461SAntonio Nino Diaz 		if (false) {				\
56cf24229eSSandrine Bailleux 			tf_log(fmt, ##__VA_ARGS__);	\
57cf24229eSSandrine Bailleux 		}					\
58*5a22e461SAntonio Nino Diaz 	} while (false)
59cf24229eSSandrine Bailleux 
60289c28a8SDan Handley #if LOG_LEVEL >= LOG_LEVEL_NOTICE
617f56e9a3SSoby Mathew # define NOTICE(...)	tf_log(LOG_MARKER_NOTICE __VA_ARGS__)
624ecca339SDan Handley #else
63cf24229eSSandrine Bailleux # define NOTICE(...)	no_tf_log(LOG_MARKER_NOTICE __VA_ARGS__)
64289c28a8SDan Handley #endif
65289c28a8SDan Handley 
66289c28a8SDan Handley #if LOG_LEVEL >= LOG_LEVEL_ERROR
677f56e9a3SSoby Mathew # define ERROR(...)	tf_log(LOG_MARKER_ERROR __VA_ARGS__)
68289c28a8SDan Handley #else
69cf24229eSSandrine Bailleux # define ERROR(...)	no_tf_log(LOG_MARKER_ERROR __VA_ARGS__)
70289c28a8SDan Handley #endif
71289c28a8SDan Handley 
72289c28a8SDan Handley #if LOG_LEVEL >= LOG_LEVEL_WARNING
737f56e9a3SSoby Mathew # define WARN(...)	tf_log(LOG_MARKER_WARNING __VA_ARGS__)
74289c28a8SDan Handley #else
75cf24229eSSandrine Bailleux # define WARN(...)	no_tf_log(LOG_MARKER_WARNING __VA_ARGS__)
764ecca339SDan Handley #endif
774ecca339SDan Handley 
78289c28a8SDan Handley #if LOG_LEVEL >= LOG_LEVEL_INFO
797f56e9a3SSoby Mathew # define INFO(...)	tf_log(LOG_MARKER_INFO __VA_ARGS__)
80289c28a8SDan Handley #else
81cf24229eSSandrine Bailleux # define INFO(...)	no_tf_log(LOG_MARKER_INFO __VA_ARGS__)
82289c28a8SDan Handley #endif
83289c28a8SDan Handley 
84289c28a8SDan Handley #if LOG_LEVEL >= LOG_LEVEL_VERBOSE
857f56e9a3SSoby Mathew # define VERBOSE(...)	tf_log(LOG_MARKER_VERBOSE __VA_ARGS__)
86289c28a8SDan Handley #else
87cf24229eSSandrine Bailleux # define VERBOSE(...)	no_tf_log(LOG_MARKER_VERBOSE __VA_ARGS__)
88289c28a8SDan Handley #endif
89289c28a8SDan Handley 
900c62883fSDouglas Raillard #if ENABLE_BACKTRACE
910c62883fSDouglas Raillard void backtrace(const char *cookie);
920c62883fSDouglas Raillard #else
930c62883fSDouglas Raillard #define backtrace(x)
940c62883fSDouglas Raillard #endif
950c62883fSDouglas Raillard 
96c6bc0710SDan Handley void __dead2 do_panic(void);
973e530d8eSAntonio Nino Diaz 
983e530d8eSAntonio Nino Diaz #define panic()				\
993e530d8eSAntonio Nino Diaz 	do {				\
1003e530d8eSAntonio Nino Diaz 		backtrace(__func__);	\
1013e530d8eSAntonio Nino Diaz 		(void)console_flush();	\
1023e530d8eSAntonio Nino Diaz 		do_panic();		\
1033e530d8eSAntonio Nino Diaz 	} while (false)
104a43d431bSSoby Mathew 
10551faada7SDouglas Raillard /* Function called when stack protection check code detects a corrupted stack */
10651faada7SDouglas Raillard void __dead2 __stack_chk_fail(void);
10751faada7SDouglas Raillard 
1087f56e9a3SSoby Mathew void tf_log(const char *fmt, ...) __printflike(1, 2);
1097f56e9a3SSoby Mathew void tf_log_set_max_level(unsigned int log_level);
110b79af934SSoby Mathew 
1111319e7b1SSoby Mathew #endif /* __ASSEMBLY__ */
112870ce3ddSAntonio Nino Diaz #endif /* DEBUG_H */
113