Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1 | /* |
Dan Handley | e83b0ca | 2014-01-14 18:17:09 +0000 | [diff] [blame] | 2 | * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 3 | * |
| 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> |
Dan Handley | 5b827a8 | 2014-04-17 18:53:42 +0100 | [diff] [blame^] | 32 | #include <stdint.h> |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 33 | #include <string.h> |
| 34 | #include <assert.h> |
Dan Handley | 5b827a8 | 2014-04-17 18:53:42 +0100 | [diff] [blame^] | 35 | #include <bl31.h> |
Achin Gupta | 0a9f747 | 2014-02-09 17:48:12 +0000 | [diff] [blame] | 36 | #include <debug.h> |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 37 | #include <arch_helpers.h> |
| 38 | #include <console.h> |
| 39 | #include <platform.h> |
| 40 | #include <psci.h> |
Achin Gupta | 0a9f747 | 2014-02-09 17:48:12 +0000 | [diff] [blame] | 41 | #include <context_mgmt.h> |
Dan Handley | 5b827a8 | 2014-04-17 18:53:42 +0100 | [diff] [blame^] | 42 | #include <runtime_svc.h> |
Dan Handley | 35e98e5 | 2014-04-09 13:13:04 +0100 | [diff] [blame] | 43 | #include "psci_private.h" |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 44 | |
| 45 | typedef int (*afflvl_on_handler)(unsigned long, |
| 46 | aff_map_node *, |
| 47 | unsigned long, |
| 48 | unsigned long); |
| 49 | |
| 50 | /******************************************************************************* |
| 51 | * This function checks whether a cpu which has been requested to be turned on |
| 52 | * is OFF to begin with. |
| 53 | ******************************************************************************/ |
Achin Gupta | 75f7367 | 2013-12-05 16:33:10 +0000 | [diff] [blame] | 54 | static int cpu_on_validate_state(aff_map_node *node) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 55 | { |
| 56 | unsigned int psci_state; |
| 57 | |
| 58 | /* Get the raw psci state */ |
Achin Gupta | 75f7367 | 2013-12-05 16:33:10 +0000 | [diff] [blame] | 59 | psci_state = psci_get_state(node); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 60 | |
| 61 | if (psci_state == PSCI_STATE_ON || psci_state == PSCI_STATE_SUSPEND) |
| 62 | return PSCI_E_ALREADY_ON; |
| 63 | |
| 64 | if (psci_state == PSCI_STATE_ON_PENDING) |
| 65 | return PSCI_E_ON_PENDING; |
| 66 | |
| 67 | assert(psci_state == PSCI_STATE_OFF); |
| 68 | return PSCI_E_SUCCESS; |
| 69 | } |
| 70 | |
| 71 | /******************************************************************************* |
| 72 | * Handler routine to turn a cpu on. It takes care of any generic, architectural |
| 73 | * or platform specific setup required. |
| 74 | * TODO: Split this code across separate handlers for each type of setup? |
| 75 | ******************************************************************************/ |
| 76 | static int psci_afflvl0_on(unsigned long target_cpu, |
| 77 | aff_map_node *cpu_node, |
| 78 | unsigned long ns_entrypoint, |
| 79 | unsigned long context_id) |
| 80 | { |
| 81 | unsigned int index, plat_state; |
| 82 | unsigned long psci_entrypoint; |
| 83 | int rc; |
| 84 | |
| 85 | /* Sanity check to safeguard against data corruption */ |
| 86 | assert(cpu_node->level == MPIDR_AFFLVL0); |
| 87 | |
| 88 | /* |
| 89 | * Generic management: Ensure that the cpu is off to be |
| 90 | * turned on |
| 91 | */ |
Achin Gupta | 75f7367 | 2013-12-05 16:33:10 +0000 | [diff] [blame] | 92 | rc = cpu_on_validate_state(cpu_node); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 93 | if (rc != PSCI_E_SUCCESS) |
| 94 | return rc; |
| 95 | |
| 96 | /* |
Achin Gupta | 607084e | 2014-02-09 18:24:19 +0000 | [diff] [blame] | 97 | * Call the cpu on handler registered by the Secure Payload Dispatcher |
| 98 | * to let it do any bookeeping. If the handler encounters an error, it's |
| 99 | * expected to assert within |
| 100 | */ |
Jeenu Viswambharan | 7f36660 | 2014-02-20 17:11:00 +0000 | [diff] [blame] | 101 | if (psci_spd_pm && psci_spd_pm->svc_on) |
| 102 | psci_spd_pm->svc_on(target_cpu); |
Achin Gupta | 607084e | 2014-02-09 18:24:19 +0000 | [diff] [blame] | 103 | |
| 104 | /* |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 105 | * Arch. management: Derive the re-entry information for |
| 106 | * the non-secure world from the non-secure state from |
| 107 | * where this call originated. |
| 108 | */ |
| 109 | index = cpu_node->data; |
| 110 | rc = psci_set_ns_entry_info(index, ns_entrypoint, context_id); |
| 111 | if (rc != PSCI_E_SUCCESS) |
| 112 | return rc; |
| 113 | |
| 114 | /* Set the secure world (EL3) re-entry point after BL1 */ |
| 115 | psci_entrypoint = (unsigned long) psci_aff_on_finish_entry; |
| 116 | |
Achin Gupta | 75f7367 | 2013-12-05 16:33:10 +0000 | [diff] [blame] | 117 | /* State management: Set this cpu's state as ON PENDING */ |
| 118 | psci_set_state(cpu_node, PSCI_STATE_ON_PENDING); |
| 119 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 120 | /* |
| 121 | * Plat. management: Give the platform the current state |
| 122 | * of the target cpu to allow it to perform the necessary |
| 123 | * steps to power on. |
| 124 | */ |
| 125 | if (psci_plat_pm_ops->affinst_on) { |
| 126 | |
| 127 | /* Get the current physical state of this cpu */ |
Achin Gupta | 75f7367 | 2013-12-05 16:33:10 +0000 | [diff] [blame] | 128 | plat_state = psci_get_phys_state(cpu_node); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 129 | rc = psci_plat_pm_ops->affinst_on(target_cpu, |
| 130 | psci_entrypoint, |
| 131 | ns_entrypoint, |
| 132 | cpu_node->level, |
| 133 | plat_state); |
| 134 | } |
| 135 | |
| 136 | return rc; |
| 137 | } |
| 138 | |
| 139 | /******************************************************************************* |
| 140 | * Handler routine to turn a cluster on. It takes care or any generic, arch. |
| 141 | * or platform specific setup required. |
| 142 | * TODO: Split this code across separate handlers for each type of setup? |
| 143 | ******************************************************************************/ |
| 144 | static int psci_afflvl1_on(unsigned long target_cpu, |
| 145 | aff_map_node *cluster_node, |
| 146 | unsigned long ns_entrypoint, |
| 147 | unsigned long context_id) |
| 148 | { |
| 149 | int rc = PSCI_E_SUCCESS; |
| 150 | unsigned int plat_state; |
| 151 | unsigned long psci_entrypoint; |
| 152 | |
| 153 | assert(cluster_node->level == MPIDR_AFFLVL1); |
| 154 | |
| 155 | /* |
| 156 | * There is no generic and arch. specific cluster |
| 157 | * management required |
| 158 | */ |
| 159 | |
Achin Gupta | 75f7367 | 2013-12-05 16:33:10 +0000 | [diff] [blame] | 160 | /* State management: Is not required while turning a cluster on */ |
| 161 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 162 | /* |
| 163 | * Plat. management: Give the platform the current state |
| 164 | * of the target cpu to allow it to perform the necessary |
| 165 | * steps to power on. |
| 166 | */ |
| 167 | if (psci_plat_pm_ops->affinst_on) { |
Achin Gupta | 75f7367 | 2013-12-05 16:33:10 +0000 | [diff] [blame] | 168 | plat_state = psci_get_phys_state(cluster_node); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 169 | psci_entrypoint = (unsigned long) psci_aff_on_finish_entry; |
| 170 | rc = psci_plat_pm_ops->affinst_on(target_cpu, |
| 171 | psci_entrypoint, |
| 172 | ns_entrypoint, |
| 173 | cluster_node->level, |
| 174 | plat_state); |
| 175 | } |
| 176 | |
| 177 | return rc; |
| 178 | } |
| 179 | |
| 180 | /******************************************************************************* |
| 181 | * Handler routine to turn a cluster of clusters on. It takes care or any |
| 182 | * generic, arch. or platform specific setup required. |
| 183 | * TODO: Split this code across separate handlers for each type of setup? |
| 184 | ******************************************************************************/ |
| 185 | static int psci_afflvl2_on(unsigned long target_cpu, |
| 186 | aff_map_node *system_node, |
| 187 | unsigned long ns_entrypoint, |
| 188 | unsigned long context_id) |
| 189 | { |
| 190 | int rc = PSCI_E_SUCCESS; |
| 191 | unsigned int plat_state; |
| 192 | unsigned long psci_entrypoint; |
| 193 | |
| 194 | /* Cannot go beyond affinity level 2 in this psci imp. */ |
| 195 | assert(system_node->level == MPIDR_AFFLVL2); |
| 196 | |
| 197 | /* |
| 198 | * There is no generic and arch. specific system management |
| 199 | * required |
| 200 | */ |
| 201 | |
Achin Gupta | 75f7367 | 2013-12-05 16:33:10 +0000 | [diff] [blame] | 202 | /* State management: Is not required while turning a system on */ |
| 203 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 204 | /* |
| 205 | * Plat. management: Give the platform the current state |
| 206 | * of the target cpu to allow it to perform the necessary |
| 207 | * steps to power on. |
| 208 | */ |
| 209 | if (psci_plat_pm_ops->affinst_on) { |
Achin Gupta | 75f7367 | 2013-12-05 16:33:10 +0000 | [diff] [blame] | 210 | plat_state = psci_get_phys_state(system_node); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 211 | psci_entrypoint = (unsigned long) psci_aff_on_finish_entry; |
| 212 | rc = psci_plat_pm_ops->affinst_on(target_cpu, |
| 213 | psci_entrypoint, |
| 214 | ns_entrypoint, |
| 215 | system_node->level, |
| 216 | plat_state); |
| 217 | } |
| 218 | |
| 219 | return rc; |
| 220 | } |
| 221 | |
| 222 | /* Private data structure to make this handlers accessible through indexing */ |
| 223 | static const afflvl_on_handler psci_afflvl_on_handlers[] = { |
| 224 | psci_afflvl0_on, |
| 225 | psci_afflvl1_on, |
| 226 | psci_afflvl2_on, |
| 227 | }; |
| 228 | |
| 229 | /******************************************************************************* |
Achin Gupta | 0959db5 | 2013-12-02 17:33:04 +0000 | [diff] [blame] | 230 | * This function takes an array of pointers to affinity instance nodes in the |
| 231 | * topology tree and calls the on handler for the corresponding affinity |
| 232 | * levels |
| 233 | ******************************************************************************/ |
| 234 | static int psci_call_on_handlers(mpidr_aff_map_nodes target_cpu_nodes, |
| 235 | int start_afflvl, |
| 236 | int end_afflvl, |
| 237 | unsigned long target_cpu, |
| 238 | unsigned long entrypoint, |
| 239 | unsigned long context_id) |
| 240 | { |
| 241 | int rc = PSCI_E_INVALID_PARAMS, level; |
| 242 | aff_map_node *node; |
| 243 | |
| 244 | for (level = end_afflvl; level >= start_afflvl; level--) { |
| 245 | node = target_cpu_nodes[level]; |
| 246 | if (node == NULL) |
| 247 | continue; |
| 248 | |
| 249 | /* |
| 250 | * TODO: In case of an error should there be a way |
| 251 | * of undoing what we might have setup at higher |
| 252 | * affinity levels. |
| 253 | */ |
| 254 | rc = psci_afflvl_on_handlers[level](target_cpu, |
| 255 | node, |
| 256 | entrypoint, |
| 257 | context_id); |
| 258 | if (rc != PSCI_E_SUCCESS) |
| 259 | break; |
| 260 | } |
| 261 | |
| 262 | return rc; |
| 263 | } |
| 264 | |
| 265 | /******************************************************************************* |
| 266 | * Generic handler which is called to physically power on a cpu identified by |
| 267 | * its mpidr. It traverses through all the affinity levels performing generic, |
| 268 | * architectural, platform setup and state management e.g. for a cpu that is |
| 269 | * to be powered on, it will ensure that enough information is stashed for it |
| 270 | * to resume execution in the non-secure security state. |
| 271 | * |
| 272 | * The state of all the relevant affinity levels is changed after calling the |
| 273 | * affinity level specific handlers as their actions would depend upon the state |
| 274 | * the affinity level is currently in. |
| 275 | * |
| 276 | * The affinity level specific handlers are called in descending order i.e. from |
| 277 | * the highest to the lowest affinity level implemented by the platform because |
| 278 | * to turn on affinity level X it is neccesary to turn on affinity level X + 1 |
| 279 | * first. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 280 | ******************************************************************************/ |
| 281 | int psci_afflvl_on(unsigned long target_cpu, |
| 282 | unsigned long entrypoint, |
| 283 | unsigned long context_id, |
Achin Gupta | 0959db5 | 2013-12-02 17:33:04 +0000 | [diff] [blame] | 284 | int start_afflvl, |
| 285 | int end_afflvl) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 286 | { |
Achin Gupta | 0959db5 | 2013-12-02 17:33:04 +0000 | [diff] [blame] | 287 | int rc = PSCI_E_SUCCESS; |
| 288 | mpidr_aff_map_nodes target_cpu_nodes; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 289 | unsigned long mpidr = read_mpidr() & MPIDR_AFFINITY_MASK; |
| 290 | |
| 291 | /* |
Achin Gupta | 0959db5 | 2013-12-02 17:33:04 +0000 | [diff] [blame] | 292 | * Collect the pointers to the nodes in the topology tree for |
| 293 | * each affinity instance in the mpidr. If this function does |
| 294 | * not return successfully then either the mpidr or the affinity |
| 295 | * levels are incorrect. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 296 | */ |
Achin Gupta | 0959db5 | 2013-12-02 17:33:04 +0000 | [diff] [blame] | 297 | rc = psci_get_aff_map_nodes(target_cpu, |
| 298 | start_afflvl, |
| 299 | end_afflvl, |
| 300 | target_cpu_nodes); |
| 301 | if (rc != PSCI_E_SUCCESS) |
| 302 | return rc; |
| 303 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 304 | |
| 305 | /* |
Achin Gupta | 0959db5 | 2013-12-02 17:33:04 +0000 | [diff] [blame] | 306 | * This function acquires the lock corresponding to each affinity |
| 307 | * level so that by the time all locks are taken, the system topology |
| 308 | * is snapshot and state management can be done safely. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 309 | */ |
Achin Gupta | 0959db5 | 2013-12-02 17:33:04 +0000 | [diff] [blame] | 310 | psci_acquire_afflvl_locks(mpidr, |
| 311 | start_afflvl, |
| 312 | end_afflvl, |
| 313 | target_cpu_nodes); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 314 | |
Achin Gupta | 0959db5 | 2013-12-02 17:33:04 +0000 | [diff] [blame] | 315 | /* Perform generic, architecture and platform specific handling. */ |
| 316 | rc = psci_call_on_handlers(target_cpu_nodes, |
| 317 | start_afflvl, |
| 318 | end_afflvl, |
| 319 | target_cpu, |
| 320 | entrypoint, |
| 321 | context_id); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 322 | |
| 323 | /* |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 324 | * This loop releases the lock corresponding to each affinity level |
Achin Gupta | 0959db5 | 2013-12-02 17:33:04 +0000 | [diff] [blame] | 325 | * in the reverse order to which they were acquired. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 326 | */ |
Achin Gupta | 0959db5 | 2013-12-02 17:33:04 +0000 | [diff] [blame] | 327 | psci_release_afflvl_locks(mpidr, |
| 328 | start_afflvl, |
| 329 | end_afflvl, |
| 330 | target_cpu_nodes); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 331 | |
| 332 | return rc; |
| 333 | } |
| 334 | |
| 335 | /******************************************************************************* |
| 336 | * The following functions finish an earlier affinity power on request. They |
| 337 | * are called by the common finisher routine in psci_common.c. |
| 338 | ******************************************************************************/ |
| 339 | static unsigned int psci_afflvl0_on_finish(unsigned long mpidr, |
Achin Gupta | 0959db5 | 2013-12-02 17:33:04 +0000 | [diff] [blame] | 340 | aff_map_node *cpu_node) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 341 | { |
Achin Gupta | 0959db5 | 2013-12-02 17:33:04 +0000 | [diff] [blame] | 342 | unsigned int index, plat_state, state, rc = PSCI_E_SUCCESS; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 343 | |
| 344 | assert(cpu_node->level == MPIDR_AFFLVL0); |
| 345 | |
Achin Gupta | 0959db5 | 2013-12-02 17:33:04 +0000 | [diff] [blame] | 346 | /* Ensure we have been explicitly woken up by another cpu */ |
Achin Gupta | 75f7367 | 2013-12-05 16:33:10 +0000 | [diff] [blame] | 347 | state = psci_get_state(cpu_node); |
Achin Gupta | 0959db5 | 2013-12-02 17:33:04 +0000 | [diff] [blame] | 348 | assert(state == PSCI_STATE_ON_PENDING); |
| 349 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 350 | /* |
| 351 | * Plat. management: Perform the platform specific actions |
| 352 | * for this cpu e.g. enabling the gic or zeroing the mailbox |
| 353 | * register. The actual state of this cpu has already been |
| 354 | * changed. |
| 355 | */ |
| 356 | if (psci_plat_pm_ops->affinst_on_finish) { |
| 357 | |
Achin Gupta | 0959db5 | 2013-12-02 17:33:04 +0000 | [diff] [blame] | 358 | /* Get the physical state of this cpu */ |
Achin Gupta | 75f7367 | 2013-12-05 16:33:10 +0000 | [diff] [blame] | 359 | plat_state = get_phys_state(state); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 360 | rc = psci_plat_pm_ops->affinst_on_finish(mpidr, |
| 361 | cpu_node->level, |
| 362 | plat_state); |
| 363 | assert(rc == PSCI_E_SUCCESS); |
| 364 | } |
| 365 | |
| 366 | /* |
| 367 | * Arch. management: Turn on mmu & restore architectural state |
| 368 | */ |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 369 | enable_mmu(); |
| 370 | |
| 371 | /* |
| 372 | * All the platform specific actions for turning this cpu |
| 373 | * on have completed. Perform enough arch.initialization |
| 374 | * to run in the non-secure address space. |
| 375 | */ |
| 376 | bl31_arch_setup(); |
| 377 | |
| 378 | /* |
Achin Gupta | 607084e | 2014-02-09 18:24:19 +0000 | [diff] [blame] | 379 | * Use the more complex exception vectors to enable SPD |
| 380 | * initialisation. SP_EL3 should point to a 'cpu_context' |
| 381 | * structure which has an exception stack allocated. The |
| 382 | * calling cpu should have set the context already |
| 383 | */ |
| 384 | assert(cm_get_context(mpidr, NON_SECURE)); |
| 385 | cm_set_next_eret_context(NON_SECURE); |
| 386 | write_vbar_el3((uint64_t) runtime_exceptions); |
| 387 | |
| 388 | /* |
| 389 | * Call the cpu on finish handler registered by the Secure Payload |
| 390 | * Dispatcher to let it do any bookeeping. If the handler encounters an |
| 391 | * error, it's expected to assert within |
| 392 | */ |
Jeenu Viswambharan | 7f36660 | 2014-02-20 17:11:00 +0000 | [diff] [blame] | 393 | if (psci_spd_pm && psci_spd_pm->svc_on_finish) |
| 394 | psci_spd_pm->svc_on_finish(0); |
Achin Gupta | 607084e | 2014-02-09 18:24:19 +0000 | [diff] [blame] | 395 | |
| 396 | /* |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 397 | * Generic management: Now we just need to retrieve the |
| 398 | * information that we had stashed away during the cpu_on |
Achin Gupta | 3140a9e | 2013-12-02 16:23:12 +0000 | [diff] [blame] | 399 | * call to set this cpu on its way. First get the index |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 400 | * for restoring the re-entry info |
| 401 | */ |
| 402 | index = cpu_node->data; |
Achin Gupta | c8afc78 | 2013-11-25 18:45:02 +0000 | [diff] [blame] | 403 | psci_get_ns_entry_info(index); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 404 | |
Achin Gupta | 75f7367 | 2013-12-05 16:33:10 +0000 | [diff] [blame] | 405 | /* State management: mark this cpu as on */ |
| 406 | psci_set_state(cpu_node, PSCI_STATE_ON); |
| 407 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 408 | /* Clean caches before re-entering normal world */ |
| 409 | dcsw_op_louis(DCCSW); |
| 410 | |
| 411 | return rc; |
| 412 | } |
| 413 | |
| 414 | static unsigned int psci_afflvl1_on_finish(unsigned long mpidr, |
Achin Gupta | 0959db5 | 2013-12-02 17:33:04 +0000 | [diff] [blame] | 415 | aff_map_node *cluster_node) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 416 | { |
Achin Gupta | 0959db5 | 2013-12-02 17:33:04 +0000 | [diff] [blame] | 417 | unsigned int plat_state, rc = PSCI_E_SUCCESS; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 418 | |
| 419 | assert(cluster_node->level == MPIDR_AFFLVL1); |
| 420 | |
| 421 | /* |
| 422 | * Plat. management: Perform the platform specific actions |
| 423 | * as per the old state of the cluster e.g. enabling |
| 424 | * coherency at the interconnect depends upon the state with |
| 425 | * which this cluster was powered up. If anything goes wrong |
| 426 | * then assert as there is no way to recover from this |
| 427 | * situation. |
| 428 | */ |
| 429 | if (psci_plat_pm_ops->affinst_on_finish) { |
Achin Gupta | 0959db5 | 2013-12-02 17:33:04 +0000 | [diff] [blame] | 430 | |
| 431 | /* Get the physical state of this cluster */ |
Achin Gupta | 75f7367 | 2013-12-05 16:33:10 +0000 | [diff] [blame] | 432 | plat_state = psci_get_phys_state(cluster_node); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 433 | rc = psci_plat_pm_ops->affinst_on_finish(mpidr, |
| 434 | cluster_node->level, |
| 435 | plat_state); |
| 436 | assert(rc == PSCI_E_SUCCESS); |
| 437 | } |
| 438 | |
Achin Gupta | 75f7367 | 2013-12-05 16:33:10 +0000 | [diff] [blame] | 439 | /* State management: Increment the cluster reference count */ |
| 440 | psci_set_state(cluster_node, PSCI_STATE_ON); |
| 441 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 442 | return rc; |
| 443 | } |
| 444 | |
| 445 | |
| 446 | static unsigned int psci_afflvl2_on_finish(unsigned long mpidr, |
Achin Gupta | 0959db5 | 2013-12-02 17:33:04 +0000 | [diff] [blame] | 447 | aff_map_node *system_node) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 448 | { |
Achin Gupta | 0959db5 | 2013-12-02 17:33:04 +0000 | [diff] [blame] | 449 | unsigned int plat_state, rc = PSCI_E_SUCCESS; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 450 | |
| 451 | /* Cannot go beyond this affinity level */ |
| 452 | assert(system_node->level == MPIDR_AFFLVL2); |
| 453 | |
| 454 | /* |
| 455 | * Currently, there are no architectural actions to perform |
| 456 | * at the system level. |
| 457 | */ |
| 458 | |
| 459 | /* |
| 460 | * Plat. management: Perform the platform specific actions |
| 461 | * as per the old state of the cluster e.g. enabling |
| 462 | * coherency at the interconnect depends upon the state with |
| 463 | * which this cluster was powered up. If anything goes wrong |
| 464 | * then assert as there is no way to recover from this |
| 465 | * situation. |
| 466 | */ |
| 467 | if (psci_plat_pm_ops->affinst_on_finish) { |
Achin Gupta | 0959db5 | 2013-12-02 17:33:04 +0000 | [diff] [blame] | 468 | |
| 469 | /* Get the physical state of the system */ |
Achin Gupta | 75f7367 | 2013-12-05 16:33:10 +0000 | [diff] [blame] | 470 | plat_state = psci_get_phys_state(system_node); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 471 | rc = psci_plat_pm_ops->affinst_on_finish(mpidr, |
| 472 | system_node->level, |
| 473 | plat_state); |
| 474 | assert(rc == PSCI_E_SUCCESS); |
| 475 | } |
| 476 | |
Achin Gupta | 75f7367 | 2013-12-05 16:33:10 +0000 | [diff] [blame] | 477 | /* State management: Increment the system reference count */ |
| 478 | psci_set_state(system_node, PSCI_STATE_ON); |
| 479 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 480 | return rc; |
| 481 | } |
| 482 | |
| 483 | const afflvl_power_on_finisher psci_afflvl_on_finishers[] = { |
| 484 | psci_afflvl0_on_finish, |
| 485 | psci_afflvl1_on_finish, |
| 486 | psci_afflvl2_on_finish, |
| 487 | }; |
| 488 | |