mali_malisw.h 4.0 KB

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