blob: 51d9b5700a4e2d6e8480c28baa2e1901fa77717c [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>
Achin Guptac8afc782013-11-25 18:45:02 +000033#include <runtime_svc.h>
Achin Gupta4f6ad662013-10-25 09:08:21 +010034#include <asm_macros.S>
Jeenu Viswambharancaa84932014-02-06 10:36:15 +000035#include <cm_macros.S>
Dan Handley35e98e52014-04-09 13:13:04 +010036#include "psci_private.h"
Achin Gupta4f6ad662013-10-25 09:08:21 +010037
38 .globl psci_aff_on_finish_entry
39 .globl psci_aff_suspend_finish_entry
40 .globl __psci_cpu_off
41 .globl __psci_cpu_suspend
42
Achin Gupta4f6ad662013-10-25 09:08:21 +010043 /* -----------------------------------------------------
44 * This cpu has been physically powered up. Depending
45 * upon whether it was resumed from suspend or simply
46 * turned on, call the common power on finisher with
47 * the handlers (chosen depending upon original state).
48 * For ease, the finisher is called with coherent
49 * stacks. This allows the cluster/cpu finishers to
50 * enter coherency and enable the mmu without running
51 * into issues. We switch back to normal stacks once
52 * all this is done.
53 * -----------------------------------------------------
54 */
Andrew Thoelke0a30cf52014-03-18 13:46:55 +000055func psci_aff_on_finish_entry
Achin Gupta4f6ad662013-10-25 09:08:21 +010056 adr x23, psci_afflvl_on_finishers
57 b psci_aff_common_finish_entry
58
59psci_aff_suspend_finish_entry:
60 adr x23, psci_afflvl_suspend_finishers
61
62psci_aff_common_finish_entry:
63 adr x22, psci_afflvl_power_on_finish
Achin Guptab739f222014-01-18 16:50:09 +000064
65 /* ---------------------------------------------
66 * Exceptions should not occur at this point.
67 * Set VBAR in order to handle and report any
68 * that do occur
69 * ---------------------------------------------
70 */
71 adr x0, early_exceptions
72 msr vbar_el3, x0
73 isb
74
Jeenu Viswambharancaa84932014-02-06 10:36:15 +000075 /* ---------------------------------------------
76 * Use SP_EL0 for the C runtime stack.
77 * ---------------------------------------------
78 */
79 msr spsel, #0
80 isb
81
Achin Gupta4f6ad662013-10-25 09:08:21 +010082 bl read_mpidr
83 mov x19, x0
84 bl platform_set_coherent_stack
85
86 /* ---------------------------------------------
87 * Call the finishers starting from affinity
88 * level 0.
89 * ---------------------------------------------
90 */
Achin Guptaa45e3972013-12-05 15:10:48 +000091 mov x0, x19
92 bl get_power_on_target_afflvl
93 cmp x0, xzr
94 b.lt _panic
Achin Gupta4f6ad662013-10-25 09:08:21 +010095 mov x3, x23
96 mov x2, x0
97 mov x0, x19
98 mov x1, #MPIDR_AFFLVL0
99 blr x22
Achin Gupta4f6ad662013-10-25 09:08:21 +0100100
101 /* --------------------------------------------
102 * Give ourselves a stack allocated in Normal
103 * -IS-WBWA memory
104 * --------------------------------------------
105 */
106 mov x0, x19
107 bl platform_set_stack
108
Jeenu Viswambharancaa84932014-02-06 10:36:15 +0000109 zero_callee_saved_regs
110 b el3_exit
Achin Gupta4f6ad662013-10-25 09:08:21 +0100111_panic:
112 b _panic
113
114 /* -----------------------------------------------------
115 * The following two stubs give the calling cpu a
116 * coherent stack to allow flushing of caches without
117 * suffering from stack coherency issues
118 * -----------------------------------------------------
119 */
Andrew Thoelke0a30cf52014-03-18 13:46:55 +0000120func __psci_cpu_off
Achin Gupta4f6ad662013-10-25 09:08:21 +0100121 func_prologue
122 sub sp, sp, #0x10
123 stp x19, x20, [sp, #0]
124 mov x19, sp
125 bl read_mpidr
126 bl platform_set_coherent_stack
127 bl psci_cpu_off
128 mov x1, #PSCI_E_SUCCESS
129 cmp x0, x1
130 b.eq final_wfi
131 mov sp, x19
132 ldp x19, x20, [sp,#0]
133 add sp, sp, #0x10
134 func_epilogue
135 ret
136
Andrew Thoelke0a30cf52014-03-18 13:46:55 +0000137func __psci_cpu_suspend
Achin Gupta4f6ad662013-10-25 09:08:21 +0100138 func_prologue
139 sub sp, sp, #0x20
140 stp x19, x20, [sp, #0]
141 stp x21, x22, [sp, #0x10]
142 mov x19, sp
143 mov x20, x0
144 mov x21, x1
145 mov x22, x2
146 bl read_mpidr
147 bl platform_set_coherent_stack
148 mov x0, x20
149 mov x1, x21
150 mov x2, x22
151 bl psci_cpu_suspend
152 mov x1, #PSCI_E_SUCCESS
153 cmp x0, x1
154 b.eq final_wfi
155 mov sp, x19
156 ldp x21, x22, [sp,#0x10]
157 ldp x19, x20, [sp,#0]
158 add sp, sp, #0x20
159 func_epilogue
160 ret
161
Andrew Thoelke0a30cf52014-03-18 13:46:55 +0000162func final_wfi
Achin Gupta4f6ad662013-10-25 09:08:21 +0100163 dsb sy
164 wfi
165wfi_spill:
166 b wfi_spill
167