xref: /openbmc/qemu/subprojects/libvduse/standard-headers/linux/const.h (revision ee057a9f2976e1fb2f58e07e86b410f38bf04ac6)
1b3c818a4SEric Farman /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2b3c818a4SEric Farman /* const.h: Macros for dealing with constants.  */
3b3c818a4SEric Farman 
4b3c818a4SEric Farman #ifndef _LINUX_CONST_H
5b3c818a4SEric Farman #define _LINUX_CONST_H
6b3c818a4SEric Farman 
7b3c818a4SEric Farman /* Some constant macros are used in both assembler and
8b3c818a4SEric Farman  * C code.  Therefore we cannot annotate them always with
9b3c818a4SEric Farman  * 'UL' and other type specifiers unilaterally.  We
10b3c818a4SEric Farman  * use the following macros to deal with this.
11b3c818a4SEric Farman  *
12b3c818a4SEric Farman  * Similarly, _AT() will cast an expression with a type in C, but
13b3c818a4SEric Farman  * leave it unchanged in asm.
14b3c818a4SEric Farman  */
15b3c818a4SEric Farman 
16b3c818a4SEric Farman #ifdef __ASSEMBLY__
17b3c818a4SEric Farman #define _AC(X,Y)	X
18b3c818a4SEric Farman #define _AT(T,X)	X
19b3c818a4SEric Farman #else
20b3c818a4SEric Farman #define __AC(X,Y)	(X##Y)
21b3c818a4SEric Farman #define _AC(X,Y)	__AC(X,Y)
22b3c818a4SEric Farman #define _AT(T,X)	((T)(X))
23b3c818a4SEric Farman #endif
24b3c818a4SEric Farman 
25b3c818a4SEric Farman #define _UL(x)		(_AC(x, UL))
26b3c818a4SEric Farman #define _ULL(x)		(_AC(x, ULL))
27b3c818a4SEric Farman 
28b3c818a4SEric Farman #define _BITUL(x)	(_UL(1) << (x))
29b3c818a4SEric Farman #define _BITULL(x)	(_ULL(1) << (x))
30b3c818a4SEric Farman 
31*0d2eeef7SBibo Mao #if !defined(__ASSEMBLY__)
32*0d2eeef7SBibo Mao /*
33*0d2eeef7SBibo Mao  * Missing __asm__ support
34*0d2eeef7SBibo Mao  *
35*0d2eeef7SBibo Mao  * __BIT128() would not work in the __asm__ code, as it shifts an
36*0d2eeef7SBibo Mao  * 'unsigned __init128' data type as direct representation of
37*0d2eeef7SBibo Mao  * 128 bit constants is not supported in the gcc compiler, as
38*0d2eeef7SBibo Mao  * they get silently truncated.
39*0d2eeef7SBibo Mao  *
40*0d2eeef7SBibo Mao  * TODO: Please revisit this implementation when gcc compiler
41*0d2eeef7SBibo Mao  * starts representing 128 bit constants directly like long
42*0d2eeef7SBibo Mao  * and unsigned long etc. Subsequently drop the comment for
43*0d2eeef7SBibo Mao  * GENMASK_U128() which would then start supporting __asm__ code.
44*0d2eeef7SBibo Mao  */
45*0d2eeef7SBibo Mao #define _BIT128(x)	((unsigned __int128)(1) << (x))
46*0d2eeef7SBibo Mao #endif
47*0d2eeef7SBibo Mao 
48d0bf492fSCédric Le Goater #define __ALIGN_KERNEL(x, a)		__ALIGN_KERNEL_MASK(x, (__typeof__(x))(a) - 1)
49b3c818a4SEric Farman #define __ALIGN_KERNEL_MASK(x, mask)	(((x) + (mask)) & ~(mask))
50b3c818a4SEric Farman 
51b3c818a4SEric Farman #define __KERNEL_DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
52b3c818a4SEric Farman 
53b3c818a4SEric Farman #endif /* _LINUX_CONST_H */
54