reset-handler.S 6.5 KB

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