base/include/asm-arm/rtai_atomic.h

Go to the documentation of this file.
00001 /* 00002 * Atomic operations. 00003 * 00004 * Original RTAI/x86 layer implementation: 00005 * Copyright (c) 2000 Paolo Mantegazza (mantegazza@aero.polimi.it) 00006 * Copyright (c) 2000 Steve Papacharalambous (stevep@zentropix.com) 00007 * Copyright (c) 2000 Stuart Hughes 00008 * and others. 00009 * 00010 * RTAI/x86 rewrite over Adeos: 00011 * Copyright (c) 2002 Philippe Gerum (rpm@xenomai.org) 00012 * 00013 * Original RTAI/ARM RTHAL implementation: 00014 * Copyright (c) 2000 Pierre Cloutier (pcloutier@poseidoncontrols.com) 00015 * Copyright (c) 2001 Alex Züpke, SYSGO RTS GmbH (azu@sysgo.de) 00016 * Copyright (c) 2002 Guennadi Liakhovetski DSA GmbH (gl@dsa-ac.de) 00017 * Copyright (c) 2002 Steve Papacharalambous (stevep@zentropix.com) 00018 * Copyright (c) 2002 Wolfgang Müller (wolfgang.mueller@dsa-ac.de) 00019 * Copyright (c) 2003 Bernard Haible, Marconi Communications 00020 * Copyright (c) 2003 Thomas Gleixner (tglx@linutronix.de) 00021 * Copyright (c) 2003 Philippe Gerum (rpm@xenomai.org) 00022 * 00023 * RTAI/ARM over Adeos rewrite: 00024 * Copyright (c) 2004-2005 Michael Neuhauser, Firmix Software GmbH (mike@firmix.at) 00025 * 00026 * RTAI/ARM over Adeos rewrite for PXA255_2.6.7: 00027 * Copyright (c) 2005 Stefano Gafforelli (stefano.gafforelli@tiscali.it) 00028 * Copyright (c) 2005 Luca Pizzi (lucapizzi@hotmail.com) 00029 * 00030 * This program is free software; you can redistribute it and/or modify it under 00031 * the terms of the GNU General Public License as published by the Free Software 00032 * Foundation, Inc., 675 Mass Ave, Cambridge MA 02139, USA; either version 2 of 00033 * the License, or (at your option) any later version. 00034 * 00035 * This program is distributed in the hope that it will be useful, but WITHOUT 00036 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00037 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 00038 * details. 00039 * 00040 * You should have received a copy of the GNU General Public License along with 00041 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00042 * Place - Suite 330, Boston, MA 02111-1307, USA. 00043 */ 00044 #ifndef _RTAI_ASM_ARM_ATOMIC_H 00045 #define _RTAI_ASM_ARM_ATOMIC_H 00046 00047 #include <linux/version.h> 00048 #include <linux/bitops.h> 00049 #include <asm/atomic.h> 00050 #include <rtai_config.h> 00051 #include <asm/rtai_hal.h> 00052 00053 #ifdef __KERNEL__ 00054 00055 #include <asm/system.h> 00056 00057 #define atomic_xchg(ptr,v) xchg(ptr,v) 00058 00059 /* Poor man's cmpxchg(). */ 00060 #define atomic_cmpxchg(p, o, n) ({ \ 00061 typeof(*(p)) __o = (o); \ 00062 typeof(*(p)) __n = (n); \ 00063 typeof(*(p)) __prev; \ 00064 unsigned long flags; \ 00065 rtai_hw_lock(flags); \ 00066 __prev = *(p); \ 00067 if (__prev == __o) \ 00068 *(p) = __n; \ 00069 rtai_hw_unlock(flags); \ 00070 __prev; }) 00071 00072 #else /* !__KERNEL__ */ 00073 00074 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) 00075 #include <asm/proc/system.h> 00076 #else 00077 #include <asm/system.h> 00078 #endif 00079 00080 static inline unsigned long 00081 atomic_xchg(volatile void *ptr, unsigned long x) 00082 { 00083 asm volatile( 00084 "swp %0, %1, [%2]" 00085 : "=&r" (x) 00086 : "r" (x), "r" (ptr) 00087 : "memory" 00088 ); 00089 return x; 00090 } 00091 00092 static inline unsigned long 00093 atomic_cmpxchg(volatile void *ptr, unsigned long o, unsigned long n) 00094 { 00095 unsigned long prev; 00096 unsigned long flags; 00097 adeos_hw_local_irq_save(flags); 00098 prev = *(unsigned long*)ptr; 00099 if (prev == o) 00100 *(unsigned long*)ptr = n; 00101 adeos_hw_local_irq_restore(flags); 00102 return prev; 00103 } 00104 00105 #endif /* __KERNEL__ */ 00106 #endif /* !_RTAI_ASM_ARM_ATOMIC_H */

Generated on Thu Nov 20 11:49:48 2008 for RTAI API by doxygen 1.3.8