2 * Copyright (C) 2011-2012 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 */
24 /* Macro for generating a kernel panic.
25 * Turned on off by compile-time Makefile settings
27 #if defined(USING_KERNEL_PANIC)
28 #include <linux/kernel.h>
29 #define MALI_PANIC(fmt, args...) panic( fmt, ## args );
31 #define MALI_PANIC(fmt, args...)
34 /* The file include several useful macros for error checking, debugging and printing.
35 * - MALI_PRINTF(...) Do not use this function: Will be included in Release builds.
36 * - MALI_DEBUG_PRINT(nr, (X) ) Prints the second argument if nr<=MALI_DEBUG_LEVEL.
37 * - MALI_DEBUG_ERROR( (X) ) Prints an errortext, a source trace, and the given error message.
38 * - MALI_DEBUG_ASSERT(exp,(X)) If the asserted expr is false, the program will exit.
39 * - MALI_DEBUG_ASSERT_POINTER(pointer) Triggers if the pointer is a zero pointer.
40 * - MALI_DEBUG_CODE( X ) The code inside the macro is only compiled in Debug builds.
42 * The (X) means that you must add an extra parenthesis around the argumentlist.
44 * The printf function: MALI_PRINTF(...) is routed to _mali_osk_debugmsg
46 * Suggested range for the DEBUG-LEVEL is [1:6] where
47 * [1:2] Is messages with highest priority, indicate possible errors.
48 * [3:4] Is messages with medium priority, output important variables.
49 * [5:6] Is messages with low priority, used during extensive debugging.
53 * Fundamental error macro. Reports an error code. This is abstracted to allow us to
54 * easily switch to a different error reporting method if we want, and also to allow
55 * us to search for error returns easily.
57 * Note no closing semicolon - this is supplied in typical usage:
59 * MALI_ERROR(MALI_ERROR_OUT_OF_MEMORY);
61 #define MALI_ERROR(error_code) return (error_code)
64 * Basic error macro, to indicate success.
65 * Note no closing semicolon - this is supplied in typical usage:
69 #define MALI_SUCCESS MALI_ERROR(_MALI_OSK_ERR_OK)
72 * Basic error macro. This checks whether the given condition is true, and if not returns
73 * from this function with the supplied error code. This is a macro so that we can override it
76 * Note that this uses the do-while-0 wrapping to ensure that we don't get problems with dangling
77 * else clauses. Note also no closing semicolon - this is supplied in typical usage:
79 * MALI_CHECK((p!=NULL), ERROR_NO_OBJECT);
81 #define MALI_CHECK(condition, error_code) do { if(!(condition)) MALI_ERROR(error_code); } while(0)
84 * Error propagation macro. If the expression given is anything other than _MALI_OSK_NO_ERROR,
85 * then the value is returned from the enclosing function as an error code. This effectively
86 * acts as a guard clause, and propagates error values up the call stack. This uses a
87 * temporary value to ensure that the error expression is not evaluated twice.
88 * If the counter for forcing a failure has been set using _mali_force_error, this error will be
89 * returned without evaluating the expression in MALI_CHECK_NO_ERROR
91 #define MALI_CHECK_NO_ERROR(expression) \
92 do { _mali_osk_errcode_t _check_no_error_result=(expression); \
93 if(_check_no_error_result != _MALI_OSK_ERR_OK) \
94 MALI_ERROR(_check_no_error_result); \
98 * Pointer check macro. Checks non-null pointer.
100 #define MALI_CHECK_NON_NULL(pointer, error_code) MALI_CHECK( ((pointer)!=NULL), (error_code) )
103 * Error macro with goto. This checks whether the given condition is true, and if not jumps
104 * to the specified label using a goto. The label must therefore be local to the function in
105 * which this macro appears. This is most usually used to execute some clean-up code before
106 * exiting with a call to ERROR.
108 * Like the other macros, this is a macro to allow us to override the condition if we wish,
109 * e.g. to force an error during stress testing.
111 #define MALI_CHECK_GOTO(condition, label) do { if(!(condition)) goto label; } while(0)
114 * Explicitly ignore a parameter passed into a function, to suppress compiler warnings.
115 * Should only be used with parameter names.
117 #define MALI_IGNORE(x) x=x
119 #define MALI_PRINTF(args) _mali_osk_dbgmsg args;
121 #define MALI_PRINT_ERROR(args) do{ \
122 MALI_PRINTF(("Mali: ERR: %s\n" ,__FILE__)); \
123 MALI_PRINTF((" %s()%4d\n ", __FUNCTION__, __LINE__)) ; \
125 MALI_PRINTF(("\n")); \
128 #define MALI_PRINT(args) do{ \
129 MALI_PRINTF(("Mali: ")); \
134 #ifndef mali_debug_level
135 extern int mali_debug_level;
138 #define MALI_DEBUG_CODE(code) code
139 #define MALI_DEBUG_PRINT(level, args) do { \
140 if((level) <= mali_debug_level)\
141 {MALI_PRINTF(("Mali<" #level ">: ")); MALI_PRINTF(args); } \
144 #define MALI_DEBUG_PRINT_ERROR(args) MALI_PRINT_ERROR(args)
146 #define MALI_DEBUG_PRINT_IF(level,condition,args) \
147 if((condition)&&((level) <= mali_debug_level))\
148 {MALI_PRINTF(("Mali<" #level ">: ")); MALI_PRINTF(args); }
150 #define MALI_DEBUG_PRINT_ELSE(level, args)\
151 else if((level) <= mali_debug_level)\
152 { MALI_PRINTF(("Mali<" #level ">: ")); MALI_PRINTF(args); }
155 * @note these variants of DEBUG ASSERTS will cause a debugger breakpoint
156 * to be entered (see _mali_osk_break() ). An alternative would be to call
157 * _mali_osk_abort(), on OSs that support it.
159 #define MALI_DEBUG_PRINT_ASSERT(condition, args) do {if( !(condition)) { MALI_PRINT_ERROR(args); _mali_osk_break(); } } while(0)
160 #define MALI_DEBUG_ASSERT_POINTER(pointer) do {if( (pointer)== NULL) {MALI_PRINT_ERROR(("NULL pointer " #pointer)); _mali_osk_break();} } while(0)
161 #define MALI_DEBUG_ASSERT(condition) do {if( !(condition)) {MALI_PRINT_ERROR(("ASSERT failed: " #condition )); _mali_osk_break();} } while(0)
165 #define MALI_DEBUG_CODE(code)
166 #define MALI_DEBUG_PRINT(string,args) do {} while(0)
167 #define MALI_DEBUG_PRINT_ERROR(args) do {} while(0)
168 #define MALI_DEBUG_PRINT_IF(level,condition,args) do {} while(0)
169 #define MALI_DEBUG_PRINT_ELSE(level,condition,args) do {} while(0)
170 #define MALI_DEBUG_PRINT_ASSERT(condition,args) do {} while(0)
171 #define MALI_DEBUG_ASSERT_POINTER(pointer) do {} while(0)
172 #define MALI_DEBUG_ASSERT(condition) do {} while(0)
177 * variables from user space cannot be dereferenced from kernel space; tagging them
178 * with __user allows the GCC compiler to generate a warning. Other compilers may
179 * not support this so we define it here as an empty macro if the compiler doesn't
186 #endif /* __MALI_KERNEL_COMMON_H__ */