| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (2004) Linus Torvalds | 
|  | 3 | * | 
|  | 4 | * Author: Zwane Mwaikambo <zwane@fsmlabs.com> | 
|  | 5 | * | 
| Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 6 | * 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 Kleen | 0cb91a2 | 2006-09-26 10:52:28 +0200 | [diff] [blame] | 10 | * | 
|  | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | */ | 
|  | 16 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/linkage.h> | 
|  | 18 | #include <linux/preempt.h> | 
|  | 19 | #include <linux/spinlock.h> | 
|  | 20 | #include <linux/interrupt.h> | 
| Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 21 | #include <linux/debug_locks.h> | 
| Paul Gortmaker | 9984de1 | 2011-05-23 14:51:41 -0400 | [diff] [blame] | 22 | #include <linux/export.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 |  | 
| Thomas Gleixner | 8e13c7b | 2009-11-09 15:21:41 +0000 | [diff] [blame] | 24 | /* | 
|  | 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 Gleixner | c2f21ce | 2009-12-02 20:02:59 +0100 | [diff] [blame] | 35 | #define raw_read_can_lock(l)	read_can_lock(l) | 
|  | 36 | #define raw_write_can_lock(l)	write_can_lock(l) | 
| Thomas Gleixner | 8e13c7b | 2009-11-09 15:21:41 +0000 | [diff] [blame] | 37 | /* | 
|  | 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 Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 47 | void __lockfunc __raw_##op##_lock(locktype##_t *lock)			\ | 
| Thomas Gleixner | 8e13c7b | 2009-11-09 15:21:41 +0000 | [diff] [blame] | 48 | {									\ | 
|  | 49 | for (;;) {							\ | 
|  | 50 | preempt_disable();					\ | 
| Thomas Gleixner | 9828ea9 | 2009-12-03 20:55:53 +0100 | [diff] [blame] | 51 | if (likely(do_raw_##op##_trylock(lock)))		\ | 
| Thomas Gleixner | 8e13c7b | 2009-11-09 15:21:41 +0000 | [diff] [blame] | 52 | break;						\ | 
|  | 53 | preempt_enable();					\ | 
|  | 54 | \ | 
|  | 55 | if (!(lock)->break_lock)				\ | 
|  | 56 | (lock)->break_lock = 1;				\ | 
| Thomas Gleixner | c2f21ce | 2009-12-02 20:02:59 +0100 | [diff] [blame] | 57 | while (!raw_##op##_can_lock(lock) && (lock)->break_lock)\ | 
| Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 58 | arch_##op##_relax(&lock->raw_lock);		\ | 
| Thomas Gleixner | 8e13c7b | 2009-11-09 15:21:41 +0000 | [diff] [blame] | 59 | }								\ | 
|  | 60 | (lock)->break_lock = 0;						\ | 
|  | 61 | }									\ | 
|  | 62 | \ | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 63 | unsigned long __lockfunc __raw_##op##_lock_irqsave(locktype##_t *lock)	\ | 
| Thomas Gleixner | 8e13c7b | 2009-11-09 15:21:41 +0000 | [diff] [blame] | 64 | {									\ | 
|  | 65 | unsigned long flags;						\ | 
|  | 66 | \ | 
|  | 67 | for (;;) {							\ | 
|  | 68 | preempt_disable();					\ | 
|  | 69 | local_irq_save(flags);					\ | 
| Thomas Gleixner | 9828ea9 | 2009-12-03 20:55:53 +0100 | [diff] [blame] | 70 | if (likely(do_raw_##op##_trylock(lock)))		\ | 
| Thomas Gleixner | 8e13c7b | 2009-11-09 15:21:41 +0000 | [diff] [blame] | 71 | break;						\ | 
|  | 72 | local_irq_restore(flags);				\ | 
|  | 73 | preempt_enable();					\ | 
|  | 74 | \ | 
|  | 75 | if (!(lock)->break_lock)				\ | 
|  | 76 | (lock)->break_lock = 1;				\ | 
| Thomas Gleixner | c2f21ce | 2009-12-02 20:02:59 +0100 | [diff] [blame] | 77 | while (!raw_##op##_can_lock(lock) && (lock)->break_lock)\ | 
| Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 78 | arch_##op##_relax(&lock->raw_lock);		\ | 
| Thomas Gleixner | 8e13c7b | 2009-11-09 15:21:41 +0000 | [diff] [blame] | 79 | }								\ | 
|  | 80 | (lock)->break_lock = 0;						\ | 
|  | 81 | return flags;							\ | 
|  | 82 | }									\ | 
|  | 83 | \ | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 84 | void __lockfunc __raw_##op##_lock_irq(locktype##_t *lock)		\ | 
| Thomas Gleixner | 8e13c7b | 2009-11-09 15:21:41 +0000 | [diff] [blame] | 85 | {									\ | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 86 | _raw_##op##_lock_irqsave(lock);					\ | 
| Thomas Gleixner | 8e13c7b | 2009-11-09 15:21:41 +0000 | [diff] [blame] | 87 | }									\ | 
|  | 88 | \ | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 89 | void __lockfunc __raw_##op##_lock_bh(locktype##_t *lock)		\ | 
| Thomas Gleixner | 8e13c7b | 2009-11-09 15:21:41 +0000 | [diff] [blame] | 90 | {									\ | 
|  | 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 Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 98 | flags = _raw_##op##_lock_irqsave(lock);				\ | 
| Thomas Gleixner | 8e13c7b | 2009-11-09 15:21:41 +0000 | [diff] [blame] | 99 | 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 Gleixner | c2f21ce | 2009-12-02 20:02:59 +0100 | [diff] [blame] | 112 | BUILD_LOCK_OPS(spin, raw_spinlock); | 
| Thomas Gleixner | 8e13c7b | 2009-11-09 15:21:41 +0000 | [diff] [blame] | 113 | BUILD_LOCK_OPS(read, rwlock); | 
|  | 114 | BUILD_LOCK_OPS(write, rwlock); | 
|  | 115 |  | 
|  | 116 | #endif | 
|  | 117 |  | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 118 | #ifndef CONFIG_INLINE_SPIN_TRYLOCK | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 119 | int __lockfunc _raw_spin_trylock(raw_spinlock_t *lock) | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 120 | { | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 121 | return __raw_spin_trylock(lock); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 122 | } | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 123 | EXPORT_SYMBOL(_raw_spin_trylock); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 124 | #endif | 
|  | 125 |  | 
|  | 126 | #ifndef CONFIG_INLINE_SPIN_TRYLOCK_BH | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 127 | int __lockfunc _raw_spin_trylock_bh(raw_spinlock_t *lock) | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 128 | { | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 129 | return __raw_spin_trylock_bh(lock); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 130 | } | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 131 | EXPORT_SYMBOL(_raw_spin_trylock_bh); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 132 | #endif | 
|  | 133 |  | 
|  | 134 | #ifndef CONFIG_INLINE_SPIN_LOCK | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 135 | void __lockfunc _raw_spin_lock(raw_spinlock_t *lock) | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 136 | { | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 137 | __raw_spin_lock(lock); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 138 | } | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 139 | EXPORT_SYMBOL(_raw_spin_lock); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 140 | #endif | 
|  | 141 |  | 
|  | 142 | #ifndef CONFIG_INLINE_SPIN_LOCK_IRQSAVE | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 143 | unsigned long __lockfunc _raw_spin_lock_irqsave(raw_spinlock_t *lock) | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 144 | { | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 145 | return __raw_spin_lock_irqsave(lock); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 146 | } | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 147 | EXPORT_SYMBOL(_raw_spin_lock_irqsave); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 148 | #endif | 
|  | 149 |  | 
|  | 150 | #ifndef CONFIG_INLINE_SPIN_LOCK_IRQ | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 151 | void __lockfunc _raw_spin_lock_irq(raw_spinlock_t *lock) | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 152 | { | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 153 | __raw_spin_lock_irq(lock); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 154 | } | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 155 | EXPORT_SYMBOL(_raw_spin_lock_irq); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 156 | #endif | 
|  | 157 |  | 
|  | 158 | #ifndef CONFIG_INLINE_SPIN_LOCK_BH | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 159 | void __lockfunc _raw_spin_lock_bh(raw_spinlock_t *lock) | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 160 | { | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 161 | __raw_spin_lock_bh(lock); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 162 | } | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 163 | EXPORT_SYMBOL(_raw_spin_lock_bh); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 164 | #endif | 
|  | 165 |  | 
|  | 166 | #ifndef CONFIG_INLINE_SPIN_UNLOCK | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 167 | void __lockfunc _raw_spin_unlock(raw_spinlock_t *lock) | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 168 | { | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 169 | __raw_spin_unlock(lock); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 170 | } | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 171 | EXPORT_SYMBOL(_raw_spin_unlock); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 172 | #endif | 
|  | 173 |  | 
|  | 174 | #ifndef CONFIG_INLINE_SPIN_UNLOCK_IRQRESTORE | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 175 | void __lockfunc _raw_spin_unlock_irqrestore(raw_spinlock_t *lock, unsigned long flags) | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 176 | { | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 177 | __raw_spin_unlock_irqrestore(lock, flags); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 178 | } | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 179 | EXPORT_SYMBOL(_raw_spin_unlock_irqrestore); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 180 | #endif | 
|  | 181 |  | 
|  | 182 | #ifndef CONFIG_INLINE_SPIN_UNLOCK_IRQ | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 183 | void __lockfunc _raw_spin_unlock_irq(raw_spinlock_t *lock) | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 184 | { | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 185 | __raw_spin_unlock_irq(lock); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 186 | } | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 187 | EXPORT_SYMBOL(_raw_spin_unlock_irq); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 188 | #endif | 
|  | 189 |  | 
|  | 190 | #ifndef CONFIG_INLINE_SPIN_UNLOCK_BH | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 191 | void __lockfunc _raw_spin_unlock_bh(raw_spinlock_t *lock) | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 192 | { | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 193 | __raw_spin_unlock_bh(lock); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 194 | } | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 195 | EXPORT_SYMBOL(_raw_spin_unlock_bh); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 196 | #endif | 
|  | 197 |  | 
|  | 198 | #ifndef CONFIG_INLINE_READ_TRYLOCK | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 199 | int __lockfunc _raw_read_trylock(rwlock_t *lock) | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 200 | { | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 201 | return __raw_read_trylock(lock); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 202 | } | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 203 | EXPORT_SYMBOL(_raw_read_trylock); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 204 | #endif | 
|  | 205 |  | 
|  | 206 | #ifndef CONFIG_INLINE_READ_LOCK | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 207 | void __lockfunc _raw_read_lock(rwlock_t *lock) | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 208 | { | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 209 | __raw_read_lock(lock); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 210 | } | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 211 | EXPORT_SYMBOL(_raw_read_lock); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 212 | #endif | 
|  | 213 |  | 
|  | 214 | #ifndef CONFIG_INLINE_READ_LOCK_IRQSAVE | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 215 | unsigned long __lockfunc _raw_read_lock_irqsave(rwlock_t *lock) | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 216 | { | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 217 | return __raw_read_lock_irqsave(lock); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 218 | } | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 219 | EXPORT_SYMBOL(_raw_read_lock_irqsave); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 220 | #endif | 
|  | 221 |  | 
|  | 222 | #ifndef CONFIG_INLINE_READ_LOCK_IRQ | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 223 | void __lockfunc _raw_read_lock_irq(rwlock_t *lock) | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 224 | { | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 225 | __raw_read_lock_irq(lock); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 226 | } | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 227 | EXPORT_SYMBOL(_raw_read_lock_irq); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 228 | #endif | 
|  | 229 |  | 
|  | 230 | #ifndef CONFIG_INLINE_READ_LOCK_BH | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 231 | void __lockfunc _raw_read_lock_bh(rwlock_t *lock) | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 232 | { | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 233 | __raw_read_lock_bh(lock); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 234 | } | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 235 | EXPORT_SYMBOL(_raw_read_lock_bh); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 236 | #endif | 
|  | 237 |  | 
|  | 238 | #ifndef CONFIG_INLINE_READ_UNLOCK | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 239 | void __lockfunc _raw_read_unlock(rwlock_t *lock) | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 240 | { | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 241 | __raw_read_unlock(lock); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 242 | } | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 243 | EXPORT_SYMBOL(_raw_read_unlock); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 244 | #endif | 
|  | 245 |  | 
|  | 246 | #ifndef CONFIG_INLINE_READ_UNLOCK_IRQRESTORE | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 247 | void __lockfunc _raw_read_unlock_irqrestore(rwlock_t *lock, unsigned long flags) | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 248 | { | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 249 | __raw_read_unlock_irqrestore(lock, flags); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 250 | } | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 251 | EXPORT_SYMBOL(_raw_read_unlock_irqrestore); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 252 | #endif | 
|  | 253 |  | 
|  | 254 | #ifndef CONFIG_INLINE_READ_UNLOCK_IRQ | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 255 | void __lockfunc _raw_read_unlock_irq(rwlock_t *lock) | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 256 | { | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 257 | __raw_read_unlock_irq(lock); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 258 | } | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 259 | EXPORT_SYMBOL(_raw_read_unlock_irq); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 260 | #endif | 
|  | 261 |  | 
|  | 262 | #ifndef CONFIG_INLINE_READ_UNLOCK_BH | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 263 | void __lockfunc _raw_read_unlock_bh(rwlock_t *lock) | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 264 | { | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 265 | __raw_read_unlock_bh(lock); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 266 | } | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 267 | EXPORT_SYMBOL(_raw_read_unlock_bh); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 268 | #endif | 
|  | 269 |  | 
|  | 270 | #ifndef CONFIG_INLINE_WRITE_TRYLOCK | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 271 | int __lockfunc _raw_write_trylock(rwlock_t *lock) | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 272 | { | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 273 | return __raw_write_trylock(lock); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 274 | } | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 275 | EXPORT_SYMBOL(_raw_write_trylock); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 276 | #endif | 
|  | 277 |  | 
|  | 278 | #ifndef CONFIG_INLINE_WRITE_LOCK | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 279 | void __lockfunc _raw_write_lock(rwlock_t *lock) | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 280 | { | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 281 | __raw_write_lock(lock); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 282 | } | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 283 | EXPORT_SYMBOL(_raw_write_lock); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 284 | #endif | 
|  | 285 |  | 
|  | 286 | #ifndef CONFIG_INLINE_WRITE_LOCK_IRQSAVE | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 287 | unsigned long __lockfunc _raw_write_lock_irqsave(rwlock_t *lock) | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 288 | { | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 289 | return __raw_write_lock_irqsave(lock); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 290 | } | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 291 | EXPORT_SYMBOL(_raw_write_lock_irqsave); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 292 | #endif | 
|  | 293 |  | 
|  | 294 | #ifndef CONFIG_INLINE_WRITE_LOCK_IRQ | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 295 | void __lockfunc _raw_write_lock_irq(rwlock_t *lock) | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 296 | { | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 297 | __raw_write_lock_irq(lock); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 298 | } | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 299 | EXPORT_SYMBOL(_raw_write_lock_irq); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 300 | #endif | 
|  | 301 |  | 
|  | 302 | #ifndef CONFIG_INLINE_WRITE_LOCK_BH | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 303 | void __lockfunc _raw_write_lock_bh(rwlock_t *lock) | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 304 | { | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 305 | __raw_write_lock_bh(lock); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 306 | } | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 307 | EXPORT_SYMBOL(_raw_write_lock_bh); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 308 | #endif | 
|  | 309 |  | 
|  | 310 | #ifndef CONFIG_INLINE_WRITE_UNLOCK | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 311 | void __lockfunc _raw_write_unlock(rwlock_t *lock) | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 312 | { | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 313 | __raw_write_unlock(lock); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 314 | } | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 315 | EXPORT_SYMBOL(_raw_write_unlock); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 316 | #endif | 
|  | 317 |  | 
|  | 318 | #ifndef CONFIG_INLINE_WRITE_UNLOCK_IRQRESTORE | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 319 | void __lockfunc _raw_write_unlock_irqrestore(rwlock_t *lock, unsigned long flags) | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 320 | { | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 321 | __raw_write_unlock_irqrestore(lock, flags); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 322 | } | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 323 | EXPORT_SYMBOL(_raw_write_unlock_irqrestore); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 324 | #endif | 
|  | 325 |  | 
|  | 326 | #ifndef CONFIG_INLINE_WRITE_UNLOCK_IRQ | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 327 | void __lockfunc _raw_write_unlock_irq(rwlock_t *lock) | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 328 | { | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 329 | __raw_write_unlock_irq(lock); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 330 | } | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 331 | EXPORT_SYMBOL(_raw_write_unlock_irq); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 332 | #endif | 
|  | 333 |  | 
|  | 334 | #ifndef CONFIG_INLINE_WRITE_UNLOCK_BH | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 335 | void __lockfunc _raw_write_unlock_bh(rwlock_t *lock) | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 336 | { | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 337 | __raw_write_unlock_bh(lock); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 338 | } | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 339 | EXPORT_SYMBOL(_raw_write_unlock_bh); | 
| Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 340 | #endif | 
|  | 341 |  | 
| Thomas Gleixner | 8e13c7b | 2009-11-09 15:21:41 +0000 | [diff] [blame] | 342 | #ifdef CONFIG_DEBUG_LOCK_ALLOC | 
|  | 343 |  | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 344 | void __lockfunc _raw_spin_lock_nested(raw_spinlock_t *lock, int subclass) | 
| Thomas Gleixner | 8e13c7b | 2009-11-09 15:21:41 +0000 | [diff] [blame] | 345 | { | 
|  | 346 | preempt_disable(); | 
|  | 347 | spin_acquire(&lock->dep_map, subclass, 0, _RET_IP_); | 
| Thomas Gleixner | 9828ea9 | 2009-12-03 20:55:53 +0100 | [diff] [blame] | 348 | LOCK_CONTENDED(lock, do_raw_spin_trylock, do_raw_spin_lock); | 
| Thomas Gleixner | 8e13c7b | 2009-11-09 15:21:41 +0000 | [diff] [blame] | 349 | } | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 350 | EXPORT_SYMBOL(_raw_spin_lock_nested); | 
| Thomas Gleixner | 8e13c7b | 2009-11-09 15:21:41 +0000 | [diff] [blame] | 351 |  | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 352 | unsigned long __lockfunc _raw_spin_lock_irqsave_nested(raw_spinlock_t *lock, | 
| Thomas Gleixner | 8e13c7b | 2009-11-09 15:21:41 +0000 | [diff] [blame] | 353 | 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 Gleixner | 9828ea9 | 2009-12-03 20:55:53 +0100 | [diff] [blame] | 360 | LOCK_CONTENDED_FLAGS(lock, do_raw_spin_trylock, do_raw_spin_lock, | 
|  | 361 | do_raw_spin_lock_flags, &flags); | 
| Thomas Gleixner | 8e13c7b | 2009-11-09 15:21:41 +0000 | [diff] [blame] | 362 | return flags; | 
|  | 363 | } | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 364 | EXPORT_SYMBOL(_raw_spin_lock_irqsave_nested); | 
| Thomas Gleixner | 8e13c7b | 2009-11-09 15:21:41 +0000 | [diff] [blame] | 365 |  | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 366 | void __lockfunc _raw_spin_lock_nest_lock(raw_spinlock_t *lock, | 
| Thomas Gleixner | 8e13c7b | 2009-11-09 15:21:41 +0000 | [diff] [blame] | 367 | struct lockdep_map *nest_lock) | 
|  | 368 | { | 
|  | 369 | preempt_disable(); | 
|  | 370 | spin_acquire_nest(&lock->dep_map, 0, 0, nest_lock, _RET_IP_); | 
| Thomas Gleixner | 9828ea9 | 2009-12-03 20:55:53 +0100 | [diff] [blame] | 371 | LOCK_CONTENDED(lock, do_raw_spin_trylock, do_raw_spin_lock); | 
| Thomas Gleixner | 8e13c7b | 2009-11-09 15:21:41 +0000 | [diff] [blame] | 372 | } | 
| Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 373 | EXPORT_SYMBOL(_raw_spin_lock_nest_lock); | 
| Thomas Gleixner | 8e13c7b | 2009-11-09 15:21:41 +0000 | [diff] [blame] | 374 |  | 
|  | 375 | #endif | 
|  | 376 |  | 
| Steven Rostedt | 0764d23 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 377 | notrace int in_lock_functions(unsigned long addr) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | { | 
|  | 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 | } | 
|  | 385 | EXPORT_SYMBOL(in_lock_functions); |