]>
Commit | Line | Data |
---|---|---|
a2c9dbe8 HC |
1 | /* |
2 | * Copyright IBM Corp. 1999, 2011 | |
3 | * | |
4 | * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>, | |
5 | */ | |
6 | ||
7 | #ifndef __ASM_CMPXCHG_H | |
8 | #define __ASM_CMPXCHG_H | |
9 | ||
b1d6b40c | 10 | #include <linux/mmdebug.h> |
a2c9dbe8 | 11 | #include <linux/types.h> |
b1d6b40c | 12 | #include <linux/bug.h> |
a2c9dbe8 | 13 | |
f318a122 MS |
14 | #define cmpxchg(ptr, o, n) \ |
15 | ({ \ | |
16 | __typeof__(*(ptr)) __o = (o); \ | |
17 | __typeof__(*(ptr)) __n = (n); \ | |
18 | (__typeof__(*(ptr))) __sync_val_compare_and_swap((ptr),__o,__n);\ | |
a2c9dbe8 HC |
19 | }) |
20 | ||
f318a122 MS |
21 | #define cmpxchg64 cmpxchg |
22 | #define cmpxchg_local cmpxchg | |
23 | #define cmpxchg64_local cmpxchg | |
a2c9dbe8 | 24 | |
f318a122 | 25 | #define xchg(ptr, x) \ |
54eaae30 | 26 | ({ \ |
f318a122 MS |
27 | __typeof__(ptr) __ptr = (ptr); \ |
28 | __typeof__(*(ptr)) __old; \ | |
29 | do { \ | |
30 | __old = *__ptr; \ | |
31 | } while (!__sync_bool_compare_and_swap(__ptr, __old, x)); \ | |
32 | __old; \ | |
54eaae30 | 33 | }) |
54eaae30 | 34 | |
e4165dcb | 35 | #define __cmpxchg_double(p1, p2, o1, o2, n1, n2) \ |
b1d6b40c HC |
36 | ({ \ |
37 | register __typeof__(*(p1)) __old1 asm("2") = (o1); \ | |
38 | register __typeof__(*(p2)) __old2 asm("3") = (o2); \ | |
39 | register __typeof__(*(p1)) __new1 asm("4") = (n1); \ | |
40 | register __typeof__(*(p2)) __new2 asm("5") = (n2); \ | |
41 | int cc; \ | |
42 | asm volatile( \ | |
e4165dcb | 43 | " cdsg %[old],%[new],%[ptr]\n" \ |
b1d6b40c HC |
44 | " ipm %[cc]\n" \ |
45 | " srl %[cc],28" \ | |
46 | : [cc] "=d" (cc), [old] "+d" (__old1), "+d" (__old2) \ | |
47 | : [new] "d" (__new1), "d" (__new2), \ | |
48 | [ptr] "Q" (*(p1)), "Q" (*(p2)) \ | |
49 | : "memory", "cc"); \ | |
50 | !cc; \ | |
51 | }) | |
52 | ||
b1d6b40c HC |
53 | #define cmpxchg_double(p1, p2, o1, o2, n1, n2) \ |
54 | ({ \ | |
55 | __typeof__(p1) __p1 = (p1); \ | |
56 | __typeof__(p2) __p2 = (p2); \ | |
b1d6b40c HC |
57 | BUILD_BUG_ON(sizeof(*(p1)) != sizeof(long)); \ |
58 | BUILD_BUG_ON(sizeof(*(p2)) != sizeof(long)); \ | |
59 | VM_BUG_ON((unsigned long)((__p1) + 1) != (unsigned long)(__p2));\ | |
e4165dcb | 60 | __cmpxchg_double(__p1, __p2, o1, o2, n1, n2); \ |
b1d6b40c HC |
61 | }) |
62 | ||
63 | #define system_has_cmpxchg_double() 1 | |
64 | ||
a2c9dbe8 | 65 | #endif /* __ASM_CMPXCHG_H */ |