1 From ba4aa02b417f08a0bee5e7b8ed70cac788a7c854 Mon Sep 17 00:00:00 2001
2 From: Arnaldo Carvalho de Melo <acme@redhat.com>
3 Date: Tue, 25 Sep 2018 10:55:59 -0300
4 Subject: tools include: Adopt linux/bits.h
6 From: Arnaldo Carvalho de Melo <acme@redhat.com>
8 commit ba4aa02b417f08a0bee5e7b8ed70cac788a7c854 upstream.
10 So that we reduce the difference of tools/include/linux/bitops.h to the
11 original kernel file, include/linux/bitops.h, trying to remove the need
12 to define BITS_PER_LONG, to avoid clashes with asm/bitsperlong.h.
14 And the things removed from tools/include/linux/bitops.h are really in
15 linux/bits.h, so that we can have a copy and then
16 tools/perf/check_headers.sh will tell us when new stuff gets added to
17 linux/bits.h so that we can check if it is useful and if any adjustment
18 needs to be done to the tools/{include,arch}/ copies.
20 Cc: Adrian Hunter <adrian.hunter@intel.com>
21 Cc: Alexander Sverdlin <alexander.sverdlin@nokia.com>
22 Cc: David Ahern <dsahern@gmail.com>
23 Cc: Jiri Olsa <jolsa@kernel.org>
24 Cc: Namhyung Kim <namhyung@kernel.org>
25 Cc: Wang Nan <wangnan0@huawei.com>
26 Link: https://lkml.kernel.org/n/tip-y1sqyydvfzo0bjjoj4zsl562@git.kernel.org
27 Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
28 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
31 tools/include/linux/bitops.h | 7 ++-----
32 tools/include/linux/bits.h | 26 ++++++++++++++++++++++++++
33 tools/perf/check-headers.sh | 1 +
34 3 files changed, 29 insertions(+), 5 deletions(-)
36 --- a/tools/include/linux/bitops.h
37 +++ b/tools/include/linux/bitops.h
39 #define _TOOLS_LINUX_BITOPS_H_
41 #include <asm/types.h>
42 -#include <linux/compiler.h>
45 #define __WORDSIZE (__SIZEOF_LONG__ * 8)
49 # define BITS_PER_LONG __WORDSIZE
51 +#include <linux/bits.h>
52 +#include <linux/compiler.h>
54 -#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
55 -#define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
56 -#define BITS_PER_BYTE 8
57 #define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
58 #define BITS_TO_U64(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(u64))
59 #define BITS_TO_U32(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(u32))
61 +++ b/tools/include/linux/bits.h
63 +/* SPDX-License-Identifier: GPL-2.0 */
64 +#ifndef __LINUX_BITS_H
65 +#define __LINUX_BITS_H
66 +#include <asm/bitsperlong.h>
68 +#define BIT(nr) (1UL << (nr))
69 +#define BIT_ULL(nr) (1ULL << (nr))
70 +#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
71 +#define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
72 +#define BIT_ULL_MASK(nr) (1ULL << ((nr) % BITS_PER_LONG_LONG))
73 +#define BIT_ULL_WORD(nr) ((nr) / BITS_PER_LONG_LONG)
74 +#define BITS_PER_BYTE 8
77 + * Create a contiguous bitmask starting at bit position @l and ending at
78 + * position @h. For example
79 + * GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000.
81 +#define GENMASK(h, l) \
82 + (((~0UL) - (1UL << (l)) + 1) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
84 +#define GENMASK_ULL(h, l) \
85 + (((~0ULL) - (1ULL << (l)) + 1) & \
86 + (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h))))
88 +#endif /* __LINUX_BITS_H */
89 --- a/tools/perf/check-headers.sh
90 +++ b/tools/perf/check-headers.sh
91 @@ -11,6 +11,7 @@ include/uapi/linux/sched.h
92 include/uapi/linux/stat.h
93 include/uapi/linux/vhost.h
94 include/uapi/sound/asound.h
97 include/uapi/linux/hw_breakpoint.h
98 arch/x86/include/asm/disabled-features.h