aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/mali400/r3p2/mali/common/mali_kernel_common.h
blob: 3376a07265637db2ef35960a0bf3c2803c9b6726 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*
 * Copyright (C) 2010, 2012 ARM Limited. All rights reserved.
 * 
 * This program is free software and is provided to you under the terms of the GNU General Public License version 2
 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence.
 * 
 * A copy of the licence is included with the program, and can also be obtained from Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#ifndef __MALI_KERNEL_COMMON_H__
#define __MALI_KERNEL_COMMON_H__

#include "mali_osk.h"

/* Make sure debug is defined when it should be */
#ifndef DEBUG
	#if defined(_DEBUG)
		#define DEBUG
	#endif
#endif

/* MALI_SEC */
/* Macro for generating a kernel panic.
 * Turned on off by compile-time Makefile settings
 */
#if defined(USING_KERNEL_PANIC)
#include <linux/kernel.h>
	#define MALI_PANIC(fmt, args...) panic( fmt, ## args );
#else
	#define MALI_PANIC(fmt, args...) 
#endif

/* The file include several useful macros for error checking, debugging and printing.
 * - MALI_PRINTF(...)           Do not use this function: Will be included in Release builds.
 * - MALI_DEBUG_PRINT(nr, (X) ) Prints the second argument if nr<=MALI_DEBUG_LEVEL.
 * - MALI_DEBUG_ERROR( (X) )    Prints an errortext, a source trace, and the given error message.
 * - MALI_DEBUG_ASSERT(exp,(X)) If the asserted expr is false, the program will exit.
 * - MALI_DEBUG_ASSERT_POINTER(pointer)  Triggers if the pointer is a zero pointer.
 * - MALI_DEBUG_CODE( X )       The code inside the macro is only compiled in Debug builds.
 *
 * The (X) means that you must add an extra parenthesis around the argumentlist.
 *
 * The  printf function: MALI_PRINTF(...) is routed to _mali_osk_debugmsg
 *
 * Suggested range for the DEBUG-LEVEL is [1:6] where
 * [1:2] Is messages with highest priority, indicate possible errors.
 * [3:4] Is messages with medium priority, output important variables.
 * [5:6] Is messages with low priority, used during extensive debugging.
 */

 /**
 *  Fundamental error macro. Reports an error code. This is abstracted to allow us to
 *  easily switch to a different error reporting method if we want, and also to allow
 *  us to search for error returns easily.
 *
 *  Note no closing semicolon - this is supplied in typical usage:
 *
 *  MALI_ERROR(MALI_ERROR_OUT_OF_MEMORY);
 */
#define MALI_ERROR(error_code) return (error_code)

/**
 *  Basic error macro, to indicate success.
 *  Note no closing semicolon - this is supplied in typical usage:
 *
 *  MALI_SUCCESS;
 */
#define MALI_SUCCESS MALI_ERROR(_MALI_OSK_ERR_OK)

/**
 *	Basic error macro. This checks whether the given condition is true, and if not returns
 *	from this function with the supplied error code. This is a macro so that we can override it
 *	for stress testing.
 *
 *	Note that this uses the do-while-0 wrapping to ensure that we don't get problems with dangling
 *	else clauses. Note also no closing semicolon - this is supplied in typical usage:
 *
 *	MALI_CHECK((p!=NULL), ERROR_NO_OBJECT);
 */
#define MALI_CHECK(condition, error_code) do { if(!(condition)) MALI_ERROR(error_code); } while(0)

/**
 *	Error propagation macro. If the expression given is anything other than _MALI_OSK_NO_ERROR,
 *	then the value is returned from the enclosing function as an error code. This effectively
 *	acts as a guard clause, and propagates error values up the call stack. This uses a
 *	temporary value to ensure that the error expression is not evaluated twice.
 *  If the counter for forcing a failure has been set using _mali_force_error, this error will be
 *  returned without evaluating the expression in MALI_CHECK_NO_ERROR
 */
#define MALI_CHECK_NO_ERROR(expression) \
    do { _mali_osk_errcode_t _check_no_error_result=(expression); \
         if(_check_no_error_result != _MALI_OSK_ERR_OK) \
         MALI_ERROR(_check_no_error_result); \
    } while(0)

