[U-Boot] [PATCH 2/2] linux/bitops.h: split BITS, GENMASK macros out into <linux/bits.h>

Masahiro Yamada yamada.masahiro at socionext.com
Thu Jun 27 09:15:00 UTC 2019


Based on Linux commit 8bd9cb51daac ("locking/atomics, asm-generic:
Move some macros from <linux/bitops.h> to a new <linux/bits.h> file").

We cannot sync <linux/bits.h>. Unfortunately, BITS_PER_LONG is defined
differently from Linux.

Signed-off-by: Masahiro Yamada <yamada.masahiro at socionext.com>
---

 include/linux/bitops.h | 25 +++----------------------
 include/linux/bits.h   | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 22 deletions(-)
 create mode 100644 include/linux/bits.h

diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index a47f6d17bb5f..6c6950822d65 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -2,30 +2,11 @@
 #define _LINUX_BITOPS_H
 
 #include <asm/types.h>
-#include <asm-generic/bitsperlong.h>
+#include <linux/bits.h>
 #include <linux/compiler.h>
 
-#ifdef	__KERNEL__
-#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))
-#endif
-
-/*
- * 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))))
+#define BITS_PER_TYPE(type) (sizeof(type) * BITS_PER_BYTE)
+#define BITS_TO_LONGS(nr)	DIV_ROUND_UP(nr, BITS_PER_TYPE(long))
 
 /*
  * ffs: find first bit set. This is defined the same way as
diff --git a/include/linux/bits.h b/include/linux/bits.h
new file mode 100644
index 000000000000..6cba17d496df
--- /dev/null
+++ b/include/linux/bits.h
@@ -0,0 +1,35 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __LINUX_BITS_H
+#define __LINUX_BITS_H
+
+/*
+ * FIXME:
+ * Linux defines BITS_PER_LONG in <asm/bitsperlong.h>, which is a wrapper
+ * of <asm-generic/bitsperlong.h>
+ * U-Boot does not have <asm/bitsperlong.h>, and defines BITS_PER_LONG
+ * in <asm/types.h>
+ */
+#include <asm/types.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 */
-- 
2.17.1



More information about the U-Boot mailing list