Skip to content

Commit

Permalink
asm-generic: introduce asm/bitsperlong.h
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
arndb authored and Arnd Bergmann committed Jun 11, 2009
1 parent 63b852a commit c31ae4b
Show file tree
Hide file tree
Showing 33 changed files with 145 additions and 46 deletions.
8 changes: 8 additions & 0 deletions arch/alpha/include/asm/bitsperlong.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef __ASM_ALPHA_BITSPERLONG_H
#define __ASM_ALPHA_BITSPERLONG_H

#define __BITS_PER_LONG 64

#include <asm-generic/bitsperlong.h>

#endif /* __ASM_ALPHA_BITSPERLONG_H */
3 changes: 0 additions & 3 deletions arch/alpha/include/asm/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ typedef unsigned int umode_t;
* These aren't exported outside the kernel to avoid name space clashes
*/
#ifdef __KERNEL__

#define BITS_PER_LONG 64

#ifndef __ASSEMBLY__

typedef u64 dma_addr_t;
Expand Down
1 change: 1 addition & 0 deletions arch/arm/include/asm/bitsperlong.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <asm-generic/bitsperlong.h>
1 change: 1 addition & 0 deletions arch/avr32/include/asm/bitsperlong.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <asm-generic/bitsperlong.h>
1 change: 1 addition & 0 deletions arch/blackfin/include/asm/bitsperlong.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <asm-generic/bitsperlong.h>
1 change: 1 addition & 0 deletions arch/cris/include/asm/bitsperlong.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <asm-generic/bitsperlong.h>
1 change: 1 addition & 0 deletions arch/frv/include/asm/bitsperlong.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <asm-generic/bitsperlong.h>
1 change: 1 addition & 0 deletions arch/h8300/include/asm/bitsperlong.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <asm-generic/bitsperlong.h>
8 changes: 8 additions & 0 deletions arch/ia64/include/asm/bitsperlong.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef __ASM_IA64_BITSPERLONG_H
#define __ASM_IA64_BITSPERLONG_H

#define __BITS_PER_LONG 64

#include <asm-generic/bitsperlong.h>

#endif /* __ASM_IA64_BITSPERLONG_H */
7 changes: 0 additions & 7 deletions arch/ia64/include/asm/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
# define __IA64_UL(x) (x)
# define __IA64_UL_CONST(x) x

# ifdef __KERNEL__
# define BITS_PER_LONG 64
# endif

#else
# define __IA64_UL(x) ((unsigned long)(x))
# define __IA64_UL_CONST(x) x##UL
Expand All @@ -34,10 +30,7 @@ typedef unsigned int umode_t;
*/
# ifdef __KERNEL__

#define BITS_PER_LONG 64

/* DMA addresses are 64-bits wide, in general. */

typedef u64 dma_addr_t;

# endif /* __KERNEL__ */
Expand Down
1 change: 1 addition & 0 deletions arch/m32r/include/asm/bitsperlong.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <asm-generic/bitsperlong.h>
1 change: 1 addition & 0 deletions arch/m68k/include/asm/bitsperlong.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <asm-generic/bitsperlong.h>
1 change: 1 addition & 0 deletions arch/microblaze/include/asm/bitsperlong.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <asm-generic/bitsperlong.h>
8 changes: 8 additions & 0 deletions arch/mips/include/asm/bitsperlong.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef __ASM_MIPS_BITSPERLONG_H
#define __ASM_MIPS_BITSPERLONG_H

#define __BITS_PER_LONG _MIPS_SZLONG

#include <asm-generic/bitsperlong.h>

#endif /* __ASM_MIPS_BITSPERLONG_H */
3 changes: 0 additions & 3 deletions arch/mips/include/asm/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ typedef unsigned short umode_t;
* These aren't exported outside the kernel to avoid name space clashes
*/
#ifdef __KERNEL__

#define BITS_PER_LONG _MIPS_SZLONG

