Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 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 | |
Thomas Gleixner | c2f21ce | 2009-12-02 20:02:59 +0100 | [diff] [blame] | 20 | #define assert_raw_spin_locked(x) BUG_ON(!raw_spin_is_locked(x)) |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 21 | |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 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); |
Thomas Gleixner | c2f21ce | 2009-12-02 20:02:59 +0100 | [diff] [blame] | 25 | void __lockfunc |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 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); |
Thomas Gleixner | 6b6b479 | 2009-11-16 18:48:37 +0100 | [diff] [blame] | 31 | |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 32 | unsigned long __lockfunc _raw_spin_lock_irqsave(raw_spinlock_t *lock) |
| 33 | __acquires(lock); |
Thomas Gleixner | c2f21ce | 2009-12-02 20:02:59 +0100 | [diff] [blame] | 34 | unsigned long __lockfunc |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 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); |
Thomas Gleixner | c2f21ce | 2009-12-02 20:02:59 +0100 | [diff] [blame] | 42 | void __lockfunc |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 43 | _raw_spin_unlock_irqrestore(raw_spinlock_t *lock, unsigned long flags) |
| 44 | __releases(lock); |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 45 | |
Thomas Gleixner | 6beb000 | 2009-11-09 15:21:34 +0000 | [diff] [blame] | 46 | #ifdef CONFIG_INLINE_SPIN_LOCK |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 47 | #define _raw_spin_lock(lock) __raw_spin_lock(lock) |
Heiko Carstens | 892a7c6 | 2009-08-31 14:43:37 +0200 | [diff] [blame] | 48 | #endif |
| 49 | |
Thomas Gleixner | 6beb000 | 2009-11-09 15:21:34 +0000 | [diff] [blame] | 50 | #ifdef CONFIG_INLINE_SPIN_LOCK_BH |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 51 | #define _raw_spin_lock_bh(lock) __raw_spin_lock_bh(lock) |
Heiko Carstens | 892a7c6 | 2009-08-31 14:43:37 +0200 | [diff] [blame] | 52 | #endif |
| 53 | |
Thomas Gleixner | 6beb000 | 2009-11-09 15:21:34 +0000 | [diff] [blame] | 54 | #ifdef CONFIG_INLINE_SPIN_LOCK_IRQ |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 55 | #define _raw_spin_lock_irq(lock) __raw_spin_lock_irq(lock) |
Heiko Carstens | 892a7c6 | 2009-08-31 14:43:37 +0200 | [diff] [blame] | 56 | #endif |
| 57 | |
Thomas Gleixner | 6beb000 | 2009-11-09 15:21:34 +0000 | [diff] [blame] | 58 | #ifdef CONFIG_INLINE_SPIN_LOCK_IRQSAVE |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 59 | #define _raw_spin_lock_irqsave(lock) __raw_spin_lock_irqsave(lock) |
Heiko Carstens | 892a7c6 | 2009-08-31 14:43:37 +0200 | [diff] [blame] | 60 | #endif |
| 61 | |
Thomas Gleixner | 6beb000 | 2009-11-09 15:21:34 +0000 | [diff] [blame] | 62 | #ifdef CONFIG_INLINE_SPIN_TRYLOCK |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 63 | #define _raw_spin_trylock(lock) __raw_spin_trylock(lock) |
Heiko Carstens | 892a7c6 | 2009-08-31 14:43:37 +0200 | [diff] [blame] | 64 | #endif |
| 65 | |
Thomas Gleixner | 6beb000 | 2009-11-09 15:21:34 +0000 | [diff] [blame] | 66 | #ifdef CONFIG_INLINE_SPIN_TRYLOCK_BH |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 67 | #define _raw_spin_trylock_bh(lock) __raw_spin_trylock_bh(lock) |
Heiko Carstens | 892a7c6 | 2009-08-31 14:43:37 +0200 | [diff] [blame] | 68 | #endif |
| 69 | |
Raghavendra K T | e335e3e | 2012-03-22 15:25:08 +0530 | [diff] [blame] | 70 | #ifndef CONFIG_UNINLINE_SPIN_UNLOCK |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 71 | #define _raw_spin_unlock(lock) __raw_spin_unlock(lock) |
Heiko Carstens | 892a7c6 | 2009-08-31 14:43:37 +0200 | [diff] [blame] | 72 | #endif |
| 73 | |
Thomas Gleixner | 6beb000 | 2009-11-09 15:21:34 +0000 | [diff] [blame] | 74 | #ifdef CONFIG_INLINE_SPIN_UNLOCK_BH |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 75 | #define _raw_spin_unlock_bh(lock) __raw_spin_unlock_bh(lock) |
Heiko Carstens | 892a7c6 | 2009-08-31 14:43:37 +0200 | [diff] [blame] | 76 | #endif |
| 77 | |
Thomas Gleixner | 6beb000 | 2009-11-09 15:21:34 +0000 | [diff] [blame] | 78 | #ifdef CONFIG_INLINE_SPIN_UNLOCK_IRQ |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 79 | #define _raw_spin_unlock_irq(lock) __raw_spin_unlock_irq(lock) |
Heiko Carstens | 892a7c6 | 2009-08-31 14:43:37 +0200 | [diff] [blame] | 80 | #endif |
| 81 | |
Thomas Gleixner | 6beb000 | 2009-11-09 15:21:34 +0000 | [diff] [blame] | 82 | #ifdef CONFIG_INLINE_SPIN_UNLOCK_IRQRESTORE |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 83 | #define _raw_spin_unlock_irqrestore(lock, flags) __raw_spin_unlock_irqrestore(lock, flags) |
Heiko Carstens | 892a7c6 | 2009-08-31 14:43:37 +0200 | [diff] [blame] | 84 | #endif |
| 85 | |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 86 | static inline int __raw_spin_trylock(raw_spinlock_t *lock) |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 87 | { |
| 88 | preempt_disable(); |
Thomas Gleixner | 9828ea9 | 2009-12-03 20:55:53 +0100 | [diff] [blame] | 89 | if (do_raw_spin_trylock(lock)) { |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 90 | spin_acquire(&lock->dep_map, 0, 1, _RET_IP_); |
| 91 | return 1; |
| 92 | } |
| 93 | preempt_enable(); |
| 94 | return 0; |
| 95 | } |
| 96 | |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 97 | /* |
| 98 | * If lockdep is enabled then we use the non-preemption spin-ops |
| 99 | * even on CONFIG_PREEMPT, because lockdep assumes that interrupts are |
| 100 | * not re-enabled during lock-acquire (which the preempt-spin-ops do): |
| 101 | */ |
| 102 | #if !defined(CONFIG_GENERIC_LOCKBREAK) || defined(CONFIG_DEBUG_LOCK_ALLOC) |
| 103 | |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 104 | static inline unsigned long __raw_spin_lock_irqsave(raw_spinlock_t *lock) |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 105 | { |
| 106 | unsigned long flags; |
| 107 | |
| 108 | local_irq_save(flags); |
| 109 | preempt_disable(); |
| 110 | spin_acquire(&lock->dep_map, 0, 0, _RET_IP_); |
| 111 | /* |
| 112 | * On lockdep we dont want the hand-coded irq-enable of |
Thomas Gleixner | 9828ea9 | 2009-12-03 20:55:53 +0100 | [diff] [blame] | 113 | * do_raw_spin_lock_flags() code, because lockdep assumes |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 114 | * that interrupts are not re-enabled during lock-acquire: |
| 115 | */ |
| 116 | #ifdef CONFIG_LOCKDEP |
Thomas Gleixner | 9828ea9 | 2009-12-03 20:55:53 +0100 | [diff] [blame] | 117 | LOCK_CONTENDED(lock, do_raw_spin_trylock, do_raw_spin_lock); |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 118 | #else |
Thomas Gleixner | 9828ea9 | 2009-12-03 20:55:53 +0100 | [diff] [blame] | 119 | do_raw_spin_lock_flags(lock, &flags); |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 120 | #endif |
| 121 | return flags; |
| 122 | } |
| 123 | |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 124 | static inline void __raw_spin_lock_irq(raw_spinlock_t *lock) |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 125 | { |
| 126 | local_irq_disable(); |
| 127 | preempt_disable(); |
| 128 | spin_acquire(&lock->dep_map, 0, 0, _RET_IP_); |
Thomas Gleixner | 9828ea9 | 2009-12-03 20:55:53 +0100 | [diff] [blame] | 129 | LOCK_CONTENDED(lock, do_raw_spin_trylock, do_raw_spin_lock); |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 130 | } |
| 131 | |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 132 | static inline void __raw_spin_lock_bh(raw_spinlock_t *lock) |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 133 | { |
| 134 | local_bh_disable(); |
| 135 | preempt_disable(); |
| 136 | spin_acquire(&lock->dep_map, 0, 0, _RET_IP_); |
Thomas Gleixner | 9828ea9 | 2009-12-03 20:55:53 +0100 | [diff] [blame] | 137 | LOCK_CONTENDED(lock, do_raw_spin_trylock, do_raw_spin_lock); |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 138 | } |
| 139 | |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 140 | static inline void __raw_spin_lock(raw_spinlock_t *lock) |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 141 | { |
| 142 | preempt_disable(); |
| 143 | spin_acquire(&lock->dep_map, 0, 0, _RET_IP_); |
Thomas Gleixner | 9828ea9 | 2009-12-03 20:55:53 +0100 | [diff] [blame] | 144 | LOCK_CONTENDED(lock, do_raw_spin_trylock, do_raw_spin_lock); |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 145 | } |
| 146 | |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 147 | #endif /* CONFIG_PREEMPT */ |
| 148 | |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 149 | static inline void __raw_spin_unlock(raw_spinlock_t *lock) |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 150 | { |
| 151 | spin_release(&lock->dep_map, 1, _RET_IP_); |
Thomas Gleixner | 9828ea9 | 2009-12-03 20:55:53 +0100 | [diff] [blame] | 152 | do_raw_spin_unlock(lock); |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 153 | preempt_enable(); |
| 154 | } |
| 155 | |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 156 | static inline void __raw_spin_unlock_irqrestore(raw_spinlock_t *lock, |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 157 | unsigned long flags) |
| 158 | { |
| 159 | spin_release(&lock->dep_map, 1, _RET_IP_); |
Thomas Gleixner | 9828ea9 | 2009-12-03 20:55:53 +0100 | [diff] [blame] | 160 | do_raw_spin_unlock(lock); |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 161 | local_irq_restore(flags); |
| 162 | preempt_enable(); |
| 163 | } |
| 164 | |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 165 | static inline void __raw_spin_unlock_irq(raw_spinlock_t *lock) |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 166 | { |
| 167 | spin_release(&lock->dep_map, 1, _RET_IP_); |
Thomas Gleixner | 9828ea9 | 2009-12-03 20:55:53 +0100 | [diff] [blame] | 168 | do_raw_spin_unlock(lock); |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 169 | local_irq_enable(); |
| 170 | preempt_enable(); |
| 171 | } |
| 172 | |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 173 | static inline void __raw_spin_unlock_bh(raw_spinlock_t *lock) |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 174 | { |
| 175 | spin_release(&lock->dep_map, 1, _RET_IP_); |
Thomas Gleixner | 9828ea9 | 2009-12-03 20:55:53 +0100 | [diff] [blame] | 176 | do_raw_spin_unlock(lock); |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 177 | preempt_enable_no_resched(); |
| 178 | local_bh_enable_ip((unsigned long)__builtin_return_address(0)); |
| 179 | } |
| 180 | |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 181 | static inline int __raw_spin_trylock_bh(raw_spinlock_t *lock) |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 182 | { |
| 183 | local_bh_disable(); |
| 184 | preempt_disable(); |
Thomas Gleixner | 9828ea9 | 2009-12-03 20:55:53 +0100 | [diff] [blame] | 185 | if (do_raw_spin_trylock(lock)) { |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 186 | spin_acquire(&lock->dep_map, 0, 1, _RET_IP_); |
| 187 | return 1; |
| 188 | } |
| 189 | preempt_enable_no_resched(); |
| 190 | local_bh_enable_ip((unsigned long)__builtin_return_address(0)); |
| 191 | return 0; |
| 192 | } |
| 193 | |
Thomas Gleixner | 6b6b479 | 2009-11-16 18:48:37 +0100 | [diff] [blame] | 194 | #include <linux/rwlock_api_smp.h> |
| 195 | |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 196 | #endif /* __LINUX_SPINLOCK_API_SMP_H */ |