1 From foo@baz Tue 14 May 2019 08:29:35 PM CEST
2 From: Will Deacon <will.deacon@arm.com>
3 Date: Tue, 19 Jun 2018 13:53:08 +0100
4 Subject: locking/atomics, asm-generic: Move some macros from <linux/bitops.h> to a new <linux/bits.h> file
6 From: Will Deacon <will.deacon@arm.com>
8 commit 8bd9cb51daac89337295b6f037b0486911e1b408 upstream.
10 In preparation for implementing the asm-generic atomic bitops in terms
11 of atomic_long_*(), we need to prevent <asm/atomic.h> implementations from
12 pulling in <linux/bitops.h>. A common reason for this include is for the
13 BITS_PER_BYTE definition, so move this and some other BIT() and masking
14 macros into a new header file, <linux/bits.h>.
16 Signed-off-by: Will Deacon <will.deacon@arm.com>
17 Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
18 Cc: Linus Torvalds <torvalds@linux-foundation.org>
19 Cc: Peter Zijlstra <peterz@infradead.org>
20 Cc: Thomas Gleixner <tglx@linutronix.de>
21 Cc: linux-arm-kernel@lists.infradead.org
22 Cc: yamada.masahiro@socionext.com
23 Link: https://lore.kernel.org/lkml/1529412794-17720-4-git-send-email-will.deacon@arm.com
24 Signed-off-by: Ingo Molnar <mingo@kernel.org>
25 Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
26 Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
27 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
29 include/linux/bitops.h | 22 +---------------------
30 include/linux/bits.h | 26 ++++++++++++++++++++++++++
31 2 files changed, 27 insertions(+), 21 deletions(-)
32 create mode 100644 include/linux/bits.h
34 --- a/include/linux/bitops.h
35 +++ b/include/linux/bitops.h
37 #ifndef _LINUX_BITOPS_H
38 #define _LINUX_BITOPS_H
39 #include <asm/types.h>
40 +#include <linux/bits.h>
43 -#define BIT(nr) (1UL << (nr))
44 -#define BIT_ULL(nr) (1ULL << (nr))
45 -#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
46 -#define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
47 -#define BIT_ULL_MASK(nr) (1ULL << ((nr) % BITS_PER_LONG_LONG))
48 -#define BIT_ULL_WORD(nr) ((nr) / BITS_PER_LONG_LONG)
49 -#define BITS_PER_BYTE 8
50 #define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
54 - * Create a contiguous bitmask starting at bit position @l and ending at
55 - * position @h. For example
56 - * GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000.
58 -#define GENMASK(h, l) \
59 - (((~0UL) - (1UL << (l)) + 1) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
61 -#define GENMASK_ULL(h, l) \
62 - (((~0ULL) - (1ULL << (l)) + 1) & \
63 - (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h))))
65 extern unsigned int __sw_hweight8(unsigned int w);
66 extern unsigned int __sw_hweight16(unsigned int w);
68 +++ b/include/linux/bits.h
70 +/* SPDX-License-Identifier: GPL-2.0 */
71 +#ifndef __LINUX_BITS_H
72 +#define __LINUX_BITS_H
73 +#include <asm/bitsperlong.h>
75 +#define BIT(nr) (1UL << (nr))
76 +#define BIT_ULL(nr) (1ULL << (nr))
77 +#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
78 +#define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
79 +#define BIT_ULL_MASK(nr) (1ULL << ((nr) % BITS_PER_LONG_LONG))
80 +#define BIT_ULL_WORD(nr) ((nr) / BITS_PER_LONG_LONG)
81 +#define BITS_PER_BYTE 8
84 + * Create a contiguous bitmask starting at bit position @l and ending at
85 + * position @h. For example
86 + * GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000.
88 +#define GENMASK(h, l) \
89 + (((~0UL) - (1UL << (l)) + 1) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
91 +#define GENMASK_ULL(h, l) \
92 + (((~0ULL) - (1ULL << (l)) + 1) & \
93 + (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h))))
95 +#endif /* __LINUX_BITS_H */