]> git.proxmox.com Git - mirror_spl-debian.git/blame - include/sys/sysmacros.h
Public Release Prep
[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
BB
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.
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>
57d1b188 29#include <sys/debug.h>
05ae387b 30#include <sys/varargs.h>
36e6f861 31#include <sys/zone.h>
1ec74a11 32#include <sys/signal.h>
14c5326c 33
34#ifndef _KERNEL
35#define _KERNEL __KERNEL__
36#endif
37
ed61a7d0 38#define FALSE 0
39#define TRUE 1
b0dd3380 40
14c5326c 41#define INT32_MAX INT_MAX
3b3ba48f 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
14c5326c 50#define NBBY 8
51#define ENOTSUP ENOTSUPP
b0dd3380 52
05ae387b 53#define MAXMSGLEN 256
14c5326c 54#define MAXNAMELEN 256
55#define MAXPATHLEN PATH_MAX
f500ccff
RC
56
57#ifdef _LP64
b0dd3380 58#define MAXOFFSET_T 0x7fffffffffffffffl
f500ccff
RC
59#else
60#define MAXOFFSET_T 0x7fffffffl
61#endif
b0dd3380 62
63#define MAXBSIZE 8192
64#define DEV_BSIZE 512
65#define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */
66
36b313da
BB
67#define curproc current
68#define proc_pageout NULL
14c5326c 69#define max_ncpus 64
12472b24 70#define CPU_SEQID smp_processor_id() /* I think... */
b0dd3380 71#define _NOTE(x)
14c5326c 72
36b313da 73
6adf99e7 74#define RLIM64_INFINITY RLIM_INFINITY
75
14c5326c 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
14c5326c 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)
b0dd3380 102#define bcmp(src,dest,size) memcmp((src), (dest), (size_t)(size))
a713518f 103
104/* Dtrace probes do not exist in the linux kernel */
0f372044
BB
105#ifdef DTRACE_PROBE
106#undef DTRACE_PROBE
107#endif /* DTRACE_PROBE */
108#define DTRACE_PROBE(a) ((void)0)
a713518f 109
110#ifdef DTRACE_PROBE1
111#undef DTRACE_PROBE1
112#endif /* DTRACE_PROBE1 */
3b3ba48f 113#define DTRACE_PROBE1(a, b, c) ((void)0)
a713518f 114
115#ifdef DTRACE_PROBE2
116#undef DTRACE_PROBE2
117#endif /* DTRACE_PROBE2 */
3b3ba48f 118#define DTRACE_PROBE2(a, b, c, d, e) ((void)0)
a713518f 119
120#ifdef DTRACE_PROBE3
121#undef DTRACE_PROBE3
122#endif /* DTRACE_PROBE3 */
3b3ba48f 123#define DTRACE_PROBE3(a, b, c, d, e, f, g) ((void)0)
a713518f 124
125#ifdef DTRACE_PROBE4
126#undef DTRACE_PROBE4
127#endif /* DTRACE_PROBE4 */
3b3ba48f 128#define DTRACE_PROBE4(a, b, c, d, e, f, g, h, i) ((void)0)
14c5326c 129
77b1fe8f 130/* Missing globals */
3561541c 131extern char spl_version[16];
937879f1 132extern long spl_hostid;
133extern char hw_serial[11];
14c5326c 134extern int p0;
135
77b1fe8f 136/* Missing misc functions */
137extern int highbit(unsigned long i);
99639e4a 138extern uint32_t zone_get_hostid(void *zone);
51a727e9
BB
139extern void spl_setup(void);
140extern void spl_cleanup(void);
77b1fe8f 141
14c5326c 142#define makedevice(maj,min) makedev(maj,min)
143
14c5326c 144/* common macros */
145#ifndef MIN
37319315 146#define MIN(a, b) ((a) < (b) ? (a) : (b))
14c5326c 147#endif
148#ifndef MAX
37319315 149#define MAX(a, b) ((a) < (b) ? (b) : (a))
14c5326c 150#endif
151#ifndef ABS
37319315
BB
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))
14c5326c 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)))
14c5326c 167#define P2PHASE(x, align) ((x) & ((align) - 1))
168#define P2NPHASE(x, align) (-(x) & ((align) - 1))
14c5326c 169#define ISP2(x) (((x) & ((x) - 1)) == 0)
170#define IS_P2ALIGNED(v, a) ((((uintptr_t)(v)) & ((uintptr_t)(a) - 1)) == 0)
160c63ab
BB
171#define P2BOUNDARY(off, len, align) \
172 (((off) ^ ((off) + (len) - 1)) > (align) - 1)
14c5326c 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
14c5326c 209#endif /* _SPL_SYSMACROS_H */