]>
Commit | Line | Data |
---|---|---|
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. |
716154c5 BB |
9 | * |
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. | |
715f6251 | 14 | * |
716154c5 | 15 | * The SPL is distributed in the hope that it will be useful, but WITHOUT |
715f6251 BB |
16 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
17 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
18 | * for more details. | |
19 | * | |
20 | * You should have received a copy of the GNU General Public License along | |
716154c5 | 21 | * with the SPL. If not, see <http://www.gnu.org/licenses/>. |
4b393c50 | 22 | */ |
715f6251 | 23 | |
14c5326c | 24 | #ifndef _SPL_SYSMACROS_H |
5461eefe | 25 | #define _SPL_SYSMACROS_H |
14c5326c | 26 | |
14c5326c | 27 | #include <linux/module.h> |
10087fe1 | 28 | #include <linux/sched.h> |
066e8252 | 29 | #include <linux/sched/rt.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 | 36 | |
14c5326c | 37 | #ifndef _KERNEL |
5461eefe | 38 | #define _KERNEL __KERNEL__ |
14c5326c BB |
39 | #endif |
40 | ||
5461eefe BB |
41 | #define FALSE 0 |
42 | #define TRUE 1 | |
43 | ||
44 | #define INT8_MAX (127) | |
45 | #define INT8_MIN (-128) | |
46 | #define UINT8_MAX (255) | |
47 | #define UINT8_MIN (0) | |
48 | ||
49 | #define INT16_MAX (32767) | |
50 | #define INT16_MIN (-32768) | |
51 | #define UINT16_MAX (65535) | |
52 | #define UINT16_MIN (0) | |
53 | ||
54 | #define INT32_MAX INT_MAX | |
55 | #define INT32_MIN INT_MIN | |
56 | #define UINT32_MAX UINT_MAX | |
57 | #define UINT32_MIN UINT_MIN | |
58 | ||
59 | #define INT64_MAX LLONG_MAX | |
60 | #define INT64_MIN LLONG_MIN | |
61 | #define UINT64_MAX ULLONG_MAX | |
62 | #define UINT64_MIN ULLONG_MIN | |
63 | ||
64 | #define NBBY 8 | |
5461eefe BB |
65 | |
66 | #define MAXMSGLEN 256 | |
67 | #define MAXNAMELEN 256 | |
a9125891 | 68 | #define MAXPATHLEN 4096 |
5461eefe BB |
69 | #define MAXOFFSET_T LLONG_MAX |
70 | #define MAXBSIZE 8192 | |
71 | #define DEV_BSIZE 512 | |
72 | #define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */ | |
73 | ||
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() | |
09eb36ce | 79 | #define CPU_SEQID_UNSTABLE raw_smp_processor_id() |
5461eefe | 80 | #define is_system_labeled() 0 |
14c5326c | 81 | |
a50cede3 | 82 | #ifndef RLIM64_INFINITY |
5461eefe | 83 | #define RLIM64_INFINITY (~0ULL) |
a50cede3 | 84 | #endif |
6adf99e7 | 85 | |
5461eefe BB |
86 | /* |
87 | * 0..MAX_PRIO-1: Process priority | |
14c5326c BB |
88 | * 0..MAX_RT_PRIO-1: RT priority tasks |
89 | * MAX_RT_PRIO..MAX_PRIO-1: SCHED_NORMAL tasks | |
90 | * | |
91 | * Treat shim tasks as SCHED_NORMAL tasks | |
92 | */ | |
5461eefe BB |
93 | #define minclsyspri (MAX_PRIO-1) |
94 | #define maxclsyspri (MAX_RT_PRIO) | |
95 | #define defclsyspri (DEFAULT_PRIO) | |
14c5326c | 96 | |
1538f4b6 | 97 | #ifndef NICE_TO_PRIO |
5461eefe | 98 | #define NICE_TO_PRIO(nice) (MAX_RT_PRIO + (nice) + 20) |
1538f4b6 CC |
99 | #endif |
100 | #ifndef PRIO_TO_NICE | |
5461eefe | 101 | #define PRIO_TO_NICE(prio) ((prio) - MAX_RT_PRIO - 20) |
1538f4b6 | 102 | #endif |
14c5326c | 103 | |
f9bde4f7 | 104 | /* |
105 | * Missing macros | |
14c5326c | 106 | */ |
f9bde4f7 | 107 | #ifndef PAGESIZE |
5461eefe | 108 | #define PAGESIZE PAGE_SIZE |
f9bde4f7 | 109 | #endif |
14c5326c | 110 | |
43b857fd | 111 | #ifndef PAGESHIFT |
5461eefe | 112 | #define PAGESHIFT PAGE_SHIFT |
43b857fd DQ |
113 | #endif |
114 | ||
77b1fe8f | 115 | /* Missing globals */ |
fa6f7d8f | 116 | extern unsigned long spl_hostid; |
14c5326c | 117 | |
77b1fe8f | 118 | /* Missing misc functions */ |
99639e4a | 119 | extern uint32_t zone_get_hostid(void *zone); |
51a727e9 BB |
120 | extern void spl_setup(void); |
121 | extern void spl_cleanup(void); | |
77b1fe8f | 122 | |
d2f97b2a TC |
123 | #define highbit(x) __fls(x) |
124 | #define lowbit(x) __ffs(x) | |
125 | ||
87f8055a | 126 | #define highbit64(x) fls64(x) |
5461eefe | 127 | #define makedevice(maj, min) makedev(maj, min) |
14c5326c | 128 | |
14c5326c BB |
129 | /* common macros */ |
130 | #ifndef MIN | |
5461eefe | 131 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) |
14c5326c BB |
132 | #endif |
133 | #ifndef MAX | |
5461eefe | 134 | #define MAX(a, b) ((a) < (b) ? (b) : (a)) |
14c5326c BB |
135 | #endif |
136 | #ifndef ABS | |
5461eefe | 137 | #define ABS(a) ((a) < 0 ? -(a) : (a)) |
37319315 BB |
138 | #endif |
139 | #ifndef DIV_ROUND_UP | |
5461eefe | 140 | #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
37319315 BB |
141 | #endif |
142 | #ifndef roundup | |
5461eefe | 143 | #define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y)) |
14c5326c | 144 | #endif |
7f23e001 | 145 | #ifndef howmany |
5461eefe | 146 | #define howmany(x, y) (((x) + ((y) - 1)) / (y)) |
7f23e001 | 147 | #endif |
14c5326c BB |
148 | |
149 | /* | |
150 | * Compatibility macros/typedefs needed for Solaris -> Linux port | |
151 | */ | |
5461eefe BB |
152 | #define P2ALIGN(x, align) ((x) & -(align)) |
153 | #define P2CROSS(x, y, align) (((x) ^ (y)) > (align) - 1) | |
154 | #define P2ROUNDUP(x, align) ((((x) - 1) | ((align) - 1)) + 1) | |
155 | #define P2PHASE(x, align) ((x) & ((align) - 1)) | |
156 | #define P2NPHASE(x, align) (-(x) & ((align) - 1)) | |
157 | #define ISP2(x) (((x) & ((x) - 1)) == 0) | |
158 | #define IS_P2ALIGNED(v, a) ((((uintptr_t)(v)) & ((uintptr_t)(a) - 1)) == 0) | |
159 | #define P2BOUNDARY(off, len, align) \ | |
32c6147d | 160 | (((off) ^ ((off) + (len) - 1)) > (align) - 1) |
14c5326c BB |
161 | |
162 | /* | |
163 | * Typed version of the P2* macros. These macros should be used to ensure | |
164 | * that the result is correctly calculated based on the data type of (x), | |
165 | * which is passed in as the last argument, regardless of the data | |
166 | * type of the alignment. For example, if (x) is of type uint64_t, | |
167 | * and we want to round it up to a page boundary using "PAGESIZE" as | |
168 | * the alignment, we can do either | |
32c6147d | 169 | * |
14c5326c BB |
170 | * P2ROUNDUP(x, (uint64_t)PAGESIZE) |
171 | * or | |
172 | * P2ROUNDUP_TYPED(x, PAGESIZE, uint64_t) | |
173 | */ | |
5461eefe BB |
174 | #define P2ALIGN_TYPED(x, align, type) \ |
175 | ((type)(x) & -(type)(align)) | |
176 | #define P2PHASE_TYPED(x, align, type) \ | |
177 | ((type)(x) & ((type)(align) - 1)) | |
178 | #define P2NPHASE_TYPED(x, align, type) \ | |
179 | (-(type)(x) & ((type)(align) - 1)) | |
180 | #define P2ROUNDUP_TYPED(x, align, type) \ | |
181 | ((((type)(x) - 1) | ((type)(align) - 1)) + 1) | |
182 | #define P2END_TYPED(x, align, type) \ | |
183 | (-(~(type)(x) & -(type)(align))) | |
184 | #define P2PHASEUP_TYPED(x, align, phase, type) \ | |
185 | ((type)(phase) - (((type)(phase) - (type)(x)) & -(type)(align))) | |
186 | #define P2CROSS_TYPED(x, y, align, type) \ | |
187 | (((type)(x) ^ (type)(y)) > (type)(align) - 1) | |
188 | #define P2SAMEHIGHBIT_TYPED(x, y, type) \ | |
189 | (((type)(x) ^ (type)(y)) < ((type)(x) & (type)(y))) | |
14c5326c | 190 | |
68a1b158 MM |
191 | #define SET_ERROR(err) \ |
192 | (__set_error(__FILE__, __func__, __LINE__, err), err) | |
193 | ||
74d1d749 MM |
194 | #include <linux/sort.h> |
195 | #define qsort(base, num, size, cmp) \ | |
196 | sort(base, num, size, cmp, NULL) | |
197 | ||
198 | #if !defined(_KMEMUSER) && !defined(offsetof) | |
14c5326c BB |
199 | |
200 | /* avoid any possibility of clashing with <stddef.h> version */ | |
201 | ||
5461eefe | 202 | #define offsetof(s, m) ((size_t)(&(((s *)0)->m))) |
14c5326c BB |
203 | #endif |
204 | ||
14c5326c | 205 | #endif /* _SPL_SYSMACROS_H */ |