blob: e253ccd7a604c83e003a0db3475bd895b752765b [file] [log] [blame]
Ingo Molnarfb1c8f92005-09-10 00:25:56 -07001#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
18int in_lock_functions(unsigned long addr);
19
Thomas Gleixnerc2f21ce2009-12-02 20:02:59 +010020#define assert_raw_spin_locked(x) BUG_ON(!raw_spin_is_locked(x))
Ingo Molnarfb1c8f92005-09-10 00:25:56 -070021
Thomas Gleixner9c1721a2009-12-03 21:52:18 +010022void __lockfunc _raw_spin_lock(raw_spinlock_t *lock) __acquires(lock);
23void __lockfunc _raw_spin_lock_nested(raw_spinlock_t *lock, int subclass)
24 __acquires(lock);
Thomas Gleixnerc2f21ce2009-12-02 20:02:59 +010025void __lockfunc
Thomas Gleixner9c1721a2009-12-03 21:52:18 +010026_raw_spin_lock_nest_lock(raw_spinlock_t *lock, struct lockdep_map *map)
27 __acquires(lock);
28void __lockfunc _raw_spin_lock_bh(raw_spinlock_t *lock) __acquires(lock);
29void __lockfunc _raw_spin_lock_irq(raw_spinlock_t *lock)
30 __acquires(lock);
Thomas Gleixner6b6b4792009-11-16 18:48:37 +010031
Thomas Gleixner9c1721a2009-12-03 21:52:18 +010032unsigned long __lockfunc _raw_spin_lock_irqsave(raw_spinlock_t *lock)
33 __acquires(lock);
Thomas Gleixnerc2f21ce2009-12-02 20:02:59 +010034unsigned long __lockfunc
Thomas Gleixner9c1721a2009-12-03 21:52:18 +010035_raw_spin_lock_irqsave_nested(raw_spinlock_t *lock, int subclass)
36 __acquires(lock);
37int __lockfunc _raw_spin_trylock(raw_spinlock_t *lock);
38int __lockfunc _raw_spin_trylock_bh(raw_spinlock_t *lock);
39void __lockfunc _raw_spin_unlock(raw_spinlock_t *lock) __releases(lock);
40void __lockfunc _raw_spin_unlock_bh(raw_spinlock_t *lock) __releases(lock);
41void __lockfunc _raw_spin_unlock_irq(raw_spinlock_t *lock) __releases(lock);
Thomas Gleixnerc2f21ce2009-12-02 20:02:59 +010042void __lockfunc
Thomas Gleixner9c1721a2009-12-03 21:52:18 +010043_raw_spin_unlock_irqrestore(raw_spinlock_t *lock, unsigned long flags)
44 __releases(lock);
Ingo Molnarfb1c8f92005-09-10 00:25:56 -070045
Thomas Gleixner6beb0002009-11-09 15:21:34 +000046#ifdef CONFIG_INLINE_SPIN_LOCK
Thomas Gleixner9c1721a2009-12-03 21:52:18 +010047#define _raw_spin_lock(lock) __raw_spin_lock(lock)
Heiko Carstens892a7c62009-08-31 14:43:37 +020048#endif
49
Thomas Gleixner6beb0002009-11-09 15:21:34 +000050#ifdef CONFIG_INLINE_SPIN_LOCK_BH
Thomas Gleixner9c1721a2009-12-03 21:52:18 +010051#define _raw_spin_lock_bh(lock) __raw_spin_lock_bh(lock)
Heiko Carstens892a7c62009-08-31 14:43:37 +020052#endif
53
Thomas Gleixner6beb0002009-11-09 15:21:34 +000054#ifdef CONFIG_INLINE_SPIN_LOCK_IRQ
Thomas Gleixner9c1721a2009-12-03 21:52:18 +010055#define _raw_spin_lock_irq(lock) __raw_spin_lock_irq(lock)
Heiko Carstens892a7c62009-08-31 14:43:37 +020056#endif
57
Thomas Gleixner6beb0002009-11-09 15:21:34 +000058#ifdef CONFIG_INLINE_SPIN_LOCK_IRQSAVE
Thomas Gleixner9c1721a2009-12-03 21:52:18 +010059#define _raw_spin_lock_irqsave(lock) __raw_spin_lock_irqsave(lock)
Heiko Carstens892a7c62009-08-31 14:43:37 +020060#endif
61
Thomas Gleixner6beb0002009-11-09 15:21:34 +000062#ifdef CONFIG_INLINE_SPIN_TRYLOCK
Thomas Gleixner9c1721a2009-12-03 21:52:18 +010063#define _raw_spin_trylock(lock) __raw_spin_trylock(lock)
Heiko Carstens892a7c62009-08-31 14:43:37 +020064#endif
65
Thomas Gleixner6beb0002009-11-09 15:21:34 +000066#ifdef CONFIG_INLINE_SPIN_TRYLOCK_BH
Thomas Gleixner9c1721a2009-12-03 21:52:18 +010067#define _raw_spin_trylock_bh(lock) __raw_spin_trylock_bh(lock)
Heiko Carstens892a7c62009-08-31 14:43:37 +020068#endif
69
Thomas Gleixner6beb0002009-11-09 15:21:34 +000070#ifdef CONFIG_INLINE_SPIN_UNLOCK
Thomas Gleixner9c1721a2009-12-03 21:52:18 +010071#define _raw_spin_unlock(lock) __raw_spin_unlock(lock)
Heiko Carstens892a7c62009-08-31 14:43:37 +020072#endif
73
Thomas Gleixner6beb0002009-11-09 15:21:34 +000074#ifdef CONFIG_INLINE_SPIN_UNLOCK_BH
Thomas Gleixner9c1721a2009-12-03 21:52:18 +010075#define _raw_spin_unlock_bh(lock) __raw_spin_unlock_bh(lock)
Heiko Carstens892a7c62009-08-31 14:43:37 +020076#endif
77
Thomas Gleixner6beb0002009-11-09 15:21:34 +000078#ifdef CONFIG_INLINE_SPIN_UNLOCK_IRQ
Thomas Gleixner9c1721a2009-12-03 21:52:18 +010079#define _raw_spin_unlock_irq(lock) __raw_spin_unlock_irq(lock)
Heiko Carstens892a7c62009-08-31 14:43:37 +020080#endif
81
Thomas Gleixner6beb0002009-11-09 15:21:34 +000082#ifdef CONFIG_INLINE_SPIN_UNLOCK_IRQRESTORE
Thomas Gleixner9c1721a2009-12-03 21:52:18 +010083#define _raw_spin_unlock_irqrestore(lock, flags) __raw_spin_unlock_irqrestore(lock, flags)
Heiko Carstens892a7c62009-08-31 14:43:37 +020084#endif
85
Thomas Gleixner9c1721a2009-12-03 21:52:18 +010086static inline int __raw_spin_trylock(raw_spinlock_t *lock)
Heiko Carstens69d0ee72009-08-31 14:43:36 +020087{
88 preempt_disable();
Thomas Gleixner9828ea92009-12-03 20:55:53 +010089 if (do_raw_spin_trylock(lock)) {
Heiko Carstens69d0ee72009-08-31 14:43:36 +020090 spin_acquire(&lock->dep_map, 0, 1, _RET_IP_);
91 return 1;
92 }
93 preempt_enable();
94 return 0;
95}
96
Heiko Carstens69d0ee72009-08-31 14:43:36 +020097/*
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 Gleixner9c1721a2009-12-03 21:52:18 +0100104static inline unsigned long __raw_spin_lock_irqsave(raw_spinlock_t *lock)
Heiko Carstens69d0ee72009-08-31 14:43:36 +0200105{
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 Gleixner9828ea92009-12-03 20:55:53 +0100113 * do_raw_spin_lock_flags() code, because lockdep assumes
Heiko Carstens69d0ee72009-08-31 14:43:36 +0200114 * that interrupts are not re-enabled during lock-acquire:
115 */
116#ifdef CONFIG_LOCKDEP
Thomas Gleixner9828ea92009-12-03 20:55:53 +0100117 LOCK_CONTENDED(lock, do_raw_spin_trylock, do_raw_spin_lock);
Heiko Carstens69d0ee72009-08-31 14:43:36 +0200118#else
Thomas Gleixner9828ea92009-12-03 20:55:53 +0100119 do_raw_spin_lock_flags(lock, &flags);
Heiko Carstens69d0ee72009-08-31 14:43:36 +0200120#endif
121 return flags;
122}
123
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100124static inline void __raw_spin_lock_irq(raw_spinlock_t *lock)
Heiko Carstens69d0ee72009-08-31 14:43:36 +0200125{
126 local_irq_disable();
127 preempt_disable();
128 spin_acquire(&lock->dep_map, 0, 0, _RET_IP_);
Thomas Gleixner9828ea92009-12-03 20:55:53 +0100129 LOCK_CONTENDED(lock, do_raw_spin_trylock, do_raw_spin_lock);
Heiko Carstens69d0ee72009-08-31 14:43:36 +0200130}
131
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100132static inline void __raw_spin_lock_bh(raw_spinlock_t *lock)
Heiko Carstens69d0ee72009-08-31 14:43:36 +0200133{
134 local_bh_disable();
135 preempt_disable();
136 spin_acquire(&lock->dep_map, 0, 0, _RET_IP_);
Thomas Gleixner9828ea92009-12-03 20:55:53 +0100137 LOCK_CONTENDED(lock, do_raw_spin_trylock, do_raw_spin_lock);
Heiko Carstens69d0ee72009-08-31 14:43:36 +0200138}
139
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100140static inline void __raw_spin_lock(raw_spinlock_t *lock)
Heiko Carstens69d0ee72009-08-31 14:43:36 +0200141{
142 preempt_disable();
143 spin_acquire(&lock->dep_map, 0, 0, _RET_IP_);
Thomas Gleixner9828ea92009-12-03 20:55:53 +0100144 LOCK_CONTENDED(lock, do_raw_spin_trylock, do_raw_spin_lock);
Heiko Carstens69d0ee72009-08-31 14:43:36 +0200145}
146
Heiko Carstens69d0ee72009-08-31 14:43:36 +0200147#endif /* CONFIG_PREEMPT */
148
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100149static inline void __raw_spin_unlock(raw_spinlock_t *lock)
Heiko Carstens69d0ee72009-08-31 14:43:36 +0200150{
151 spin_release(&lock->dep_map, 1, _RET_IP_);
Thomas Gleixner9828ea92009-12-03 20:55:53 +0100152 do_raw_spin_unlock(lock);
Heiko Carstens69d0ee72009-08-31 14:43:36 +0200153 preempt_enable();
154}
155
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100156static inline void __raw_spin_unlock_irqrestore(raw_spinlock_t *lock,
Heiko Carstens69d0ee72009-08-31 14:43:36 +0200157 unsigned long flags)
158{
159 spin_release(&lock->dep_map, 1, _RET_IP_);
Thomas Gleixner9828ea92009-12-03 20:55:53 +0100160 do_raw_spin_unlock(lock);
Heiko Carstens69d0ee72009-08-31 14:43:36 +0200161 local_irq_restore(flags);
162 preempt_enable();
163}
164
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100165static inline void __raw_spin_unlock_irq(raw_spinlock_t *lock)
Heiko Carstens69d0ee72009-08-31 14:43:36 +0200166{
167 spin_release(&lock->dep_map, 1, _RET_IP_);
Thomas Gleixner9828ea92009-12-03 20:55:53 +0100168 do_raw_spin_unlock(lock);
Heiko Carstens69d0ee72009-08-31 14:43:36 +0200169 local_irq_enable();
170 preempt_enable();
171}
172
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100173static inline void __raw_spin_unlock_bh(raw_spinlock_t *lock)
Heiko Carstens69d0ee72009-08-31 14:43:36 +0200174{
175 spin_release(&lock->dep_map, 1, _RET_IP_);
Thomas Gleixner9828ea92009-12-03 20:55:53 +0100176 do_raw_spin_unlock(lock);
Heiko Carstens69d0ee72009-08-31 14:43:36 +0200177 preempt_enable_no_resched();
178 local_bh_enable_ip((unsigned long)__builtin_return_address(0));
179}
180
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100181static inline int __raw_spin_trylock_bh(raw_spinlock_t *lock)
Heiko Carstens69d0ee72009-08-31 14:43:36 +0200182{
183 local_bh_disable();
184 preempt_disable();
Thomas Gleixner9828ea92009-12-03 20:55:53 +0100185 if (do_raw_spin_trylock(lock)) {
Heiko Carstens69d0ee72009-08-31 14:43:36 +0200186 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 Gleixner6b6b4792009-11-16 18:48:37 +0100194#include <linux/rwlock_api_smp.h>
195
Ingo Molnarfb1c8f92005-09-10 00:25:56 -0700196#endif /* __LINUX_SPINLOCK_API_SMP_H */