1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __ASM_SH_BITOPS_CAS_H
3 #define __ASM_SH_BITOPS_CAS_H
5 static inline unsigned __bo_cas(volatile unsigned *p, unsigned old, unsigned new)
7 __asm__ __volatile__("cas.l %1,%0,@r0"
14 static inline void set_bit(int nr, volatile void *addr)
17 volatile unsigned *a = addr;
20 mask = 1U << (nr & 0x1f);
23 while (__bo_cas(a, old, old|mask) != old);
26 static inline void clear_bit(int nr, volatile void *addr)
29 volatile unsigned *a = addr;
32 mask = 1U << (nr & 0x1f);
35 while (__bo_cas(a, old, old&~mask) != old);
38 static inline void change_bit(int nr, volatile void *addr)
41 volatile unsigned *a = addr;
44 mask = 1U << (nr & 0x1f);
47 while (__bo_cas(a, old, old^mask) != old);
50 static inline int test_and_set_bit(int nr, volatile void *addr)
53 volatile unsigned *a = addr;
56 mask = 1U << (nr & 0x1f);
59 while (__bo_cas(a, old, old|mask) != old);
61 return !!(old & mask);
64 static inline int test_and_clear_bit(int nr, volatile void *addr)
67 volatile unsigned *a = addr;
70 mask = 1U << (nr & 0x1f);
73 while (__bo_cas(a, old, old&~mask) != old);
75 return !!(old & mask);
78 static inline int test_and_change_bit(int nr, volatile void *addr)
81 volatile unsigned *a = addr;
84 mask = 1U << (nr & 0x1f);
87 while (__bo_cas(a, old, old^mask) != old);
89 return !!(old & mask);
92 #include <asm-generic/bitops/non-atomic.h>
94 #endif /* __ASM_SH_BITOPS_CAS_H */