2 * Copyright (c) 2012, NVIDIA Corporation. All rights reserved.
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.
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
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/>.
17 #include <linux/linkage.h>
18 #include <linux/init.h>
20 #include <asm/cache.h>
21 #include <asm/asm-offsets.h>
22 #include <asm/hardware/cache-l2x0.h>
29 #define APB_MISC_GP_HIDREV 0x804
30 #define PMC_SCRATCH41 0x140
32 #define RESET_DATA(x) ((TEGRA_RESET_##x)*4)
34 #ifdef CONFIG_PM_SLEEP
38 * CPU boot vector when restarting the a CPU following
39 * an LP2 transition. Also branched to by LP0 and LP1 resume after
44 /* Enable coresight */
46 mcr p14, 0, r0, c7, c12, 6
52 #ifdef CONFIG_ARCH_TEGRA_3x_SOC
53 /* Are we on Tegra20? */
54 mov32 r6, TEGRA_APB_MISC_BASE
55 ldr r0, [r6, #APB_MISC_GP_HIDREV]
59 /* Clear the flow controller flags for this CPU. */
60 mov32 r2, TEGRA_FLOW_CTRL_BASE + FLOW_CTRL_CPU0_CSR @ CPU0 CSR
62 /* Clear event & intr flag */
64 #FLOW_CTRL_CSR_INTR_FLAG | FLOW_CTRL_CSR_EVENT_FLAG
65 movw r0, #0x0FFD @ enable, cluster_switch, immed, & bitmaps
71 #ifdef CONFIG_HAVE_ARM_SCU
73 mov32 r0, TEGRA_ARM_PERIF_BASE
79 /* L2 cache resume & re-enable */
80 l2_cache_resume r0, r1, r2, l2x0_saved_regs_addr
86 #ifdef CONFIG_CACHE_L2X0
87 .globl l2x0_saved_regs_addr
93 ENTRY(__tegra_cpu_reset_handler_start)
96 * __tegra_cpu_reset_handler:
98 * Common handler for all CPU reset events.
100 * Register usage within the reset handler:
102 * R7 = CPU present (to the OS) mask
103 * R8 = CPU in LP1 state mask
104 * R9 = CPU in LP2 state mask
107 * R12 = pointer to reset handler data
109 * NOTE: This code is copied to IRAM. All code and data accesses
110 * must be position-independent.
113 .align L1_CACHE_SHIFT
114 ENTRY(__tegra_cpu_reset_handler)
116 cpsid aif, 0x13 @ SVC mode, interrupts disabled
117 mrc p15, 0, r10, c0, c0, 5 @ MPIDR
118 and r10, r10, #0x3 @ R10 = CPU number
120 mov r11, r11, lsl r10 @ R11 = CPU mask
121 adr r12, __tegra_cpu_reset_handler_data
124 /* Does the OS know about this CPU? */
125 ldr r7, [r12, #RESET_DATA(MASK_PRESENT)]
126 tst r7, r11 @ if !present
127 bleq __die @ CPU not present (to OS)
130 #ifdef CONFIG_ARCH_TEGRA_2x_SOC
131 /* Are we on Tegra20? */
132 mov32 r6, TEGRA_APB_MISC_BASE
133 ldr r0, [r6, #APB_MISC_GP_HIDREV]
137 /* If not CPU0, don't let CPU0 reset CPU1 now that CPU1 is coming up. */
138 mov32 r6, TEGRA_PMC_BASE
141 strne r0, [r6, #PMC_SCRATCH41]
145 /* Waking up from LP2? */
146 ldr r9, [r12, #RESET_DATA(MASK_LP2)]
147 tst r9, r11 @ if in_lp2
149 ldr lr, [r12, #RESET_DATA(STARTUP_LP2)]
151 bleq __die @ no LP2 startup handler
158 * Can only be secondary boot (initial or hotplug) but CPU 0
162 bleq __die @ CPU0 cannot be here
163 ldr lr, [r12, #RESET_DATA(STARTUP_SECONDARY)]
165 bleq __die @ no secondary startup handler
170 * We don't know why the CPU reset. Just kill it.
171 * The LR register will contain the address we died at + 4.
176 mov32 r7, TEGRA_PMC_BASE
177 str lr, [r7, #PMC_SCRATCH41]
179 mov32 r7, TEGRA_CLK_RESET_BASE
181 /* Are we on Tegra20? */
182 mov32 r6, TEGRA_APB_MISC_BASE
183 ldr r0, [r6, #APB_MISC_GP_HIDREV]
188 #ifdef CONFIG_ARCH_TEGRA_2x_SOC
191 str r1, [r7, #0x340] @ CLK_RST_CPU_CMPLX_SET
194 #ifdef CONFIG_ARCH_TEGRA_3x_SOC
195 mov32 r6, TEGRA_FLOW_CTRL_BASE
198 moveq r1, #FLOW_CTRL_HALT_CPU0_EVENTS
199 moveq r2, #FLOW_CTRL_CPU0_CSR
200 movne r1, r10, lsl #3
201 addne r2, r1, #(FLOW_CTRL_CPU1_CSR-8)
202 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. */
207 orr r0, r0, #FLOW_CTRL_CSR_INTR_FLAG | FLOW_CTRL_CSR_EVENT_FLAG
208 orr r0, r0, #FLOW_CTRL_CSR_ENABLE
211 /* Unconditionally halt this CPU */
212 mov r0, #FLOW_CTRL_WAITEVENT
214 ldr r0, [r6, +r1] @ memory barrier
218 wfi @ CPU should be power gated here
220 /* If the CPU didn't power gate above just kill it's clock. */
223 str r0, [r7, #348] @ CLK_CPU_CMPLX_SET
226 /* If the CPU still isn't dead, just spin here. */
228 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
237 .align L1_CACHE_SHIFT
239 ENTRY(__tegra_cpu_reset_handler_end)