mali_kernel_common.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * This confidential and proprietary software may be used only as
  3. * authorised by a licensing agreement from ARM Limited
  4. * (C) COPYRIGHT 2007-2010, 2012-2013 ARM Limited
  5. * ALL RIGHTS RESERVED
  6. * The entire notice above must be reproduced on all authorised
  7. * copies and copies may only be made to the extent permitted
  8. * by a licensing agreement from ARM Limited.
  9. */
  10. #ifndef __MALI_KERNEL_COMMON_H__
  11. #define __MALI_KERNEL_COMMON_H__
  12. #include "mali_osk.h"
  13. /* Make sure debug is defined when it should be */
  14. #ifndef DEBUG
  15. #if defined(_DEBUG)
  16. #define DEBUG
  17. #endif
  18. #endif
  19. /* The file include several useful macros for error checking, debugging and printing.
  20. * - MALI_PRINTF(...) Do not use this function: Will be included in Release builds.
  21. * - MALI_DEBUG_PRINT(nr, (X) ) Prints the second argument if nr<=MALI_DEBUG_LEVEL.
  22. * - MALI_DEBUG_ERROR( (X) ) Prints an errortext, a source trace, and the given error message.
  23. * - MALI_DEBUG_ASSERT(exp,(X)) If the asserted expr is false, the program will exit.
  24. * - MALI_DEBUG_ASSERT_POINTER(pointer) Triggers if the pointer is a zero pointer.
  25. * - MALI_DEBUG_CODE( X ) The code inside the macro is only compiled in Debug builds.
  26. *
  27. * The (X) means that you must add an extra parenthesis around the argumentlist.
  28. *
  29. * The printf function: MALI_PRINTF(...) is routed to _mali_osk_debugmsg
  30. *
  31. * Suggested range for the DEBUG-LEVEL is [1:6] where
  32. * [1:2] Is messages with highest priority, indicate possible errors.
  33. * [3:4] Is messages with medium priority, output important variables.
  34. * [5:6] Is messages with low priority, used during extensive debugging.
  35. */
  36. /**
  37. * Fundamental error macro. Reports an error code. This is abstracted to allow us to
  38. * easily switch to a different error reporting method if we want, and also to allow
  39. * us to search for error returns easily.
  40. *
  41. * Note no closing semicolon - this is supplied in typical usage:
  42. *
  43. * MALI_ERROR(MALI_ERROR_OUT_OF_MEMORY);
  44. */
  45. #define MALI_ERROR(error_code) return (error_code)
  46. /**
  47. * Basic error macro, to indicate success.
  48. * Note no closing semicolon - this is supplied in typical usage:
  49. *
  50. * MALI_SUCCESS;
  51. */
  52. #define MALI_SUCCESS MALI_ERROR(_MALI_OSK_ERR_OK)
  53. /**
  54. * Basic error macro. This checks whether the given condition is true, and if not returns
  55. * from this function with the supplied error code. This is a macro so that we can override it
  56. * for stress testing.
  57. *
  58. * Note that this uses the do-while-0 wrapping to ensure that we don't get problems with dangling
  59. * else clauses. Note also no closing semicolon - this is supplied in typical usage:
  60. *
  61. * MALI_CHECK((p!=NULL), ERROR_NO_OBJECT);
  62. */
  63. #define MALI_CHECK(condition, error_code) do { if(!(condition)) MALI_ERROR(error_code); } while(0)
  64. /**
  65. * Error propagation macro. If the expression given is anything other than _MALI_OSK_NO_ERROR,
  66. * then the value is returned from the enclosing function as an error code. This effectively
  67. * acts as a guard clause, and propagates error values up the call stack. This uses a
  68. * temporary value to ensure that the error expression is not evaluated twice.
  69. * If the counter for forcing a failure has been set using _mali_force_error, this error will be
  70. * returned without evaluating the expression in MALI_CHECK_NO_ERROR
  71. */
  72. #define MALI_CHECK_NO_ERROR(expression) \
  73. do { _mali_osk_errcode_t _check_no_error_result=(expression); \
  74. if(_check_no_error_result != _MALI_OSK_ERR_OK) \
  75. MALI_ERROR(_check_no_error_result); \
  76. } while(0)
  77. /**
  78. * Pointer check macro. Checks non-null pointer.
  79. */
  80. #define MALI_CHECK_NON_NULL(pointer, error_code) MALI_CHECK( ((pointer)!=NULL), (error_code) )
  81. /**
  82. * Error macro with goto. This checks whether the given condition is true, and if not jumps
  83. * to the specified label using a goto. The label must therefore be local to the function in
  84. * which this macro appears. This is most usually used to execute some clean-up code before
  85. * exiting with a call to ERROR.
  86. *
  87. * Like the other macros, this is a macro to allow us to override the condition if we wish,
  88. * e.g. to force an error during stress testing.
  89. */
  90. #define MALI_CHECK_GOTO(condition, label) do { if(!(condition)) goto label; } while(0)
  91. /**
  92. * Explicitly ignore a parameter passed into a function, to suppress compiler warnings.
  93. * Should only be used with parameter names.
  94. */
  95. #define MALI_IGNORE(x) x=x
  96. #define MALI_PRINTF(args) _mali_osk_dbgmsg args;
  97. #define MALI_PRINT_ERROR(args) do{ \
  98. MALI_PRINTF(("Mali: ERR: %s\n" ,__FILE__)); \
  99. MALI_PRINTF((" %s()%4d\n ", __FUNCTION__, __LINE__)) ; \
  100. MALI_PRINTF(args); \
  101. MALI_PRINTF(("\n")); \
  102. } while(0)
  103. #define MALI_PRINT(args) do{ \
  104. MALI_PRINTF(("Mali: ")); \
  105. MALI_PRINTF(args); \
  106. } while (0)
  107. #ifdef DEBUG
  108. #ifndef mali_debug_level
  109. extern int mali_debug_level;
  110. #endif
  111. #define MALI_DEBUG_CODE(code) code
  112. #define MALI_DEBUG_PRINT(level, args) do { \
  113. if((level) <= mali_debug_level)\
  114. {MALI_PRINTF(("Mali<" #level ">: ")); MALI_PRINTF(args); } \
  115. } while (0)
  116. #define MALI_DEBUG_PRINT_ERROR(args) MALI_PRINT_ERROR(args)
  117. #define MALI_DEBUG_PRINT_IF(level,condition,args) \
  118. if((condition)&&((level) <= mali_debug_level))\
  119. {MALI_PRINTF(("Mali<" #level ">: ")); MALI_PRINTF(args); }
  120. #define MALI_DEBUG_PRINT_ELSE(level, args)\
  121. else if((level) <= mali_debug_level)\
  122. { MALI_PRINTF(("Mali<" #level ">: ")); MALI_PRINTF(args); }
  123. /**
  124. * @note these variants of DEBUG ASSERTS will cause a debugger breakpoint
  125. * to be entered (see _mali_osk_break() ). An alternative would be to call
  126. * _mali_osk_abort(), on OSs that support it.
  127. */
  128. #define MALI_DEBUG_PRINT_ASSERT(condition, args) do {if( !(condition)) { MALI_PRINT_ERROR(args); _mali_osk_break(); } } while(0)
  129. #define MALI_DEBUG_ASSERT_POINTER(pointer) do {if( (pointer)== NULL) {MALI_PRINT_ERROR(("NULL pointer " #pointer)); _mali_osk_break();} } while(0)
  130. #define MALI_DEBUG_ASSERT(condition) do {if( !(condition)) {MALI_PRINT_ERROR(("ASSERT failed: " #condition )); _mali_osk_break();} } while(0)
  131. #else /* DEBUG */
  132. #define MALI_DEBUG_CODE(code)
  133. #define MALI_DEBUG_PRINT(string,args) do {} while(0)
  134. #define MALI_DEBUG_PRINT_ERROR(args) do {} while(0)
  135. #define MALI_DEBUG_PRINT_IF(level,condition,args) do {} while(0)
  136. #define MALI_DEBUG_PRINT_ELSE(level,condition,args) do {} while(0)
  137. #define MALI_DEBUG_PRINT_ASSERT(condition,args) do {} while(0)
  138. #define MALI_DEBUG_ASSERT_POINTER(pointer) do {} while(0)
  139. #define MALI_DEBUG_ASSERT(condition) do {} while(0)
  140. #endif /* DEBUG */
  141. /**
  142. * variables from user space cannot be dereferenced from kernel space; tagging them
  143. * with __user allows the GCC compiler to generate a warning. Other compilers may
  144. * not support this so we define it here as an empty macro if the compiler doesn't
  145. * define it.
  146. */
  147. #ifndef __user
  148. #define __user
  149. #endif
  150. #endif /* __MALI_KERNEL_COMMON_H__ */