Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

asm-generic: introduce asm/bitsperlong.h

This provides a reliable way for asm-generic/types.h and other
files to find out if it is running on a 32 or 64 bit platform.

We cannot use CONFIG_64BIT for this in headers that are included
from user space because CONFIG symbols are not available there.
We also cannot do it inside of asm/types.h because some headers
need the word size but cannot include types.h.

The solution is to introduce a new header <asm/bitsperlong.h>
that defines both __BITS_PER_LONG for user space and
BITS_PER_LONG for usage in the kernel. The asm-generic
version falls back to 32 bit unless the architecture overrides
it, which I did for all 64 bit platforms.

Signed-off-by: Remis Lima Baima <remis.developer@googlemail.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>

authored by

Arnd Bergmann and committed by
Arnd Bergmann
c31ae4bb 63b852a6

+145 -46
+8
arch/alpha/include/asm/bitsperlong.h
··· 1 + #ifndef __ASM_ALPHA_BITSPERLONG_H 2 + #define __ASM_ALPHA_BITSPERLONG_H 3 + 4 + #define __BITS_PER_LONG 64 5 + 6 + #include <asm-generic/bitsperlong.h> 7 + 8 + #endif /* __ASM_ALPHA_BITSPERLONG_H */
-3
arch/alpha/include/asm/types.h
··· 25 25 * These aren't exported outside the kernel to avoid name space clashes 26 26 */ 27 27 #ifdef __KERNEL__ 28 - 29 - #define BITS_PER_LONG 64 30 - 31 28 #ifndef __ASSEMBLY__ 32 29 33 30 typedef u64 dma_addr_t;
+1
arch/arm/include/asm/bitsperlong.h
··· 1 + #include <asm-generic/bitsperlong.h>
+1
arch/avr32/include/asm/bitsperlong.h
··· 1 + #include <asm-generic/bitsperlong.h>
+1
arch/blackfin/include/asm/bitsperlong.h
··· 1 + #include <asm-generic/bitsperlong.h>
+1
arch/cris/include/asm/bitsperlong.h
··· 1 + #include <asm-generic/bitsperlong.h>
+1
arch/frv/include/asm/bitsperlong.h
··· 1 + #include <asm-generic/bitsperlong.h>
+1
arch/h8300/include/asm/bitsperlong.h
··· 1 + #include <asm-generic/bitsperlong.h>
+8
arch/ia64/include/asm/bitsperlong.h
··· 1 + #ifndef __ASM_IA64_BITSPERLONG_H 2 + #define __ASM_IA64_BITSPERLONG_H 3 + 4 + #define __BITS_PER_LONG 64 5 + 6 + #include <asm-generic/bitsperlong.h> 7 + 8 + #endif /* __ASM_IA64_BITSPERLONG_H */
-7
arch/ia64/include/asm/types.h
··· 19 19 # define __IA64_UL(x) (x) 20 20 # define __IA64_UL_CONST(x) x 21 21 22 - # ifdef __KERNEL__ 23 - # define BITS_PER_LONG 64 24 - # endif 25 - 26 22 #else 27 23 # define __IA64_UL(x) ((unsigned long)(x)) 28 24 # define __IA64_UL_CONST(x) x##UL ··· 30 34 */ 31 35 # ifdef __KERNEL__ 32 36 33 - #define BITS_PER_LONG 64 34 - 35 37 /* DMA addresses are 64-bits wide, in general. */ 36 - 37 38 typedef u64 dma_addr_t; 38 39 39 40 # endif /* __KERNEL__ */
+1
arch/m32r/include/asm/bitsperlong.h
··· 1 + #include <asm-generic/bitsperlong.h>
+1
arch/m68k/include/asm/bitsperlong.h
··· 1 + #include <asm-generic/bitsperlong.h>
+1
arch/microblaze/include/asm/bitsperlong.h
··· 1 + #include <asm-generic/bitsperlong.h>
+8
arch/mips/include/asm/bitsperlong.h
··· 1 + #ifndef __ASM_MIPS_BITSPERLONG_H 2 + #define __ASM_MIPS_BITSPERLONG_H 3 + 4 + #define __BITS_PER_LONG _MIPS_SZLONG 5 + 6 + #include <asm-generic/bitsperlong.h> 7 + 8 + #endif /* __ASM_MIPS_BITSPERLONG_H */
-3
arch/mips/include/asm/types.h
··· 31 31 * These aren't exported outside the kernel to avoid name space clashes 32 32 */ 33 33 #ifdef __KERNEL__ 34 - 35 - #define BITS_PER_LONG _MIPS_SZLONG 36 - 37 34 #ifndef __ASSEMBLY__ 38 35 39 36 #if (defined(CONFIG_HIGHMEM) && defined(CONFIG_64BIT_PHYS_ADDR)) \
+1
arch/mn10300/include/asm/bitsperlong.h
··· 1 + #include <asm-generic/bitsperlong.h>
+20
arch/parisc/include/asm/bitsperlong.h
··· 1 + #ifndef __ASM_PARISC_BITSPERLONG_H 2 + #define __ASM_PARISC_BITSPERLONG_H 3 + 4 + /* 5 + * using CONFIG_* outside of __KERNEL__ is wrong, 6 + * __LP64__ was also removed from headers, so what 7 + * is the right approach on parisc? 8 + * -arnd 9 + */ 10 + #if (defined(__KERNEL__) && defined(CONFIG_64BIT)) || defined (__LP64__) 11 + #define __BITS_PER_LONG 64 12 + #define SHIFT_PER_LONG 6 13 + #else 14 + #define __BITS_PER_LONG 32 15 + #define SHIFT_PER_LONG 5 16 + #endif 17 + 18 + #include <asm-generic/bitsperlong.h> 19 + 20 + #endif /* __ASM_PARISC_BITSPERLONG_H */
-8
arch/parisc/include/asm/types.h
··· 14 14 */ 15 15 #ifdef __KERNEL__ 16 16 17 - #ifdef CONFIG_64BIT 18 - #define BITS_PER_LONG 64 19 - #define SHIFT_PER_LONG 6 20 - #else 21 - #define BITS_PER_LONG 32 22 - #define SHIFT_PER_LONG 5 23 - #endif 24 - 25 17 #ifndef __ASSEMBLY__ 26 18 27 19 /* Dma addresses are 32-bits wide. */
+12
arch/powerpc/include/asm/bitsperlong.h
··· 1 + #ifndef __ASM_POWERPC_BITSPERLONG_H 2 + #define __ASM_POWERPC_BITSPERLONG_H 3 + 4 + #if defined(__powerpc64__) 5 + # define __BITS_PER_LONG 64 6 + #else 7 + # define __BITS_PER_LONG 32 8 + #endif 9 + 10 + #include <asm-generic/bitsperlong.h> 11 + 12 + #endif /* __ASM_POWERPC_BITSPERLONG_H */
-9
arch/powerpc/include/asm/types.h
··· 40 40 #endif /* __ASSEMBLY__ */ 41 41 42 42 #ifdef __KERNEL__ 43 - /* 44 - * These aren't exported outside the kernel to avoid name space clashes 45 - */ 46 - #ifdef __powerpc64__ 47 - #define BITS_PER_LONG 64 48 - #else 49 - #define BITS_PER_LONG 32 50 - #endif 51 - 52 43 #ifndef __ASSEMBLY__ 53 44 54 45 typedef __vector128 vector128;
+13
arch/s390/include/asm/bitsperlong.h
··· 1 + #ifndef __ASM_S390_BITSPERLONG_H 2 + #define __ASM_S390_BITSPERLONG_H 3 + 4 + #ifndef __s390x__ 5 + #define __BITS_PER_LONG 32 6 + #else 7 + #define __BITS_PER_LONG 64 8 + #endif 9 + 10 + #include <asm-generic/bitsperlong.h> 11 + 12 + #endif /* __ASM_S390_BITSPERLONG_H */ 13 +
-6
arch/s390/include/asm/types.h
··· 28 28 */ 29 29 #ifdef __KERNEL__ 30 30 31 - #ifndef __s390x__ 32 - #define BITS_PER_LONG 32 33 - #else 34 - #define BITS_PER_LONG 64 35 - #endif 36 - 37 31 #ifndef __ASSEMBLY__ 38 32 39 33 typedef u64 dma64_addr_t;
+1
arch/sh/include/asm/bitsperlong.h
··· 1 + #include <asm-generic/bitsperlong.h>
+13
arch/sparc/include/asm/bitsperlong.h
··· 1 + #ifndef __ASM_ALPHA_BITSPERLONG_H 2 + #define __ASM_ALPHA_BITSPERLONG_H 3 + 4 + #if defined(__sparc__) && defined(__arch64__) 5 + #define __BITS_PER_LONG 64 6 + #else 7 + #define __BITS_PER_LONG 32 8 + #endif 9 + 10 + #include <asm-generic/bitsperlong.h> 11 + 12 + #endif /* __ASM_ALPHA_BITSPERLONG_H */ 13 +
-4
arch/sparc/include/asm/types.h
··· 21 21 22 22 #ifdef __KERNEL__ 23 23 24 - #define BITS_PER_LONG 64 25 - 26 24 #ifndef __ASSEMBLY__ 27 25 28 26 /* Dma addresses come in generic and 64-bit flavours. */ ··· 43 45 #endif /* __ASSEMBLY__ */ 44 46 45 47 #ifdef __KERNEL__ 46 - 47 - #define BITS_PER_LONG 32 48 48 49 49 #ifndef __ASSEMBLY__ 50 50
+13
arch/x86/include/asm/bitsperlong.h
··· 1 + #ifndef __ASM_X86_BITSPERLONG_H 2 + #define __ASM_X86_BITSPERLONG_H 3 + 4 + #ifdef __x86_64__ 5 + # define __BITS_PER_LONG 64 6 + #else 7 + # define __BITS_PER_LONG 32 8 + #endif 9 + 10 + #include <asm-generic/bitsperlong.h> 11 + 12 + #endif /* __ASM_X86_BITSPERLONG_H */ 13 +
-6
arch/x86/include/asm/types.h
··· 14 14 */ 15 15 #ifdef __KERNEL__ 16 16 17 - #ifdef CONFIG_X86_32 18 - # define BITS_PER_LONG 32 19 - #else 20 - # define BITS_PER_LONG 64 21 - #endif 22 - 23 17 #ifndef __ASSEMBLY__ 24 18 25 19 typedef u64 dma64_addr_t;
+1
arch/xtensa/include/asm/bitsperlong.h
··· 1 + #include <asm-generic/bitsperlong.h>
+1
include/asm-generic/Kbuild
··· 1 + header-y += bitsperlong.h 1 2 header-y += errno-base.h 2 3 header-y += errno.h 3 4 header-y += fcntl.h
+1
include/asm-generic/Kbuild.asm
··· 9 9 endif 10 10 unifdef-y += auxvec.h 11 11 unifdef-y += byteorder.h 12 + unifdef-y += bitsperlong.h 12 13 unifdef-y += errno.h 13 14 unifdef-y += fcntl.h 14 15 unifdef-y += ioctl.h
+32
include/asm-generic/bitsperlong.h
··· 1 + #ifndef __ASM_GENERIC_BITS_PER_LONG 2 + #define __ASM_GENERIC_BITS_PER_LONG 3 + 4 + /* 5 + * There seems to be no way of detecting this automatically from user 6 + * space, so 64 bit architectures should override this in their 7 + * bitsperlong.h. In particular, an architecture that supports 8 + * both 32 and 64 bit user space must not rely on CONFIG_64BIT 9 + * to decide it, but rather check a compiler provided macro. 10 + */ 11 + #ifndef __BITS_PER_LONG 12 + #define __BITS_PER_LONG 32 13 + #endif 14 + 15 + #ifdef __KERNEL__ 16 + 17 + #ifdef CONFIG_64BIT 18 + #define BITS_PER_LONG 64 19 + #else 20 + #define BITS_PER_LONG 32 21 + #endif /* CONFIG_64BIT */ 22 + 23 + /* 24 + * FIXME: The check currently breaks x86-64 build, so it's 25 + * temporarily disabled. Please fix x86-64 and reenable 26 + */ 27 + #if 0 && BITS_PER_LONG != __BITS_PER_LONG 28 + #error Inconsistent word size. Check asm/bitsperlong.h 29 + #endif 30 + 31 + #endif /* __KERNEL__ */ 32 + #endif /* __ASM_GENERIC_BITS_PER_LONG */
+2
include/asm-generic/int-l64.h
··· 8 8 #ifndef _ASM_GENERIC_INT_L64_H 9 9 #define _ASM_GENERIC_INT_L64_H 10 10 11 + #include <asm/bitsperlong.h> 12 + 11 13 #ifndef __ASSEMBLY__ 12 14 /* 13 15 * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
+2
include/asm-generic/int-ll64.h
··· 8 8 #ifndef _ASM_GENERIC_INT_LL64_H 9 9 #define _ASM_GENERIC_INT_LL64_H 10 10 11 + #include <asm/bitsperlong.h> 12 + 11 13 #ifndef __ASSEMBLY__ 12 14 /* 13 15 * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the