1 /* Modified by Broadcom Corp. Portions Copyright (c) Broadcom Corp, 2012. */
2 #ifndef __ASM_GENERIC_CMPXCHG_LOCAL_H
3 #define __ASM_GENERIC_CMPXCHG_LOCAL_H
5 #include <linux/types.h>
7 #if defined(CONFIG_BUZZZ_FUNC)
8 #ifndef __always_inline__
9 #define __always_inline__ inline __attribute__((always_inline)) __attribute__((no_instrument_function))
11 #else /* !CONFIG_BUZZZ_FUNC */
12 #ifndef __always_inline__
13 #define __always_inline__ inline
15 #endif /* !CONFIG_BUZZZ_FUNC */
17 extern unsigned long wrong_size_cmpxchg(volatile void *ptr
);
20 * Generic version of __cmpxchg_local (disables interrupts). Takes an unsigned
21 * long parameter, supporting various types of architectures.
23 static __always_inline__
unsigned long __cmpxchg_local_generic(volatile void *ptr
,
24 unsigned long old
, unsigned long new, int size
)
26 unsigned long flags
, prev
;
29 * Sanity checking, compile-time.
31 if (size
== 8 && sizeof(unsigned long) != 8)
32 wrong_size_cmpxchg(ptr
);
34 local_irq_save(flags
);
36 case 1: prev
= *(u8
*)ptr
;
40 case 2: prev
= *(u16
*)ptr
;
42 *(u16
*)ptr
= (u16
)new;
44 case 4: prev
= *(u32
*)ptr
;
46 *(u32
*)ptr
= (u32
)new;
48 case 8: prev
= *(u64
*)ptr
;
50 *(u64
*)ptr
= (u64
)new;
53 wrong_size_cmpxchg(ptr
);
55 local_irq_restore(flags
);
60 * Generic version of __cmpxchg64_local. Takes an u64 parameter.
62 static __always_inline__ u64
__cmpxchg64_local_generic(volatile void *ptr
,
68 local_irq_save(flags
);
72 local_irq_restore(flags
);