3 * (C) COPYRIGHT ARM Limited. All rights reserved.
5 * This program is free software and is provided to you under the terms of the
6 * GNU General Public License version 2 as published by the Free Software
7 * Foundation, and any use by you of this program is subject to the terms
10 * A copy of the licence is included with the program, and can also be obtained
11 * from Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
12 * Boston, MA 02110-1301, USA.
20 #ifndef _KBASE_DEBUG_H
21 #define _KBASE_DEBUG_H
23 #include <linux/bug.h>
25 /** @brief If equals to 0, a trace containing the file, line, and function will be displayed before each message. */
26 #define KBASE_DEBUG_SKIP_TRACE 0
28 /** @brief If different from 0, the trace will only contain the file and line. */
29 #define KBASE_DEBUG_SKIP_FUNCTION_NAME 0
31 /** @brief Disable the asserts tests if set to 1. Default is to disable the asserts in release. */
32 #ifndef KBASE_DEBUG_DISABLE_ASSERTS
33 #ifdef CONFIG_MALI_DEBUG
34 #define KBASE_DEBUG_DISABLE_ASSERTS 0
36 #define KBASE_DEBUG_DISABLE_ASSERTS 1
38 #endif /* KBASE_DEBUG_DISABLE_ASSERTS */
41 KBASE_UNKNOWN = 0, /**< @brief Unknown module */
42 KBASE_MMU, /**< @brief ID of Base MMU */
43 KBASE_JD, /**< @brief ID of Base Job Dispatch */
44 KBASE_JM, /**< @brief ID of Base Job Manager */
45 KBASE_CORE, /**< @brief ID of Base Core */
46 KBASE_MEM, /**< @brief ID of Base Memory */
47 KBASE_EVENT, /**< @brief ID of Base Event */
48 KBASE_CTX, /**< @brief ID of Base Context */
49 KBASE_PM, /**< @brief ID of Base Power Management */
50 KBASE_DEV, /**< @brief ID of Base Device */
51 KBASE_MODULES_ALL /**< @brief Select all the modules at once / Also gives the number of modules in the enum */
54 /** Function type that is called on an KBASE_DEBUG_ASSERT() or KBASE_DEBUG_ASSERT_MSG() */
55 typedef void (kbase_debug_assert_hook) (void *);
57 typedef struct kbasep_debug_assert_cb {
58 kbase_debug_assert_hook *func;
60 } kbasep_debug_assert_cb;
63 * @def KBASEP_DEBUG_PRINT_TRACE
64 * @brief Private macro containing the format of the trace to display before every message
65 * @sa KBASE_DEBUG_SKIP_TRACE, KBASE_DEBUG_SKIP_FUNCTION_NAME
67 #if KBASE_DEBUG_SKIP_TRACE == 0
68 #define KBASEP_DEBUG_PRINT_TRACE \
69 "In file: " __FILE__ " line: " CSTD_STR2(__LINE__)
70 #if KBASE_DEBUG_SKIP_FUNCTION_NAME == 0
71 #define KBASEP_DEBUG_PRINT_FUNCTION CSTD_FUNC
73 #define KBASEP_DEBUG_PRINT_FUNCTION ""
76 #define KBASEP_DEBUG_PRINT_TRACE ""
80 * @def KBASEP_DEBUG_ASSERT_OUT(trace, function, ...)
81 * @brief (Private) system printing function associated to the @see KBASE_DEBUG_ASSERT_MSG event.
82 * @param trace location in the code from where the message is printed
83 * @param function function from where the message is printed
84 * @param ... Format string followed by format arguments.
85 * @note function parameter cannot be concatenated with other strings
87 /* Select the correct system output function*/
88 #ifdef CONFIG_MALI_DEBUG
89 #define KBASEP_DEBUG_ASSERT_OUT(trace, function, ...)\
91 printk(KERN_ERR "Mali<ASSERT>: %s function:%s ", trace, function);\
92 printk(KERN_ERR __VA_ARGS__);\
93 printk(KERN_ERR "\n");\
96 #define KBASEP_DEBUG_ASSERT_OUT(trace, function, ...) CSTD_NOP()
99 #ifdef CONFIG_MALI_DEBUG
100 #define KBASE_CALL_ASSERT_HOOK() kbasep_debug_assert_call_hook();
102 #define KBASE_CALL_ASSERT_HOOK() CSTD_NOP();
106 * @def KBASE_DEBUG_ASSERT(expr)
107 * @brief Calls @see KBASE_PRINT_ASSERT and prints the expression @a expr if @a expr is false
109 * @note This macro does nothing if the flag @see KBASE_DEBUG_DISABLE_ASSERTS is set to 1
111 * @param expr Boolean expression
113 #define KBASE_DEBUG_ASSERT(expr) \
114 KBASE_DEBUG_ASSERT_MSG(expr, #expr)
116 #if KBASE_DEBUG_DISABLE_ASSERTS
117 #define KBASE_DEBUG_ASSERT_MSG(expr, ...) CSTD_NOP()
120 * @def KBASE_DEBUG_ASSERT_MSG(expr, ...)
121 * @brief Calls @see KBASEP_DEBUG_ASSERT_OUT and prints the given message if @a expr is false
123 * @note This macro does nothing if the flag @see KBASE_DEBUG_DISABLE_ASSERTS is set to 1
125 * @param expr Boolean expression
126 * @param ... Message to display when @a expr is false, as a format string followed by format arguments.
128 #define KBASE_DEBUG_ASSERT_MSG(expr, ...) \
130 if (MALI_FALSE == (expr)) { \
131 KBASEP_DEBUG_ASSERT_OUT(KBASEP_DEBUG_PRINT_TRACE, KBASEP_DEBUG_PRINT_FUNCTION, __VA_ARGS__);\
132 KBASE_CALL_ASSERT_HOOK();\
136 #endif /* KBASE_DEBUG_DISABLE_ASSERTS */
139 * @def KBASEP_DEBUG_WARN_OUT(module, trace, ...)
140 * @brief (Private) system printing function associated to the @see KBASE_DEBUG_PRINT_WARN event.
141 * @param module module ID
142 * @param trace location in the code from where the message is printed
143 * @param function function from where the message is printed
144 * @param ... Format string followed by format arguments.
145 * @note function parameter cannot be concatenated with other strings
147 #ifdef CONFIG_MALI_DEBUG
148 #define KBASE_DEBUG_PRINT_WARN(module, ...)\
150 printk(KERN_WARNING "Mali<WARN, %s>: %s function:%s ", kbasep_debug_module_to_str(module), KBASEP_DEBUG_PRINT_TRACE, KBASEP_DEBUG_PRINT_FUNCTION);\
151 printk(KERN_WARNING __VA_ARGS__);\
152 printk(KERN_WARNING "\n");\
155 #define KBASE_DEBUG_PRINT_WARN(module, ...) CSTD_NOP()
158 #define KBASE_DEBUG_PRINT_ERROR(module, ...)\
160 printk(KERN_ERR "Mali<ERROR, %s>: %s function:%s ", kbasep_debug_module_to_str(module), KBASEP_DEBUG_PRINT_TRACE, KBASEP_DEBUG_PRINT_FUNCTION);\
161 printk(KERN_ERR __VA_ARGS__);\
162 printk(KERN_ERR "\n");\
165 /*If this is not disabled then Android boot times out*/
166 #define KBASE_DEBUG_PRINT_INFO(module, ...) CSTD_NOP()
168 #define KBASE_DEBUG_PRINT_RAW(module, ...)\
170 printk(__VA_ARGS__);\
174 #define KBASE_DEBUG_PRINT_RAW_LEVEL(level, module, ...)\
176 printk(level __VA_ARGS__);\
180 #define KBASE_DEBUG_PRINT(module, ...) KBASE_DEBUG_PRINT_RAW(module, __VA_ARGS__)
183 * @def KBASE_DEBUG_CODE( X )
184 * @brief Executes the code inside the macro only in debug mode
186 * @param X Code to compile only in debug mode.
188 #ifdef CONFIG_MALI_DEBUG
189 #define KBASE_DEBUG_CODE(X) X
191 #define KBASE_DEBUG_CODE(X) CSTD_NOP()
192 #endif /* CONFIG_MALI_DEBUG */
195 * @brief Register a function to call on ASSERT
197 * Such functions will \b only be called during Debug mode, and for debugging
198 * features \b only. Do not rely on them to be called in general use.
200 * To disable the hook, supply NULL to \a func.
202 * @note This function is not thread-safe, and should only be used to
203 * register/deregister once in the module's lifetime.
205 * @param[in] func the function to call when an assert is triggered.
206 * @param[in] param the parameter to pass to \a func when calling it
208 void kbase_debug_assert_register_hook(kbase_debug_assert_hook *func, void *param);
211 * @brief Call a debug assert hook previously registered with kbase_debug_assert_register_hook()
213 * @note This function is not thread-safe with respect to multiple threads
214 * registering functions and parameters with
215 * kbase_debug_assert_register_hook(). Otherwise, thread safety is the
216 * responsibility of the registered hook.
218 void kbasep_debug_assert_call_hook(void);
221 * @brief Convert a module id into a module name.
223 * @param module ID of the module to convert
224 * @note module names are stored in : @see kbasep_str_modules.
225 * @return the name of the given module ID as a string of characters.
227 const char *kbasep_debug_module_to_str(const kbase_module module);
229 #endif /* _KBASE_DEBUG_H */