2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (c) 1994-1997, 99, 2000, 06, 07 Ralf Baechle (ralf@linux-mips.org)
7 * Copyright (c) 1999, 2000 Silicon Graphics, Inc.
9 #include <linux/bitops.h>
10 #include <linux/irqflags.h>
11 #include <linux/export.h>
15 * __mips_set_bit - Atomically set a bit in memory. This is called by
16 * set_bit() if it cannot find a faster solution.
18 * @addr: the address to start counting from
20 void __mips_set_bit(unsigned long nr, volatile unsigned long *addr)
22 volatile unsigned long *a = addr;
23 unsigned bit = nr & SZLONG_MASK;
27 a += nr >> SZLONG_LOG;
29 raw_local_irq_save(flags);
31 raw_local_irq_restore(flags);
33 EXPORT_SYMBOL(__mips_set_bit);
37 * __mips_clear_bit - Clears a bit in memory. This is called by clear_bit() if
38 * it cannot find a faster solution.
40 * @addr: Address to start counting from
42 void __mips_clear_bit(unsigned long nr, volatile unsigned long *addr)
44 volatile unsigned long *a = addr;
45 unsigned bit = nr & SZLONG_MASK;
49 a += nr >> SZLONG_LOG;
51 raw_local_irq_save(flags);
53 raw_local_irq_restore(flags);
55 EXPORT_SYMBOL(__mips_clear_bit);
59 * __mips_change_bit - Toggle a bit in memory. This is called by change_bit()
60 * if it cannot find a faster solution.
62 * @addr: Address to start counting from
64 void __mips_change_bit(unsigned long nr, volatile unsigned long *addr)
66 volatile unsigned long *a = addr;
67 unsigned bit = nr & SZLONG_MASK;
71 a += nr >> SZLONG_LOG;
73 raw_local_irq_save(flags);
75 raw_local_irq_restore(flags);
77 EXPORT_SYMBOL(__mips_change_bit);
81 * __mips_test_and_set_bit - Set a bit and return its old value. This is
82 * called by test_and_set_bit() if it cannot find a faster solution.
84 * @addr: Address to count from
86 int __mips_test_and_set_bit(unsigned long nr,
87 volatile unsigned long *addr)
89 volatile unsigned long *a = addr;
90 unsigned bit = nr & SZLONG_MASK;
95 a += nr >> SZLONG_LOG;
97 raw_local_irq_save(flags);
98 res = (mask & *a) != 0;
100 raw_local_irq_restore(flags);
103 EXPORT_SYMBOL(__mips_test_and_set_bit);
107 * __mips_test_and_set_bit_lock - Set a bit and return its old value. This is
108 * called by test_and_set_bit_lock() if it cannot find a faster solution.
110 * @addr: Address to count from
112 int __mips_test_and_set_bit_lock(unsigned long nr,
113 volatile unsigned long *addr)
115 volatile unsigned long *a = addr;
116 unsigned bit = nr & SZLONG_MASK;
121 a += nr >> SZLONG_LOG;
123 raw_local_irq_save(flags);
124 res = (mask & *a) != 0;
126 raw_local_irq_restore(flags);
129 EXPORT_SYMBOL(__mips_test_and_set_bit_lock);
133 * __mips_test_and_clear_bit - Clear a bit and return its old value. This is
134 * called by test_and_clear_bit() if it cannot find a faster solution.
136 * @addr: Address to count from
138 int __mips_test_and_clear_bit(unsigned long nr, volatile unsigned long *addr)
140 volatile unsigned long *a = addr;
141 unsigned bit = nr & SZLONG_MASK;
146 a += nr >> SZLONG_LOG;
148 raw_local_irq_save(flags);
149 res = (mask & *a) != 0;
151 raw_local_irq_restore(flags);
154 EXPORT_SYMBOL(__mips_test_and_clear_bit);
158 * __mips_test_and_change_bit - Change a bit and return its old value. This is
159 * called by test_and_change_bit() if it cannot find a faster solution.
161 * @addr: Address to count from
163 int __mips_test_and_change_bit(unsigned long nr, volatile unsigned long *addr)
165 volatile unsigned long *a = addr;
166 unsigned bit = nr & SZLONG_MASK;
171 a += nr >> SZLONG_LOG;
173 raw_local_irq_save(flags);
174 res = (mask & *a) != 0;
176 raw_local_irq_restore(flags);
179 EXPORT_SYMBOL(__mips_test_and_change_bit);