2 * Copyright 1995, Russell King.
3 * Various bits and pieces copyrights include:
4 * Linus Torvalds (test_bit).
5 * Big endian support: Copyright 2001, Nicolas Pitre
8 * bit 0 is the LSB of an "unsigned long" quantity.
10 * Please note that the code in this file should never be included
11 * from user space. Many of these are not implemented in assembler
12 * since they would be too costly. Also, they require privileged
13 * instructions (which are not available from user mode) to ensure
14 * that they are atomic.
17 #ifndef __ASM_ARM_BITOPS_H
18 #define __ASM_ARM_BITOPS_H
20 #include <asm/system.h>
22 #define smp_mb__before_clear_bit() mb()
23 #define smp_mb__after_clear_bit() mb()
26 * These functions are the basis of our bit ops.
28 * First, the atomic bitops. These use native endian.
30 static inline void ____atomic_set_bit(unsigned int bit
, volatile unsigned long *p
)
33 unsigned long mask
= 1UL << (bit
& 31);
37 local_irq_save(flags
);
39 local_irq_restore(flags
);
42 static inline void ____atomic_clear_bit(unsigned int bit
, volatile unsigned long *p
)
45 unsigned long mask
= 1UL << (bit
& 31);
49 local_irq_save(flags
);
51 local_irq_restore(flags
);
54 static inline void ____atomic_change_bit(unsigned int bit
, volatile unsigned long *p
)
57 unsigned long mask
= 1UL << (bit
& 31);
61 local_irq_save(flags
);
63 local_irq_restore(flags
);
67 ____atomic_test_and_set_bit(unsigned int bit
, volatile unsigned long *p
)
71 unsigned long mask
= 1UL << (bit
& 31);
75 local_irq_save(flags
);
78 local_irq_restore(flags
);
84 ____atomic_test_and_clear_bit(unsigned int bit
, volatile unsigned long *p
)
88 unsigned long mask
= 1UL << (bit
& 31);
92 local_irq_save(flags
);
95 local_irq_restore(flags
);
101 ____atomic_test_and_change_bit(unsigned int bit
, volatile unsigned long *p
)
105 unsigned long mask
= 1UL << (bit
& 31);
109 local_irq_save(flags
);
112 local_irq_restore(flags
);
117 //#include <asm-generic/bitops/non-atomic.h>
120 * A note about Endian-ness.
121 * -------------------------
123 * When the ARM is put into big endian mode via CR15, the processor
124 * merely swaps the order of bytes within words, thus:
126 * ------------ physical data bus bits -----------
127 * D31 ... D24 D23 ... D16 D15 ... D8 D7 ... D0
128 * little byte 3 byte 2 byte 1 byte 0
129 * big byte 0 byte 1 byte 2 byte 3
131 * This means that reading a 32-bit word at address 0 returns the same
132 * value irrespective of the endian mode bit.
134 * Peripheral devices should be connected with the data bus reversed in
135 * "Big Endian" mode. ARM Application Note 61 is applicable, and is
136 * available from http://www.arm.com/.
138 * The following assumes that the data bus connectivity for big endian
139 * mode has been followed.
141 * Note that bit 0 is defined to be 32-bit word bit 0, not byte 0 bit 0.
145 * Little endian assembly bitops. nr = 0 -> byte 0 bit 0.
147 extern void _set_bit_le(int nr
, volatile unsigned long * p
);
148 extern void _clear_bit_le(int nr
, volatile unsigned long * p
);
149 extern void _change_bit_le(int nr
, volatile unsigned long * p
);
150 extern int _test_and_set_bit_le(int nr
, volatile unsigned long * p
);
151 extern int _test_and_clear_bit_le(int nr
, volatile unsigned long * p
);
152 extern int _test_and_change_bit_le(int nr
, volatile unsigned long * p
);
153 extern int _find_first_zero_bit_le(const void * p
, unsigned size
);
154 extern int _find_next_zero_bit_le(const void * p
, int size
, int offset
);
155 extern int _find_first_bit_le(const unsigned long *p
, unsigned size
);
156 extern int _find_next_bit_le(const unsigned long *p
, int size
, int offset
);
159 * Big endian assembly bitops. nr = 0 -> byte 3 bit 0.
161 extern void _set_bit_be(int nr
, volatile unsigned long * p
);
162 extern void _clear_bit_be(int nr
, volatile unsigned long * p
);
163 extern void _change_bit_be(int nr
, volatile unsigned long * p
);
164 extern int _test_and_set_bit_be(int nr
, volatile unsigned long * p
);
165 extern int _test_and_clear_bit_be(int nr
, volatile unsigned long * p
);
166 extern int _test_and_change_bit_be(int nr
, volatile unsigned long * p
);
167 extern int _find_first_zero_bit_be(const void * p
, unsigned size
);
168 extern int _find_next_zero_bit_be(const void * p
, int size
, int offset
);
169 extern int _find_first_bit_be(const unsigned long *p
, unsigned size
);
170 extern int _find_next_bit_be(const unsigned long *p
, int size
, int offset
);
173 * The __* form of bitops are non-atomic and may be reordered.
175 #define ATOMIC_BITOP_LE(name,nr,p) \
176 (__builtin_constant_p(nr) ? \
177 ____atomic_##name(nr, p) : \
180 #define ATOMIC_BITOP_BE(name,nr,p) \
181 (__builtin_constant_p(nr) ? \
182 ____atomic_##name(nr, p) : \
185 #define NONATOMIC_BITOP(name,nr,p) \
186 (____nonatomic_##name(nr, p))
189 * These are the little endian, atomic definitions.
191 #define set_bit(nr,p) ATOMIC_BITOP_LE(set_bit,nr,p)
192 #define clear_bit(nr,p) ATOMIC_BITOP_LE(clear_bit,nr,p)
193 #define change_bit(nr,p) ATOMIC_BITOP_LE(change_bit,nr,p)
194 #define test_and_set_bit(nr,p) ATOMIC_BITOP_LE(test_and_set_bit,nr,p)
195 #define test_and_clear_bit(nr,p) ATOMIC_BITOP_LE(test_and_clear_bit,nr,p)
196 #define test_and_change_bit(nr,p) ATOMIC_BITOP_LE(test_and_change_bit,nr,p)
197 #define find_first_zero_bit(p,sz) _find_first_zero_bit_le(p,sz)
198 #define find_next_zero_bit(p,sz,off) _find_next_zero_bit_le(p,sz,off)
199 #define find_first_bit(p,sz) _find_first_bit_le(p,sz)
200 #define find_next_bit(p,sz,off) _find_next_bit_le(p,sz,off)
202 #define WORD_BITOFF_TO_LE(x) ((x))
205 #include <asm-generic/bitops/ffz.h>
206 #include <asm-generic/bitops/__ffs.h>
207 #include <asm-generic/bitops/fls.h>
208 #include <asm-generic/bitops/ffs.h>
210 #include <asm-generic/bitops/fls64.h>
212 #include <asm-generic/bitops/sched.h>
213 #include <asm-generic/bitops/hweight.h>
216 #define BITS_PER_LONG 32
217 #define BITOP_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
218 #define BITOP_WORD(nr) ((nr) / BITS_PER_LONG)
220 static inline int test_bit(int nr
, const volatile unsigned long *addr
)
222 return 1UL & (addr
[BITOP_WORD(nr
)] >> (nr
& (BITS_PER_LONG
-1)));
225 #endif /* _ARM_BITOPS_H */