2 * arch/arm/common/mcpm_head.S -- kernel entry point for multi-cluster PM
4 * Created by: Nicolas Pitre, March 2012
5 * Copyright: (C) 2012-2013 Linaro Limited
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 as
9 * published by the Free Software Foundation.
12 * Refer to Documentation/arm/cluster-pm-race-avoidance.txt
13 * for details of the synchronisation algorithms used here.
16 #include <linux/linkage.h>
19 .if MCPM_SYNC_CLUSTER_CPUS
20 .error "cpus must be the first member of struct mcpm_sync_struct"
24 #if defined(CONFIG_DEBUG_LL) && defined(DEBUG)
27 1903: .asciz " cluster"
28 1904: .asciz ": \string"
46 ENTRY(mcpm_entry_point)
48 THUMB( adr r12, BSYM(1f) )
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, {r6, r7, r8}
73 add r6, r5, r6 @ r6 = mcpm_entry_vectors
74 ldr r7, [r5, r7] @ r7 = mcpm_power_up_setup_phys
75 add r8, r5, r8 @ r8 = mcpm_sync
77 mov r0, #MCPM_SYNC_CLUSTER_SIZE
78 mla r8, r0, r10, r8 @ r8 = sync cluster base
80 @ Signal that this CPU is coming UP:
81 mov r0, #CPU_COMING_UP
82 mov r5, #MCPM_SYNC_CPU_SIZE
83 mla r5, r9, r5, r8 @ r5 = sync cpu address
86 @ At this point, the cluster cannot unexpectedly enter the GOING_DOWN
87 @ state, because there is at least one active CPU (this CPU).
89 @ Note: the following is racy as another CPU might be testing
90 @ the same flag at the same moment. That'll be fixed later.
91 ldrb r0, [r8, #MCPM_SYNC_CLUSTER_CLUSTER]
92 cmp r0, #CLUSTER_UP @ cluster already up?
93 bne mcpm_setup @ if not, set up the cluster
95 @ Otherwise, skip setup:
99 @ Control dependency implies strb not observable before previous ldrb.
101 @ Signal that the cluster is being brought up:
102 mov r0, #INBOUND_COMING_UP
103 strb r0, [r8, #MCPM_SYNC_CLUSTER_INBOUND]
106 @ Any CPU trying to take the cluster into CLUSTER_GOING_DOWN from this
107 @ point onwards will observe INBOUND_COMING_UP and abort.
109 @ Wait for any previously-pending cluster teardown operations to abort
112 ldrb r0, [r8, #MCPM_SYNC_CLUSTER_CLUSTER]
113 cmp r0, #CLUSTER_GOING_DOWN
121 @ If the outbound gave up before teardown started, skip cluster setup:
126 @ power_up_setup is now responsible for setting up the cluster:
129 mov r0, #1 @ second (cluster) affinity level
130 blxne r7 @ Call power_up_setup if defined
134 strb r0, [r8, #MCPM_SYNC_CLUSTER_CLUSTER]
138 @ Leave the cluster setup critical section:
140 mov r0, #INBOUND_NOT_COMING_UP
141 strb r0, [r8, #MCPM_SYNC_CLUSTER_INBOUND]
146 @ If a platform-specific CPU setup hook is needed, it is
150 mov r0, #0 @ first (CPU) affinity level
151 blxne r7 @ Call power_up_setup if defined
154 @ Mark the CPU as up:
159 @ Observability order of CPU_UP and opening of the gate does not matter.
162 ldr r5, [r6, r4, lsl #2] @ r5 = CPU entry vector
173 3: .word mcpm_entry_vectors - .
174 .word mcpm_power_up_setup_phys - 3b
177 ENDPROC(mcpm_entry_point)
182 .type mcpm_entry_vectors, #object
183 ENTRY(mcpm_entry_vectors)
184 .space 4 * MAX_NR_CLUSTERS * MAX_CPUS_PER_CLUSTER
186 .type mcpm_power_up_setup_phys, #object
187 ENTRY(mcpm_power_up_setup_phys)
188 .space 4 @ set by mcpm_sync_init()