1f15cbe6fSPaul Mundt #ifndef __ASM_SH_CMPXCHG_IRQ_H 2f15cbe6fSPaul Mundt #define __ASM_SH_CMPXCHG_IRQ_H 3f15cbe6fSPaul Mundt 4e839ca52SDavid Howells #include <linux/irqflags.h> 5e839ca52SDavid Howells 6f15cbe6fSPaul Mundt static inline unsigned long xchg_u32(volatile u32 *m, unsigned long val) 7f15cbe6fSPaul Mundt { 8f15cbe6fSPaul Mundt unsigned long flags, retval; 9f15cbe6fSPaul Mundt 10f15cbe6fSPaul Mundt local_irq_save(flags); 11f15cbe6fSPaul Mundt retval = *m; 12f15cbe6fSPaul Mundt *m = val; 13f15cbe6fSPaul Mundt local_irq_restore(flags); 14f15cbe6fSPaul Mundt return retval; 15f15cbe6fSPaul Mundt } 16f15cbe6fSPaul Mundt 173226aad8SMichael S. Tsirkin static inline unsigned long xchg_u16(volatile u16 *m, unsigned long val) 183226aad8SMichael S. Tsirkin { 193226aad8SMichael S. Tsirkin unsigned long flags, retval; 203226aad8SMichael S. Tsirkin 213226aad8SMichael S. Tsirkin local_irq_save(flags); 223226aad8SMichael S. Tsirkin retval = *m; 233226aad8SMichael S. Tsirkin *m = val; 243226aad8SMichael S. Tsirkin local_irq_restore(flags); 253226aad8SMichael S. Tsirkin return retval; 263226aad8SMichael S. Tsirkin } 273226aad8SMichael S. Tsirkin 28f15cbe6fSPaul Mundt static inline unsigned long xchg_u8(volatile u8 *m, unsigned long val) 29f15cbe6fSPaul Mundt { 30f15cbe6fSPaul Mundt unsigned long flags, retval; 31f15cbe6fSPaul Mundt 32f15cbe6fSPaul Mundt local_irq_save(flags); 33f15cbe6fSPaul Mundt retval = *m; 34f15cbe6fSPaul Mundt *m = val & 0xff; 35f15cbe6fSPaul Mundt local_irq_restore(flags); 36f15cbe6fSPaul Mundt return retval; 37f15cbe6fSPaul Mundt } 38f15cbe6fSPaul Mundt 39f15cbe6fSPaul Mundt static inline unsigned long __cmpxchg_u32(volatile int *m, unsigned long old, 40f15cbe6fSPaul Mundt unsigned long new) 41f15cbe6fSPaul Mundt { 42f15cbe6fSPaul Mundt __u32 retval; 43f15cbe6fSPaul Mundt unsigned long flags; 44f15cbe6fSPaul Mundt 45f15cbe6fSPaul Mundt local_irq_save(flags); 46f15cbe6fSPaul Mundt retval = *m; 47f15cbe6fSPaul Mundt if (retval == old) 48f15cbe6fSPaul Mundt *m = new; 49f15cbe6fSPaul Mundt local_irq_restore(flags); /* implies memory barrier */ 50f15cbe6fSPaul Mundt return retval; 51f15cbe6fSPaul Mundt } 52f15cbe6fSPaul Mundt 53f15cbe6fSPaul Mundt #endif /* __ASM_SH_CMPXCHG_IRQ_H */ 54