mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH master 08/13] include: import uapi/linux/kernel.h header from Linux
Date: Mon, 14 Oct 2024 13:39:07 +0200	[thread overview]
Message-ID: <20241014113912.2826190-9-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20241014113912.2826190-1-a.fatoum@pengutronix.de>

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@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




  parent reply	other threads:[~2024-10-14 13:27 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-14 11:38 [PATCH master 00/13] Misc compile test fixes Ahmad Fatoum
2024-10-14 11:39 ` [PATCH master 01/13] clk: add stub definition for of_clk_get_from_provider Ahmad Fatoum
2024-10-14 11:39 ` [PATCH master 02/13] tee: add missing header for BIT macro definition Ahmad Fatoum
2024-10-14 11:39 ` [PATCH master 03/13] tee: shm: include missing header for basprintf Ahmad Fatoum
2024-10-14 11:39 ` [PATCH master 04/13] net: dsa: realtek: fix CONFIG_SANDBOX build Ahmad Fatoum
2024-10-14 11:39 ` [PATCH master 05/13] pmdomain: imx8mp-blk-ctrl: add missing definition of ARRAY_SIZE Ahmad Fatoum
2024-10-14 11:39 ` [PATCH master 06/13] PWM: rockchip: fix compile testing with CONFIG_SANDBOX Ahmad Fatoum
2024-10-14 11:39 ` [PATCH master 07/13] watchdog: imxulp: drop unused include of asm/system.h Ahmad Fatoum
2024-10-14 11:39 ` Ahmad Fatoum [this message]
2024-10-14 11:39 ` [PATCH master 09/13] usb: typec: fix compile test with CONFIG_SANDBOX Ahmad Fatoum
2024-10-14 11:39 ` [PATCH master 10/13] bitops: fix missing defintion for DIV_ROUND_UP definitions Ahmad Fatoum
2024-10-14 11:39 ` [PATCH master 11/13] mci: am654-sdhci: drop dummy redefinition of MMC_CAP2_HS200/400 Ahmad Fatoum
2024-10-14 11:39 ` [PATCH master 12/13] hw_random: fix compilation with 64-bit size_t Ahmad Fatoum
2024-10-14 11:39 ` [PATCH master 13/13] optee: make OP-TEE OF fixup ARM-specific Ahmad Fatoum
2024-10-15  6:59 ` [PATCH master 00/13] Misc compile test fixes Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241014113912.2826190-9-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox