Path: blob/master/arch/tile/include/asm/bitops_32.h
10818 views
/*1* Copyright 2010 Tilera Corporation. All Rights Reserved.2*3* This program is free software; you can redistribute it and/or4* modify it under the terms of the GNU General Public License5* as published by the Free Software Foundation, version 2.6*7* This program is distributed in the hope that it will be useful, but8* WITHOUT ANY WARRANTY; without even the implied warranty of9* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or10* NON INFRINGEMENT. See the GNU General Public License for11* more details.12*/1314#ifndef _ASM_TILE_BITOPS_32_H15#define _ASM_TILE_BITOPS_32_H1617#include <linux/compiler.h>18#include <asm/atomic.h>19#include <asm/system.h>2021/* Tile-specific routines to support <asm/bitops.h>. */22unsigned long _atomic_or(volatile unsigned long *p, unsigned long mask);23unsigned long _atomic_andn(volatile unsigned long *p, unsigned long mask);24unsigned long _atomic_xor(volatile unsigned long *p, unsigned long mask);2526/**27* set_bit - Atomically set a bit in memory28* @nr: the bit to set29* @addr: the address to start counting from30*31* This function is atomic and may not be reordered.32* See __set_bit() if you do not require the atomic guarantees.33* Note that @nr may be almost arbitrarily large; this function is not34* restricted to acting on a single-word quantity.35*/36static inline void set_bit(unsigned nr, volatile unsigned long *addr)37{38_atomic_or(addr + BIT_WORD(nr), BIT_MASK(nr));39}4041/**42* clear_bit - Clears a bit in memory43* @nr: Bit to clear44* @addr: Address to start counting from45*46* clear_bit() is atomic and may not be reordered.47* See __clear_bit() if you do not require the atomic guarantees.48* Note that @nr may be almost arbitrarily large; this function is not49* restricted to acting on a single-word quantity.50*51* clear_bit() may not contain a memory barrier, so if it is used for52* locking purposes, you should call smp_mb__before_clear_bit() and/or53* smp_mb__after_clear_bit() to ensure changes are visible on other cpus.54*/55static inline void clear_bit(unsigned nr, volatile unsigned long *addr)56{57_atomic_andn(addr + BIT_WORD(nr), BIT_MASK(nr));58}5960/**61* change_bit - Toggle a bit in memory62* @nr: Bit to change63* @addr: Address to start counting from64*65* change_bit() is atomic and may not be reordered.66* See __change_bit() if you do not require the atomic guarantees.67* Note that @nr may be almost arbitrarily large; this function is not68* restricted to acting on a single-word quantity.69*/70static inline void change_bit(unsigned nr, volatile unsigned long *addr)71{72_atomic_xor(addr + BIT_WORD(nr), BIT_MASK(nr));73}7475/**76* test_and_set_bit - Set a bit and return its old value77* @nr: Bit to set78* @addr: Address to count from79*80* This operation is atomic and cannot be reordered.81* It also implies a memory barrier.82*/83static inline int test_and_set_bit(unsigned nr, volatile unsigned long *addr)84{85unsigned long mask = BIT_MASK(nr);86addr += BIT_WORD(nr);87smp_mb(); /* barrier for proper semantics */88return (_atomic_or(addr, mask) & mask) != 0;89}9091/**92* test_and_clear_bit - Clear a bit and return its old value93* @nr: Bit to clear94* @addr: Address to count from95*96* This operation is atomic and cannot be reordered.97* It also implies a memory barrier.98*/99static inline int test_and_clear_bit(unsigned nr, volatile unsigned long *addr)100{101unsigned long mask = BIT_MASK(nr);102addr += BIT_WORD(nr);103smp_mb(); /* barrier for proper semantics */104return (_atomic_andn(addr, mask) & mask) != 0;105}106107/**108* test_and_change_bit - Change a bit and return its old value109* @nr: Bit to change110* @addr: Address to count from111*112* This operation is atomic and cannot be reordered.113* It also implies a memory barrier.114*/115static inline int test_and_change_bit(unsigned nr,116volatile unsigned long *addr)117{118unsigned long mask = BIT_MASK(nr);119addr += BIT_WORD(nr);120smp_mb(); /* barrier for proper semantics */121return (_atomic_xor(addr, mask) & mask) != 0;122}123124/* See discussion at smp_mb__before_atomic_dec() in <asm/atomic_32.h>. */125#define smp_mb__before_clear_bit() smp_mb()126#define smp_mb__after_clear_bit() do {} while (0)127128#include <asm-generic/bitops/ext2-atomic.h>129130#endif /* _ASM_TILE_BITOPS_32_H */131132133