x86: add copies of some headers to convert to asm-generic
[linux/fpc-iii.git] / arch / blackfin / include / asm / bitops.h
blob75fee2f7d9f240b3c98d5080a35016eca8e60399
1 #ifndef _BLACKFIN_BITOPS_H
2 #define _BLACKFIN_BITOPS_H
4 /*
5 * Copyright 1992, Linus Torvalds.
6 */
8 #include <linux/compiler.h>
9 #include <asm/byteorder.h> /* swab32 */
11 #ifdef __KERNEL__
13 #ifndef _LINUX_BITOPS_H
14 #error only <linux/bitops.h> can be included directly
15 #endif
17 #include <asm-generic/bitops/ffs.h>
18 #include <asm-generic/bitops/__ffs.h>
19 #include <asm-generic/bitops/sched.h>
20 #include <asm-generic/bitops/ffz.h>
22 #ifdef CONFIG_SMP
24 #include <linux/linkage.h>
26 asmlinkage int __raw_bit_set_asm(volatile unsigned long *addr, int nr);
28 asmlinkage int __raw_bit_clear_asm(volatile unsigned long *addr, int nr);
30 asmlinkage int __raw_bit_toggle_asm(volatile unsigned long *addr, int nr);
32 asmlinkage int __raw_bit_test_set_asm(volatile unsigned long *addr, int nr);
34 asmlinkage int __raw_bit_test_clear_asm(volatile unsigned long *addr, int nr);
36 asmlinkage int __raw_bit_test_toggle_asm(volatile unsigned long *addr, int nr);
38 asmlinkage int __raw_bit_test_asm(const volatile unsigned long *addr, int nr);
40 static inline void set_bit(int nr, volatile unsigned long *addr)
42 volatile unsigned long *a = addr + (nr >> 5);
43 __raw_bit_set_asm(a, nr & 0x1f);
46 static inline void clear_bit(int nr, volatile unsigned long *addr)
48 volatile unsigned long *a = addr + (nr >> 5);
49 __raw_bit_clear_asm(a, nr & 0x1f);
52 static inline void change_bit(int nr, volatile unsigned long *addr)
54 volatile unsigned long *a = addr + (nr >> 5);
55 __raw_bit_toggle_asm(a, nr & 0x1f);
58 static inline int test_bit(int nr, const volatile unsigned long *addr)
60 volatile const unsigned long *a = addr + (nr >> 5);
61 return __raw_bit_test_asm(a, nr & 0x1f) != 0;
64 static inline int test_and_set_bit(int nr, volatile unsigned long *addr)
66 volatile unsigned long *a = addr + (nr >> 5);
67 return __raw_bit_test_set_asm(a, nr & 0x1f);
70 static inline int test_and_clear_bit(int nr, volatile unsigned long *addr)
72 volatile unsigned long *a = addr + (nr >> 5);
73 return __raw_bit_test_clear_asm(a, nr & 0x1f);
76 static inline int test_and_change_bit(int nr, volatile unsigned long *addr)
78 volatile unsigned long *a = addr + (nr >> 5);
79 return __raw_bit_test_toggle_asm(a, nr & 0x1f);
82 #else /* !CONFIG_SMP */
84 #include <asm/system.h> /* save_flags */
86 static inline void set_bit(int nr, volatile unsigned long *addr)
88 int *a = (int *)addr;
89 int mask;
90 unsigned long flags;
91 a += nr >> 5;
92 mask = 1 << (nr & 0x1f);
93 local_irq_save_hw(flags);
94 *a |= mask;
95 local_irq_restore_hw(flags);
98 static inline void clear_bit(int nr, volatile unsigned long *addr)
100 int *a = (int *)addr;
101 int mask;
102 unsigned long flags;
103 a += nr >> 5;
104 mask = 1 << (nr & 0x1f);
105 local_irq_save_hw(flags);
106 *a &= ~mask;
107 local_irq_restore_hw(flags);
110 static inline void change_bit(int nr, volatile unsigned long *addr)
112 int mask;
113 unsigned long flags;
114 unsigned long *ADDR = (unsigned long *)addr;
116 ADDR += nr >> 5;
117 mask = 1 << (nr & 31);
118 local_irq_save_hw(flags);
119 *ADDR ^= mask;
120 local_irq_restore_hw(flags);
123 static inline int test_and_set_bit(int nr, volatile unsigned long *addr)
125 int mask, retval;
126 volatile unsigned int *a = (volatile unsigned int *)addr;
127 unsigned long flags;
129 a += nr >> 5;
130 mask = 1 << (nr & 0x1f);
131 local_irq_save_hw(flags);
132 retval = (mask & *a) != 0;
133 *a |= mask;
134 local_irq_restore_hw(flags);
136 return retval;
139 static inline int test_and_clear_bit(int nr, volatile unsigned long *addr)
141 int mask, retval;
142 volatile unsigned int *a = (volatile unsigned int *)addr;
143 unsigned long flags;
145 a += nr >> 5;
146 mask = 1 << (nr & 0x1f);
147 local_irq_save_hw(flags);
148 retval = (mask & *a) != 0;
149 *a &= ~mask;
150 local_irq_restore_hw(flags);
152 return retval;
155 static inline int test_and_change_bit(int nr, volatile unsigned long *addr)
157 int mask, retval;
158 volatile unsigned int *a = (volatile unsigned int *)addr;
159 unsigned long flags;
161 a += nr >> 5;
162 mask = 1 << (nr & 0x1f);
163 local_irq_save_hw(flags);
164 retval = (mask & *a) != 0;
165 *a ^= mask;
166 local_irq_restore_hw(flags);
167 return retval;
170 #endif /* CONFIG_SMP */
173 * clear_bit() doesn't provide any barrier for the compiler.
175 #define smp_mb__before_clear_bit() barrier()
176 #define smp_mb__after_clear_bit() barrier()
178 static inline void __set_bit(int nr, volatile unsigned long *addr)
180 int *a = (int *)addr;
181 int mask;
183 a += nr >> 5;
184 mask = 1 << (nr & 0x1f);
185 *a |= mask;
188 static inline void __clear_bit(int nr, volatile unsigned long *addr)
190 int *a = (int *)addr;
191 int mask;
193 a += nr >> 5;
194 mask = 1 << (nr & 0x1f);
195 *a &= ~mask;
198 static inline void __change_bit(int nr, volatile unsigned long *addr)
200 int mask;
201 unsigned long *ADDR = (unsigned long *)addr;
203 ADDR += nr >> 5;
204 mask = 1 << (nr & 31);
205 *ADDR ^= mask;
208 static inline int __test_and_set_bit(int nr, volatile unsigned long *addr)
210 int mask, retval;
211 volatile unsigned int *a = (volatile unsigned int *)addr;
213 a += nr >> 5;
214 mask = 1 << (nr & 0x1f);
215 retval = (mask & *a) != 0;
216 *a |= mask;
217 return retval;
220 static inline int __test_and_clear_bit(int nr, volatile unsigned long *addr)
222 int mask, retval;
223 volatile unsigned int *a = (volatile unsigned int *)addr;
225 a += nr >> 5;
226 mask = 1 << (nr & 0x1f);
227 retval = (mask & *a) != 0;
228 *a &= ~mask;
229 return retval;
232 static inline int __test_and_change_bit(int nr,
233 volatile unsigned long *addr)
235 int mask, retval;
236 volatile unsigned int *a = (volatile unsigned int *)addr;
238 a += nr >> 5;
239 mask = 1 << (nr & 0x1f);
240 retval = (mask & *a) != 0;
241 *a ^= mask;
242 return retval;
245 static inline int __test_bit(int nr, const void *addr)
247 int *a = (int *)addr;
248 int mask;
250 a += nr >> 5;
251 mask = 1 << (nr & 0x1f);
252 return ((mask & *a) != 0);
255 #ifndef CONFIG_SMP
257 * This routine doesn't need irq save and restore ops in UP
258 * context.
260 static inline int test_bit(int nr, const void *addr)
262 return __test_bit(nr, addr);
264 #endif
266 #include <asm-generic/bitops/find.h>
267 #include <asm-generic/bitops/hweight.h>
268 #include <asm-generic/bitops/lock.h>
270 #include <asm-generic/bitops/ext2-atomic.h>
271 #include <asm-generic/bitops/ext2-non-atomic.h>
273 #include <asm-generic/bitops/minix.h>
275 #endif /* __KERNEL__ */
277 #include <asm-generic/bitops/fls.h>
278 #include <asm-generic/bitops/__fls.h>
279 #include <asm-generic/bitops/fls64.h>
281 #endif /* _BLACKFIN_BITOPS_H */