Print this page
8956 Implement KPTI
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: Robert Mustacchi <rm@joyent.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/sys/sysmacros.h
+++ new/usr/src/uts/common/sys/sysmacros.h
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
↓ open down ↓ |
19 lines elided |
↑ open up ↑ |
20 20 */
21 21 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
22 22 /* All Rights Reserved */
23 23
24 24
25 25 /*
26 26 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
27 27 * Use is subject to license terms.
28 28 *
29 29 * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
30 + *
31 + * Copyright 2018 Joyent Inc.
30 32 */
31 33
32 34 #ifndef _SYS_SYSMACROS_H
33 35 #define _SYS_SYSMACROS_H
34 36
35 37 #include <sys/param.h>
36 38 #include <sys/stddef.h>
37 39
38 40 #ifdef __cplusplus
39 41 extern "C" {
40 42 #endif
41 43
42 44 /*
43 45 * Some macros for units conversion
44 46 */
45 47 /*
46 48 * Disk blocks (sectors) and bytes.
47 49 */
48 50 #define dtob(DD) ((DD) << DEV_BSHIFT)
49 51 #define btod(BB) (((BB) + DEV_BSIZE - 1) >> DEV_BSHIFT)
50 52 #define btodt(BB) ((BB) >> DEV_BSHIFT)
51 53 #define lbtod(BB) (((offset_t)(BB) + DEV_BSIZE - 1) >> DEV_BSHIFT)
52 54
53 55 /* common macros */
54 56 #ifndef MIN
55 57 #define MIN(a, b) ((a) < (b) ? (a) : (b))
56 58 #endif
57 59 #ifndef MAX
58 60 #define MAX(a, b) ((a) < (b) ? (b) : (a))
59 61 #endif
60 62 #ifndef ABS
61 63 #define ABS(a) ((a) < 0 ? -(a) : (a))
62 64 #endif
63 65 #ifndef SIGNOF
64 66 #define SIGNOF(a) ((a) < 0 ? -1 : (a) > 0)
65 67 #endif
66 68
67 69 #ifdef _KERNEL
68 70
69 71 /*
70 72 * Convert a single byte to/from binary-coded decimal (BCD).
71 73 */
72 74 extern unsigned char byte_to_bcd[256];
73 75 extern unsigned char bcd_to_byte[256];
74 76
75 77 #define BYTE_TO_BCD(x) byte_to_bcd[(x) & 0xff]
76 78 #define BCD_TO_BYTE(x) bcd_to_byte[(x) & 0xff]
77 79
78 80 #endif /* _KERNEL */
79 81
80 82 /*
81 83 * WARNING: The device number macros defined here should not be used by device
82 84 * drivers or user software. Device drivers should use the device functions
83 85 * defined in the DDI/DKI interface (see also ddi.h). Application software
84 86 * should make use of the library routines available in makedev(3). A set of
85 87 * new device macros are provided to operate on the expanded device number
86 88 * format supported in SVR4. Macro versions of the DDI device functions are
87 89 * provided for use by kernel proper routines only. Macro routines bmajor(),
88 90 * major(), minor(), emajor(), eminor(), and makedev() will be removed or
89 91 * their definitions changed at the next major release following SVR4.
90 92 */
91 93
92 94 #define O_BITSMAJOR 7 /* # of SVR3 major device bits */
93 95 #define O_BITSMINOR 8 /* # of SVR3 minor device bits */
94 96 #define O_MAXMAJ 0x7f /* SVR3 max major value */
95 97 #define O_MAXMIN 0xff /* SVR3 max minor value */
96 98
97 99
98 100 #define L_BITSMAJOR32 14 /* # of SVR4 major device bits */
99 101 #define L_BITSMINOR32 18 /* # of SVR4 minor device bits */
100 102 #define L_MAXMAJ32 0x3fff /* SVR4 max major value */
101 103 #define L_MAXMIN32 0x3ffff /* MAX minor for 3b2 software drivers. */
102 104 /* For 3b2 hardware devices the minor is */
103 105 /* restricted to 256 (0-255) */
104 106
105 107 #ifdef _LP64
106 108 #define L_BITSMAJOR 32 /* # of major device bits in 64-bit Solaris */
107 109 #define L_BITSMINOR 32 /* # of minor device bits in 64-bit Solaris */
108 110 #define L_MAXMAJ 0xfffffffful /* max major value */
109 111 #define L_MAXMIN 0xfffffffful /* max minor value */
110 112 #else
111 113 #define L_BITSMAJOR L_BITSMAJOR32
112 114 #define L_BITSMINOR L_BITSMINOR32
113 115 #define L_MAXMAJ L_MAXMAJ32
114 116 #define L_MAXMIN L_MAXMIN32
115 117 #endif
116 118
117 119 #ifdef _KERNEL
118 120
119 121 /* major part of a device internal to the kernel */
120 122
121 123 #define major(x) (major_t)((((unsigned)(x)) >> O_BITSMINOR) & O_MAXMAJ)
122 124 #define bmajor(x) (major_t)((((unsigned)(x)) >> O_BITSMINOR) & O_MAXMAJ)
123 125
124 126 /* get internal major part of expanded device number */
125 127
126 128 #define getmajor(x) (major_t)((((dev_t)(x)) >> L_BITSMINOR) & L_MAXMAJ)
127 129
128 130 /* minor part of a device internal to the kernel */
129 131
130 132 #define minor(x) (minor_t)((x) & O_MAXMIN)
131 133
132 134 /* get internal minor part of expanded device number */
133 135
134 136 #define getminor(x) (minor_t)((x) & L_MAXMIN)
135 137
136 138 #else /* _KERNEL */
137 139
138 140 /* major part of a device external from the kernel (same as emajor below) */
139 141
140 142 #define major(x) (major_t)((((unsigned)(x)) >> O_BITSMINOR) & O_MAXMAJ)
141 143
142 144 /* minor part of a device external from the kernel (same as eminor below) */
143 145
144 146 #define minor(x) (minor_t)((x) & O_MAXMIN)
145 147
146 148 #endif /* _KERNEL */
147 149
148 150 /* create old device number */
149 151
150 152 #define makedev(x, y) (unsigned short)(((x) << O_BITSMINOR) | ((y) & O_MAXMIN))
151 153
152 154 /* make an new device number */
153 155
154 156 #define makedevice(x, y) (dev_t)(((dev_t)(x) << L_BITSMINOR) | ((y) & L_MAXMIN))
155 157
156 158
157 159 /*
158 160 * emajor() allows kernel/driver code to print external major numbers
159 161 * eminor() allows kernel/driver code to print external minor numbers
160 162 */
161 163
162 164 #define emajor(x) \
163 165 (major_t)(((unsigned int)(x) >> O_BITSMINOR) > O_MAXMAJ) ? \
164 166 NODEV : (((unsigned int)(x) >> O_BITSMINOR) & O_MAXMAJ)
165 167
166 168 #define eminor(x) \
167 169 (minor_t)((x) & O_MAXMIN)
168 170
169 171 /*
170 172 * get external major and minor device
171 173 * components from expanded device number
172 174 */
173 175 #define getemajor(x) (major_t)((((dev_t)(x) >> L_BITSMINOR) > L_MAXMAJ) ? \
174 176 NODEV : (((dev_t)(x) >> L_BITSMINOR) & L_MAXMAJ))
175 177 #define geteminor(x) (minor_t)((x) & L_MAXMIN)
176 178
177 179 /*
178 180 * These are versions of the kernel routines for compressing and
179 181 * expanding long device numbers that don't return errors.
180 182 */
181 183 #if (L_BITSMAJOR32 == L_BITSMAJOR) && (L_BITSMINOR32 == L_BITSMINOR)
182 184
183 185 #define DEVCMPL(x) (x)
184 186 #define DEVEXPL(x) (x)
185 187
186 188 #else
187 189
188 190 #define DEVCMPL(x) \
189 191 (dev32_t)((((x) >> L_BITSMINOR) > L_MAXMAJ32 || \
190 192 ((x) & L_MAXMIN) > L_MAXMIN32) ? NODEV32 : \
191 193 ((((x) >> L_BITSMINOR) << L_BITSMINOR32) | ((x) & L_MAXMIN32)))
192 194
193 195 #define DEVEXPL(x) \
194 196 (((x) == NODEV32) ? NODEV : \
195 197 makedevice(((x) >> L_BITSMINOR32) & L_MAXMAJ32, (x) & L_MAXMIN32))
196 198
197 199 #endif /* L_BITSMAJOR32 ... */
198 200
199 201 /* convert to old (SVR3.2) dev format */
200 202
201 203 #define cmpdev(x) \
202 204 (o_dev_t)((((x) >> L_BITSMINOR) > O_MAXMAJ || \
203 205 ((x) & L_MAXMIN) > O_MAXMIN) ? NODEV : \
204 206 ((((x) >> L_BITSMINOR) << O_BITSMINOR) | ((x) & O_MAXMIN)))
205 207
206 208 /* convert to new (SVR4) dev format */
207 209
208 210 #define expdev(x) \
209 211 (dev_t)(((dev_t)(((x) >> O_BITSMINOR) & O_MAXMAJ) << L_BITSMINOR) | \
210 212 ((x) & O_MAXMIN))
211 213
212 214 /*
213 215 * Macro for checking power of 2 address alignment.
214 216 */
215 217 #define IS_P2ALIGNED(v, a) ((((uintptr_t)(v)) & ((uintptr_t)(a) - 1)) == 0)
216 218
217 219 /*
218 220 * Macros for counting and rounding.
219 221 */
220 222 #define howmany(x, y) (((x)+((y)-1))/(y))
221 223 #define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
222 224
223 225 /*
224 226 * Macro to determine if value is a power of 2
225 227 */
226 228 #define ISP2(x) (((x) & ((x) - 1)) == 0)
227 229
228 230 /*
229 231 * Macros for various sorts of alignment and rounding. The "align" must
230 232 * be a power of 2. Often times it is a block, sector, or page.
231 233 */
232 234
233 235 /*
234 236 * return x rounded down to an align boundary
235 237 * eg, P2ALIGN(1200, 1024) == 1024 (1*align)
236 238 * eg, P2ALIGN(1024, 1024) == 1024 (1*align)
237 239 * eg, P2ALIGN(0x1234, 0x100) == 0x1200 (0x12*align)
238 240 * eg, P2ALIGN(0x5600, 0x100) == 0x5600 (0x56*align)
239 241 */
240 242 #define P2ALIGN(x, align) ((x) & -(align))
241 243
242 244 /*
243 245 * return x % (mod) align
244 246 * eg, P2PHASE(0x1234, 0x100) == 0x34 (x-0x12*align)
245 247 * eg, P2PHASE(0x5600, 0x100) == 0x00 (x-0x56*align)
246 248 */
247 249 #define P2PHASE(x, align) ((x) & ((align) - 1))
248 250
249 251 /*
250 252 * return how much space is left in this block (but if it's perfectly
251 253 * aligned, return 0).
252 254 * eg, P2NPHASE(0x1234, 0x100) == 0xcc (0x13*align-x)
253 255 * eg, P2NPHASE(0x5600, 0x100) == 0x00 (0x56*align-x)
254 256 */
255 257 #define P2NPHASE(x, align) (-(x) & ((align) - 1))
256 258
257 259 /*
258 260 * return x rounded up to an align boundary
259 261 * eg, P2ROUNDUP(0x1234, 0x100) == 0x1300 (0x13*align)
260 262 * eg, P2ROUNDUP(0x5600, 0x100) == 0x5600 (0x56*align)
261 263 */
262 264 #define P2ROUNDUP(x, align) (-(-(x) & -(align)))
263 265
264 266 /*
265 267 * return the ending address of the block that x is in
266 268 * eg, P2END(0x1234, 0x100) == 0x12ff (0x13*align - 1)
267 269 * eg, P2END(0x5600, 0x100) == 0x56ff (0x57*align - 1)
268 270 */
269 271 #define P2END(x, align) (-(~(x) & -(align)))
270 272
271 273 /*
272 274 * return x rounded up to the next phase (offset) within align.
273 275 * phase should be < align.
274 276 * eg, P2PHASEUP(0x1234, 0x100, 0x10) == 0x1310 (0x13*align + phase)
275 277 * eg, P2PHASEUP(0x5600, 0x100, 0x10) == 0x5610 (0x56*align + phase)
276 278 */
277 279 #define P2PHASEUP(x, align, phase) ((phase) - (((phase) - (x)) & -(align)))
278 280
279 281 /*
280 282 * return TRUE if adding len to off would cause it to cross an align
281 283 * boundary.
282 284 * eg, P2BOUNDARY(0x1234, 0xe0, 0x100) == TRUE (0x1234 + 0xe0 == 0x1314)
283 285 * eg, P2BOUNDARY(0x1234, 0x50, 0x100) == FALSE (0x1234 + 0x50 == 0x1284)
284 286 */
285 287 #define P2BOUNDARY(off, len, align) \
286 288 (((off) ^ ((off) + (len) - 1)) > (align) - 1)
287 289
288 290 /*
289 291 * Return TRUE if they have the same highest bit set.
290 292 * eg, P2SAMEHIGHBIT(0x1234, 0x1001) == TRUE (the high bit is 0x1000)
291 293 * eg, P2SAMEHIGHBIT(0x1234, 0x3010) == FALSE (high bit of 0x3010 is 0x2000)
292 294 */
293 295 #define P2SAMEHIGHBIT(x, y) (((x) ^ (y)) < ((x) & (y)))
294 296
295 297 /*
296 298 * Typed version of the P2* macros. These macros should be used to ensure
297 299 * that the result is correctly calculated based on the data type of (x),
298 300 * which is passed in as the last argument, regardless of the data
299 301 * type of the alignment. For example, if (x) is of type uint64_t,
300 302 * and we want to round it up to a page boundary using "PAGESIZE" as
301 303 * the alignment, we can do either
302 304 * P2ROUNDUP(x, (uint64_t)PAGESIZE)
303 305 * or
304 306 * P2ROUNDUP_TYPED(x, PAGESIZE, uint64_t)
305 307 */
306 308 #define P2ALIGN_TYPED(x, align, type) \
307 309 ((type)(x) & -(type)(align))
308 310 #define P2PHASE_TYPED(x, align, type) \
309 311 ((type)(x) & ((type)(align) - 1))
310 312 #define P2NPHASE_TYPED(x, align, type) \
311 313 (-(type)(x) & ((type)(align) - 1))
312 314 #define P2ROUNDUP_TYPED(x, align, type) \
313 315 (-(-(type)(x) & -(type)(align)))
314 316 #define P2END_TYPED(x, align, type) \
315 317 (-(~(type)(x) & -(type)(align)))
316 318 #define P2PHASEUP_TYPED(x, align, phase, type) \
317 319 ((type)(phase) - (((type)(phase) - (type)(x)) & -(type)(align)))
318 320 #define P2CROSS_TYPED(x, y, align, type) \
319 321 (((type)(x) ^ (type)(y)) > (type)(align) - 1)
320 322 #define P2SAMEHIGHBIT_TYPED(x, y, type) \
321 323 (((type)(x) ^ (type)(y)) < ((type)(x) & (type)(y)))
322 324
323 325 /*
324 326 * Macros to atomically increment/decrement a variable. mutex and var
325 327 * must be pointers.
326 328 */
327 329 #define INCR_COUNT(var, mutex) mutex_enter(mutex), (*(var))++, mutex_exit(mutex)
328 330 #define DECR_COUNT(var, mutex) mutex_enter(mutex), (*(var))--, mutex_exit(mutex)
329 331
330 332 /*
331 333 * Macros to declare bitfields - the order in the parameter list is
332 334 * Low to High - that is, declare bit 0 first. We only support 8-bit bitfields
333 335 * because if a field crosses a byte boundary it's not likely to be meaningful
334 336 * without reassembly in its nonnative endianness.
335 337 */
336 338 #if defined(_BIT_FIELDS_LTOH)
337 339 #define DECL_BITFIELD2(_a, _b) \
338 340 uint8_t _a, _b
339 341 #define DECL_BITFIELD3(_a, _b, _c) \
340 342 uint8_t _a, _b, _c
341 343 #define DECL_BITFIELD4(_a, _b, _c, _d) \
342 344 uint8_t _a, _b, _c, _d
343 345 #define DECL_BITFIELD5(_a, _b, _c, _d, _e) \
344 346 uint8_t _a, _b, _c, _d, _e
345 347 #define DECL_BITFIELD6(_a, _b, _c, _d, _e, _f) \
346 348 uint8_t _a, _b, _c, _d, _e, _f
347 349 #define DECL_BITFIELD7(_a, _b, _c, _d, _e, _f, _g) \
348 350 uint8_t _a, _b, _c, _d, _e, _f, _g
349 351 #define DECL_BITFIELD8(_a, _b, _c, _d, _e, _f, _g, _h) \
350 352 uint8_t _a, _b, _c, _d, _e, _f, _g, _h
351 353 #elif defined(_BIT_FIELDS_HTOL)
352 354 #define DECL_BITFIELD2(_a, _b) \
353 355 uint8_t _b, _a
354 356 #define DECL_BITFIELD3(_a, _b, _c) \
355 357 uint8_t _c, _b, _a
356 358 #define DECL_BITFIELD4(_a, _b, _c, _d) \
357 359 uint8_t _d, _c, _b, _a
358 360 #define DECL_BITFIELD5(_a, _b, _c, _d, _e) \
359 361 uint8_t _e, _d, _c, _b, _a
↓ open down ↓ |
320 lines elided |
↑ open up ↑ |
360 362 #define DECL_BITFIELD6(_a, _b, _c, _d, _e, _f) \
361 363 uint8_t _f, _e, _d, _c, _b, _a
362 364 #define DECL_BITFIELD7(_a, _b, _c, _d, _e, _f, _g) \
363 365 uint8_t _g, _f, _e, _d, _c, _b, _a
364 366 #define DECL_BITFIELD8(_a, _b, _c, _d, _e, _f, _g, _h) \
365 367 uint8_t _h, _g, _f, _e, _d, _c, _b, _a
366 368 #else
367 369 #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
368 370 #endif /* _BIT_FIELDS_LTOH */
369 371
370 -/* avoid any possibility of clashing with <stddef.h> version */
371 -#if (defined(_KERNEL) || defined(_FAKE_KERNEL)) && !defined(_KMEMUSER)
372 -
372 +#if !defined(ARRAY_SIZE)
373 373 #define ARRAY_SIZE(x) (sizeof (x) / sizeof (x[0]))
374 +#endif
374 375
375 -#endif /* _KERNEL, !_KMEMUSER */
376 -
377 376 #ifdef __cplusplus
378 377 }
379 378 #endif
380 379
381 380 #endif /* _SYS_SYSMACROS_H */
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX