blob: 361dfde4535564695ff8e41de046d08f4eeb99ef [file] [log] [blame]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001/*
Dan Handleye83b0ca2014-01-14 18:17:09 +00002 * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved.
Achin Gupta4f6ad662013-10-25 09:08:21 +01003 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9 *
10 * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * Neither the name of ARM nor the names of its contributors may be used
15 * to endorse or promote products derived from this software without specific
16 * prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#include <arch.h>
32#include <platform.h>
33#include <psci.h>
34#include <psci_private.h>
Achin Guptac8afc782013-11-25 18:45:02 +000035#include <runtime_svc.h>
Achin Gupta4f6ad662013-10-25 09:08:21 +010036#include <asm_macros.S>
Jeenu Viswambharancaa84932014-02-06 10:36:15 +000037#include <cm_macros.S>
Achin Gupta4f6ad662013-10-25 09:08:21 +010038
39 .globl psci_aff_on_finish_entry
40 .globl psci_aff_suspend_finish_entry
41 .globl __psci_cpu_off
42 .globl __psci_cpu_suspend
43
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000044 .section .text, "ax"; .align 3
Achin Gupta4f6ad662013-10-25 09:08:21 +010045
46 /* -----------------------------------------------------
47 * This cpu has been physically powered up. Depending
48 * upon whether it was resumed from suspend or simply
49 * turned on, call the common power on finisher with
50 * the handlers (chosen depending upon original state).
51 * For ease, the finisher is called with coherent
52 * stacks. This allows the cluster/cpu finishers to
53 * enter coherency and enable the mmu without running
54 * into issues. We switch back to normal stacks once
55 * all this is done.
56 * -----------------------------------------------------
57 */
58psci_aff_on_finish_entry:
59 adr x23, psci_afflvl_on_finishers
60 b psci_aff_common_finish_entry
61
62psci_aff_suspend_finish_entry:
63 adr x23, psci_afflvl_suspend_finishers
64
65psci_aff_common_finish_entry:
66 adr x22, psci_afflvl_power_on_finish
Achin Guptab739f222014-01-18 16:50:09 +000067
68 /* ---------------------------------------------
69 * Exceptions should not occur at this point.
70 * Set VBAR in order to handle and report any
71 * that do occur
72 * ---------------------------------------------
73 */
74 adr x0, early_exceptions
75 msr vbar_el3, x0
76 isb
77
Jeenu Viswambharancaa84932014-02-06 10:36:15 +000078 /* ---------------------------------------------
79 * Use SP_EL0 for the C runtime stack.
80 * ---------------------------------------------
81 */
82 msr spsel, #0
83 isb
84
Achin Gupta4f6ad662013-10-25 09:08:21 +010085 bl read_mpidr
86 mov x19, x0
87 bl platform_set_coherent_stack
88
89 /* ---------------------------------------------
90 * Call the finishers starting from affinity
91 * level 0.
92 * ---------------------------------------------
93 */
Achin Guptaa45e3972013-12-05 15:10:48 +000094 mov x0, x19
95 bl get_power_on_target_afflvl
96 cmp x0, xzr
97 b.lt _panic
Achin Gupta4f6ad662013-10-25 09:08:21 +010098 mov x3, x23
99 mov x2, x0
100 mov x0, x19
101 mov x1, #MPIDR_AFFLVL0
102 blr x22
Achin Gupta4f6ad662013-10-25 09:08:21 +0100103
104 /* --------------------------------------------
105 * Give ourselves a stack allocated in Normal
106 * -IS-WBWA memory
107 * --------------------------------------------
108 */
109 mov x0, x19
110 bl platform_set_stack
111
Jeenu Viswambharancaa84932014-02-06 10:36:15 +0000112 zero_callee_saved_regs
113 b el3_exit
Achin Gupta4f6ad662013-10-25 09:08:21 +0100114_panic:
115 b _panic
116
117 /* -----------------------------------------------------
118 * The following two stubs give the calling cpu a
119 * coherent stack to allow flushing of caches without
120 * suffering from stack coherency issues
121 * -----------------------------------------------------
122 */
123__psci_cpu_off:
124 func_prologue
125 sub sp, sp, #0x10
126 stp x19, x20, [sp, #0]
127 mov x19, sp
128 bl read_mpidr
129 bl platform_set_coherent_stack
130 bl psci_cpu_off
131 mov x1, #PSCI_E_SUCCESS
132 cmp x0, x1
133 b.eq final_wfi
134 mov sp, x19
135 ldp x19, x20, [sp,#0]
136 add sp, sp, #0x10
137 func_epilogue
138 ret
139
140__psci_cpu_suspend:
141 func_prologue
142 sub sp, sp, #0x20
143 stp x19, x20, [sp, #0]
144 stp x21, x22, [sp, #0x10]
145 mov x19, sp
146 mov x20, x0
147 mov x21, x1
148 mov x22, x2
149 bl read_mpidr
150 bl platform_set_coherent_stack
151 mov x0, x20
152 mov x1, x21
153 mov x2, x22
154 bl psci_cpu_suspend
155 mov x1, #PSCI_E_SUCCESS
156 cmp x0, x1
157 b.eq final_wfi
158 mov sp, x19
159 ldp x21, x22, [sp,#0x10]
160 ldp x19, x20, [sp,#0]
161 add sp, sp, #0x20
162 func_epilogue
163 ret
164
165final_wfi:
166 dsb sy
167 wfi
168wfi_spill:
169 b wfi_spill
170