reset-handler.S 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. /*
  2. * Copyright (c) 2012, NVIDIA Corporation. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include <linux/init.h>
  17. #include <linux/linkage.h>
  18. #include <soc/tegra/fuse.h>
  19. #include <asm/asm-offsets.h>
  20. #include <asm/cache.h>
  21. #include "flowctrl.h"
  22. #include "iomap.h"
  23. #include "reset.h"
  24. #include "sleep.h"
  25. #define PMC_SCRATCH41 0x140
  26. #define RESET_DATA(x) ((TEGRA_RESET_##x)*4)
  27. #ifdef CONFIG_PM_SLEEP
  28. /*
  29. * tegra_resume
  30. *
  31. * CPU boot vector when restarting the a CPU following
  32. * an LP2 transition. Also branched to by LP0 and LP1 resume after
  33. * re-enabling sdram.
  34. *
  35. * r6: SoC ID
  36. * r8: CPU part number
  37. */
  38. ENTRY(tegra_resume)
  39. check_cpu_part_num 0xc09, r8, r9
  40. bleq v7_invalidate_l1
  41. cpu_id r0
  42. cmp r0, #0 @ CPU0?
  43. THUMB( it ne )
  44. bne cpu_resume @ no
  45. /* Are we on Tegra20? */
  46. cmp r6, #TEGRA20
  47. beq 1f @ Yes
  48. /* Clear the flow controller flags for this CPU. */
  49. cpu_to_csr_reg r1, r0
  50. mov32 r2, TEGRA_FLOW_CTRL_BASE
  51. ldr r1, [r2, r1]
  52. /* Clear event & intr flag */
  53. orr r1, r1, \
  54. #FLOW_CTRL_CSR_INTR_FLAG | FLOW_CTRL_CSR_EVENT_FLAG
  55. movw r0, #0x3FFD @ enable, cluster_switch, immed, bitmaps
  56. @ & ext flags for CPU power mgnt
  57. bic r1, r1, r0
  58. str r1, [r2]
  59. 1:
  60. mov32 r9, 0xc09
  61. cmp r8, r9
  62. bne end_ca9_scu_l2_resume
  63. #ifdef CONFIG_HAVE_ARM_SCU
  64. /* enable SCU */
  65. mov32 r0, TEGRA_ARM_PERIF_BASE
  66. ldr r1, [r0]
  67. orr r1, r1, #1
  68. str r1, [r0]
  69. #endif
  70. #ifdef CONFIG_CACHE_L2X0
  71. /* L2 cache resume & re-enable */
  72. bl l2c310_early_resume
  73. #endif
  74. end_ca9_scu_l2_resume:
  75. mov32 r9, 0xc0f
  76. cmp r8, r9
  77. bleq tegra_init_l2_for_a15
  78. b cpu_resume
  79. ENDPROC(tegra_resume)
  80. #endif
  81. .align L1_CACHE_SHIFT
  82. ENTRY(__tegra_cpu_reset_handler_start)
  83. /*
  84. * __tegra_cpu_reset_handler:
  85. *
  86. * Common handler for all CPU reset events.
  87. *
  88. * Register usage within the reset handler:
  89. *
  90. * Others: scratch
  91. * R6 = SoC ID
  92. * R7 = CPU present (to the OS) mask
  93. * R8 = CPU in LP1 state mask
  94. * R9 = CPU in LP2 state mask
  95. * R10 = CPU number
  96. * R11 = CPU mask
  97. * R12 = pointer to reset handler data
  98. *
  99. * NOTE: This code is copied to IRAM. All code and data accesses
  100. * must be position-independent.
  101. */
  102. .align L1_CACHE_SHIFT
  103. ENTRY(__tegra_cpu_reset_handler)
  104. cpsid aif, 0x13 @ SVC mode, interrupts disabled
  105. tegra_get_soc_id TEGRA_APB_MISC_BASE, r6
  106. #ifdef CONFIG_ARCH_TEGRA_2x_SOC
  107. t20_check:
  108. cmp r6, #TEGRA20
  109. bne after_t20_check
  110. t20_errata:
  111. # Tegra20 is a Cortex-A9 r1p1
  112. mrc p15, 0, r0, c1, c0, 0 @ read system control register
  113. orr r0, r0, #1 << 14 @ erratum 716044
  114. mcr p15, 0, r0, c1, c0, 0 @ write system control register
  115. mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register
  116. orr r0, r0, #1 << 4 @ erratum 742230
  117. orr r0, r0, #1 << 11 @ erratum 751472
  118. mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register
  119. b after_errata
  120. after_t20_check:
  121. #endif
  122. #ifdef CONFIG_ARCH_TEGRA_3x_SOC
  123. t30_check:
  124. cmp r6, #TEGRA30
  125. bne after_t30_check
  126. t30_errata:
  127. # Tegra30 is a Cortex-A9 r2p9
  128. mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register
  129. orr r0, r0, #1 << 6 @ erratum 743622
  130. orr r0, r0, #1 << 11 @ erratum 751472
  131. mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register
  132. b after_errata
  133. after_t30_check:
  134. #endif
  135. after_errata:
  136. mrc p15, 0, r10, c0, c0, 5 @ MPIDR
  137. and r10, r10, #0x3 @ R10 = CPU number
  138. mov r11, #1
  139. mov r11, r11, lsl r10 @ R11 = CPU mask
  140. adr r12, __tegra_cpu_reset_handler_data
  141. #ifdef CONFIG_SMP
  142. /* Does the OS know about this CPU? */
  143. ldr r7, [r12, #RESET_DATA(MASK_PRESENT)]
  144. tst r7, r11 @ if !present
  145. bleq __die @ CPU not present (to OS)
  146. #endif
  147. #ifdef CONFIG_ARCH_TEGRA_2x_SOC
  148. /* Are we on Tegra20? */
  149. cmp r6, #TEGRA20
  150. bne 1f
  151. /* If not CPU0, don't let CPU0 reset CPU1 now that CPU1 is coming up. */
  152. mov32 r5, TEGRA_PMC_BASE
  153. mov r0, #0
  154. cmp r10, #0
  155. strne r0, [r5, #PMC_SCRATCH41]
  156. 1:
  157. #endif
  158. /* Waking up from LP1? */
  159. ldr r8, [r12, #RESET_DATA(MASK_LP1)]
  160. tst r8, r11 @ if in_lp1
  161. beq __is_not_lp1
  162. cmp r10, #0
  163. bne __die @ only CPU0 can be here
  164. ldr lr, [r12, #RESET_DATA(STARTUP_LP1)]
  165. cmp lr, #0
  166. bleq __die @ no LP1 startup handler
  167. THUMB( add lr, lr, #1 ) @ switch to Thumb mode
  168. bx lr
  169. __is_not_lp1:
  170. /* Waking up from LP2? */
  171. ldr r9, [r12, #RESET_DATA(MASK_LP2)]
  172. tst r9, r11 @ if in_lp2
  173. beq __is_not_lp2
  174. ldr lr, [r12, #RESET_DATA(STARTUP_LP2)]
  175. cmp lr, #0
  176. bleq __die @ no LP2 startup handler
  177. bx lr
  178. __is_not_lp2:
  179. #ifdef CONFIG_SMP
  180. /*
  181. * Can only be secondary boot (initial or hotplug)
  182. * CPU0 can't be here for Tegra20/30
  183. */
  184. cmp r6, #TEGRA114
  185. beq __no_cpu0_chk
  186. cmp r10, #0
  187. bleq __die @ CPU0 cannot be here
  188. __no_cpu0_chk:
  189. ldr lr, [r12, #RESET_DATA(STARTUP_SECONDARY)]
  190. cmp lr, #0
  191. bleq __die @ no secondary startup handler
  192. bx lr
  193. #endif
  194. /*
  195. * We don't know why the CPU reset. Just kill it.
  196. * The LR register will contain the address we died at + 4.
  197. */
  198. __die:
  199. sub lr, lr, #4
  200. mov32 r7, TEGRA_PMC_BASE
  201. str lr, [r7, #PMC_SCRATCH41]
  202. mov32 r7, TEGRA_CLK_RESET_BASE
  203. /* Are we on Tegra20? */
  204. cmp r6, #TEGRA20
  205. bne 1f
  206. #ifdef CONFIG_ARCH_TEGRA_2x_SOC
  207. mov32 r0, 0x1111
  208. mov r1, r0, lsl r10
  209. str r1, [r7, #0x340] @ CLK_RST_CPU_CMPLX_SET
  210. #endif
  211. 1:
  212. #ifdef CONFIG_ARCH_TEGRA_3x_SOC
  213. mov32 r6, TEGRA_FLOW_CTRL_BASE
  214. cmp r10, #0
  215. moveq r1, #FLOW_CTRL_HALT_CPU0_EVENTS
  216. moveq r2, #FLOW_CTRL_CPU0_CSR
  217. movne r1, r10, lsl #3
  218. addne r2, r1, #(FLOW_CTRL_CPU1_CSR-8)
  219. addne r1, r1, #(FLOW_CTRL_HALT_CPU1_EVENTS-8)
  220. /* Clear CPU "event" and "interrupt" flags and power gate
  221. it when halting but not before it is in the "WFI" state. */
  222. ldr r0, [r6, +r2]
  223. orr r0, r0, #FLOW_CTRL_CSR_INTR_FLAG | FLOW_CTRL_CSR_EVENT_FLAG
  224. orr r0, r0, #FLOW_CTRL_CSR_ENABLE
  225. str r0, [r6, +r2]
  226. /* Unconditionally halt this CPU */
  227. mov r0, #FLOW_CTRL_WAITEVENT
  228. str r0, [r6, +r1]
  229. ldr r0, [r6, +r1] @ memory barrier
  230. dsb
  231. isb
  232. wfi @ CPU should be power gated here
  233. /* If the CPU didn't power gate above just kill it's clock. */
  234. mov r0, r11, lsl #8
  235. str r0, [r7, #348] @ CLK_CPU_CMPLX_SET
  236. #endif
  237. /* If the CPU still isn't dead, just spin here. */
  238. b .
  239. ENDPROC(__tegra_cpu_reset_handler)
  240. .align L1_CACHE_SHIFT
  241. .type __tegra_cpu_reset_handler_data, %object
  242. .globl __tegra_cpu_reset_handler_data
  243. __tegra_cpu_reset_handler_data:
  244. .rept TEGRA_RESET_DATA_SIZE
  245. .long 0
  246. .endr
  247. .align L1_CACHE_SHIFT
  248. ENTRY(__tegra_cpu_reset_handler_end)