blob: 9964e17232e9104e5ea37d7a18a8768f7684c570 [file] [log] [blame]
Bryan Wu1394f032007-05-06 14:50:22 -07001#ifndef _BLACKFIN_BITOPS_H
2#define _BLACKFIN_BITOPS_H
3
4/*
5 * Copyright 1992, Linus Torvalds.
6 */
7
8#include <linux/compiler.h>
9#include <asm/byteorder.h> /* swab32 */
Bryan Wu1394f032007-05-06 14:50:22 -070010
11#ifdef __KERNEL__
12
Jiri Slaby06245172007-10-18 23:40:26 -070013#ifndef _LINUX_BITOPS_H
14#error only <linux/bitops.h> can be included directly
15#endif
16
Bryan Wu1394f032007-05-06 14:50:22 -070017#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>
21
Graf Yang6b3087c2009-01-07 23:14:39 +080022#ifdef CONFIG_SMP
23
24#include <linux/linkage.h>
25
26asmlinkage int __raw_bit_set_asm(volatile unsigned long *addr, int nr);
27
28asmlinkage int __raw_bit_clear_asm(volatile unsigned long *addr, int nr);
29
30asmlinkage int __raw_bit_toggle_asm(volatile unsigned long *addr, int nr);
31
32asmlinkage int __raw_bit_test_set_asm(volatile unsigned long *addr, int nr);
33
34asmlinkage int __raw_bit_test_clear_asm(volatile unsigned long *addr, int nr);
35
36asmlinkage int __raw_bit_test_toggle_asm(volatile unsigned long *addr, int nr);
37
38asmlinkage int __raw_bit_test_asm(const volatile unsigned long *addr, int nr);
39
40static inline void set_bit(int nr, volatile unsigned long *addr)
41{
42 volatile unsigned long *a = addr + (nr >> 5);
43 __raw_bit_set_asm(a, nr & 0x1f);
44}
45
46static inline void clear_bit(int nr, volatile unsigned long *addr)
47{
48 volatile unsigned long *a = addr + (nr >> 5);
49 __raw_bit_clear_asm(a, nr & 0x1f);
50}
51
52static inline void change_bit(int nr, volatile unsigned long *addr)
53{
54 volatile unsigned long *a = addr + (nr >> 5);
55 __raw_bit_toggle_asm(a, nr & 0x1f);
56}
57
58static inline int test_bit(int nr, const volatile unsigned long *addr)
59{
60 volatile const unsigned long *a = addr + (nr >> 5);
61 return __raw_bit_test_asm(a, nr & 0x1f) != 0;
62}
63
64static inline int test_and_set_bit(int nr, volatile unsigned long *addr)
65{
66 volatile unsigned long *a = addr + (nr >> 5);
67 return __raw_bit_test_set_asm(a, nr & 0x1f);
68}
69
70static inline int test_and_clear_bit(int nr, volatile unsigned long *addr)
71{
72 volatile unsigned long *a = addr + (nr >> 5);
73 return __raw_bit_test_clear_asm(a, nr & 0x1f);
74}
75
76static inline int test_and_change_bit(int nr, volatile unsigned long *addr)
77{
78 volatile unsigned long *a = addr + (nr >> 5);
79 return __raw_bit_test_toggle_asm(a, nr & 0x1f);
80}
81
82#else /* !CONFIG_SMP */
83
84#include <asm/system.h> /* save_flags */
85
86static inline void set_bit(int nr, volatile unsigned long *addr)
Bryan Wu1394f032007-05-06 14:50:22 -070087{
88 int *a = (int *)addr;
89 int mask;
90 unsigned long flags;
Bryan Wu1394f032007-05-06 14:50:22 -070091 a += nr >> 5;
92 mask = 1 << (nr & 0x1f);
93 local_irq_save(flags);
94 *a |= mask;
95 local_irq_restore(flags);
96}
97
Graf Yang6b3087c2009-01-07 23:14:39 +080098static inline void clear_bit(int nr, volatile unsigned long *addr)
Bryan Wu1394f032007-05-06 14:50:22 -070099{
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(flags);
106 *a &= ~mask;
107 local_irq_restore(flags);
108}
109
Graf Yang6b3087c2009-01-07 23:14:39 +0800110static inline void change_bit(int nr, volatile unsigned long *addr)
Bryan Wu1394f032007-05-06 14:50:22 -0700111{
112 int mask, flags;
113 unsigned long *ADDR = (unsigned long *)addr;
114
115 ADDR += nr >> 5;
116 mask = 1 << (nr & 31);
117 local_irq_save(flags);
118 *ADDR ^= mask;
119 local_irq_restore(flags);
120}
121
Graf Yang6b3087c2009-01-07 23:14:39 +0800122static inline int test_and_set_bit(int nr, volatile unsigned long *addr)
Bryan Wu1394f032007-05-06 14:50:22 -0700123{
124 int mask, retval;
125 volatile unsigned int *a = (volatile unsigned int *)addr;
126 unsigned long flags;
127
128 a += nr >> 5;
129 mask = 1 << (nr & 0x1f);
130 local_irq_save(flags);
131 retval = (mask & *a) != 0;
132 *a |= mask;
133 local_irq_restore(flags);
134
135 return retval;
136}
137
Graf Yang6b3087c2009-01-07 23:14:39 +0800138static inline int test_and_clear_bit(int nr, volatile unsigned long *addr)
Bryan Wu1394f032007-05-06 14:50:22 -0700139{
140 int mask, retval;
141 volatile unsigned int *a = (volatile unsigned int *)addr;
142 unsigned long flags;
143
144 a += nr >> 5;
145 mask = 1 << (nr & 0x1f);
146 local_irq_save(flags);
147 retval = (mask & *a) != 0;
148 *a &= ~mask;
149 local_irq_restore(flags);
150
151 return retval;
152}
153
Graf Yang6b3087c2009-01-07 23:14:39 +0800154static inline int test_and_change_bit(int nr, volatile unsigned long *addr)
Bryan Wu1394f032007-05-06 14:50:22 -0700155{
156 int mask, retval;
157 volatile unsigned int *a = (volatile unsigned int *)addr;
158 unsigned long flags;
159
160 a += nr >> 5;
161 mask = 1 << (nr & 0x1f);
162 local_irq_save(flags);
163 retval = (mask & *a) != 0;
164 *a ^= mask;
165 local_irq_restore(flags);
166 return retval;
167}
168
Graf Yang6b3087c2009-01-07 23:14:39 +0800169#endif /* CONFIG_SMP */
170
171/*
172 * clear_bit() doesn't provide any barrier for the compiler.
173 */
174#define smp_mb__before_clear_bit() barrier()
175#define smp_mb__after_clear_bit() barrier()
176
177static inline void __set_bit(int nr, volatile unsigned long *addr)
178{
179 int *a = (int *)addr;
180 int mask;
181
182 a += nr >> 5;
183 mask = 1 << (nr & 0x1f);
184 *a |= mask;
185}
186
187static inline void __clear_bit(int nr, volatile unsigned long *addr)
188{
189 int *a = (int *)addr;
190 int mask;
191
192 a += nr >> 5;
193 mask = 1 << (nr & 0x1f);
194 *a &= ~mask;
195}
196
197static inline void __change_bit(int nr, volatile unsigned long *addr)
198{
199 int mask;
200 unsigned long *ADDR = (unsigned long *)addr;
201
202 ADDR += nr >> 5;
203 mask = 1 << (nr & 31);
204 *ADDR ^= mask;
205}
206
207static inline int __test_and_set_bit(int nr, volatile unsigned long *addr)
208{
209 int mask, retval;
210 volatile unsigned int *a = (volatile unsigned int *)addr;
211
212 a += nr >> 5;
213 mask = 1 << (nr & 0x1f);
214 retval = (mask & *a) != 0;
215 *a |= mask;
216 return retval;
217}
218
219static inline int __test_and_clear_bit(int nr, volatile unsigned long *addr)
220{
221 int mask, retval;
222 volatile unsigned int *a = (volatile unsigned int *)addr;
223
224 a += nr >> 5;
225 mask = 1 << (nr & 0x1f);
226 retval = (mask & *a) != 0;
227 *a &= ~mask;
228 return retval;
229}
230
231static inline int __test_and_change_bit(int nr,
Bryan Wu1394f032007-05-06 14:50:22 -0700232 volatile unsigned long *addr)
233{
234 int mask, retval;
235 volatile unsigned int *a = (volatile unsigned int *)addr;
236
237 a += nr >> 5;
238 mask = 1 << (nr & 0x1f);
239 retval = (mask & *a) != 0;
240 *a ^= mask;
241 return retval;
242}
243
Graf Yang6b3087c2009-01-07 23:14:39 +0800244static inline int __test_bit(int nr, const void *addr)
Bryan Wu1394f032007-05-06 14:50:22 -0700245{
246 int *a = (int *)addr;
247 int mask;
248
249 a += nr >> 5;
250 mask = 1 << (nr & 0x1f);
251 return ((mask & *a) != 0);
252}
253
Graf Yang6b3087c2009-01-07 23:14:39 +0800254#ifndef CONFIG_SMP
255/*
256 * This routine doesn't need irq save and restore ops in UP
257 * context.
258 */
259static inline int test_bit(int nr, const void *addr)
260{
261 return __test_bit(nr, addr);
262}
263#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700264
265#include <asm-generic/bitops/find.h>
266#include <asm-generic/bitops/hweight.h>
Nick Piggin26333572007-10-18 03:06:39 -0700267#include <asm-generic/bitops/lock.h>
Bryan Wu1394f032007-05-06 14:50:22 -0700268
269#include <asm-generic/bitops/ext2-atomic.h>
270#include <asm-generic/bitops/ext2-non-atomic.h>
271
272#include <asm-generic/bitops/minix.h>
273
274#endif /* __KERNEL__ */
275
276#include <asm-generic/bitops/fls.h>
Rusty Russellccec25f2009-01-01 10:12:17 +1030277#include <asm-generic/bitops/__fls.h>
Bryan Wu1394f032007-05-06 14:50:22 -0700278#include <asm-generic/bitops/fls64.h>
279
280#endif /* _BLACKFIN_BITOPS_H */