blob: 62d270fadbfd619c6ea2a0768426d89e6fbc5cca [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 <stdio.h>
32#include <string.h>
33#include <assert.h>
Achin Gupta0a9f7472014-02-09 17:48:12 +000034#include <debug.h>
Achin Gupta4f6ad662013-10-25 09:08:21 +010035#include <arch_helpers.h>
36#include <console.h>
37#include <platform.h>
38#include <psci.h>
39#include <psci_private.h>
Achin Guptaef7a28c2014-02-01 08:59:56 +000040#include <context_mgmt.h>
Achin Gupta4f6ad662013-10-25 09:08:21 +010041
42typedef int (*afflvl_suspend_handler)(unsigned long,
43 aff_map_node *,
44 unsigned long,
45 unsigned long,
46 unsigned int);
47
48/*******************************************************************************
Achin Guptaa45e3972013-12-05 15:10:48 +000049 * This function sets the affinity level till which the current cpu is being
50 * powered down to during a cpu_suspend call
51 ******************************************************************************/
52void psci_set_suspend_afflvl(aff_map_node *node, int afflvl)
53{
54 /*
55 * Check that nobody else is calling this function on our behalf &
56 * this information is being set only in the cpu node
57 */
58 assert(node->mpidr == (read_mpidr() & MPIDR_AFFINITY_MASK));
59 assert(node->level == MPIDR_AFFLVL0);
60
61 /*
62 * Store the affinity level we are powering down to in our context.
63 * The cache flush in the suspend code will ensure that this info
64 * is available immediately upon resuming.
65 */
66 psci_suspend_context[node->data].suspend_level = afflvl;
67}
68
69/*******************************************************************************
70 * This function gets the affinity level till which the current cpu was powered
71 * down during a cpu_suspend call.
72 ******************************************************************************/
73int psci_get_suspend_afflvl(aff_map_node *node)
74{
75 /* Return the target affinity level */
76 return psci_suspend_context[node->data].suspend_level;
77}
78
79/*******************************************************************************
Achin Gupta4f6ad662013-10-25 09:08:21 +010080 * The next three functions implement a handler for each supported affinity
81 * level which is called when that affinity level is about to be suspended.
82 ******************************************************************************/
83static int psci_afflvl0_suspend(unsigned long mpidr,
84 aff_map_node *cpu_node,
85 unsigned long ns_entrypoint,
86 unsigned long context_id,
87 unsigned int power_state)
88{
89 unsigned int index, plat_state;
90 unsigned long psci_entrypoint, sctlr = read_sctlr();
Achin Gupta0a9f7472014-02-09 17:48:12 +000091 el3_state *saved_el3_state;
Achin Gupta4f6ad662013-10-25 09:08:21 +010092 int rc = PSCI_E_SUCCESS;
93
94 /* Sanity check to safeguard against data corruption */
95 assert(cpu_node->level == MPIDR_AFFLVL0);
96
Achin Gupta607084e2014-02-09 18:24:19 +000097 /*
98 * Generic management: Store the re-entry information for the non-secure
99 * world and allow the secure world to suspend itself
100 */
101
102 /*
103 * Call the cpu suspend handler registered by the Secure Payload
104 * Dispatcher to let it do any bookeeping. If the handler encounters an
105 * error, it's expected to assert within
106 */
107 if (spd_pm.svc_suspend)
108 spd_pm.svc_suspend(power_state);
109
Achin Gupta75f73672013-12-05 16:33:10 +0000110 /* State management: mark this cpu as suspended */
111 psci_set_state(cpu_node, PSCI_STATE_SUSPEND);
112
Achin Gupta4f6ad662013-10-25 09:08:21 +0100113 /*
114 * Generic management: Store the re-entry information for the
115 * non-secure world
116 */
117 index = cpu_node->data;
118 rc = psci_set_ns_entry_info(index, ns_entrypoint, context_id);
119 if (rc != PSCI_E_SUCCESS)
120 return rc;
121
122 /*
Achin Guptaef7a28c2014-02-01 08:59:56 +0000123 * Arch. management: Save the EL3 state in the 'cpu_context'
124 * structure that has been allocated for this cpu, flush the
Achin Gupta4f6ad662013-10-25 09:08:21 +0100125 * L1 caches and exit intra-cluster coherency et al
126 */
Achin Guptaef7a28c2014-02-01 08:59:56 +0000127 cm_el3_sysregs_context_save(NON_SECURE);
128 rc = PSCI_E_SUCCESS;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100129
Achin Gupta0a9f7472014-02-09 17:48:12 +0000130 /*
131 * The EL3 state to PoC since it will be accessed after a
132 * reset with the caches turned off
133 */
134 saved_el3_state = get_el3state_ctx(cm_get_context(mpidr, NON_SECURE));
135 flush_dcache_range((uint64_t) saved_el3_state, sizeof(*saved_el3_state));
136
Achin Gupta4f6ad662013-10-25 09:08:21 +0100137 /* Set the secure world (EL3) re-entry point after BL1 */
138 psci_entrypoint = (unsigned long) psci_aff_suspend_finish_entry;
139
140 /*
141 * Arch. management. Perform the necessary steps to flush all
142 * cpu caches.
143 *
144 * TODO: This power down sequence varies across cpus so it needs to be
145 * abstracted out on the basis of the MIDR like in cpu_reset_handler().
146 * Do the bare minimal for the time being. Fix this before porting to
147 * Cortex models.
148 */
149 sctlr &= ~SCTLR_C_BIT;
150 write_sctlr(sctlr);
151
152 /*
153 * CAUTION: This flush to the level of unification makes an assumption
154 * about the cache hierarchy at affinity level 0 (cpu) in the platform.
155 * Ideally the platform should tell psci which levels to flush to exit
156 * coherency.
157 */
158 dcsw_op_louis(DCCISW);
159
160 /*
161 * Plat. management: Allow the platform to perform the
162 * necessary actions to turn off this cpu e.g. set the
163 * platform defined mailbox with the psci entrypoint,
164 * program the power controller etc.
165 */
166 if (psci_plat_pm_ops->affinst_suspend) {
Achin Gupta75f73672013-12-05 16:33:10 +0000167 plat_state = psci_get_phys_state(cpu_node);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100168 rc = psci_plat_pm_ops->affinst_suspend(mpidr,
169 psci_entrypoint,
170 ns_entrypoint,
171 cpu_node->level,
172 plat_state);
173 }
174
175 return rc;
176}
177
178static int psci_afflvl1_suspend(unsigned long mpidr,
179 aff_map_node *cluster_node,
180 unsigned long ns_entrypoint,
181 unsigned long context_id,
182 unsigned int power_state)
183{
184 int rc = PSCI_E_SUCCESS;
185 unsigned int plat_state;
186 unsigned long psci_entrypoint;
187
188 /* Sanity check the cluster level */
189 assert(cluster_node->level == MPIDR_AFFLVL1);
190
Achin Gupta75f73672013-12-05 16:33:10 +0000191 /* State management: Decrement the cluster reference count */
192 psci_set_state(cluster_node, PSCI_STATE_SUSPEND);
193
Achin Gupta4f6ad662013-10-25 09:08:21 +0100194 /*
195 * Keep the physical state of this cluster handy to decide
196 * what action needs to be taken
197 */
Achin Gupta75f73672013-12-05 16:33:10 +0000198 plat_state = psci_get_phys_state(cluster_node);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100199
200 /*
201 * Arch. management: Flush all levels of caches to PoC if the
202 * cluster is to be shutdown
203 */
204 if (plat_state == PSCI_STATE_OFF)
205 dcsw_op_all(DCCISW);
206
207 /*
Achin Gupta3140a9e2013-12-02 16:23:12 +0000208 * Plat. Management. Allow the platform to do its cluster
Achin Gupta4f6ad662013-10-25 09:08:21 +0100209 * specific bookeeping e.g. turn off interconnect coherency,
210 * program the power controller etc.
211 */
212 if (psci_plat_pm_ops->affinst_suspend) {
213
214 /*
215 * Sending the psci entrypoint is currently redundant
216 * beyond affinity level 0 but one never knows what a
217 * platform might do. Also it allows us to keep the
218 * platform handler prototype the same.
219 */
220 psci_entrypoint = (unsigned long) psci_aff_suspend_finish_entry;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100221 rc = psci_plat_pm_ops->affinst_suspend(mpidr,
222 psci_entrypoint,
223 ns_entrypoint,
224 cluster_node->level,
225 plat_state);
226 }
227
228 return rc;
229}
230
231
232static int psci_afflvl2_suspend(unsigned long mpidr,
233 aff_map_node *system_node,
234 unsigned long ns_entrypoint,
235 unsigned long context_id,
236 unsigned int power_state)
237{
238 int rc = PSCI_E_SUCCESS;
239 unsigned int plat_state;
240 unsigned long psci_entrypoint;
241
242 /* Cannot go beyond this */
243 assert(system_node->level == MPIDR_AFFLVL2);
244
Achin Gupta75f73672013-12-05 16:33:10 +0000245 /* State management: Decrement the system reference count */
246 psci_set_state(system_node, PSCI_STATE_SUSPEND);
247
Achin Gupta4f6ad662013-10-25 09:08:21 +0100248 /*
249 * Keep the physical state of the system handy to decide what
250 * action needs to be taken
251 */
Achin Gupta75f73672013-12-05 16:33:10 +0000252 plat_state = psci_get_phys_state(system_node);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100253
254 /*
Achin Gupta3140a9e2013-12-02 16:23:12 +0000255 * Plat. Management : Allow the platform to do its bookeeping
Achin Gupta4f6ad662013-10-25 09:08:21 +0100256 * at this affinity level
257 */
258 if (psci_plat_pm_ops->affinst_suspend) {
259
260 /*
261 * Sending the psci entrypoint is currently redundant
262 * beyond affinity level 0 but one never knows what a
263 * platform might do. Also it allows us to keep the
264 * platform handler prototype the same.
265 */
266 psci_entrypoint = (unsigned long) psci_aff_suspend_finish_entry;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100267 rc = psci_plat_pm_ops->affinst_suspend(mpidr,
268 psci_entrypoint,
269 ns_entrypoint,
270 system_node->level,
271 plat_state);
272 }
273
274 return rc;
275}
276
277static const afflvl_suspend_handler psci_afflvl_suspend_handlers[] = {
278 psci_afflvl0_suspend,
279 psci_afflvl1_suspend,
280 psci_afflvl2_suspend,
281};
282
283/*******************************************************************************
Achin Gupta0959db52013-12-02 17:33:04 +0000284 * This function takes an array of pointers to affinity instance nodes in the
285 * topology tree and calls the suspend handler for the corresponding affinity
286 * levels
287 ******************************************************************************/
288static int psci_call_suspend_handlers(mpidr_aff_map_nodes mpidr_nodes,
289 int start_afflvl,
290 int end_afflvl,
291 unsigned long mpidr,
292 unsigned long entrypoint,
293 unsigned long context_id,
294 unsigned int power_state)
295{
296 int rc = PSCI_E_INVALID_PARAMS, level;
297 aff_map_node *node;
298
299 for (level = start_afflvl; level <= end_afflvl; level++) {
300 node = mpidr_nodes[level];
301 if (node == NULL)
302 continue;
303
304 /*
305 * TODO: In case of an error should there be a way
306 * of restoring what we might have torn down at
307 * lower affinity levels.
308 */
309 rc = psci_afflvl_suspend_handlers[level](mpidr,
310 node,
311 entrypoint,
312 context_id,
313 power_state);
314 if (rc != PSCI_E_SUCCESS)
315 break;
316 }
317
318 return rc;
319}
320
321/*******************************************************************************
322 * Top level handler which is called when a cpu wants to suspend its execution.
323 * It is assumed that along with turning the cpu off, higher affinity levels
324 * until the target affinity level will be turned off as well. It traverses
325 * through all the affinity levels performing generic, architectural, platform
326 * setup and state management e.g. for a cluster that's to be suspended, it will
327 * call the platform specific code which will disable coherency at the
328 * interconnect level if the cpu is the last in the cluster. For a cpu it could
329 * mean programming the power controller etc.
330 *
331 * The state of all the relevant affinity levels is changed prior to calling the
332 * affinity level specific handlers as their actions would depend upon the state
333 * the affinity level is about to enter.
334 *
335 * The affinity level specific handlers are called in ascending order i.e. from
336 * the lowest to the highest affinity level implemented by the platform because
337 * to turn off affinity level X it is neccesary to turn off affinity level X - 1
338 * first.
339 *
340 * CAUTION: This function is called with coherent stacks so that coherency can
341 * be turned off and caches can be flushed safely.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100342 ******************************************************************************/
343int psci_afflvl_suspend(unsigned long mpidr,
344 unsigned long entrypoint,
345 unsigned long context_id,
346 unsigned int power_state,
Achin Gupta0959db52013-12-02 17:33:04 +0000347 int start_afflvl,
348 int end_afflvl)
Achin Gupta4f6ad662013-10-25 09:08:21 +0100349{
Achin Gupta0959db52013-12-02 17:33:04 +0000350 int rc = PSCI_E_SUCCESS;
Achin Gupta0959db52013-12-02 17:33:04 +0000351 mpidr_aff_map_nodes mpidr_nodes;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100352
353 mpidr &= MPIDR_AFFINITY_MASK;
354
355 /*
Achin Gupta0959db52013-12-02 17:33:04 +0000356 * Collect the pointers to the nodes in the topology tree for
357 * each affinity instance in the mpidr. If this function does
358 * not return successfully then either the mpidr or the affinity
359 * levels are incorrect.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100360 */
Achin Gupta0959db52013-12-02 17:33:04 +0000361 rc = psci_get_aff_map_nodes(mpidr,
362 start_afflvl,
363 end_afflvl,
364 mpidr_nodes);
365 if (rc != PSCI_E_SUCCESS)
366 return rc;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100367
368 /*
Achin Gupta0959db52013-12-02 17:33:04 +0000369 * This function acquires the lock corresponding to each affinity
370 * level so that by the time all locks are taken, the system topology
371 * is snapshot and state management can be done safely.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100372 */
Achin Gupta0959db52013-12-02 17:33:04 +0000373 psci_acquire_afflvl_locks(mpidr,
374 start_afflvl,
375 end_afflvl,
376 mpidr_nodes);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100377
Achin Gupta0959db52013-12-02 17:33:04 +0000378
Achin Guptaa45e3972013-12-05 15:10:48 +0000379 /* Save the affinity level till which this cpu can be powered down */
380 psci_set_suspend_afflvl(mpidr_nodes[MPIDR_AFFLVL0], end_afflvl);
381
Achin Gupta0959db52013-12-02 17:33:04 +0000382 /* Perform generic, architecture and platform specific handling */
383 rc = psci_call_suspend_handlers(mpidr_nodes,
384 start_afflvl,
385 end_afflvl,
386 mpidr,
387 entrypoint,
388 context_id,
389 power_state);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100390
391 /*
Achin Gupta0959db52013-12-02 17:33:04 +0000392 * Release the locks corresponding to each affinity level in the
393 * reverse order to which they were acquired.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100394 */
Achin Gupta0959db52013-12-02 17:33:04 +0000395 psci_release_afflvl_locks(mpidr,
396 start_afflvl,
397 end_afflvl,
398 mpidr_nodes);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100399
Achin Gupta4f6ad662013-10-25 09:08:21 +0100400 return rc;
401}
402
403/*******************************************************************************
404 * The following functions finish an earlier affinity suspend request. They
405 * are called by the common finisher routine in psci_common.c.
406 ******************************************************************************/
407static unsigned int psci_afflvl0_suspend_finish(unsigned long mpidr,
Achin Gupta0959db52013-12-02 17:33:04 +0000408 aff_map_node *cpu_node)
Achin Gupta4f6ad662013-10-25 09:08:21 +0100409{
Achin Gupta0959db52013-12-02 17:33:04 +0000410 unsigned int index, plat_state, state, rc = PSCI_E_SUCCESS;
Achin Gupta607084e2014-02-09 18:24:19 +0000411 int32_t suspend_level;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100412
413 assert(cpu_node->level == MPIDR_AFFLVL0);
414
Achin Gupta0959db52013-12-02 17:33:04 +0000415 /* Ensure we have been woken up from a suspended state */
Achin Gupta75f73672013-12-05 16:33:10 +0000416 state = psci_get_state(cpu_node);
Achin Gupta0959db52013-12-02 17:33:04 +0000417 assert(state == PSCI_STATE_SUSPEND);
418
Achin Gupta4f6ad662013-10-25 09:08:21 +0100419 /*
420 * Plat. management: Perform the platform specific actions
421 * before we change the state of the cpu e.g. enabling the
422 * gic or zeroing the mailbox register. If anything goes
423 * wrong then assert as there is no way to recover from this
424 * situation.
425 */
426 if (psci_plat_pm_ops->affinst_suspend_finish) {
Achin Gupta0959db52013-12-02 17:33:04 +0000427
428 /* Get the physical state of this cpu */
Achin Gupta75f73672013-12-05 16:33:10 +0000429 plat_state = get_phys_state(state);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100430 rc = psci_plat_pm_ops->affinst_suspend_finish(mpidr,
431 cpu_node->level,
432 plat_state);
433 assert(rc == PSCI_E_SUCCESS);
434 }
435
436 /* Get the index for restoring the re-entry information */
437 index = cpu_node->data;
438
439 /*
Achin Guptaef7a28c2014-02-01 08:59:56 +0000440 * Arch. management: Restore the stashed EL3 architectural
441 * context from the 'cpu_context' structure for this cpu.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100442 */
Achin Guptaef7a28c2014-02-01 08:59:56 +0000443 cm_el3_sysregs_context_restore(NON_SECURE);
444 rc = PSCI_E_SUCCESS;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100445
446 /*
Achin Gupta607084e2014-02-09 18:24:19 +0000447 * Use the more complex exception vectors to enable SPD
448 * initialisation. SP_EL3 should point to a 'cpu_context'
449 * structure which has an exception stack allocated. The
450 * non-secure context should have been set on this cpu
451 * prior to suspension.
452 */
453 assert(cm_get_context(mpidr, NON_SECURE));
454 cm_set_next_eret_context(NON_SECURE);
455 write_vbar_el3((uint64_t) runtime_exceptions);
456
457 /*
458 * Call the cpu suspend finish handler registered by the Secure Payload
459 * Dispatcher to let it do any bookeeping. If the handler encounters an
460 * error, it's expected to assert within
461 */
462 if (spd_pm.svc_suspend) {
463 suspend_level = psci_get_suspend_afflvl(cpu_node);
464 spd_pm.svc_suspend_finish(suspend_level);
465 }
466
467 /*
Achin Gupta4f6ad662013-10-25 09:08:21 +0100468 * Generic management: Now we just need to retrieve the
469 * information that we had stashed away during the suspend
Achin Gupta3140a9e2013-12-02 16:23:12 +0000470 * call to set this cpu on its way.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100471 */
Achin Guptac8afc782013-11-25 18:45:02 +0000472 psci_get_ns_entry_info(index);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100473
Achin Gupta75f73672013-12-05 16:33:10 +0000474 /* State management: mark this cpu as on */
475 psci_set_state(cpu_node, PSCI_STATE_ON);
476
Achin Gupta4f6ad662013-10-25 09:08:21 +0100477 /* Clean caches before re-entering normal world */
478 dcsw_op_louis(DCCSW);
479
480 return rc;
481}
482
483static unsigned int psci_afflvl1_suspend_finish(unsigned long mpidr,
Achin Gupta0959db52013-12-02 17:33:04 +0000484 aff_map_node *cluster_node)
Achin Gupta4f6ad662013-10-25 09:08:21 +0100485{
Achin Gupta0959db52013-12-02 17:33:04 +0000486 unsigned int plat_state, rc = PSCI_E_SUCCESS;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100487
488 assert(cluster_node->level == MPIDR_AFFLVL1);
489
490 /*
491 * Plat. management: Perform the platform specific actions
492 * as per the old state of the cluster e.g. enabling
493 * coherency at the interconnect depends upon the state with
494 * which this cluster was powered up. If anything goes wrong
495 * then assert as there is no way to recover from this
496 * situation.
497 */
498 if (psci_plat_pm_ops->affinst_suspend_finish) {
Achin Gupta0959db52013-12-02 17:33:04 +0000499
500 /* Get the physical state of this cpu */
Achin Gupta75f73672013-12-05 16:33:10 +0000501 plat_state = psci_get_phys_state(cluster_node);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100502 rc = psci_plat_pm_ops->affinst_suspend_finish(mpidr,
503 cluster_node->level,
504 plat_state);
505 assert(rc == PSCI_E_SUCCESS);
506 }
507
Achin Gupta75f73672013-12-05 16:33:10 +0000508 /* State management: Increment the cluster reference count */
509 psci_set_state(cluster_node, PSCI_STATE_ON);
510
Achin Gupta4f6ad662013-10-25 09:08:21 +0100511 return rc;
512}
513
514
515static unsigned int psci_afflvl2_suspend_finish(unsigned long mpidr,
Achin Gupta0959db52013-12-02 17:33:04 +0000516 aff_map_node *system_node)
Achin Gupta4f6ad662013-10-25 09:08:21 +0100517{
Achin Gupta0959db52013-12-02 17:33:04 +0000518 unsigned int plat_state, rc = PSCI_E_SUCCESS;;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100519
520 /* Cannot go beyond this affinity level */
521 assert(system_node->level == MPIDR_AFFLVL2);
522
523 /*
524 * Currently, there are no architectural actions to perform
525 * at the system level.
526 */
527
528 /*
529 * Plat. management: Perform the platform specific actions
530 * as per the old state of the cluster e.g. enabling
531 * coherency at the interconnect depends upon the state with
532 * which this cluster was powered up. If anything goes wrong
533 * then assert as there is no way to recover from this
534 * situation.
535 */
536 if (psci_plat_pm_ops->affinst_suspend_finish) {
Achin Gupta0959db52013-12-02 17:33:04 +0000537
538 /* Get the physical state of the system */
Achin Gupta75f73672013-12-05 16:33:10 +0000539 plat_state = psci_get_phys_state(system_node);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100540 rc = psci_plat_pm_ops->affinst_suspend_finish(mpidr,
541 system_node->level,
542 plat_state);
543 assert(rc == PSCI_E_SUCCESS);
544 }
545
Achin Gupta75f73672013-12-05 16:33:10 +0000546 /* State management: Increment the system reference count */
547 psci_set_state(system_node, PSCI_STATE_ON);
548
Achin Gupta4f6ad662013-10-25 09:08:21 +0100549 return rc;
550}
551
552const afflvl_power_on_finisher psci_afflvl_suspend_finishers[] = {
553 psci_afflvl0_suspend_finish,
554 psci_afflvl1_suspend_finish,
555 psci_afflvl2_suspend_finish,
556};
557