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