reset-handler.S 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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. tegra_get_soc_id TEGRA_APB_MISC_BASE, r6
  46. /* Are we on Tegra20? */
  47. cmp r6, #TEGRA20
  48. beq 1f @ Yes
  49. /* Clear the flow controller flags for this CPU. */
  50. cpu_to_csr_reg r1, r0
  51. mov32 r2, TEGRA_FLOW_CTRL_BASE
  52. ldr r1, [r2, r1]
  53. /* Clear event & intr flag */
  54. orr r1, r1, \
  55. #FLOW_CTRL_CSR_INTR_FLAG | FLOW_CTRL_CSR_EVENT_FLAG
  56. movw r0, #0x3FFD @ enable, cluster_switch, immed, bitmaps
  57. @ & ext flags for CPU power mgnt
  58. bic r1, r1, r0
  59. str r1, [r2]
  60. 1:
  61. mov32 r9, 0xc09
  62. cmp r8, r9
  63. bne end_ca9_scu_l2_resume
  64. #ifdef CONFIG_HAVE_ARM_SCU
  65. /* enable SCU */
  66. mov32 r0, TEGRA_ARM_PERIF_BASE
  67. ldr r1, [r0]
  68. orr r1, r1, #1
  69. str r1, [r0]
  70. #endif
  71. #ifdef CONFIG_CACHE_L2X0
  72. /* L2 cache resume & re-enable */
  73. bl l2c310_early_resume
  74. #endif
  75. end_ca9_scu_l2_resume:
  76. mov32 r9, 0xc0f
  77. cmp r8, r9
  78. bleq tegra_init_l2_for_a15
  79. b cpu_resume
  80. ENDPROC(tegra_resume)
  81. #endif
  82. .align L1_CACHE_SHIFT
  83. ENTRY(__tegra_cpu_reset_handler_start)
  84. /*
  85. * __tegra_cpu_reset_handler:
  86. *
  87. * Common handler for all CPU reset events.
  88. *
  89. * Register usage within the reset handler:
  90. *
  91. * Others: scratch
  92. * R6 = SoC ID
  93. * R7 = CPU present (to the OS) mask
  94. * R8 = CPU in LP1 state mask
  95. * R9 = CPU in LP2 state mask
  96. * R10 = CPU number
  97. * R11 = CPU mask
  98. * R12 = pointer to reset handler data
  99. *
  100. * NOTE: This code is copied to IRAM. All code and data accesses
  101. * must be position-independent.
  102. */
  103. .align L1_CACHE_SHIFT
  104. ENTRY(__tegra_cpu_reset_handler)
  105. cpsid aif, 0x13 @ SVC mode, interrupts disabled
  106. tegra_get_soc_id TEGRA_APB_MISC_BASE, r6
  107. #ifdef CONFIG_ARCH_TEGRA_2x_SOC
  108. t20_check:
  109. cmp r6, #TEGRA20
  110. bne after_t20_check
  111. t20_errata:
  112. # Tegra20 is a Cortex-A9 r1p1
  113. mrc p15, 0, r0, c1, c0, 0 @ read system control register
  114. orr r0, r0, #1 << 14 @ erratum 716044
  115. mcr p15, 0, r0, c1, c0, 0 @ write system control register
  116. mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register
  117. orr r0, r0, #1 << 4 @ erratum 742230
  118. orr r0, r0, #1 << 11 @ erratum 751472
  119. mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register
  120. b after_errata
  121. after_t20_check:
  122. #endif
  123. #ifdef CONFIG_ARCH_TEGRA_3x_SOC
  124. t30_check:
  125. cmp r6, #TEGRA30
  126. bne after_t30_check
  127. t30_errata:
  128. # Tegra30 is a Cortex-A9 r2p9
  129. mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register
  130. orr r0, r0, #1 << 6 @ erratum 743622
  131. orr r0, r0, #1 << 11 @ erratum 751472
  132. mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register
  133. b after_errata
  134. after_t30_check:
  135. #endif
  136. after_errata:
  137. mrc p15, 0, r10, c0, c0, 5 @ MPIDR
  138. and r10, r10, #0x3 @ R10 = CPU number
  139. mov r11, #1
  140. mov r11, r11, lsl r10 @ R11 = CPU mask
  141. adr r12, __tegra_cpu_reset_handler_data
  142. #ifdef CONFIG_SMP
  143. /* Does the OS know about this CPU? */
  144. ldr r7, [r12, #RESET_DATA(MASK_PRESENT)]
  145. tst r7, r11 @ if !present
  146. bleq __die @ CPU not present (to OS)
  147. #endif
  148. #ifdef CONFIG_ARCH_TEGRA_2x_SOC
  149. /* Are we on Tegra20? */
  150. cmp r6, #TEGRA20
  151. bne 1f
  152. /* If not CPU0, don't let CPU0 reset CPU1 now that CPU1 is coming up. */
  153. mov32 r5, TEGRA_IRAM_BASE + TEGRA_IRAM_RESET_HANDLER_OFFSET
  154. mov r0, #CPU_NOT_RESETTABLE
  155. cmp r10, #0
  156. strneb r0, [r5, #__tegra20_cpu1_resettable_status_offset]
  157. 1:
  158. #endif
  159. /* Waking up from LP1? */
  160. ldr r8, [r12, #RESET_DATA(MASK_LP1)]
  161. tst r8, r11 @ if in_lp1
  162. beq __is_not_lp1
  163. cmp r10, #0
  164. bne __die @ only CPU0 can be here
  165. ldr lr, [r12, #RESET_DATA(STARTUP_LP1)]
  166. cmp lr, #0
  167. bleq __die @ no LP1 startup handler
  168. THUMB( add lr, lr, #1 ) @ switch to Thumb mode
  169. bx lr
  170. __is_not_lp1:
  171. /* Waking up from LP2? */
  172. ldr r9, [r12, #RESET_DATA(MASK_LP2)]
  173. tst r9, r11 @ if in_lp2
  174. beq __is_not_lp2
  175. ldr lr, [r12, #RESET_DATA(STARTUP_LP2)]
  176. cmp lr, #0
  177. bleq __die @ no LP2 startup handler
  178. bx lr
  179. __is_not_lp2:
  180. #ifdef CONFIG_SMP
  181. /*
  182. * Can only be secondary boot (initial or hotplug)
  183. * CPU0 can't be here for Tegra20/30
  184. */
  185. cmp r6, #TEGRA114
  186. beq __no_cpu0_chk
  187. cmp r10, #0
  188. bleq __die @ CPU0 cannot be here
  189. __no_cpu0_chk:
  190. ldr lr, [r12, #RESET_DATA(STARTUP_SECONDARY)]
  191. cmp lr, #0
  192. bleq __die @ no secondary startup handler
  193. bx lr
  194. #endif
  195. /*
  196. * We don't know why the CPU reset. Just kill it.
  197. * The LR register will contain the address we died at + 4.
  198. */
  199. __die:
  200. sub lr, lr, #4
  201. mov32 r7, TEGRA_PMC_BASE
  202. str lr, [r7, #PMC_SCRATCH41]
  203. mov32 r7, TEGRA_CLK_RESET_BASE
  204. /* Are we on Tegra20? */
  205. cmp r6, #TEGRA20
  206. bne 1f
  207. #ifdef CONFIG_ARCH_TEGRA_2x_SOC
  208. mov32 r0, 0x1111
  209. mov r1, r0, lsl r10
  210. str r1, [r7, #0x340] @ CLK_RST_CPU_CMPLX_SET
  211. #endif
  212. 1:
  213. #ifdef CONFIG_ARCH_TEGRA_3x_SOC
  214. mov32 r6, TEGRA_FLOW_CTRL_BASE
  215. cmp r10, #0
  216. moveq r1, #FLOW_CTRL_HALT_CPU0_EVENTS
  217. moveq r2, #FLOW_CTRL_CPU0_CSR
  218. movne r1, r10, lsl #3
  219. addne r2, r1, #(FLOW_CTRL_CPU1_CSR-8)
  220. addne r1, r1, #(FLOW_CTRL_HALT_CPU1_EVENTS-8)
  221. /* Clear CPU "event" and "interrupt" flags and power gate
  222. it when halting but not before it is in the "WFI" state. */
  223. ldr r0, [r6, +r2]
  224. orr r0, r0, #FLOW_CTRL_CSR_INTR_FLAG | FLOW_CTRL_CSR_EVENT_FLAG
  225. orr r0, r0, #FLOW_CTRL_CSR_ENABLE
  226. str r0, [r6, +r2]
  227. /* Unconditionally halt this CPU */
  228. mov r0, #FLOW_CTRL_WAITEVENT
  229. str r0, [r6, +r1]
  230. ldr r0, [r6, +r1] @ memory barrier
  231. dsb
  232. isb
  233. wfi @ CPU should be power gated here
  234. /* If the CPU didn't power gate above just kill it's clock. */
  235. mov r0, r11, lsl #8
  236. str r0, [r7, #348] @ CLK_CPU_CMPLX_SET
  237. #endif
  238. /* If the CPU still isn't dead, just spin here. */
  239. b .
  240. ENDPROC(__tegra_cpu_reset_handler)
  241. .align L1_CACHE_SHIFT
  242. .type __tegra_cpu_reset_handler_data, %object
  243. .globl __tegra_cpu_reset_handler_data
  244. __tegra_cpu_reset_handler_data:
  245. .rept TEGRA_RESET_DATA_SIZE
  246. .long 0
  247. .endr
  248. .globl __tegra20_cpu1_resettable_status_offset
  249. .equ __tegra20_cpu1_resettable_status_offset, \
  250. . - __tegra_cpu_reset_handler_start
  251. .byte 0
  252. .align L1_CACHE_SHIFT
  253. ENTRY(__tegra_cpu_reset_handler_end)