blob: e2c690db3a7e51b4a9fb664199f8ad8cfa26c9d9 [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>
Achin Gupta4f6ad662013-10-25 09:08:21 +010032#include <asm_macros.S>
Jeenu Viswambharancaa84932014-02-06 10:36:15 +000033#include <cm_macros.S>
Dan Handley2bd4ef22014-04-09 13:14:54 +010034#include <psci.h>
Achin Gupta4f6ad662013-10-25 09:08:21 +010035
36 .globl psci_aff_on_finish_entry
37 .globl psci_aff_suspend_finish_entry
38 .globl __psci_cpu_off
39 .globl __psci_cpu_suspend
40
Achin Gupta4f6ad662013-10-25 09:08:21 +010041 /* -----------------------------------------------------
42 * This cpu has been physically powered up. Depending
43 * upon whether it was resumed from suspend or simply
44 * turned on, call the common power on finisher with
45 * the handlers (chosen depending upon original state).
46 * For ease, the finisher is called with coherent
47 * stacks. This allows the cluster/cpu finishers to
48 * enter coherency and enable the mmu without running
49 * into issues. We switch back to normal stacks once
50 * all this is done.
51 * -----------------------------------------------------
52 */
Andrew Thoelke38bde412014-03-18 13:46:55 +000053func psci_aff_on_finish_entry
Achin Gupta4f6ad662013-10-25 09:08:21 +010054 adr x23, psci_afflvl_on_finishers
55 b psci_aff_common_finish_entry
56
57psci_aff_suspend_finish_entry:
58 adr x23, psci_afflvl_suspend_finishers
59
60psci_aff_common_finish_entry:
61 adr x22, psci_afflvl_power_on_finish
Achin Guptab739f222014-01-18 16:50:09 +000062
63 /* ---------------------------------------------
64 * Exceptions should not occur at this point.
65 * Set VBAR in order to handle and report any
66 * that do occur
67 * ---------------------------------------------
68 */
69 adr x0, early_exceptions
70 msr vbar_el3, x0
71 isb
72
Jeenu Viswambharancaa84932014-02-06 10:36:15 +000073 /* ---------------------------------------------
74 * Use SP_EL0 for the C runtime stack.
75 * ---------------------------------------------
76 */
77 msr spsel, #0
78 isb
79
Achin Gupta4f6ad662013-10-25 09:08:21 +010080 bl read_mpidr
81 mov x19, x0
82 bl platform_set_coherent_stack
83
84 /* ---------------------------------------------
85 * Call the finishers starting from affinity
86 * level 0.
87 * ---------------------------------------------
88 */
Achin Guptaa45e3972013-12-05 15:10:48 +000089 mov x0, x19
90 bl get_power_on_target_afflvl
91 cmp x0, xzr
92 b.lt _panic
Achin Gupta4f6ad662013-10-25 09:08:21 +010093 mov x3, x23
94 mov x2, x0
95 mov x0, x19
96 mov x1, #MPIDR_AFFLVL0
97 blr x22
Achin Gupta4f6ad662013-10-25 09:08:21 +010098
99 /* --------------------------------------------
100 * Give ourselves a stack allocated in Normal
101 * -IS-WBWA memory
102 * --------------------------------------------
103 */
104 mov x0, x19
105 bl platform_set_stack
106
Jeenu Viswambharancaa84932014-02-06 10:36:15 +0000107 zero_callee_saved_regs
108 b el3_exit
Achin Gupta4f6ad662013-10-25 09:08:21 +0100109_panic:
110 b _panic
111
112 /* -----------------------------------------------------
113 * The following two stubs give the calling cpu a
114 * coherent stack to allow flushing of caches without
115 * suffering from stack coherency issues
116 * -----------------------------------------------------
117 */
Andrew Thoelke38bde412014-03-18 13:46:55 +0000118func __psci_cpu_off
Achin Gupta4f6ad662013-10-25 09:08:21 +0100119 func_prologue
120 sub sp, sp, #0x10
121 stp x19, x20, [sp, #0]
122 mov x19, sp
123 bl read_mpidr
124 bl platform_set_coherent_stack
125 bl psci_cpu_off
126 mov x1, #PSCI_E_SUCCESS
127 cmp x0, x1
128 b.eq final_wfi
129 mov sp, x19
130 ldp x19, x20, [sp,#0]
131 add sp, sp, #0x10
132 func_epilogue
133 ret
134
Andrew Thoelke38bde412014-03-18 13:46:55 +0000135func __psci_cpu_suspend
Achin Gupta4f6ad662013-10-25 09:08:21 +0100136 func_prologue
137 sub sp, sp, #0x20
138 stp x19, x20, [sp, #0]
139 stp x21, x22, [sp, #0x10]
140 mov x19, sp
141 mov x20, x0
142 mov x21, x1
143 mov x22, x2
144 bl read_mpidr
145 bl platform_set_coherent_stack
146 mov x0, x20
147 mov x1, x21
148 mov x2, x22
149 bl psci_cpu_suspend
150 mov x1, #PSCI_E_SUCCESS
151 cmp x0, x1
152 b.eq final_wfi
153 mov sp, x19
154 ldp x21, x22, [sp,#0x10]
155 ldp x19, x20, [sp,#0]
156 add sp, sp, #0x20
157 func_epilogue
158 ret
159
Andrew Thoelke38bde412014-03-18 13:46:55 +0000160func final_wfi
Achin Gupta4f6ad662013-10-25 09:08:21 +0100161 dsb sy
162 wfi
163wfi_spill:
164 b wfi_spill
165