blob: bdd571e774433f5f4a77ba3d989b3127129b0715 [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
Achin Gupta4f6ad662013-10-25 09:08:21 +010044 /* -----------------------------------------------------
45 * This cpu has been physically powered up. Depending
46 * upon whether it was resumed from suspend or simply
47 * turned on, call the common power on finisher with
48 * the handlers (chosen depending upon original state).
49 * For ease, the finisher is called with coherent
50 * stacks. This allows the cluster/cpu finishers to
51 * enter coherency and enable the mmu without running
52 * into issues. We switch back to normal stacks once
53 * all this is done.
54 * -----------------------------------------------------
55 */
Andrew Thoelke38bde412014-03-18 13:46:55 +000056func psci_aff_on_finish_entry
Achin Gupta4f6ad662013-10-25 09:08:21 +010057 adr x23, psci_afflvl_on_finishers
58 b psci_aff_common_finish_entry
59
60psci_aff_suspend_finish_entry:
61 adr x23, psci_afflvl_suspend_finishers
62
63psci_aff_common_finish_entry:
64 adr x22, psci_afflvl_power_on_finish
Achin Guptab739f222014-01-18 16:50:09 +000065
66 /* ---------------------------------------------
67 * Exceptions should not occur at this point.
68 * Set VBAR in order to handle and report any
69 * that do occur
70 * ---------------------------------------------
71 */
72 adr x0, early_exceptions
73 msr vbar_el3, x0
74 isb
75
Jeenu Viswambharancaa84932014-02-06 10:36:15 +000076 /* ---------------------------------------------
77 * Use SP_EL0 for the C runtime stack.
78 * ---------------------------------------------
79 */
80 msr spsel, #0
81 isb
82
Achin Gupta4f6ad662013-10-25 09:08:21 +010083 bl read_mpidr
84 mov x19, x0
85 bl platform_set_coherent_stack
86
87 /* ---------------------------------------------
88 * Call the finishers starting from affinity
89 * level 0.
90 * ---------------------------------------------
91 */
Achin Guptaa45e3972013-12-05 15:10:48 +000092 mov x0, x19
93 bl get_power_on_target_afflvl
94 cmp x0, xzr
95 b.lt _panic
Achin Gupta4f6ad662013-10-25 09:08:21 +010096 mov x3, x23
97 mov x2, x0
98 mov x0, x19
99 mov x1, #MPIDR_AFFLVL0
100 blr x22
Achin Gupta4f6ad662013-10-25 09:08:21 +0100101
102 /* --------------------------------------------
103 * Give ourselves a stack allocated in Normal
104 * -IS-WBWA memory
105 * --------------------------------------------
106 */
107 mov x0, x19
108 bl platform_set_stack
109
Jeenu Viswambharancaa84932014-02-06 10:36:15 +0000110 zero_callee_saved_regs
111 b el3_exit
Achin Gupta4f6ad662013-10-25 09:08:21 +0100112_panic:
113 b _panic
114
115 /* -----------------------------------------------------
116 * The following two stubs give the calling cpu a
117 * coherent stack to allow flushing of caches without
118 * suffering from stack coherency issues
119 * -----------------------------------------------------
120 */
Andrew Thoelke38bde412014-03-18 13:46:55 +0000121func __psci_cpu_off
Achin Gupta4f6ad662013-10-25 09:08:21 +0100122 func_prologue
123 sub sp, sp, #0x10
124 stp x19, x20, [sp, #0]
125 mov x19, sp
126 bl read_mpidr
127 bl platform_set_coherent_stack
128 bl psci_cpu_off
129 mov x1, #PSCI_E_SUCCESS
130 cmp x0, x1
131 b.eq final_wfi
132 mov sp, x19
133 ldp x19, x20, [sp,#0]
134 add sp, sp, #0x10
135 func_epilogue
136 ret
137
Andrew Thoelke38bde412014-03-18 13:46:55 +0000138func __psci_cpu_suspend
Achin Gupta4f6ad662013-10-25 09:08:21 +0100139 func_prologue
140 sub sp, sp, #0x20
141 stp x19, x20, [sp, #0]
142 stp x21, x22, [sp, #0x10]
143 mov x19, sp
144 mov x20, x0
145 mov x21, x1
146 mov x22, x2
147 bl read_mpidr
148 bl platform_set_coherent_stack
149 mov x0, x20
150 mov x1, x21
151 mov x2, x22
152 bl psci_cpu_suspend
153 mov x1, #PSCI_E_SUCCESS
154 cmp x0, x1
155 b.eq final_wfi
156 mov sp, x19
157 ldp x21, x22, [sp,#0x10]
158 ldp x19, x20, [sp,#0]
159 add sp, sp, #0x20
160 func_epilogue
161 ret
162
Andrew Thoelke38bde412014-03-18 13:46:55 +0000163func final_wfi
Achin Gupta4f6ad662013-10-25 09:08:21 +0100164 dsb sy
165 wfi
166wfi_spill:
167 b wfi_spill
168