]> git.proxmox.com Git - mirror_zfs.git/blob - include/spl/sys/sysmacros.h
Prepare SPL repo to merge with ZFS repo
[mirror_zfs.git] / include / spl / sys / sysmacros.h
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>.
6 * UCRL-CODE-235197
7 *
8 * This file is part of the SPL, Solaris Porting Layer.
9 * For details, see <http://zfsonlinux.org/>.
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.
15 *
16 * The SPL is distributed in the hope that it will be useful, but WITHOUT
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
22 * with the SPL. If not, see <http://www.gnu.org/licenses/>.
23 */
24
25 #ifndef _SPL_SYSMACROS_H
26 #define _SPL_SYSMACROS_H
27
28 #include <linux/module.h>
29 #include <linux/sched.h>
30 #include <linux/cpumask.h>
31 #include <sys/debug.h>
32 #include <sys/zone.h>
33 #include <sys/signal.h>
34 #include <asm/page.h>
35
36 #ifdef HAVE_SCHED_RT_HEADER
37 #include <linux/sched/rt.h>
38 #endif
39
40 #ifndef _KERNEL
41 #define _KERNEL __KERNEL__
42 #endif
43
44 #define FALSE 0
45 #define TRUE 1
46
47 #define INT8_MAX (127)
48 #define INT8_MIN (-128)
49 #define UINT8_MAX (255)
50 #define UINT8_MIN (0)
51
52 #define INT16_MAX (32767)
53 #define INT16_MIN (-32768)
54 #define UINT16_MAX (65535)
55 #define UINT16_MIN (0)
56
57 #define INT32_MAX INT_MAX
58 #define INT32_MIN INT_MIN
59 #define UINT32_MAX UINT_MAX
60 #define UINT32_MIN UINT_MIN
61
62 #define INT64_MAX LLONG_MAX
63 #define INT64_MIN LLONG_MIN
64 #define UINT64_MAX ULLONG_MAX
65 #define UINT64_MIN ULLONG_MIN
66
67 #define NBBY 8
68
69 #define MAXMSGLEN 256
70 #define MAXNAMELEN 256
71 #define MAXPATHLEN 4096
72 #define MAXOFFSET_T LLONG_MAX
73 #define MAXBSIZE 8192
74 #define DEV_BSIZE 512
75 #define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */
76
77 #define proc_pageout NULL
78 #define curproc current
79 #define max_ncpus num_possible_cpus()
80 #define boot_ncpus num_online_cpus()
81 #define CPU_SEQID smp_processor_id()
82 #define _NOTE(x)
83 #define is_system_labeled() 0
84
85 #ifndef RLIM64_INFINITY
86 #define RLIM64_INFINITY (~0ULL)
87 #endif
88
89 /*
90 * 0..MAX_PRIO-1: Process priority
91 * 0..MAX_RT_PRIO-1: RT priority tasks
92 * MAX_RT_PRIO..MAX_PRIO-1: SCHED_NORMAL tasks
93 *
94 * Treat shim tasks as SCHED_NORMAL tasks
95 */
96 #define minclsyspri (MAX_PRIO-1)
97 #define maxclsyspri (MAX_RT_PRIO)
98 #define defclsyspri (DEFAULT_PRIO)
99
100 #ifndef NICE_TO_PRIO
101 #define NICE_TO_PRIO(nice) (MAX_RT_PRIO + (nice) + 20)
102 #endif
103 #ifndef PRIO_TO_NICE
104 #define PRIO_TO_NICE(prio) ((prio) - MAX_RT_PRIO - 20)
105 #endif
106
107 /*
108 * Missing macros
109 */
110 #ifndef PAGESIZE
111 #define PAGESIZE PAGE_SIZE
112 #endif
113
114 #ifndef PAGESHIFT
115 #define PAGESHIFT PAGE_SHIFT
116 #endif
117
118 /* Dtrace probes do not exist in the linux kernel */
119 #ifdef DTRACE_PROBE
120 #undef DTRACE_PROBE
121 #endif /* DTRACE_PROBE */
122 #define DTRACE_PROBE(a) ((void)0)
123
124 #ifdef DTRACE_PROBE1
125 #undef DTRACE_PROBE1
126 #endif /* DTRACE_PROBE1 */
127 #define DTRACE_PROBE1(a, b, c) ((void)0)
128
129 #ifdef DTRACE_PROBE2
130 #undef DTRACE_PROBE2
131 #endif /* DTRACE_PROBE2 */
132 #define DTRACE_PROBE2(a, b, c, d, e) ((void)0)
133
134 #ifdef DTRACE_PROBE3
135 #undef DTRACE_PROBE3
136 #endif /* DTRACE_PROBE3 */
137 #define DTRACE_PROBE3(a, b, c, d, e, f, g) ((void)0)
138
139 #ifdef DTRACE_PROBE4
140 #undef DTRACE_PROBE4
141 #endif /* DTRACE_PROBE4 */
142 #define DTRACE_PROBE4(a, b, c, d, e, f, g, h, i) ((void)0)
143
144 /* Missing globals */
145 extern char spl_version[32];
146 extern unsigned long spl_hostid;
147
148 /* Missing misc functions */
149 extern uint32_t zone_get_hostid(void *zone);
150 extern void spl_setup(void);
151 extern void spl_cleanup(void);
152
153 #define highbit(x) __fls(x)
154 #define lowbit(x) __ffs(x)
155
156 #define highbit64(x) fls64(x)
157 #define makedevice(maj, min) makedev(maj, min)
158
159 /* common macros */
160 #ifndef MIN
161 #define MIN(a, b) ((a) < (b) ? (a) : (b))
162 #endif
163 #ifndef MAX
164 #define MAX(a, b) ((a) < (b) ? (b) : (a))
165 #endif
166 #ifndef ABS
167 #define ABS(a) ((a) < 0 ? -(a) : (a))
168 #endif
169 #ifndef DIV_ROUND_UP
170 #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
171 #endif
172 #ifndef roundup
173 #define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
174 #endif
175 #ifndef howmany
176 #define howmany(x, y) (((x) + ((y) - 1)) / (y))
177 #endif
178
179 /*
180 * Compatibility macros/typedefs needed for Solaris -> Linux port
181 */
182 #define P2ALIGN(x, align) ((x) & -(align))
183 #define P2CROSS(x, y, align) (((x) ^ (y)) > (align) - 1)
184 #define P2ROUNDUP(x, align) ((((x) - 1) | ((align) - 1)) + 1)
185 #define P2PHASE(x, align) ((x) & ((align) - 1))
186 #define P2NPHASE(x, align) (-(x) & ((align) - 1))
187 #define ISP2(x) (((x) & ((x) - 1)) == 0)
188 #define IS_P2ALIGNED(v, a) ((((uintptr_t)(v)) & ((uintptr_t)(a) - 1)) == 0)
189 #define P2BOUNDARY(off, len, align) \
190 (((off) ^ ((off) + (len) - 1)) > (align) - 1)
191
192 /*
193 * Typed version of the P2* macros. These macros should be used to ensure
194 * that the result is correctly calculated based on the data type of (x),
195 * which is passed in as the last argument, regardless of the data
196 * type of the alignment. For example, if (x) is of type uint64_t,
197 * and we want to round it up to a page boundary using "PAGESIZE" as
198 * the alignment, we can do either
199 *
200 * P2ROUNDUP(x, (uint64_t)PAGESIZE)
201 * or
202 * P2ROUNDUP_TYPED(x, PAGESIZE, uint64_t)
203 */
204 #define P2ALIGN_TYPED(x, align, type) \
205 ((type)(x) & -(type)(align))
206 #define P2PHASE_TYPED(x, align, type) \
207 ((type)(x) & ((type)(align) - 1))
208 #define P2NPHASE_TYPED(x, align, type) \
209 (-(type)(x) & ((type)(align) - 1))
210 #define P2ROUNDUP_TYPED(x, align, type) \
211 ((((type)(x) - 1) | ((type)(align) - 1)) + 1)
212 #define P2END_TYPED(x, align, type) \
213 (-(~(type)(x) & -(type)(align)))
214 #define P2PHASEUP_TYPED(x, align, phase, type) \
215 ((type)(phase) - (((type)(phase) - (type)(x)) & -(type)(align)))
216 #define P2CROSS_TYPED(x, y, align, type) \
217 (((type)(x) ^ (type)(y)) > (type)(align) - 1)
218 #define P2SAMEHIGHBIT_TYPED(x, y, type) \
219 (((type)(x) ^ (type)(y)) < ((type)(x) & (type)(y)))
220
221 #if defined(_KERNEL) && !defined(_KMEMUSER) && !defined(offsetof)
222
223 /* avoid any possibility of clashing with <stddef.h> version */
224
225 #define offsetof(s, m) ((size_t)(&(((s *)0)->m)))
226 #endif
227
228 #endif /* _SPL_SYSMACROS_H */