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> |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 32 | #include <arch_helpers.h> |
Dan Handley | 2bd4ef2 | 2014-04-09 13:14:54 +0100 | [diff] [blame] | 33 | #include <assert.h> |
Soby Mathew | 9616838 | 2014-12-17 14:47:57 +0000 | [diff] [blame] | 34 | #include <debug.h> |
| 35 | #include <platform.h> |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 36 | #include <runtime_svc.h> |
Soby Mathew | 6cdddaf | 2015-01-07 11:10:22 +0000 | [diff] [blame] | 37 | #include <std_svc.h> |
Dan Handley | 714a0d2 | 2014-04-09 13:13:04 +0100 | [diff] [blame] | 38 | #include "psci_private.h" |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 39 | |
| 40 | /******************************************************************************* |
| 41 | * PSCI frontend api for servicing SMCs. Described in the PSCI spec. |
| 42 | ******************************************************************************/ |
| 43 | int psci_cpu_on(unsigned long target_cpu, |
| 44 | unsigned long entrypoint, |
| 45 | unsigned long context_id) |
| 46 | |
| 47 | { |
| 48 | int rc; |
Achin Gupta | 0959db5 | 2013-12-02 17:33:04 +0000 | [diff] [blame] | 49 | unsigned int start_afflvl, end_afflvl; |
Soby Mathew | 8595b87 | 2015-01-06 15:36:38 +0000 | [diff] [blame] | 50 | entry_point_info_t ep; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 51 | |
| 52 | /* Determine if the cpu exists of not */ |
| 53 | rc = psci_validate_mpidr(target_cpu, MPIDR_AFFLVL0); |
| 54 | if (rc != PSCI_E_SUCCESS) { |
Soby Mathew | 74e52a7 | 2014-10-02 16:56:51 +0100 | [diff] [blame] | 55 | return PSCI_E_INVALID_PARAMS; |
| 56 | } |
| 57 | |
| 58 | /* Validate the entrypoint using platform pm_ops */ |
| 59 | if (psci_plat_pm_ops->validate_ns_entrypoint) { |
| 60 | rc = psci_plat_pm_ops->validate_ns_entrypoint(entrypoint); |
| 61 | if (rc != PSCI_E_SUCCESS) { |
| 62 | assert(rc == PSCI_E_INVALID_PARAMS); |
| 63 | return PSCI_E_INVALID_PARAMS; |
| 64 | } |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 65 | } |
| 66 | |
Achin Gupta | 0959db5 | 2013-12-02 17:33:04 +0000 | [diff] [blame] | 67 | /* |
Soby Mathew | 8595b87 | 2015-01-06 15:36:38 +0000 | [diff] [blame] | 68 | * Verify and derive the re-entry information for |
| 69 | * the non-secure world from the non-secure state from |
| 70 | * where this call originated. |
| 71 | */ |
| 72 | rc = psci_get_ns_ep_info(&ep, entrypoint, context_id); |
| 73 | if (rc != PSCI_E_SUCCESS) |
| 74 | return rc; |
| 75 | |
| 76 | |
| 77 | /* |
Achin Gupta | 0959db5 | 2013-12-02 17:33:04 +0000 | [diff] [blame] | 78 | * To turn this cpu on, specify which affinity |
| 79 | * levels need to be turned on |
| 80 | */ |
| 81 | start_afflvl = MPIDR_AFFLVL0; |
Soby Mathew | 2b7de2b | 2015-02-12 14:45:02 +0000 | [diff] [blame] | 82 | end_afflvl = PLATFORM_MAX_AFFLVL; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 83 | rc = psci_afflvl_on(target_cpu, |
Soby Mathew | 8595b87 | 2015-01-06 15:36:38 +0000 | [diff] [blame] | 84 | &ep, |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 85 | start_afflvl, |
Achin Gupta | 0959db5 | 2013-12-02 17:33:04 +0000 | [diff] [blame] | 86 | end_afflvl); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 87 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 88 | return rc; |
| 89 | } |
| 90 | |
| 91 | unsigned int psci_version(void) |
| 92 | { |
| 93 | return PSCI_MAJOR_VER | PSCI_MINOR_VER; |
| 94 | } |
| 95 | |
| 96 | int psci_cpu_suspend(unsigned int power_state, |
| 97 | unsigned long entrypoint, |
| 98 | unsigned long context_id) |
| 99 | { |
| 100 | int rc; |
Achin Gupta | 0959db5 | 2013-12-02 17:33:04 +0000 | [diff] [blame] | 101 | unsigned int target_afflvl, pstate_type; |
Soby Mathew | 8595b87 | 2015-01-06 15:36:38 +0000 | [diff] [blame] | 102 | entry_point_info_t ep; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 103 | |
Vikram Kanigiri | f100f41 | 2014-04-01 19:26:26 +0100 | [diff] [blame] | 104 | /* Check SBZ bits in power state are zero */ |
| 105 | if (psci_validate_power_state(power_state)) |
| 106 | return PSCI_E_INVALID_PARAMS; |
| 107 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 108 | /* Sanity check the requested state */ |
Achin Gupta | 0959db5 | 2013-12-02 17:33:04 +0000 | [diff] [blame] | 109 | target_afflvl = psci_get_pstate_afflvl(power_state); |
Soby Mathew | 2b7de2b | 2015-02-12 14:45:02 +0000 | [diff] [blame] | 110 | if (target_afflvl > PLATFORM_MAX_AFFLVL) |
Vikram Kanigiri | 3b7c59b | 2014-03-21 11:57:10 +0000 | [diff] [blame] | 111 | return PSCI_E_INVALID_PARAMS; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 112 | |
Soby Mathew | 74e52a7 | 2014-10-02 16:56:51 +0100 | [diff] [blame] | 113 | /* Validate the power_state using platform pm_ops */ |
| 114 | if (psci_plat_pm_ops->validate_power_state) { |
| 115 | rc = psci_plat_pm_ops->validate_power_state(power_state); |
| 116 | if (rc != PSCI_E_SUCCESS) { |
| 117 | assert(rc == PSCI_E_INVALID_PARAMS); |
| 118 | return PSCI_E_INVALID_PARAMS; |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | /* Validate the entrypoint using platform pm_ops */ |
| 123 | if (psci_plat_pm_ops->validate_ns_entrypoint) { |
| 124 | rc = psci_plat_pm_ops->validate_ns_entrypoint(entrypoint); |
| 125 | if (rc != PSCI_E_SUCCESS) { |
| 126 | assert(rc == PSCI_E_INVALID_PARAMS); |
| 127 | return PSCI_E_INVALID_PARAMS; |
| 128 | } |
| 129 | } |
| 130 | |
Achin Gupta | 42c5280 | 2014-05-09 19:32:25 +0100 | [diff] [blame] | 131 | /* Determine the 'state type' in the 'power_state' parameter */ |
Vikram Kanigiri | 3b7c59b | 2014-03-21 11:57:10 +0000 | [diff] [blame] | 132 | pstate_type = psci_get_pstate_type(power_state); |
Achin Gupta | 42c5280 | 2014-05-09 19:32:25 +0100 | [diff] [blame] | 133 | |
| 134 | /* |
| 135 | * Ensure that we have a platform specific handler for entering |
| 136 | * a standby state. |
| 137 | */ |
Vikram Kanigiri | 3b7c59b | 2014-03-21 11:57:10 +0000 | [diff] [blame] | 138 | if (pstate_type == PSTATE_TYPE_STANDBY) { |
Achin Gupta | 42c5280 | 2014-05-09 19:32:25 +0100 | [diff] [blame] | 139 | if (!psci_plat_pm_ops->affinst_standby) |
Vikram Kanigiri | 3b7c59b | 2014-03-21 11:57:10 +0000 | [diff] [blame] | 140 | return PSCI_E_INVALID_PARAMS; |
Achin Gupta | 42c5280 | 2014-05-09 19:32:25 +0100 | [diff] [blame] | 141 | |
Soby Mathew | 74e52a7 | 2014-10-02 16:56:51 +0100 | [diff] [blame] | 142 | psci_plat_pm_ops->affinst_standby(power_state); |
| 143 | return PSCI_E_SUCCESS; |
Vikram Kanigiri | 3b7c59b | 2014-03-21 11:57:10 +0000 | [diff] [blame] | 144 | } |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 145 | |
Achin Gupta | 42c5280 | 2014-05-09 19:32:25 +0100 | [diff] [blame] | 146 | /* |
Soby Mathew | 8595b87 | 2015-01-06 15:36:38 +0000 | [diff] [blame] | 147 | * Verify and derive the re-entry information for |
| 148 | * the non-secure world from the non-secure state from |
| 149 | * where this call originated. |
| 150 | */ |
| 151 | rc = psci_get_ns_ep_info(&ep, entrypoint, context_id); |
| 152 | if (rc != PSCI_E_SUCCESS) |
| 153 | return rc; |
| 154 | |
Soby Mathew | f512157 | 2014-09-30 11:19:51 +0100 | [diff] [blame] | 155 | /* Save PSCI power state parameter for the core in suspend context */ |
| 156 | psci_set_suspend_power_state(power_state); |
| 157 | |
Soby Mathew | 8595b87 | 2015-01-06 15:36:38 +0000 | [diff] [blame] | 158 | /* |
Achin Gupta | 42c5280 | 2014-05-09 19:32:25 +0100 | [diff] [blame] | 159 | * Do what is needed to enter the power down state. Upon success, |
Soby Mathew | 74e52a7 | 2014-10-02 16:56:51 +0100 | [diff] [blame] | 160 | * enter the final wfi which will power down this CPU. |
Achin Gupta | 42c5280 | 2014-05-09 19:32:25 +0100 | [diff] [blame] | 161 | */ |
Soby Mathew | 74e52a7 | 2014-10-02 16:56:51 +0100 | [diff] [blame] | 162 | psci_afflvl_suspend(&ep, |
| 163 | MPIDR_AFFLVL0, |
| 164 | target_afflvl); |
| 165 | |
Soby Mathew | f512157 | 2014-09-30 11:19:51 +0100 | [diff] [blame] | 166 | /* Reset PSCI power state parameter for the core. */ |
| 167 | psci_set_suspend_power_state(PSCI_INVALID_DATA); |
Soby Mathew | 74e52a7 | 2014-10-02 16:56:51 +0100 | [diff] [blame] | 168 | return PSCI_E_SUCCESS; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 169 | } |
| 170 | |
Soby Mathew | 9616838 | 2014-12-17 14:47:57 +0000 | [diff] [blame] | 171 | int psci_system_suspend(unsigned long entrypoint, |
| 172 | unsigned long context_id) |
| 173 | { |
| 174 | int rc; |
| 175 | unsigned int power_state; |
| 176 | entry_point_info_t ep; |
| 177 | |
| 178 | /* Validate the entrypoint using platform pm_ops */ |
| 179 | if (psci_plat_pm_ops->validate_ns_entrypoint) { |
| 180 | rc = psci_plat_pm_ops->validate_ns_entrypoint(entrypoint); |
| 181 | if (rc != PSCI_E_SUCCESS) { |
| 182 | assert(rc == PSCI_E_INVALID_PARAMS); |
| 183 | return PSCI_E_INVALID_PARAMS; |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | /* Check if the current CPU is the last ON CPU in the system */ |
| 188 | if (!psci_is_last_on_cpu()) |
| 189 | return PSCI_E_DENIED; |
| 190 | |
| 191 | /* |
| 192 | * Verify and derive the re-entry information for |
| 193 | * the non-secure world from the non-secure state from |
| 194 | * where this call originated. |
| 195 | */ |
| 196 | rc = psci_get_ns_ep_info(&ep, entrypoint, context_id); |
| 197 | if (rc != PSCI_E_SUCCESS) |
| 198 | return rc; |
| 199 | |
| 200 | /* |
| 201 | * Assert that the required pm_ops hook is implemented to ensure that |
| 202 | * the capability detected during psci_setup() is valid. |
| 203 | */ |
| 204 | assert(psci_plat_pm_ops->get_sys_suspend_power_state); |
| 205 | |
| 206 | /* |
| 207 | * Query the platform for the power_state required for system suspend |
| 208 | */ |
| 209 | power_state = psci_plat_pm_ops->get_sys_suspend_power_state(); |
| 210 | |
| 211 | /* Save PSCI power state parameter for the core in suspend context */ |
| 212 | psci_set_suspend_power_state(power_state); |
| 213 | |
| 214 | /* |
| 215 | * Do what is needed to enter the power down state. Upon success, |
| 216 | * enter the final wfi which will power down this cpu. |
| 217 | */ |
| 218 | psci_afflvl_suspend(&ep, |
| 219 | MPIDR_AFFLVL0, |
| 220 | PLATFORM_MAX_AFFLVL); |
| 221 | |
| 222 | /* Reset PSCI power state parameter for the core. */ |
| 223 | psci_set_suspend_power_state(PSCI_INVALID_DATA); |
| 224 | return PSCI_E_SUCCESS; |
| 225 | } |
| 226 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 227 | int psci_cpu_off(void) |
| 228 | { |
| 229 | int rc; |
Soby Mathew | 2b7de2b | 2015-02-12 14:45:02 +0000 | [diff] [blame] | 230 | int target_afflvl = PLATFORM_MAX_AFFLVL; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 231 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 232 | /* |
| 233 | * Traverse from the highest to the lowest affinity level. When the |
| 234 | * lowest affinity level is hit, all the locks are acquired. State |
| 235 | * management is done immediately followed by cpu, cluster ... |
| 236 | * ..target_afflvl specific actions as this function unwinds back. |
| 237 | */ |
Andrew Thoelke | 2bc0785 | 2014-06-09 12:44:21 +0100 | [diff] [blame] | 238 | rc = psci_afflvl_off(MPIDR_AFFLVL0, target_afflvl); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 239 | |
Achin Gupta | 3140a9e | 2013-12-02 16:23:12 +0000 | [diff] [blame] | 240 | /* |
| 241 | * The only error cpu_off can return is E_DENIED. So check if that's |
| 242 | * indeed the case. |
| 243 | */ |
Achin Gupta | 42c5280 | 2014-05-09 19:32:25 +0100 | [diff] [blame] | 244 | assert (rc == PSCI_E_DENIED); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 245 | |
| 246 | return rc; |
| 247 | } |
| 248 | |
| 249 | int psci_affinity_info(unsigned long target_affinity, |
| 250 | unsigned int lowest_affinity_level) |
| 251 | { |
| 252 | int rc = PSCI_E_INVALID_PARAMS; |
| 253 | unsigned int aff_state; |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 254 | aff_map_node_t *node; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 255 | |
Soby Mathew | 2b7de2b | 2015-02-12 14:45:02 +0000 | [diff] [blame] | 256 | if (lowest_affinity_level > PLATFORM_MAX_AFFLVL) |
Achin Gupta | 75f7367 | 2013-12-05 16:33:10 +0000 | [diff] [blame] | 257 | return rc; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 258 | |
| 259 | node = psci_get_aff_map_node(target_affinity, lowest_affinity_level); |
| 260 | if (node && (node->state & PSCI_AFF_PRESENT)) { |
Achin Gupta | 75f7367 | 2013-12-05 16:33:10 +0000 | [diff] [blame] | 261 | |
| 262 | /* |
| 263 | * TODO: For affinity levels higher than 0 i.e. cpu, the |
| 264 | * state will always be either ON or OFF. Need to investigate |
| 265 | * how critical is it to support ON_PENDING here. |
| 266 | */ |
| 267 | aff_state = psci_get_state(node); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 268 | |
| 269 | /* A suspended cpu is available & on for the OS */ |
| 270 | if (aff_state == PSCI_STATE_SUSPEND) { |
| 271 | aff_state = PSCI_STATE_ON; |
| 272 | } |
| 273 | |
| 274 | rc = aff_state; |
| 275 | } |
Achin Gupta | 75f7367 | 2013-12-05 16:33:10 +0000 | [diff] [blame] | 276 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 277 | return rc; |
| 278 | } |
| 279 | |
Soby Mathew | 110fe36 | 2014-10-23 10:35:34 +0100 | [diff] [blame] | 280 | int psci_migrate(unsigned long target_cpu) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 281 | { |
Soby Mathew | 110fe36 | 2014-10-23 10:35:34 +0100 | [diff] [blame] | 282 | int rc; |
| 283 | unsigned long resident_cpu_mpidr; |
| 284 | |
| 285 | rc = psci_spd_migrate_info(&resident_cpu_mpidr); |
| 286 | if (rc != PSCI_TOS_UP_MIG_CAP) |
| 287 | return (rc == PSCI_TOS_NOT_UP_MIG_CAP) ? |
| 288 | PSCI_E_DENIED : PSCI_E_NOT_SUPPORTED; |
| 289 | |
| 290 | /* |
| 291 | * Migrate should only be invoked on the CPU where |
| 292 | * the Secure OS is resident. |
| 293 | */ |
| 294 | if (resident_cpu_mpidr != read_mpidr_el1()) |
| 295 | return PSCI_E_NOT_PRESENT; |
| 296 | |
| 297 | /* Check the validity of the specified target cpu */ |
| 298 | rc = psci_validate_mpidr(target_cpu, MPIDR_AFFLVL0); |
| 299 | if (rc != PSCI_E_SUCCESS) |
| 300 | return PSCI_E_INVALID_PARAMS; |
| 301 | |
| 302 | assert(psci_spd_pm && psci_spd_pm->svc_migrate); |
| 303 | |
| 304 | rc = psci_spd_pm->svc_migrate(read_mpidr_el1(), target_cpu); |
| 305 | assert(rc == PSCI_E_SUCCESS || rc == PSCI_E_INTERN_FAIL); |
| 306 | |
| 307 | return rc; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 308 | } |
| 309 | |
Soby Mathew | 110fe36 | 2014-10-23 10:35:34 +0100 | [diff] [blame] | 310 | int psci_migrate_info_type(void) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 311 | { |
Soby Mathew | 110fe36 | 2014-10-23 10:35:34 +0100 | [diff] [blame] | 312 | unsigned long resident_cpu_mpidr; |
| 313 | |
| 314 | return psci_spd_migrate_info(&resident_cpu_mpidr); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 315 | } |
| 316 | |
Soby Mathew | 110fe36 | 2014-10-23 10:35:34 +0100 | [diff] [blame] | 317 | long psci_migrate_info_up_cpu(void) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 318 | { |
Soby Mathew | 110fe36 | 2014-10-23 10:35:34 +0100 | [diff] [blame] | 319 | unsigned long resident_cpu_mpidr; |
| 320 | int rc; |
| 321 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 322 | /* |
Soby Mathew | 110fe36 | 2014-10-23 10:35:34 +0100 | [diff] [blame] | 323 | * Return value of this depends upon what |
| 324 | * psci_spd_migrate_info() returns. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 325 | */ |
Soby Mathew | 110fe36 | 2014-10-23 10:35:34 +0100 | [diff] [blame] | 326 | rc = psci_spd_migrate_info(&resident_cpu_mpidr); |
| 327 | if (rc != PSCI_TOS_NOT_UP_MIG_CAP && rc != PSCI_TOS_UP_MIG_CAP) |
| 328 | return PSCI_E_INVALID_PARAMS; |
| 329 | |
| 330 | return resident_cpu_mpidr; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 331 | } |
| 332 | |
Soby Mathew | 6cdddaf | 2015-01-07 11:10:22 +0000 | [diff] [blame] | 333 | int psci_features(unsigned int psci_fid) |
| 334 | { |
| 335 | uint32_t local_caps = psci_caps; |
| 336 | |
| 337 | /* Check if it is a 64 bit function */ |
| 338 | if (((psci_fid >> FUNCID_CC_SHIFT) & FUNCID_CC_MASK) == SMC_64) |
| 339 | local_caps &= PSCI_CAP_64BIT_MASK; |
| 340 | |
| 341 | /* Check for invalid fid */ |
| 342 | if (!(is_std_svc_call(psci_fid) && is_valid_fast_smc(psci_fid) |
| 343 | && is_psci_fid(psci_fid))) |
| 344 | return PSCI_E_NOT_SUPPORTED; |
| 345 | |
| 346 | |
| 347 | /* Check if the psci fid is supported or not */ |
| 348 | if (!(local_caps & define_psci_cap(psci_fid))) |
| 349 | return PSCI_E_NOT_SUPPORTED; |
| 350 | |
| 351 | /* Format the feature flags */ |
| 352 | if (psci_fid == PSCI_CPU_SUSPEND_AARCH32 || |
| 353 | psci_fid == PSCI_CPU_SUSPEND_AARCH64) { |
| 354 | /* |
| 355 | * The trusted firmware uses the original power state format |
| 356 | * and does not support OS Initiated Mode. |
| 357 | */ |
| 358 | return (FF_PSTATE_ORIG << FF_PSTATE_SHIFT) | |
| 359 | ((!FF_SUPPORTS_OS_INIT_MODE) << FF_MODE_SUPPORT_SHIFT); |
| 360 | } |
| 361 | |
| 362 | /* Return 0 for all other fid's */ |
| 363 | return PSCI_E_SUCCESS; |
| 364 | } |
| 365 | |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 366 | /******************************************************************************* |
| 367 | * PSCI top level handler for servicing SMCs. |
| 368 | ******************************************************************************/ |
| 369 | uint64_t psci_smc_handler(uint32_t smc_fid, |
| 370 | uint64_t x1, |
| 371 | uint64_t x2, |
| 372 | uint64_t x3, |
| 373 | uint64_t x4, |
| 374 | void *cookie, |
| 375 | void *handle, |
| 376 | uint64_t flags) |
| 377 | { |
Andrew Thoelke | 89a3c84 | 2014-06-10 16:37:37 +0100 | [diff] [blame] | 378 | if (is_caller_secure(flags)) |
| 379 | SMC_RET1(handle, SMC_UNK); |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 380 | |
Soby Mathew | 61e615b | 2015-01-15 11:49:49 +0000 | [diff] [blame] | 381 | /* Check the fid against the capabilities */ |
| 382 | if (!(psci_caps & define_psci_cap(smc_fid))) |
| 383 | SMC_RET1(handle, SMC_UNK); |
| 384 | |
Andrew Thoelke | 89a3c84 | 2014-06-10 16:37:37 +0100 | [diff] [blame] | 385 | if (((smc_fid >> FUNCID_CC_SHIFT) & FUNCID_CC_MASK) == SMC_32) { |
| 386 | /* 32-bit PSCI function, clear top parameter bits */ |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 387 | |
Andrew Thoelke | 89a3c84 | 2014-06-10 16:37:37 +0100 | [diff] [blame] | 388 | x1 = (uint32_t)x1; |
| 389 | x2 = (uint32_t)x2; |
| 390 | x3 = (uint32_t)x3; |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 391 | |
Andrew Thoelke | 89a3c84 | 2014-06-10 16:37:37 +0100 | [diff] [blame] | 392 | switch (smc_fid) { |
| 393 | case PSCI_VERSION: |
| 394 | SMC_RET1(handle, psci_version()); |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 395 | |
Andrew Thoelke | 89a3c84 | 2014-06-10 16:37:37 +0100 | [diff] [blame] | 396 | case PSCI_CPU_OFF: |
Achin Gupta | e1aa516 | 2014-06-26 09:58:52 +0100 | [diff] [blame] | 397 | SMC_RET1(handle, psci_cpu_off()); |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 398 | |
Andrew Thoelke | 89a3c84 | 2014-06-10 16:37:37 +0100 | [diff] [blame] | 399 | case PSCI_CPU_SUSPEND_AARCH32: |
Achin Gupta | e1aa516 | 2014-06-26 09:58:52 +0100 | [diff] [blame] | 400 | SMC_RET1(handle, psci_cpu_suspend(x1, x2, x3)); |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 401 | |
Andrew Thoelke | 89a3c84 | 2014-06-10 16:37:37 +0100 | [diff] [blame] | 402 | case PSCI_CPU_ON_AARCH32: |
| 403 | SMC_RET1(handle, psci_cpu_on(x1, x2, x3)); |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 404 | |
Andrew Thoelke | 89a3c84 | 2014-06-10 16:37:37 +0100 | [diff] [blame] | 405 | case PSCI_AFFINITY_INFO_AARCH32: |
| 406 | SMC_RET1(handle, psci_affinity_info(x1, x2)); |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 407 | |
Andrew Thoelke | 89a3c84 | 2014-06-10 16:37:37 +0100 | [diff] [blame] | 408 | case PSCI_MIG_AARCH32: |
| 409 | SMC_RET1(handle, psci_migrate(x1)); |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 410 | |
Andrew Thoelke | 89a3c84 | 2014-06-10 16:37:37 +0100 | [diff] [blame] | 411 | case PSCI_MIG_INFO_TYPE: |
| 412 | SMC_RET1(handle, psci_migrate_info_type()); |
| 413 | |
| 414 | case PSCI_MIG_INFO_UP_CPU_AARCH32: |
| 415 | SMC_RET1(handle, psci_migrate_info_up_cpu()); |
| 416 | |
Soby Mathew | 9616838 | 2014-12-17 14:47:57 +0000 | [diff] [blame] | 417 | case PSCI_SYSTEM_SUSPEND_AARCH32: |
| 418 | SMC_RET1(handle, psci_system_suspend(x1, x2)); |
| 419 | |
Juan Castillo | 4dc4a47 | 2014-08-12 11:17:06 +0100 | [diff] [blame] | 420 | case PSCI_SYSTEM_OFF: |
| 421 | psci_system_off(); |
| 422 | /* We should never return from psci_system_off() */ |
| 423 | |
| 424 | case PSCI_SYSTEM_RESET: |
| 425 | psci_system_reset(); |
| 426 | /* We should never return from psci_system_reset() */ |
| 427 | |
Soby Mathew | 6cdddaf | 2015-01-07 11:10:22 +0000 | [diff] [blame] | 428 | case PSCI_FEATURES: |
| 429 | SMC_RET1(handle, psci_features(x1)); |
| 430 | |
Andrew Thoelke | 89a3c84 | 2014-06-10 16:37:37 +0100 | [diff] [blame] | 431 | default: |
| 432 | break; |
| 433 | } |
| 434 | } else { |
| 435 | /* 64-bit PSCI function */ |
| 436 | |
| 437 | switch (smc_fid) { |
| 438 | case PSCI_CPU_SUSPEND_AARCH64: |
Achin Gupta | e1aa516 | 2014-06-26 09:58:52 +0100 | [diff] [blame] | 439 | SMC_RET1(handle, psci_cpu_suspend(x1, x2, x3)); |
Andrew Thoelke | 89a3c84 | 2014-06-10 16:37:37 +0100 | [diff] [blame] | 440 | |
| 441 | case PSCI_CPU_ON_AARCH64: |
| 442 | SMC_RET1(handle, psci_cpu_on(x1, x2, x3)); |
| 443 | |
| 444 | case PSCI_AFFINITY_INFO_AARCH64: |
| 445 | SMC_RET1(handle, psci_affinity_info(x1, x2)); |
| 446 | |
| 447 | case PSCI_MIG_AARCH64: |
| 448 | SMC_RET1(handle, psci_migrate(x1)); |
| 449 | |
| 450 | case PSCI_MIG_INFO_UP_CPU_AARCH64: |
| 451 | SMC_RET1(handle, psci_migrate_info_up_cpu()); |
| 452 | |
Soby Mathew | 9616838 | 2014-12-17 14:47:57 +0000 | [diff] [blame] | 453 | case PSCI_SYSTEM_SUSPEND_AARCH64: |
| 454 | SMC_RET1(handle, psci_system_suspend(x1, x2)); |
| 455 | |
Andrew Thoelke | 89a3c84 | 2014-06-10 16:37:37 +0100 | [diff] [blame] | 456 | default: |
| 457 | break; |
| 458 | } |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 459 | } |
| 460 | |
Andrew Thoelke | 89a3c84 | 2014-06-10 16:37:37 +0100 | [diff] [blame] | 461 | WARN("Unimplemented PSCI Call: 0x%x \n", smc_fid); |
| 462 | SMC_RET1(handle, SMC_UNK); |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 463 | } |