summaryrefslogtreecommitdiff
path: root/include/uapi/linux/bits.h
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2023-12-12 11:15:28 -0500
committerPaolo Bonzini <pbonzini@redhat.com>2024-02-08 08:41:03 -0500
commit3c7a8e190bc580813ddd9259f62971c8d2a6b5ad (patch)
tree09e2ec9478f5d3fec2fb4af45c1df92f457a72d8 /include/uapi/linux/bits.h
parent047371968ffc470769f541d6933e262dc7085456 (diff)
uapi: introduce uapi-friendly macros for GENMASK
Move __GENMASK and __GENMASK_ULL from include/ to include/uapi/ so that they can be used to define masks in userspace API headers. Compared to what is already in include/linux/bits.h, the definitions need to use the uglified versions of UL(), ULL(), BITS_PER_LONG and BITS_PER_LONG_LONG (which did not even exist), but otherwise expand to the same content. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'include/uapi/linux/bits.h')
-rw-r--r--include/uapi/linux/bits.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/include/uapi/linux/bits.h b/include/uapi/linux/bits.h
new file mode 100644
index 000000000000..3c2a101986a3
--- /dev/null
+++ b/include/uapi/linux/bits.h
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/* bits.h: Macros for dealing with bitmasks. */
+
+#ifndef _UAPI_LINUX_BITS_H
+#define _UAPI_LINUX_BITS_H
+
+#define __GENMASK(h, l) \
+ (((~_UL(0)) - (_UL(1) << (l)) + 1) & \
+ (~_UL(0) >> (__BITS_PER_LONG - 1 - (h))))
+
+#define __GENMASK_ULL(h, l) \
+ (((~_ULL(0)) - (_ULL(1) << (l)) + 1) & \
+ (~_ULL(0) >> (__BITS_PER_LONG_LONG - 1 - (h))))
+
+#endif /* _UAPI_LINUX_BITS_H */