2 * Generic UP xchg and cmpxchg using interrupt disablement. Does not
6 #ifndef __ASM_GENERIC_CMPXCHG_H
7 #define __ASM_GENERIC_CMPXCHG_H
10 #error "Cannot use generic cmpxchg on SMP"
13 #include <linux/types.h>
14 #include <linux/irqflags.h>
19 * This function doesn't exist, so you'll get a linker error if
20 * something tries to do an invalidly-sized xchg().
22 extern void __xchg_called_with_bad_pointer(void);
25 unsigned long __xchg(unsigned long x
, volatile void *ptr
, int size
)
27 unsigned long ret
, flags
;
32 return __xchg_u8(x
, ptr
);
34 local_irq_save(flags
);
35 ret
= *(volatile u8
*)ptr
;
36 *(volatile u8
*)ptr
= x
;
37 local_irq_restore(flags
);
39 #endif /* __xchg_u8 */
43 return __xchg_u16(x
, ptr
);
45 local_irq_save(flags
);
46 ret
= *(volatile u16
*)ptr
;
47 *(volatile u16
*)ptr
= x
;
48 local_irq_restore(flags
);
50 #endif /* __xchg_u16 */
54 return __xchg_u32(x
, ptr
);
56 local_irq_save(flags
);
57 ret
= *(volatile u32
*)ptr
;
58 *(volatile u32
*)ptr
= x
;
59 local_irq_restore(flags
);
61 #endif /* __xchg_u32 */
66 return __xchg_u64(x
, ptr
);
68 local_irq_save(flags
);
69 ret
= *(volatile u64
*)ptr
;
70 *(volatile u64
*)ptr
= x
;
71 local_irq_restore(flags
);
73 #endif /* __xchg_u64 */
74 #endif /* CONFIG_64BIT */
77 __xchg_called_with_bad_pointer();
82 #define xchg(ptr, x) \
83 ((__typeof__(*(ptr))) __xchg((unsigned long)(x), (ptr), sizeof(*(ptr))))
88 * Atomic compare and exchange.
90 * Do not define __HAVE_ARCH_CMPXCHG because we want to use it to check whether
91 * a cmpxchg primitive faster than repeated local irq save/restore exists.
93 #include <asm-generic/cmpxchg-local.h>
96 #define cmpxchg_local(ptr, o, n) \
97 ((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), (unsigned long)(o),\
98 (unsigned long)(n), sizeof(*(ptr))))
101 #ifndef cmpxchg64_local
102 #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
105 #define cmpxchg(ptr, o, n) cmpxchg_local((ptr), (o), (n))
106 #define cmpxchg64(ptr, o, n) cmpxchg64_local((ptr), (o), (n))
108 #endif /* __ASM_GENERIC_CMPXCHG_H */