[U-Boot] [PATCH 1/2] sandbox: remove CONFIG_SANDBOX_BITS_PER_LONG and GENMASK hack

Commit e519c616061d ("bitops: Fix GENMASK definition for Sandbox") is wrong.
BITS_PER_LONG must match to sizeof(long) of the compiler. If not, we are already totally screwed up.
It is weird to patch GENMASK() only.
Signed-off-by: Masahiro Yamada yamada.masahiro@socionext.com ---
arch/sandbox/Kconfig | 5 ----- arch/sandbox/include/asm/io.h | 4 ---- arch/sandbox/include/asm/posix_types.h | 2 +- arch/sandbox/include/asm/types.h | 2 +- include/linux/bitops.h | 5 ----- 5 files changed, 2 insertions(+), 16 deletions(-)
diff --git a/arch/sandbox/Kconfig b/arch/sandbox/Kconfig index 2a08533c4b59..977170b4ab84 100644 --- a/arch/sandbox/Kconfig +++ b/arch/sandbox/Kconfig @@ -41,9 +41,4 @@ config HOST_64BIT
endchoice
-config SANDBOX_BITS_PER_LONG - int - default 32 if HOST_32BIT - default 64 if HOST_64BIT - endmenu diff --git a/arch/sandbox/include/asm/io.h b/arch/sandbox/include/asm/io.h index 2a350a826c4b..fb2dd23d4659 100644 --- a/arch/sandbox/include/asm/io.h +++ b/arch/sandbox/include/asm/io.h @@ -42,15 +42,11 @@ phys_addr_t map_to_sysmem(const void *ptr); #define readb(addr) ((void)addr, 0) #define readw(addr) ((void)addr, 0) #define readl(addr) ((void)addr, 0) -#ifdef CONFIG_SANDBOX64 #define readq(addr) ((void)addr, 0) -#endif #define writeb(v, addr) ((void)addr) #define writew(v, addr) ((void)addr) #define writel(v, addr) ((void)addr) -#ifdef CONFIG_SANDBOX64 #define writeq(v, addr) ((void)addr) -#endif
/* * Clear and set bits in one shot. These macros can be used to clear and diff --git a/arch/sandbox/include/asm/posix_types.h b/arch/sandbox/include/asm/posix_types.h index ec18ed7e3c29..00e313bc08b3 100644 --- a/arch/sandbox/include/asm/posix_types.h +++ b/arch/sandbox/include/asm/posix_types.h @@ -28,7 +28,7 @@ typedef int __kernel_pid_t; typedef unsigned short __kernel_ipc_pid_t; typedef unsigned short __kernel_uid_t; typedef unsigned short __kernel_gid_t; -#if CONFIG_SANDBOX_BITS_PER_LONG == 32 +#ifdef CONFIG_HOST_32BIT typedef unsigned int __kernel_size_t; typedef int __kernel_ssize_t; typedef int __kernel_ptrdiff_t; diff --git a/arch/sandbox/include/asm/types.h b/arch/sandbox/include/asm/types.h index c1a5d2af8285..8fc3877fe1bc 100644 --- a/arch/sandbox/include/asm/types.h +++ b/arch/sandbox/include/asm/types.h @@ -18,7 +18,7 @@ typedef unsigned short umode_t; /* * Number of bits in a C 'long' on this architecture. */ -#ifdef CONFIG_PHYS_64BIT +#ifdef CONFIG_HOST_64BIT #define BITS_PER_LONG 64 #else /* CONFIG_PHYS_64BIT */ #define BITS_PER_LONG 32 diff --git a/include/linux/bitops.h b/include/linux/bitops.h index 259df43fb00f..a47f6d17bb5f 100644 --- a/include/linux/bitops.h +++ b/include/linux/bitops.h @@ -21,13 +21,8 @@ * position @h. For example * GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000. */ -#ifdef CONFIG_SANDBOX -#define GENMASK(h, l) \ - (((~0UL) << (l)) & (~0UL >> (CONFIG_SANDBOX_BITS_PER_LONG - 1 - (h)))) -#else #define GENMASK(h, l) \ (((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h)))) -#endif
#define GENMASK_ULL(h, l) \ (((~0ULL) << (l)) & (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h))))

