Commit | Line | Data |
---|---|---|
fb1c8f93 IM |
1 | #ifndef __LINUX_SPINLOCK_API_SMP_H |
2 | #define __LINUX_SPINLOCK_API_SMP_H | |
3 | ||
4 | #ifndef __LINUX_SPINLOCK_H | |
5 | # error "please don't include this file directly" | |
6 | #endif | |
7 | ||
8 | /* | |
9 | * include/linux/spinlock_api_smp.h | |
10 | * | |
11 | * spinlock API declarations on SMP (and debug) | |
12 | * (implemented in kernel/spinlock.c) | |
13 | * | |
14 | * portions Copyright 2005, Red Hat, Inc., Ingo Molnar | |
15 | * Released under the General Public License (GPL). | |
16 | */ | |
17 | ||
18 | int in_lock_functions(unsigned long addr); | |
19 | ||
c2f21ce2 | 20 | #define assert_raw_spin_locked(x) BUG_ON(!raw_spin_is_locked(x)) |
fb1c8f93 | 21 | |
9c1721aa TG |
22 | void __lockfunc _raw_spin_lock(raw_spinlock_t *lock) __acquires(lock); |
23 | void __lockfunc _raw_spin_lock_nested(raw_spinlock_t *lock, int subclass) | |
24 | __acquires(lock); | |
c2f21ce2 | 25 | void __lockfunc |
9c1721aa TG |
26 | _raw_spin_lock_nest_lock(raw_spinlock_t *lock, struct lockdep_map *map) |
27 | __acquires(lock); | |
28 | void __lockfunc _raw_spin_lock_bh(raw_spinlock_t *lock) __acquires(lock); | |
29 | void __lockfunc _raw_spin_lock_irq(raw_spinlock_t *lock) | |
30 | __acquires(lock); | |
31 | ||
32 | unsigned long __lockfunc _raw_spin_lock_irqsave(raw_spinlock_t *lock) | |
33 | __acquires(lock); | |
c2f21ce2 | 34 | unsigned long __lockfunc |
9c1721aa TG |
35 | _raw_spin_lock_irqsave_nested(raw_spinlock_t *lock, int subclass) |
36 | __acquires(lock); | |
37 | int __lockfunc _raw_spin_trylock(raw_spinlock_t *lock); | |
38 | int __lockfunc _raw_spin_trylock_bh(raw_spinlock_t *lock); | |
39 | void __lockfunc _raw_spin_unlock(raw_spinlock_t *lock) __releases(lock); | |
40 | void __lockfunc _raw_spin_unlock_bh(raw_spinlock_t *lock) __releases(lock); | |
41 | void __lockfunc _raw_spin_unlock_irq(raw_spinlock_t *lock) __releases(lock); | |
c2f21ce2 | 42 | void __lockfunc |
9c1721aa TG |
43 | _raw_spin_unlock_irqrestore(raw_spinlock_t *lock, unsigned long flags) |
44 | __releases(lock); | |
fb1c8f93 | 45 | |
6beb0009 | 46 | #ifdef CONFIG_INLINE_SPIN_LOCK |
9c1721aa | 47 | #define _raw_spin_lock(lock) __raw_spin_lock(lock) |
892a7c67 HC |
48 | #endif |
49 | ||
6beb0009 | 50 | #ifdef CONFIG_INLINE_SPIN_LOCK_BH |
9c1721aa | 51 | #define _raw_spin_lock_bh(lock) __raw_spin_lock_bh(lock) |
892a7c67 HC |
52 | #endif |
53 | ||
6beb0009 | 54 | #ifdef CONFIG_INLINE_SPIN_LOCK_IRQ |
9c1721aa | 55 | #define _raw_spin_lock_irq(lock) __raw_spin_lock_irq(lock) |
892a7c67 HC |
56 | #endif |
57 | ||
6beb0009 | 58 | #ifdef CONFIG_INLINE_SPIN_LOCK_IRQSAVE |
9c1721aa | 59 | #define _raw_spin_lock_irqsave(lock) __raw_spin_lock_irqsave(lock) |
892a7c67 HC |
60 | #endif |
61 | ||
6beb0009 | 62 | #ifdef CONFIG_INLINE_SPIN_TRYLOCK |
9c1721aa | 63 | #define _raw_spin_trylock(lock) __raw_spin_trylock(lock) |
892a7c67 HC |
64 | #endif |
65 | ||
6beb0009 | 66 | #ifdef CONFIG_INLINE_SPIN_TRYLOCK_BH |
9c1721aa | 67 | #define _raw_spin_trylock_bh(lock) __raw_spin_trylock_bh(lock) |
892a7c67 HC |
68 | #endif |
69 | ||
e335e3eb | 70 | #ifndef CONFIG_UNINLINE_SPIN_UNLOCK |
9c1721aa | 71 | #define _raw_spin_unlock(lock) __raw_spin_unlock(lock) |
892a7c67 HC |
72 | #endif |
73 | ||
6beb0009 | 74 | #ifdef CONFIG_INLINE_SPIN_UNLOCK_BH |
9c1721aa | 75 | #define _raw_spin_unlock_bh(lock) __raw_spin_unlock_bh(lock) |
892a7c67 HC |
76 | #endif |
77 | ||
6beb0009 | 78 | #ifdef CONFIG_INLINE_SPIN_UNLOCK_IRQ |
9c1721aa | 79 | #define _raw_spin_unlock_irq(lock) __raw_spin_unlock_irq(lock) |
892a7c67 HC |
80 | #endif |
81 | ||
6beb0009 | 82 | #ifdef CONFIG_INLINE_SPIN_UNLOCK_IRQRESTORE |
9c1721aa | 83 | #define _raw_spin_unlock_irqrestore(lock, flags) __raw_spin_unlock_irqrestore(lock, flags) |
892a7c67 HC |
84 | #endif |
85 | ||
9c1721aa | 86 | static inline int __raw_spin_trylock(raw_spinlock_t *lock) |
69d0ee73 HC |
87 | { |
88 | preempt_disable(); | |
9828ea9d | 89 | if (do_raw_spin_trylock(lock)) { |
70e37fad | 90 | dbg_snapshot_spinlock(lock, 1); |
69d0ee73 | 91 | spin_acquire(&lock->dep_map, 0, 1, _RET_IP_); |
70e37fad | 92 | dbg_snapshot_spinlock(lock, 2); |
69d0ee73 HC |
93 | return 1; |
94 | } | |
95 | preempt_enable(); | |
96 | return 0; | |
97 | } | |
98 | ||
69d0ee73 HC |
99 | /* |
100 | * If lockdep is enabled then we use the non-preemption spin-ops | |
101 | * even on CONFIG_PREEMPT, because lockdep assumes that interrupts are | |
102 | * not re-enabled during lock-acquire (which the preempt-spin-ops do): | |
103 | */ | |
104 | #if !defined(CONFIG_GENERIC_LOCKBREAK) || defined(CONFIG_DEBUG_LOCK_ALLOC) | |
105 | ||
9c1721aa | 106 | static inline unsigned long __raw_spin_lock_irqsave(raw_spinlock_t *lock) |
69d0ee73 HC |
107 | { |
108 | unsigned long flags; | |
109 | ||
110 | local_irq_save(flags); | |
111 | preempt_disable(); | |
a55d78d4 | 112 | dbg_snapshot_spinlock(lock, 1); |
69d0ee73 HC |
113 | spin_acquire(&lock->dep_map, 0, 0, _RET_IP_); |
114 | /* | |
115 | * On lockdep we dont want the hand-coded irq-enable of | |
9828ea9d | 116 | * do_raw_spin_lock_flags() code, because lockdep assumes |
69d0ee73 HC |
117 | * that interrupts are not re-enabled during lock-acquire: |
118 | */ | |
119 | #ifdef CONFIG_LOCKDEP | |
9828ea9d | 120 | LOCK_CONTENDED(lock, do_raw_spin_trylock, do_raw_spin_lock); |
69d0ee73 | 121 | #else |
9828ea9d | 122 | do_raw_spin_lock_flags(lock, &flags); |
69d0ee73 | 123 | #endif |
a55d78d4 | 124 | dbg_snapshot_spinlock(lock, 2); |
69d0ee73 HC |
125 | return flags; |
126 | } | |
127 | ||
9c1721aa | 128 | static inline void __raw_spin_lock_irq(raw_spinlock_t *lock) |
69d0ee73 HC |
129 | { |
130 | local_irq_disable(); | |
131 | preempt_disable(); | |
a55d78d4 | 132 | dbg_snapshot_spinlock(lock, 1); |
69d0ee73 | 133 | spin_acquire(&lock->dep_map, 0, 0, _RET_IP_); |
9828ea9d | 134 | LOCK_CONTENDED(lock, do_raw_spin_trylock, do_raw_spin_lock); |
a55d78d4 | 135 | dbg_snapshot_spinlock(lock, 2); |
69d0ee73 HC |
136 | } |
137 | ||
9c1721aa | 138 | static inline void __raw_spin_lock_bh(raw_spinlock_t *lock) |
69d0ee73 | 139 | { |
9ea4c380 | 140 | __local_bh_disable_ip(_RET_IP_, SOFTIRQ_LOCK_OFFSET); |
69d0ee73 | 141 | spin_acquire(&lock->dep_map, 0, 0, _RET_IP_); |
9828ea9d | 142 | LOCK_CONTENDED(lock, do_raw_spin_trylock, do_raw_spin_lock); |
69d0ee73 HC |
143 | } |
144 | ||
9c1721aa | 145 | static inline void __raw_spin_lock(raw_spinlock_t *lock) |
69d0ee73 HC |
146 | { |
147 | preempt_disable(); | |
a55d78d4 | 148 | dbg_snapshot_spinlock(lock, 1); |
69d0ee73 | 149 | spin_acquire(&lock->dep_map, 0, 0, _RET_IP_); |
9828ea9d | 150 | LOCK_CONTENDED(lock, do_raw_spin_trylock, do_raw_spin_lock); |
a55d78d4 | 151 | dbg_snapshot_spinlock(lock, 2); |
69d0ee73 HC |
152 | } |
153 | ||
ae58403f | 154 | #endif /* !CONFIG_GENERIC_LOCKBREAK || CONFIG_DEBUG_LOCK_ALLOC */ |
69d0ee73 | 155 | |
9c1721aa | 156 | static inline void __raw_spin_unlock(raw_spinlock_t *lock) |
69d0ee73 HC |
157 | { |
158 | spin_release(&lock->dep_map, 1, _RET_IP_); | |
a55d78d4 | 159 | dbg_snapshot_spinlock(lock, 3); |
b9049efa | 160 | do_raw_spin_unlock(lock); |
69d0ee73 HC |
161 | preempt_enable(); |
162 | } | |
163 | ||
9c1721aa | 164 | static inline void __raw_spin_unlock_irqrestore(raw_spinlock_t *lock, |
69d0ee73 HC |
165 | unsigned long flags) |
166 | { | |
167 | spin_release(&lock->dep_map, 1, _RET_IP_); | |
9828ea9d | 168 | do_raw_spin_unlock(lock); |
a55d78d4 | 169 | dbg_snapshot_spinlock(lock, 3); |
69d0ee73 HC |
170 | local_irq_restore(flags); |
171 | preempt_enable(); | |
172 | } | |
173 | ||
9c1721aa | 174 | static inline void __raw_spin_unlock_irq(raw_spinlock_t *lock) |
69d0ee73 HC |
175 | { |
176 | spin_release(&lock->dep_map, 1, _RET_IP_); | |
9828ea9d | 177 | do_raw_spin_unlock(lock); |
a55d78d4 | 178 | dbg_snapshot_spinlock(lock, 3); |
69d0ee73 HC |
179 | local_irq_enable(); |
180 | preempt_enable(); | |
181 | } | |
182 | ||
9c1721aa | 183 | static inline void __raw_spin_unlock_bh(raw_spinlock_t *lock) |
69d0ee73 HC |
184 | { |
185 | spin_release(&lock->dep_map, 1, _RET_IP_); | |
9828ea9d | 186 | do_raw_spin_unlock(lock); |
9ea4c380 | 187 | __local_bh_enable_ip(_RET_IP_, SOFTIRQ_LOCK_OFFSET); |
69d0ee73 HC |
188 | } |
189 | ||
9c1721aa | 190 | static inline int __raw_spin_trylock_bh(raw_spinlock_t *lock) |
69d0ee73 | 191 | { |
9ea4c380 | 192 | __local_bh_disable_ip(_RET_IP_, SOFTIRQ_LOCK_OFFSET); |
9828ea9d | 193 | if (do_raw_spin_trylock(lock)) { |
69d0ee73 HC |
194 | spin_acquire(&lock->dep_map, 0, 1, _RET_IP_); |
195 | return 1; | |
196 | } | |
9ea4c380 | 197 | __local_bh_enable_ip(_RET_IP_, SOFTIRQ_LOCK_OFFSET); |
69d0ee73 HC |
198 | return 0; |
199 | } | |
200 | ||
6b6b4792 TG |
201 | #include <linux/rwlock_api_smp.h> |
202 | ||
fb1c8f93 | 203 | #endif /* __LINUX_SPINLOCK_API_SMP_H */ |