blob: fdf320979fab9165e9d4ecc3ffe06602015831a9 [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
Achin Gupta4f6ad662013-10-25 09:08:21 +010031#include <arch_helpers.h>
Dan Handleyfb42b122014-06-20 09:43:15 +010032#include <arm_gic.h>
Dan Handley2bd4ef22014-04-09 13:14:54 +010033#include <assert.h>
Achin Gupta4f6ad662013-10-25 09:08:21 +010034#include <bakery_lock.h>
35#include <cci400.h>
Juan Castillo4dc4a472014-08-12 11:17:06 +010036#include <debug.h>
Dan Handley2bd4ef22014-04-09 13:14:54 +010037#include <mmio.h>
38#include <platform.h>
Dan Handley1c54d972014-06-20 12:02:01 +010039#include <plat_config.h>
Dan Handleyed6ff952014-05-14 17:44:19 +010040#include <platform_def.h>
Achin Gupta4f6ad662013-10-25 09:08:21 +010041#include <psci.h>
Achin Gupta85876392014-07-31 17:45:51 +010042#include <errno.h>
Dan Handley4d2e49d2014-04-11 11:52:12 +010043#include "drivers/pwrc/fvp_pwrc.h"
Dan Handleyed6ff952014-05-14 17:44:19 +010044#include "fvp_def.h"
45#include "fvp_private.h"
Achin Gupta4f6ad662013-10-25 09:08:21 +010046
47/*******************************************************************************
Achin Gupta85876392014-07-31 17:45:51 +010048 * Private FVP function to program the mailbox for a cpu before it is released
49 * from reset.
50 ******************************************************************************/
51static void fvp_program_mailbox(uint64_t mpidr, uint64_t address)
52{
53 uint64_t linear_id;
54 mailbox_t *fvp_mboxes;
55
56 linear_id = platform_get_core_pos(mpidr);
57 fvp_mboxes = (mailbox_t *)MBOX_BASE;
58 fvp_mboxes[linear_id].value = address;
59 flush_dcache_range((unsigned long) &fvp_mboxes[linear_id],
60 sizeof(unsigned long));
61}
62
63/*******************************************************************************
64 * Function which implements the common FVP specific operations to power down a
65 * cpu in response to a CPU_OFF or CPU_SUSPEND request.
66 ******************************************************************************/
67static void fvp_cpu_pwrdwn_common()
68{
Achin Gupta85876392014-07-31 17:45:51 +010069 /* Prevent interrupts from spuriously waking up this cpu */
70 arm_gic_cpuif_deactivate();
71
72 /* Program the power controller to power off this cpu. */
73 fvp_pwrc_write_ppoffr(read_mpidr_el1());
74}
75
76/*******************************************************************************
77 * Function which implements the common FVP specific operations to power down a
78 * cluster in response to a CPU_OFF or CPU_SUSPEND request.
79 ******************************************************************************/
80static void fvp_cluster_pwrdwn_common()
81{
82 uint64_t mpidr = read_mpidr_el1();
83
84 /* Disable coherency if this cluster is to be turned off */
85 if (get_plat_config()->flags & CONFIG_HAS_CCI)
86 cci_disable_cluster_coherency(mpidr);
87
88 /* Program the power controller to turn the cluster off */
89 fvp_pwrc_write_pcoffr(mpidr);
90}
91
92/*******************************************************************************
93 * Private FVP function which is used to determine if any platform actions
94 * should be performed for the specified affinity instance given its
95 * state. Nothing needs to be done if the 'state' is not off or if this is not
96 * the highest affinity level which will enter the 'state'.
97 ******************************************************************************/
98static int32_t fvp_do_plat_actions(unsigned int afflvl, unsigned int state)
99{
100 unsigned int max_phys_off_afflvl;
101
102 assert(afflvl <= MPIDR_AFFLVL1);
103
104 if (state != PSCI_STATE_OFF)
105 return -EAGAIN;
106
107 /*
108 * Find the highest affinity level which will be suspended and postpone
109 * all the platform specific actions until that level is hit.
110 */
111 max_phys_off_afflvl = psci_get_max_phys_off_afflvl();
112 assert(max_phys_off_afflvl != PSCI_INVALID_DATA);
113 if (afflvl != max_phys_off_afflvl)
114 return -EAGAIN;
115
116 return 0;
117}
118
119/*******************************************************************************
Vikram Kanigiri3b7c59b2014-03-21 11:57:10 +0000120 * FVP handler called when an affinity instance is about to enter standby.
121 ******************************************************************************/
122int fvp_affinst_standby(unsigned int power_state)
123{
124 unsigned int target_afflvl;
125
126 /* Sanity check the requested state */
127 target_afflvl = psci_get_pstate_afflvl(power_state);
128
129 /*
130 * It's possible to enter standby only on affinity level 0 i.e. a cpu
131 * on the FVP. Ignore any other affinity level.
132 */
133 if (target_afflvl != MPIDR_AFFLVL0)
134 return PSCI_E_INVALID_PARAMS;
135
Andrew Thoelke42e75a72014-04-28 12:28:39 +0100136 /*
137 * Enter standby state
138 * dsb is good practice before using wfi to enter low power states
139 */
140 dsb();
Vikram Kanigiri3b7c59b2014-03-21 11:57:10 +0000141 wfi();
142
143 return PSCI_E_SUCCESS;
144}
145
146/*******************************************************************************
Achin Gupta4f6ad662013-10-25 09:08:21 +0100147 * FVP handler called when an affinity instance is about to be turned on. The
148 * level and mpidr determine the affinity instance.
149 ******************************************************************************/
150int fvp_affinst_on(unsigned long mpidr,
151 unsigned long sec_entrypoint,
Achin Gupta4f6ad662013-10-25 09:08:21 +0100152 unsigned int afflvl,
153 unsigned int state)
154{
155 int rc = PSCI_E_SUCCESS;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100156 unsigned int psysr;
157
Achin Gupta4f6ad662013-10-25 09:08:21 +0100158 /*
159 * It's possible to turn on only affinity level 0 i.e. a cpu
160 * on the FVP. Ignore any other affinity level.
161 */
162 if (afflvl != MPIDR_AFFLVL0)
Achin Gupta85876392014-07-31 17:45:51 +0100163 return rc;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100164
165 /*
166 * Ensure that we do not cancel an inflight power off request
167 * for the target cpu. That would leave it in a zombie wfi.
168 * Wait for it to power off, program the jump address for the
169 * target cpu and then program the power controller to turn
170 * that cpu on
171 */
172 do {
173 psysr = fvp_pwrc_read_psysr(mpidr);
174 } while (psysr & PSYSR_AFF_L0);
175
Achin Gupta85876392014-07-31 17:45:51 +0100176 fvp_program_mailbox(mpidr, sec_entrypoint);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100177 fvp_pwrc_write_pponr(mpidr);
178
Achin Gupta4f6ad662013-10-25 09:08:21 +0100179 return rc;
180}
181
182/*******************************************************************************
183 * FVP handler called when an affinity instance is about to be turned off. The
184 * level and mpidr determine the affinity instance. The 'state' arg. allows the
185 * platform to decide whether the cluster is being turned off and take apt
186 * actions.
187 *
Achin Gupta9c60d802014-06-26 11:12:37 +0100188 * CAUTION: There is no guarantee that caches will remain turned on across calls
189 * to this function as each affinity level is dealt with. So do not write & read
190 * global variables across calls. It will be wise to do flush a write to the
191 * global to prevent unpredictable results.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100192 ******************************************************************************/
Soby Mathewffb4ab12014-09-26 15:08:52 +0100193int fvp_affinst_off(unsigned int afflvl,
Achin Gupta4f6ad662013-10-25 09:08:21 +0100194 unsigned int state)
195{
Achin Gupta85876392014-07-31 17:45:51 +0100196 /* Determine if any platform actions need to be executed */
197 if (fvp_do_plat_actions(afflvl, state) == -EAGAIN)
198 return PSCI_E_SUCCESS;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100199
Achin Gupta85876392014-07-31 17:45:51 +0100200 /*
201 * If execution reaches this stage then this affinity level will be
202 * suspended. Perform at least the cpu specific actions followed the
203 * cluster specific operations if applicable.
204 */
205 fvp_cpu_pwrdwn_common();
Achin Gupta4f6ad662013-10-25 09:08:21 +0100206
Achin Gupta85876392014-07-31 17:45:51 +0100207 if (afflvl != MPIDR_AFFLVL0)
208 fvp_cluster_pwrdwn_common();
Achin Gupta4f6ad662013-10-25 09:08:21 +0100209
Achin Gupta85876392014-07-31 17:45:51 +0100210 return PSCI_E_SUCCESS;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100211}
212
213/*******************************************************************************
214 * FVP handler called when an affinity instance is about to be suspended. The
215 * level and mpidr determine the affinity instance. The 'state' arg. allows the
216 * platform to decide whether the cluster is being turned off and take apt
217 * actions.
218 *
Achin Gupta9c60d802014-06-26 11:12:37 +0100219 * CAUTION: There is no guarantee that caches will remain turned on across calls
220 * to this function as each affinity level is dealt with. So do not write & read
221 * global variables across calls. It will be wise to do flush a write to the
222 * global to prevent unpredictable results.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100223 ******************************************************************************/
Soby Mathewffb4ab12014-09-26 15:08:52 +0100224int fvp_affinst_suspend(unsigned long sec_entrypoint,
Achin Gupta4f6ad662013-10-25 09:08:21 +0100225 unsigned int afflvl,
226 unsigned int state)
227{
Soby Mathewffb4ab12014-09-26 15:08:52 +0100228 unsigned long mpidr;
229
Achin Gupta85876392014-07-31 17:45:51 +0100230 /* Determine if any platform actions need to be executed. */
231 if (fvp_do_plat_actions(afflvl, state) == -EAGAIN)
232 return PSCI_E_SUCCESS;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100233
Soby Mathewffb4ab12014-09-26 15:08:52 +0100234 /* Get the mpidr for this cpu */
235 mpidr = read_mpidr_el1();
236
237 /* Program the jump address for the this cpu */
238 fvp_program_mailbox(mpidr, sec_entrypoint);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100239
Achin Gupta85876392014-07-31 17:45:51 +0100240 /* Program the power controller to enable wakeup interrupts. */
241 fvp_pwrc_set_wen(mpidr);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100242
Achin Gupta85876392014-07-31 17:45:51 +0100243 /* Perform the common cpu specific operations */
244 fvp_cpu_pwrdwn_common();
Achin Gupta4f6ad662013-10-25 09:08:21 +0100245
Achin Gupta85876392014-07-31 17:45:51 +0100246 /* Perform the common cluster specific operations */
247 if (afflvl != MPIDR_AFFLVL0)
248 fvp_cluster_pwrdwn_common();
Achin Gupta4f6ad662013-10-25 09:08:21 +0100249
Achin Gupta85876392014-07-31 17:45:51 +0100250 return PSCI_E_SUCCESS;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100251}
252
253/*******************************************************************************
254 * FVP handler called when an affinity instance has just been powered on after
255 * being turned off earlier. The level and mpidr determine the affinity
256 * instance. The 'state' arg. allows the platform to decide whether the cluster
257 * was turned off prior to wakeup and do what's necessary to setup it up
258 * correctly.
259 ******************************************************************************/
Soby Mathewffb4ab12014-09-26 15:08:52 +0100260int fvp_affinst_on_finish(unsigned int afflvl,
Achin Gupta4f6ad662013-10-25 09:08:21 +0100261 unsigned int state)
262{
263 int rc = PSCI_E_SUCCESS;
Soby Mathewffb4ab12014-09-26 15:08:52 +0100264 unsigned long mpidr;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100265
Achin Gupta85876392014-07-31 17:45:51 +0100266 /* Determine if any platform actions need to be executed. */
267 if (fvp_do_plat_actions(afflvl, state) == -EAGAIN)
268 return PSCI_E_SUCCESS;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100269
Soby Mathewffb4ab12014-09-26 15:08:52 +0100270 /* Get the mpidr for this cpu */
271 mpidr = read_mpidr_el1();
272
Achin Gupta85876392014-07-31 17:45:51 +0100273 /* Perform the common cluster specific operations */
274 if (afflvl != MPIDR_AFFLVL0) {
Achin Gupta4f6ad662013-10-25 09:08:21 +0100275 /*
Achin Gupta85876392014-07-31 17:45:51 +0100276 * This CPU might have woken up whilst the cluster was
277 * attempting to power down. In this case the FVP power
278 * controller will have a pending cluster power off request
279 * which needs to be cleared by writing to the PPONR register.
280 * This prevents the power controller from interpreting a
281 * subsequent entry of this cpu into a simple wfi as a power
282 * down request.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100283 */
Achin Gupta85876392014-07-31 17:45:51 +0100284 fvp_pwrc_write_pponr(mpidr);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100285
Achin Gupta85876392014-07-31 17:45:51 +0100286 /* Enable coherency if this cluster was off */
287 fvp_cci_enable();
288 }
Achin Guptab127cdb2013-11-12 16:40:00 +0000289
Achin Gupta85876392014-07-31 17:45:51 +0100290 /*
Achin Gupta85876392014-07-31 17:45:51 +0100291 * Clear PWKUPR.WEN bit to ensure interrupts do not interfere
292 * with a cpu power down unless the bit is set again
293 */
294 fvp_pwrc_clr_wen(mpidr);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100295
Achin Gupta85876392014-07-31 17:45:51 +0100296 /* Zero the jump address in the mailbox for this cpu */
Soby Mathewffb4ab12014-09-26 15:08:52 +0100297 fvp_program_mailbox(mpidr, 0);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100298
Achin Gupta85876392014-07-31 17:45:51 +0100299 /* Enable the gic cpu interface */
300 arm_gic_cpuif_setup();
Achin Gupta4f6ad662013-10-25 09:08:21 +0100301
Achin Gupta85876392014-07-31 17:45:51 +0100302 /* TODO: This setup is needed only after a cold boot */
303 arm_gic_pcpu_distif_setup();
Achin Gupta4f6ad662013-10-25 09:08:21 +0100304
305 return rc;
306}
307
308/*******************************************************************************
309 * FVP handler called when an affinity instance has just been powered on after
310 * having been suspended earlier. The level and mpidr determine the affinity
311 * instance.
312 * TODO: At the moment we reuse the on finisher and reinitialize the secure
313 * context. Need to implement a separate suspend finisher.
314 ******************************************************************************/
Soby Mathewffb4ab12014-09-26 15:08:52 +0100315int fvp_affinst_suspend_finish(unsigned int afflvl,
Achin Gupta4f6ad662013-10-25 09:08:21 +0100316 unsigned int state)
317{
Soby Mathewffb4ab12014-09-26 15:08:52 +0100318 return fvp_affinst_on_finish(afflvl, state);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100319}
320
Juan Castillo4dc4a472014-08-12 11:17:06 +0100321/*******************************************************************************
322 * FVP handlers to shutdown/reboot the system
323 ******************************************************************************/
324static void __dead2 fvp_system_off(void)
325{
326 /* Write the System Configuration Control Register */
327 mmio_write_32(VE_SYSREGS_BASE + V2M_SYS_CFGCTRL,
328 CFGCTRL_START | CFGCTRL_RW | CFGCTRL_FUNC(FUNC_SHUTDOWN));
329 wfi();
330 ERROR("FVP System Off: operation not handled.\n");
331 panic();
332}
333
334static void __dead2 fvp_system_reset(void)
335{
336 /* Write the System Configuration Control Register */
337 mmio_write_32(VE_SYSREGS_BASE + V2M_SYS_CFGCTRL,
338 CFGCTRL_START | CFGCTRL_RW | CFGCTRL_FUNC(FUNC_REBOOT));
339 wfi();
340 ERROR("FVP System Reset: operation not handled.\n");
341 panic();
342}
Achin Gupta4f6ad662013-10-25 09:08:21 +0100343
344/*******************************************************************************
345 * Export the platform handlers to enable psci to invoke them
346 ******************************************************************************/
Dan Handleya4cb68e2014-04-23 13:47:06 +0100347static const plat_pm_ops_t fvp_plat_pm_ops = {
Juan Castillo4dc4a472014-08-12 11:17:06 +0100348 .affinst_standby = fvp_affinst_standby,
349 .affinst_on = fvp_affinst_on,
350 .affinst_off = fvp_affinst_off,
351 .affinst_suspend = fvp_affinst_suspend,
352 .affinst_on_finish = fvp_affinst_on_finish,
353 .affinst_suspend_finish = fvp_affinst_suspend_finish,
354 .system_off = fvp_system_off,
355 .system_reset = fvp_system_reset
Achin Gupta4f6ad662013-10-25 09:08:21 +0100356};
357
358/*******************************************************************************
359 * Export the platform specific power ops & initialize the fvp power controller
360 ******************************************************************************/
Dan Handleya4cb68e2014-04-23 13:47:06 +0100361int platform_setup_pm(const plat_pm_ops_t **plat_ops)
Achin Gupta4f6ad662013-10-25 09:08:21 +0100362{
363 *plat_ops = &fvp_plat_pm_ops;
364 return 0;
365}