]> git.proxmox.com Git - mirror_spl.git/blob - include/sys/sysmacros.h
Public Release Prep
[mirror_spl.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://github.com/behlendorf/spl/>.
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 <sys/debug.h>
30 #include <sys/varargs.h>
31 #include <sys/zone.h>
32 #include <sys/signal.h>
33
34 #ifndef _KERNEL
35 #define _KERNEL __KERNEL__
36 #endif
37
38 #define FALSE 0
39 #define TRUE 1
40
41 #define INT32_MAX INT_MAX
42 #define INT32_MIN INT_MIN
43 #define UINT32_MAX UINT_MAX
44 #define UINT32_MIN UINT_MIN
45 #define INT64_MAX LLONG_MAX
46 #define INT64_MIN LLONG_MIN
47 #define UINT64_MAX ULLONG_MAX
48 #define UINT64_MIN ULLONG_MIN
49
50 #define NBBY 8
51 #define ENOTSUP ENOTSUPP
52
53 #define MAXMSGLEN 256
54 #define MAXNAMELEN 256
55 #define MAXPATHLEN PATH_MAX
56
57 #ifdef _LP64
58 #define MAXOFFSET_T 0x7fffffffffffffffl
59 #else
60 #define MAXOFFSET_T 0x7fffffffl
61 #endif
62
63 #define MAXBSIZE 8192
64 #define DEV_BSIZE 512
65 #define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */
66
67 #define curproc current
68 #define proc_pageout NULL
69 #define max_ncpus 64
70 #define CPU_SEQID smp_processor_id() /* I think... */
71 #define _NOTE(x)
72
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 #ifdef DTRACE_PROBE
106 #undef DTRACE_PROBE
107 #endif /* DTRACE_PROBE */
108 #define DTRACE_PROBE(a) ((void)0)
109
110 #ifdef DTRACE_PROBE1
111 #undef DTRACE_PROBE1
112 #endif /* DTRACE_PROBE1 */
113 #define DTRACE_PROBE1(a, b, c) ((void)0)
114
115 #ifdef DTRACE_PROBE2
116 #undef DTRACE_PROBE2
117 #endif /* DTRACE_PROBE2 */
118 #define DTRACE_PROBE2(a, b, c, d, e) ((void)0)
119
120 #ifdef DTRACE_PROBE3
121 #undef DTRACE_PROBE3
122 #endif /* DTRACE_PROBE3 */
123 #define DTRACE_PROBE3(a, b, c, d, e, f, g) ((void)0)
124
125 #ifdef DTRACE_PROBE4
126 #undef DTRACE_PROBE4
127 #endif /* DTRACE_PROBE4 */
128 #define DTRACE_PROBE4(a, b, c, d, e, f, g, h, i) ((void)0)
129
130 /* Missing globals */
131 extern char spl_version[16];
132 extern long spl_hostid;
133 extern char hw_serial[11];
134 extern int p0;
135
136 /* Missing misc functions */
137 extern int highbit(unsigned long i);
138 extern uint32_t zone_get_hostid(void *zone);
139 extern void spl_setup(void);
140 extern void spl_cleanup(void);
141
142 #define makedevice(maj,min) makedev(maj,min)
143
144 /* common macros */
145 #ifndef MIN
146 #define MIN(a, b) ((a) < (b) ? (a) : (b))
147 #endif
148 #ifndef MAX
149 #define MAX(a, b) ((a) < (b) ? (b) : (a))
150 #endif
151 #ifndef ABS
152 #define ABS(a) ((a) < 0 ? -(a) : (a))
153 #endif
154 #ifndef DIV_ROUND_UP
155 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
156 #endif
157 #ifndef roundup
158 #define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
159 #endif
160
161 /*
162 * Compatibility macros/typedefs needed for Solaris -> Linux port
163 */
164 #define P2ALIGN(x, align) ((x) & -(align))
165 #define P2CROSS(x, y, align) (((x) ^ (y)) > (align) - 1)
166 #define P2ROUNDUP(x, align) (-(-(x) & -(align)))
167 #define P2PHASE(x, align) ((x) & ((align) - 1))
168 #define P2NPHASE(x, align) (-(x) & ((align) - 1))
169 #define ISP2(x) (((x) & ((x) - 1)) == 0)
170 #define IS_P2ALIGNED(v, a) ((((uintptr_t)(v)) & ((uintptr_t)(a) - 1)) == 0)
171 #define P2BOUNDARY(off, len, align) \
172 (((off) ^ ((off) + (len) - 1)) > (align) - 1)
173
174 /*
175 * Typed version of the P2* macros. These macros should be used to ensure
176 * that the result is correctly calculated based on the data type of (x),
177 * which is passed in as the last argument, regardless of the data
178 * type of the alignment. For example, if (x) is of type uint64_t,
179 * and we want to round it up to a page boundary using "PAGESIZE" as
180 * the alignment, we can do either
181 * P2ROUNDUP(x, (uint64_t)PAGESIZE)
182 * or
183 * P2ROUNDUP_TYPED(x, PAGESIZE, uint64_t)
184 */
185 #define P2ALIGN_TYPED(x, align, type) \
186 ((type)(x) & -(type)(align))
187 #define P2PHASE_TYPED(x, align, type) \
188 ((type)(x) & ((type)(align) - 1))
189 #define P2NPHASE_TYPED(x, align, type) \
190 (-(type)(x) & ((type)(align) - 1))
191 #define P2ROUNDUP_TYPED(x, align, type) \
192 (-(-(type)(x) & -(type)(align)))
193 #define P2END_TYPED(x, align, type) \
194 (-(~(type)(x) & -(type)(align)))
195 #define P2PHASEUP_TYPED(x, align, phase, type) \
196 ((type)(phase) - (((type)(phase) - (type)(x)) & -(type)(align)))
197 #define P2CROSS_TYPED(x, y, align, type) \
198 (((type)(x) ^ (type)(y)) > (type)(align) - 1)
199 #define P2SAMEHIGHBIT_TYPED(x, y, type) \
200 (((type)(x) ^ (type)(y)) < ((type)(x) & (type)(y)))
201
202 #if defined(_KERNEL) && !defined(_KMEMUSER) && !defined(offsetof)
203
204 /* avoid any possibility of clashing with <stddef.h> version */
205
206 #define offsetof(s, m) ((size_t)(&(((s *)0)->m)))
207 #endif
208
209 #endif /* _SPL_SYSMACROS_H */