Linux 4.8-rc8
[linux/fpc-iii.git] / arch / hexagon / include / asm / spinlock.h
bloba1c55788c5d6591eac4786b2dc0fcdd3164eb65c
1 /*
2 * Spinlock support for the Hexagon architecture
4 * Copyright (c) 2010-2011, The Linux Foundation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 and
9 * only version 2 as published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 * 02110-1301, USA.
22 #ifndef _ASM_SPINLOCK_H
23 #define _ASM_SPINLOCK_H
25 #include <asm/irqflags.h>
26 #include <asm/barrier.h>
27 #include <asm/processor.h>
30 * This file is pulled in for SMP builds.
31 * Really need to check all the barrier stuff for "true" SMP
35 * Read locks:
36 * - load the lock value
37 * - increment it
38 * - if the lock value is still negative, go back and try again.
39 * - unsuccessful store is unsuccessful. Go back and try again. Loser.
40 * - successful store new lock value if positive -> lock acquired
42 static inline void arch_read_lock(arch_rwlock_t *lock)
44 __asm__ __volatile__(
45 "1: R6 = memw_locked(%0);\n"
46 " { P3 = cmp.ge(R6,#0); R6 = add(R6,#1);}\n"
47 " { if !P3 jump 1b; }\n"
48 " memw_locked(%0,P3) = R6;\n"
49 " { if !P3 jump 1b; }\n"
51 : "r" (&lock->lock)
52 : "memory", "r6", "p3"
57 static inline void arch_read_unlock(arch_rwlock_t *lock)
59 __asm__ __volatile__(
60 "1: R6 = memw_locked(%0);\n"
61 " R6 = add(R6,#-1);\n"
62 " memw_locked(%0,P3) = R6\n"
63 " if !P3 jump 1b;\n"
65 : "r" (&lock->lock)
66 : "memory", "r6", "p3"
71 /* I think this returns 0 on fail, 1 on success. */
72 static inline int arch_read_trylock(arch_rwlock_t *lock)
74 int temp;
75 __asm__ __volatile__(
76 " R6 = memw_locked(%1);\n"
77 " { %0 = #0; P3 = cmp.ge(R6,#0); R6 = add(R6,#1);}\n"
78 " { if !P3 jump 1f; }\n"
79 " memw_locked(%1,P3) = R6;\n"
80 " { %0 = P3 }\n"
81 "1:\n"
82 : "=&r" (temp)
83 : "r" (&lock->lock)
84 : "memory", "r6", "p3"
86 return temp;
89 static inline int arch_read_can_lock(arch_rwlock_t *rwlock)
91 return rwlock->lock == 0;
94 static inline int arch_write_can_lock(arch_rwlock_t *rwlock)
96 return rwlock->lock == 0;
99 /* Stuffs a -1 in the lock value? */
100 static inline void arch_write_lock(arch_rwlock_t *lock)
102 __asm__ __volatile__(
103 "1: R6 = memw_locked(%0)\n"
104 " { P3 = cmp.eq(R6,#0); R6 = #-1;}\n"
105 " { if !P3 jump 1b; }\n"
106 " memw_locked(%0,P3) = R6;\n"
107 " { if !P3 jump 1b; }\n"
109 : "r" (&lock->lock)
110 : "memory", "r6", "p3"
115 static inline int arch_write_trylock(arch_rwlock_t *lock)
117 int temp;
118 __asm__ __volatile__(
119 " R6 = memw_locked(%1)\n"
120 " { %0 = #0; P3 = cmp.eq(R6,#0); R6 = #-1;}\n"
121 " { if !P3 jump 1f; }\n"
122 " memw_locked(%1,P3) = R6;\n"
123 " %0 = P3;\n"
124 "1:\n"
125 : "=&r" (temp)
126 : "r" (&lock->lock)
127 : "memory", "r6", "p3"
129 return temp;
133 static inline void arch_write_unlock(arch_rwlock_t *lock)
135 smp_mb();
136 lock->lock = 0;
139 static inline void arch_spin_lock(arch_spinlock_t *lock)
141 __asm__ __volatile__(
142 "1: R6 = memw_locked(%0);\n"
143 " P3 = cmp.eq(R6,#0);\n"
144 " { if !P3 jump 1b; R6 = #1; }\n"
145 " memw_locked(%0,P3) = R6;\n"
146 " { if !P3 jump 1b; }\n"
148 : "r" (&lock->lock)
149 : "memory", "r6", "p3"
154 static inline void arch_spin_unlock(arch_spinlock_t *lock)
156 smp_mb();
157 lock->lock = 0;
160 static inline unsigned int arch_spin_trylock(arch_spinlock_t *lock)
162 int temp;
163 __asm__ __volatile__(
164 " R6 = memw_locked(%1);\n"
165 " P3 = cmp.eq(R6,#0);\n"
166 " { if !P3 jump 1f; R6 = #1; %0 = #0; }\n"
167 " memw_locked(%1,P3) = R6;\n"
168 " %0 = P3;\n"
169 "1:\n"
170 : "=&r" (temp)
171 : "r" (&lock->lock)
172 : "memory", "r6", "p3"
174 return temp;
178 * SMP spinlocks are intended to allow only a single CPU at the lock
180 #define arch_spin_lock_flags(lock, flags) arch_spin_lock(lock)
182 static inline void arch_spin_unlock_wait(arch_spinlock_t *lock)
184 smp_cond_load_acquire(&lock->lock, !VAL);
187 #define arch_spin_is_locked(x) ((x)->lock != 0)
189 #define arch_read_lock_flags(lock, flags) arch_read_lock(lock)
190 #define arch_write_lock_flags(lock, flags) arch_write_lock(lock)
192 #endif