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