#ifndef __ASSEMBLY__

#if (defined(CONFIG_HIGHMEM) && defined(CONFIG_64BIT_PHYS_ADDR)) \
Expand Down
1 change: 1 addition & 0 deletions arch/mn10300/include/asm/bitsperlong.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <asm-generic/bitsperlong.h>
20 changes: 20 additions & 0 deletions arch/parisc/include/asm/bitsperlong.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef __ASM_PARISC_BITSPERLONG_H
#define __ASM_PARISC_BITSPERLONG_H

/*
* using CONFIG_* outside of __KERNEL__ is wrong,
* __LP64__ was also removed from headers, so what
* is the right approach on parisc?
* -arnd
*/
#if (defined(__KERNEL__) && defined(CONFIG_64BIT)) || defined (__LP64__)
#define __BITS_PER_LONG 64
#define SHIFT_PER_LONG 6
#else
#define __BITS_PER_LONG 32
#define SHIFT_PER_LONG 5
#endif

#include <asm-generic/bitsperlong.h>

#endif /* __ASM_PARISC_BITSPERLONG_H */
8 changes: 0 additions & 8 deletions arch/parisc/include/asm/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@ typedef unsigned short umode_t;
*/
#ifdef __KERNEL__

#ifdef CONFIG_64BIT
#define BITS_PER_LONG 64
#define SHIFT_PER_LONG 6
#else
#define BITS_PER_LONG 32
#define SHIFT_PER_LONG 5
#endif

#ifndef __ASSEMBLY__

/* Dma addresses are 32-bits wide. */
Expand Down
12 changes: 12 additions & 0 deletions arch/powerpc/include/asm/bitsperlong.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef __ASM_POWERPC_BITSPERLONG_H
#define __ASM_POWERPC_BITSPERLONG_H

#if defined(__powerpc64__)
# define __BITS_PER_LONG 64
#else
# define __BITS_PER_LONG 32
#endif

#include <asm-generic/bitsperlong.h>

