1#ifndef _ASM_GENERIC_BITOPS_NON_ATOMIC_H_
2#define _ASM_GENERIC_BITOPS_NON_ATOMIC_H_
3
4#include <asm/types.h>
5
6/**
7 * __set_bit - Set a bit in memory
8 * @nr: the bit to set
9 * @addr: the address to start counting from
10 *
11 * Unlike set_bit(), this function is non-atomic and may be reordered.
12 * If it's called on the same region of memory simultaneously, the effect
13 * may be that only one operation succeeds.
14 */
15static inline void __set_bit(int nr, volatile unsigned long *addr)
16{
17	unsigned long mask = BIT_MASK(nr);
18	unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
19
20	*p  |= mask;
21}
22
23#define PLATFORM__SET_BIT
24
25static inline void __clear_bit(int nr, volatile unsigned long *addr)
26{
27	unsigned long mask = BIT_MASK(nr);
28	unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
29
30	*p &= ~mask;
31}
32
33#define PLATFORM__CLEAR_BIT
34
35/**
36 * __change_bit - Toggle a bit in memory
37 * @nr: the bit to change
38 * @addr: the address to start counting from
39 *
40 * Unlike change_bit(), this function is non-atomic and may be reordered.
41 * If it's called on the same region of memory simultaneously, the effect
42 * may be that only one operation succeeds.
43 */
44static inline void __change_bit(int nr, volatile unsigned long *addr)
45{
46	unsigned long mask = BIT_MASK(nr);
47	unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
48
49	*p ^= mask;
50}
51
52/**
53 * __test_and_set_bit - Set a bit and return its old value
54 * @nr: Bit to set
55 * @addr: Address to count from
56 *
57 * This operation is non-atomic and can be reordered.
58 * If two examples of this operation race, one can appear to succeed
59 * but actually fail.  You must protect multiple accesses with a lock.
60 */
61static inline int __test_and_set_bit(int nr, volatile unsigned long *addr)
62{
63	unsigned long mask = BIT_MASK(nr);
64	unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
65	unsigned long old = *p;
66
67	*p = old | mask;
68	return (old & mask) != 0;
69}
70
71/**
72 * __test_and_clear_bit - Clear a bit and return its old value
73 * @nr: Bit to clear
74 * @addr: Address to count from
75 *
76 * This operation is non-atomic and can be reordered.
77 * If two examples of this operation race, one can appear to succeed
78 * but actually fail.  You must protect multiple accesses with a lock.
79 */
80static inline int __test_and_clear_bit(int nr, volatile unsigned long *addr)
81{
82	unsigned long mask = BIT_MASK(nr);
83	unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
84	unsigned long old = *p;
85
86	*p = old & ~mask;
87	return (old & mask) != 0;
88}
89
90/* WARNING: non atomic and it can be reordered! */
91static inline int __test_and_change_bit(int nr,
92					    volatile unsigned long *addr)
93{
94	unsigned long mask = BIT_MASK(nr);
95	unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
96	unsigned long old = *p;
97
98	*p = old ^ mask;
99	return (old & mask) != 0;
100}
101
102/**
103 * test_bit - Determine whether a bit is set
104 * @nr: bit number to test
105 * @addr: Address to start counting from
106 */
107static inline int test_bit(int nr, const volatile unsigned long *addr)
108{
109	return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1)));
110}
111
112#endif /* _ASM_GENERIC_BITOPS_NON_ATOMIC_H_ */
113