1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_M32R_BITOPS_H
3 #define _ASM_M32R_BITOPS_H
6 * linux/include/asm-m32r/bitops.h
8 * Copyright 1992, Linus Torvalds.
11 * Copyright (C) 2001, 2002 Hitoshi Yamamoto
12 * Copyright (C) 2004 Hirokazu Takata <takata at linux-m32r.org>
15 #ifndef _LINUX_BITOPS_H
16 #error only <linux/bitops.h> can be included directly
19 #include <linux/compiler.h>
20 #include <linux/irqflags.h>
21 #include <asm/assembler.h>
22 #include <asm/byteorder.h>
23 #include <asm/dcache_clear.h>
24 #include <asm/types.h>
25 #include <asm/barrier.h>
28 * These have to be done with inline assembly: that way the bit-setting
29 * is guaranteed to be atomic. All bit operations return 0 if the bit
30 * was cleared before the operation and != 0 if it was not.
32 * bit 0 is the LSB of addr; bit 32 is the LSB of (addr+1).
36 * set_bit - Atomically set a bit in memory
38 * @addr: the address to start counting from
40 * This function is atomic and may not be reordered. See __set_bit()
41 * if you do not require the atomic guarantees.
42 * Note that @nr may be almost arbitrarily large; this function is not
43 * restricted to acting on a single-word quantity.
45 static __inline__
void set_bit(int nr
, volatile void * addr
)
48 volatile __u32
*a
= addr
;
53 mask
= (1 << (nr
& 0x1F));
55 local_irq_save(flags
);
56 __asm__
__volatile__ (
57 DCACHE_CLEAR("%0", "r6", "%1")
58 M32R_LOCK
" %0, @%1; \n\t"
60 M32R_UNLOCK
" %0, @%1; \n\t"
64 #ifdef CONFIG_CHIP_M32700_TS1
66 #endif /* CONFIG_CHIP_M32700_TS1 */
68 local_irq_restore(flags
);
72 * clear_bit - Clears a bit in memory
74 * @addr: Address to start counting from
76 * clear_bit() is atomic and may not be reordered. However, it does
77 * not contain a memory barrier, so if it is used for locking purposes,
78 * you should call smp_mb__before_atomic() and/or smp_mb__after_atomic()
79 * in order to ensure changes are visible on other processors.
81 static __inline__
void clear_bit(int nr
, volatile void * addr
)
84 volatile __u32
*a
= addr
;
89 mask
= (1 << (nr
& 0x1F));
91 local_irq_save(flags
);
93 __asm__
__volatile__ (
94 DCACHE_CLEAR("%0", "r6", "%1")
95 M32R_LOCK
" %0, @%1; \n\t"
97 M32R_UNLOCK
" %0, @%1; \n\t"
99 : "r" (a
), "r" (~mask
)
101 #ifdef CONFIG_CHIP_M32700_TS1
103 #endif /* CONFIG_CHIP_M32700_TS1 */
105 local_irq_restore(flags
);
109 * change_bit - Toggle a bit in memory
111 * @addr: Address to start counting from
113 * change_bit() is atomic and may not be reordered.
114 * Note that @nr may be almost arbitrarily large; this function is not
115 * restricted to acting on a single-word quantity.
117 static __inline__
void change_bit(int nr
, volatile void * addr
)
120 volatile __u32
*a
= addr
;
125 mask
= (1 << (nr
& 0x1F));
127 local_irq_save(flags
);
128 __asm__
__volatile__ (
129 DCACHE_CLEAR("%0", "r6", "%1")
130 M32R_LOCK
" %0, @%1; \n\t"
132 M32R_UNLOCK
" %0, @%1; \n\t"
134 : "r" (a
), "r" (mask
)
136 #ifdef CONFIG_CHIP_M32700_TS1
138 #endif /* CONFIG_CHIP_M32700_TS1 */
140 local_irq_restore(flags
);
144 * test_and_set_bit - Set a bit and return its old value
146 * @addr: Address to count from
148 * This operation is atomic and cannot be reordered.
149 * It also implies a memory barrier.
151 static __inline__
int test_and_set_bit(int nr
, volatile void * addr
)
154 volatile __u32
*a
= addr
;
159 mask
= (1 << (nr
& 0x1F));
161 local_irq_save(flags
);
162 __asm__
__volatile__ (
163 DCACHE_CLEAR("%0", "%1", "%2")
164 M32R_LOCK
" %0, @%2; \n\t"
168 M32R_UNLOCK
" %1, @%2; \n\t"
169 : "=&r" (oldbit
), "=&r" (tmp
)
170 : "r" (a
), "r" (mask
)
173 local_irq_restore(flags
);
175 return (oldbit
!= 0);
179 * test_and_clear_bit - Clear a bit and return its old value
181 * @addr: Address to count from
183 * This operation is atomic and cannot be reordered.
184 * It also implies a memory barrier.
186 static __inline__
int test_and_clear_bit(int nr
, volatile void * addr
)
189 volatile __u32
*a
= addr
;
194 mask
= (1 << (nr
& 0x1F));
196 local_irq_save(flags
);
198 __asm__
__volatile__ (
199 DCACHE_CLEAR("%0", "%1", "%3")
200 M32R_LOCK
" %0, @%3; \n\t"
205 M32R_UNLOCK
" %1, @%3; \n\t"
206 : "=&r" (oldbit
), "=&r" (tmp
), "+r" (mask
)
210 local_irq_restore(flags
);
212 return (oldbit
!= 0);
216 * test_and_change_bit - Change a bit and return its old value
218 * @addr: Address to count from
220 * This operation is atomic and cannot be reordered.
221 * It also implies a memory barrier.
223 static __inline__
int test_and_change_bit(int nr
, volatile void * addr
)
226 volatile __u32
*a
= addr
;
231 mask
= (1 << (nr
& 0x1F));
233 local_irq_save(flags
);
234 __asm__
__volatile__ (
235 DCACHE_CLEAR("%0", "%1", "%2")
236 M32R_LOCK
" %0, @%2; \n\t"
240 M32R_UNLOCK
" %1, @%2; \n\t"
241 : "=&r" (oldbit
), "=&r" (tmp
)
242 : "r" (a
), "r" (mask
)
245 local_irq_restore(flags
);
247 return (oldbit
!= 0);
250 #include <asm-generic/bitops/non-atomic.h>
251 #include <asm-generic/bitops/ffz.h>
252 #include <asm-generic/bitops/__ffs.h>
253 #include <asm-generic/bitops/fls.h>
254 #include <asm-generic/bitops/__fls.h>
255 #include <asm-generic/bitops/fls64.h>
259 #include <asm-generic/bitops/sched.h>
260 #include <asm-generic/bitops/find.h>
261 #include <asm-generic/bitops/ffs.h>
262 #include <asm-generic/bitops/hweight.h>
263 #include <asm-generic/bitops/lock.h>
265 #endif /* __KERNEL__ */
269 #include <asm-generic/bitops/le.h>
270 #include <asm-generic/bitops/ext2-atomic.h>
272 #endif /* __KERNEL__ */
274 #endif /* _ASM_M32R_BITOPS_H */