backports: add GENMASK and GENMASK_ULL
authorFelix Fietkau <nbd@openwrt.org>
Sun, 16 Nov 2014 13:39:57 +0000 (14:39 +0100)
committerHauke Mehrtens <hauke@hauke-m.de>
Sun, 16 Nov 2014 15:09:17 +0000 (16:09 +0100)
I intend to use this for a new driver

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
backport/backport-include/linux/bitops.h [new file with mode: 0644]

diff --git a/backport/backport-include/linux/bitops.h b/backport/backport-include/linux/bitops.h
new file mode 100644 (file)
index 0000000..b0e9283
--- /dev/null
@@ -0,0 +1,19 @@
+#ifndef __BACKPORT_BITOPS_H
+#define __BACKPORT_BITOPS_H
+#include_next <linux/bitops.h>
+#include <linux/version.h>
+#include <generated/utsrelease.h>
+
+#ifndef GENMASK
+
+/*
+ * 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)          (((U32_C(1) << ((h) - (l) + 1)) - 1) << (l))
+#define GENMASK_ULL(h, l)      (((U64_C(1) << ((h) - (l) + 1)) - 1) << (l))
+
+#endif
+
+#endif /* __BACKPORT_BITOPS_H */