reset-handler.S 6.5 KB

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