XenevaOS
Loading...
Searching...
No Matches
bits.h
Go to the documentation of this file.
1#ifndef __LINUX_BITS_H__
2#define __LINUX_BITS_H__
3
4/*
5 * DCL <linux/bits.h> -- the mask macros mainline gets from
6 * <uapi/linux/bits.h> and <vdso/bits.h>.
7 *
8 * __GENMASK was missing from the whole tree, and a missing *macro* does not
9 * stay a parse error here: `__GENMASK(15, 0)` compiles as an implicit call
10 * to a function of that name, so drm_mode.h's colour macros
11 * (DRM_ARGB64_PREP and friends, :1546-1594) produced an undefined symbol
12 * called __GENMASK in every object that expanded them --
13 * drm_atomic_state_helper.o:78, drm_blend.o and vkms_composer.o.
14 *
15 * This header is the only place it can go: drm_mode.h:14 includes
16 * <linux/bits.h> itself, and DCL has no uapi/linux/bits.h for it to reach
17 * first. The BITS_PER_LONG fallback below is the same one bitops.h carries
18 * and the spellings have to agree token for token, because the include order
19 * decides which wins (drm_mode.h leads with this header, kernel.h leads with
20 * bitops.h) and a mismatch would be a -Wmacro-redefined on every drm file.
21 *
22 * DMA_BIT_MASK is here for the same reachability reason rather than for
23 * affinity. Its mainline home is <linux/dma-mapping.h>, which DCL keeps for
24 * declarations only, while vkms_drv.c:188 --
25 * `dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(64))` -- has this header
26 * in its include chain through the drm_fourcc.h path. Written
27 * self-contained (not over GENMASK_ULL, which kernel.h owns and which may
28 * not have been parsed yet) but with mainline's answer: all-ones at 64 bits
29 * and (1<<n)-1 below, so the ternary is what keeps the shift defined.
30 *
31 * upstream uapi/linux/bits.h (__GENMASK), dma-mapping.h:118
32 * (DMA_BIT_MASK = GENMASK_ULL((n) - 1, 0))
33 */
34
35#ifndef BITS_PER_LONG
36/* 32 -- this target is LLP64, see the long note in <linux/kernel.h>. */
37#define BITS_PER_LONG 32
38#endif
39
40#ifndef __GENMASK
41#define __GENMASK(h, l) \
42 (((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
43#endif
44
45#ifndef __GENMASK_ULL
46#define __GENMASK_ULL(h, l) \
47 (((~0ULL) << (l)) & (~0ULL >> (63 - (h))))
48#endif
49
50#ifndef DMA_BIT_MASK
51#define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL << (n)) - 1))
52#endif
53
54#endif /* __LINUX_BITS_H__ */