blob: db3ccb1dd614800e006c0a8cfd99b9c40aae124a [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>
Paul Gortmaker9984de12011-05-23 14:51:41 -040022#include <linux/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
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)
Will Deaconc14c3382013-09-11 14:23:23 -070037
38/*
39 * Some architectures can relax in favour of the CPU owning the lock.
40 */
41#ifndef arch_read_relax
42# define arch_read_relax(l) cpu_relax()
43#endif
44#ifndef arch_write_relax
45# define arch_write_relax(l) cpu_relax()
46#endif
47#ifndef arch_spin_relax
48# define arch_spin_relax(l) cpu_relax()
49#endif
50
Thomas Gleixner8e13c7b2009-11-09 15:21:41 +000051/*
52 * We build the __lock_function inlines here. They are too large for
53 * inlining all over the place, but here is only one user per function
54 * which embedds them into the calling _lock_function below.
55 *
56 * This could be a long-held lock. We both prepare to spin for a long
57 * time (making _this_ CPU preemptable if possible), and we also signal
58 * towards that other CPU that it should break the lock ASAP.
59 */
60#define BUILD_LOCK_OPS(op, locktype) \
Thomas Gleixner9c1721a2009-12-03 21:52:18 +010061void __lockfunc __raw_##op##_lock(locktype##_t *lock) \
Thomas Gleixner8e13c7b2009-11-09 15:21:41 +000062{ \
63 for (;;) { \
64 preempt_disable(); \
Thomas Gleixner9828ea92009-12-03 20:55:53 +010065 if (likely(do_raw_##op##_trylock(lock))) \
Thomas Gleixner8e13c7b2009-11-09 15:21:41 +000066 break; \
67 preempt_enable(); \
68 \
69 if (!(lock)->break_lock) \
70 (lock)->break_lock = 1; \
Thomas Gleixnerc2f21ce2009-12-02 20:02:59 +010071 while (!raw_##op##_can_lock(lock) && (lock)->break_lock)\
Thomas Gleixner0199c4e2009-12-02 20:01:25 +010072 arch_##op##_relax(&lock->raw_lock); \
Thomas Gleixner8e13c7b2009-11-09 15:21:41 +000073 } \
74 (lock)->break_lock = 0; \
75} \
76 \
Thomas Gleixner9c1721a2009-12-03 21:52:18 +010077unsigned long __lockfunc __raw_##op##_lock_irqsave(locktype##_t *lock) \
Thomas Gleixner8e13c7b2009-11-09 15:21:41 +000078{ \
79 unsigned long flags; \
80 \
81 for (;;) { \
82 preempt_disable(); \
83 local_irq_save(flags); \
Thomas Gleixner9828ea92009-12-03 20:55:53 +010084 if (likely(do_raw_##op##_trylock(lock))) \
Thomas Gleixner8e13c7b2009-11-09 15:21:41 +000085 break; \
86 local_irq_restore(flags); \
87 preempt_enable(); \
88 \
89 if (!(lock)->break_lock) \
90 (lock)->break_lock = 1; \
Thomas Gleixnerc2f21ce2009-12-02 20:02:59 +010091 while (!raw_##op##_can_lock(lock) && (lock)->break_lock)\
Thomas Gleixner0199c4e2009-12-02 20:01:25 +010092 arch_##op##_relax(&lock->raw_lock); \
Thomas Gleixner8e13c7b2009-11-09 15:21:41 +000093 } \
94 (lock)->break_lock = 0; \
95 return flags; \
96} \
97 \
Thomas Gleixner9c1721a2009-12-03 21:52:18 +010098void __lockfunc __raw_##op##_lock_irq(locktype##_t *lock) \
Thomas Gleixner8e13c7b2009-11-09 15:21:41 +000099{ \
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100100 _raw_##op##_lock_irqsave(lock); \
Thomas Gleixner8e13c7b2009-11-09 15:21:41 +0000101} \
102 \
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100103void __lockfunc __raw_##op##_lock_bh(locktype##_t *lock) \
Thomas Gleixner8e13c7b2009-11-09 15:21:41 +0000104{ \
105 unsigned long flags; \
106 \
107 /* */ \
108 /* Careful: we must exclude softirqs too, hence the */ \
109 /* irq-disabling. We use the generic preemption-aware */ \
110 /* function: */ \
111 /**/ \
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100112 flags = _raw_##op##_lock_irqsave(lock); \
Thomas Gleixner8e13c7b2009-11-09 15:21:41 +0000113 local_bh_disable(); \
114 local_irq_restore(flags); \
115} \
116
117/*
118 * Build preemption-friendly versions of the following
119 * lock-spinning functions:
120 *
121 * __[spin|read|write]_lock()
122 * __[spin|read|write]_lock_irq()
123 * __[spin|read|write]_lock_irqsave()
124 * __[spin|read|write]_lock_bh()
125 */
Thomas Gleixnerc2f21ce2009-12-02 20:02:59 +0100126BUILD_LOCK_OPS(spin, raw_spinlock);
Thomas Gleixner8e13c7b2009-11-09 15:21:41 +0000127BUILD_LOCK_OPS(read, rwlock);
128BUILD_LOCK_OPS(write, rwlock);
129
130#endif
131
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100132#ifndef CONFIG_INLINE_SPIN_TRYLOCK
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100133int __lockfunc _raw_spin_trylock(raw_spinlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100134{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100135 return __raw_spin_trylock(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100136}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100137EXPORT_SYMBOL(_raw_spin_trylock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100138#endif
139
140#ifndef CONFIG_INLINE_SPIN_TRYLOCK_BH
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100141int __lockfunc _raw_spin_trylock_bh(raw_spinlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100142{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100143 return __raw_spin_trylock_bh(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100144}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100145EXPORT_SYMBOL(_raw_spin_trylock_bh);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100146#endif
147
148#ifndef CONFIG_INLINE_SPIN_LOCK
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100149void __lockfunc _raw_spin_lock(raw_spinlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100150{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100151 __raw_spin_lock(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100152}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100153EXPORT_SYMBOL(_raw_spin_lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100154#endif
155
156#ifndef CONFIG_INLINE_SPIN_LOCK_IRQSAVE
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100157unsigned long __lockfunc _raw_spin_lock_irqsave(raw_spinlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100158{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100159 return __raw_spin_lock_irqsave(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100160}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100161EXPORT_SYMBOL(_raw_spin_lock_irqsave);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100162#endif
163
164#ifndef CONFIG_INLINE_SPIN_LOCK_IRQ
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100165void __lockfunc _raw_spin_lock_irq(raw_spinlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100166{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100167 __raw_spin_lock_irq(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100168}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100169EXPORT_SYMBOL(_raw_spin_lock_irq);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100170#endif
171
172#ifndef CONFIG_INLINE_SPIN_LOCK_BH
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100173void __lockfunc _raw_spin_lock_bh(raw_spinlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100174{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100175 __raw_spin_lock_bh(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100176}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100177EXPORT_SYMBOL(_raw_spin_lock_bh);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100178#endif
179
Raghavendra K Te335e3e2012-03-22 15:25:08 +0530180#ifdef CONFIG_UNINLINE_SPIN_UNLOCK
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100181void __lockfunc _raw_spin_unlock(raw_spinlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100182{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100183 __raw_spin_unlock(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100184}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100185EXPORT_SYMBOL(_raw_spin_unlock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100186#endif
187
188#ifndef CONFIG_INLINE_SPIN_UNLOCK_IRQRESTORE
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100189void __lockfunc _raw_spin_unlock_irqrestore(raw_spinlock_t *lock, unsigned long flags)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100190{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100191 __raw_spin_unlock_irqrestore(lock, flags);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100192}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100193EXPORT_SYMBOL(_raw_spin_unlock_irqrestore);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100194#endif
195
196#ifndef CONFIG_INLINE_SPIN_UNLOCK_IRQ
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100197void __lockfunc _raw_spin_unlock_irq(raw_spinlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100198{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100199 __raw_spin_unlock_irq(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100200}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100201EXPORT_SYMBOL(_raw_spin_unlock_irq);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100202#endif
203
204#ifndef CONFIG_INLINE_SPIN_UNLOCK_BH
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100205void __lockfunc _raw_spin_unlock_bh(raw_spinlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100206{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100207 __raw_spin_unlock_bh(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100208}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100209EXPORT_SYMBOL(_raw_spin_unlock_bh);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100210#endif
211
212#ifndef CONFIG_INLINE_READ_TRYLOCK
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100213int __lockfunc _raw_read_trylock(rwlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100214{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100215 return __raw_read_trylock(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100216}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100217EXPORT_SYMBOL(_raw_read_trylock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100218#endif
219
220#ifndef CONFIG_INLINE_READ_LOCK
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100221void __lockfunc _raw_read_lock(rwlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100222{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100223 __raw_read_lock(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100224}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100225EXPORT_SYMBOL(_raw_read_lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100226#endif
227
228#ifndef CONFIG_INLINE_READ_LOCK_IRQSAVE
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100229unsigned long __lockfunc _raw_read_lock_irqsave(rwlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100230{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100231 return __raw_read_lock_irqsave(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100232}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100233EXPORT_SYMBOL(_raw_read_lock_irqsave);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100234#endif
235
236#ifndef CONFIG_INLINE_READ_LOCK_IRQ
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100237void __lockfunc _raw_read_lock_irq(rwlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100238{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100239 __raw_read_lock_irq(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100240}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100241EXPORT_SYMBOL(_raw_read_lock_irq);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100242#endif
243
244#ifndef CONFIG_INLINE_READ_LOCK_BH
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100245void __lockfunc _raw_read_lock_bh(rwlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100246{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100247 __raw_read_lock_bh(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100248}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100249EXPORT_SYMBOL(_raw_read_lock_bh);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100250#endif
251
252#ifndef CONFIG_INLINE_READ_UNLOCK
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100253void __lockfunc _raw_read_unlock(rwlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100254{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100255 __raw_read_unlock(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100256}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100257EXPORT_SYMBOL(_raw_read_unlock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100258#endif
259
260#ifndef CONFIG_INLINE_READ_UNLOCK_IRQRESTORE
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100261void __lockfunc _raw_read_unlock_irqrestore(rwlock_t *lock, unsigned long flags)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100262{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100263 __raw_read_unlock_irqrestore(lock, flags);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100264}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100265EXPORT_SYMBOL(_raw_read_unlock_irqrestore);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100266#endif
267
268#ifndef CONFIG_INLINE_READ_UNLOCK_IRQ
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100269void __lockfunc _raw_read_unlock_irq(rwlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100270{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100271 __raw_read_unlock_irq(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100272}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100273EXPORT_SYMBOL(_raw_read_unlock_irq);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100274#endif
275
276#ifndef CONFIG_INLINE_READ_UNLOCK_BH
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100277void __lockfunc _raw_read_unlock_bh(rwlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100278{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100279 __raw_read_unlock_bh(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100280}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100281EXPORT_SYMBOL(_raw_read_unlock_bh);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100282#endif
283
284#ifndef CONFIG_INLINE_WRITE_TRYLOCK
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100285int __lockfunc _raw_write_trylock(rwlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100286{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100287 return __raw_write_trylock(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100288}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100289EXPORT_SYMBOL(_raw_write_trylock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100290#endif
291
292#ifndef CONFIG_INLINE_WRITE_LOCK
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100293void __lockfunc _raw_write_lock(rwlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100294{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100295 __raw_write_lock(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100296}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100297EXPORT_SYMBOL(_raw_write_lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100298#endif
299
300#ifndef CONFIG_INLINE_WRITE_LOCK_IRQSAVE
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100301unsigned long __lockfunc _raw_write_lock_irqsave(rwlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100302{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100303 return __raw_write_lock_irqsave(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100304}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100305EXPORT_SYMBOL(_raw_write_lock_irqsave);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100306#endif
307
308#ifndef CONFIG_INLINE_WRITE_LOCK_IRQ
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100309void __lockfunc _raw_write_lock_irq(rwlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100310{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100311 __raw_write_lock_irq(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100312}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100313EXPORT_SYMBOL(_raw_write_lock_irq);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100314#endif
315
316#ifndef CONFIG_INLINE_WRITE_LOCK_BH
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100317void __lockfunc _raw_write_lock_bh(rwlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100318{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100319 __raw_write_lock_bh(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100320}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100321EXPORT_SYMBOL(_raw_write_lock_bh);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100322#endif
323
324#ifndef CONFIG_INLINE_WRITE_UNLOCK
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100325void __lockfunc _raw_write_unlock(rwlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100326{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100327 __raw_write_unlock(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100328}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100329EXPORT_SYMBOL(_raw_write_unlock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100330#endif
331
332#ifndef CONFIG_INLINE_WRITE_UNLOCK_IRQRESTORE
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100333void __lockfunc _raw_write_unlock_irqrestore(rwlock_t *lock, unsigned long flags)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100334{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100335 __raw_write_unlock_irqrestore(lock, flags);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100336}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100337EXPORT_SYMBOL(_raw_write_unlock_irqrestore);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100338#endif
339
340#ifndef CONFIG_INLINE_WRITE_UNLOCK_IRQ
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100341void __lockfunc _raw_write_unlock_irq(rwlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100342{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100343 __raw_write_unlock_irq(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100344}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100345EXPORT_SYMBOL(_raw_write_unlock_irq);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100346#endif
347
348#ifndef CONFIG_INLINE_WRITE_UNLOCK_BH
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100349void __lockfunc _raw_write_unlock_bh(rwlock_t *lock)
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100350{
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100351 __raw_write_unlock_bh(lock);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100352}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100353EXPORT_SYMBOL(_raw_write_unlock_bh);
Thomas Gleixnerb7b40ad2009-11-09 21:01:59 +0100354#endif
355
Thomas Gleixner8e13c7b2009-11-09 15:21:41 +0000356#ifdef CONFIG_DEBUG_LOCK_ALLOC
357
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100358void __lockfunc _raw_spin_lock_nested(raw_spinlock_t *lock, int subclass)
Thomas Gleixner8e13c7b2009-11-09 15:21:41 +0000359{
360 preempt_disable();
361 spin_acquire(&lock->dep_map, subclass, 0, _RET_IP_);
Thomas Gleixner9828ea92009-12-03 20:55:53 +0100362 LOCK_CONTENDED(lock, do_raw_spin_trylock, do_raw_spin_lock);
Thomas Gleixner8e13c7b2009-11-09 15:21:41 +0000363}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100364EXPORT_SYMBOL(_raw_spin_lock_nested);
Thomas Gleixner8e13c7b2009-11-09 15:21:41 +0000365
Thomas Graf113948d2015-01-02 23:00:19 +0100366void __lockfunc _raw_spin_lock_bh_nested(raw_spinlock_t *lock, int subclass)
367{
368 __local_bh_disable_ip(_RET_IP_, SOFTIRQ_LOCK_OFFSET);
369 spin_acquire(&lock->dep_map, subclass, 0, _RET_IP_);
370 LOCK_CONTENDED(lock, do_raw_spin_trylock, do_raw_spin_lock);
371}
372EXPORT_SYMBOL(_raw_spin_lock_bh_nested);
373
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100374unsigned long __lockfunc _raw_spin_lock_irqsave_nested(raw_spinlock_t *lock,
Thomas Gleixner8e13c7b2009-11-09 15:21:41 +0000375 int subclass)
376{
377 unsigned long flags;
378
379 local_irq_save(flags);
380 preempt_disable();
381 spin_acquire(&lock->dep_map, subclass, 0, _RET_IP_);
Thomas Gleixner9828ea92009-12-03 20:55:53 +0100382 LOCK_CONTENDED_FLAGS(lock, do_raw_spin_trylock, do_raw_spin_lock,
383 do_raw_spin_lock_flags, &flags);
Thomas Gleixner8e13c7b2009-11-09 15:21:41 +0000384 return flags;
385}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100386EXPORT_SYMBOL(_raw_spin_lock_irqsave_nested);
Thomas Gleixner8e13c7b2009-11-09 15:21:41 +0000387
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100388void __lockfunc _raw_spin_lock_nest_lock(raw_spinlock_t *lock,
Thomas Gleixner8e13c7b2009-11-09 15:21:41 +0000389 struct lockdep_map *nest_lock)
390{
391 preempt_disable();
392 spin_acquire_nest(&lock->dep_map, 0, 0, nest_lock, _RET_IP_);
Thomas Gleixner9828ea92009-12-03 20:55:53 +0100393 LOCK_CONTENDED(lock, do_raw_spin_trylock, do_raw_spin_lock);
Thomas Gleixner8e13c7b2009-11-09 15:21:41 +0000394}
Thomas Gleixner9c1721a2009-12-03 21:52:18 +0100395EXPORT_SYMBOL(_raw_spin_lock_nest_lock);
Thomas Gleixner8e13c7b2009-11-09 15:21:41 +0000396
397#endif
398
Steven Rostedt0764d232008-05-12 21:20:44 +0200399notrace int in_lock_functions(unsigned long addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400{
401 /* Linker adds these: start and end of __lockfunc functions */
402 extern char __lock_text_start[], __lock_text_end[];
403
404 return addr >= (unsigned long)__lock_text_start
405 && addr < (unsigned long)__lock_text_end;
406}
407EXPORT_SYMBOL(in_lock_functions);