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-2018 François Tigeot <ftigeot@wolfpond.org>
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice unmodified, this list of conditions, and the following
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.
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.
31 #ifndef _LINUX_COMPILER_H_
32 #define _LINUX_COMPILER_H_
34 #include <sys/cdefs.h>
42 #define __chk_user_ptr(x) 0
43 #define __chk_io_ptr(x) 0
44 #define __builtin_warning(x, y...) (1)
47 #define __acquire(x) 0
48 #define __release(x) 0
49 #define __cond_lock(x,c) (c)
56 #define __stringify(x) #x
57 #define __attribute_const__ __attribute__((__const__))
58 #undef __always_inline
59 #define __always_inline inline
61 #define likely(x) __builtin_expect(!!(x), 1)
62 #define unlikely(x) __builtin_expect(!!(x), 0)
63 #define typeof(x) __typeof(x)
66 #define __always_unused __unused
67 #define __must_check __heedresult
69 #define __printf(a,b) __printflike(a,b)
72 #define barrier() cpu_ccfence()
74 #define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
76 #ifdef _KERNEL /* This file is included by kdump(1) */
78 #include <sys/param.h>
81 * The READ_ONCE() and WRITE_ONCE() macros force volatile accesses to
83 * Their complexity is caused by the necessity to work-around
84 * compiler cleverness and bugs.
85 * Some GCC versions drop the volatile modifier if the variable used
86 * is not of a scalar type.
89 __volatile_read(const volatile void *x, int size, void *result)
93 *(uint64_t *)result = *(const volatile uint64_t *)x;
96 *(uint32_t *)result = *(const volatile uint32_t *)x;
99 *(uint16_t *)result = *(const volatile uint16_t *)x;
102 *(uint8_t *)result = *(const volatile uint8_t *)x;
105 panic("__volatile_read called with size %d\n", size);
110 __volatile_write(volatile void *var, int size, void *value)
114 *(volatile uint64_t *)var = *(uint64_t *)value;
117 *(volatile uint32_t *)var = *(uint32_t *)value;
120 *(volatile uint16_t *)var = *(uint16_t *)value;
123 *(volatile uint8_t *)var = *(uint8_t *)value;
126 panic("__volatile_write called with size %d\n", size);
131 #define READ_ONCE(x) ({ \
133 __typeof(x) initial_type; \
137 result.nc_type = 0; \
138 __volatile_read(&(x), sizeof(x), &result.nc_type); \
139 result.initial_type; \
142 #define WRITE_ONCE(var, value) ({ \
144 __typeof(var) initial_type; \
148 result.initial_type = value; \
149 __volatile_write(&(var), sizeof(var), &result.nc_type); \
150 result.initial_type; \
153 #endif /* __KERNEL__ */
155 #endif /* _LINUX_COMPILER_H_ */