From 89b5c81b75658b7ff66dea6c38a51dfecc9dd508 Mon Sep 17 00:00:00 2001
From: Jagan Teki <jteki@openedev.com>
Date: Wed, 21 Oct 2015 16:46:51 +0530
Subject: [PATCH] linux/bitops.h: GENMASK copy from linux

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

This patch is a copy from Linux, with below commit details
"bitops: Fix shift overflow in GENMASK macros"
(sha1: 00b4d9a14125f1e51874def2b9de6092e007412d)

Cc: Tom Rini <trini@konsulko.com>
Cc: Masahiro Yamada <yamada.m@jp.panasonic.com>
Signed-off-by: Jagan Teki <jteki@openedev.com>
---
 include/asm-generic/bitsperlong.h |  8 ++++++++
 include/linux/bitops.h            | 11 +++++++++++
 2 files changed, 19 insertions(+)
 create mode 100644 include/asm-generic/bitsperlong.h

diff --git a/include/asm-generic/bitsperlong.h b/include/asm-generic/bitsperlong.h
new file mode 100644
index 0000000000..75ee21e86a
--- /dev/null
+++ b/include/asm-generic/bitsperlong.h
@@ -0,0 +1,8 @@
+#ifndef __ASM_GENERIC_BITS_PER_LONG
+#define __ASM_GENERIC_BITS_PER_LONG
+
+#ifndef BITS_PER_LONG_LONG
+#define BITS_PER_LONG_LONG 64
+#endif
+
+#endif /* __ASM_GENERIC_BITS_PER_LONG */
diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index e9bb827f42..7b4011f0a3 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -7,6 +7,17 @@
 #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))))
+
 /*
  * ffs: find first bit set. This is defined the same way as
  * the libc and compiler builtin ffs routines, therefore
-- 
2.39.5