]> git.proxmox.com Git - mirror_spl-debian.git/blob - include/sys/sysmacros.h
Go through and add a header with the proper UCRL number.
[mirror_spl-debian.git] / include / sys / sysmacros.h
1 /*
2 * This file is part of the SPL: Solaris Porting Layer.
3 *
4 * Copyright (c) 2008 Lawrence Livermore National Security, LLC.
5 * Produced at Lawrence Livermore National Laboratory
6 * Written by:
7 * Brian Behlendorf <behlendorf1@llnl.gov>,
8 * Herb Wartens <wartens2@llnl.gov>,
9 * Jim Garlick <garlick@llnl.gov>
10 * UCRL-CODE-235197
11 *
12 * This is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 *
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 */
26
27 #ifndef _SPL_SYSMACROS_H
28 #define _SPL_SYSMACROS_H
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 #include <linux/module.h>
35 #include <sys/debug.h>
36 #include <sys/varargs.h>
37 #include <sys/zone.h>
38 #include <sys/signal.h>
39
40 #ifndef _KERNEL
41 #define _KERNEL __KERNEL__
42 #endif
43
44 /* Missing defines.
45 */
46 #define FALSE 0
47 #define TRUE 1
48
49 #define INT32_MAX INT_MAX
50 #define INT32_MIN INT_MIN
51 #define UINT32_MAX UINT_MAX
52 #define UINT32_MIN UINT_MIN
53 #define INT64_MAX LLONG_MAX
54 #define INT64_MIN LLONG_MIN
55 #define UINT64_MAX ULLONG_MAX
56 #define UINT64_MIN ULLONG_MIN
57
58 #define NBBY 8
59 #define ENOTSUP ENOTSUPP
60
61 #define MAXMSGLEN 256
62 #define MAXNAMELEN 256
63 #define MAXPATHLEN PATH_MAX
64 #define MAXOFFSET_T 0x7fffffffffffffffl
65
66 #define MAXBSIZE 8192
67 #define DEV_BSIZE 512
68 #define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */
69
70 #define max_ncpus 64
71 #define CPU_SEQID smp_processor_id() /* I think... */
72 #define _NOTE(x)
73
74 #define RLIM64_INFINITY RLIM_INFINITY
75
76 /* 0..MAX_PRIO-1: Process priority
77 * 0..MAX_RT_PRIO-1: RT priority tasks
78 * MAX_RT_PRIO..MAX_PRIO-1: SCHED_NORMAL tasks
79 *
80 * Treat shim tasks as SCHED_NORMAL tasks
81 */
82 #define minclsyspri (MAX_RT_PRIO)
83 #define maxclsyspri (MAX_PRIO-1)
84
85 #define NICE_TO_PRIO(nice) (MAX_RT_PRIO + (nice) + 20)
86 #define PRIO_TO_NICE(prio) ((prio) - MAX_RT_PRIO - 20)
87
88 /* Missing macros
89 */
90 #define PAGESIZE PAGE_SIZE
91
92 /* from Solaris sys/byteorder.h */
93 #define BSWAP_8(x) ((x) & 0xff)
94 #define BSWAP_16(x) ((BSWAP_8(x) << 8) | BSWAP_8((x) >> 8))
95 #define BSWAP_32(x) ((BSWAP_16(x) << 16) | BSWAP_16((x) >> 16))
96 #define BSWAP_64(x) ((BSWAP_32(x) << 32) | BSWAP_32((x) >> 32))
97
98 /* Map some simple functions.
99 */
100 #define bzero(ptr,size) memset(ptr,0,size)
101 #define bcopy(src,dest,size) memcpy(dest,src,size)
102 #define bcmp(src,dest,size) memcmp((src), (dest), (size_t)(size))
103
104 /* Dtrace probes do not exist in the linux kernel */
105
106 #ifdef DTRACE_PROBE1
107 #undef DTRACE_PROBE1
108 #endif /* DTRACE_PROBE1 */
109 #define DTRACE_PROBE1(a, b, c) ((void)0)
110
111 #ifdef DTRACE_PROBE2
112 #undef DTRACE_PROBE2
113 #endif /* DTRACE_PROBE2 */
114 #define DTRACE_PROBE2(a, b, c, d, e) ((void)0)
115
116 #ifdef DTRACE_PROBE3
117 #undef DTRACE_PROBE3
118 #endif /* DTRACE_PROBE3 */
119 #define DTRACE_PROBE3(a, b, c, d, e, f, g) ((void)0)
120
121 #ifdef DTRACE_PROBE4
122 #undef DTRACE_PROBE4
123 #endif /* DTRACE_PROBE4 */
124 #define DTRACE_PROBE4(a, b, c, d, e, f, g, h, i) ((void)0)
125
126 /* Missing globals */
127 extern char spl_version[16];
128 extern long spl_hostid;
129 extern char hw_serial[11];
130 extern int p0;
131
132 /* Missing misc functions */
133 extern int highbit(unsigned long i);
134 extern int ddi_strtoul(const char *str, char **nptr,
135 int base, unsigned long *result);
136
137 #define makedevice(maj,min) makedev(maj,min)
138
139 /* common macros */
140 #ifndef MIN
141 #define MIN(a, b) ((a) < (b) ? (a) : (b))
142 #endif
143 #ifndef MAX
144 #define MAX(a, b) ((a) < (b) ? (b) : (a))
145 #endif
146 #ifndef ABS
147 #define ABS(a) ((a) < 0 ? -(a) : (a))
148 #endif
149
150 /*
151 * Compatibility macros/typedefs needed for Solaris -> Linux port
152 */
153 #define P2ALIGN(x, align) ((x) & -(align))
154 #define P2CROSS(x, y, align) (((x) ^ (y)) > (align) - 1)
155 #define P2ROUNDUP(x, align) (-(-(x) & -(align)))
156 #define P2ROUNDUP_TYPED(x, align, type) \
157 (-(-(type)(x) & -(type)(align)))
158 #define P2PHASE(x, align) ((x) & ((align) - 1))
159 #define P2NPHASE(x, align) (-(x) & ((align) - 1))
160 #define P2NPHASE_TYPED(x, align, type) \
161 (-(type)(x) & ((type)(align) - 1))
162 #define ISP2(x) (((x) & ((x) - 1)) == 0)
163 #define IS_P2ALIGNED(v, a) ((((uintptr_t)(v)) & ((uintptr_t)(a) - 1)) == 0)
164
165 /*
166 * Typed version of the P2* macros. These macros should be used to ensure
167 * that the result is correctly calculated based on the data type of (x),
168 * which is passed in as the last argument, regardless of the data
169 * type of the alignment. For example, if (x) is of type uint64_t,
170 * and we want to round it up to a page boundary using "PAGESIZE" as
171 * the alignment, we can do either
172 * P2ROUNDUP(x, (uint64_t)PAGESIZE)
173 * or
174 * P2ROUNDUP_TYPED(x, PAGESIZE, uint64_t)
175 */
176 #define P2ALIGN_TYPED(x, align, type) \
177 ((type)(x) & -(type)(align))
178 #define P2PHASE_TYPED(x, align, type) \
179 ((type)(x) & ((type)(align) - 1))
180 #define P2NPHASE_TYPED(x, align, type) \
181 (-(type)(x) & ((type)(align) - 1))
182 #define P2ROUNDUP_TYPED(x, align, type) \
183 (-(-(type)(x) & -(type)(align)))
184 #define P2END_TYPED(x, align, type) \
185 (-(~(type)(x) & -(type)(align)))
186 #define P2PHASEUP_TYPED(x, align, phase, type) \
187 ((type)(phase) - (((type)(phase) - (type)(x)) & -(type)(align)))
188 #define P2CROSS_TYPED(x, y, align, type) \
189 (((type)(x) ^ (type)(y)) > (type)(align) - 1)
190 #define P2SAMEHIGHBIT_TYPED(x, y, type) \
191 (((type)(x) ^ (type)(y)) < ((type)(x) & (type)(y)))
192
193 #if defined(_KERNEL) && !defined(_KMEMUSER) && !defined(offsetof)
194
195 /* avoid any possibility of clashing with <stddef.h> version */
196
197 #define offsetof(s, m) ((size_t)(&(((s *)0)->m)))
198 #endif
199
200 #ifdef __cplusplus
201 }
202 #endif
203
204 #endif /* _SPL_SYSMACROS_H */