blob: 87ef54c68a35ae52a5a54c5fe5395120bcd8c000 [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>
Dan Handley4d2e49d2014-04-11 11:52:12 +010042#include "drivers/pwrc/fvp_pwrc.h"
Dan Handleyed6ff952014-05-14 17:44:19 +010043#include "fvp_def.h"
44#include "fvp_private.h"
Achin Gupta4f6ad662013-10-25 09:08:21 +010045
46/*******************************************************************************
Vikram Kanigiri3b7c59b2014-03-21 11:57:10 +000047 * FVP handler called when an affinity instance is about to enter standby.
48 ******************************************************************************/
49int fvp_affinst_standby(unsigned int power_state)
50{
51 unsigned int target_afflvl;
52
53 /* Sanity check the requested state */
54 target_afflvl = psci_get_pstate_afflvl(power_state);
55
56 /*
57 * It's possible to enter standby only on affinity level 0 i.e. a cpu
58 * on the FVP. Ignore any other affinity level.
59 */
60 if (target_afflvl != MPIDR_AFFLVL0)
61 return PSCI_E_INVALID_PARAMS;
62
Andrew Thoelke42e75a72014-04-28 12:28:39 +010063 /*
64 * Enter standby state
65 * dsb is good practice before using wfi to enter low power states
66 */
67 dsb();
Vikram Kanigiri3b7c59b2014-03-21 11:57:10 +000068 wfi();
69
70 return PSCI_E_SUCCESS;
71}
72
73/*******************************************************************************
Achin Gupta4f6ad662013-10-25 09:08:21 +010074 * FVP handler called when an affinity instance is about to be turned on. The
75 * level and mpidr determine the affinity instance.
76 ******************************************************************************/
77int fvp_affinst_on(unsigned long mpidr,
78 unsigned long sec_entrypoint,
79 unsigned long ns_entrypoint,
80 unsigned int afflvl,
81 unsigned int state)
82{
83 int rc = PSCI_E_SUCCESS;
84 unsigned long linear_id;
Dan Handleye2712bc2014-04-10 15:37:22 +010085 mailbox_t *fvp_mboxes;
Achin Gupta4f6ad662013-10-25 09:08:21 +010086 unsigned int psysr;
87
Achin Gupta4f6ad662013-10-25 09:08:21 +010088 /*
89 * It's possible to turn on only affinity level 0 i.e. a cpu
90 * on the FVP. Ignore any other affinity level.
91 */
92 if (afflvl != MPIDR_AFFLVL0)
93 goto exit;
94
95 /*
96 * Ensure that we do not cancel an inflight power off request
97 * for the target cpu. That would leave it in a zombie wfi.
98 * Wait for it to power off, program the jump address for the
99 * target cpu and then program the power controller to turn
100 * that cpu on
101 */
102 do {
103 psysr = fvp_pwrc_read_psysr(mpidr);
104 } while (psysr & PSYSR_AFF_L0);
105
106 linear_id = platform_get_core_pos(mpidr);
Juan Castillo48e84b32014-08-12 13:51:51 +0100107 fvp_mboxes = (mailbox_t *)MBOX_BASE;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100108 fvp_mboxes[linear_id].value = sec_entrypoint;
109 flush_dcache_range((unsigned long) &fvp_mboxes[linear_id],
110 sizeof(unsigned long));
111
112 fvp_pwrc_write_pponr(mpidr);
113
114exit:
115 return rc;
116}
117
118/*******************************************************************************
119 * FVP handler called when an affinity instance is about to be turned off. The
120 * level and mpidr determine the affinity instance. The 'state' arg. allows the
121 * platform to decide whether the cluster is being turned off and take apt
122 * actions.
123 *
Achin Gupta9c60d802014-06-26 11:12:37 +0100124 * CAUTION: There is no guarantee that caches will remain turned on across calls
125 * to this function as each affinity level is dealt with. So do not write & read
126 * global variables across calls. It will be wise to do flush a write to the
127 * global to prevent unpredictable results.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100128 ******************************************************************************/
129int fvp_affinst_off(unsigned long mpidr,
130 unsigned int afflvl,
131 unsigned int state)
132{
133 int rc = PSCI_E_SUCCESS;
Dan Handleyfb42b122014-06-20 09:43:15 +0100134 unsigned int ectlr;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100135
136 switch (afflvl) {
137 case MPIDR_AFFLVL1:
138 if (state == PSCI_STATE_OFF) {
139 /*
140 * Disable coherency if this cluster is to be
141 * turned off
142 */
Dan Handley1c54d972014-06-20 12:02:01 +0100143 if (get_plat_config()->flags & CONFIG_HAS_CCI)
Dan Handleybe234f92014-08-04 16:11:15 +0100144 cci_disable_cluster_coherency(mpidr);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100145
146 /*
147 * Program the power controller to turn the
148 * cluster off
149 */
150 fvp_pwrc_write_pcoffr(mpidr);
151
152 }
153 break;
154
155 case MPIDR_AFFLVL0:
156 if (state == PSCI_STATE_OFF) {
157
158 /*
159 * Take this cpu out of intra-cluster coherency if
160 * the FVP flavour supports the SMP bit.
161 */
Dan Handley1c54d972014-06-20 12:02:01 +0100162 if (get_plat_config()->flags & CONFIG_CPUECTLR_SMP_BIT) {
Achin Gupta4f6ad662013-10-25 09:08:21 +0100163 ectlr = read_cpuectlr();
164 ectlr &= ~CPUECTLR_SMP_BIT;
165 write_cpuectlr(ectlr);
166 }
167
168 /*
169 * Prevent interrupts from spuriously waking up
170 * this cpu
171 */
Dan Handleyfb42b122014-06-20 09:43:15 +0100172 arm_gic_cpuif_deactivate();
Achin Gupta4f6ad662013-10-25 09:08:21 +0100173
174 /*
175 * Program the power controller to power this
176 * cpu off
177 */
178 fvp_pwrc_write_ppoffr(mpidr);
179 }
180 break;
181
182 default:
183 assert(0);
184 }
185
186 return rc;
187}
188
189/*******************************************************************************
190 * FVP handler called when an affinity instance is about to be suspended. The
191 * level and mpidr determine the affinity instance. The 'state' arg. allows the
192 * platform to decide whether the cluster is being turned off and take apt
193 * actions.
194 *
Achin Gupta9c60d802014-06-26 11:12:37 +0100195 * CAUTION: There is no guarantee that caches will remain turned on across calls
196 * to this function as each affinity level is dealt with. So do not write & read
197 * global variables across calls. It will be wise to do flush a write to the
198 * global to prevent unpredictable results.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100199 ******************************************************************************/
200int fvp_affinst_suspend(unsigned long mpidr,
201 unsigned long sec_entrypoint,
202 unsigned long ns_entrypoint,
203 unsigned int afflvl,
204 unsigned int state)
205{
206 int rc = PSCI_E_SUCCESS;
Dan Handleyfb42b122014-06-20 09:43:15 +0100207 unsigned int ectlr;
Dan Handley1c54d972014-06-20 12:02:01 +0100208 unsigned long linear_id;
Dan Handleye2712bc2014-04-10 15:37:22 +0100209 mailbox_t *fvp_mboxes;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100210
Achin Gupta4f6ad662013-10-25 09:08:21 +0100211 switch (afflvl) {
212 case MPIDR_AFFLVL1:
213 if (state == PSCI_STATE_OFF) {
214 /*
215 * Disable coherency if this cluster is to be
216 * turned off
217 */
Dan Handley1c54d972014-06-20 12:02:01 +0100218 if (get_plat_config()->flags & CONFIG_HAS_CCI)
Dan Handleybe234f92014-08-04 16:11:15 +0100219 cci_disable_cluster_coherency(mpidr);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100220
221 /*
222 * Program the power controller to turn the
223 * cluster off
224 */
225 fvp_pwrc_write_pcoffr(mpidr);
226
227 }
228 break;
229
230 case MPIDR_AFFLVL0:
231 if (state == PSCI_STATE_OFF) {
232 /*
233 * Take this cpu out of intra-cluster coherency if
234 * the FVP flavour supports the SMP bit.
235 */
Dan Handley1c54d972014-06-20 12:02:01 +0100236 if (get_plat_config()->flags & CONFIG_CPUECTLR_SMP_BIT) {
Achin Gupta4f6ad662013-10-25 09:08:21 +0100237 ectlr = read_cpuectlr();
238 ectlr &= ~CPUECTLR_SMP_BIT;
239 write_cpuectlr(ectlr);
240 }
241
242 /* Program the jump address for the target cpu */
243 linear_id = platform_get_core_pos(mpidr);
Juan Castillo48e84b32014-08-12 13:51:51 +0100244 fvp_mboxes = (mailbox_t *)MBOX_BASE;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100245 fvp_mboxes[linear_id].value = sec_entrypoint;
246 flush_dcache_range((unsigned long) &fvp_mboxes[linear_id],
247 sizeof(unsigned long));
248
249 /*
250 * Prevent interrupts from spuriously waking up
251 * this cpu
252 */
Dan Handleyfb42b122014-06-20 09:43:15 +0100253 arm_gic_cpuif_deactivate();
Achin Gupta4f6ad662013-10-25 09:08:21 +0100254
255 /*
256 * Program the power controller to power this
257 * cpu off and enable wakeup interrupts.
258 */
Achin Guptab127cdb2013-11-12 16:40:00 +0000259 fvp_pwrc_set_wen(mpidr);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100260 fvp_pwrc_write_ppoffr(mpidr);
261 }
262 break;
263
264 default:
265 assert(0);
266 }
267
Achin Gupta4f6ad662013-10-25 09:08:21 +0100268 return rc;
269}
270
271/*******************************************************************************
272 * FVP handler called when an affinity instance has just been powered on after
273 * being turned off earlier. The level and mpidr determine the affinity
274 * instance. The 'state' arg. allows the platform to decide whether the cluster
275 * was turned off prior to wakeup and do what's necessary to setup it up
276 * correctly.
277 ******************************************************************************/
278int fvp_affinst_on_finish(unsigned long mpidr,
279 unsigned int afflvl,
280 unsigned int state)
281{
282 int rc = PSCI_E_SUCCESS;
Dan Handley1c54d972014-06-20 12:02:01 +0100283 unsigned long linear_id;
Dan Handleye2712bc2014-04-10 15:37:22 +0100284 mailbox_t *fvp_mboxes;
Dan Handleyfb42b122014-06-20 09:43:15 +0100285 unsigned int ectlr;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100286
287 switch (afflvl) {
288
289 case MPIDR_AFFLVL1:
290 /* Enable coherency if this cluster was off */
Harry Liebel30affd52013-10-30 17:41:48 +0000291 if (state == PSCI_STATE_OFF) {
Achin Guptab2187ab2014-01-17 16:52:29 +0000292
293 /*
294 * This CPU might have woken up whilst the
295 * cluster was attempting to power down. In
296 * this case the FVP power controller will
297 * have a pending cluster power off request
298 * which needs to be cleared by writing to the
299 * PPONR register. This prevents the power
300 * controller from interpreting a subsequent
301 * entry of this cpu into a simple wfi as a
302 * power down request.
303 */
304 fvp_pwrc_write_pponr(mpidr);
305
Dan Handleybe234f92014-08-04 16:11:15 +0100306 fvp_cci_enable();
Harry Liebel30affd52013-10-30 17:41:48 +0000307 }
Achin Gupta4f6ad662013-10-25 09:08:21 +0100308 break;
309
310 case MPIDR_AFFLVL0:
311 /*
312 * Ignore the state passed for a cpu. It could only have
313 * been off if we are here.
314 */
315
316 /*
317 * Turn on intra-cluster coherency if the FVP flavour supports
318 * it.
319 */
Dan Handley1c54d972014-06-20 12:02:01 +0100320 if (get_plat_config()->flags & CONFIG_CPUECTLR_SMP_BIT) {
Achin Gupta4f6ad662013-10-25 09:08:21 +0100321 ectlr = read_cpuectlr();
322 ectlr |= CPUECTLR_SMP_BIT;
323 write_cpuectlr(ectlr);
324 }
325
Achin Guptab127cdb2013-11-12 16:40:00 +0000326 /*
327 * Clear PWKUPR.WEN bit to ensure interrupts do not interfere
328 * with a cpu power down unless the bit is set again
329 */
330 fvp_pwrc_clr_wen(mpidr);
331
Achin Gupta4f6ad662013-10-25 09:08:21 +0100332 /* Zero the jump address in the mailbox for this cpu */
Juan Castillo48e84b32014-08-12 13:51:51 +0100333 fvp_mboxes = (mailbox_t *)MBOX_BASE;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100334 linear_id = platform_get_core_pos(mpidr);
335 fvp_mboxes[linear_id].value = 0;
336 flush_dcache_range((unsigned long) &fvp_mboxes[linear_id],
337 sizeof(unsigned long));
338
Achin Gupta4f6ad662013-10-25 09:08:21 +0100339 /* Enable the gic cpu interface */
Dan Handleyfb42b122014-06-20 09:43:15 +0100340 arm_gic_cpuif_setup();
Achin Gupta4f6ad662013-10-25 09:08:21 +0100341
342 /* TODO: This setup is needed only after a cold boot */
Dan Handleyfb42b122014-06-20 09:43:15 +0100343 arm_gic_pcpu_distif_setup();
Achin Gupta4f6ad662013-10-25 09:08:21 +0100344
Achin Gupta4f6ad662013-10-25 09:08:21 +0100345 break;
346
347 default:
348 assert(0);
349 }
350
351 return rc;
352}
353
354/*******************************************************************************
355 * FVP handler called when an affinity instance has just been powered on after
356 * having been suspended earlier. The level and mpidr determine the affinity
357 * instance.
358 * TODO: At the moment we reuse the on finisher and reinitialize the secure
359 * context. Need to implement a separate suspend finisher.
360 ******************************************************************************/
361int fvp_affinst_suspend_finish(unsigned long mpidr,
362 unsigned int afflvl,
363 unsigned int state)
364{
365 return fvp_affinst_on_finish(mpidr, afflvl, state);
366}
367
Juan Castillo4dc4a472014-08-12 11:17:06 +0100368/*******************************************************************************
369 * FVP handlers to shutdown/reboot the system
370 ******************************************************************************/
371static void __dead2 fvp_system_off(void)
372{
373 /* Write the System Configuration Control Register */
374 mmio_write_32(VE_SYSREGS_BASE + V2M_SYS_CFGCTRL,
375 CFGCTRL_START | CFGCTRL_RW | CFGCTRL_FUNC(FUNC_SHUTDOWN));
376 wfi();
377 ERROR("FVP System Off: operation not handled.\n");
378 panic();
379}
380
381static void __dead2 fvp_system_reset(void)
382{
383 /* Write the System Configuration Control Register */
384 mmio_write_32(VE_SYSREGS_BASE + V2M_SYS_CFGCTRL,
385 CFGCTRL_START | CFGCTRL_RW | CFGCTRL_FUNC(FUNC_REBOOT));
386 wfi();
387 ERROR("FVP System Reset: operation not handled.\n");
388 panic();
389}
Achin Gupta4f6ad662013-10-25 09:08:21 +0100390
391/*******************************************************************************
392 * Export the platform handlers to enable psci to invoke them
393 ******************************************************************************/
Dan Handleya4cb68e2014-04-23 13:47:06 +0100394static const plat_pm_ops_t fvp_plat_pm_ops = {
Juan Castillo4dc4a472014-08-12 11:17:06 +0100395 .affinst_standby = fvp_affinst_standby,
396 .affinst_on = fvp_affinst_on,
397 .affinst_off = fvp_affinst_off,
398 .affinst_suspend = fvp_affinst_suspend,
399 .affinst_on_finish = fvp_affinst_on_finish,
400 .affinst_suspend_finish = fvp_affinst_suspend_finish,
401 .system_off = fvp_system_off,
402 .system_reset = fvp_system_reset
Achin Gupta4f6ad662013-10-25 09:08:21 +0100403};
404
405/*******************************************************************************
406 * Export the platform specific power ops & initialize the fvp power controller
407 ******************************************************************************/
Dan Handleya4cb68e2014-04-23 13:47:06 +0100408int platform_setup_pm(const plat_pm_ops_t **plat_ops)
Achin Gupta4f6ad662013-10-25 09:08:21 +0100409{
410 *plat_ops = &fvp_plat_pm_ops;
411 return 0;
412}