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 #include <compat/linuxkpi/common/include/linux/compiler_types.h> 37 38 #define __bitwise 39 #define __devinitdata 40 #define __init 41 #define __initconst 42 #define __devinit 43 #define __devexit 44 #define __exit 45 #define ____cacheline_aligned __aligned(CACHE_LINE_SIZE) 46 #define ____cacheline_aligned_in_smp __aligned(CACHE_LINE_SIZE) 47 48 #if __has_attribute(__counted_by__) 49 #define __counted_by(_x) __attribute__((__counted_by__(_x))) 50 #else 51 #define __counted_by(_x) 52 #endif 53 #if BYTE_ORDER == LITTLE_ENDIAN 54 #define __counted_by_le(_x) __counted_by(_x) 55 #define __counted_by_be(_x) 56 #else 57 #define __counted_by_le(_x) 58 #define __counted_by_be(_x) __counted_by(_x) 59 #endif 60 61 #define likely(x) __builtin_expect(!!(x), 1) 62 #define unlikely(x) __builtin_expect(!!(x), 0) 63 #define typeof(x) __typeof(x) 64 65 #define uninitialized_var(x) x = x 66 67 #define barrier() __asm__ __volatile__("": : :"memory") 68 69 #define WRITE_ONCE(x,v) do { \ 70 barrier(); \ 71 (*(volatile __typeof(x) *)(uintptr_t)&(x)) = (v); \ 72 barrier(); \ 73 } while (0) 74 75 #define READ_ONCE(x) ({ \ 76 __typeof(x) __var = ({ \ 77 barrier(); \ 78 (*(const volatile __typeof(x) *)&(x)); \ 79 }); \ 80 barrier(); \ 81 __var; \ 82 }) 83 84 #define lockless_dereference(p) READ_ONCE(p) 85 86 #define _AT(T,X) ((T)(X)) 87 #define __must_be_array(a) __same_type(a, &(a)[0]) 88 89 #define sizeof_field(_s, _m) sizeof(((_s *)0)->_m) 90 91 #define is_signed_type(t) ((t)-1 < (t)1) 92 #define is_unsigned_type(t) ((t)-1 > (t)1) 93 94 #if __has_builtin(__builtin_dynamic_object_size) 95 #define __struct_size(_s) __builtin_dynamic_object_size(_s, 0) 96 #else 97 #define __struct_size(_s) __builtin_object_size(_s, 0) 98 #endif 99 100 #endif /* _LINUXKPI_LINUX_COMPILER_H_ */ 101