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>
24 #include <asm/barrier.h>
27 * These have to be done with inline assembly: that way the bit-setting
28 * is guaranteed to be atomic. All bit operations return 0 if the bit
29 * was cleared before the operation and != 0 if it was not.
31 * bit 0 is the LSB of addr; bit 32 is the LSB of (addr+1).
35 * set_bit - Atomically set a bit in memory
37 * @addr: the address to start counting from
39 * This function is atomic and may not be reordered. See __set_bit()
40 * if you do not require the atomic guarantees.
41 * Note that @nr may be almost arbitrarily large; this function is not
42 * restricted to acting on a single-word quantity.
44 static __inline__
void set_bit(int nr
, volatile void * addr
)
47 volatile __u32
*a
= addr
;
52 mask
= (1 << (nr
& 0x1F));
54 local_irq_save(flags
);
55 __asm__
__volatile__ (
56 DCACHE_CLEAR("%0", "r6", "%1")
57 M32R_LOCK
" %0, @%1; \n\t"
59 M32R_UNLOCK
" %0, @%1; \n\t"
63 #ifdef CONFIG_CHIP_M32700_TS1
65 #endif /* CONFIG_CHIP_M32700_TS1 */
67 local_irq_restore(flags
);
71 * clear_bit - Clears a bit in memory
73 * @addr: Address to start counting from
75 * clear_bit() is atomic and may not be reordered. However, it does
76 * not contain a memory barrier, so if it is used for locking purposes,
77 * you should call smp_mb__before_atomic() and/or smp_mb__after_atomic()
78 * in order to ensure changes are visible on other processors.
80 static __inline__
void clear_bit(int nr
, volatile void * addr
)
83 volatile __u32
*a
= addr
;
88 mask
= (1 << (nr
& 0x1F));
90 local_irq_save(flags
);
92 __asm__
__volatile__ (
93 DCACHE_CLEAR("%0", "r6", "%1")
94 M32R_LOCK
" %0, @%1; \n\t"
96 M32R_UNLOCK
" %0, @%1; \n\t"
98 : "r" (a
), "r" (~mask
)
100 #ifdef CONFIG_CHIP_M32700_TS1
102 #endif /* CONFIG_CHIP_M32700_TS1 */
104 local_irq_restore(flags
);
108 * change_bit - Toggle a bit in memory
110 * @addr: Address to start counting from
112 * change_bit() is atomic and may not be reordered.
113 * Note that @nr may be almost arbitrarily large; this function is not
114 * restricted to acting on a single-word quantity.
116 static __inline__
void change_bit(int nr
, volatile void * addr
)
119 volatile __u32
*a
= addr
;
124 mask
= (1 << (nr
& 0x1F));
126 local_irq_save(flags
);
127 __asm__
__volatile__ (
128 DCACHE_CLEAR("%0", "r6", "%1")
129 M32R_LOCK
" %0, @%1; \n\t"
131 M32R_UNLOCK
" %0, @%1; \n\t"
133 : "r" (a
), "r" (mask
)
135 #ifdef CONFIG_CHIP_M32700_TS1
137 #endif /* CONFIG_CHIP_M32700_TS1 */
139 local_irq_restore(flags
);
143 * test_and_set_bit - Set a bit and return its old value
145 * @addr: Address to count from
147 * This operation is atomic and cannot be reordered.
148 * It also implies a memory barrier.
150 static __inline__
int test_and_set_bit(int nr
, volatile void * addr
)
153 volatile __u32
*a
= addr
;
158 mask
= (1 << (nr
& 0x1F));
160 local_irq_save(flags
);
161 __asm__
__volatile__ (
162 DCACHE_CLEAR("%0", "%1", "%2")
163 M32R_LOCK
" %0, @%2; \n\t"
167 M32R_UNLOCK
" %1, @%2; \n\t"
168 : "=&r" (oldbit
), "=&r" (tmp
)
169 : "r" (a
), "r" (mask
)
172 local_irq_restore(flags
);
174 return (oldbit
!= 0);
178 * test_and_clear_bit - Clear a bit and return its old value
180 * @addr: Address to count from
182 * This operation is atomic and cannot be reordered.
183 * It also implies a memory barrier.
185 static __inline__
int test_and_clear_bit(int nr
, volatile void * addr
)
188 volatile __u32
*a
= addr
;
193 mask
= (1 << (nr
& 0x1F));
195 local_irq_save(flags
);
197 __asm__
__volatile__ (
198 DCACHE_CLEAR("%0", "%1", "%3")
199 M32R_LOCK
" %0, @%3; \n\t"
204 M32R_UNLOCK
" %1, @%3; \n\t"
205 : "=&r" (oldbit
), "=&r" (tmp
), "+r" (mask
)
209 local_irq_restore(flags
);
211 return (oldbit
!= 0);
215 * test_and_change_bit - Change a bit and return its old value
217 * @addr: Address to count from
219 * This operation is atomic and cannot be reordered.
220 * It also implies a memory barrier.
222 static __inline__
int test_and_change_bit(int nr
, volatile void * addr
)
225 volatile __u32
*a
= addr
;
230 mask
= (1 << (nr
& 0x1F));
232 local_irq_save(flags
);
233 __asm__
__volatile__ (
234 DCACHE_CLEAR("%0", "%1", "%2")
235 M32R_LOCK
" %0, @%2; \n\t"
239 M32R_UNLOCK
" %1, @%2; \n\t"
240 : "=&r" (oldbit
), "=&r" (tmp
)
241 : "r" (a
), "r" (mask
)
244 local_irq_restore(flags
);
246 return (oldbit
!= 0);
249 #include <asm-generic/bitops/non-atomic.h>
250 #include <asm-generic/bitops/ffz.h>
251 #include <asm-generic/bitops/__ffs.h>
252 #include <asm-generic/bitops/fls.h>
253 #include <asm-generic/bitops/__fls.h>
254 #include <asm-generic/bitops/fls64.h>
258 #include <asm-generic/bitops/sched.h>
259 #include <asm-generic/bitops/find.h>
260 #include <asm-generic/bitops/ffs.h>
261 #include <asm-generic/bitops/hweight.h>
262 #include <asm-generic/bitops/lock.h>
264 #endif /* __KERNEL__ */
268 #include <asm-generic/bitops/le.h>
269 #include <asm-generic/bitops/ext2-atomic.h>
271 #endif /* __KERNEL__ */
273 #endif /* _ASM_M32R_BITOPS_H */