reset-handler.S 6.4 KB

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