]> git.proxmox.com Git - mirror_spl-debian.git/blob - include/sys/sysmacros.h
New upstream version 0.7.2
[mirror_spl-debian.git] / include / 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/varargs.h>
33 #include <sys/zone.h>
34 #include <sys/signal.h>
35 #include <asm/page.h>
36
37 #ifdef HAVE_SCHED_RT_HEADER
38 #include <linux/sched/rt.h>
39 #endif
40
41 #ifndef _KERNEL
42 #define _KERNEL __KERNEL__
43 #endif
44
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
86
87 #ifndef RLIM64_INFINITY
88 #define RLIM64_INFINITY (~0ULL)
89 #endif
90
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 */
97 #define minclsyspri (MAX_PRIO-1)
98 #define maxclsyspri (MAX_RT_PRIO)
99 #define defclsyspri (DEFAULT_PRIO)
100
101 #ifndef NICE_TO_PRIO
102 #define NICE_TO_PRIO(nice) (MAX_RT_PRIO + (nice) + 20)
103 #endif
104 #ifndef PRIO_TO_NICE
105 #define PRIO_TO_NICE(prio) ((prio) - MAX_RT_PRIO - 20)
106 #endif
107
108 /*
109 * Missing macros
110 */
111 #ifndef PAGESIZE
112 #define PAGESIZE PAGE_SIZE
113 #endif
114
115 #ifndef PAGESHIFT
116 #define PAGESHIFT PAGE_SHIFT
117 #endif
118
119 /* from Solaris sys/byteorder.h */
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))
124
125 /* Map some simple functions.
126 */
127 #define bzero(ptr,size) memset(ptr,0,size)
128 #define bcopy(src,dest,size) memmove(dest,src,size)
129 #define bcmp(src,dest,size) memcmp((src), (dest), (size_t)(size))
130
131 /* Dtrace probes do not exist in the linux kernel */
132 #ifdef DTRACE_PROBE
133 #undef DTRACE_PROBE
134 #endif /* DTRACE_PROBE */
135 #define DTRACE_PROBE(a) ((void)0)
136
137 #ifdef DTRACE_PROBE1
138 #undef DTRACE_PROBE1
139 #endif /* DTRACE_PROBE1 */
140 #define DTRACE_PROBE1(a, b, c) ((void)0)
141
142 #ifdef DTRACE_PROBE2
143 #undef DTRACE_PROBE2
144 #endif /* DTRACE_PROBE2 */
145 #define DTRACE_PROBE2(a, b, c, d, e) ((void)0)
146
147 #ifdef DTRACE_PROBE3
148 #undef DTRACE_PROBE3
149 #endif /* DTRACE_PROBE3 */
150 #define DTRACE_PROBE3(a, b, c, d, e, f, g) ((void)0)
151
152 #ifdef DTRACE_PROBE4
153 #undef DTRACE_PROBE4
154 #endif /* DTRACE_PROBE4 */
155 #define DTRACE_PROBE4(a, b, c, d, e, f, g, h, i) ((void)0)
156
157 /* Missing globals */
158 extern char spl_version[32];
159 extern unsigned long spl_hostid;
160
161 /* Missing misc functions */
162 extern uint32_t zone_get_hostid(void *zone);
163 extern void spl_setup(void);
164 extern void spl_cleanup(void);
165
166 #define highbit(x) __fls(x)
167 #define lowbit(x) __ffs(x)
168
169 #define highbit64(x) fls64(x)
170 #define makedevice(maj,min) makedev(maj,min)
171
172 /* common macros */
173 #ifndef MIN
174 #define MIN(a, b) ((a) < (b) ? (a) : (b))
175 #endif
176 #ifndef MAX
177 #define MAX(a, b) ((a) < (b) ? (b) : (a))
178 #endif
179 #ifndef ABS
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))
187 #endif
188 #ifndef howmany
189 #define howmany(x, y) (((x) + ((y) - 1)) / (y))
190 #endif
191
192 /*
193 * Compatibility macros/typedefs needed for Solaris -> Linux port
194 */
195 #define P2ALIGN(x, align) ((x) & -(align))
196 #define P2CROSS(x, y, align) (((x) ^ (y)) > (align) - 1)
197 #define P2ROUNDUP(x, align) ((((x) - 1) | ((align) - 1)) + 1)
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)
202 #define P2BOUNDARY(off, len, align) \
203 (((off) ^ ((off) + (len) - 1)) > (align) - 1)
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
212 *
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) \
224 ((((type)(x) - 1) | ((type)(align) - 1)) + 1)
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
241 #endif /* _SPL_SYSMACROS_H */