1 #ifndef _ASM_M32R_BITOPS_H
2 #define _ASM_M32R_BITOPS_H
5 * linux/include/asm-m32r/bitops.h
7 * Copyright 1992, Linus Torvalds.
10 * Copyright (C) 2001, 2002 Hitoshi Yamamoto
11 * Copyright (C) 2004 Hirokazu Takata <takata at linux-m32r.org>
14 #ifndef _LINUX_BITOPS_H
15 #error only <linux/bitops.h> can be included directly
18 #include <linux/compiler.h>
19 #include <linux/irqflags.h>
20 #include <asm/assembler.h>
21 #include <asm/byteorder.h>
22 #include <asm/dcache_clear.h>
23 #include <asm/types.h>
26 * These have to be done with inline assembly: that way the bit-setting
27 * is guaranteed to be atomic. All bit operations return 0 if the bit
28 * was cleared before the operation and != 0 if it was not.
30 * bit 0 is the LSB of addr; bit 32 is the LSB of (addr+1).
34 * set_bit - Atomically set a bit in memory
36 * @addr: the address to start counting from
38 * This function is atomic and may not be reordered. See __set_bit()
39 * if you do not require the atomic guarantees.
40 * Note that @nr may be almost arbitrarily large; this function is not
41 * restricted to acting on a single-word quantity.
43 static __inline__
void set_bit(int nr
, volatile void * addr
)
46 volatile __u32
*a
= addr
;
51 mask
= (1 << (nr
& 0x1F));
53 local_irq_save(flags
);
54 __asm__
__volatile__ (
55 DCACHE_CLEAR("%0", "r6", "%1")
56 M32R_LOCK
" %0, @%1; \n\t"
58 M32R_UNLOCK
" %0, @%1; \n\t"
62 #ifdef CONFIG_CHIP_M32700_TS1
64 #endif /* CONFIG_CHIP_M32700_TS1 */
66 local_irq_restore(flags
);
70 * clear_bit - Clears a bit in memory
72 * @addr: Address to start counting from
74 * clear_bit() is atomic and may not be reordered. However, it does
75 * not contain a memory barrier, so if it is used for locking purposes,
76 * you should call smp_mb__before_clear_bit() and/or smp_mb__after_clear_bit()
77 * in order to ensure changes are visible on other processors.
79 static __inline__
void clear_bit(int nr
, volatile void * addr
)
82 volatile __u32
*a
= addr
;
87 mask
= (1 << (nr
& 0x1F));
89 local_irq_save(flags
);
91 __asm__
__volatile__ (
92 DCACHE_CLEAR("%0", "r6", "%1")
93 M32R_LOCK
" %0, @%1; \n\t"
95 M32R_UNLOCK
" %0, @%1; \n\t"
97 : "r" (a
), "r" (~mask
)
99 #ifdef CONFIG_CHIP_M32700_TS1
101 #endif /* CONFIG_CHIP_M32700_TS1 */
103 local_irq_restore(flags
);
106 #define smp_mb__before_clear_bit() barrier()
107 #define smp_mb__after_clear_bit() barrier()
110 * change_bit - Toggle a bit in memory
112 * @addr: Address to start counting from
114 * change_bit() is atomic and may not be reordered.
115 * Note that @nr may be almost arbitrarily large; this function is not
116 * restricted to acting on a single-word quantity.
118 static __inline__
void change_bit(int nr
, volatile void * addr
)
121 volatile __u32
*a
= addr
;
126 mask
= (1 << (nr
& 0x1F));
128 local_irq_save(flags
);
129 __asm__
__volatile__ (
130 DCACHE_CLEAR("%0", "r6", "%1")
131 M32R_LOCK
" %0, @%1; \n\t"
133 M32R_UNLOCK
" %0, @%1; \n\t"
135 : "r" (a
), "r" (mask
)
137 #ifdef CONFIG_CHIP_M32700_TS1
139 #endif /* CONFIG_CHIP_M32700_TS1 */
141 local_irq_restore(flags
);
145 * test_and_set_bit - Set a bit and return its old value
147 * @addr: Address to count from
149 * This operation is atomic and cannot be reordered.
150 * It also implies a memory barrier.
152 static __inline__
int test_and_set_bit(int nr
, volatile void * addr
)
155 volatile __u32
*a
= addr
;
160 mask
= (1 << (nr
& 0x1F));
162 local_irq_save(flags
);
163 __asm__
__volatile__ (
164 DCACHE_CLEAR("%0", "%1", "%2")
165 M32R_LOCK
" %0, @%2; \n\t"
169 M32R_UNLOCK
" %1, @%2; \n\t"
170 : "=&r" (oldbit
), "=&r" (tmp
)
171 : "r" (a
), "r" (mask
)
174 local_irq_restore(flags
);
176 return (oldbit
!= 0);
180 * test_and_clear_bit - Clear a bit and return its old value
182 * @addr: Address to count from
184 * This operation is atomic and cannot be reordered.
185 * It also implies a memory barrier.
187 static __inline__
int test_and_clear_bit(int nr
, volatile void * addr
)
190 volatile __u32
*a
= addr
;
195 mask
= (1 << (nr
& 0x1F));
197 local_irq_save(flags
);
199 __asm__
__volatile__ (
200 DCACHE_CLEAR("%0", "%1", "%3")
201 M32R_LOCK
" %0, @%3; \n\t"
206 M32R_UNLOCK
" %1, @%3; \n\t"
207 : "=&r" (oldbit
), "=&r" (tmp
), "+r" (mask
)
211 local_irq_restore(flags
);
213 return (oldbit
!= 0);
217 * test_and_change_bit - Change a bit and return its old value
219 * @addr: Address to count from
221 * This operation is atomic and cannot be reordered.
222 * It also implies a memory barrier.
224 static __inline__
int test_and_change_bit(int nr
, volatile void * addr
)
227 volatile __u32
*a
= addr
;
232 mask
= (1 << (nr
& 0x1F));
234 local_irq_save(flags
);
235 __asm__
__volatile__ (
236 DCACHE_CLEAR("%0", "%1", "%2")
237 M32R_LOCK
" %0, @%2; \n\t"
241 M32R_UNLOCK
" %1, @%2; \n\t"
242 : "=&r" (oldbit
), "=&r" (tmp
)
243 : "r" (a
), "r" (mask
)
246 local_irq_restore(flags
);
248 return (oldbit
!= 0);
251 #include <asm-generic/bitops/non-atomic.h>
252 #include <asm-generic/bitops/ffz.h>
253 #include <asm-generic/bitops/__ffs.h>
254 #include <asm-generic/bitops/fls.h>
255 #include <asm-generic/bitops/__fls.h>
256 #include <asm-generic/bitops/fls64.h>
260 #include <asm-generic/bitops/sched.h>
261 #include <asm-generic/bitops/find.h>
262 #include <asm-generic/bitops/ffs.h>
263 #include <asm-generic/bitops/hweight.h>
264 #include <asm-generic/bitops/lock.h>
266 #endif /* __KERNEL__ */
270 #include <asm-generic/bitops/le.h>
271 #include <asm-generic/bitops/ext2-atomic.h>
273 #endif /* __KERNEL__ */
275 #endif /* _ASM_M32R_BITOPS_H */