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>.
8 * This file is part of the SPL, Solaris Porting Layer.
10 * The SPL is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version.
15 * The SPL is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * You should have received a copy of the GNU General Public License along
21 * with the SPL. If not, see <http://www.gnu.org/licenses/>.
24 #ifndef _SPL_SYSMACROS_H
25 #define _SPL_SYSMACROS_H
27 #include <linux/module.h>
28 #include <linux/sched.h>
29 #include <linux/sched/rt.h>
30 #include <linux/cpumask.h>
31 #include <sys/debug.h>
33 #include <sys/signal.h>
38 #define _KERNEL __KERNEL__
44 #define INT8_MAX (127)
45 #define INT8_MIN (-128)
46 #define UINT8_MAX (255)
49 #define INT16_MAX (32767)
50 #define INT16_MIN (-32768)
51 #define UINT16_MAX (65535)
52 #define UINT16_MIN (0)
54 #define INT32_MAX INT_MAX
55 #define INT32_MIN INT_MIN
56 #define UINT32_MAX UINT_MAX
57 #define UINT32_MIN UINT_MIN
59 #define INT64_MAX LLONG_MAX
60 #define INT64_MIN LLONG_MIN
61 #define UINT64_MAX ULLONG_MAX
62 #define UINT64_MIN ULLONG_MIN
67 #define MAXNAMELEN 256
68 #define MAXPATHLEN 4096
69 #define MAXOFFSET_T LLONG_MAX
72 #define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */
74 #define proc_pageout NULL
75 #define curproc current
76 #define max_ncpus num_possible_cpus()
77 #define boot_ncpus num_online_cpus()
78 #define CPU_SEQID smp_processor_id()
79 #define CPU_SEQID_UNSTABLE raw_smp_processor_id()
80 #define is_system_labeled() 0
82 #ifndef RLIM64_INFINITY
83 #define RLIM64_INFINITY (~0ULL)
87 * 0..MAX_PRIO-1: Process priority
88 * 0..MAX_RT_PRIO-1: RT priority tasks
89 * MAX_RT_PRIO..MAX_PRIO-1: SCHED_NORMAL tasks
91 * Treat shim tasks as SCHED_NORMAL tasks
93 #define minclsyspri (MAX_PRIO-1)
94 #define maxclsyspri (MAX_RT_PRIO)
95 #define defclsyspri (DEFAULT_PRIO)
98 #define NICE_TO_PRIO(nice) (MAX_RT_PRIO + (nice) + 20)
101 #define PRIO_TO_NICE(prio) ((prio) - MAX_RT_PRIO - 20)
108 #define PAGESIZE PAGE_SIZE
112 #define PAGESHIFT PAGE_SHIFT
115 /* Missing globals */
116 extern unsigned long spl_hostid
;
118 /* Missing misc functions */
119 extern uint32_t zone_get_hostid(void *zone
);
120 extern void spl_setup(void);
121 extern void spl_cleanup(void);
124 * Only handles the first 4096 majors and first 256 minors. We don't have a
125 * libc for the kernel module so we define this inline.
128 makedev(unsigned int major
, unsigned int minor
)
130 return ((major
& 0xFFF) << 8) | (minor
& 0xFF);
133 #define highbit(x) __fls(x)
134 #define lowbit(x) __ffs(x)
136 #define highbit64(x) fls64(x)
137 #define makedevice(maj, min) makedev(maj, min)
141 #define MIN(a, b) ((a) < (b) ? (a) : (b))
144 #define MAX(a, b) ((a) < (b) ? (b) : (a))
147 #define ABS(a) ((a) < 0 ? -(a) : (a))
150 #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
153 #define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
156 #define howmany(x, y) (((x) + ((y) - 1)) / (y))
160 * Compatibility macros/typedefs needed for Solaris -> Linux port
162 // Deprecated. Use P2ALIGN_TYPED instead.
163 // #define P2ALIGN(x, align) ((x) & -(align))
164 #define P2CROSS(x, y, align) (((x) ^ (y)) > (align) - 1)
165 #define P2ROUNDUP(x, align) ((((x) - 1) | ((align) - 1)) + 1)
166 #define P2PHASE(x, align) ((x) & ((align) - 1))
167 #define P2NPHASE(x, align) (-(x) & ((align) - 1))
168 #define ISP2(x) (((x) & ((x) - 1)) == 0)
169 #define IS_P2ALIGNED(v, a) ((((uintptr_t)(v)) & ((uintptr_t)(a) - 1)) == 0)
170 #define P2BOUNDARY(off, len, align) \
171 (((off) ^ ((off) + (len) - 1)) > (align) - 1)
174 * Typed version of the P2* macros. These macros should be used to ensure
175 * that the result is correctly calculated based on the data type of (x),
176 * which is passed in as the last argument, regardless of the data
177 * type of the alignment. For example, if (x) is of type uint64_t,
178 * and we want to round it up to a page boundary using "PAGESIZE" as
179 * the alignment, we can do either
181 * P2ROUNDUP(x, (uint64_t)PAGESIZE)
183 * P2ROUNDUP_TYPED(x, PAGESIZE, uint64_t)
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) - 1) | ((type)(align) - 1)) + 1)
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)))
202 #define SET_ERROR(err) \
203 (__set_error(__FILE__, __func__, __LINE__, err), err)
205 #include <linux/sort.h>
206 #define qsort(base, num, size, cmp) \
207 sort(base, num, size, cmp, NULL)
209 #if !defined(_KMEMUSER) && !defined(offsetof)
211 /* avoid any possibility of clashing with <stddef.h> version */
213 #define offsetof(s, m) ((size_t)(&(((s *)0)->m)))
216 #endif /* _SPL_SYSMACROS_H */