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