Based on Linux commit 8bd9cb51daac ("locking/atomics, asm-generic: Move some macros from <linux/bitops.h> to a new <linux/bits.h> file").
We cannot sync <linux/bits.h>. Unfortunately, BITS_PER_LONG is defined differently from Linux.
Signed-off-by: Masahiro Yamada yamada.masahiro@socionext.com ---
include/linux/bitops.h | 25 +++---------------------- include/linux/bits.h | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 22 deletions(-) create mode 100644 include/linux/bits.h
diff --git a/include/linux/bitops.h b/include/linux/bitops.h index a47f6d17bb5f..6c6950822d65 100644 --- a/include/linux/bitops.h +++ b/include/linux/bitops.h @@ -2,30 +2,11 @@ #define _LINUX_BITOPS_H
#include <asm/types.h> -#include <asm-generic/bitsperlong.h> +#include <linux/bits.h> #include <linux/compiler.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_WORD(nr) ((nr) / BITS_PER_LONG) -#define BIT_ULL_MASK(nr) (1ULL << ((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)) -#endif - -/* - * Create a contiguous bitmask starting at bit position @l and ending at - * position @h. For example - * GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000. - */ -#define GENMASK(h, l) \ - (((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h)))) - -#define GENMASK_ULL(h, l) \ - (((~0ULL) << (l)) & (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h)))) +#define BITS_PER_TYPE(type) (sizeof(type) * BITS_PER_BYTE) +#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_TYPE(long))
/* * ffs: find first bit set. This is defined the same way as diff --git a/include/linux/bits.h b/include/linux/bits.h new file mode 100644 index 000000000000..6cba17d496df --- /dev/null +++ b/include/linux/bits.h @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __LINUX_BITS_H +#define __LINUX_BITS_H + +/* + * FIXME: + * Linux defines BITS_PER_LONG in <asm/bitsperlong.h>, which is a wrapper + * of <asm-generic/bitsperlong.h> + * U-Boot does not have <asm/bitsperlong.h>, and defines BITS_PER_LONG + * in <asm/types.h> + */ +#include <asm/types.h> +//#include <asm/bitsperlong.h> + +#define BIT(nr) (1UL << (nr)) +#define BIT_ULL(nr) (1ULL << (nr)) +#define BIT_MASK(nr) (1UL << ((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_WORD(nr) ((nr) / BITS_PER_LONG_LONG) +#define BITS_PER_BYTE 8 + +/* + * Create a contiguous bitmask starting at bit position @l and ending at + * position @h. For example + * GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000. + */ +#define GENMASK(h, l) \ + (((~0UL) - (1UL << (l)) + 1) & (~0UL >> (BITS_PER_LONG - 1 - (h)))) + +#define GENMASK_ULL(h, l) \ + (((~0ULL) - (1ULL << (l)) + 1) & \ + (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h)))) + +#endif /* __LINUX_BITS_H */

On Thu, Jun 27, 2019 at 06:15:00PM +0900, Masahiro Yamada wrote:
Based on Linux commit 8bd9cb51daac ("locking/atomics, asm-generic: Move some macros from <linux/bitops.h> to a new <linux/bits.h> file").
We cannot sync <linux/bits.h>. Unfortunately, BITS_PER_LONG is defined differently from Linux.
Signed-off-by: Masahiro Yamada yamada.masahiro@socionext.com
include/linux/bitops.h | 25 +++---------------------- include/linux/bits.h | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 22 deletions(-) create mode 100644 include/linux/bits.h
This breaks at least db-88f6720 and am65x_evm_a53 over boards that need to change their #includes apparently. Please re-work to cover that, thanks!
participants (2)
-
Masahiro Yamada
-
Tom Rini