diff options
Diffstat (limited to 'include/asm-i386/system.h')
-rw-r--r-- | include/asm-i386/system.h | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/include/asm-i386/system.h b/include/asm-i386/system.h index 098bcee94e38..a6dabbcd6e6a 100644 --- a/include/asm-i386/system.h +++ b/include/asm-i386/system.h | |||
@@ -267,6 +267,9 @@ static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int siz | |||
267 | #define cmpxchg(ptr,o,n)\ | 267 | #define cmpxchg(ptr,o,n)\ |
268 | ((__typeof__(*(ptr)))__cmpxchg((ptr),(unsigned long)(o),\ | 268 | ((__typeof__(*(ptr)))__cmpxchg((ptr),(unsigned long)(o),\ |
269 | (unsigned long)(n),sizeof(*(ptr)))) | 269 | (unsigned long)(n),sizeof(*(ptr)))) |
270 | #define sync_cmpxchg(ptr,o,n)\ | ||
271 | ((__typeof__(*(ptr)))__sync_cmpxchg((ptr),(unsigned long)(o),\ | ||
272 | (unsigned long)(n),sizeof(*(ptr)))) | ||
270 | #endif | 273 | #endif |
271 | 274 | ||
272 | static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old, | 275 | static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old, |
@@ -296,6 +299,39 @@ static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old, | |||
296 | return old; | 299 | return old; |
297 | } | 300 | } |
298 | 301 | ||
302 | /* | ||
303 | * Always use locked operations when touching memory shared with a | ||
304 | * hypervisor, since the system may be SMP even if the guest kernel | ||
305 | * isn't. | ||
306 | */ | ||
307 | static inline unsigned long __sync_cmpxchg(volatile void *ptr, | ||
308 | unsigned long old, | ||
309 | unsigned long new, int size) | ||
310 | { | ||
311 | unsigned long prev; | ||
312 | switch (size) { | ||
313 | case 1: | ||
314 | __asm__ __volatile__("lock; cmpxchgb %b1,%2" | ||
315 | : "=a"(prev) | ||
316 | : "q"(new), "m"(*__xg(ptr)), "0"(old) | ||
317 | : "memory"); | ||
318 | return prev; | ||
319 | case 2: | ||
320 | __asm__ __volatile__("lock; cmpxchgw %w1,%2" | ||
321 | : "=a"(prev) | ||
322 | : "r"(new), "m"(*__xg(ptr)), "0"(old) | ||
323 | : "memory"); | ||
324 | return prev; | ||
325 | case 4: | ||
326 | __asm__ __volatile__("lock; cmpxchgl %1,%2" | ||
327 | : "=a"(prev) | ||
328 | : "r"(new), "m"(*__xg(ptr)), "0"(old) | ||
329 | : "memory"); | ||
330 | return prev; | ||
331 | } | ||
332 | return old; | ||
333 | } | ||
334 | |||
299 | #ifndef CONFIG_X86_CMPXCHG | 335 | #ifndef CONFIG_X86_CMPXCHG |
300 | /* | 336 | /* |
301 | * Building a kernel capable running on 80386. It may be necessary to | 337 | * Building a kernel capable running on 80386. It may be necessary to |