]>
Commit | Line | Data |
---|---|---|
716154c5 BB |
1 | /*****************************************************************************\ |
2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. | |
3 | * Copyright (C) 2007 The Regents of the University of California. | |
4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). | |
5 | * Written by Brian Behlendorf <behlendorf1@llnl.gov>. | |
715f6251 | 6 | * UCRL-CODE-235197 |
7 | * | |
716154c5 | 8 | * This file is part of the SPL, Solaris Porting Layer. |
3d6af2dd | 9 | * For details, see <http://zfsonlinux.org/>. |
716154c5 BB |
10 | * |
11 | * The SPL is free software; you can redistribute it and/or modify it | |
12 | * under the terms of the GNU General Public License as published by the | |
13 | * Free Software Foundation; either version 2 of the License, or (at your | |
14 | * option) any later version. | |
715f6251 | 15 | * |
716154c5 | 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT |
715f6251 | 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
19 | * for more details. | |
20 | * | |
21 | * You should have received a copy of the GNU General Public License along | |
716154c5 BB |
22 | * with the SPL. If not, see <http://www.gnu.org/licenses/>. |
23 | \*****************************************************************************/ | |
715f6251 | 24 | |
14c5326c | 25 | #ifndef _SPL_SYSMACROS_H |
26 | #define _SPL_SYSMACROS_H | |
27 | ||
14c5326c | 28 | #include <linux/module.h> |
10087fe1 | 29 | #include <linux/sched.h> |
15b52c08 | 30 | #include <linux/cpumask.h> |
57d1b188 | 31 | #include <sys/debug.h> |
05ae387b | 32 | #include <sys/varargs.h> |
36e6f861 | 33 | #include <sys/zone.h> |
1ec74a11 | 34 | #include <sys/signal.h> |
ec06701b | 35 | #include <asm/page.h> |
14c5326c | 36 | |
10087fe1 RY |
37 | #ifdef HAVE_SCHED_RT_HEADER |
38 | #include <linux/sched/rt.h> | |
39 | #endif | |
40 | ||
14c5326c | 41 | #ifndef _KERNEL |
32c6147d | 42 | #define _KERNEL __KERNEL__ |
14c5326c | 43 | #endif |
44 | ||
ed61a7d0 | 45 | #define FALSE 0 |
46 | #define TRUE 1 | |
b0dd3380 | 47 | |
32c6147d BB |
48 | #define INT8_MAX (127) |
49 | #define INT8_MIN (-128) | |
50 | #define UINT8_MAX (255) | |
51 | #define UINT8_MIN (0) | |
52 | ||
53 | #define INT16_MAX (32767) | |
54 | #define INT16_MIN (-32768) | |
55 | #define UINT16_MAX (65535) | |
56 | #define UINT16_MIN (0) | |
57 | ||
58 | #define INT32_MAX INT_MAX | |
59 | #define INT32_MIN INT_MIN | |
3b3ba48f | 60 | #define UINT32_MAX UINT_MAX |
61 | #define UINT32_MIN UINT_MIN | |
32c6147d | 62 | |
3b3ba48f | 63 | #define INT64_MAX LLONG_MAX |
64 | #define INT64_MIN LLONG_MIN | |
32c6147d | 65 | #define UINT64_MAX ULLONG_MAX |
3b3ba48f | 66 | #define UINT64_MIN ULLONG_MIN |
67 | ||
32c6147d | 68 | #define NBBY 8 |
00ba7ef9 | 69 | #define ENOTSUP EOPNOTSUPP |
b0dd3380 | 70 | |
05ae387b | 71 | #define MAXMSGLEN 256 |
32c6147d BB |
72 | #define MAXNAMELEN 256 |
73 | #define MAXPATHLEN PATH_MAX | |
d837ae39 | 74 | #define MAXOFFSET_T LLONG_MAX |
b0dd3380 | 75 | #define MAXBSIZE 8192 |
76 | #define DEV_BSIZE 512 | |
77 | #define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */ | |
78 | ||
36b313da | 79 | #define proc_pageout NULL |
44e406d7 | 80 | #define curproc current |
15b52c08 | 81 | #define max_ncpus num_possible_cpus() |
f6188ddd | 82 | #define boot_ncpus num_online_cpus() |
15b52c08 | 83 | #define CPU_SEQID smp_processor_id() |
b0dd3380 | 84 | #define _NOTE(x) |
ae4c36ad | 85 | #define is_system_labeled() 0 |
14c5326c | 86 | |
a50cede3 BB |
87 | #ifndef RLIM64_INFINITY |
88 | #define RLIM64_INFINITY (~0ULL) | |
89 | #endif | |
6adf99e7 | 90 | |
14c5326c | 91 | /* 0..MAX_PRIO-1: Process priority |
92 | * 0..MAX_RT_PRIO-1: RT priority tasks | |
93 | * MAX_RT_PRIO..MAX_PRIO-1: SCHED_NORMAL tasks | |
94 | * | |
95 | * Treat shim tasks as SCHED_NORMAL tasks | |
96 | */ | |
f6188ddd AX |
97 | #define minclsyspri (MAX_PRIO-1) |
98 | #define maxclsyspri (MAX_RT_PRIO) | |
99 | #define defclsyspri (DEFAULT_PRIO) | |
14c5326c | 100 | |
9e4fb5c2 | 101 | #ifndef NICE_TO_PRIO |
14c5326c | 102 | #define NICE_TO_PRIO(nice) (MAX_RT_PRIO + (nice) + 20) |
9e4fb5c2 LG |
103 | #endif |
104 | #ifndef PRIO_TO_NICE | |
14c5326c | 105 | #define PRIO_TO_NICE(prio) ((prio) - MAX_RT_PRIO - 20) |
9e4fb5c2 | 106 | #endif |
14c5326c | 107 | |
10946b02 AX |
108 | /* |
109 | * Missing macros | |
14c5326c | 110 | */ |
10946b02 | 111 | #ifndef PAGESIZE |
32c6147d | 112 | #define PAGESIZE PAGE_SIZE |
10946b02 | 113 | #endif |
14c5326c | 114 | |
ec06701b AX |
115 | #ifndef PAGESHIFT |
116 | #define PAGESHIFT PAGE_SHIFT | |
117 | #endif | |
118 | ||
14c5326c | 119 | /* from Solaris sys/byteorder.h */ |
32c6147d BB |
120 | #define BSWAP_8(x) ((x) & 0xff) |
121 | #define BSWAP_16(x) ((BSWAP_8(x) << 8) | BSWAP_8((x) >> 8)) | |
122 | #define BSWAP_32(x) ((BSWAP_16(x) << 16) | BSWAP_16((x) >> 16)) | |
123 | #define BSWAP_64(x) ((BSWAP_32(x) << 32) | BSWAP_32((x) >> 32)) | |
14c5326c | 124 | |
125 | /* Map some simple functions. | |
126 | */ | |
32c6147d | 127 | #define bzero(ptr,size) memset(ptr,0,size) |
9dd5d138 | 128 | #define bcopy(src,dest,size) memmove(dest,src,size) |
b0dd3380 | 129 | #define bcmp(src,dest,size) memcmp((src), (dest), (size_t)(size)) |
a713518f | 130 | |
131 | /* Dtrace probes do not exist in the linux kernel */ | |
0f372044 BB |
132 | #ifdef DTRACE_PROBE |
133 | #undef DTRACE_PROBE | |
134 | #endif /* DTRACE_PROBE */ | |
135 | #define DTRACE_PROBE(a) ((void)0) | |
a713518f | 136 | |
137 | #ifdef DTRACE_PROBE1 | |
138 | #undef DTRACE_PROBE1 | |
139 | #endif /* DTRACE_PROBE1 */ | |
3b3ba48f | 140 | #define DTRACE_PROBE1(a, b, c) ((void)0) |
a713518f | 141 | |
142 | #ifdef DTRACE_PROBE2 | |
143 | #undef DTRACE_PROBE2 | |
144 | #endif /* DTRACE_PROBE2 */ | |
3b3ba48f | 145 | #define DTRACE_PROBE2(a, b, c, d, e) ((void)0) |
a713518f | 146 | |
147 | #ifdef DTRACE_PROBE3 | |
148 | #undef DTRACE_PROBE3 | |
149 | #endif /* DTRACE_PROBE3 */ | |
3b3ba48f | 150 | #define DTRACE_PROBE3(a, b, c, d, e, f, g) ((void)0) |
a713518f | 151 | |
152 | #ifdef DTRACE_PROBE4 | |
153 | #undef DTRACE_PROBE4 | |
154 | #endif /* DTRACE_PROBE4 */ | |
3b3ba48f | 155 | #define DTRACE_PROBE4(a, b, c, d, e, f, g, h, i) ((void)0) |
14c5326c | 156 | |
77b1fe8f | 157 | /* Missing globals */ |
0835057e | 158 | extern char spl_version[32]; |
fa6f7d8f | 159 | extern unsigned long spl_hostid; |
14c5326c | 160 | |
77b1fe8f | 161 | /* Missing misc functions */ |
99639e4a | 162 | extern uint32_t zone_get_hostid(void *zone); |
51a727e9 BB |
163 | extern void spl_setup(void); |
164 | extern void spl_cleanup(void); | |
77b1fe8f | 165 | |
ec06701b AX |
166 | #define highbit(x) __fls(x) |
167 | #define lowbit(x) __ffs(x) | |
168 | ||
10946b02 AX |
169 | #define highbit64(x) fls64(x) |
170 | #define makedevice(maj,min) makedev(maj,min) | |
14c5326c | 171 | |
14c5326c | 172 | /* common macros */ |
173 | #ifndef MIN | |
37319315 | 174 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) |
14c5326c | 175 | #endif |
176 | #ifndef MAX | |
37319315 | 177 | #define MAX(a, b) ((a) < (b) ? (b) : (a)) |
14c5326c | 178 | #endif |
179 | #ifndef ABS | |
37319315 BB |
180 | #define ABS(a) ((a) < 0 ? -(a) : (a)) |
181 | #endif | |
182 | #ifndef DIV_ROUND_UP | |
183 | #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) | |
184 | #endif | |
185 | #ifndef roundup | |
186 | #define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y)) | |
14c5326c | 187 | #endif |
9e4fb5c2 LG |
188 | #ifndef howmany |
189 | #define howmany(x, y) (((x) + ((y) - 1)) / (y)) | |
190 | #endif | |
14c5326c | 191 | |
192 | /* | |
193 | * Compatibility macros/typedefs needed for Solaris -> Linux port | |
194 | */ | |
32c6147d BB |
195 | #define P2ALIGN(x, align) ((x) & -(align)) |
196 | #define P2CROSS(x, y, align) (((x) ^ (y)) > (align) - 1) | |
879bbbc7 | 197 | #define P2ROUNDUP(x, align) ((((x) - 1) | ((align) - 1)) + 1) |
32c6147d BB |
198 | #define P2PHASE(x, align) ((x) & ((align) - 1)) |
199 | #define P2NPHASE(x, align) (-(x) & ((align) - 1)) | |
200 | #define ISP2(x) (((x) & ((x) - 1)) == 0) | |
201 | #define IS_P2ALIGNED(v, a) ((((uintptr_t)(v)) & ((uintptr_t)(a) - 1))==0) | |
160c63ab | 202 | #define P2BOUNDARY(off, len, align) \ |
32c6147d | 203 | (((off) ^ ((off) + (len) - 1)) > (align) - 1) |
14c5326c | 204 | |
205 | /* | |
206 | * Typed version of the P2* macros. These macros should be used to ensure | |
207 | * that the result is correctly calculated based on the data type of (x), | |
208 | * which is passed in as the last argument, regardless of the data | |
209 | * type of the alignment. For example, if (x) is of type uint64_t, | |
210 | * and we want to round it up to a page boundary using "PAGESIZE" as | |
211 | * the alignment, we can do either | |
32c6147d | 212 | * |
14c5326c | 213 | * P2ROUNDUP(x, (uint64_t)PAGESIZE) |
214 | * or | |
215 | * P2ROUNDUP_TYPED(x, PAGESIZE, uint64_t) | |
216 | */ | |
217 | #define P2ALIGN_TYPED(x, align, type) \ | |
218 | ((type)(x) & -(type)(align)) | |
219 | #define P2PHASE_TYPED(x, align, type) \ | |
220 | ((type)(x) & ((type)(align) - 1)) | |
221 | #define P2NPHASE_TYPED(x, align, type) \ | |
222 | (-(type)(x) & ((type)(align) - 1)) | |
223 | #define P2ROUNDUP_TYPED(x, align, type) \ | |
879bbbc7 | 224 | ((((type)(x) - 1) | ((type)(align) - 1)) + 1) |
14c5326c | 225 | #define P2END_TYPED(x, align, type) \ |
226 | (-(~(type)(x) & -(type)(align))) | |
227 | #define P2PHASEUP_TYPED(x, align, phase, type) \ | |
228 | ((type)(phase) - (((type)(phase) - (type)(x)) & -(type)(align))) | |
229 | #define P2CROSS_TYPED(x, y, align, type) \ | |
230 | (((type)(x) ^ (type)(y)) > (type)(align) - 1) | |
231 | #define P2SAMEHIGHBIT_TYPED(x, y, type) \ | |
232 | (((type)(x) ^ (type)(y)) < ((type)(x) & (type)(y))) | |
233 | ||
234 | #if defined(_KERNEL) && !defined(_KMEMUSER) && !defined(offsetof) | |
235 | ||
236 | /* avoid any possibility of clashing with <stddef.h> version */ | |
237 | ||
238 | #define offsetof(s, m) ((size_t)(&(((s *)0)->m))) | |
239 | #endif | |
240 | ||
14c5326c | 241 | #endif /* _SPL_SYSMACROS_H */ |