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 17f15cbe6fSPaul Mundt static inline unsigned long xchg_u8(volatile u8 *m, unsigned long val) 18f15cbe6fSPaul Mundt { 19f15cbe6fSPaul Mundt unsigned long flags, retval; 20f15cbe6fSPaul Mundt 21f15cbe6fSPaul Mundt local_irq_save(flags); 22f15cbe6fSPaul Mundt retval = *m; 23f15cbe6fSPaul Mundt *m = val & 0xff; 24f15cbe6fSPaul Mundt local_irq_restore(flags); 25f15cbe6fSPaul Mundt return retval; 26f15cbe6fSPaul Mundt } 27f15cbe6fSPaul Mundt 28f15cbe6fSPaul Mundt static inline unsigned long __cmpxchg_u32(volatile int *m, unsigned long old, 29f15cbe6fSPaul Mundt unsigned long new) 30f15cbe6fSPaul Mundt { 31f15cbe6fSPaul Mundt __u32 retval; 32f15cbe6fSPaul Mundt unsigned long flags; 33f15cbe6fSPaul Mundt 34f15cbe6fSPaul Mundt local_irq_save(flags); 35f15cbe6fSPaul Mundt retval = *m; 36f15cbe6fSPaul Mundt if (retval == old) 37f15cbe6fSPaul Mundt *m = new; 38f15cbe6fSPaul Mundt local_irq_restore(flags); /* implies memory barrier */ 39f15cbe6fSPaul Mundt return retval; 40f15cbe6fSPaul Mundt } 41f15cbe6fSPaul Mundt 42f15cbe6fSPaul Mundt #endif /* __ASM_SH_CMPXCHG_IRQ_H */ 43