ia64/xen-unstable

changeset 5149:321a7af76a9b

bitkeeper revision 1.1551 (4294789ea5Ghsn6s5aIMFHK5LY4uSw)

Add 64-bit (cmpxchg8b) support to the cmpxchg() macro for x86_32.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Wed May 25 13:07:42 2005 +0000 (2005-05-25)
parents 561f71aa056d
children 0c7bde5b8e83
files xen/include/asm-x86/system.h
line diff
     1.1 --- a/xen/include/asm-x86/system.h	Wed May 25 12:44:27 2005 +0000
     1.2 +++ b/xen/include/asm-x86/system.h	Wed May 25 13:07:42 2005 +0000
     1.3 @@ -2,6 +2,7 @@
     1.4  #define __ASM_SYSTEM_H
     1.5  
     1.6  #include <xen/config.h>
     1.7 +#include <xen/types.h>
     1.8  #include <asm/bitops.h>
     1.9  
    1.10  /* Clear and set 'TS' bit respectively */
    1.11 @@ -70,8 +71,8 @@ static always_inline unsigned long __xch
    1.12   * indicated by comparing RETURN with OLD.
    1.13   */
    1.14  
    1.15 -static always_inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
    1.16 -				      unsigned long new, int size)
    1.17 +static always_inline unsigned long __cmpxchg(
    1.18 +    volatile void *ptr, unsigned long old, unsigned long new, int size)
    1.19  {
    1.20  	unsigned long prev;
    1.21  	switch (size) {
    1.22 @@ -113,9 +114,49 @@ static always_inline unsigned long __cmp
    1.23  }
    1.24  
    1.25  #define __HAVE_ARCH_CMPXCHG
    1.26 -#define cmpxchg(ptr,o,n)\
    1.27 -	((__typeof__(*(ptr)))__cmpxchg((ptr),(unsigned long)(o),\
    1.28 -					(unsigned long)(n),sizeof(*(ptr))))
    1.29 +
    1.30 +#if BITS_PER_LONG == 64
    1.31 +
    1.32 +#define cmpxchg(ptr,o,n)                                                \
    1.33 +    ((__typeof__(*(ptr)))__cmpxchg((ptr),(unsigned long)(o),            \
    1.34 +                                   (unsigned long)(n),sizeof(*(ptr))))
    1.35 +#else
    1.36 +
    1.37 +static always_inline unsigned long long __cmpxchg8b(
    1.38 +    volatile void *ptr, unsigned long long old, unsigned long long new)
    1.39 +{
    1.40 +    unsigned long long prev;
    1.41 +    __asm__ __volatile__ (
    1.42 +        LOCK_PREFIX "cmpxchg8b %3"
    1.43 +        : "=A" (prev)
    1.44 +        : "c" ((u32)(new>>32)), "b" ((u32)new),
    1.45 +          "m" (*__xg((volatile void *)ptr)), "0" (old)
    1.46 +        : "memory" );
    1.47 +    return prev;
    1.48 +}
    1.49 +
    1.50 +#define cmpxchg(ptr,o,n)                                \
    1.51 +({                                                      \
    1.52 +    __typeof__(*(ptr)) __prev;                          \
    1.53 +    switch ( sizeof(*(ptr)) ) {                         \
    1.54 +    case 8:                                             \
    1.55 +        __prev = ((__typeof__(*(ptr)))__cmpxchg8b(      \
    1.56 +            (ptr),                                      \
    1.57 +            (unsigned long long)(o),                    \
    1.58 +            (unsigned long long)(n)));                  \
    1.59 +        break;                                          \
    1.60 +    default:                                            \
    1.61 +        __prev = ((__typeof__(*(ptr)))__cmpxchg(        \
    1.62 +            (ptr),                                      \
    1.63 +            (unsigned long)(o),                         \
    1.64 +            (unsigned long)(n),                         \
    1.65 +            sizeof(*(ptr))));                           \
    1.66 +        break;                                          \
    1.67 +    }                                                   \
    1.68 +    __prev;                                             \
    1.69 +})
    1.70 +
    1.71 +#endif
    1.72  
    1.73  
    1.74  /*