mcpm_head.S 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * arch/arm/common/mcpm_head.S -- kernel entry point for multi-cluster PM
  4. *
  5. * Created by: Nicolas Pitre, March 2012
  6. * Copyright: (C) 2012-2013 Linaro Limited
  7. *
  8. * Refer to Documentation/arm/cluster-pm-race-avoidance.rst
  9. * for details of the synchronisation algorithms used here.
  10. */
  11. #include <linux/linkage.h>
  12. #include <asm/mcpm.h>
  13. #include <asm/assembler.h>
  14. #include "vlock.h"
  15. .if MCPM_SYNC_CLUSTER_CPUS
  16. .error "cpus must be the first member of struct mcpm_sync_struct"
  17. .endif
  18. .macro pr_dbg string
  19. #if defined(CONFIG_DEBUG_LL) && defined(DEBUG)
  20. b 1901f
  21. 1902: .asciz "CPU"
  22. 1903: .asciz " cluster"
  23. 1904: .asciz ": \string"
  24. .align
  25. 1901: adr r0, 1902b
  26. bl printascii
  27. mov r0, r9
  28. bl printhex2
  29. adr r0, 1903b
  30. bl printascii
  31. mov r0, r10
  32. bl printhex2
  33. adr r0, 1904b
  34. bl printascii
  35. #endif
  36. .endm
  37. .arm
  38. .align
  39. ENTRY(mcpm_entry_point)
  40. ARM_BE8(setend be)
  41. THUMB( badr r12, 1f )
  42. THUMB( bx r12 )
  43. THUMB( .thumb )
  44. 1:
  45. mrc p15, 0, r0, c0, c0, 5 @ MPIDR
  46. ubfx r9, r0, #0, #8 @ r9 = cpu
  47. ubfx r10, r0, #8, #8 @ r10 = cluster
  48. mov r3, #MAX_CPUS_PER_CLUSTER
  49. mla r4, r3, r10, r9 @ r4 = canonical CPU index
  50. cmp r4, #(MAX_CPUS_PER_CLUSTER * MAX_NR_CLUSTERS)
  51. blo 2f
  52. /* We didn't expect this CPU. Try to cheaply make it quiet. */
  53. 1: wfi
  54. wfe
  55. b 1b
  56. 2: pr_dbg "kernel mcpm_entry_point\n"
  57. /*
  58. * MMU is off so we need to get to various variables in a
  59. * position independent way.
  60. */
  61. adr r5, 3f
  62. ldmia r5, {r0, r6, r7, r8, r11}
  63. add r0, r5, r0 @ r0 = mcpm_entry_early_pokes
  64. add r6, r5, r6 @ r6 = mcpm_entry_vectors
  65. ldr r7, [r5, r7] @ r7 = mcpm_power_up_setup_phys
  66. add r8, r5, r8 @ r8 = mcpm_sync
  67. add r11, r5, r11 @ r11 = first_man_locks
  68. @ Perform an early poke, if any
  69. add r0, r0, r4, lsl #3
  70. ldmia r0, {r0, r1}
  71. teq r0, #0
  72. strne r1, [r0]
  73. mov r0, #MCPM_SYNC_CLUSTER_SIZE
  74. mla r8, r0, r10, r8 @ r8 = sync cluster base
  75. @ Signal that this CPU is coming UP:
  76. mov r0, #CPU_COMING_UP
  77. mov r5, #MCPM_SYNC_CPU_SIZE
  78. mla r5, r9, r5, r8 @ r5 = sync cpu address
  79. strb r0, [r5]
  80. @ At this point, the cluster cannot unexpectedly enter the GOING_DOWN
  81. @ state, because there is at least one active CPU (this CPU).
  82. mov r0, #VLOCK_SIZE
  83. mla r11, r0, r10, r11 @ r11 = cluster first man lock
  84. mov r0, r11
  85. mov r1, r9 @ cpu
  86. bl vlock_trylock @ implies DMB
  87. cmp r0, #0 @ failed to get the lock?
  88. bne mcpm_setup_wait @ wait for cluster setup if so
  89. ldrb r0, [r8, #MCPM_SYNC_CLUSTER_CLUSTER]
  90. cmp r0, #CLUSTER_UP @ cluster already up?
  91. bne mcpm_setup @ if not, set up the cluster
  92. @ Otherwise, release the first man lock and skip setup:
  93. mov r0, r11
  94. bl vlock_unlock
  95. b mcpm_setup_complete
  96. mcpm_setup:
  97. @ Control dependency implies strb not observable before previous ldrb.
  98. @ Signal that the cluster is being brought up:
  99. mov r0, #INBOUND_COMING_UP
  100. strb r0, [r8, #MCPM_SYNC_CLUSTER_INBOUND]
  101. dmb
  102. @ Any CPU trying to take the cluster into CLUSTER_GOING_DOWN from this
  103. @ point onwards will observe INBOUND_COMING_UP and abort.
  104. @ Wait for any previously-pending cluster teardown operations to abort
  105. @ or complete:
  106. mcpm_teardown_wait:
  107. ldrb r0, [r8, #MCPM_SYNC_CLUSTER_CLUSTER]
  108. cmp r0, #CLUSTER_GOING_DOWN
  109. bne first_man_setup
  110. wfe
  111. b mcpm_teardown_wait
  112. first_man_setup:
  113. dmb
  114. @ If the outbound gave up before teardown started, skip cluster setup:
  115. cmp r0, #CLUSTER_UP
  116. beq mcpm_setup_leave
  117. @ power_up_setup is now responsible for setting up the cluster:
  118. cmp r7, #0
  119. mov r0, #1 @ second (cluster) affinity level
  120. blxne r7 @ Call power_up_setup if defined
  121. dmb
  122. mov r0, #CLUSTER_UP
  123. strb r0, [r8, #MCPM_SYNC_CLUSTER_CLUSTER]
  124. dmb
  125. mcpm_setup_leave:
  126. @ Leave the cluster setup critical section:
  127. mov r0, #INBOUND_NOT_COMING_UP
  128. strb r0, [r8, #MCPM_SYNC_CLUSTER_INBOUND]
  129. dsb st
  130. sev
  131. mov r0, r11
  132. bl vlock_unlock @ implies DMB
  133. b mcpm_setup_complete
  134. @ In the contended case, non-first men wait here for cluster setup
  135. @ to complete:
  136. mcpm_setup_wait:
  137. ldrb r0, [r8, #MCPM_SYNC_CLUSTER_CLUSTER]
  138. cmp r0, #CLUSTER_UP
  139. wfene
  140. bne mcpm_setup_wait
  141. dmb
  142. mcpm_setup_complete:
  143. @ If a platform-specific CPU setup hook is needed, it is
  144. @ called from here.
  145. cmp r7, #0
  146. mov r0, #0 @ first (CPU) affinity level
  147. blxne r7 @ Call power_up_setup if defined
  148. dmb
  149. @ Mark the CPU as up:
  150. mov r0, #CPU_UP
  151. strb r0, [r5]
  152. @ Observability order of CPU_UP and opening of the gate does not matter.
  153. mcpm_entry_gated:
  154. ldr r5, [r6, r4, lsl #2] @ r5 = CPU entry vector
  155. cmp r5, #0
  156. wfeeq
  157. beq mcpm_entry_gated
  158. dmb
  159. pr_dbg "released\n"
  160. bx r5
  161. .align 2
  162. 3: .word mcpm_entry_early_pokes - .
  163. .word mcpm_entry_vectors - 3b
  164. .word mcpm_power_up_setup_phys - 3b
  165. .word mcpm_sync - 3b
  166. .word first_man_locks - 3b
  167. ENDPROC(mcpm_entry_point)
  168. .bss
  169. .align CACHE_WRITEBACK_ORDER
  170. .type first_man_locks, #object
  171. first_man_locks:
  172. .space VLOCK_SIZE * MAX_NR_CLUSTERS
  173. .align CACHE_WRITEBACK_ORDER
  174. .type mcpm_entry_vectors, #object
  175. ENTRY(mcpm_entry_vectors)
  176. .space 4 * MAX_NR_CLUSTERS * MAX_CPUS_PER_CLUSTER
  177. .type mcpm_entry_early_pokes, #object
  178. ENTRY(mcpm_entry_early_pokes)
  179. .space 8 * MAX_NR_CLUSTERS * MAX_CPUS_PER_CLUSTER
  180. .type mcpm_power_up_setup_phys, #object
  181. ENTRY(mcpm_power_up_setup_phys)
  182. .space 4 @ set by mcpm_sync_init()