/**
 *  Pointer check macro. Checks non-null pointer.
 */
#define MALI_CHECK_NON_NULL(pointer, error_code) MALI_CHECK( ((pointer)!=NULL), (error_code) )

/**
 *	Error macro with goto. This checks whether the given condition is true, and if not jumps
 *	to the specified label using a goto. The label must therefore be local to the function in
 *	which this macro appears. This is most usually used to execute some clean-up code before
 *	exiting with a call to ERROR.
 *
 *	Like the other macros, this is a macro to allow us to override the condition if we wish,
 *	e.g. to force an error during stress testing.
 */
#define MALI_CHECK_GOTO(condition, label) do { if(!(condition)) goto label; } while(0)

/**
 *  Explicitly ignore a parameter passed into a function, to suppress compiler warnings.
 *  Should only be used with parameter names.
 */
#define MALI_IGNORE(x) x=x

#define MALI_PRINTF(args) _mali_osk_dbgmsg args;

#define MALI_PRINT_ERROR(args) do{ \
	MALI_PRINTF(("Mali: ERR: %s\n" ,__FILE__)); \
	MALI_PRINTF(("           %s()%4d\n           ", __FUNCTION__, __LINE__)) ; \
	MALI_PRINTF(args); \
	MALI_PRINTF(("\n")); \
	} while(0)

#define MALI_PRINT(args) do{ \
	MALI_PRINTF(("Mali: ")); \
	MALI_PRINTF(args); \
	} while (0)

#ifdef DEBUG
#ifndef mali_debug_level
extern int mali_debug_level;
#endif

#define MALI_DEBUG_CODE(code) code
#define MALI_DEBUG_PRINT(level, args)  do { \
	if((level) <=  mali_debug_level)\
        {MALI_PRINTF(("Mali<" #level ">: ")); MALI_PRINTF(args); } \
	} while (0)

#define MALI_DEBUG_PRINT_ERROR(args) MALI_PRINT_ERROR(args)

#define MALI_DEBUG_PRINT_IF(level,condition,args)  \
	if((condition)&&((level) <=  mali_debug_level))\
        {MALI_PRINTF(("Mali<" #level ">: ")); MALI_PRINTF(args); }

#define MALI_DEBUG_PRINT_ELSE(level, args)\
	else if((level) <=  mali_debug_level)\
    { MALI_PRINTF(("Mali<" #level ">: ")); MALI_PRINTF(args); }

/**
 * @note these variants of DEBUG ASSERTS will cause a debugger breakpoint
 * to be entered (see _mali_osk_break() ). An alternative would be to call
 * _mali_osk_abort(), on OSs that support it.
 */
#define MALI_DEBUG_PRINT_ASSERT(condition, args) do  {if( !(condition)) { MALI_PRINT_ERROR(args); _mali_osk_break(); } } while(0)
#define MALI_DEBUG_ASSERT_POINTER(pointer) do  {if( (pointer)== NULL) {MALI_PRINT_ERROR(("NULL pointer " #pointer)); _mali_osk_break();} } while(0)
#define MALI_DEBUG_ASSERT(condition) do  {if( !(condition)) {MALI_PRINT_ERROR(("ASSERT failed: " #condition )); _mali_osk_break();} } while(0)

#else /* DEBUG */

#define MALI_DEBUG_CODE(code)
#define MALI_DEBUG_PRINT(string,args) do {} while(0)
#define MALI_DEBUG_PRINT_ERROR(args) do {} while(0)
#define MALI_DEBUG_PRINT_IF(level,condition,args) do {} while(0)
#define MALI_DEBUG_PRINT_ELSE(level,condition,args) do {} while(0)
#define MALI_DEBUG_PRINT_ASSERT(condition,args) do {} while(0)
#define MALI_DEBUG_ASSERT_POINTER(pointer) do {} while(0)
#define MALI_DEBUG_ASSERT(condition) do {} while(0)

#endif /* DEBUG */

/**
 * variables from user space cannot be dereferenced from kernel space; tagging them
 * with __user allows the GCC compiler to generate a warning. Other compilers may
 * not support this so we define it here as an empty macro if the compiler doesn't
 * define it.
 */
#ifndef __user
#define __user
#endif

#endif /* __MALI_KERNEL_COMMON_H__ */