blob: 42dfab89e740aeb08de1896e491607789eacda4b [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
Raghavendra K Te335e3e2012-03-22 15:25:08 +053070#ifndef CONFIG_UNINLINE_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{
Peter Zijlstra9ea4c382013-11-19 16:13:38 +0100134 __local_bh_disable_ip(_RET_IP_, SOFTIRQ_LOCK_OFFSET);
Heiko Carstens69d0ee72009-08-31 14:43:36 +0200135 spin_acquire(&lock->dep_map, 0, 0, _RET_IP_);
Thomas Gleixner9828ea92009-12-03 20:55:53 +0100136 LOCK_CONTENDED(lock, do_raw_spin_trylock, do_raw_spin_lock);
Heiko Carstens69d0ee72009-08-31 14:43:36 +0200137}
138
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100139static inline void __raw_spin_lock(raw_spinlock_t *lock)
Heiko Carstens69d0ee72009-08-31 14:43:36 +0200140{
141 preempt_disable();
142 spin_acquire(&lock->dep_map, 0, 0, _RET_IP_);
Thomas Gleixner9828ea92009-12-03 20:55:53 +0100143 LOCK_CONTENDED(lock, do_raw_spin_trylock, do_raw_spin_lock);
Heiko Carstens69d0ee72009-08-31 14:43:36 +0200144}
145
Chen Gangae584032013-06-19 11:15:46 +0800146#endif /* !CONFIG_GENERIC_LOCKBREAK || CONFIG_DEBUG_LOCK_ALLOC */
Heiko Carstens69d0ee72009-08-31 14:43:36 +0200147
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100148static inline void __raw_spin_unlock(raw_spinlock_t *lock)
Heiko Carstens69d0ee72009-08-31 14:43:36 +0200149{
150 spin_release(&lock->dep_map, 1, _RET_IP_);
Thomas Gleixner9828ea92009-12-03 20:55:53 +0100151 do_raw_spin_unlock(lock);
Heiko Carstens69d0ee72009-08-31 14:43:36 +0200152 preempt_enable();
153}
154
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100155static inline void __raw_spin_unlock_irqrestore(raw_spinlock_t *lock,
Heiko Carstens69d0ee72009-08-31 14:43:36 +0200156 unsigned long flags)
157{
158 spin_release(&lock->dep_map, 1, _RET_IP_);
Thomas Gleixner9828ea92009-12-03 20:55:53 +0100159 do_raw_spin_unlock(lock);
Heiko Carstens69d0ee72009-08-31 14:43:36 +0200160 local_irq_restore(flags);
161 preempt_enable();
162}
163
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100164static inline void __raw_spin_unlock_irq(raw_spinlock_t *lock)
Heiko Carstens69d0ee72009-08-31 14:43:36 +0200165{
166 spin_release(&lock->dep_map, 1, _RET_IP_);
Thomas Gleixner9828ea92009-12-03 20:55:53 +0100167 do_raw_spin_unlock(lock);
Heiko Carstens69d0ee72009-08-31 14:43:36 +0200168 local_irq_enable();
169 preempt_enable();
170}
171
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100172static inline void __raw_spin_unlock_bh(raw_spinlock_t *lock)
Heiko Carstens69d0ee72009-08-31 14:43:36 +0200173{
174 spin_release(&lock->dep_map, 1, _RET_IP_);
Thomas Gleixner9828ea92009-12-03 20:55:53 +0100175 do_raw_spin_unlock(lock);
Peter Zijlstra9ea4c382013-11-19 16:13:38 +0100176 __local_bh_enable_ip(_RET_IP_, SOFTIRQ_LOCK_OFFSET);
Heiko Carstens69d0ee72009-08-31 14:43:36 +0200177}
178
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100179static inline int __raw_spin_trylock_bh(raw_spinlock_t *lock)
Heiko Carstens69d0ee72009-08-31 14:43:36 +0200180{
Peter Zijlstra9ea4c382013-11-19 16:13:38 +0100181 __local_bh_disable_ip(_RET_IP_, SOFTIRQ_LOCK_OFFSET);
Thomas Gleixner9828ea92009-12-03 20:55:53 +0100182 if (do_raw_spin_trylock(lock)) {
Heiko Carstens69d0ee72009-08-31 14:43:36 +0200183 spin_acquire(&lock->dep_map, 0, 1, _RET_IP_);
184 return 1;
185 }
Peter Zijlstra9ea4c382013-11-19 16:13:38 +0100186 __local_bh_enable_ip(_RET_IP_, SOFTIRQ_LOCK_OFFSET);
Heiko Carstens69d0ee72009-08-31 14:43:36 +0200187 return 0;
188}
189
Thomas Gleixner6b6b4792009-11-16 18:48:37 +0100190#include <linux/rwlock_api_smp.h>
191
Ingo Molnarfb1c8f92005-09-10 00:25:56 -0700192#endif /* __LINUX_SPINLOCK_API_SMP_H */