1 /* 2 * 3 * (C) COPYRIGHT 2014-2015, 2018 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 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, you can access it online at 17 * http://www.gnu.org/licenses/gpl-2.0.html. 18 * 19 * SPDX-License-Identifier: GPL-2.0 20 * 21 */ 22 23 /** 24 * Kernel-wide include for common macros and types. 25 */ 26 27 #ifndef MALISW_H_ 28 #define MALISW_H_ 29 30 #include <linux/version.h> 31 #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0) 32 #define U8_MAX ((u8)~0U) 33 #define S8_MAX ((s8)(U8_MAX >> 1)) 34 #define S8_MIN ((s8)(-S8_MAX - 1)) 35 #define U16_MAX ((u16)~0U) 36 #define S16_MAX ((s16)(U16_MAX >> 1)) 37 #define S16_MIN ((s16)(-S16_MAX - 1)) 38 #define U32_MAX ((u32)~0U) 39 #define S32_MAX ((s32)(U32_MAX >> 1)) 40 #define S32_MIN ((s32)(-S32_MAX - 1)) 41 #define U64_MAX ((u64)~0ULL) 42 #define S64_MAX ((s64)(U64_MAX >> 1)) 43 #define S64_MIN ((s64)(-S64_MAX - 1)) 44 #endif /* LINUX_VERSION_CODE */ 45 #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 5, 0) 46 #define SIZE_MAX (~(size_t)0) 47 #endif /* LINUX_VERSION_CODE */ 48 49 /** 50 * MIN - Return the lesser of two values. 51 * 52 * As a macro it may evaluate its arguments more than once. 53 * Refer to MAX macro for more details 54 */ 55 #define MIN(x, y) ((x) < (y) ? (x) : (y)) 56 57 /** 58 * MAX - Return the greater of two values. 59 * 60 * As a macro it may evaluate its arguments more than once. 61 * If called on the same two arguments as MIN it is guaranteed to return 62 * the one that MIN didn't return. This is significant for types where not 63 * all values are comparable e.g. NaNs in floating-point types. But if you want 64 * to retrieve the min and max of two values, consider using a conditional swap 65 * instead. 66 */ 67 #define MAX(x, y) ((x) < (y) ? (y) : (x)) 68 69 /** 70 * @hideinitializer 71 * Function-like macro for suppressing unused variable warnings. Where possible 72 * such variables should be removed; this macro is present for cases where we 73 * much support API backwards compatibility. 74 */ 75 #define CSTD_UNUSED(x) ((void)(x)) 76 77 /** 78 * @hideinitializer 79 * Function-like macro for use where "no behavior" is desired. This is useful 80 * when compile time macros turn a function-like macro in to a no-op, but 81 * where having no statement is otherwise invalid. 82 */ 83 #define CSTD_NOP(...) ((void)#__VA_ARGS__) 84 85 /** 86 * @hideinitializer 87 * Function-like macro for stringizing a single level macro. 88 * @code 89 * #define MY_MACRO 32 90 * CSTD_STR1( MY_MACRO ) 91 * > "MY_MACRO" 92 * @endcode 93 */ 94 #define CSTD_STR1(x) #x 95 96 /** 97 * @hideinitializer 98 * Function-like macro for stringizing a macro's value. This should not be used 99 * if the macro is defined in a way which may have no value; use the 100 * alternative @c CSTD_STR2N macro should be used instead. 101 * @code 102 * #define MY_MACRO 32 103 * CSTD_STR2( MY_MACRO ) 104 * > "32" 105 * @endcode 106 */ 107 #define CSTD_STR2(x) CSTD_STR1(x) 108 109 #endif /* _MALISW_H_ */ 110