#endif /* __ASM_POWERPC_BITSPERLONG_H */
9 changes: 0 additions & 9 deletions arch/powerpc/include/asm/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,6 @@ typedef struct {
#endif /* __ASSEMBLY__ */

#ifdef __KERNEL__
/*
* These aren't exported outside the kernel to avoid name space clashes
*/
#ifdef __powerpc64__
#define BITS_PER_LONG 64
#else
#define BITS_PER_LONG 32
#endif

#ifndef __ASSEMBLY__

typedef __vector128 vector128;
Expand Down
13 changes: 13 additions & 0 deletions arch/s390/include/asm/bitsperlong.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef __ASM_S390_BITSPERLONG_H
#define __ASM_S390_BITSPERLONG_H

#ifndef __s390x__
#define __BITS_PER_LONG 32
#else
#define __BITS_PER_LONG 64
#endif

#include <asm-generic/bitsperlong.h>

#endif /* __ASM_S390_BITSPERLONG_H */

6 changes: 0 additions & 6 deletions arch/s390/include/asm/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ typedef __signed__ long saddr_t;
*/
#ifdef __KERNEL__

#ifndef __s390x__
#define BITS_PER_LONG 32
#else
#define BITS_PER_LONG 64
#endif

#ifndef __ASSEMBLY__

typedef u64 dma64_addr_t;
Expand Down
1 change: 1 addition & 0 deletions arch/sh/include/asm/bitsperlong.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <asm-generic/bitsperlong.h>
13 changes: 13 additions & 0 deletions arch/sparc/include/asm/bitsperlong.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef __ASM_ALPHA_BITSPERLONG_H
#define __ASM_ALPHA_BITSPERLONG_H

#if defined(__sparc__) && defined(__arch64__)
#define __BITS_PER_LONG 64
#else
#define __BITS_PER_LONG 32
#endif

#include <asm-generic/bitsperlong.h>

#endif /* __ASM_ALPHA_BITSPERLONG_H */

4 changes: 0 additions & 4 deletions arch/sparc/include/asm/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ typedef unsigned short umode_t;

#ifdef __KERNEL__

#define BITS_PER_LONG 64

#ifndef __ASSEMBLY__

/* Dma addresses come in generic and 64-bit flavours. */
Expand All @@ -46,8 +44,6 @@ typedef unsigned short umode_t;

#ifdef __KERNEL__

#define BITS_PER_LONG 32

#ifndef __ASSEMBLY__

typedef u32 dma_addr_t;
Expand Down
13 changes: 13 additions & 0 deletions arch/x86/include/asm/bitsperlong.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef __ASM_X86_BITSPERLONG_H
#define __ASM_X86_BITSPERLONG_H

#ifdef __x86_64__
# define __BITS_PER_LONG 64
#else
# define __BITS_PER_LONG 32
#endif

#include <asm-generic/bitsperlong.h>

#endif /* __ASM_X86_BITSPERLONG_H */

6 changes: 0 additions & 6 deletions arch/x86/include/asm/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ typedef unsigned short umode_t;
*/
#ifdef __KERNEL__

#ifdef CONFIG_X86_32
# define BITS_PER_LONG 32
#else
# define BITS_PER_LONG 64
#endif

#ifndef __ASSEMBLY__

typedef u64 dma64_addr_t;
Expand Down
1 change: 1 addition & 0 deletions arch/xtensa/include/asm/bitsperlong.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <asm-generic/bitsperlong.h>
1 change: 1 addition & 0 deletions include/asm-generic/Kbuild
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
header-y += bitsperlong.h
header-y += errno-base.h
header-y += errno.h
header-y += fcntl.h
Expand Down
1 change: 1 addition & 0 deletions include/asm-generic/Kbuild.asm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ unifdef-y += a.out.h
endif
unifdef-y += auxvec.h
unifdef-y += byteorder.h
unifdef-y += bitsperlong.h
unifdef-y += errno.h
unifdef-y += fcntl.h
unifdef-y += ioctl.h
Expand Down
32 changes: 32 additions & 0 deletions include/asm-generic/bitsperlong.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#ifndef __ASM_GENERIC_BITS_PER_LONG
#define __ASM_GENERIC_BITS_PER_LONG

/*
* There seems to be no way of detecting this automatically from user
* space, so 64 bit architectures should override this in their
* bitsperlong.h. In particular, an architecture that supports
* both 32 and 64 bit user space must not rely on CONFIG_64BIT
* to decide it, but rather check a compiler provided macro.
*/
#ifndef __BITS_PER_LONG
#define __BITS_PER_LONG 32
#endif

#ifdef __KERNEL__

#ifdef CONFIG_64BIT
#define BITS_PER_LONG 64
#else
#define BITS_PER_LONG 32
#endif /* CONFIG_64BIT */

/*
* FIXME: The check currently breaks x86-64 build, so it's
* temporarily disabled. Please fix x86-64 and reenable
*/
#if 0 && BITS_PER_LONG != __BITS_PER_LONG
#error Inconsistent word size. Check asm/bitsperlong.h
#endif

#endif /* __KERNEL__ */
#endif /* __ASM_GENERIC_BITS_PER_LONG */
2 changes: 2 additions & 0 deletions include/asm-generic/int-l64.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#ifndef _ASM_GENERIC_INT_L64_H
#define _ASM_GENERIC_INT_L64_H

#include <asm/bitsperlong.h>

#ifndef __ASSEMBLY__
/*
* __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
Expand Down
2 changes: 2 additions & 0 deletions include/asm-generic/int-ll64.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#ifndef _ASM_GENERIC_INT_LL64_H
#define _ASM_GENERIC_INT_LL64_H

#include <asm/bitsperlong.h>

#ifndef __ASSEMBLY__
/*
* __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
Expand Down

0 comments on commit c31ae4b

Please sign in to comment.