blob: be6517fb9c14e66b4b4b0d7d40e91ac8b56ee06a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (2004) Linus Torvalds
3 *
4 * Author: Zwane Mwaikambo <zwane@fsmlabs.com>
5 *
Ingo Molnarfb1c8f92005-09-10 00:25:56 -07006 * Copyright (2004, 2005) Ingo Molnar
7 *
8 * This file contains the spinlock/rwlock implementations for the
9 * SMP and the DEBUG_SPINLOCK cases. (UP-nondebug inlines them)
Andi Kleen0cb91a22006-09-26 10:52:28 +020010 *
11 * Note that some architectures have special knowledge about the
12 * stack frames of these functions in their profile_pc. If you
13 * change anything significant here that could change the stack
14 * frame contact the architecture maintainers.
Linus Torvalds1da177e2005-04-16 15:20:36 -070015 */
16
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/linkage.h>
18#include <linux/preempt.h>
19#include <linux/spinlock.h>
20#include <linux/interrupt.h>
Ingo Molnar8a25d5d2006-07-03 00:24:54 -070021#include <linux/debug_locks.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/module.h>
23
Thomas Gleixner8e13c7b2009-11-09 15:21:41 +000024/*
25 * If lockdep is enabled then we use the non-preemption spin-ops
26 * even on CONFIG_PREEMPT, because lockdep assumes that interrupts are
27 * not re-enabled during lock-acquire (which the preempt-spin-ops do):
28 */
29#if !defined(CONFIG_GENERIC_LOCKBREAK) || defined(CONFIG_DEBUG_LOCK_ALLOC)
30/*
31 * The __lock_function inlines are taken from
32 * include/linux/spinlock_api_smp.h
33 */
34#else
Thomas Gleixnerc2f21ce2009-12-02 20:02:59 +010035#define raw_read_can_lock(l) read_can_lock(l)
36#define raw_write_can_lock(l) write_can_lock(l)
Thomas Gleixner8e13c7b2009-11-09 15:21:41 +000037/*
38 * We build the __lock_function inlines here. They are too large for
39 * inlining all over the place, but here is only one user per function
40 * which embedds them into the calling _lock_function below.
41 *
42 * This could be a long-held lock. We both prepare to spin for a long
43 * time (making _this_ CPU preemptable if possible), and we also signal
44 * towards that other CPU that it should break the lock ASAP.
45 */
46#define BUILD_LOCK_OPS(op, locktype) \
Thomas Gleixner9c1721a2009-12-03 21:52:18 +010047void __lockfunc __raw_##op##_lock(locktype##_t *lock) \
Thomas Gleixner8e13c7b2009-11-09 15:21:41 +000048{ \
49 for (;;) { \
50 preempt_disable(); \
Thomas Gleixner9828ea92009-12-03 20:55:53 +010051 if (likely(do_raw_##op##_trylock(lock))) \
Thomas Gleixner8e13c7b2009-11-09 15:21:41 +000052 break; \
53 preempt_enable(); \
54 \
55 if (!(lock)->break_lock) \
56 (lock)->break_lock = 1; \
Thomas Gleixnerc2f21ce2009-12-02 20:02:59 +010057 while (!raw_##op##_can_lock(lock) && (lock)->break_lock)\
Thomas Gleixner0199c4e2009-12-02 20:01:25 +010058 arch_##op##_relax(&lock->raw_lock); \
Thomas Gleixner8e13c7b2009-11-09 15:21:41 +000059 } \
60 (lock)->break_lock = 0; \
61} \
62 \
Thomas Gleixner9c1721a2009-12-03 21:52:18 +010063unsigned long __lockfunc __raw_##op##_lock_irqsave(locktype##_t *lock) \
Thomas Gleixner8e13c7b2009-11-09 15:21:41 +000064{ \
65 unsigned long flags; \
66 \
67 for (;;) { \
68 preempt_disable(); \
69 local_irq_save(flags); \
Thomas Gleixner9828ea92009-12-03 20:55:53 +010070 if (likely(do_raw_##op##_trylock(lock))) \
Thomas Gleixner8e13c7b2009-11-09 15:21:41 +000071 break; \
72 local_irq_restore(flags); \
73 preempt_enable(); \
74 \
75 if (!(lock)->break_lock) \
76 (lock)->break_lock = 1; \
Thomas Gleixnerc2f21ce2009-12-02 20:02:59 +010077 while (!raw_##op##_can_lock(lock) && (lock)->break_lock)\
Thomas Gleixner0199c4e2009-12-02 20:01:25 +010078 arch_##op##_relax(&lock->raw_lock); \
Thomas Gleixner8e13c7b2009-11-09 15:21:41 +000079 } \
80 (lock)->break_lock = 0; \
81 return flags; \
82} \
83 \
Thomas Gleixner9c1721a2009-12-03 21:52:18 +010084void __lockfunc __raw_##op##_lock_irq(locktype##_t *lock) \
Thomas Gleixner8e13c7b2009-11-09 15:21:41 +000085{ \
Thomas Gleixner9c1721a2009-12-03 21:52:18 +010086 _raw_##op##_lock_irqsave(lock); \
Thomas Gleixner8e13c7b2009-11-09 15:21:41 +000087} \
88 \
Thomas Gleixner9c1721a2009-12-03 21:52:18 +010089void __lockfunc __raw_##op##_lock_bh(locktype##_t *lock) \
Thomas Gleixner8e13c7b2009-11-09 15:21:41 +000090{ \
91 unsigned long flags; \
92 \
93 /* */ \
94 /* Careful: we must exclude softirqs too, hence the */ \
95 /* irq-disabling. We use the generic preemption-aware */ \
96 /* function: */ \
97 /**/ \
Thomas Gleixner9c1721a2009-12-03 21:52:18 +010098 flags = _raw_##op##_lock_irqsave(lock); \
Thomas Gleixner8e13c7b2009-11-09 15:21:41 +000099 local_bh_disable(); \
100 local_irq_restore(flags); \
101} \
102
103/*
104 * Build preemption-friendly versions of the following
105 * lock-spinning functions:
106 *
107 * __[spin|read|write]_lock()
108 * __[spin|read|write]_lock_irq()
109 * __[spin|read|write]_lock_irqsave()
110 * __[spin|read|write]_lock_bh()
111 */
Thomas Gleixnerc2f21ce2009-12-02 20:02:59 +0100112BUILD_LOCK_OPS(spin, raw_spinlock);
Thomas Gleixner8e13c7b2009-11-09 15:21:41 +0000113BUILD_LOCK_OPS(read, rwlock);
114BUILD_LOCK_OPS(write, rwlock);
115
116#endif
117
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100118#ifndef CONFIG_INLINE_SPIN_TRYLOCK
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100119int __lockfunc _raw_spin_trylock(raw_spinlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100120{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100121 return __raw_spin_trylock(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100122}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100123EXPORT_SYMBOL(_raw_spin_trylock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100124#endif
125
126#ifndef CONFIG_INLINE_SPIN_TRYLOCK_BH
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100127int __lockfunc _raw_spin_trylock_bh(raw_spinlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100128{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100129 return __raw_spin_trylock_bh(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100130}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100131EXPORT_SYMBOL(_raw_spin_trylock_bh);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100132#endif
133
134#ifndef CONFIG_INLINE_SPIN_LOCK
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100135void __lockfunc _raw_spin_lock(raw_spinlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100136{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100137 __raw_spin_lock(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100138}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100139EXPORT_SYMBOL(_raw_spin_lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100140#endif
141
142#ifndef CONFIG_INLINE_SPIN_LOCK_IRQSAVE
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100143unsigned long __lockfunc _raw_spin_lock_irqsave(raw_spinlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100144{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100145 return __raw_spin_lock_irqsave(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100146}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100147EXPORT_SYMBOL(_raw_spin_lock_irqsave);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100148#endif
149
150#ifndef CONFIG_INLINE_SPIN_LOCK_IRQ
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100151void __lockfunc _raw_spin_lock_irq(raw_spinlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100152{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100153 __raw_spin_lock_irq(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100154}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100155EXPORT_SYMBOL(_raw_spin_lock_irq);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100156#endif
157
158#ifndef CONFIG_INLINE_SPIN_LOCK_BH
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100159void __lockfunc _raw_spin_lock_bh(raw_spinlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100160{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100161 __raw_spin_lock_bh(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100162}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100163EXPORT_SYMBOL(_raw_spin_lock_bh);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100164#endif
165
166#ifndef CONFIG_INLINE_SPIN_UNLOCK
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100167void __lockfunc _raw_spin_unlock(raw_spinlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100168{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100169 __raw_spin_unlock(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100170}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100171EXPORT_SYMBOL(_raw_spin_unlock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100172#endif
173
174#ifndef CONFIG_INLINE_SPIN_UNLOCK_IRQRESTORE
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100175void __lockfunc _raw_spin_unlock_irqrestore(raw_spinlock_t *lock, unsigned long flags)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100176{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100177 __raw_spin_unlock_irqrestore(lock, flags);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100178}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100179EXPORT_SYMBOL(_raw_spin_unlock_irqrestore);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100180#endif
181
182#ifndef CONFIG_INLINE_SPIN_UNLOCK_IRQ
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100183void __lockfunc _raw_spin_unlock_irq(raw_spinlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100184{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100185 __raw_spin_unlock_irq(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100186}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100187EXPORT_SYMBOL(_raw_spin_unlock_irq);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100188#endif
189
190#ifndef CONFIG_INLINE_SPIN_UNLOCK_BH
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100191void __lockfunc _raw_spin_unlock_bh(raw_spinlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100192{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100193 __raw_spin_unlock_bh(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100194}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100195EXPORT_SYMBOL(_raw_spin_unlock_bh);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100196#endif
197
198#ifndef CONFIG_INLINE_READ_TRYLOCK
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100199int __lockfunc _raw_read_trylock(rwlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100200{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100201 return __raw_read_trylock(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100202}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100203EXPORT_SYMBOL(_raw_read_trylock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100204#endif
205
206#ifndef CONFIG_INLINE_READ_LOCK
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100207void __lockfunc _raw_read_lock(rwlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100208{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100209 __raw_read_lock(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100210}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100211EXPORT_SYMBOL(_raw_read_lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100212#endif
213
214#ifndef CONFIG_INLINE_READ_LOCK_IRQSAVE
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100215unsigned long __lockfunc _raw_read_lock_irqsave(rwlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100216{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100217 return __raw_read_lock_irqsave(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100218}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100219EXPORT_SYMBOL(_raw_read_lock_irqsave);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100220#endif
221
222#ifndef CONFIG_INLINE_READ_LOCK_IRQ
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100223void __lockfunc _raw_read_lock_irq(rwlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100224{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100225 __raw_read_lock_irq(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100226}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100227EXPORT_SYMBOL(_raw_read_lock_irq);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100228#endif
229
230#ifndef CONFIG_INLINE_READ_LOCK_BH
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100231void __lockfunc _raw_read_lock_bh(rwlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100232{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100233 __raw_read_lock_bh(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100234}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100235EXPORT_SYMBOL(_raw_read_lock_bh);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100236#endif
237
238#ifndef CONFIG_INLINE_READ_UNLOCK
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100239void __lockfunc _raw_read_unlock(rwlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100240{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100241 __raw_read_unlock(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100242}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100243EXPORT_SYMBOL(_raw_read_unlock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100244#endif
245
246#ifndef CONFIG_INLINE_READ_UNLOCK_IRQRESTORE
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100247void __lockfunc _raw_read_unlock_irqrestore(rwlock_t *lock, unsigned long flags)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100248{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100249 __raw_read_unlock_irqrestore(lock, flags);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100250}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100251EXPORT_SYMBOL(_raw_read_unlock_irqrestore);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100252#endif
253
254#ifndef CONFIG_INLINE_READ_UNLOCK_IRQ
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100255void __lockfunc _raw_read_unlock_irq(rwlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100256{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100257 __raw_read_unlock_irq(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100258}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100259EXPORT_SYMBOL(_raw_read_unlock_irq);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100260#endif
261
262#ifndef CONFIG_INLINE_READ_UNLOCK_BH
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100263void __lockfunc _raw_read_unlock_bh(rwlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100264{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100265 __raw_read_unlock_bh(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100266}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100267EXPORT_SYMBOL(_raw_read_unlock_bh);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100268#endif
269
270#ifndef CONFIG_INLINE_WRITE_TRYLOCK
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100271int __lockfunc _raw_write_trylock(rwlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100272{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100273 return __raw_write_trylock(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100274}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100275EXPORT_SYMBOL(_raw_write_trylock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100276#endif
277
278#ifndef CONFIG_INLINE_WRITE_LOCK
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100279void __lockfunc _raw_write_lock(rwlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100280{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100281 __raw_write_lock(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100282}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100283EXPORT_SYMBOL(_raw_write_lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100284#endif
285
286#ifndef CONFIG_INLINE_WRITE_LOCK_IRQSAVE
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100287unsigned long __lockfunc _raw_write_lock_irqsave(rwlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100288{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100289 return __raw_write_lock_irqsave(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100290}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100291EXPORT_SYMBOL(_raw_write_lock_irqsave);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100292#endif
293
294#ifndef CONFIG_INLINE_WRITE_LOCK_IRQ
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100295void __lockfunc _raw_write_lock_irq(rwlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100296{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100297 __raw_write_lock_irq(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100298}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100299EXPORT_SYMBOL(_raw_write_lock_irq);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100300#endif
301
302#ifndef CONFIG_INLINE_WRITE_LOCK_BH
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100303void __lockfunc _raw_write_lock_bh(rwlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100304{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100305 __raw_write_lock_bh(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100306}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100307EXPORT_SYMBOL(_raw_write_lock_bh);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100308#endif
309
310#ifndef CONFIG_INLINE_WRITE_UNLOCK
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100311void __lockfunc _raw_write_unlock(rwlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100312{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100313 __raw_write_unlock(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100314}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100315EXPORT_SYMBOL(_raw_write_unlock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100316#endif
317
318#ifndef CONFIG_INLINE_WRITE_UNLOCK_IRQRESTORE
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100319void __lockfunc _raw_write_unlock_irqrestore(rwlock_t *lock, unsigned long flags)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100320{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100321 __raw_write_unlock_irqrestore(lock, flags);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100322}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100323EXPORT_SYMBOL(_raw_write_unlock_irqrestore);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100324#endif
325
326#ifndef CONFIG_INLINE_WRITE_UNLOCK_IRQ
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100327void __lockfunc _raw_write_unlock_irq(rwlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100328{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100329 __raw_write_unlock_irq(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100330}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100331EXPORT_SYMBOL(_raw_write_unlock_irq);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100332#endif
333
334#ifndef CONFIG_INLINE_WRITE_UNLOCK_BH
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100335void __lockfunc _raw_write_unlock_bh(rwlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100336{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100337 __raw_write_unlock_bh(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100338}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100339EXPORT_SYMBOL(_raw_write_unlock_bh);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100340#endif
341
Thomas Gleixner8e13c7b2009-11-09 15:21:41 +0000342#ifdef CONFIG_DEBUG_LOCK_ALLOC
343
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100344void __lockfunc _raw_spin_lock_nested(raw_spinlock_t *lock, int subclass)
Thomas Gleixner8e13c7b2009-11-09 15:21:41 +0000345{
346 preempt_disable();
347 spin_acquire(&lock->dep_map, subclass, 0, _RET_IP_);
Thomas Gleixner9828ea92009-12-03 20:55:53 +0100348 LOCK_CONTENDED(lock, do_raw_spin_trylock, do_raw_spin_lock);
Thomas Gleixner8e13c7b2009-11-09 15:21:41 +0000349}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100350EXPORT_SYMBOL(_raw_spin_lock_nested);
Thomas Gleixner8e13c7b2009-11-09 15:21:41 +0000351
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100352unsigned long __lockfunc _raw_spin_lock_irqsave_nested(raw_spinlock_t *lock,
Thomas Gleixner8e13c7b2009-11-09 15:21:41 +0000353 int subclass)
354{
355 unsigned long flags;
356
357 local_irq_save(flags);
358 preempt_disable();
359 spin_acquire(&lock->dep_map, subclass, 0, _RET_IP_);
Thomas Gleixner9828ea92009-12-03 20:55:53 +0100360 LOCK_CONTENDED_FLAGS(lock, do_raw_spin_trylock, do_raw_spin_lock,
361 do_raw_spin_lock_flags, &flags);
Thomas Gleixner8e13c7b2009-11-09 15:21:41 +0000362 return flags;
363}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100364EXPORT_SYMBOL(_raw_spin_lock_irqsave_nested);
Thomas Gleixner8e13c7b2009-11-09 15:21:41 +0000365
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100366void __lockfunc _raw_spin_lock_nest_lock(raw_spinlock_t *lock,
Thomas Gleixner8e13c7b2009-11-09 15:21:41 +0000367 struct lockdep_map *nest_lock)
368{
369 preempt_disable();
370 spin_acquire_nest(&lock->dep_map, 0, 0, nest_lock, _RET_IP_);
Thomas Gleixner9828ea92009-12-03 20:55:53 +0100371 LOCK_CONTENDED(lock, do_raw_spin_trylock, do_raw_spin_lock);
Thomas Gleixner8e13c7b2009-11-09 15:21:41 +0000372}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100373EXPORT_SYMBOL(_raw_spin_lock_nest_lock);
Thomas Gleixner8e13c7b2009-11-09 15:21:41 +0000374
375#endif
376
Steven Rostedt0764d232008-05-12 21:20:44 +0200377notrace int in_lock_functions(unsigned long addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378{
379 /* Linker adds these: start and end of __lockfunc functions */
380 extern char __lock_text_start[], __lock_text_end[];
381
382 return addr >= (unsigned long)__lock_text_start
383 && addr < (unsigned long)__lock_text_end;
384}
385EXPORT_SYMBOL(in_lock_functions);