reset-handler.S 6.5 KB

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