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