[U-Boot] [PATCH v2 4/5] linux/bitops.h: GENMASK copy from linux

Jagan Teki jteki at openedev.com
Sun May 10 17:22:09 CEST 2015


GENMASK is used to create a contiguous bitmask([hi:lo]).

Signed-off-by: Jagan Teki <jteki at openedev.com>
Cc: Tom Rini <trini at konsulko.com>
Cc: Simon Glass <sjg at chromium.org>
Cc: Masahiro Yamada <yamada.m at jp.panasonic.com>
---
 include/linux/bitops.h | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index c098c9a..08db119 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -108,6 +108,17 @@ static inline unsigned int generic_hweight8(unsigned int w)
 #define BIT_MASK(nr)		(1UL << ((nr) % BITS_PER_LONG))
 #define BIT_WORD(nr)		((nr) / BITS_PER_LONG)
 
+/*
+ * 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))))
+
 #include <asm/bitops.h>
 
 /* linux/include/asm-generic/bitops/non-atomic.h */
-- 
1.9.1



More information about the U-Boot mailing list