reset-handler.S 6.8 KB

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