@@ -2,7 +2,6 @@
#define _ASMARM_BITOPS_H_
/*
* Adapated from
- * include/linux/bitops.h
* arch/arm/lib/bitops.h
*
* Copyright (C) 2015, Red Hat Inc, Andrew Jones <drjones@redhat.com>
@@ -10,10 +9,11 @@
* This work is licensed under the terms of the GNU LGPL, version 2.
*/
+#ifndef _BITOPS_H_
+#error only <bitops.h> can be included directly
+#endif
+
#define BITS_PER_LONG 32
-#define BIT(nr) (1UL << (nr))
-#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
-#define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
#define ATOMIC_BITOP(insn, mask, word) \
({ \
@@ -8,7 +8,7 @@
* This work is licensed under the terms of the GNU LGPL, version 2.
*/
#include <asm/setup.h>
-#include <asm/bitops.h>
+#include <bitops.h>
#define CPUMASK_NR_LONGS ((NR_CPUS + BITS_PER_LONG - 1) / BITS_PER_LONG)
@@ -6,7 +6,7 @@
*
* This work is licensed under the terms of the GNU LGPL, version 2.
*/
-#include <asm/bitops.h>
+#include <bitops.h>
#include <asm/barrier.h>
#include <asm/mmu.h>
@@ -2,7 +2,6 @@
#define _ASMARM64_BITOPS_H_
/*
* Adapated from
- * include/linux/bitops.h
* arch/arm64/lib/bitops.S
*
* Copyright (C) 2015, Red Hat Inc, Andrew Jones <drjones@redhat.com>
@@ -10,10 +9,11 @@
* This work is licensed under the terms of the GNU LGPL, version 2.
*/
+#ifndef _BITOPS_H_
+#error only <bitops.h> can be included directly
+#endif
+
#define BITS_PER_LONG 64
-#define BIT(nr) (1UL << (nr))
-#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
-#define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
#define ATOMIC_BITOP(insn, mask, word) \
({ \
new file mode 100644
@@ -0,0 +1,35 @@
+#ifndef _BITOPS_H_
+#define _BITOPS_H_
+
+/*
+ * Adapated from
+ * include/linux/bitops.h
+ *
+ * Copyright (C) 2015, Red Hat Inc, Andrew Jones <drjones@redhat.com>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.
+ */
+
+#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
+#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
+
+#include <asm/bitops.h>
+
+/*
+ * 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) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
+
+#define GENMASK_ULL(h, l) \
+ (((~0ULL) << (l)) & (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h))))
+
+#endif
new file mode 100644
@@ -0,0 +1,10 @@
+#ifndef _ASMPPC64_BITOPS_H_
+#define _ASMPPC64_BITOPS_H_
+
+#ifndef _BITOPS_H_
+#error only <bitops.h> can be included directly
+#endif
+
+#define BITS_PER_LONG 64
+
+#endif
new file mode 100644
@@ -0,0 +1,14 @@
+#ifndef _ASMX86_BITOPS_H_
+#define _ASMX86_BITOPS_H_
+
+#ifndef _BITOPS_H_
+#error only <bitops.h> can be included directly
+#endif
+
+#ifdef __x86_64__
+#define BITS_PER_LONG 64
+#else
+#define BITS_PER_LONG 32
+#endif
+
+#endif
Factored out common bitops stuff, just like Linux's include/linux/bitops.h. Signed-off-by: Peter Feiner <pfeiner@google.com> --- lib/arm/asm/bitops.h | 8 ++++---- lib/arm/asm/cpumask.h | 2 +- lib/arm/bitops.c | 2 +- lib/arm64/asm/bitops.h | 8 ++++---- lib/bitops.h | 35 +++++++++++++++++++++++++++++++++++ lib/ppc64/asm/bitops.h | 10 ++++++++++ lib/x86/asm/bitops.h | 14 ++++++++++++++ 7 files changed, 69 insertions(+), 10 deletions(-) create mode 100644 lib/bitops.h create mode 100644 lib/ppc64/asm/bitops.h create mode 100644 lib/x86/asm/bitops.h