]> git.proxmox.com Git - mirror_spl-debian.git/blame - include/sys/sysmacros.h
Expand SEM() outside init_rwsem and directly call __init_rwsem().
[mirror_spl-debian.git] / include / sys / sysmacros.h
CommitLineData
715f6251 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
14c5326c 27#ifndef _SPL_SYSMACROS_H
28#define _SPL_SYSMACROS_H
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34#include <linux/module.h>
57d1b188 35#include <sys/debug.h>
05ae387b 36#include <sys/varargs.h>
36e6f861 37#include <sys/zone.h>
1ec74a11 38#include <sys/signal.h>
14c5326c 39
40#ifndef _KERNEL
41#define _KERNEL __KERNEL__
42#endif
43
44/* Missing defines.
45 */
ed61a7d0 46#define FALSE 0
47#define TRUE 1
b0dd3380 48
14c5326c 49#define INT32_MAX INT_MAX
3b3ba48f 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
14c5326c 58#define NBBY 8
59#define ENOTSUP ENOTSUPP
b0dd3380 60
05ae387b 61#define MAXMSGLEN 256
14c5326c 62#define MAXNAMELEN 256
63#define MAXPATHLEN PATH_MAX
f500ccff
RC
64
65#ifdef _LP64
b0dd3380 66#define MAXOFFSET_T 0x7fffffffffffffffl
f500ccff
RC
67#else
68#define MAXOFFSET_T 0x7fffffffl
69#endif
b0dd3380 70
71#define MAXBSIZE 8192
72#define DEV_BSIZE 512
73#define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */
74
36b313da
BB
75#define curproc current
76#define proc_pageout NULL
14c5326c 77#define max_ncpus 64
12472b24 78#define CPU_SEQID smp_processor_id() /* I think... */
b0dd3380 79#define _NOTE(x)
14c5326c 80
36b313da 81
6adf99e7 82#define RLIM64_INFINITY RLIM_INFINITY
83
14c5326c 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
14c5326c 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) memcpy(dest,src,size)
b0dd3380 110#define bcmp(src,dest,size) memcmp((src), (dest), (size_t)(size))
a713518f 111
112/* Dtrace probes do not exist in the linux kernel */
0f372044
BB
113#ifdef DTRACE_PROBE
114#undef DTRACE_PROBE
115#endif /* DTRACE_PROBE */
116#define DTRACE_PROBE(a) ((void)0)
a713518f 117
118#ifdef DTRACE_PROBE1
119#undef DTRACE_PROBE1
120#endif /* DTRACE_PROBE1 */
3b3ba48f 121#define DTRACE_PROBE1(a, b, c) ((void)0)
a713518f 122
123#ifdef DTRACE_PROBE2
124#undef DTRACE_PROBE2
125#endif /* DTRACE_PROBE2 */
3b3ba48f 126#define DTRACE_PROBE2(a, b, c, d, e) ((void)0)
a713518f 127
128#ifdef DTRACE_PROBE3
129#undef DTRACE_PROBE3
130#endif /* DTRACE_PROBE3 */
3b3ba48f 131#define DTRACE_PROBE3(a, b, c, d, e, f, g) ((void)0)
a713518f 132
133#ifdef DTRACE_PROBE4
134#undef DTRACE_PROBE4
135#endif /* DTRACE_PROBE4 */
3b3ba48f 136#define DTRACE_PROBE4(a, b, c, d, e, f, g, h, i) ((void)0)
14c5326c 137
77b1fe8f 138/* Missing globals */
3561541c 139extern char spl_version[16];
937879f1 140extern long spl_hostid;
141extern char hw_serial[11];
14c5326c 142extern int p0;
143
77b1fe8f 144/* Missing misc functions */
145extern int highbit(unsigned long i);
99639e4a 146extern uint32_t zone_get_hostid(void *zone);
77b1fe8f 147
14c5326c 148#define makedevice(maj,min) makedev(maj,min)
149
14c5326c 150/* common macros */
151#ifndef MIN
37319315 152#define MIN(a, b) ((a) < (b) ? (a) : (b))
14c5326c 153#endif
154#ifndef MAX
37319315 155#define MAX(a, b) ((a) < (b) ? (b) : (a))
14c5326c 156#endif
157#ifndef ABS
37319315
BB
158#define ABS(a) ((a) < 0 ? -(a) : (a))
159#endif
160#ifndef DIV_ROUND_UP
161#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
162#endif
163#ifndef roundup
164#define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
14c5326c 165#endif
166
167/*
168 * Compatibility macros/typedefs needed for Solaris -> Linux port
169 */
170#define P2ALIGN(x, align) ((x) & -(align))
171#define P2CROSS(x, y, align) (((x) ^ (y)) > (align) - 1)
172#define P2ROUNDUP(x, align) (-(-(x) & -(align)))
173#define P2ROUNDUP_TYPED(x, align, type) \
174 (-(-(type)(x) & -(type)(align)))
175#define P2PHASE(x, align) ((x) & ((align) - 1))
176#define P2NPHASE(x, align) (-(x) & ((align) - 1))
177#define P2NPHASE_TYPED(x, align, type) \
178 (-(type)(x) & ((type)(align) - 1))
179#define ISP2(x) (((x) & ((x) - 1)) == 0)
180#define IS_P2ALIGNED(v, a) ((((uintptr_t)(v)) & ((uintptr_t)(a) - 1)) == 0)
160c63ab
BB
181#define P2BOUNDARY(off, len, align) \
182 (((off) ^ ((off) + (len) - 1)) > (align) - 1)
14c5326c 183
184/*
185 * Typed version of the P2* macros. These macros should be used to ensure
186 * that the result is correctly calculated based on the data type of (x),
187 * which is passed in as the last argument, regardless of the data
188 * type of the alignment. For example, if (x) is of type uint64_t,
189 * and we want to round it up to a page boundary using "PAGESIZE" as
190 * the alignment, we can do either
191 * P2ROUNDUP(x, (uint64_t)PAGESIZE)
192 * or
193 * P2ROUNDUP_TYPED(x, PAGESIZE, uint64_t)
194 */
195#define P2ALIGN_TYPED(x, align, type) \
196 ((type)(x) & -(type)(align))
197#define P2PHASE_TYPED(x, align, type) \
198 ((type)(x) & ((type)(align) - 1))
199#define P2NPHASE_TYPED(x, align, type) \
200 (-(type)(x) & ((type)(align) - 1))
201#define P2ROUNDUP_TYPED(x, align, type) \
202 (-(-(type)(x) & -(type)(align)))
203#define P2END_TYPED(x, align, type) \
204 (-(~(type)(x) & -(type)(align)))
205#define P2PHASEUP_TYPED(x, align, phase, type) \
206 ((type)(phase) - (((type)(phase) - (type)(x)) & -(type)(align)))
207#define P2CROSS_TYPED(x, y, align, type) \
208 (((type)(x) ^ (type)(y)) > (type)(align) - 1)
209#define P2SAMEHIGHBIT_TYPED(x, y, type) \
210 (((type)(x) ^ (type)(y)) < ((type)(x) & (type)(y)))
211
212#if defined(_KERNEL) && !defined(_KMEMUSER) && !defined(offsetof)
213
214/* avoid any possibility of clashing with <stddef.h> version */
215
216#define offsetof(s, m) ((size_t)(&(((s *)0)->m)))
217#endif
218
219#ifdef __cplusplus
220}
221#endif
222
223#endif /* _SPL_SYSMACROS_H */