]>
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 |
34ee731f | 26 | #define _SPL_SYSMACROS_H |
14c5326c | 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 |
34ee731f | 42 | #define _KERNEL __KERNEL__ |
14c5326c | 43 | #endif |
44 | ||
34ee731f AX |
45 | #define FALSE 0 |
46 | #define TRUE 1 | |
47 | ||
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 | |
60 | #define UINT32_MAX UINT_MAX | |
61 | #define UINT32_MIN UINT_MIN | |
62 | ||
63 | #define INT64_MAX LLONG_MAX | |
64 | #define INT64_MIN LLONG_MIN | |
65 | #define UINT64_MAX ULLONG_MAX | |
66 | #define UINT64_MIN ULLONG_MIN | |
67 | ||
68 | #define NBBY 8 | |
69 | #define ENOTSUP EOPNOTSUPP | |
70 | ||
71 | #define MAXMSGLEN 256 | |
72 | #define MAXNAMELEN 256 | |
73 | #define MAXPATHLEN PATH_MAX | |
74 | #define MAXOFFSET_T LLONG_MAX | |
75 | #define MAXBSIZE 8192 | |
76 | #define DEV_BSIZE 512 | |
77 | #define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */ | |
78 | ||
79 | #define proc_pageout NULL | |
80 | #define curproc current | |
81 | #define max_ncpus num_possible_cpus() | |
82 | #define boot_ncpus num_online_cpus() | |
83 | #define CPU_SEQID smp_processor_id() | |
84 | #define _NOTE(x) | |
85 | #define is_system_labeled() 0 | |
14c5326c | 86 | |
a50cede3 | 87 | #ifndef RLIM64_INFINITY |
34ee731f | 88 | #define RLIM64_INFINITY (~0ULL) |
a50cede3 | 89 | #endif |
6adf99e7 | 90 | |
34ee731f AX |
91 | /* |
92 | * 0..MAX_PRIO-1: Process priority | |
14c5326c | 93 | * 0..MAX_RT_PRIO-1: RT priority tasks |
94 | * MAX_RT_PRIO..MAX_PRIO-1: SCHED_NORMAL tasks | |
95 | * | |
96 | * Treat shim tasks as SCHED_NORMAL tasks | |
97 | */ | |
34ee731f AX |
98 | #define minclsyspri (MAX_PRIO-1) |
99 | #define maxclsyspri (MAX_RT_PRIO) | |
100 | #define defclsyspri (DEFAULT_PRIO) | |
14c5326c | 101 | |
9e4fb5c2 | 102 | #ifndef NICE_TO_PRIO |
34ee731f | 103 | #define NICE_TO_PRIO(nice) (MAX_RT_PRIO + (nice) + 20) |
9e4fb5c2 LG |
104 | #endif |
105 | #ifndef PRIO_TO_NICE | |
34ee731f | 106 | #define PRIO_TO_NICE(prio) ((prio) - MAX_RT_PRIO - 20) |
9e4fb5c2 | 107 | #endif |
14c5326c | 108 | |
10946b02 AX |
109 | /* |
110 | * Missing macros | |
14c5326c | 111 | */ |
10946b02 | 112 | #ifndef PAGESIZE |
34ee731f | 113 | #define PAGESIZE PAGE_SIZE |
10946b02 | 114 | #endif |
14c5326c | 115 | |
ec06701b | 116 | #ifndef PAGESHIFT |
34ee731f | 117 | #define PAGESHIFT PAGE_SHIFT |
ec06701b AX |
118 | #endif |
119 | ||
14c5326c | 120 | /* from Solaris sys/byteorder.h */ |
34ee731f AX |
121 | #define BSWAP_8(x) ((x) & 0xff) |
122 | #define BSWAP_16(x) ((BSWAP_8(x) << 8) | BSWAP_8((x) >> 8)) | |
123 | #define BSWAP_32(x) ((BSWAP_16(x) << 16) | BSWAP_16((x) >> 16)) | |
124 | #define BSWAP_64(x) ((BSWAP_32(x) << 32) | BSWAP_32((x) >> 32)) | |
14c5326c | 125 | |
34ee731f AX |
126 | /* |
127 | * Map some simple functions. | |
14c5326c | 128 | */ |
34ee731f AX |
129 | #define bzero(ptr, size) memset(ptr, 0, size) |
130 | #define bcopy(src, dest, size) memmove(dest, src, size) | |
131 | #define bcmp(src, dest, size) memcmp((src), (dest), (size_t)(size)) | |
a713518f | 132 | |
133 | /* Dtrace probes do not exist in the linux kernel */ | |
0f372044 BB |
134 | #ifdef DTRACE_PROBE |
135 | #undef DTRACE_PROBE | |
136 | #endif /* DTRACE_PROBE */ | |
34ee731f | 137 | #define DTRACE_PROBE(a) ((void)0) |
a713518f | 138 | |
139 | #ifdef DTRACE_PROBE1 | |
140 | #undef DTRACE_PROBE1 | |
141 | #endif /* DTRACE_PROBE1 */ | |
34ee731f | 142 | #define DTRACE_PROBE1(a, b, c) ((void)0) |
a713518f | 143 | |
144 | #ifdef DTRACE_PROBE2 | |
145 | #undef DTRACE_PROBE2 | |
146 | #endif /* DTRACE_PROBE2 */ | |
34ee731f | 147 | #define DTRACE_PROBE2(a, b, c, d, e) ((void)0) |
a713518f | 148 | |
149 | #ifdef DTRACE_PROBE3 | |
150 | #undef DTRACE_PROBE3 | |
151 | #endif /* DTRACE_PROBE3 */ | |
34ee731f | 152 | #define DTRACE_PROBE3(a, b, c, d, e, f, g) ((void)0) |
a713518f | 153 | |
154 | #ifdef DTRACE_PROBE4 | |
155 | #undef DTRACE_PROBE4 | |
156 | #endif /* DTRACE_PROBE4 */ | |
34ee731f | 157 | #define DTRACE_PROBE4(a, b, c, d, e, f, g, h, i) ((void)0) |
14c5326c | 158 | |
77b1fe8f | 159 | /* Missing globals */ |
0835057e | 160 | extern char spl_version[32]; |
fa6f7d8f | 161 | extern unsigned long spl_hostid; |
14c5326c | 162 | |
77b1fe8f | 163 | /* Missing misc functions */ |
99639e4a | 164 | extern uint32_t zone_get_hostid(void *zone); |
51a727e9 BB |
165 | extern void spl_setup(void); |
166 | extern void spl_cleanup(void); | |
77b1fe8f | 167 | |
ec06701b AX |
168 | #define highbit(x) __fls(x) |
169 | #define lowbit(x) __ffs(x) | |
170 | ||
10946b02 | 171 | #define highbit64(x) fls64(x) |
34ee731f | 172 | #define makedevice(maj, min) makedev(maj, min) |
14c5326c | 173 | |
14c5326c | 174 | /* common macros */ |
175 | #ifndef MIN | |
34ee731f | 176 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) |
14c5326c | 177 | #endif |
178 | #ifndef MAX | |
34ee731f | 179 | #define MAX(a, b) ((a) < (b) ? (b) : (a)) |
14c5326c | 180 | #endif |
181 | #ifndef ABS | |
34ee731f | 182 | #define ABS(a) ((a) < 0 ? -(a) : (a)) |
37319315 BB |
183 | #endif |
184 | #ifndef DIV_ROUND_UP | |
34ee731f | 185 | #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
37319315 BB |
186 | #endif |
187 | #ifndef roundup | |
34ee731f | 188 | #define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y)) |
14c5326c | 189 | #endif |
9e4fb5c2 | 190 | #ifndef howmany |
34ee731f | 191 | #define howmany(x, y) (((x) + ((y) - 1)) / (y)) |
9e4fb5c2 | 192 | #endif |
14c5326c | 193 | |
194 | /* | |
195 | * Compatibility macros/typedefs needed for Solaris -> Linux port | |
196 | */ | |
34ee731f AX |
197 | #define P2ALIGN(x, align) ((x) & -(align)) |
198 | #define P2CROSS(x, y, align) (((x) ^ (y)) > (align) - 1) | |
199 | #define P2ROUNDUP(x, align) ((((x) - 1) | ((align) - 1)) + 1) | |
200 | #define P2PHASE(x, align) ((x) & ((align) - 1)) | |
201 | #define P2NPHASE(x, align) (-(x) & ((align) - 1)) | |
202 | #define ISP2(x) (((x) & ((x) - 1)) == 0) | |
203 | #define IS_P2ALIGNED(v, a) ((((uintptr_t)(v)) & ((uintptr_t)(a) - 1)) == 0) | |
204 | #define P2BOUNDARY(off, len, align) \ | |
32c6147d | 205 | (((off) ^ ((off) + (len) - 1)) > (align) - 1) |
14c5326c | 206 | |
207 | /* | |
208 | * Typed version of the P2* macros. These macros should be used to ensure | |
209 | * that the result is correctly calculated based on the data type of (x), | |
210 | * which is passed in as the last argument, regardless of the data | |
211 | * type of the alignment. For example, if (x) is of type uint64_t, | |
212 | * and we want to round it up to a page boundary using "PAGESIZE" as | |
213 | * the alignment, we can do either | |
32c6147d | 214 | * |
14c5326c | 215 | * P2ROUNDUP(x, (uint64_t)PAGESIZE) |
216 | * or | |
217 | * P2ROUNDUP_TYPED(x, PAGESIZE, uint64_t) | |
218 | */ | |
34ee731f AX |
219 | #define P2ALIGN_TYPED(x, align, type) \ |
220 | ((type)(x) & -(type)(align)) | |
221 | #define P2PHASE_TYPED(x, align, type) \ | |
222 | ((type)(x) & ((type)(align) - 1)) | |
223 | #define P2NPHASE_TYPED(x, align, type) \ | |
224 | (-(type)(x) & ((type)(align) - 1)) | |
225 | #define P2ROUNDUP_TYPED(x, align, type) \ | |
226 | ((((type)(x) - 1) | ((type)(align) - 1)) + 1) | |
227 | #define P2END_TYPED(x, align, type) \ | |
228 | (-(~(type)(x) & -(type)(align))) | |
229 | #define P2PHASEUP_TYPED(x, align, phase, type) \ | |
230 | ((type)(phase) - (((type)(phase) - (type)(x)) & -(type)(align))) | |
231 | #define P2CROSS_TYPED(x, y, align, type) \ | |
232 | (((type)(x) ^ (type)(y)) > (type)(align) - 1) | |
233 | #define P2SAMEHIGHBIT_TYPED(x, y, type) \ | |
234 | (((type)(x) ^ (type)(y)) < ((type)(x) & (type)(y))) | |
14c5326c | 235 | |
236 | #if defined(_KERNEL) && !defined(_KMEMUSER) && !defined(offsetof) | |
237 | ||
238 | /* avoid any possibility of clashing with <stddef.h> version */ | |
239 | ||
34ee731f | 240 | #define offsetof(s, m) ((size_t)(&(((s *)0)->m))) |
14c5326c | 241 | #endif |
242 | ||
14c5326c | 243 | #endif /* _SPL_SYSMACROS_H */ |