]> git.proxmox.com Git - mirror_zfs.git/blame - include/spl/sys/sysmacros.h
Update build system and packaging
[mirror_zfs.git] / include / spl / sys / sysmacros.h
CommitLineData
4b393c50 1/*
716154c5
BB
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
BB
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
BB
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 22 * with the SPL. If not, see <http://www.gnu.org/licenses/>.
4b393c50 23 */
715f6251 24
14c5326c 25#ifndef _SPL_SYSMACROS_H
5461eefe 26#define _SPL_SYSMACROS_H
14c5326c 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>
36e6f861 32#include <sys/zone.h>
1ec74a11 33#include <sys/signal.h>
43b857fd 34#include <asm/page.h>
14c5326c 35
10087fe1
RY
36#ifdef HAVE_SCHED_RT_HEADER
37#include <linux/sched/rt.h>
38#endif
39
14c5326c 40#ifndef _KERNEL
5461eefe 41#define _KERNEL __KERNEL__
14c5326c
BB
42#endif
43
5461eefe
BB
44#define FALSE 0
45#define TRUE 1
46
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
59#define UINT32_MAX UINT_MAX
60#define UINT32_MIN UINT_MIN
61
62#define INT64_MAX LLONG_MAX
63#define INT64_MIN LLONG_MIN
64#define UINT64_MAX ULLONG_MAX
65#define UINT64_MIN ULLONG_MIN
66
67#define NBBY 8
5461eefe
BB
68
69#define MAXMSGLEN 256
70#define MAXNAMELEN 256
a9125891 71#define MAXPATHLEN 4096
5461eefe
BB
72#define MAXOFFSET_T LLONG_MAX
73#define MAXBSIZE 8192
74#define DEV_BSIZE 512
75#define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */
76
77#define proc_pageout NULL
78#define curproc current
79#define max_ncpus num_possible_cpus()
80#define boot_ncpus num_online_cpus()
81#define CPU_SEQID smp_processor_id()
5461eefe 82#define is_system_labeled() 0
14c5326c 83
a50cede3 84#ifndef RLIM64_INFINITY
5461eefe 85#define RLIM64_INFINITY (~0ULL)
a50cede3 86#endif
6adf99e7 87
5461eefe
BB
88/*
89 * 0..MAX_PRIO-1: Process priority
14c5326c
BB
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 */
5461eefe
BB
95#define minclsyspri (MAX_PRIO-1)
96#define maxclsyspri (MAX_RT_PRIO)
97#define defclsyspri (DEFAULT_PRIO)
14c5326c 98
1538f4b6 99#ifndef NICE_TO_PRIO
5461eefe 100#define NICE_TO_PRIO(nice) (MAX_RT_PRIO + (nice) + 20)
1538f4b6
CC
101#endif
102#ifndef PRIO_TO_NICE
5461eefe 103#define PRIO_TO_NICE(prio) ((prio) - MAX_RT_PRIO - 20)
1538f4b6 104#endif
14c5326c 105
f9bde4f7 106/*
107 * Missing macros
14c5326c 108 */
f9bde4f7 109#ifndef PAGESIZE
5461eefe 110#define PAGESIZE PAGE_SIZE
f9bde4f7 111#endif
14c5326c 112
43b857fd 113#ifndef PAGESHIFT
5461eefe 114#define PAGESHIFT PAGE_SHIFT
43b857fd
DQ
115#endif
116
a713518f 117/* Dtrace probes do not exist in the linux kernel */
0f372044
BB
118#ifdef DTRACE_PROBE
119#undef DTRACE_PROBE
120#endif /* DTRACE_PROBE */
5461eefe 121#define DTRACE_PROBE(a) ((void)0)
a713518f
BB
122
123#ifdef DTRACE_PROBE1
124#undef DTRACE_PROBE1
125#endif /* DTRACE_PROBE1 */
5461eefe 126#define DTRACE_PROBE1(a, b, c) ((void)0)
a713518f
BB
127
128#ifdef DTRACE_PROBE2
129#undef DTRACE_PROBE2
130#endif /* DTRACE_PROBE2 */
5461eefe 131#define DTRACE_PROBE2(a, b, c, d, e) ((void)0)
a713518f
BB
132
133#ifdef DTRACE_PROBE3
134#undef DTRACE_PROBE3
135#endif /* DTRACE_PROBE3 */
5461eefe 136#define DTRACE_PROBE3(a, b, c, d, e, f, g) ((void)0)
a713518f
BB
137
138#ifdef DTRACE_PROBE4
139#undef DTRACE_PROBE4
140#endif /* DTRACE_PROBE4 */
5461eefe 141#define DTRACE_PROBE4(a, b, c, d, e, f, g, h, i) ((void)0)
14c5326c 142
77b1fe8f 143/* Missing globals */
0835057e 144extern char spl_version[32];
fa6f7d8f 145extern unsigned long spl_hostid;
14c5326c 146
77b1fe8f 147/* Missing misc functions */
99639e4a 148extern uint32_t zone_get_hostid(void *zone);
51a727e9
BB
149extern void spl_setup(void);
150extern void spl_cleanup(void);
77b1fe8f 151
d2f97b2a
TC
152#define highbit(x) __fls(x)
153#define lowbit(x) __ffs(x)
154
87f8055a 155#define highbit64(x) fls64(x)
5461eefe 156#define makedevice(maj, min) makedev(maj, min)
14c5326c 157
14c5326c
BB
158/* common macros */
159#ifndef MIN
5461eefe 160#define MIN(a, b) ((a) < (b) ? (a) : (b))
14c5326c
BB
161#endif
162#ifndef MAX
5461eefe 163#define MAX(a, b) ((a) < (b) ? (b) : (a))
14c5326c
BB
164#endif
165#ifndef ABS
5461eefe 166#define ABS(a) ((a) < 0 ? -(a) : (a))
37319315
BB
167#endif
168#ifndef DIV_ROUND_UP
5461eefe 169#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
37319315
BB
170#endif
171#ifndef roundup
5461eefe 172#define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
14c5326c 173#endif
7f23e001 174#ifndef howmany
5461eefe 175#define howmany(x, y) (((x) + ((y) - 1)) / (y))
7f23e001 176#endif
14c5326c
BB
177
178/*
179 * Compatibility macros/typedefs needed for Solaris -> Linux port
180 */
5461eefe
BB
181#define P2ALIGN(x, align) ((x) & -(align))
182#define P2CROSS(x, y, align) (((x) ^ (y)) > (align) - 1)
183#define P2ROUNDUP(x, align) ((((x) - 1) | ((align) - 1)) + 1)
184#define P2PHASE(x, align) ((x) & ((align) - 1))
185#define P2NPHASE(x, align) (-(x) & ((align) - 1))
186#define ISP2(x) (((x) & ((x) - 1)) == 0)
187#define IS_P2ALIGNED(v, a) ((((uintptr_t)(v)) & ((uintptr_t)(a) - 1)) == 0)
188#define P2BOUNDARY(off, len, align) \
32c6147d 189 (((off) ^ ((off) + (len) - 1)) > (align) - 1)
14c5326c
BB
190
191/*
192 * Typed version of the P2* macros. These macros should be used to ensure
193 * that the result is correctly calculated based on the data type of (x),
194 * which is passed in as the last argument, regardless of the data
195 * type of the alignment. For example, if (x) is of type uint64_t,
196 * and we want to round it up to a page boundary using "PAGESIZE" as
197 * the alignment, we can do either
32c6147d 198 *
14c5326c
BB
199 * P2ROUNDUP(x, (uint64_t)PAGESIZE)
200 * or
201 * P2ROUNDUP_TYPED(x, PAGESIZE, uint64_t)
202 */
5461eefe
BB
203#define P2ALIGN_TYPED(x, align, type) \
204 ((type)(x) & -(type)(align))
205#define P2PHASE_TYPED(x, align, type) \
206 ((type)(x) & ((type)(align) - 1))
207#define P2NPHASE_TYPED(x, align, type) \
208 (-(type)(x) & ((type)(align) - 1))
209#define P2ROUNDUP_TYPED(x, align, type) \
210 ((((type)(x) - 1) | ((type)(align) - 1)) + 1)
211#define P2END_TYPED(x, align, type) \
212 (-(~(type)(x) & -(type)(align)))
213#define P2PHASEUP_TYPED(x, align, phase, type) \
214 ((type)(phase) - (((type)(phase) - (type)(x)) & -(type)(align)))
215#define P2CROSS_TYPED(x, y, align, type) \
216 (((type)(x) ^ (type)(y)) > (type)(align) - 1)
217#define P2SAMEHIGHBIT_TYPED(x, y, type) \
218 (((type)(x) ^ (type)(y)) < ((type)(x) & (type)(y)))
14c5326c
BB
219
220#if defined(_KERNEL) && !defined(_KMEMUSER) && !defined(offsetof)
221
222/* avoid any possibility of clashing with <stddef.h> version */
223
5461eefe 224#define offsetof(s, m) ((size_t)(&(((s *)0)->m)))
14c5326c
BB
225#endif
226
14c5326c 227#endif /* _SPL_SYSMACROS_H */