hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/arch/mips/lib/bitops.c
....@@ -7,6 +7,7 @@
77 * Copyright (c) 1999, 2000 Silicon Graphics, Inc.
88 */
99 #include <linux/bitops.h>
10
+#include <linux/bits.h>
1011 #include <linux/irqflags.h>
1112 #include <linux/export.h>
1213
....@@ -19,12 +20,11 @@
1920 */
2021 void __mips_set_bit(unsigned long nr, volatile unsigned long *addr)
2122 {
22
- unsigned long *a = (unsigned long *)addr;
23
- unsigned bit = nr & SZLONG_MASK;
23
+ volatile unsigned long *a = &addr[BIT_WORD(nr)];
24
+ unsigned int bit = nr % BITS_PER_LONG;
2425 unsigned long mask;
2526 unsigned long flags;
2627
27
- a += nr >> SZLONG_LOG;
2828 mask = 1UL << bit;
2929 raw_local_irq_save(flags);
3030 *a |= mask;
....@@ -41,12 +41,11 @@
4141 */
4242 void __mips_clear_bit(unsigned long nr, volatile unsigned long *addr)
4343 {
44
- unsigned long *a = (unsigned long *)addr;
45
- unsigned bit = nr & SZLONG_MASK;
44
+ volatile unsigned long *a = &addr[BIT_WORD(nr)];
45
+ unsigned int bit = nr % BITS_PER_LONG;
4646 unsigned long mask;
4747 unsigned long flags;
4848
49
- a += nr >> SZLONG_LOG;
5049 mask = 1UL << bit;
5150 raw_local_irq_save(flags);
5251 *a &= ~mask;
....@@ -63,44 +62,17 @@
6362 */
6463 void __mips_change_bit(unsigned long nr, volatile unsigned long *addr)
6564 {
66
- unsigned long *a = (unsigned long *)addr;
67
- unsigned bit = nr & SZLONG_MASK;
65
+ volatile unsigned long *a = &addr[BIT_WORD(nr)];
66
+ unsigned int bit = nr % BITS_PER_LONG;
6867 unsigned long mask;
6968 unsigned long flags;
7069
71
- a += nr >> SZLONG_LOG;
7270 mask = 1UL << bit;
7371 raw_local_irq_save(flags);
7472 *a ^= mask;
7573 raw_local_irq_restore(flags);
7674 }
7775 EXPORT_SYMBOL(__mips_change_bit);
78
-
79
-
80
-/**
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.
83
- * @nr: Bit to set
84
- * @addr: Address to count from
85
- */
86
-int __mips_test_and_set_bit(unsigned long nr,
87
- volatile unsigned long *addr)
88
-{
89
- unsigned long *a = (unsigned long *)addr;
90
- unsigned bit = nr & SZLONG_MASK;
91
- unsigned long mask;
92
- unsigned long flags;
93
- int res;
94
-
95
- a += nr >> SZLONG_LOG;
96
- mask = 1UL << bit;
97
- raw_local_irq_save(flags);
98
- res = (mask & *a) != 0;
99
- *a |= mask;
100
- raw_local_irq_restore(flags);
101
- return res;
102
-}
103
-EXPORT_SYMBOL(__mips_test_and_set_bit);
10476
10577
10678 /**
....@@ -112,13 +84,12 @@
11284 int __mips_test_and_set_bit_lock(unsigned long nr,
11385 volatile unsigned long *addr)
11486 {
115
- unsigned long *a = (unsigned long *)addr;
116
- unsigned bit = nr & SZLONG_MASK;
87
+ volatile unsigned long *a = &addr[BIT_WORD(nr)];
88
+ unsigned int bit = nr % BITS_PER_LONG;
11789 unsigned long mask;
11890 unsigned long flags;
11991 int res;
12092
121
- a += nr >> SZLONG_LOG;
12293 mask = 1UL << bit;
12394 raw_local_irq_save(flags);
12495 res = (mask & *a) != 0;
....@@ -137,13 +108,12 @@
137108 */
138109 int __mips_test_and_clear_bit(unsigned long nr, volatile unsigned long *addr)
139110 {
140
- unsigned long *a = (unsigned long *)addr;
141
- unsigned bit = nr & SZLONG_MASK;
111
+ volatile unsigned long *a = &addr[BIT_WORD(nr)];
112
+ unsigned int bit = nr % BITS_PER_LONG;
142113 unsigned long mask;
143114 unsigned long flags;
144115 int res;
145116
146
- a += nr >> SZLONG_LOG;
147117 mask = 1UL << bit;
148118 raw_local_irq_save(flags);
149119 res = (mask & *a) != 0;
....@@ -162,13 +132,12 @@
162132 */
163133 int __mips_test_and_change_bit(unsigned long nr, volatile unsigned long *addr)
164134 {
165
- unsigned long *a = (unsigned long *)addr;
166
- unsigned bit = nr & SZLONG_MASK;
135
+ volatile unsigned long *a = &addr[BIT_WORD(nr)];
136
+ unsigned int bit = nr % BITS_PER_LONG;
167137 unsigned long mask;
168138 unsigned long flags;
169139 int res;
170140
171
- a += nr >> SZLONG_LOG;
172141 mask = 1UL << bit;
173142 raw_local_irq_save(flags);
174143 res = (mask & *a) != 0;