Link: https://lore.kernel.org/r/20260217200002.683975158@linuxfoundation.org Tested-by: Florian Fainelli <florian.fainelli@broadcom.com> Tested-by: Takeshi Ogasawara <takeshi.ogasawara@futuring-girl.com> Tested-by: Peter Schneider <pschneider1968@googlemail.com> Tested-by: Jon Hunter <jonathanh@nvidia.com> Tested-by: Salvatore Bonaccorso <carnil@debian.org> Tested-by: Brett A C Sheffield <bacs@librecast.net> Tested-by: Mark Brown <broonie@kernel.org> Tested-by: Luna Jernberg <droidbittin@gmail.com> Tested-by: Ronald Warsow <rwarsow@gmx.de> Tested-by: Justin M. Forbes <jforbes@fedoraproject.org> Tested-by: Ron Economos <re@w6rz.net> Tested-by: Miguel Ojeda <ojeda@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
95 lines
1.7 KiB
C
95 lines
1.7 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef __ASM_SH_BITOPS_CAS_H
|
|
#define __ASM_SH_BITOPS_CAS_H
|
|
|
|
static inline unsigned __bo_cas(volatile unsigned *p, unsigned old, unsigned new)
|
|
{
|
|
__asm__ __volatile__("cas.l %1,%0,@r0"
|
|
: "+r"(new)
|
|
: "r"(old), "z"(p)
|
|
: "t", "memory" );
|
|
return new;
|
|
}
|
|
|
|
static inline void set_bit(int nr, volatile void *addr)
|
|
{
|
|
unsigned mask, old;
|
|
volatile unsigned *a = addr;
|
|
|
|
a += nr >> 5;
|
|
mask = 1U << (nr & 0x1f);
|
|
|
|
do old = *a;
|
|
while (__bo_cas(a, old, old|mask) != old);
|
|
}
|
|
|
|
static inline void clear_bit(int nr, volatile void *addr)
|
|
{
|
|
unsigned mask, old;
|
|
volatile unsigned *a = addr;
|
|
|
|
a += nr >> 5;
|
|
mask = 1U << (nr & 0x1f);
|
|
|
|
do old = *a;
|
|
while (__bo_cas(a, old, old&~mask) != old);
|
|
}
|
|
|
|
static inline void change_bit(int nr, volatile void *addr)
|
|
{
|
|
unsigned mask, old;
|
|
volatile unsigned *a = addr;
|
|
|
|
a += nr >> 5;
|
|
mask = 1U << (nr & 0x1f);
|
|
|
|
do old = *a;
|
|
while (__bo_cas(a, old, old^mask) != old);
|
|
}
|
|
|
|
static inline int test_and_set_bit(int nr, volatile void *addr)
|
|
{
|
|
unsigned mask, old;
|
|
volatile unsigned *a = addr;
|
|
|
|
a += nr >> 5;
|
|
mask = 1U << (nr & 0x1f);
|
|
|
|
do old = *a;
|
|
while (__bo_cas(a, old, old|mask) != old);
|
|
|
|
return !!(old & mask);
|
|
}
|
|
|
|
static inline int test_and_clear_bit(int nr, volatile void *addr)
|
|
{
|
|
unsigned mask, old;
|
|
volatile unsigned *a = addr;
|
|
|
|
a += nr >> 5;
|
|
mask = 1U << (nr & 0x1f);
|
|
|
|
do old = *a;
|
|
while (__bo_cas(a, old, old&~mask) != old);
|
|
|
|
return !!(old & mask);
|
|
}
|
|
|
|
static inline int test_and_change_bit(int nr, volatile void *addr)
|
|
{
|
|
unsigned mask, old;
|
|
volatile unsigned *a = addr;
|
|
|
|
a += nr >> 5;
|
|
mask = 1U << (nr & 0x1f);
|
|
|
|
do old = *a;
|
|
while (__bo_cas(a, old, old^mask) != old);
|
|
|
|
return !!(old & mask);
|
|
}
|
|
|
|
#include <asm-generic/bitops/non-atomic.h>
|
|
|
|
#endif /* __ASM_SH_BITOPS_CAS_H */
|