blob: ca521ff38e0ef7f16ae12f0304c157d2c39a4a0e [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;
Vikram Kanigiri78a6e0c2014-03-11 17:41:00 +000090 unsigned long psci_entrypoint, 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 */
Jeenu Viswambharan7f366602014-02-20 17:11:00 +0000107 if (psci_spd_pm && psci_spd_pm->svc_suspend)
108 psci_spd_pm->svc_suspend(power_state);
Achin Gupta607084e2014-02-09 18:24:19 +0000109
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 */
Vikram Kanigiri78a6e0c2014-03-11 17:41:00 +0000149 sctlr = read_sctlr_el3();
Achin Gupta4f6ad662013-10-25 09:08:21 +0100150 sctlr &= ~SCTLR_C_BIT;
Vikram Kanigiri78a6e0c2014-03-11 17:41:00 +0000151 write_sctlr_el3(sctlr);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100152
153 /*
154 * CAUTION: This flush to the level of unification makes an assumption
155 * about the cache hierarchy at affinity level 0 (cpu) in the platform.
156 * Ideally the platform should tell psci which levels to flush to exit
157 * coherency.
158 */
159 dcsw_op_louis(DCCISW);
160
161 /*
162 * Plat. management: Allow the platform to perform the
163 * necessary actions to turn off this cpu e.g. set the
164 * platform defined mailbox with the psci entrypoint,
165 * program the power controller etc.
166 */
167 if (psci_plat_pm_ops->affinst_suspend) {
Achin Gupta75f73672013-12-05 16:33:10 +0000168 plat_state = psci_get_phys_state(cpu_node);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100169 rc = psci_plat_pm_ops->affinst_suspend(mpidr,
170 psci_entrypoint,
171 ns_entrypoint,
172 cpu_node->level,
173 plat_state);
174 }
175
176 return rc;
177}
178
179static int psci_afflvl1_suspend(unsigned long mpidr,
180 aff_map_node *cluster_node,
181 unsigned long ns_entrypoint,
182 unsigned long context_id,
183 unsigned int power_state)
184{
185 int rc = PSCI_E_SUCCESS;
186 unsigned int plat_state;
187 unsigned long psci_entrypoint;
188
189 /* Sanity check the cluster level */
190 assert(cluster_node->level == MPIDR_AFFLVL1);
191
Achin Gupta75f73672013-12-05 16:33:10 +0000192 /* State management: Decrement the cluster reference count */
193 psci_set_state(cluster_node, PSCI_STATE_SUSPEND);
194
Achin Gupta4f6ad662013-10-25 09:08:21 +0100195 /*
196 * Keep the physical state of this cluster handy to decide
197 * what action needs to be taken
198 */
Achin Gupta75f73672013-12-05 16:33:10 +0000199 plat_state = psci_get_phys_state(cluster_node);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100200
201 /*
202 * Arch. management: Flush all levels of caches to PoC if the
203 * cluster is to be shutdown
204 */
205 if (plat_state == PSCI_STATE_OFF)
206 dcsw_op_all(DCCISW);
207
208 /*
Achin Gupta3140a9e2013-12-02 16:23:12 +0000209 * Plat. Management. Allow the platform to do its cluster
Achin Gupta4f6ad662013-10-25 09:08:21 +0100210 * specific bookeeping e.g. turn off interconnect coherency,
211 * program the power controller etc.
212 */
213 if (psci_plat_pm_ops->affinst_suspend) {
214
215 /*
216 * Sending the psci entrypoint is currently redundant
217 * beyond affinity level 0 but one never knows what a
218 * platform might do. Also it allows us to keep the
219 * platform handler prototype the same.
220 */
221 psci_entrypoint = (unsigned long) psci_aff_suspend_finish_entry;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100222 rc = psci_plat_pm_ops->affinst_suspend(mpidr,
223 psci_entrypoint,
224 ns_entrypoint,
225 cluster_node->level,
226 plat_state);
227 }
228
229 return rc;
230}
231
232
233static int psci_afflvl2_suspend(unsigned long mpidr,
234 aff_map_node *system_node,
235 unsigned long ns_entrypoint,
236 unsigned long context_id,
237 unsigned int power_state)
238{
239 int rc = PSCI_E_SUCCESS;
240 unsigned int plat_state;
241 unsigned long psci_entrypoint;
242
243 /* Cannot go beyond this */
244 assert(system_node->level == MPIDR_AFFLVL2);
245
Achin Gupta75f73672013-12-05 16:33:10 +0000246 /* State management: Decrement the system reference count */
247 psci_set_state(system_node, PSCI_STATE_SUSPEND);
248
Achin Gupta4f6ad662013-10-25 09:08:21 +0100249 /*
250 * Keep the physical state of the system handy to decide what
251 * action needs to be taken
252 */
Achin Gupta75f73672013-12-05 16:33:10 +0000253 plat_state = psci_get_phys_state(system_node);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100254
255 /*
Achin Gupta3140a9e2013-12-02 16:23:12 +0000256 * Plat. Management : Allow the platform to do its bookeeping
Achin Gupta4f6ad662013-10-25 09:08:21 +0100257 * at this affinity level
258 */
259 if (psci_plat_pm_ops->affinst_suspend) {
260
261 /*
262 * Sending the psci entrypoint is currently redundant
263 * beyond affinity level 0 but one never knows what a
264 * platform might do. Also it allows us to keep the
265 * platform handler prototype the same.
266 */
267 psci_entrypoint = (unsigned long) psci_aff_suspend_finish_entry;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100268 rc = psci_plat_pm_ops->affinst_suspend(mpidr,
269 psci_entrypoint,
270 ns_entrypoint,
271 system_node->level,
272 plat_state);
273 }
274
275 return rc;
276}
277
278static const afflvl_suspend_handler psci_afflvl_suspend_handlers[] = {
279 psci_afflvl0_suspend,
280 psci_afflvl1_suspend,
281 psci_afflvl2_suspend,
282};
283
284/*******************************************************************************
Achin Gupta0959db52013-12-02 17:33:04 +0000285 * This function takes an array of pointers to affinity instance nodes in the
286 * topology tree and calls the suspend handler for the corresponding affinity
287 * levels
288 ******************************************************************************/
289static int psci_call_suspend_handlers(mpidr_aff_map_nodes mpidr_nodes,
290 int start_afflvl,
291 int end_afflvl,
292 unsigned long mpidr,
293 unsigned long entrypoint,
294 unsigned long context_id,
295 unsigned int power_state)
296{
297 int rc = PSCI_E_INVALID_PARAMS, level;
298 aff_map_node *node;
299
300 for (level = start_afflvl; level <= end_afflvl; level++) {
301 node = mpidr_nodes[level];
302 if (node == NULL)
303 continue;
304
305 /*
306 * TODO: In case of an error should there be a way
307 * of restoring what we might have torn down at
308 * lower affinity levels.
309 */
310 rc = psci_afflvl_suspend_handlers[level](mpidr,
311 node,
312 entrypoint,
313 context_id,
314 power_state);
315 if (rc != PSCI_E_SUCCESS)
316 break;
317 }
318
319 return rc;
320}
321
322/*******************************************************************************
323 * Top level handler which is called when a cpu wants to suspend its execution.
324 * It is assumed that along with turning the cpu off, higher affinity levels
325 * until the target affinity level will be turned off as well. It traverses
326 * through all the affinity levels performing generic, architectural, platform
327 * setup and state management e.g. for a cluster that's to be suspended, it will
328 * call the platform specific code which will disable coherency at the
329 * interconnect level if the cpu is the last in the cluster. For a cpu it could
330 * mean programming the power controller etc.
331 *
332 * The state of all the relevant affinity levels is changed prior to calling the
333 * affinity level specific handlers as their actions would depend upon the state
334 * the affinity level is about to enter.
335 *
336 * The affinity level specific handlers are called in ascending order i.e. from
337 * the lowest to the highest affinity level implemented by the platform because
338 * to turn off affinity level X it is neccesary to turn off affinity level X - 1
339 * first.
340 *
341 * CAUTION: This function is called with coherent stacks so that coherency can
342 * be turned off and caches can be flushed safely.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100343 ******************************************************************************/
344int psci_afflvl_suspend(unsigned long mpidr,
345 unsigned long entrypoint,
346 unsigned long context_id,
347 unsigned int power_state,
Achin Gupta0959db52013-12-02 17:33:04 +0000348 int start_afflvl,
349 int end_afflvl)
Achin Gupta4f6ad662013-10-25 09:08:21 +0100350{
Achin Gupta0959db52013-12-02 17:33:04 +0000351 int rc = PSCI_E_SUCCESS;
Achin Gupta0959db52013-12-02 17:33:04 +0000352 mpidr_aff_map_nodes mpidr_nodes;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100353
354 mpidr &= MPIDR_AFFINITY_MASK;
355
356 /*
Achin Gupta0959db52013-12-02 17:33:04 +0000357 * Collect the pointers to the nodes in the topology tree for
358 * each affinity instance in the mpidr. If this function does
359 * not return successfully then either the mpidr or the affinity
360 * levels are incorrect.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100361 */
Achin Gupta0959db52013-12-02 17:33:04 +0000362 rc = psci_get_aff_map_nodes(mpidr,
363 start_afflvl,
364 end_afflvl,
365 mpidr_nodes);
366 if (rc != PSCI_E_SUCCESS)
367 return rc;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100368
369 /*
Achin Gupta0959db52013-12-02 17:33:04 +0000370 * This function acquires the lock corresponding to each affinity
371 * level so that by the time all locks are taken, the system topology
372 * is snapshot and state management can be done safely.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100373 */
Achin Gupta0959db52013-12-02 17:33:04 +0000374 psci_acquire_afflvl_locks(mpidr,
375 start_afflvl,
376 end_afflvl,
377 mpidr_nodes);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100378
Achin Gupta0959db52013-12-02 17:33:04 +0000379
Achin Guptaa45e3972013-12-05 15:10:48 +0000380 /* Save the affinity level till which this cpu can be powered down */
381 psci_set_suspend_afflvl(mpidr_nodes[MPIDR_AFFLVL0], end_afflvl);
382
Achin Gupta0959db52013-12-02 17:33:04 +0000383 /* Perform generic, architecture and platform specific handling */
384 rc = psci_call_suspend_handlers(mpidr_nodes,
385 start_afflvl,
386 end_afflvl,
387 mpidr,
388 entrypoint,
389 context_id,
390 power_state);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100391
392 /*
Achin Gupta0959db52013-12-02 17:33:04 +0000393 * Release the locks corresponding to each affinity level in the
394 * reverse order to which they were acquired.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100395 */
Achin Gupta0959db52013-12-02 17:33:04 +0000396 psci_release_afflvl_locks(mpidr,
397 start_afflvl,
398 end_afflvl,
399 mpidr_nodes);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100400
Achin Gupta4f6ad662013-10-25 09:08:21 +0100401 return rc;
402}
403
404/*******************************************************************************
405 * The following functions finish an earlier affinity suspend request. They
406 * are called by the common finisher routine in psci_common.c.
407 ******************************************************************************/
408static unsigned int psci_afflvl0_suspend_finish(unsigned long mpidr,
Achin Gupta0959db52013-12-02 17:33:04 +0000409 aff_map_node *cpu_node)
Achin Gupta4f6ad662013-10-25 09:08:21 +0100410{
Achin Gupta0959db52013-12-02 17:33:04 +0000411 unsigned int index, plat_state, state, rc = PSCI_E_SUCCESS;
Achin Gupta607084e2014-02-09 18:24:19 +0000412 int32_t suspend_level;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100413
414 assert(cpu_node->level == MPIDR_AFFLVL0);
415
Achin Gupta0959db52013-12-02 17:33:04 +0000416 /* Ensure we have been woken up from a suspended state */
Achin Gupta75f73672013-12-05 16:33:10 +0000417 state = psci_get_state(cpu_node);
Achin Gupta0959db52013-12-02 17:33:04 +0000418 assert(state == PSCI_STATE_SUSPEND);
419
Achin Gupta4f6ad662013-10-25 09:08:21 +0100420 /*
421 * Plat. management: Perform the platform specific actions
422 * before we change the state of the cpu e.g. enabling the
423 * gic or zeroing the mailbox register. If anything goes
424 * wrong then assert as there is no way to recover from this
425 * situation.
426 */
427 if (psci_plat_pm_ops->affinst_suspend_finish) {
Achin Gupta0959db52013-12-02 17:33:04 +0000428
429 /* Get the physical state of this cpu */
Achin Gupta75f73672013-12-05 16:33:10 +0000430 plat_state = get_phys_state(state);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100431 rc = psci_plat_pm_ops->affinst_suspend_finish(mpidr,
432 cpu_node->level,
433 plat_state);
434 assert(rc == PSCI_E_SUCCESS);
435 }
436
437 /* Get the index for restoring the re-entry information */
438 index = cpu_node->data;
439
440 /*
Achin Guptaef7a28c2014-02-01 08:59:56 +0000441 * Arch. management: Restore the stashed EL3 architectural
442 * context from the 'cpu_context' structure for this cpu.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100443 */
Achin Guptaef7a28c2014-02-01 08:59:56 +0000444 cm_el3_sysregs_context_restore(NON_SECURE);
445 rc = PSCI_E_SUCCESS;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100446
447 /*
Achin Gupta607084e2014-02-09 18:24:19 +0000448 * Use the more complex exception vectors to enable SPD
449 * initialisation. SP_EL3 should point to a 'cpu_context'
450 * structure which has an exception stack allocated. The
451 * non-secure context should have been set on this cpu
452 * prior to suspension.
453 */
454 assert(cm_get_context(mpidr, NON_SECURE));
455 cm_set_next_eret_context(NON_SECURE);
456 write_vbar_el3((uint64_t) runtime_exceptions);
457
458 /*
459 * Call the cpu suspend finish handler registered by the Secure Payload
460 * Dispatcher to let it do any bookeeping. If the handler encounters an
461 * error, it's expected to assert within
462 */
Jeenu Viswambharan7f366602014-02-20 17:11:00 +0000463 if (psci_spd_pm && psci_spd_pm->svc_suspend) {
Achin Gupta607084e2014-02-09 18:24:19 +0000464 suspend_level = psci_get_suspend_afflvl(cpu_node);
Jeenu Viswambharan7f366602014-02-20 17:11:00 +0000465 psci_spd_pm->svc_suspend_finish(suspend_level);
Achin Gupta607084e2014-02-09 18:24:19 +0000466 }
467
468 /*
Achin Gupta4f6ad662013-10-25 09:08:21 +0100469 * Generic management: Now we just need to retrieve the
470 * information that we had stashed away during the suspend
Achin Gupta3140a9e2013-12-02 16:23:12 +0000471 * call to set this cpu on its way.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100472 */
Achin Guptac8afc782013-11-25 18:45:02 +0000473 psci_get_ns_entry_info(index);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100474
Achin Gupta75f73672013-12-05 16:33:10 +0000475 /* State management: mark this cpu as on */
476 psci_set_state(cpu_node, PSCI_STATE_ON);
477
Achin Gupta4f6ad662013-10-25 09:08:21 +0100478 /* Clean caches before re-entering normal world */
479 dcsw_op_louis(DCCSW);
480
481 return rc;
482}
483
484static unsigned int psci_afflvl1_suspend_finish(unsigned long mpidr,
Achin Gupta0959db52013-12-02 17:33:04 +0000485 aff_map_node *cluster_node)
Achin Gupta4f6ad662013-10-25 09:08:21 +0100486{
Achin Gupta0959db52013-12-02 17:33:04 +0000487 unsigned int plat_state, rc = PSCI_E_SUCCESS;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100488
489 assert(cluster_node->level == MPIDR_AFFLVL1);
490
491 /*
492 * Plat. management: Perform the platform specific actions
493 * as per the old state of the cluster e.g. enabling
494 * coherency at the interconnect depends upon the state with
495 * which this cluster was powered up. If anything goes wrong
496 * then assert as there is no way to recover from this
497 * situation.
498 */
499 if (psci_plat_pm_ops->affinst_suspend_finish) {
Achin Gupta0959db52013-12-02 17:33:04 +0000500
501 /* Get the physical state of this cpu */
Achin Gupta75f73672013-12-05 16:33:10 +0000502 plat_state = psci_get_phys_state(cluster_node);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100503 rc = psci_plat_pm_ops->affinst_suspend_finish(mpidr,
504 cluster_node->level,
505 plat_state);
506 assert(rc == PSCI_E_SUCCESS);
507 }
508
Achin Gupta75f73672013-12-05 16:33:10 +0000509 /* State management: Increment the cluster reference count */
510 psci_set_state(cluster_node, PSCI_STATE_ON);
511
Achin Gupta4f6ad662013-10-25 09:08:21 +0100512 return rc;
513}
514
515
516static unsigned int psci_afflvl2_suspend_finish(unsigned long mpidr,
Achin Gupta0959db52013-12-02 17:33:04 +0000517 aff_map_node *system_node)
Achin Gupta4f6ad662013-10-25 09:08:21 +0100518{
Achin Gupta0959db52013-12-02 17:33:04 +0000519 unsigned int plat_state, rc = PSCI_E_SUCCESS;;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100520
521 /* Cannot go beyond this affinity level */
522 assert(system_node->level == MPIDR_AFFLVL2);
523
524 /*
525 * Currently, there are no architectural actions to perform
526 * at the system level.
527 */
528
529 /*
530 * Plat. management: Perform the platform specific actions
531 * as per the old state of the cluster e.g. enabling
532 * coherency at the interconnect depends upon the state with
533 * which this cluster was powered up. If anything goes wrong
534 * then assert as there is no way to recover from this
535 * situation.
536 */
537 if (psci_plat_pm_ops->affinst_suspend_finish) {
Achin Gupta0959db52013-12-02 17:33:04 +0000538
539 /* Get the physical state of the system */
Achin Gupta75f73672013-12-05 16:33:10 +0000540 plat_state = psci_get_phys_state(system_node);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100541 rc = psci_plat_pm_ops->affinst_suspend_finish(mpidr,
542 system_node->level,
543 plat_state);
544 assert(rc == PSCI_E_SUCCESS);
545 }
546
Achin Gupta75f73672013-12-05 16:33:10 +0000547 /* State management: Increment the system reference count */
548 psci_set_state(system_node, PSCI_STATE_ON);
549
Achin Gupta4f6ad662013-10-25 09:08:21 +0100550 return rc;
551}
552
553const afflvl_power_on_finisher psci_afflvl_suspend_finishers[] = {
554 psci_afflvl0_suspend_finish,
555 psci_afflvl1_suspend_finish,
556 psci_afflvl2_suspend_finish,
557};
558