1 /*- 2 * Copyright (c) 2010 Isilon Systems, Inc. 3 * Copyright (c) 2010 iX Systems, Inc. 4 * Copyright (c) 2010 Panasas, Inc. 5 * Copyright (c) 2013-2016 Mellanox Technologies, Ltd. 6 * Copyright (c) 2015 François Tigeot 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice unmodified, this list of conditions, and the following 14 * disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 #ifndef _LINUXKPI_LINUX_COMPILER_H_ 31 #define _LINUXKPI_LINUX_COMPILER_H_ 32 33 #include <sys/cdefs.h> 34 #include <sys/endian.h> 35 36 #define __user 37 #define __kernel 38 #define __safe 39 #define __force 40 #define __nocast 41 #define __iomem 42 #define __chk_user_ptr(x) ((void)0) 43 #define __chk_io_ptr(x) ((void)0) 44 #define __builtin_warning(x, y...) (1) 45 #define __acquires(x) 46 #define __releases(x) 47 #define __acquire(x) do { } while (0) 48 #define __release(x) do { } while (0) 49 #define __cond_lock(x,c) (c) 50 #define __bitwise 51 #define __devinitdata 52 #ifndef __deprecated 53 #define __deprecated 54 #endif 55 #define __init 56 #define __initconst 57 #define __devinit 58 #define __devexit 59 #define __exit 60 #define __rcu 61 #define __percpu 62 #define __weak __weak_symbol 63 #define __malloc 64 #define __attribute_const__ __attribute__((__const__)) 65 #undef __always_inline 66 #define __always_inline inline 67 #define noinline __noinline 68 #define noinline_for_stack __noinline 69 #define ____cacheline_aligned __aligned(CACHE_LINE_SIZE) 70 #define ____cacheline_aligned_in_smp __aligned(CACHE_LINE_SIZE) 71 #define fallthrough /* FALLTHROUGH */ do { } while(0) 72 73 #if __has_attribute(__nonstring__) 74 #define __nonstring __attribute__((__nonstring__)) 75 #else 76 #define __nonstring 77 #endif 78 #if __has_attribute(__counted_by__) 79 #define __counted_by(_x) __attribute__((__counted_by__(_x))) 80 #else 81 #define __counted_by(_x) 82 #endif 83 #if BYTE_ORDER == LITTLE_ENDIAN 84 #define __counted_by_le(_x) __counted_by(_x) 85 #define __counted_by_be(_x) 86 #else 87 #define __counted_by_le(_x) 88 #define __counted_by_be(_x) __counted_by(_x) 89 #endif 90 91 #define likely(x) __builtin_expect(!!(x), 1) 92 #define unlikely(x) __builtin_expect(!!(x), 0) 93 #define typeof(x) __typeof(x) 94 95 #define uninitialized_var(x) x = x 96 #define __maybe_unused __unused 97 #define __always_unused __unused 98 #define __must_check __result_use_check 99 100 #define __printf(a,b) __printflike(a,b) 101 102 #define __diag_push() 103 #define __diag_pop() 104 #define __diag_ignore_all(...) 105 106 #define barrier() __asm__ __volatile__("": : :"memory") 107 108 #define lower_32_bits(n) ((u32)(n)) 109 #define upper_32_bits(n) ((u32)(((n) >> 16) >> 16)) 110 111 #define ___PASTE(a,b) a##b 112 #define __PASTE(a,b) ___PASTE(a,b) 113 114 #define WRITE_ONCE(x,v) do { \ 115 barrier(); \ 116 (*(volatile __typeof(x) *)(uintptr_t)&(x)) = (v); \ 117 barrier(); \ 118 } while (0) 119 120 #define READ_ONCE(x) ({ \ 121 __typeof(x) __var = ({ \ 122 barrier(); \ 123 (*(const volatile __typeof(x) *)&(x)); \ 124 }); \ 125 barrier(); \ 126 __var; \ 127 }) 128 129 #define lockless_dereference(p) READ_ONCE(p) 130 131 #define _AT(T,X) ((T)(X)) 132 133 #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b)) 134 #define __must_be_array(a) __same_type(a, &(a)[0]) 135 136 #define sizeof_field(_s, _m) sizeof(((_s *)0)->_m) 137 138 #define is_signed_type(t) ((t)-1 < (t)1) 139 #define is_unsigned_type(t) ((t)-1 > (t)1) 140 141 #if __has_builtin(__builtin_dynamic_object_size) 142 #define __struct_size(_s) __builtin_dynamic_object_size(_s, 0) 143 #else 144 #define __struct_size(_s) __builtin_object_size(_s, 0) 145 #endif 146 147 #endif /* _LINUXKPI_LINUX_COMPILER_H_ */ 148