aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-i386/system.h
diff options
context:
space:
mode:
authorChris Wright <chrisw@sous-sol.org>2006-09-26 02:32:23 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2006-09-26 11:48:55 -0400
commit027a8c7e6067a1bcdef6775d1b1c08729dfbae51 (patch)
tree8c791bb8820d6c0734aded634a045369dd3347cc /include/asm-i386/system.h
parent05f4a3ec94281347e05c81eafefcfe5ea545c94c (diff)
[PATCH] x86: implement always-locked bit ops, for memory shared with an SMP hypervisor
Add "always lock'd" implementations of set_bit, clear_bit and change_bit and the corresponding test_and_ functions. Also add "always lock'd" implementation of cmpxchg. These give guaranteed strong synchronisation and are required for non-SMP kernels running on an SMP hypervisor. Signed-off-by: Ian Pratt <ian.pratt@xensource.com> Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk> Signed-off-by: Chris Wright <chrisw@sous-sol.org> Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com> Cc: Christoph Lameter <clameter@sgi.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'include/asm-i386/system.h')
-rw-r--r--include/asm-i386/system.h36
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
272static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old, 275static 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 */
307static 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