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