mali_malisw.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. *
  3. * (C) COPYRIGHT 2014-2015 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. * Kernel-wide include for common macros and types.
  17. */
  18. #ifndef _MALISW_H_
  19. #define _MALISW_H_
  20. #include <linux/version.h>
  21. /**
  22. * MIN - Return the lesser of two values.
  23. *
  24. * As a macro it may evaluate its arguments more than once.
  25. * Refer to MAX macro for more details
  26. */
  27. #define MIN(x, y) ((x) < (y) ? (x) : (y))
  28. /**
  29. * MAX - Return the greater of two values.
  30. *
  31. * As a macro it may evaluate its arguments more than once.
  32. * If called on the same two arguments as MIN it is guaranteed to return
  33. * the one that MIN didn't return. This is significant for types where not
  34. * all values are comparable e.g. NaNs in floating-point types. But if you want
  35. * to retrieve the min and max of two values, consider using a conditional swap
  36. * instead.
  37. */
  38. #define MAX(x, y) ((x) < (y) ? (y) : (x))
  39. /**
  40. * @hideinitializer
  41. * Function-like macro for suppressing unused variable warnings. Where possible
  42. * such variables should be removed; this macro is present for cases where we
  43. * much support API backwards compatibility.
  44. */
  45. #define CSTD_UNUSED(x) ((void)(x))
  46. /**
  47. * @hideinitializer
  48. * Function-like macro for use where "no behavior" is desired. This is useful
  49. * when compile time macros turn a function-like macro in to a no-op, but
  50. * where having no statement is otherwise invalid.
  51. */
  52. #define CSTD_NOP(...) ((void)#__VA_ARGS__)
  53. /**
  54. * Function-like macro for converting a pointer in to a u64 for storing into
  55. * an external data structure. This is commonly used when pairing a 32-bit
  56. * CPU with a 64-bit peripheral, such as a Midgard GPU. C's type promotion
  57. * is complex and a straight cast does not work reliably as pointers are
  58. * often considered as signed.
  59. */
  60. #define PTR_TO_U64(x) ((uint64_t)((uintptr_t)(x)))
  61. /**
  62. * @hideinitializer
  63. * Function-like macro for stringizing a single level macro.
  64. * @code
  65. * #define MY_MACRO 32
  66. * CSTD_STR1( MY_MACRO )
  67. * > "MY_MACRO"
  68. * @endcode
  69. */
  70. #define CSTD_STR1(x) #x
  71. /**
  72. * @hideinitializer
  73. * Function-like macro for stringizing a macro's value. This should not be used
  74. * if the macro is defined in a way which may have no value; use the
  75. * alternative @c CSTD_STR2N macro should be used instead.
  76. * @code
  77. * #define MY_MACRO 32
  78. * CSTD_STR2( MY_MACRO )
  79. * > "32"
  80. * @endcode
  81. */
  82. #define CSTD_STR2(x) CSTD_STR1(x)
  83. /**
  84. * Specify an assertion value which is evaluated at compile time. Recommended
  85. * usage is specification of a @c static @c INLINE function containing all of
  86. * the assertions thus:
  87. *
  88. * @code
  89. * static INLINE [module]_compile_time_assertions( void )
  90. * {
  91. * COMPILE_TIME_ASSERT( sizeof(uintptr_t) == sizeof(intptr_t) );
  92. * }
  93. * @endcode
  94. *
  95. * @note Use @c static not @c STATIC. We never want to turn off this @c static
  96. * specification for testing purposes.
  97. */
  98. #define CSTD_COMPILE_TIME_ASSERT(expr) \
  99. do { switch (0) { case 0: case (expr):; } } while (false)
  100. #endif /* _MALISW_H_ */