* [PATCH 1/3] include: const: make UL/ULL() macros commonly available
2023-06-09 4:54 [PATCH 0/3] include: bitops/const: partial update from Linux Denis Orlov
@ 2023-06-09 4:54 ` Denis Orlov
2023-06-09 4:54 ` [PATCH 2/3] include: bitops: allow BIT* macros to be used in assembly code Denis Orlov
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Denis Orlov @ 2023-06-09 4:54 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum, Denis Orlov
Import the definitions from Linux. Some code actually used those
already, defining them locally. As these are not needed now that there
are common ones available, remove the duplicate definitions.
While at it, also update _BITUL/_BITULL() definitions to align more with
the latest Linux sources.
Signed-off-by: Denis Orlov <denorl2009@gmail.com>
---
arch/arm/include/asm/memory.h | 5 -----
arch/arm/include/asm/pgtable64.h | 2 --
arch/kvx/include/asm/sfr_defs.h | 2 --
include/linux/const.h | 10 ++++++++--
4 files changed, 8 insertions(+), 11 deletions(-)
diff --git a/arch/arm/include/asm/memory.h b/arch/arm/include/asm/memory.h
index 2b454fa673..23fbbd8438 100644
--- a/arch/arm/include/asm/memory.h
+++ b/arch/arm/include/asm/memory.h
@@ -6,11 +6,6 @@
#include <memory.h>
#include <linux/const.h>
-/*
- * Allow for constants defined here to be used from assembly code
- * by prepending the UL suffix only with actual C code compilation.
- */
-#define UL(x) _AC(x, UL)
static inline int arm_add_mem_device(const char* name, resource_size_t start,
resource_size_t size)
diff --git a/arch/arm/include/asm/pgtable64.h b/arch/arm/include/asm/pgtable64.h
index dbec61753b..21dac30cfe 100644
--- a/arch/arm/include/asm/pgtable64.h
+++ b/arch/arm/include/asm/pgtable64.h
@@ -4,8 +4,6 @@
#ifndef __ASM_PGTABLE64_H
#define __ASM_PGTABLE64_H
-#define UL(x) _AC(x, UL)
-
#define UNUSED_DESC 0x6EbAAD0BBADbA6E0
#define VA_START 0x0
diff --git a/arch/kvx/include/asm/sfr_defs.h b/arch/kvx/include/asm/sfr_defs.h
index 2b7598e0aa..7f6fbd206b 100644
--- a/arch/kvx/include/asm/sfr_defs.h
+++ b/arch/kvx/include/asm/sfr_defs.h
@@ -8,8 +8,6 @@
#include <linux/const.h>
-#define _ULL(X) _AC(X, ULL)
-
/* Register file indices */
#define KVX_SFR_PC 0 /* Program Counter $pc $s0 */
#define KVX_SFR_PS 1 /* Processor State $ps $s1 */
diff --git a/include/linux/const.h b/include/linux/const.h
index 07f886d271..07414f95de 100644
--- a/include/linux/const.h
+++ b/include/linux/const.h
@@ -23,7 +23,13 @@
#define _AT(T,X) ((T)(X))
#endif
-#define _BITUL(x) (_AC(1,UL) << (x))
-#define _BITULL(x) (_AC(1,ULL) << (x))
+#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 UL(x) (_UL(x))
+#define ULL(x) (_ULL(x))
#endif /* !(_LINUX_CONST_H) */
--
2.41.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/3] include: bitops: allow BIT* macros to be used in assembly code
2023-06-09 4:54 [PATCH 0/3] include: bitops/const: partial update from Linux Denis Orlov
2023-06-09 4:54 ` [PATCH 1/3] include: const: make UL/ULL() macros commonly available Denis Orlov
@ 2023-06-09 4:54 ` Denis Orlov
2023-06-09 4:54 ` [PATCH 3/3] include: bitops: import more BITS_TO_* defines from linux Denis Orlov
2023-06-09 6:30 ` [PATCH 0/3] include: bitops/const: partial update from Linux Sascha Hauer
3 siblings, 0 replies; 5+ messages in thread
From: Denis Orlov @ 2023-06-09 4:54 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum, Denis Orlov
Use UL/ULL() macros for those so that corresponding suffixes only appear
when we are compiling C code. Hide all the other functions/macros that
we can't use in assembly with '#ifndef __ASSEMBLY__'.
Signed-off-by: Denis Orlov <denorl2009@gmail.com>
---
include/linux/bitops.h | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index eb5ff37f2f..d9a5a81a9c 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -2,14 +2,16 @@
#ifndef _LINUX_BITOPS_H
#define _LINUX_BITOPS_H
+
#include <linux/types.h>
+#include <linux/const.h>
#ifdef __KERNEL__
-#define BIT(nr) (1UL << (nr))
-#define BIT_ULL(nr) (1ULL << (nr))
-#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
+#define BIT(nr) (UL(1) << (nr))
+#define BIT_ULL(nr) (ULL(1) << (nr))
+#define BIT_MASK(nr) (UL(1) << ((nr) % BITS_PER_LONG))
#define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
-#define BIT_ULL_MASK(nr) (1ULL << ((nr) % BITS_PER_LONG_LONG))
+#define BIT_ULL_MASK(nr) (ULL(1) << ((nr) % BITS_PER_LONG_LONG))
#define BIT_ULL_WORD(nr) ((nr) / BITS_PER_LONG_LONG)
#define BITS_PER_BYTE 8
#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
@@ -21,11 +23,14 @@
* GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000.
*/
#define GENMASK(h, l) \
- (((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
+ (((~UL(0)) - (UL(1) << (l)) + 1) & \
+ (~UL(0) >> (BITS_PER_LONG - 1 - (h))))
#define GENMASK_ULL(h, l) \
- (((~0ULL) << (l)) & (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h))))
+ (((~ULL(0)) - (ULL(1) << (l)) + 1) & \
+ (~ULL(0) >> (BITS_PER_LONG_LONG - 1 - (h))))
+#ifndef __ASSEMBLY__
/*
* Include this here because some architectures need generic_ffs/fls in
* scope
@@ -237,5 +242,6 @@ extern unsigned long find_last_bit(const unsigned long *addr,
unsigned long size);
#endif
+#endif /* !(__ASSEMBLY__) */
#endif /* __KERNEL__ */
#endif
--
2.41.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 3/3] include: bitops: import more BITS_TO_* defines from linux
2023-06-09 4:54 [PATCH 0/3] include: bitops/const: partial update from Linux Denis Orlov
2023-06-09 4:54 ` [PATCH 1/3] include: const: make UL/ULL() macros commonly available Denis Orlov
2023-06-09 4:54 ` [PATCH 2/3] include: bitops: allow BIT* macros to be used in assembly code Denis Orlov
@ 2023-06-09 4:54 ` Denis Orlov
2023-06-09 6:30 ` [PATCH 0/3] include: bitops/const: partial update from Linux Sascha Hauer
3 siblings, 0 replies; 5+ messages in thread
From: Denis Orlov @ 2023-06-09 4:54 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum, Denis Orlov
Those seem quite useful, e.g. when defining bitmasks.
Signed-off-by: Denis Orlov <denorl2009@gmail.com>
---
include/linux/bitops.h | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index d9a5a81a9c..a5f6ac6545 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -14,7 +14,11 @@
#define BIT_ULL_MASK(nr) (ULL(1) << ((nr) % BITS_PER_LONG_LONG))
#define BIT_ULL_WORD(nr) ((nr) / BITS_PER_LONG_LONG)
#define BITS_PER_BYTE 8
-#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
+#define BITS_PER_TYPE(type) (sizeof(type) * BITS_PER_BYTE)
+#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_TYPE(long))
+#define BITS_TO_U64(nr) DIV_ROUND_UP(nr, BITS_PER_TYPE(u64))
+#define BITS_TO_U32(nr) DIV_ROUND_UP(nr, BITS_PER_TYPE(u32))
+#define BITS_TO_BYTES(nr) DIV_ROUND_UP(nr, BITS_PER_TYPE(char))
#endif
/*
--
2.41.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 0/3] include: bitops/const: partial update from Linux
2023-06-09 4:54 [PATCH 0/3] include: bitops/const: partial update from Linux Denis Orlov
` (2 preceding siblings ...)
2023-06-09 4:54 ` [PATCH 3/3] include: bitops: import more BITS_TO_* defines from linux Denis Orlov
@ 2023-06-09 6:30 ` Sascha Hauer
3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2023-06-09 6:30 UTC (permalink / raw)
To: Denis Orlov; +Cc: barebox, Ahmad Fatoum
On Fri, Jun 09, 2023 at 07:54:06AM +0300, Denis Orlov wrote:
> This updates some of the definitions in those files, mainly to make
> BIT*/GENMASK() macros usable in assembly code.
>
> Denis Orlov (3):
> include: const: make UL/ULL() macros commonly available
> include: bitops: allow BIT* macros to be used in assembly code
> include: bitops: import more BITS_TO_* defines from linux
Applied, thanks
Sascha
>
> arch/arm/include/asm/memory.h | 5 -----
> arch/arm/include/asm/pgtable64.h | 2 --
> arch/kvx/include/asm/sfr_defs.h | 2 --
> include/linux/bitops.h | 24 +++++++++++++++++-------
> include/linux/const.h | 10 ++++++++--
> 5 files changed, 25 insertions(+), 18 deletions(-)
>
> --
> 2.41.0
>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 5+ messages in thread