/* asm/bitops.h for Linux/CRIS1*2* TODO: asm versions if speed is needed3*4* All bit operations return 0 if the bit was cleared before the5* operation and != 0 if it was not.6*7* bit 0 is the LSB of addr; bit 32 is the LSB of (addr+1).8*/910#ifndef _CRIS_BITOPS_H11#define _CRIS_BITOPS_H1213/* Currently this is unsuitable for consumption outside the kernel. */14#ifdef __KERNEL__1516#ifndef _LINUX_BITOPS_H17#error only <linux/bitops.h> can be included directly18#endif1920#include <arch/bitops.h>21#include <asm/system.h>22#include <asm/atomic.h>23#include <linux/compiler.h>2425/*26* set_bit - Atomically set a bit in memory27* @nr: the bit to set28* @addr: the address to start counting from29*30* This function is atomic and may not be reordered. See __set_bit()31* if you do not require the atomic guarantees.32* Note that @nr may be almost arbitrarily large; this function is not33* restricted to acting on a single-word quantity.34*/3536#define set_bit(nr, addr) (void)test_and_set_bit(nr, addr)3738/*39* clear_bit - Clears a bit in memory40* @nr: Bit to clear41* @addr: Address to start counting from42*43* clear_bit() is atomic and may not be reordered. However, it does44* not contain a memory barrier, so if it is used for locking purposes,45* you should call smp_mb__before_clear_bit() and/or smp_mb__after_clear_bit()46* in order to ensure changes are visible on other processors.47*/4849#define clear_bit(nr, addr) (void)test_and_clear_bit(nr, addr)5051/*52* change_bit - Toggle a bit in memory53* @nr: Bit to change54* @addr: Address to start counting from55*56* change_bit() is atomic and may not be reordered.57* Note that @nr may be almost arbitrarily large; this function is not58* restricted to acting on a single-word quantity.59*/6061#define change_bit(nr, addr) (void)test_and_change_bit(nr, addr)6263/**64* test_and_set_bit - Set a bit and return its old value65* @nr: Bit to set66* @addr: Address to count from67*68* This operation is atomic and cannot be reordered.69* It also implies a memory barrier.70*/7172static inline int test_and_set_bit(int nr, volatile unsigned long *addr)73{74unsigned int mask, retval;75unsigned long flags;76unsigned int *adr = (unsigned int *)addr;7778adr += nr >> 5;79mask = 1 << (nr & 0x1f);80cris_atomic_save(addr, flags);81retval = (mask & *adr) != 0;82*adr |= mask;83cris_atomic_restore(addr, flags);84return retval;85}8687/*88* clear_bit() doesn't provide any barrier for the compiler.89*/90#define smp_mb__before_clear_bit() barrier()91#define smp_mb__after_clear_bit() barrier()9293/**94* test_and_clear_bit - Clear a bit and return its old value95* @nr: Bit to clear96* @addr: Address to count from97*98* This operation is atomic and cannot be reordered.99* It also implies a memory barrier.100*/101102static inline int test_and_clear_bit(int nr, volatile unsigned long *addr)103{104unsigned int mask, retval;105unsigned long flags;106unsigned int *adr = (unsigned int *)addr;107108adr += nr >> 5;109mask = 1 << (nr & 0x1f);110cris_atomic_save(addr, flags);111retval = (mask & *adr) != 0;112*adr &= ~mask;113cris_atomic_restore(addr, flags);114return retval;115}116117/**118* test_and_change_bit - Change a bit and return its old value119* @nr: Bit to change120* @addr: Address to count from121*122* This operation is atomic and cannot be reordered.123* It also implies a memory barrier.124*/125126static inline int test_and_change_bit(int nr, volatile unsigned long *addr)127{128unsigned int mask, retval;129unsigned long flags;130unsigned int *adr = (unsigned int *)addr;131adr += nr >> 5;132mask = 1 << (nr & 0x1f);133cris_atomic_save(addr, flags);134retval = (mask & *adr) != 0;135*adr ^= mask;136cris_atomic_restore(addr, flags);137return retval;138}139140#include <asm-generic/bitops/non-atomic.h>141142/*143* Since we define it "external", it collides with the built-in144* definition, which doesn't have the same semantics. We don't want to145* use -fno-builtin, so just hide the name ffs.146*/147#define ffs kernel_ffs148149#include <asm-generic/bitops/fls.h>150#include <asm-generic/bitops/__fls.h>151#include <asm-generic/bitops/fls64.h>152#include <asm-generic/bitops/hweight.h>153#include <asm-generic/bitops/find.h>154#include <asm-generic/bitops/lock.h>155156#include <asm-generic/bitops/le.h>157158#define ext2_set_bit_atomic(l,n,a) test_and_set_bit(n,a)159#define ext2_clear_bit_atomic(l,n,a) test_and_clear_bit(n,a)160161#include <asm-generic/bitops/sched.h>162163#endif /* __KERNEL__ */164165#endif /* _CRIS_BITOPS_H */166167168