#include <linux/types.h>
 #include <linux/irqflags.h>
 
-#ifndef xchg
-
 /*
  * This function doesn't exist, so you'll get a linker error if
  * something tries to do an invalidly-sized xchg().
  */
-extern void __xchg_called_with_bad_pointer(void);
+extern void __generic_xchg_called_with_bad_pointer(void);
 
 static inline
-unsigned long __xchg(unsigned long x, volatile void *ptr, int size)
+unsigned long __generic_xchg(unsigned long x, volatile void *ptr, int size)
 {
        unsigned long ret, flags;
 
 #endif /* CONFIG_64BIT */
 
        default:
-               __xchg_called_with_bad_pointer();
+               __generic_xchg_called_with_bad_pointer();
                return x;
        }
 }
 
-#define xchg(ptr, x) ({                                                        \
-       ((__typeof__(*(ptr)))                                           \
-               __xchg((unsigned long)(x), (ptr), sizeof(*(ptr))));     \
+#define generic_xchg(ptr, x) ({                                                        \
+       ((__typeof__(*(ptr)))                                                   \
+               __generic_xchg((unsigned long)(x), (ptr), sizeof(*(ptr))));     \
 })
 
-#endif /* xchg */
-
 /*
  * Atomic compare and exchange.
  */
 #include <asm-generic/cmpxchg-local.h>
 
-#ifndef cmpxchg_local
-#define cmpxchg_local(ptr, o, n) ({                                           \
-       ((__typeof__(*(ptr)))__generic_cmpxchg_local((ptr), (unsigned long)(o),\
-                       (unsigned long)(n), sizeof(*(ptr))));                  \
+#define generic_cmpxchg_local(ptr, o, n) ({                                    \
+       ((__typeof__(*(ptr)))__generic_cmpxchg_local((ptr), (unsigned long)(o), \
+                       (unsigned long)(n), sizeof(*(ptr))));                   \
 })
+
+#define generic_cmpxchg64_local(ptr, o, n) \
+       __generic_cmpxchg64_local((ptr), (o), (n))
+
+
+#ifdef CONFIG_ARCH_ATOMIC
+
+#ifndef arch_xchg
+#define arch_xchg              generic_xchg
+#endif
+
+#ifndef arch_cmpxchg_local
+#define arch_cmpxchg_local     generic_cmpxchg_local
+#endif
+
+#ifndef arch_cmpxchg64_local
+#define arch_cmpxchg64_local   generic_cmpxchg64_local
+#endif
+
+#define arch_cmpxchg           arch_cmpxchg_local
+#define arch_cmpxchg64         arch_cmpxchg64_local
+
+#else /* CONFIG_ARCH_ATOMIC */
+
+#ifndef xchg
+#define xchg                   generic_xchg
+#endif
+
+#ifndef cmpxchg_local
+#define cmpxchg_local          generic_cmpxchg_local
 #endif
 
 #ifndef cmpxchg64_local
-#define cmpxchg64_local(ptr, o, n) __generic_cmpxchg64_local((ptr), (o), (n))
+#define cmpxchg64_local                generic_cmpxchg64_local
 #endif
 
-#define cmpxchg(ptr, o, n)     cmpxchg_local((ptr), (o), (n))
-#define cmpxchg64(ptr, o, n)   cmpxchg64_local((ptr), (o), (n))
+#define cmpxchg                        cmpxchg_local
+#define cmpxchg64              cmpxchg64_local
+
+#endif /* CONFIG_ARCH_ATOMIC */
 
 #endif /* __ASM_GENERIC_CMPXCHG_H */