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 #include <linux/config.h>
15 #include <linux/compiler.h>
16 #include <asm/assembler.h>
17 #include <asm/system.h>
18 #include <asm/byteorder.h>
19 #include <asm/types.h>
22 * These have to be done with inline assembly: that way the bit-setting
23 * is guaranteed to be atomic. All bit operations return 0 if the bit
24 * was cleared before the operation and != 0 if it was not.
26 * bit 0 is the LSB of addr; bit 32 is the LSB of (addr+1).
30 * set_bit - Atomically set a bit in memory
32 * @addr: the address to start counting from
34 * This function is atomic and may not be reordered. See __set_bit()
35 * if you do not require the atomic guarantees.
36 * Note that @nr may be almost arbitrarily large; this function is not
37 * restricted to acting on a single-word quantity.
39 static __inline__ void set_bit(int nr, volatile void * addr)
42 volatile __u32 *a = addr;
47 mask = (1 << (nr & 0x1F));
49 local_irq_save(flags);
50 __asm__ __volatile__ (
51 DCACHE_CLEAR("%0", "r6", "%1")
52 M32R_LOCK" %0, @%1; \n\t"
54 M32R_UNLOCK" %0, @%1; \n\t"
58 #ifdef CONFIG_CHIP_M32700_TS1
60 #endif /* CONFIG_CHIP_M32700_TS1 */
62 local_irq_restore(flags);
66 * clear_bit - Clears a bit in memory
68 * @addr: Address to start counting from
70 * clear_bit() is atomic and may not be reordered. However, it does
71 * not contain a memory barrier, so if it is used for locking purposes,
72 * you should call smp_mb__before_clear_bit() and/or smp_mb__after_clear_bit()
73 * in order to ensure changes are visible on other processors.
75 static __inline__ void clear_bit(int nr, volatile void * addr)
78 volatile __u32 *a = addr;
83 mask = (1 << (nr & 0x1F));
85 local_irq_save(flags);
87 __asm__ __volatile__ (
88 DCACHE_CLEAR("%0", "r6", "%1")
89 M32R_LOCK" %0, @%1; \n\t"
91 M32R_UNLOCK" %0, @%1; \n\t"
93 : "r" (a), "r" (~mask)
95 #ifdef CONFIG_CHIP_M32700_TS1
97 #endif /* CONFIG_CHIP_M32700_TS1 */
99 local_irq_restore(flags);
102 #define smp_mb__before_clear_bit() barrier()
103 #define smp_mb__after_clear_bit() barrier()
106 * change_bit - Toggle a bit in memory
108 * @addr: Address to start counting from
110 * change_bit() is atomic and may not be reordered.
111 * Note that @nr may be almost arbitrarily large; this function is not
112 * restricted to acting on a single-word quantity.
114 static __inline__ void change_bit(int nr, volatile void * addr)
117 volatile __u32 *a = addr;
122 mask = (1 << (nr & 0x1F));
124 local_irq_save(flags);
125 __asm__ __volatile__ (
126 DCACHE_CLEAR("%0", "r6", "%1")
127 M32R_LOCK" %0, @%1; \n\t"
129 M32R_UNLOCK" %0, @%1; \n\t"
131 : "r" (a), "r" (mask)
133 #ifdef CONFIG_CHIP_M32700_TS1
135 #endif /* CONFIG_CHIP_M32700_TS1 */
137 local_irq_restore(flags);
141 * test_and_set_bit - Set a bit and return its old value
143 * @addr: Address to count from
145 * This operation is atomic and cannot be reordered.
146 * It also implies a memory barrier.
148 static __inline__ int test_and_set_bit(int nr, volatile void * addr)
151 volatile __u32 *a = addr;
156 mask = (1 << (nr & 0x1F));
158 local_irq_save(flags);
159 __asm__ __volatile__ (
160 DCACHE_CLEAR("%0", "%1", "%2")
161 M32R_LOCK" %0, @%2; \n\t"
165 M32R_UNLOCK" %1, @%2; \n\t"
166 : "=&r" (oldbit), "=&r" (tmp)
167 : "r" (a), "r" (mask)
170 local_irq_restore(flags);
172 return (oldbit != 0);
176 * test_and_clear_bit - Clear a bit and return its old value
178 * @addr: Address to count from
180 * This operation is atomic and cannot be reordered.
181 * It also implies a memory barrier.
183 static __inline__ int test_and_clear_bit(int nr, volatile void * addr)
186 volatile __u32 *a = addr;
191 mask = (1 << (nr & 0x1F));
193 local_irq_save(flags);
195 __asm__ __volatile__ (
196 DCACHE_CLEAR("%0", "%1", "%3")
197 M32R_LOCK" %0, @%3; \n\t"
202 M32R_UNLOCK" %1, @%3; \n\t"
203 : "=&r" (oldbit), "=&r" (tmp), "+r" (mask)
207 local_irq_restore(flags);
209 return (oldbit != 0);
213 * test_and_change_bit - Change a bit and return its old value
215 * @addr: Address to count from
217 * This operation is atomic and cannot be reordered.
218 * It also implies a memory barrier.
220 static __inline__ int test_and_change_bit(int nr, volatile void * addr)
223 volatile __u32 *a = addr;
228 mask = (1 << (nr & 0x1F));
230 local_irq_save(flags);
231 __asm__ __volatile__ (
232 DCACHE_CLEAR("%0", "%1", "%2")
233 M32R_LOCK" %0, @%2; \n\t"
237 M32R_UNLOCK" %1, @%2; \n\t"
238 : "=&r" (oldbit), "=&r" (tmp)
239 : "r" (a), "r" (mask)
242 local_irq_restore(flags);
244 return (oldbit != 0);
247 #include <asm-generic/bitops/non-atomic.h>
248 #include <asm-generic/bitops/ffz.h>
249 #include <asm-generic/bitops/__ffs.h>
250 #include <asm-generic/bitops/fls.h>
251 #include <asm-generic/bitops/fls64.h>
255 #include <asm-generic/bitops/sched.h>
256 #include <asm-generic/bitops/find.h>
257 #include <asm-generic/bitops/ffs.h>
258 #include <asm-generic/bitops/hweight.h>
260 #endif /* __KERNEL__ */
264 #include <asm-generic/bitops/ext2-non-atomic.h>
265 #include <asm-generic/bitops/ext2-atomic.h>
266 #include <asm-generic/bitops/minix.h>
268 #endif /* __KERNEL__ */
270 #endif /* _ASM_M32R_BITOPS_H */