1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Spinlock support for the Hexagon architecture
5 * Copyright (c) 2010-2011, The Linux Foundation. All rights reserved.
8 #ifndef _ASM_SPINLOCK_H
9 #define _ASM_SPINLOCK_H
11 #include <asm/irqflags.h>
12 #include <asm/barrier.h>
13 #include <asm/processor.h>
16 * This file is pulled in for SMP builds.
17 * Really need to check all the barrier stuff for "true" SMP
22 * - load the lock value
24 * - if the lock value is still negative, go back and try again.
25 * - unsuccessful store is unsuccessful. Go back and try again. Loser.
26 * - successful store new lock value if positive -> lock acquired
28 static inline void arch_read_lock(arch_rwlock_t
*lock
)
31 "1: R6 = memw_locked(%0);\n"
32 " { P3 = cmp.ge(R6,#0); R6 = add(R6,#1);}\n"
33 " { if (!P3) jump 1b; }\n"
34 " memw_locked(%0,P3) = R6;\n"
35 " { if (!P3) jump 1b; }\n"
38 : "memory", "r6", "p3"
43 static inline void arch_read_unlock(arch_rwlock_t
*lock
)
46 "1: R6 = memw_locked(%0);\n"
47 " R6 = add(R6,#-1);\n"
48 " memw_locked(%0,P3) = R6\n"
49 " if (!P3) jump 1b;\n"
52 : "memory", "r6", "p3"
57 /* I think this returns 0 on fail, 1 on success. */
58 static inline int arch_read_trylock(arch_rwlock_t
*lock
)
62 " R6 = memw_locked(%1);\n"
63 " { %0 = #0; P3 = cmp.ge(R6,#0); R6 = add(R6,#1);}\n"
64 " { if (!P3) jump 1f; }\n"
65 " memw_locked(%1,P3) = R6;\n"
70 : "memory", "r6", "p3"
75 /* Stuffs a -1 in the lock value? */
76 static inline void arch_write_lock(arch_rwlock_t
*lock
)
79 "1: R6 = memw_locked(%0)\n"
80 " { P3 = cmp.eq(R6,#0); R6 = #-1;}\n"
81 " { if (!P3) jump 1b; }\n"
82 " memw_locked(%0,P3) = R6;\n"
83 " { if (!P3) jump 1b; }\n"
86 : "memory", "r6", "p3"
91 static inline int arch_write_trylock(arch_rwlock_t
*lock
)
95 " R6 = memw_locked(%1)\n"
96 " { %0 = #0; P3 = cmp.eq(R6,#0); R6 = #-1;}\n"
97 " { if (!P3) jump 1f; }\n"
98 " memw_locked(%1,P3) = R6;\n"
103 : "memory", "r6", "p3"
109 static inline void arch_write_unlock(arch_rwlock_t
*lock
)
115 static inline void arch_spin_lock(arch_spinlock_t
*lock
)
117 __asm__
__volatile__(
118 "1: R6 = memw_locked(%0);\n"
119 " P3 = cmp.eq(R6,#0);\n"
120 " { if (!P3) jump 1b; R6 = #1; }\n"
121 " memw_locked(%0,P3) = R6;\n"
122 " { if (!P3) jump 1b; }\n"
125 : "memory", "r6", "p3"
130 static inline void arch_spin_unlock(arch_spinlock_t
*lock
)
136 static inline unsigned int arch_spin_trylock(arch_spinlock_t
*lock
)
139 __asm__
__volatile__(
140 " R6 = memw_locked(%1);\n"
141 " P3 = cmp.eq(R6,#0);\n"
142 " { if (!P3) jump 1f; R6 = #1; %0 = #0; }\n"
143 " memw_locked(%1,P3) = R6;\n"
148 : "memory", "r6", "p3"
154 * SMP spinlocks are intended to allow only a single CPU at the lock
156 #define arch_spin_is_locked(x) ((x)->lock != 0)