blob: 236309cf9efe6c5d8b23b9e6e8d1cdda4d0dcf77 [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>
34#include <arch_helpers.h>
35#include <console.h>
36#include <platform.h>
37#include <psci.h>
38#include <psci_private.h>
Jeenu Viswambharancaa84932014-02-06 10:36:15 +000039#include <context_mgmt.h>
Achin Guptac8afc782013-11-25 18:45:02 +000040#include <runtime_svc.h>
James Morrissey40a6f642014-02-10 14:24:36 +000041#include "debug.h"
Achin Gupta4f6ad662013-10-25 09:08:21 +010042
Achin Gupta607084e2014-02-09 18:24:19 +000043/*
Jeenu Viswambharan7f366602014-02-20 17:11:00 +000044 * SPD power management operations, expected to be supplied by the registered
45 * SPD on successful SP initialization
Achin Gupta607084e2014-02-09 18:24:19 +000046 */
Jeenu Viswambharan7f366602014-02-20 17:11:00 +000047const spd_pm_ops *psci_spd_pm;
Achin Gupta607084e2014-02-09 18:24:19 +000048
Achin Gupta4f6ad662013-10-25 09:08:21 +010049/*******************************************************************************
50 * Arrays that contains information needs to resume a cpu's execution when woken
51 * out of suspend or off states. 'psci_ns_einfo_idx' keeps track of the next
Achin Guptaa59caa42013-12-05 14:21:04 +000052 * free index in the 'psci_ns_entry_info' & 'psci_suspend_context' arrays. Each
Achin Gupta4f6ad662013-10-25 09:08:21 +010053 * cpu is allocated a single entry in each array during startup.
54 ******************************************************************************/
Achin Guptaa59caa42013-12-05 14:21:04 +000055suspend_context psci_suspend_context[PSCI_NUM_AFFS];
Achin Gupta4f6ad662013-10-25 09:08:21 +010056ns_entry_info psci_ns_entry_info[PSCI_NUM_AFFS];
57unsigned int psci_ns_einfo_idx;
58
59/*******************************************************************************
60 * Grand array that holds the platform's topology information for state
61 * management of affinity instances. Each node (aff_map_node) in the array
62 * corresponds to an affinity instance e.g. cluster, cpu within an mpidr
63 ******************************************************************************/
64aff_map_node psci_aff_map[PSCI_NUM_AFFS]
65__attribute__ ((section("tzfw_coherent_mem")));
66
67/*******************************************************************************
68 * In a system, a certain number of affinity instances are present at an
69 * affinity level. The cumulative number of instances across all levels are
70 * stored in 'psci_aff_map'. The topology tree has been flattenned into this
71 * array. To retrieve nodes, information about the extents of each affinity
72 * level i.e. start index and end index needs to be present. 'psci_aff_limits'
73 * stores this information.
74 ******************************************************************************/
75aff_limits_node psci_aff_limits[MPIDR_MAX_AFFLVL + 1];
76
77/*******************************************************************************
78 * Pointer to functions exported by the platform to complete power mgmt. ops
79 ******************************************************************************/
80plat_pm_ops *psci_plat_pm_ops;
81
82/*******************************************************************************
Achin Guptaa45e3972013-12-05 15:10:48 +000083 * Routine to return the maximum affinity level to traverse to after a cpu has
84 * been physically powered up. It is expected to be called immediately after
85 * reset from assembler code. It has to find its 'aff_map_node' instead of
86 * getting it as an argument.
87 * TODO: Calling psci_get_aff_map_node() with the MMU disabled is slow. Add
88 * support to allow faster access to the target affinity level.
89 ******************************************************************************/
90int get_power_on_target_afflvl(unsigned long mpidr)
91{
92 aff_map_node *node;
93 unsigned int state;
94
95 /* Retrieve our node from the topology tree */
Jeenu Viswambharancaa84932014-02-06 10:36:15 +000096 node = psci_get_aff_map_node(mpidr & MPIDR_AFFINITY_MASK,
97 MPIDR_AFFLVL0);
Achin Guptaa45e3972013-12-05 15:10:48 +000098 assert(node);
99
100 /*
101 * Return the maximum supported affinity level if this cpu was off.
102 * Call the handler in the suspend code if this cpu had been suspended.
103 * Any other state is invalid.
104 */
Achin Gupta75f73672013-12-05 16:33:10 +0000105 state = psci_get_state(node);
Achin Guptaa45e3972013-12-05 15:10:48 +0000106 if (state == PSCI_STATE_ON_PENDING)
107 return get_max_afflvl();
108
109 if (state == PSCI_STATE_SUSPEND)
110 return psci_get_suspend_afflvl(node);
111
112 return PSCI_E_INVALID_PARAMS;
113}
114
115/*******************************************************************************
Achin Gupta4f6ad662013-10-25 09:08:21 +0100116 * Simple routine to retrieve the maximum affinity level supported by the
117 * platform and check that it makes sense.
118 ******************************************************************************/
119int get_max_afflvl()
120{
121 int aff_lvl;
122
123 aff_lvl = plat_get_max_afflvl();
124 assert(aff_lvl <= MPIDR_MAX_AFFLVL && aff_lvl >= MPIDR_AFFLVL0);
125
126 return aff_lvl;
127}
128
129/*******************************************************************************
130 * Simple routine to set the id of an affinity instance at a given level in the
131 * mpidr.
132 ******************************************************************************/
133unsigned long mpidr_set_aff_inst(unsigned long mpidr,
134 unsigned char aff_inst,
135 int aff_lvl)
136{
137 unsigned long aff_shift;
138
139 assert(aff_lvl <= MPIDR_AFFLVL3);
140
141 /*
142 * Decide the number of bits to shift by depending upon
143 * the affinity level
144 */
145 aff_shift = get_afflvl_shift(aff_lvl);
146
147 /* Clear the existing affinity instance & set the new one*/
148 mpidr &= ~(MPIDR_AFFLVL_MASK << aff_shift);
149 mpidr |= aff_inst << aff_shift;
150
151 return mpidr;
152}
153
154/*******************************************************************************
Achin Gupta0959db52013-12-02 17:33:04 +0000155 * This function sanity checks a range of affinity levels.
156 ******************************************************************************/
157int psci_check_afflvl_range(int start_afflvl, int end_afflvl)
158{
159 /* Sanity check the parameters passed */
160 if (end_afflvl > MPIDR_MAX_AFFLVL)
161 return PSCI_E_INVALID_PARAMS;
162
163 if (start_afflvl < MPIDR_AFFLVL0)
164 return PSCI_E_INVALID_PARAMS;
165
166 if (end_afflvl < start_afflvl)
167 return PSCI_E_INVALID_PARAMS;
168
169 return PSCI_E_SUCCESS;
170}
171
172/*******************************************************************************
173 * This function is passed an array of pointers to affinity level nodes in the
174 * topology tree for an mpidr. It picks up locks for each affinity level bottom
175 * up in the range specified.
176 ******************************************************************************/
177void psci_acquire_afflvl_locks(unsigned long mpidr,
178 int start_afflvl,
179 int end_afflvl,
180 mpidr_aff_map_nodes mpidr_nodes)
181{
182 int level;
183
184 for (level = start_afflvl; level <= end_afflvl; level++) {
185 if (mpidr_nodes[level] == NULL)
186 continue;
187 bakery_lock_get(mpidr, &mpidr_nodes[level]->lock);
188 }
189}
190
191/*******************************************************************************
192 * This function is passed an array of pointers to affinity level nodes in the
193 * topology tree for an mpidr. It releases the lock for each affinity level top
194 * down in the range specified.
195 ******************************************************************************/
196void psci_release_afflvl_locks(unsigned long mpidr,
197 int start_afflvl,
198 int end_afflvl,
199 mpidr_aff_map_nodes mpidr_nodes)
200{
201 int level;
202
203 for (level = end_afflvl; level >= start_afflvl; level--) {
204 if (mpidr_nodes[level] == NULL)
205 continue;
206 bakery_lock_release(mpidr, &mpidr_nodes[level]->lock);
207 }
208}
209
210/*******************************************************************************
Achin Gupta4f6ad662013-10-25 09:08:21 +0100211 * Simple routine to determine whether an affinity instance at a given level
212 * in an mpidr exists or not.
213 ******************************************************************************/
214int psci_validate_mpidr(unsigned long mpidr, int level)
215{
216 aff_map_node *node;
217
218 node = psci_get_aff_map_node(mpidr, level);
219 if (node && (node->state & PSCI_AFF_PRESENT))
220 return PSCI_E_SUCCESS;
221 else
222 return PSCI_E_INVALID_PARAMS;
223}
224
225/*******************************************************************************
Achin Gupta4f6ad662013-10-25 09:08:21 +0100226 * This function retrieves all the stashed information needed to correctly
227 * resume a cpu's execution in the non-secure state after it has been physically
228 * powered on i.e. turned ON or resumed from SUSPEND
229 ******************************************************************************/
Achin Guptac8afc782013-11-25 18:45:02 +0000230void psci_get_ns_entry_info(unsigned int index)
Achin Gupta4f6ad662013-10-25 09:08:21 +0100231{
232 unsigned long sctlr = 0, scr, el_status, id_aa64pfr0;
Jeenu Viswambharancaa84932014-02-06 10:36:15 +0000233 uint64_t mpidr = read_mpidr();
234 cpu_context *ns_entry_context;
235 gp_regs *ns_entry_gpregs;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100236
237 scr = read_scr();
238
Achin Gupta4f6ad662013-10-25 09:08:21 +0100239 /* Find out which EL we are going to */
240 id_aa64pfr0 = read_id_aa64pfr0_el1();
241 el_status = (id_aa64pfr0 >> ID_AA64PFR0_EL2_SHIFT) &
242 ID_AA64PFR0_ELX_MASK;
243
244 /* Restore endianess */
245 if (psci_ns_entry_info[index].sctlr & SCTLR_EE_BIT)
246 sctlr |= SCTLR_EE_BIT;
247 else
248 sctlr &= ~SCTLR_EE_BIT;
249
250 /* Turn off MMU and Caching */
251 sctlr &= ~(SCTLR_M_BIT | SCTLR_C_BIT | SCTLR_M_BIT);
252
253 /* Set the register width */
254 if (psci_ns_entry_info[index].scr & SCR_RW_BIT)
255 scr |= SCR_RW_BIT;
256 else
257 scr &= ~SCR_RW_BIT;
258
259 scr |= SCR_NS_BIT;
260
261 if (el_status)
262 write_sctlr_el2(sctlr);
263 else
264 write_sctlr_el1(sctlr);
265
266 /* Fulfill the cpu_on entry reqs. as per the psci spec */
Jeenu Viswambharancaa84932014-02-06 10:36:15 +0000267 ns_entry_context = (cpu_context *) cm_get_context(mpidr, NON_SECURE);
268 assert(ns_entry_context);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100269
Achin Guptac8afc782013-11-25 18:45:02 +0000270 /*
Jeenu Viswambharancaa84932014-02-06 10:36:15 +0000271 * Setup general purpose registers to return the context id and
272 * prevent leakage of secure information into the normal world.
Achin Guptac8afc782013-11-25 18:45:02 +0000273 */
Jeenu Viswambharancaa84932014-02-06 10:36:15 +0000274 ns_entry_gpregs = get_gpregs_ctx(ns_entry_context);
275 write_ctx_reg(ns_entry_gpregs,
276 CTX_GPREG_X0,
277 psci_ns_entry_info[index].context_id);
278
279 /*
280 * Tell the context management library to setup EL3 system registers to
281 * be able to ERET into the ns state, and SP_EL3 points to the right
282 * context to exit from EL3 correctly.
283 */
284 cm_set_el3_eret_context(NON_SECURE,
285 psci_ns_entry_info[index].eret_info.entrypoint,
286 psci_ns_entry_info[index].eret_info.spsr,
287 scr);
288
289 cm_set_next_eret_context(NON_SECURE);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100290}
291
292/*******************************************************************************
293 * This function retrieves and stashes all the information needed to correctly
294 * resume a cpu's execution in the non-secure state after it has been physically
295 * powered on i.e. turned ON or resumed from SUSPEND. This is done prior to
296 * turning it on or before suspending it.
297 ******************************************************************************/
298int psci_set_ns_entry_info(unsigned int index,
299 unsigned long entrypoint,
300 unsigned long context_id)
301{
302 int rc = PSCI_E_SUCCESS;
303 unsigned int rw, mode, ee, spsr = 0;
304 unsigned long id_aa64pfr0 = read_id_aa64pfr0_el1(), scr = read_scr();
305 unsigned long el_status;
306
307 /* Figure out what mode do we enter the non-secure world in */
308 el_status = (id_aa64pfr0 >> ID_AA64PFR0_EL2_SHIFT) &
309 ID_AA64PFR0_ELX_MASK;
310
311 /*
312 * Figure out whether the cpu enters the non-secure address space
313 * in aarch32 or aarch64
314 */
315 rw = scr & SCR_RW_BIT;
316 if (rw) {
317
318 /*
319 * Check whether a Thumb entry point has been provided for an
320 * aarch64 EL
321 */
322 if (entrypoint & 0x1)
323 return PSCI_E_INVALID_PARAMS;
324
325 if (el_status && (scr & SCR_HCE_BIT)) {
326 mode = MODE_EL2;
327 ee = read_sctlr_el2() & SCTLR_EE_BIT;
328 } else {
329 mode = MODE_EL1;
330 ee = read_sctlr_el1() & SCTLR_EE_BIT;
331 }
332
333 spsr = DAIF_DBG_BIT | DAIF_ABT_BIT;
334 spsr |= DAIF_IRQ_BIT | DAIF_FIQ_BIT;
335 spsr <<= PSR_DAIF_SHIFT;
336 spsr |= make_spsr(mode, MODE_SP_ELX, !rw);
337
338 psci_ns_entry_info[index].sctlr |= ee;
339 psci_ns_entry_info[index].scr |= SCR_RW_BIT;
340 } else {
341
342 /* Check whether aarch32 has to be entered in Thumb mode */
343 if (entrypoint & 0x1)
344 spsr = SPSR32_T_BIT;
345
346 if (el_status && (scr & SCR_HCE_BIT)) {
347 mode = AARCH32_MODE_HYP;
348 ee = read_sctlr_el2() & SCTLR_EE_BIT;
349 } else {
350 mode = AARCH32_MODE_SVC;
351 ee = read_sctlr_el1() & SCTLR_EE_BIT;
352 }
353
354 /*
355 * TODO: Choose async. exception bits if HYP mode is not
356 * implemented according to the values of SCR.{AW, FW} bits
357 */
358 spsr |= DAIF_ABT_BIT | DAIF_IRQ_BIT | DAIF_FIQ_BIT;
359 spsr <<= PSR_DAIF_SHIFT;
Jeenu Viswambharancaa84932014-02-06 10:36:15 +0000360 if (ee)
Achin Gupta4f6ad662013-10-25 09:08:21 +0100361 spsr |= SPSR32_EE_BIT;
362 spsr |= mode;
363
364 /* Ensure that the CSPR.E and SCTLR.EE bits match */
365 psci_ns_entry_info[index].sctlr |= ee;
366 psci_ns_entry_info[index].scr &= ~SCR_RW_BIT;
367 }
368
369 psci_ns_entry_info[index].eret_info.entrypoint = entrypoint;
370 psci_ns_entry_info[index].eret_info.spsr = spsr;
371 psci_ns_entry_info[index].context_id = context_id;
372
373 return rc;
374}
375
376/*******************************************************************************
Achin Gupta75f73672013-12-05 16:33:10 +0000377 * This function takes a pointer to an affinity node in the topology tree and
378 * returns its state. State of a non-leaf node needs to be calculated.
379 ******************************************************************************/
380unsigned short psci_get_state(aff_map_node *node)
381{
382 assert(node->level >= MPIDR_AFFLVL0 && node->level <= MPIDR_MAX_AFFLVL);
383
384 /* A cpu node just contains the state which can be directly returned */
385 if (node->level == MPIDR_AFFLVL0)
386 return (node->state >> PSCI_STATE_SHIFT) & PSCI_STATE_MASK;
387
388 /*
389 * For an affinity level higher than a cpu, the state has to be
390 * calculated. It depends upon the value of the reference count
391 * which is managed by each node at the next lower affinity level
392 * e.g. for a cluster, each cpu increments/decrements the reference
393 * count. If the reference count is 0 then the affinity level is
394 * OFF else ON.
395 */
396 if (node->ref_count)
397 return PSCI_STATE_ON;
398 else
399 return PSCI_STATE_OFF;
400}
401
402/*******************************************************************************
403 * This function takes a pointer to an affinity node in the topology tree and
404 * a target state. State of a non-leaf node needs to be converted to a reference
405 * count. State of a leaf node can be set directly.
406 ******************************************************************************/
407void psci_set_state(aff_map_node *node, unsigned short state)
408{
409 assert(node->level >= MPIDR_AFFLVL0 && node->level <= MPIDR_MAX_AFFLVL);
410
411 /*
412 * For an affinity level higher than a cpu, the state is used
413 * to decide whether the reference count is incremented or
414 * decremented. Entry into the ON_PENDING state does not have
415 * effect.
416 */
417 if (node->level > MPIDR_AFFLVL0) {
418 switch (state) {
419 case PSCI_STATE_ON:
420 node->ref_count++;
421 break;
422 case PSCI_STATE_OFF:
423 case PSCI_STATE_SUSPEND:
424 node->ref_count--;
425 break;
426 case PSCI_STATE_ON_PENDING:
427 /*
428 * An affinity level higher than a cpu will not undergo
429 * a state change when it is about to be turned on
430 */
431 return;
432 default:
433 assert(0);
434 }
435 } else {
436 node->state &= ~(PSCI_STATE_MASK << PSCI_STATE_SHIFT);
437 node->state |= (state & PSCI_STATE_MASK) << PSCI_STATE_SHIFT;
438 }
439}
440
441/*******************************************************************************
Achin Gupta4f6ad662013-10-25 09:08:21 +0100442 * An affinity level could be on, on_pending, suspended or off. These are the
Achin Gupta3140a9e2013-12-02 16:23:12 +0000443 * logical states it can be in. Physically either it is off or on. When it is in
444 * the state on_pending then it is about to be turned on. It is not possible to
Achin Gupta4f6ad662013-10-25 09:08:21 +0100445 * tell whether that's actually happenned or not. So we err on the side of
446 * caution & treat the affinity level as being turned off.
447 ******************************************************************************/
Achin Gupta75f73672013-12-05 16:33:10 +0000448unsigned short psci_get_phys_state(aff_map_node *node)
Achin Gupta4f6ad662013-10-25 09:08:21 +0100449{
Achin Gupta75f73672013-12-05 16:33:10 +0000450 unsigned int state;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100451
Achin Gupta75f73672013-12-05 16:33:10 +0000452 state = psci_get_state(node);
453 return get_phys_state(state);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100454}
455
456/*******************************************************************************
Achin Gupta0959db52013-12-02 17:33:04 +0000457 * This function takes an array of pointers to affinity instance nodes in the
458 * topology tree and calls the physical power on handler for the corresponding
459 * affinity levels
460 ******************************************************************************/
461static int psci_call_power_on_handlers(mpidr_aff_map_nodes mpidr_nodes,
462 int start_afflvl,
463 int end_afflvl,
464 afflvl_power_on_finisher *pon_handlers,
465 unsigned long mpidr)
466{
467 int rc = PSCI_E_INVALID_PARAMS, level;
468 aff_map_node *node;
469
470 for (level = end_afflvl; level >= start_afflvl; level--) {
471 node = mpidr_nodes[level];
472 if (node == NULL)
473 continue;
474
475 /*
476 * If we run into any trouble while powering up an
477 * affinity instance, then there is no recovery path
478 * so simply return an error and let the caller take
479 * care of the situation.
480 */
481 rc = pon_handlers[level](mpidr, node);
482 if (rc != PSCI_E_SUCCESS)
483 break;
484 }
485
486 return rc;
487}
488
489/*******************************************************************************
Achin Gupta4f6ad662013-10-25 09:08:21 +0100490 * Generic handler which is called when a cpu is physically powered on. It
Achin Gupta0959db52013-12-02 17:33:04 +0000491 * traverses through all the affinity levels performing generic, architectural,
Achin Gupta4f6ad662013-10-25 09:08:21 +0100492 * platform setup and state management e.g. for a cluster that's been powered
493 * on, it will call the platform specific code which will enable coherency at
494 * the interconnect level. For a cpu it could mean turning on the MMU etc.
495 *
Achin Gupta0959db52013-12-02 17:33:04 +0000496 * The state of all the relevant affinity levels is changed after calling the
497 * affinity level specific handlers as their actions would depend upon the state
498 * the affinity level is exiting from.
499 *
500 * The affinity level specific handlers are called in descending order i.e. from
501 * the highest to the lowest affinity level implemented by the platform because
502 * to turn on affinity level X it is neccesary to turn on affinity level X + 1
503 * first.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100504 *
505 * CAUTION: This function is called with coherent stacks so that coherency and
506 * the mmu can be turned on safely.
507 ******************************************************************************/
Achin Gupta0959db52013-12-02 17:33:04 +0000508void psci_afflvl_power_on_finish(unsigned long mpidr,
509 int start_afflvl,
510 int end_afflvl,
511 afflvl_power_on_finisher *pon_handlers)
Achin Gupta4f6ad662013-10-25 09:08:21 +0100512{
Achin Gupta0959db52013-12-02 17:33:04 +0000513 mpidr_aff_map_nodes mpidr_nodes;
514 int rc;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100515
Jeenu Viswambharancaa84932014-02-06 10:36:15 +0000516 mpidr &= MPIDR_AFFINITY_MASK;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100517
518 /*
Achin Gupta0959db52013-12-02 17:33:04 +0000519 * Collect the pointers to the nodes in the topology tree for
520 * each affinity instance in the mpidr. If this function does
521 * not return successfully then either the mpidr or the affinity
522 * levels are incorrect. Either case is an irrecoverable error.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100523 */
Achin Gupta0959db52013-12-02 17:33:04 +0000524 rc = psci_get_aff_map_nodes(mpidr,
525 start_afflvl,
526 end_afflvl,
527 mpidr_nodes);
James Morrissey40a6f642014-02-10 14:24:36 +0000528 if (rc != PSCI_E_SUCCESS)
529 panic();
Achin Gupta4f6ad662013-10-25 09:08:21 +0100530
531 /*
Achin Gupta0959db52013-12-02 17:33:04 +0000532 * This function acquires the lock corresponding to each affinity
533 * level so that by the time all locks are taken, the system topology
534 * is snapshot and state management can be done safely.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100535 */
Achin Gupta0959db52013-12-02 17:33:04 +0000536 psci_acquire_afflvl_locks(mpidr,
537 start_afflvl,
538 end_afflvl,
539 mpidr_nodes);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100540
541 /* Perform generic, architecture and platform specific handling */
Achin Gupta0959db52013-12-02 17:33:04 +0000542 rc = psci_call_power_on_handlers(mpidr_nodes,
543 start_afflvl,
544 end_afflvl,
545 pon_handlers,
546 mpidr);
James Morrissey40a6f642014-02-10 14:24:36 +0000547 if (rc != PSCI_E_SUCCESS)
548 panic();
Achin Gupta4f6ad662013-10-25 09:08:21 +0100549
550 /*
Achin Gupta0959db52013-12-02 17:33:04 +0000551 * This loop releases the lock corresponding to each affinity level
552 * in the reverse order to which they were acquired.
553 */
554 psci_release_afflvl_locks(mpidr,
555 start_afflvl,
556 end_afflvl,
557 mpidr_nodes);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100558}
Jeenu Viswambharan7f366602014-02-20 17:11:00 +0000559
560/*******************************************************************************
561 * This function initializes the set of hooks that PSCI invokes as part of power
562 * management operation. The power management hooks are expected to be provided
563 * by the SPD, after it finishes all its initialization
564 ******************************************************************************/
565void psci_register_spd_pm_hook(const spd_pm_ops *pm)
566{
567 psci_spd_pm = pm;
568}