f66d387dbd536560efe4d99caa3553de1b8b0722
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / arm / t6xx / kbase / mali_kbase_debug.h
1 /*
2  *
3  * (C) COPYRIGHT ARM Limited. All rights reserved.
4  *
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
8  * of such GNU licence.
9  *
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.
13  *
14  */
15
16
17
18
19
20 #ifndef _KBASE_DEBUG_H
21 #define _KBASE_DEBUG_H
22
23 #include <linux/bug.h>
24
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
27
28 /** @brief If different from 0, the trace will only contain the file and line. */
29 #define KBASE_DEBUG_SKIP_FUNCTION_NAME 0
30
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
35 #else
36 #define KBASE_DEBUG_DISABLE_ASSERTS 1
37 #endif
38 #endif                          /* KBASE_DEBUG_DISABLE_ASSERTS */
39
40 typedef enum {
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 */
52 } kbase_module;
53
54 /** Function type that is called on an KBASE_DEBUG_ASSERT() or KBASE_DEBUG_ASSERT_MSG() */
55 typedef void (kbase_debug_assert_hook) (void *);
56
57 typedef struct kbasep_debug_assert_cb {
58         kbase_debug_assert_hook *func;
59         void *param;
60 } kbasep_debug_assert_cb;
61
62 /**
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
66  */
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
72 #else
73 #define KBASEP_DEBUG_PRINT_FUNCTION ""
74 #endif
75 #else
76 #define KBASEP_DEBUG_PRINT_TRACE ""
77 #endif
78
79 /**
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
86  */
87 /* Select the correct system output function*/
88 #ifdef CONFIG_MALI_DEBUG
89 #define KBASEP_DEBUG_ASSERT_OUT(trace, function, ...)\
90                 do { \
91                         printk(KERN_ERR "Mali<ASSERT>: %s function:%s ", trace, function);\
92                         printk(KERN_ERR __VA_ARGS__);\
93                         printk(KERN_ERR "\n");\
94                 } while (MALI_FALSE)
95 #else
96 #define KBASEP_DEBUG_ASSERT_OUT(trace, function, ...) CSTD_NOP()
97 #endif
98
99 #ifdef CONFIG_MALI_DEBUG
100 #define KBASE_CALL_ASSERT_HOOK() kbasep_debug_assert_call_hook();
101 #else
102 #define KBASE_CALL_ASSERT_HOOK() CSTD_NOP();
103 #endif
104
105 /**
106  * @def KBASE_DEBUG_ASSERT(expr)
107  * @brief Calls @see KBASE_PRINT_ASSERT and prints the expression @a expr if @a expr is false
108  *
109  * @note This macro does nothing if the flag @see KBASE_DEBUG_DISABLE_ASSERTS is set to 1
110  *
111  * @param expr Boolean expression
112  */
113 #define KBASE_DEBUG_ASSERT(expr) \
114         KBASE_DEBUG_ASSERT_MSG(expr, #expr)
115
116 #if KBASE_DEBUG_DISABLE_ASSERTS
117 #define KBASE_DEBUG_ASSERT_MSG(expr, ...) CSTD_NOP()
118 #else
119         /**
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
122          *
123          * @note This macro does nothing if the flag @see KBASE_DEBUG_DISABLE_ASSERTS is set to 1
124          *
125          * @param expr Boolean expression
126          * @param ...  Message to display when @a expr is false, as a format string followed by format arguments.
127          */
128 #define KBASE_DEBUG_ASSERT_MSG(expr, ...) \
129                 do { \
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();\
133                                 BUG();\
134                         } \
135                 } while (MALI_FALSE)
136 #endif                          /* KBASE_DEBUG_DISABLE_ASSERTS */
137
138 /**
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
146  */
147 #ifdef CONFIG_MALI_DEBUG
148 #define KBASE_DEBUG_PRINT_WARN(module, ...)\
149                 do {\
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");\
153                 } while (MALI_FALSE)
154 #else
155 #define KBASE_DEBUG_PRINT_WARN(module, ...) CSTD_NOP()
156 #endif
157
158 #define KBASE_DEBUG_PRINT_ERROR(module, ...)\
159         do {\
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");\
163         } while (MALI_FALSE)
164
165 /*If this is not disabled then Android boot times out*/
166 #define KBASE_DEBUG_PRINT_INFO(module, ...) CSTD_NOP()
167
168 #define KBASE_DEBUG_PRINT_RAW(module, ...)\
169         do {\
170                 printk(__VA_ARGS__);\
171                 printk("\n");\
172         } while (MALI_FALSE)
173
174 #define KBASE_DEBUG_PRINT_RAW_LEVEL(level, module, ...)\
175         do {\
176                 printk(level __VA_ARGS__);\
177                 printk(level "\n");\
178         } while (MALI_FALSE)
179
180 #define KBASE_DEBUG_PRINT(module, ...) KBASE_DEBUG_PRINT_RAW(module, __VA_ARGS__)
181
182 /**
183  * @def KBASE_DEBUG_CODE( X )
184  * @brief Executes the code inside the macro only in debug mode
185  *
186  * @param X Code to compile only in debug mode.
187  */
188 #ifdef CONFIG_MALI_DEBUG
189 #define KBASE_DEBUG_CODE(X) X
190 #else
191 #define KBASE_DEBUG_CODE(X) CSTD_NOP()
192 #endif                          /* CONFIG_MALI_DEBUG */
193
194 /**
195  * @brief Register a function to call on ASSERT
196  *
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.
199  *
200  * To disable the hook, supply NULL to \a func.
201  *
202  * @note This function is not thread-safe, and should only be used to
203  * register/deregister once in the module's lifetime.
204  *
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
207  */
208 void kbase_debug_assert_register_hook(kbase_debug_assert_hook *func, void *param);
209
210 /**
211  * @brief Call a debug assert hook previously registered with kbase_debug_assert_register_hook()
212  *
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.
217  */
218 void kbasep_debug_assert_call_hook(void);
219
220 /**
221  * @brief Convert a module id into a module name.
222  *
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.
226  */
227 const char *kbasep_debug_module_to_str(const kbase_module module);
228
229 #endif                          /* _KBASE_DEBUG_H */