blob: 926e01ede162a6a944efd338d41e2041c8f98b2a [file] [log] [blame]
From: Anshuman Khandual <anshuman.khandual@arm.com>
Subject: uapi: define GENMASK_U128
Date: Thu, 25 Jul 2024 11:18:07 +0530
Patch series "uapi: Add support for GENMASK_U128()", v2.
This adds support for GENMASK_U128() and some corresponding tests as well.
GENMASK_U128() generated 128 bit masks will be required later on the
arm64 platform for enabling FEAT_SYSREG128 and FEAT_D128 features.
Because GENMAKS_U128() depends on __int128 data type being supported in
the compiler, its usage needs to be protected with
CONFIG_ARCH_SUPPORTS_INT128.
This patch (of 2):
This adds GENMASK_U128() and __GENMASK_U128() macros using __BITS_PER_U128
and __int128 data types. These macros will be used in providing support for
generating 128 bit masks.
Link: https://lkml.kernel.org/r/20240725054808.286708-1-anshuman.khandual@arm.com
Link: https://lkml.kernel.org/r/20240725054808.286708-2-anshuman.khandual@arm.com
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
Cc: Yury Norov <yury.norov@gmail.com>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
include/linux/bits.h | 2 ++
include/uapi/asm-generic/bitsperlong.h | 2 ++
include/uapi/linux/bits.h | 3 +++
include/uapi/linux/const.h | 1 +
4 files changed, 8 insertions(+)
--- a/include/linux/bits.h~uapi-define-genmask_u128
+++ a/include/linux/bits.h
@@ -35,5 +35,7 @@
(GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
#define GENMASK_ULL(h, l) \
(GENMASK_INPUT_CHECK(h, l) + __GENMASK_ULL(h, l))
+#define GENMASK_U128(h, l) \
+ (GENMASK_INPUT_CHECK(h, l) + __GENMASK_U128(h, l))
#endif /* __LINUX_BITS_H */
--- a/include/uapi/asm-generic/bitsperlong.h~uapi-define-genmask_u128
+++ a/include/uapi/asm-generic/bitsperlong.h
@@ -28,4 +28,6 @@
#define __BITS_PER_LONG_LONG 64
#endif
+#define __BITS_PER_U128 128
+
#endif /* _UAPI__ASM_GENERIC_BITS_PER_LONG */
--- a/include/uapi/linux/bits.h~uapi-define-genmask_u128
+++ a/include/uapi/linux/bits.h
@@ -12,4 +12,7 @@
(((~_ULL(0)) - (_ULL(1) << (l)) + 1) & \
(~_ULL(0) >> (__BITS_PER_LONG_LONG - 1 - (h))))
+#define __GENMASK_U128(h, l) \
+ ((_BIT128((h) + 1)) - (_BIT128(l)))
+
#endif /* _UAPI_LINUX_BITS_H */
--- a/include/uapi/linux/const.h~uapi-define-genmask_u128
+++ a/include/uapi/linux/const.h
@@ -27,6 +27,7 @@
#define _BITUL(x) (_UL(1) << (x))
#define _BITULL(x) (_ULL(1) << (x))
+#define _BIT128(x) ((unsigned __int128)(1) << (x))
#define __ALIGN_KERNEL(x, a) __ALIGN_KERNEL_MASK(x, (__typeof__(x))(a) - 1)
#define __ALIGN_KERNEL_MASK(x, mask) (((x) + (mask)) & ~(mask))
_