2 * Copyright (C) 2010, 2012-2015 ARM Limited. All rights reserved.
4 * This program is free software and is provided to you under the terms of the GNU General Public License version 2
5 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence.
7 * A copy of the licence is included with the program, and can also be obtained from Free Software
8 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
11 #ifndef __MALI_KERNEL_COMMON_H__
12 #define __MALI_KERNEL_COMMON_H__
16 /* Make sure debug is defined when it should be */
23 /* The file include several useful macros for error checking, debugging and printing.
24 * - MALI_PRINTF(...) Do not use this function: Will be included in Release builds.
25 * - MALI_DEBUG_PRINT(nr, (X) ) Prints the second argument if nr<=MALI_DEBUG_LEVEL.
26 * - MALI_DEBUG_ERROR( (X) ) Prints an errortext, a source trace, and the given error message.
27 * - MALI_DEBUG_ASSERT(exp,(X)) If the asserted expr is false, the program will exit.
28 * - MALI_DEBUG_ASSERT_POINTER(pointer) Triggers if the pointer is a zero pointer.
29 * - MALI_DEBUG_CODE( X ) The code inside the macro is only compiled in Debug builds.
31 * The (X) means that you must add an extra parenthesis around the argumentlist.
33 * The printf function: MALI_PRINTF(...) is routed to _mali_osk_debugmsg
35 * Suggested range for the DEBUG-LEVEL is [1:6] where
36 * [1:2] Is messages with highest priority, indicate possible errors.
37 * [3:4] Is messages with medium priority, output important variables.
38 * [5:6] Is messages with low priority, used during extensive debugging.
42 * Fundamental error macro. Reports an error code. This is abstracted to allow us to
43 * easily switch to a different error reporting method if we want, and also to allow
44 * us to search for error returns easily.
46 * Note no closing semicolon - this is supplied in typical usage:
48 * MALI_ERROR(MALI_ERROR_OUT_OF_MEMORY);
50 #define MALI_ERROR(error_code) return (error_code)
53 * Basic error macro, to indicate success.
54 * Note no closing semicolon - this is supplied in typical usage:
58 #define MALI_SUCCESS MALI_ERROR(_MALI_OSK_ERR_OK)
61 * Basic error macro. This checks whether the given condition is true, and if not returns
62 * from this function with the supplied error code. This is a macro so that we can override it
65 * Note that this uses the do-while-0 wrapping to ensure that we don't get problems with dangling
66 * else clauses. Note also no closing semicolon - this is supplied in typical usage:
68 * MALI_CHECK((p!=NULL), ERROR_NO_OBJECT);
70 #define MALI_CHECK(condition, error_code) do { if(!(condition)) MALI_ERROR(error_code); } while(0)
73 * Error propagation macro. If the expression given is anything other than
74 * _MALI_OSK_NO_ERROR, then the value is returned from the enclosing function
75 * as an error code. This effectively acts as a guard clause, and propagates
76 * error values up the call stack. This uses a temporary value to ensure that
77 * the error expression is not evaluated twice.
78 * If the counter for forcing a failure has been set using _mali_force_error,
79 * this error will be returned without evaluating the expression in
82 #define MALI_CHECK_NO_ERROR(expression) \
83 do { _mali_osk_errcode_t _check_no_error_result=(expression); \
84 if(_check_no_error_result != _MALI_OSK_ERR_OK) \
85 MALI_ERROR(_check_no_error_result); \
89 * Pointer check macro. Checks non-null pointer.
91 #define MALI_CHECK_NON_NULL(pointer, error_code) MALI_CHECK( ((pointer)!=NULL), (error_code) )
94 * Error macro with goto. This checks whether the given condition is true, and if not jumps
95 * to the specified label using a goto. The label must therefore be local to the function in
96 * which this macro appears. This is most usually used to execute some clean-up code before
97 * exiting with a call to ERROR.
99 * Like the other macros, this is a macro to allow us to override the condition if we wish,
100 * e.g. to force an error during stress testing.
102 #define MALI_CHECK_GOTO(condition, label) do { if(!(condition)) goto label; } while(0)
105 * Explicitly ignore a parameter passed into a function, to suppress compiler warnings.
106 * Should only be used with parameter names.
108 #define MALI_IGNORE(x) x=x
110 #if defined(CONFIG_MALI_QUIET)
111 #define MALI_PRINTF(args)
113 #define MALI_PRINTF(args) _mali_osk_dbgmsg args;
116 #define MALI_PRINT_ERROR(args) do{ \
117 MALI_PRINTF(("Mali: ERR: %s\n" ,__FILE__)); \
118 MALI_PRINTF((" %s()%4d\n ", __FUNCTION__, __LINE__)) ; \
120 MALI_PRINTF(("\n")); \
123 #define MALI_PRINT(args) do{ \
124 MALI_PRINTF(("Mali: ")); \
129 #ifndef mali_debug_level
130 extern int mali_debug_level;
133 #define MALI_DEBUG_CODE(code) code
134 #define MALI_DEBUG_PRINT(level, args) do { \
135 if((level) <= mali_debug_level)\
136 {MALI_PRINTF(("Mali<" #level ">: ")); MALI_PRINTF(args); } \
139 #define MALI_DEBUG_PRINT_ERROR(args) MALI_PRINT_ERROR(args)
141 #define MALI_DEBUG_PRINT_IF(level,condition,args) \
142 if((condition)&&((level) <= mali_debug_level))\
143 {MALI_PRINTF(("Mali<" #level ">: ")); MALI_PRINTF(args); }
145 #define MALI_DEBUG_PRINT_ELSE(level, args)\
146 else if((level) <= mali_debug_level)\
147 { MALI_PRINTF(("Mali<" #level ">: ")); MALI_PRINTF(args); }
150 * @note these variants of DEBUG ASSERTS will cause a debugger breakpoint
151 * to be entered (see _mali_osk_break() ). An alternative would be to call
152 * _mali_osk_abort(), on OSs that support it.
154 #define MALI_DEBUG_PRINT_ASSERT(condition, args) do {if( !(condition)) { MALI_PRINT_ERROR(args); _mali_osk_break(); } } while(0)
155 #define MALI_DEBUG_ASSERT_POINTER(pointer) do {if( (pointer)== NULL) {MALI_PRINT_ERROR(("NULL pointer " #pointer)); _mali_osk_break();} } while(0)
156 #define MALI_DEBUG_ASSERT(condition) do {if( !(condition)) {MALI_PRINT_ERROR(("ASSERT failed: " #condition )); _mali_osk_break();} } while(0)
160 #define MALI_DEBUG_CODE(code)
161 #define MALI_DEBUG_PRINT(string,args) do {} while(0)
162 #define MALI_DEBUG_PRINT_ERROR(args) do {} while(0)
163 #define MALI_DEBUG_PRINT_IF(level,condition,args) do {} while(0)
164 #define MALI_DEBUG_PRINT_ELSE(level,condition,args) do {} while(0)
165 #define MALI_DEBUG_PRINT_ASSERT(condition,args) do {} while(0)
166 #define MALI_DEBUG_ASSERT_POINTER(pointer) do {} while(0)
167 #define MALI_DEBUG_ASSERT(condition) do {} while(0)
172 * variables from user space cannot be dereferenced from kernel space; tagging them
173 * with __user allows the GCC compiler to generate a warning. Other compilers may
174 * not support this so we define it here as an empty macro if the compiler doesn't
181 #endif /* __MALI_KERNEL_COMMON_H__ */