Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
bitops.c
Go to the documentation of this file.
1 /*
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
4  * for more details.
5  *
6  * Copyright (c) 1994-1997, 99, 2000, 06, 07 Ralf Baechle ([email protected])
7  * Copyright (c) 1999, 2000 Silicon Graphics, Inc.
8  */
9 #include <linux/bitops.h>
10 #include <linux/irqflags.h>
11 #include <linux/export.h>
12 
13 
20 void __mips_set_bit(unsigned long nr, volatile unsigned long *addr)
21 {
22  volatile unsigned long *a = addr;
23  unsigned bit = nr & SZLONG_MASK;
24  unsigned long mask;
25  unsigned long flags;
26 
27  a += nr >> SZLONG_LOG;
28  mask = 1UL << bit;
29  raw_local_irq_save(flags);
30  *a |= mask;
31  raw_local_irq_restore(flags);
32 }
34 
35 
42 void __mips_clear_bit(unsigned long nr, volatile unsigned long *addr)
43 {
44  volatile unsigned long *a = addr;
45  unsigned bit = nr & SZLONG_MASK;
46  unsigned long mask;
47  unsigned long flags;
48 
49  a += nr >> SZLONG_LOG;
50  mask = 1UL << bit;
51  raw_local_irq_save(flags);
52  *a &= ~mask;
53  raw_local_irq_restore(flags);
54 }
56 
57 
64 void __mips_change_bit(unsigned long nr, volatile unsigned long *addr)
65 {
66  volatile unsigned long *a = addr;
67  unsigned bit = nr & SZLONG_MASK;
68  unsigned long mask;
69  unsigned long flags;
70 
71  a += nr >> SZLONG_LOG;
72  mask = 1UL << bit;
73  raw_local_irq_save(flags);
74  *a ^= mask;
75  raw_local_irq_restore(flags);
76 }
78 
79 
86 int __mips_test_and_set_bit(unsigned long nr,
87  volatile unsigned long *addr)
88 {
89  volatile unsigned long *a = addr;
90  unsigned bit = nr & SZLONG_MASK;
91  unsigned long mask;
92  unsigned long flags;
93  unsigned long res;
94 
95  a += nr >> SZLONG_LOG;
96  mask = 1UL << bit;
97  raw_local_irq_save(flags);
98  res = (mask & *a);
99  *a |= mask;
100  raw_local_irq_restore(flags);
101  return res;
102 }
104 
105 
113  volatile unsigned long *addr)
114 {
115  volatile unsigned long *a = addr;
116  unsigned bit = nr & SZLONG_MASK;
117  unsigned long mask;
118  unsigned long flags;
119  unsigned long res;
120 
121  a += nr >> SZLONG_LOG;
122  mask = 1UL << bit;
123  raw_local_irq_save(flags);
124  res = (mask & *a);
125  *a |= mask;
126  raw_local_irq_restore(flags);
127  return res;
128 }
130 
131 
138 int __mips_test_and_clear_bit(unsigned long nr, volatile unsigned long *addr)
139 {
140  volatile unsigned long *a = addr;
141  unsigned bit = nr & SZLONG_MASK;
142  unsigned long mask;
143  unsigned long flags;
144  unsigned long res;
145 
146  a += nr >> SZLONG_LOG;
147  mask = 1UL << bit;
148  raw_local_irq_save(flags);
149  res = (mask & *a);
150  *a &= ~mask;
151  raw_local_irq_restore(flags);
152  return res;
153 }
155 
156 
163 int __mips_test_and_change_bit(unsigned long nr, volatile unsigned long *addr)
164 {
165  volatile unsigned long *a = addr;
166  unsigned bit = nr & SZLONG_MASK;
167  unsigned long mask;
168  unsigned long flags;
169  unsigned long res;
170 
171  a += nr >> SZLONG_LOG;
172  mask = 1UL << bit;
173  raw_local_irq_save(flags);
174  res = (mask & *a);
175  *a ^= mask;
176  raw_local_irq_restore(flags);
177  return res;
178 }