1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * arch/arm/common/mcpm_head.S -- kernel entry point for multi-cluster PM
5 * Created by: Nicolas Pitre, March 2012
6 * Copyright: (C) 2012-2013 Linaro Limited
8 * Refer to Documentation/arm/cluster-pm-race-avoidance.rst
9 * for details of the synchronisation algorithms used here.
12 #include <linux/linkage.h>
14 #include <asm/assembler.h>
18 .if MCPM_SYNC_CLUSTER_CPUS
19 .error "cpus must be the first member of struct mcpm_sync_struct"
23 #if defined(CONFIG_DEBUG_LL) && defined(DEBUG)
26 1903: .asciz " cluster"
27 1904: .asciz ": \string"
45 ENTRY(mcpm_entry_point)
52 mrc p15, 0, r0, c0, c0, 5 @ MPIDR
53 ubfx r9, r0, #0, #8 @ r9 = cpu
54 ubfx r10, r0, #8, #8 @ r10 = cluster
55 mov r3, #MAX_CPUS_PER_CLUSTER
56 mla r4, r3, r10, r9 @ r4 = canonical CPU index
57 cmp r4, #(MAX_CPUS_PER_CLUSTER * MAX_NR_CLUSTERS)
60 /* We didn't expect this CPU. Try to cheaply make it quiet. */
65 2: pr_dbg "kernel mcpm_entry_point\n"
68 * MMU is off so we need to get to various variables in a
69 * position independent way.
72 ldmia r5, {r0, r6, r7, r8, r11}
73 add r0, r5, r0 @ r0 = mcpm_entry_early_pokes
74 add r6, r5, r6 @ r6 = mcpm_entry_vectors
75 ldr r7, [r5, r7] @ r7 = mcpm_power_up_setup_phys
76 add r8, r5, r8 @ r8 = mcpm_sync
77 add r11, r5, r11 @ r11 = first_man_locks
79 @ Perform an early poke, if any
80 add r0, r0, r4, lsl #3
85 mov r0, #MCPM_SYNC_CLUSTER_SIZE
86 mla r8, r0, r10, r8 @ r8 = sync cluster base
88 @ Signal that this CPU is coming UP:
89 mov r0, #CPU_COMING_UP
90 mov r5, #MCPM_SYNC_CPU_SIZE
91 mla r5, r9, r5, r8 @ r5 = sync cpu address
94 @ At this point, the cluster cannot unexpectedly enter the GOING_DOWN
95 @ state, because there is at least one active CPU (this CPU).
98 mla r11, r0, r10, r11 @ r11 = cluster first man lock
101 bl vlock_trylock @ implies DMB
103 cmp r0, #0 @ failed to get the lock?
104 bne mcpm_setup_wait @ wait for cluster setup if so
106 ldrb r0, [r8, #MCPM_SYNC_CLUSTER_CLUSTER]
107 cmp r0, #CLUSTER_UP @ cluster already up?
108 bne mcpm_setup @ if not, set up the cluster
110 @ Otherwise, release the first man lock and skip setup:
113 b mcpm_setup_complete
116 @ Control dependency implies strb not observable before previous ldrb.
118 @ Signal that the cluster is being brought up:
119 mov r0, #INBOUND_COMING_UP
120 strb r0, [r8, #MCPM_SYNC_CLUSTER_INBOUND]
123 @ Any CPU trying to take the cluster into CLUSTER_GOING_DOWN from this
124 @ point onwards will observe INBOUND_COMING_UP and abort.
126 @ Wait for any previously-pending cluster teardown operations to abort
129 ldrb r0, [r8, #MCPM_SYNC_CLUSTER_CLUSTER]
130 cmp r0, #CLUSTER_GOING_DOWN
138 @ If the outbound gave up before teardown started, skip cluster setup:
143 @ power_up_setup is now responsible for setting up the cluster:
146 mov r0, #1 @ second (cluster) affinity level
147 blxne r7 @ Call power_up_setup if defined
151 strb r0, [r8, #MCPM_SYNC_CLUSTER_CLUSTER]
155 @ Leave the cluster setup critical section:
157 mov r0, #INBOUND_NOT_COMING_UP
158 strb r0, [r8, #MCPM_SYNC_CLUSTER_INBOUND]
163 bl vlock_unlock @ implies DMB
164 b mcpm_setup_complete
166 @ In the contended case, non-first men wait here for cluster setup
169 ldrb r0, [r8, #MCPM_SYNC_CLUSTER_CLUSTER]
176 @ If a platform-specific CPU setup hook is needed, it is
180 mov r0, #0 @ first (CPU) affinity level
181 blxne r7 @ Call power_up_setup if defined
184 @ Mark the CPU as up:
189 @ Observability order of CPU_UP and opening of the gate does not matter.
192 ldr r5, [r6, r4, lsl #2] @ r5 = CPU entry vector
203 3: .word mcpm_entry_early_pokes - .
204 .word mcpm_entry_vectors - 3b
205 .word mcpm_power_up_setup_phys - 3b
207 .word first_man_locks - 3b
209 ENDPROC(mcpm_entry_point)
213 .align CACHE_WRITEBACK_ORDER
214 .type first_man_locks, #object
216 .space VLOCK_SIZE * MAX_NR_CLUSTERS
217 .align CACHE_WRITEBACK_ORDER
219 .type mcpm_entry_vectors, #object
220 ENTRY(mcpm_entry_vectors)
221 .space 4 * MAX_NR_CLUSTERS * MAX_CPUS_PER_CLUSTER
223 .type mcpm_entry_early_pokes, #object
224 ENTRY(mcpm_entry_early_pokes)
225 .space 8 * MAX_NR_CLUSTERS * MAX_CPUS_PER_CLUSTER
227 .type mcpm_power_up_setup_phys, #object
228 ENTRY(mcpm_power_up_setup_phys)
229 .space 4 @ set by mcpm_sync_init()