From: Jagan Teki Date: Sun, 10 May 2015 20:52:09 +0530 Subject: [U-Boot] [PATCH v2 4/5] linux/bitops.h: GENMASK copy from linux In-Reply-To: <1431271330-7169-1-git-send-email-jteki@openedev.com> References: <1431271330-7169-1-git-send-email-jteki@openedev.com> Message-ID: <1431271330-7169-5-git-send-email-jteki@openedev.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de GENMASK is used to create a contiguous bitmask([hi:lo]). Signed-off-by: Jagan Teki Cc: Tom Rini Cc: Simon Glass Cc: Masahiro Yamada --- 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@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 /* linux/include/asm-generic/bitops/non-atomic.h */ -- 1.9.1