Commit c31ae4bb4a9fa4606a74c0a4fb61b74f804e861e

Authored by Arnd Bergmann
Committed by Arnd Bergmann
1 parent 63b852a6b6

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>

Showing 33 changed files with 145 additions and 46 deletions Side-by-side Diff

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 */
arch/alpha/include/asm/types.h
... ... @@ -25,9 +25,6 @@
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;
arch/arm/include/asm/bitsperlong.h
  1 +#include <asm-generic/bitsperlong.h>
arch/avr32/include/asm/bitsperlong.h
  1 +#include <asm-generic/bitsperlong.h>
arch/blackfin/include/asm/bitsperlong.h
  1 +#include <asm-generic/bitsperlong.h>
arch/cris/include/asm/bitsperlong.h
  1 +#include <asm-generic/bitsperlong.h>
arch/frv/include/asm/bitsperlong.h
  1 +#include <asm-generic/bitsperlong.h>
arch/h8300/include/asm/bitsperlong.h
  1 +#include <asm-generic/bitsperlong.h>
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 */
arch/ia64/include/asm/types.h
... ... @@ -19,10 +19,6 @@
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
29 25  
... ... @@ -34,10 +30,7 @@
34 30 */
35 31 # ifdef __KERNEL__
36 32  
37   -#define BITS_PER_LONG 64
38   -
39 33 /* DMA addresses are 64-bits wide, in general. */
40   -
41 34 typedef u64 dma_addr_t;
42 35  
43 36 # endif /* __KERNEL__ */
arch/m32r/include/asm/bitsperlong.h
  1 +#include <asm-generic/bitsperlong.h>
arch/m68k/include/asm/bitsperlong.h
  1 +#include <asm-generic/bitsperlong.h>
arch/microblaze/include/asm/bitsperlong.h
  1 +#include <asm-generic/bitsperlong.h>
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 */
arch/mips/include/asm/types.h
... ... @@ -31,9 +31,6 @@
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)) \
arch/mn10300/include/asm/bitsperlong.h
  1 +#include <asm-generic/bitsperlong.h>
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 */
arch/parisc/include/asm/types.h
... ... @@ -14,14 +14,6 @@
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. */
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 */
arch/powerpc/include/asm/types.h
... ... @@ -40,15 +40,6 @@
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;
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 */
arch/s390/include/asm/types.h
... ... @@ -28,12 +28,6 @@
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;
arch/sh/include/asm/bitsperlong.h
  1 +#include <asm-generic/bitsperlong.h>
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 */
arch/sparc/include/asm/types.h
... ... @@ -21,8 +21,6 @@
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. */
... ... @@ -45,8 +43,6 @@
45 43 #endif /* __ASSEMBLY__ */
46 44  
47 45 #ifdef __KERNEL__
48   -
49   -#define BITS_PER_LONG 32
50 46  
51 47 #ifndef __ASSEMBLY__
52 48  
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 */
arch/x86/include/asm/types.h
... ... @@ -14,12 +14,6 @@
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;
arch/xtensa/include/asm/bitsperlong.h
  1 +#include <asm-generic/bitsperlong.h>
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
include/asm-generic/Kbuild.asm
... ... @@ -9,6 +9,7 @@
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
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 */
include/asm-generic/int-l64.h
... ... @@ -8,6 +8,8 @@
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
include/asm-generic/int-ll64.h
... ... @@ -8,6 +8,8 @@
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