[PATCH master 08/13] include: import uapi/linux/kernel.h header from Linux

Ahmad Fatoum a.fatoum at pengutronix.de
Mon Oct 14 04:39:07 PDT 2024


The UAPI (userspace API) headers in LInux are chiefly meant for
inclusion from userspace, but they are also used from normal kernel
headers to break recursive dependencies.

In order to keep it easier to sync the kernel header code, let's adopt
the same structure in barebox.

No functional change intended.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 include/linux/align.h       |  8 +++++---
 include/linux/const.h       | 24 +-----------------------
 include/linux/math.h        |  2 +-
 include/uapi/linux/const.h  | 36 ++++++++++++++++++++++++++++++++++++
 include/uapi/linux/kernel.h |  7 +++++++
 5 files changed, 50 insertions(+), 27 deletions(-)
 create mode 100644 include/uapi/linux/const.h
 create mode 100644 include/uapi/linux/kernel.h

diff --git a/include/linux/align.h b/include/linux/align.h
index 4b373bf73d5b..3b0c60d6e9ae 100644
--- a/include/linux/align.h
+++ b/include/linux/align.h
@@ -2,9 +2,11 @@
 #ifndef _LINUX_ALIGN_H
 #define _LINUX_ALIGN_H
 
-#define ALIGN(x, a)		__ALIGN_MASK(x, (typeof(x))(a) - 1)
-#define ALIGN_DOWN(x, a)	ALIGN((x) - ((a) - 1), (a))
-#define __ALIGN_MASK(x, mask)	(((x) + (mask)) & ~(mask))
+#include <linux/const.h>
+
+#define ALIGN(x, a)		__ALIGN_KERNEL((x), (a))
+#define ALIGN_DOWN(x, a)	__ALIGN_KERNEL((x) - ((a) - 1), (a))
+#define __ALIGN_MASK(x, mask)	__ALIGN_KERNEL_MASK((x), (mask))
 #define PTR_ALIGN(p, a)		((typeof(p))ALIGN((unsigned long)(p), (a)))
 #define PTR_ALIGN_DOWN(p, a)	((typeof(p))ALIGN_DOWN((unsigned long)(p), (a)))
 #define PTR_IS_ALIGNED(x, a)	IS_ALIGNED((unsigned long)(x), (a))
diff --git a/include/linux/const.h b/include/linux/const.h
index 77e4f6fd8a2a..90662deeb7ca 100644
--- a/include/linux/const.h
+++ b/include/linux/const.h
@@ -5,29 +5,7 @@
 #ifndef _LINUX_CONST_H
 #define _LINUX_CONST_H
 
-/* Some constant macros are used in both assembler and
- * C code.  Therefore we cannot annotate them always with
- * 'UL' and other type specifiers unilaterally.  We
- * use the following macros to deal with this.
- *
- * Similarly, _AT() will cast an expression with a type in C, but
- * leave it unchanged in asm.
- */
-
-#ifdef __ASSEMBLY__
-#define _AC(X,Y)	X
-#define _AT(T,X)	X
-#else
-#define __AC(X,Y)	(X##Y)
-#define _AC(X,Y)	__AC(X,Y)
-#define _AT(T,X)	((T)(X))
-#endif
-
-#define _UL(x)		(_AC(x, UL))
-#define _ULL(x)		(_AC(x, ULL))
-
-#define _BITUL(x)	(_UL(1) << (x))
-#define _BITULL(x)	(_ULL(1) << (x))
+#include <uapi/linux/const.h>
 
 #define UL(x)		(_UL(x))
 #define ULL(x)		(_ULL(x))
diff --git a/include/linux/math.h b/include/linux/math.h
index e7c47fa404ab..e09ecaeab67c 100644
--- a/include/linux/math.h
+++ b/include/linux/math.h
@@ -33,7 +33,7 @@
  */
 #define round_down(x, y) ((x) & ~__round_mask(x, y))
 
-#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
+#define DIV_ROUND_UP __KERNEL_DIV_ROUND_UP
 
 #define DIV_ROUND_DOWN_ULL(ll, d) \
 	({ unsigned long long _tmp = (ll); do_div(_tmp, d); _tmp; })
diff --git a/include/uapi/linux/const.h b/include/uapi/linux/const.h
new file mode 100644
index 000000000000..a429381e7ca5
--- /dev/null
+++ b/include/uapi/linux/const.h
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/* const.h: Macros for dealing with constants.  */
+
+#ifndef _UAPI_LINUX_CONST_H
+#define _UAPI_LINUX_CONST_H
+
+/* Some constant macros are used in both assembler and
+ * C code.  Therefore we cannot annotate them always with
+ * 'UL' and other type specifiers unilaterally.  We
+ * use the following macros to deal with this.
+ *
+ * Similarly, _AT() will cast an expression with a type in C, but
+ * leave it unchanged in asm.
+ */
+
+#ifdef __ASSEMBLY__
+#define _AC(X,Y)	X
+#define _AT(T,X)	X
+#else
+#define __AC(X,Y)	(X##Y)
+#define _AC(X,Y)	__AC(X,Y)
+#define _AT(T,X)	((T)(X))
+#endif
+
+#define _UL(x)		(_AC(x, UL))
+#define _ULL(x)		(_AC(x, ULL))
+
+#define _BITUL(x)	(_UL(1) << (x))
+#define _BITULL(x)	(_ULL(1) << (x))
+
+#define __ALIGN_KERNEL(x, a)		__ALIGN_KERNEL_MASK(x, (__typeof__(x))(a) - 1)
+#define __ALIGN_KERNEL_MASK(x, mask)	(((x) + (mask)) & ~(mask))
+
+#define __KERNEL_DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
+
+#endif /* _UAPI_LINUX_CONST_H */
diff --git a/include/uapi/linux/kernel.h b/include/uapi/linux/kernel.h
new file mode 100644
index 000000000000..d3f1a684864e
--- /dev/null
+++ b/include/uapi/linux/kernel.h
@@ -0,0 +1,7 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+#ifndef _UAPI_LINUX_KERNEL_H
+#define _UAPI_LINUX_KERNEL_H
+
+#include <linux/const.h>
+
+#endif /* _UAPI_LINUX_KERNEL_H */
-- 
2.39.5




More information about the barebox mailing list