blob: 94855061f10561c64ada4a22344b16d394fea0bb [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
Dan Handley2bd4ef22014-04-09 13:14:54 +010031#include <arch.h>
Achin Gupta4f6ad662013-10-25 09:08:21 +010032#include <arch_helpers.h>
Dan Handley2bd4ef22014-04-09 13:14:54 +010033#include <assert.h>
34#include <bl_common.h>
35#include <context.h>
Jeenu Viswambharancaa84932014-02-06 10:36:15 +000036#include <context_mgmt.h>
Dan Handley714a0d22014-04-09 13:13:04 +010037#include <debug.h>
Dan Handleyed6ff952014-05-14 17:44:19 +010038#include <platform.h>
Andrew Thoelke4e126072014-06-04 21:10:52 +010039#include <string.h>
Dan Handley714a0d22014-04-09 13:13:04 +010040#include "psci_private.h"
Achin Gupta4f6ad662013-10-25 09:08:21 +010041
Achin Gupta607084e2014-02-09 18:24:19 +000042/*
Jeenu Viswambharan7f366602014-02-20 17:11:00 +000043 * SPD power management operations, expected to be supplied by the registered
44 * SPD on successful SP initialization
Achin Gupta607084e2014-02-09 18:24:19 +000045 */
Dan Handleye2712bc2014-04-10 15:37:22 +010046const spd_pm_ops_t *psci_spd_pm;
Achin Gupta607084e2014-02-09 18:24:19 +000047
Achin Gupta4f6ad662013-10-25 09:08:21 +010048/*******************************************************************************
Achin Gupta4f6ad662013-10-25 09:08:21 +010049 * Grand array that holds the platform's topology information for state
50 * management of affinity instances. Each node (aff_map_node) in the array
51 * corresponds to an affinity instance e.g. cluster, cpu within an mpidr
52 ******************************************************************************/
Dan Handleye2712bc2014-04-10 15:37:22 +010053aff_map_node_t psci_aff_map[PSCI_NUM_AFFS]
Achin Gupta4f6ad662013-10-25 09:08:21 +010054__attribute__ ((section("tzfw_coherent_mem")));
55
56/*******************************************************************************
Achin Gupta4f6ad662013-10-25 09:08:21 +010057 * Pointer to functions exported by the platform to complete power mgmt. ops
58 ******************************************************************************/
Dan Handleya4cb68e2014-04-23 13:47:06 +010059const plat_pm_ops_t *psci_plat_pm_ops;
Achin Gupta4f6ad662013-10-25 09:08:21 +010060
61/*******************************************************************************
Achin Guptaa45e3972013-12-05 15:10:48 +000062 * Routine to return the maximum affinity level to traverse to after a cpu has
63 * been physically powered up. It is expected to be called immediately after
Achin Guptaf3ccbab2014-07-25 14:52:47 +010064 * reset from assembler code.
Achin Guptaa45e3972013-12-05 15:10:48 +000065 ******************************************************************************/
Achin Guptaf3ccbab2014-07-25 14:52:47 +010066int get_power_on_target_afflvl()
Achin Guptaa45e3972013-12-05 15:10:48 +000067{
Vikram Kanigirif100f412014-04-01 19:26:26 +010068 int afflvl;
Achin Guptaa45e3972013-12-05 15:10:48 +000069
Achin Guptaf3ccbab2014-07-25 14:52:47 +010070#if DEBUG
71 unsigned int state;
72 aff_map_node_t *node;
73
Achin Guptaa45e3972013-12-05 15:10:48 +000074 /* Retrieve our node from the topology tree */
Achin Guptaf3ccbab2014-07-25 14:52:47 +010075 node = psci_get_aff_map_node(read_mpidr_el1() & MPIDR_AFFINITY_MASK,
76 MPIDR_AFFLVL0);
Achin Guptaa45e3972013-12-05 15:10:48 +000077 assert(node);
78
79 /*
Achin Guptaf3ccbab2014-07-25 14:52:47 +010080 * Sanity check the state of the cpu. It should be either suspend or "on
81 * pending"
Achin Guptaa45e3972013-12-05 15:10:48 +000082 */
Achin Gupta75f73672013-12-05 16:33:10 +000083 state = psci_get_state(node);
Achin Guptaf3ccbab2014-07-25 14:52:47 +010084 assert(state == PSCI_STATE_SUSPEND || state == PSCI_STATE_ON_PENDING);
85#endif
Achin Guptaa45e3972013-12-05 15:10:48 +000086
Achin Guptaf3ccbab2014-07-25 14:52:47 +010087 /*
88 * Assume that this cpu was suspended and retrieve its target affinity
89 * level. If it is invalid then it could only have been turned off
90 * earlier. get_max_afflvl() will return the highest affinity level a
91 * cpu can be turned off to.
92 */
93 afflvl = psci_get_suspend_afflvl();
94 if (afflvl == PSCI_INVALID_DATA)
95 afflvl = get_max_afflvl();
96 return afflvl;
Achin Guptaa45e3972013-12-05 15:10:48 +000097}
98
99/*******************************************************************************
Achin Gupta4f6ad662013-10-25 09:08:21 +0100100 * Simple routine to retrieve the maximum affinity level supported by the
101 * platform and check that it makes sense.
102 ******************************************************************************/
Juan Castillo2d552402014-06-13 17:05:10 +0100103int get_max_afflvl(void)
Achin Gupta4f6ad662013-10-25 09:08:21 +0100104{
105 int aff_lvl;
106
107 aff_lvl = plat_get_max_afflvl();
108 assert(aff_lvl <= MPIDR_MAX_AFFLVL && aff_lvl >= MPIDR_AFFLVL0);
109
110 return aff_lvl;
111}
112
113/*******************************************************************************
114 * Simple routine to set the id of an affinity instance at a given level in the
115 * mpidr.
116 ******************************************************************************/
117unsigned long mpidr_set_aff_inst(unsigned long mpidr,
118 unsigned char aff_inst,
119 int aff_lvl)
120{
121 unsigned long aff_shift;
122
123 assert(aff_lvl <= MPIDR_AFFLVL3);
124
125 /*
126 * Decide the number of bits to shift by depending upon
127 * the affinity level
128 */
129 aff_shift = get_afflvl_shift(aff_lvl);
130
131 /* Clear the existing affinity instance & set the new one*/
132 mpidr &= ~(MPIDR_AFFLVL_MASK << aff_shift);
133 mpidr |= aff_inst << aff_shift;
134
135 return mpidr;
136}
137
138/*******************************************************************************
Achin Gupta0959db52013-12-02 17:33:04 +0000139 * This function sanity checks a range of affinity levels.
140 ******************************************************************************/
141int psci_check_afflvl_range(int start_afflvl, int end_afflvl)
142{
143 /* Sanity check the parameters passed */
144 if (end_afflvl > MPIDR_MAX_AFFLVL)
145 return PSCI_E_INVALID_PARAMS;
146
147 if (start_afflvl < MPIDR_AFFLVL0)
148 return PSCI_E_INVALID_PARAMS;
149
150 if (end_afflvl < start_afflvl)
151 return PSCI_E_INVALID_PARAMS;
152
153 return PSCI_E_SUCCESS;
154}
155
156/*******************************************************************************
157 * This function is passed an array of pointers to affinity level nodes in the
Achin Guptacab78e42014-07-28 00:09:01 +0100158 * topology tree for an mpidr and the state which each node should transition
159 * to. It updates the state of each node between the specified affinity levels.
160 ******************************************************************************/
161void psci_do_afflvl_state_mgmt(uint32_t start_afflvl,
162 uint32_t end_afflvl,
163 mpidr_aff_map_nodes_t mpidr_nodes,
164 uint32_t state)
165{
166 uint32_t level;
167
168 for (level = start_afflvl; level <= end_afflvl; level++) {
169 if (mpidr_nodes[level] == NULL)
170 continue;
171 psci_set_state(mpidr_nodes[level], state);
172 }
173}
174
175/*******************************************************************************
176 * This function is passed an array of pointers to affinity level nodes in the
Achin Gupta0959db52013-12-02 17:33:04 +0000177 * topology tree for an mpidr. It picks up locks for each affinity level bottom
178 * up in the range specified.
179 ******************************************************************************/
Andrew Thoelke2bc07852014-06-09 12:44:21 +0100180void psci_acquire_afflvl_locks(int start_afflvl,
Achin Gupta0959db52013-12-02 17:33:04 +0000181 int end_afflvl,
Dan Handleye2712bc2014-04-10 15:37:22 +0100182 mpidr_aff_map_nodes_t mpidr_nodes)
Achin Gupta0959db52013-12-02 17:33:04 +0000183{
184 int level;
185
186 for (level = start_afflvl; level <= end_afflvl; level++) {
187 if (mpidr_nodes[level] == NULL)
188 continue;
Andrew Thoelke958cc022014-06-09 12:54:15 +0100189 bakery_lock_get(&mpidr_nodes[level]->lock);
Achin Gupta0959db52013-12-02 17:33:04 +0000190 }
191}
192
193/*******************************************************************************
194 * This function is passed an array of pointers to affinity level nodes in the
195 * topology tree for an mpidr. It releases the lock for each affinity level top
196 * down in the range specified.
197 ******************************************************************************/
Andrew Thoelke2bc07852014-06-09 12:44:21 +0100198void psci_release_afflvl_locks(int start_afflvl,
Achin Gupta0959db52013-12-02 17:33:04 +0000199 int end_afflvl,
Dan Handleye2712bc2014-04-10 15:37:22 +0100200 mpidr_aff_map_nodes_t mpidr_nodes)
Achin Gupta0959db52013-12-02 17:33:04 +0000201{
202 int level;
203
204 for (level = end_afflvl; level >= start_afflvl; level--) {
205 if (mpidr_nodes[level] == NULL)
206 continue;
Andrew Thoelke958cc022014-06-09 12:54:15 +0100207 bakery_lock_release(&mpidr_nodes[level]->lock);
Achin Gupta0959db52013-12-02 17:33:04 +0000208 }
209}
210
211/*******************************************************************************
Achin Gupta4f6ad662013-10-25 09:08:21 +0100212 * Simple routine to determine whether an affinity instance at a given level
213 * in an mpidr exists or not.
214 ******************************************************************************/
215int psci_validate_mpidr(unsigned long mpidr, int level)
216{
Dan Handleye2712bc2014-04-10 15:37:22 +0100217 aff_map_node_t *node;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100218
219 node = psci_get_aff_map_node(mpidr, level);
220 if (node && (node->state & PSCI_AFF_PRESENT))
221 return PSCI_E_SUCCESS;
222 else
223 return PSCI_E_INVALID_PARAMS;
224}
225
226/*******************************************************************************
Andrew Thoelke4e126072014-06-04 21:10:52 +0100227 * This function determines the full entrypoint information for the requested
228 * PSCI entrypoint on power on/resume and saves this in the non-secure CPU
229 * cpu_context, ready for when the core boots.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100230 ******************************************************************************/
Andrew Thoelke4e126072014-06-04 21:10:52 +0100231int psci_save_ns_entry(uint64_t mpidr,
232 uint64_t entrypoint, uint64_t context_id,
233 uint32_t ns_scr_el3, uint32_t ns_sctlr_el1)
Achin Gupta4f6ad662013-10-25 09:08:21 +0100234{
Andrew Thoelke4e126072014-06-04 21:10:52 +0100235 uint32_t ep_attr, mode, sctlr, daif, ee;
236 entry_point_info_t ep;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100237
Andrew Thoelke4e126072014-06-04 21:10:52 +0100238 sctlr = ns_scr_el3 & SCR_HCE_BIT ? read_sctlr_el2() : ns_sctlr_el1;
239 ee = 0;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100240
Andrew Thoelke4e126072014-06-04 21:10:52 +0100241 ep_attr = NON_SECURE | EP_ST_DISABLE;
242 if (sctlr & SCTLR_EE_BIT) {
243 ep_attr |= EP_EE_BIG;
244 ee = 1;
245 }
246 SET_PARAM_HEAD(&ep, PARAM_EP, VERSION_1, ep_attr);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100247
Andrew Thoelke4e126072014-06-04 21:10:52 +0100248 ep.pc = entrypoint;
249 memset(&ep.args, 0, sizeof(ep.args));
250 ep.args.arg0 = context_id;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100251
252 /*
253 * Figure out whether the cpu enters the non-secure address space
254 * in aarch32 or aarch64
255 */
Andrew Thoelke4e126072014-06-04 21:10:52 +0100256 if (ns_scr_el3 & SCR_RW_BIT) {
Achin Gupta4f6ad662013-10-25 09:08:21 +0100257
258 /*
259 * Check whether a Thumb entry point has been provided for an
260 * aarch64 EL
261 */
262 if (entrypoint & 0x1)
263 return PSCI_E_INVALID_PARAMS;
264
Andrew Thoelke4e126072014-06-04 21:10:52 +0100265 mode = ns_scr_el3 & SCR_HCE_BIT ? MODE_EL2 : MODE_EL1;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100266
Andrew Thoelke4e126072014-06-04 21:10:52 +0100267 ep.spsr = SPSR_64(mode, MODE_SP_ELX, DISABLE_ALL_EXCEPTIONS);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100268 } else {
269
Andrew Thoelke4e126072014-06-04 21:10:52 +0100270 mode = ns_scr_el3 & SCR_HCE_BIT ? MODE32_hyp : MODE32_svc;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100271
272 /*
273 * TODO: Choose async. exception bits if HYP mode is not
274 * implemented according to the values of SCR.{AW, FW} bits
275 */
Vikram Kanigiri9851e422014-05-13 14:42:08 +0100276 daif = DAIF_ABT_BIT | DAIF_IRQ_BIT | DAIF_FIQ_BIT;
277
Andrew Thoelke4e126072014-06-04 21:10:52 +0100278 ep.spsr = SPSR_MODE32(mode, entrypoint & 0x1, ee, daif);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100279 }
280
Andrew Thoelke4e126072014-06-04 21:10:52 +0100281 /* initialise an entrypoint to set up the CPU context */
282 cm_init_context(mpidr, &ep);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100283
Andrew Thoelke4e126072014-06-04 21:10:52 +0100284 return PSCI_E_SUCCESS;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100285}
286
287/*******************************************************************************
Achin Gupta75f73672013-12-05 16:33:10 +0000288 * This function takes a pointer to an affinity node in the topology tree and
289 * returns its state. State of a non-leaf node needs to be calculated.
290 ******************************************************************************/
Dan Handleye2712bc2014-04-10 15:37:22 +0100291unsigned short psci_get_state(aff_map_node_t *node)
Achin Gupta75f73672013-12-05 16:33:10 +0000292{
293 assert(node->level >= MPIDR_AFFLVL0 && node->level <= MPIDR_MAX_AFFLVL);
294
295 /* A cpu node just contains the state which can be directly returned */
296 if (node->level == MPIDR_AFFLVL0)
297 return (node->state >> PSCI_STATE_SHIFT) & PSCI_STATE_MASK;
298
299 /*
300 * For an affinity level higher than a cpu, the state has to be
301 * calculated. It depends upon the value of the reference count
302 * which is managed by each node at the next lower affinity level
303 * e.g. for a cluster, each cpu increments/decrements the reference
304 * count. If the reference count is 0 then the affinity level is
305 * OFF else ON.
306 */
307 if (node->ref_count)
308 return PSCI_STATE_ON;
309 else
310 return PSCI_STATE_OFF;
311}
312
313/*******************************************************************************
314 * This function takes a pointer to an affinity node in the topology tree and
315 * a target state. State of a non-leaf node needs to be converted to a reference
316 * count. State of a leaf node can be set directly.
317 ******************************************************************************/
Dan Handleye2712bc2014-04-10 15:37:22 +0100318void psci_set_state(aff_map_node_t *node, unsigned short state)
Achin Gupta75f73672013-12-05 16:33:10 +0000319{
320 assert(node->level >= MPIDR_AFFLVL0 && node->level <= MPIDR_MAX_AFFLVL);
321
322 /*
323 * For an affinity level higher than a cpu, the state is used
324 * to decide whether the reference count is incremented or
325 * decremented. Entry into the ON_PENDING state does not have
326 * effect.
327 */
328 if (node->level > MPIDR_AFFLVL0) {
329 switch (state) {
330 case PSCI_STATE_ON:
331 node->ref_count++;
332 break;
333 case PSCI_STATE_OFF:
334 case PSCI_STATE_SUSPEND:
335 node->ref_count--;
336 break;
337 case PSCI_STATE_ON_PENDING:
338 /*
339 * An affinity level higher than a cpu will not undergo
340 * a state change when it is about to be turned on
341 */
342 return;
343 default:
344 assert(0);
345 }
346 } else {
347 node->state &= ~(PSCI_STATE_MASK << PSCI_STATE_SHIFT);
348 node->state |= (state & PSCI_STATE_MASK) << PSCI_STATE_SHIFT;
349 }
350}
351
352/*******************************************************************************
Achin Gupta4f6ad662013-10-25 09:08:21 +0100353 * An affinity level could be on, on_pending, suspended or off. These are the
Achin Gupta3140a9e2013-12-02 16:23:12 +0000354 * logical states it can be in. Physically either it is off or on. When it is in
355 * the state on_pending then it is about to be turned on. It is not possible to
Achin Gupta4f6ad662013-10-25 09:08:21 +0100356 * tell whether that's actually happenned or not. So we err on the side of
357 * caution & treat the affinity level as being turned off.
358 ******************************************************************************/
Dan Handleye2712bc2014-04-10 15:37:22 +0100359unsigned short psci_get_phys_state(aff_map_node_t *node)
Achin Gupta4f6ad662013-10-25 09:08:21 +0100360{
Achin Gupta75f73672013-12-05 16:33:10 +0000361 unsigned int state;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100362
Achin Gupta75f73672013-12-05 16:33:10 +0000363 state = psci_get_state(node);
364 return get_phys_state(state);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100365}
366
367/*******************************************************************************
Achin Gupta0959db52013-12-02 17:33:04 +0000368 * This function takes an array of pointers to affinity instance nodes in the
369 * topology tree and calls the physical power on handler for the corresponding
370 * affinity levels
371 ******************************************************************************/
Dan Handleye2712bc2014-04-10 15:37:22 +0100372static int psci_call_power_on_handlers(mpidr_aff_map_nodes_t mpidr_nodes,
Achin Gupta0959db52013-12-02 17:33:04 +0000373 int start_afflvl,
374 int end_afflvl,
Andrew Thoelke2bc07852014-06-09 12:44:21 +0100375 afflvl_power_on_finisher_t *pon_handlers)
Achin Gupta0959db52013-12-02 17:33:04 +0000376{
377 int rc = PSCI_E_INVALID_PARAMS, level;
Dan Handleye2712bc2014-04-10 15:37:22 +0100378 aff_map_node_t *node;
Achin Gupta0959db52013-12-02 17:33:04 +0000379
380 for (level = end_afflvl; level >= start_afflvl; level--) {
381 node = mpidr_nodes[level];
382 if (node == NULL)
383 continue;
384
385 /*
386 * If we run into any trouble while powering up an
387 * affinity instance, then there is no recovery path
388 * so simply return an error and let the caller take
389 * care of the situation.
390 */
Andrew Thoelke2bc07852014-06-09 12:44:21 +0100391 rc = pon_handlers[level](node);
Achin Gupta0959db52013-12-02 17:33:04 +0000392 if (rc != PSCI_E_SUCCESS)
393 break;
394 }
395
396 return rc;
397}
398
399/*******************************************************************************
Achin Gupta4f6ad662013-10-25 09:08:21 +0100400 * Generic handler which is called when a cpu is physically powered on. It
Achin Gupta0959db52013-12-02 17:33:04 +0000401 * traverses through all the affinity levels performing generic, architectural,
Achin Gupta4f6ad662013-10-25 09:08:21 +0100402 * platform setup and state management e.g. for a cluster that's been powered
403 * on, it will call the platform specific code which will enable coherency at
404 * the interconnect level. For a cpu it could mean turning on the MMU etc.
405 *
Achin Gupta0959db52013-12-02 17:33:04 +0000406 * The state of all the relevant affinity levels is changed after calling the
407 * affinity level specific handlers as their actions would depend upon the state
408 * the affinity level is exiting from.
409 *
410 * The affinity level specific handlers are called in descending order i.e. from
411 * the highest to the lowest affinity level implemented by the platform because
412 * to turn on affinity level X it is neccesary to turn on affinity level X + 1
413 * first.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100414 ******************************************************************************/
Andrew Thoelke2bc07852014-06-09 12:44:21 +0100415void psci_afflvl_power_on_finish(int start_afflvl,
Achin Gupta0959db52013-12-02 17:33:04 +0000416 int end_afflvl,
Dan Handleye2712bc2014-04-10 15:37:22 +0100417 afflvl_power_on_finisher_t *pon_handlers)
Achin Gupta4f6ad662013-10-25 09:08:21 +0100418{
Dan Handleye2712bc2014-04-10 15:37:22 +0100419 mpidr_aff_map_nodes_t mpidr_nodes;
Achin Gupta0959db52013-12-02 17:33:04 +0000420 int rc;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100421
Achin Gupta4f6ad662013-10-25 09:08:21 +0100422 /*
Achin Gupta0959db52013-12-02 17:33:04 +0000423 * Collect the pointers to the nodes in the topology tree for
424 * each affinity instance in the mpidr. If this function does
425 * not return successfully then either the mpidr or the affinity
426 * levels are incorrect. Either case is an irrecoverable error.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100427 */
Andrew Thoelke2bc07852014-06-09 12:44:21 +0100428 rc = psci_get_aff_map_nodes(read_mpidr_el1() & MPIDR_AFFINITY_MASK,
Achin Gupta0959db52013-12-02 17:33:04 +0000429 start_afflvl,
430 end_afflvl,
431 mpidr_nodes);
James Morrissey40a6f642014-02-10 14:24:36 +0000432 if (rc != PSCI_E_SUCCESS)
433 panic();
Achin Gupta4f6ad662013-10-25 09:08:21 +0100434
435 /*
Achin Gupta0959db52013-12-02 17:33:04 +0000436 * This function acquires the lock corresponding to each affinity
437 * level so that by the time all locks are taken, the system topology
438 * is snapshot and state management can be done safely.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100439 */
Andrew Thoelke2bc07852014-06-09 12:44:21 +0100440 psci_acquire_afflvl_locks(start_afflvl,
Achin Gupta0959db52013-12-02 17:33:04 +0000441 end_afflvl,
442 mpidr_nodes);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100443
444 /* Perform generic, architecture and platform specific handling */
Achin Gupta0959db52013-12-02 17:33:04 +0000445 rc = psci_call_power_on_handlers(mpidr_nodes,
446 start_afflvl,
447 end_afflvl,
Andrew Thoelke2bc07852014-06-09 12:44:21 +0100448 pon_handlers);
James Morrissey40a6f642014-02-10 14:24:36 +0000449 if (rc != PSCI_E_SUCCESS)
450 panic();
Achin Gupta4f6ad662013-10-25 09:08:21 +0100451
452 /*
Achin Guptacab78e42014-07-28 00:09:01 +0100453 * This function updates the state of each affinity instance
454 * corresponding to the mpidr in the range of affinity levels
455 * specified.
456 */
457 psci_do_afflvl_state_mgmt(start_afflvl,
458 end_afflvl,
459 mpidr_nodes,
460 PSCI_STATE_ON);
461
462 /*
Achin Gupta0959db52013-12-02 17:33:04 +0000463 * This loop releases the lock corresponding to each affinity level
464 * in the reverse order to which they were acquired.
465 */
Andrew Thoelke2bc07852014-06-09 12:44:21 +0100466 psci_release_afflvl_locks(start_afflvl,
Achin Gupta0959db52013-12-02 17:33:04 +0000467 end_afflvl,
468 mpidr_nodes);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100469}
Jeenu Viswambharan7f366602014-02-20 17:11:00 +0000470
471/*******************************************************************************
472 * This function initializes the set of hooks that PSCI invokes as part of power
473 * management operation. The power management hooks are expected to be provided
474 * by the SPD, after it finishes all its initialization
475 ******************************************************************************/
Dan Handleye2712bc2014-04-10 15:37:22 +0100476void psci_register_spd_pm_hook(const spd_pm_ops_t *pm)
Jeenu Viswambharan7f366602014-02-20 17:11:00 +0000477{
478 psci_spd_pm = pm;
479}
Juan Castillo4dc4a472014-08-12 11:17:06 +0100480
481/*******************************************************************************
482 * This function prints the state of all affinity instances present in the
483 * system
484 ******************************************************************************/
485void psci_print_affinity_map(void)
486{
487#if LOG_LEVEL >= LOG_LEVEL_INFO
488 aff_map_node_t *node;
489 unsigned int idx;
490 /* This array maps to the PSCI_STATE_X definitions in psci.h */
491 static const char *psci_state_str[] = {
492 "ON",
493 "OFF",
494 "ON_PENDING",
495 "SUSPEND"
496 };
497
498 INFO("PSCI Affinity Map:\n");
499 for (idx = 0; idx < PSCI_NUM_AFFS ; idx++) {
500 node = &psci_aff_map[idx];
501 if (!(node->state & PSCI_AFF_PRESENT)) {
502 continue;
503 }
504 INFO(" AffInst: Level %u, MPID 0x%lx, State %s\n",
505 node->level, node->mpidr,
506 psci_state_str[psci_get_state(node)]);
507 }
508#endif
509}