mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-11-25 14:20:52 +07:00
3226aad81a
This completes the xchg implementation for sh architecture. Note: The llsc variant is tricky since this only supports 4 byte atomics, the existing implementation of 1 byte xchg is wrong: we need to do a 4 byte cmpxchg and retry if any bytes changed meanwhile. Write this in C for clarity. Suggested-by: Rich Felker <dalias@libc.org> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
54 lines
1.0 KiB
C
54 lines
1.0 KiB
C
#ifndef __ASM_SH_CMPXCHG_IRQ_H
|
|
#define __ASM_SH_CMPXCHG_IRQ_H
|
|
|
|
#include <linux/irqflags.h>
|
|
|
|
static inline unsigned long xchg_u32(volatile u32 *m, unsigned long val)
|
|
{
|
|
unsigned long flags, retval;
|
|
|
|
local_irq_save(flags);
|
|
retval = *m;
|
|
*m = val;
|
|
local_irq_restore(flags);
|
|
return retval;
|
|
}
|
|
|
|
static inline unsigned long xchg_u16(volatile u16 *m, unsigned long val)
|
|
{
|
|
unsigned long flags, retval;
|
|
|
|
local_irq_save(flags);
|
|
retval = *m;
|
|
*m = val;
|
|
local_irq_restore(flags);
|
|
return retval;
|
|
}
|
|
|
|
static inline unsigned long xchg_u8(volatile u8 *m, unsigned long val)
|
|
{
|
|
unsigned long flags, retval;
|
|
|
|
local_irq_save(flags);
|
|
retval = *m;
|
|
*m = val & 0xff;
|
|
local_irq_restore(flags);
|
|
return retval;
|
|
}
|
|
|
|
static inline unsigned long __cmpxchg_u32(volatile int *m, unsigned long old,
|
|
unsigned long new)
|
|
{
|
|
__u32 retval;
|
|
unsigned long flags;
|
|
|
|
local_irq_save(flags);
|
|
retval = *m;
|
|
if (retval == old)
|
|
*m = new;
|
|
local_irq_restore(flags); /* implies memory barrier */
|
|
return retval;
|
|
}
|
|
|
|
#endif /* __ASM_SH_CMPXCHG_IRQ_H */
|