summaryrefslogtreecommitdiff
path: root/include/linux/bits.h
diff options
context:
space:
mode:
authorMark Brown <broonie@kernel.org>2018-08-28 19:03:57 +0100
committerMark Brown <broonie@kernel.org>2018-08-28 19:03:57 +0100
commit6e2d6b2728fcb408eabd7991804f8cb33ff59f20 (patch)
tree18dc3fc5bd55fa9ff92430e4ab8353de6c5c0e55 /include/linux/bits.h
parent6f0a256253f48095ba2e5bcdfbed41f21643c105 (diff)
parent5b394b2ddf0347bef56e50c69a58773c94343ff3 (diff)
Merge tag 'v4.19-rc1' into asoc-4.19
Linux 4.19-rc1
Diffstat (limited to 'include/linux/bits.h')
-rw-r--r--include/linux/bits.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/include/linux/bits.h b/include/linux/bits.h
new file mode 100644
index 000000000000..2b7b532c1d51
--- /dev/null
+++ b/include/linux/bits.h
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __LINUX_BITS_H
+#define __LINUX_BITS_H
+#include <asm/bitsperlong.h>
+
+#define BIT(nr) (1UL << (nr))
+#define BIT_ULL(nr) (1ULL << (nr))
+#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
+#define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
+#define BIT_ULL_MASK(nr) (1ULL << ((nr) % BITS_PER_LONG_LONG))
+#define BIT_ULL_WORD(nr) ((nr) / BITS_PER_LONG_LONG)
+#define BITS_PER_BYTE 8
+
+/*
+ * Create a contiguous bitmask starting at bit position @l and ending at
+ * position @h. For example
+ * GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000.
+ */
+#define GENMASK(h, l) \
+ (((~0UL) - (1UL << (l)) + 1) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
+
+#define GENMASK_ULL(h, l) \
+ (((~0ULL) - (1ULL << (l)) + 1) & \
+ (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h))))
+
+#endif /* __LINUX_BITS_H */