Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1 | /* |
Jayanth Dodderi Chidanand | 7076350 | 2022-08-22 23:46:10 +0100 | [diff] [blame] | 2 | * Copyright (c) 2013-2022, Arm Limited and Contributors. All rights reserved. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
Dan Handley | 2bd4ef2 | 2014-04-09 13:14:54 +0100 | [diff] [blame] | 7 | #include <assert.h> |
Soby Mathew | 981487a | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 8 | #include <string.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 9 | |
| 10 | #include <arch.h> |
| 11 | #include <arch_helpers.h> |
| 12 | #include <common/debug.h> |
| 13 | #include <lib/pmf/pmf.h> |
| 14 | #include <lib/runtime_instr.h> |
| 15 | #include <lib/smccc.h> |
| 16 | #include <plat/common/platform.h> |
| 17 | #include <services/arm_arch_svc.h> |
| 18 | |
Dan Handley | 714a0d2 | 2014-04-09 13:13:04 +0100 | [diff] [blame] | 19 | #include "psci_private.h" |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 20 | |
| 21 | /******************************************************************************* |
| 22 | * PSCI frontend api for servicing SMCs. Described in the PSCI spec. |
| 23 | ******************************************************************************/ |
Soby Mathew | 011ca18 | 2015-07-29 17:05:03 +0100 | [diff] [blame] | 24 | int psci_cpu_on(u_register_t target_cpu, |
| 25 | uintptr_t entrypoint, |
| 26 | u_register_t context_id) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 27 | |
| 28 | { |
| 29 | int rc; |
Soby Mathew | 8595b87 | 2015-01-06 15:36:38 +0000 | [diff] [blame] | 30 | entry_point_info_t ep; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 31 | |
| 32 | /* Determine if the cpu exists of not */ |
Soby Mathew | 981487a | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 33 | rc = psci_validate_mpidr(target_cpu); |
| 34 | if (rc != PSCI_E_SUCCESS) |
Soby Mathew | 74e52a7 | 2014-10-02 16:56:51 +0100 | [diff] [blame] | 35 | return PSCI_E_INVALID_PARAMS; |
Soby Mathew | 74e52a7 | 2014-10-02 16:56:51 +0100 | [diff] [blame] | 36 | |
Soby Mathew | f1f97a1 | 2015-07-15 12:13:26 +0100 | [diff] [blame] | 37 | /* Validate the entry point and get the entry_point_info */ |
| 38 | rc = psci_validate_entry_point(&ep, entrypoint, context_id); |
Soby Mathew | 8595b87 | 2015-01-06 15:36:38 +0000 | [diff] [blame] | 39 | if (rc != PSCI_E_SUCCESS) |
| 40 | return rc; |
| 41 | |
Soby Mathew | 8595b87 | 2015-01-06 15:36:38 +0000 | [diff] [blame] | 42 | /* |
Soby Mathew | 981487a | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 43 | * To turn this cpu on, specify which power |
Achin Gupta | 0959db5 | 2013-12-02 17:33:04 +0000 | [diff] [blame] | 44 | * levels need to be turned on |
| 45 | */ |
Sandrine Bailleux | 7497bff | 2016-04-25 09:28:43 +0100 | [diff] [blame] | 46 | return psci_cpu_on_start(target_cpu, &ep); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | unsigned int psci_version(void) |
| 50 | { |
| 51 | return PSCI_MAJOR_VER | PSCI_MINOR_VER; |
| 52 | } |
| 53 | |
| 54 | int psci_cpu_suspend(unsigned int power_state, |
Soby Mathew | 011ca18 | 2015-07-29 17:05:03 +0100 | [diff] [blame] | 55 | uintptr_t entrypoint, |
| 56 | u_register_t context_id) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 57 | { |
| 58 | int rc; |
Soby Mathew | 981487a | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 59 | unsigned int target_pwrlvl, is_power_down_state; |
Soby Mathew | 8595b87 | 2015-01-06 15:36:38 +0000 | [diff] [blame] | 60 | entry_point_info_t ep; |
Soby Mathew | 981487a | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 61 | psci_power_state_t state_info = { {PSCI_LOCAL_STATE_RUN} }; |
| 62 | plat_local_state_t cpu_pd_state; |
Wing Li | 2c556f3 | 2022-09-14 13:18:17 -0700 | [diff] [blame] | 63 | #if PSCI_OS_INIT_MODE |
| 64 | unsigned int cpu_idx = plat_my_core_pos(); |
| 65 | plat_local_state_t prev[PLAT_MAX_PWR_LVL]; |
| 66 | #endif |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 67 | |
Soby Mathew | 981487a | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 68 | /* Validate the power_state parameter */ |
| 69 | rc = psci_validate_power_state(power_state, &state_info); |
| 70 | if (rc != PSCI_E_SUCCESS) { |
| 71 | assert(rc == PSCI_E_INVALID_PARAMS); |
| 72 | return rc; |
| 73 | } |
Vikram Kanigiri | f100f41 | 2014-04-01 19:26:26 +0100 | [diff] [blame] | 74 | |
Soby Mathew | 981487a | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 75 | /* |
| 76 | * Get the value of the state type bit from the power state parameter. |
| 77 | */ |
| 78 | is_power_down_state = psci_get_pstate_type(power_state); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 79 | |
Soby Mathew | 981487a | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 80 | /* Sanity check the requested suspend levels */ |
Soby Mathew | 24ab34f | 2016-05-03 17:11:42 +0100 | [diff] [blame] | 81 | assert(psci_validate_suspend_req(&state_info, is_power_down_state) |
Soby Mathew | 981487a | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 82 | == PSCI_E_SUCCESS); |
Soby Mathew | 74e52a7 | 2014-10-02 16:56:51 +0100 | [diff] [blame] | 83 | |
Soby Mathew | 981487a | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 84 | target_pwrlvl = psci_find_target_suspend_lvl(&state_info); |
Sandrine Bailleux | f9f3bbf | 2016-06-22 16:35:01 +0100 | [diff] [blame] | 85 | if (target_pwrlvl == PSCI_INVALID_PWR_LVL) { |
| 86 | ERROR("Invalid target power level for suspend operation\n"); |
| 87 | panic(); |
| 88 | } |
Soby Mathew | 981487a | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 89 | |
| 90 | /* Fast path for CPU standby.*/ |
Antonio Nino Diaz | de11a5b | 2018-08-01 16:42:10 +0100 | [diff] [blame] | 91 | if (is_cpu_standby_req(is_power_down_state, target_pwrlvl)) { |
Antonio Nino Diaz | 78a95a6 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 92 | if (psci_plat_pm_ops->cpu_standby == NULL) |
Soby Mathew | 74e52a7 | 2014-10-02 16:56:51 +0100 | [diff] [blame] | 93 | return PSCI_E_INVALID_PARAMS; |
Soby Mathew | 74e52a7 | 2014-10-02 16:56:51 +0100 | [diff] [blame] | 94 | |
Soby Mathew | 981487a | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 95 | /* |
| 96 | * Set the state of the CPU power domain to the platform |
| 97 | * specific retention state and enter the standby state. |
| 98 | */ |
| 99 | cpu_pd_state = state_info.pwr_domain_state[PSCI_CPU_PWR_LVL]; |
| 100 | psci_set_cpu_local_state(cpu_pd_state); |
Yatharth Kochar | 241ec6c | 2016-05-09 18:26:35 +0100 | [diff] [blame] | 101 | |
Wing Li | 2c556f3 | 2022-09-14 13:18:17 -0700 | [diff] [blame] | 102 | #if PSCI_OS_INIT_MODE |
| 103 | /* |
| 104 | * If in OS-initiated mode, save a copy of the previous |
| 105 | * requested local power states and update the new requested |
| 106 | * local power states for this CPU. |
| 107 | */ |
| 108 | if (psci_suspend_mode == OS_INIT) { |
| 109 | psci_update_req_local_pwr_states(target_pwrlvl, cpu_idx, |
| 110 | &state_info, prev); |
| 111 | } |
| 112 | #endif |
| 113 | |
Yatharth Kochar | 241ec6c | 2016-05-09 18:26:35 +0100 | [diff] [blame] | 114 | #if ENABLE_PSCI_STAT |
dp-arm | 66abfbe | 2017-01-31 13:01:04 +0000 | [diff] [blame] | 115 | plat_psci_stat_accounting_start(&state_info); |
Yatharth Kochar | 241ec6c | 2016-05-09 18:26:35 +0100 | [diff] [blame] | 116 | #endif |
| 117 | |
dp-arm | 3cac786 | 2016-09-19 11:18:44 +0100 | [diff] [blame] | 118 | #if ENABLE_RUNTIME_INSTRUMENTATION |
| 119 | PMF_CAPTURE_TIMESTAMP(rt_instr_svc, |
| 120 | RT_INSTR_ENTER_HW_LOW_PWR, |
| 121 | PMF_NO_CACHE_MAINT); |
| 122 | #endif |
| 123 | |
Soby Mathew | 981487a | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 124 | psci_plat_pm_ops->cpu_standby(cpu_pd_state); |
Achin Gupta | 42c5280 | 2014-05-09 19:32:25 +0100 | [diff] [blame] | 125 | |
Soby Mathew | 981487a | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 126 | /* Upon exit from standby, set the state back to RUN. */ |
| 127 | psci_set_cpu_local_state(PSCI_LOCAL_STATE_RUN); |
Achin Gupta | 42c5280 | 2014-05-09 19:32:25 +0100 | [diff] [blame] | 128 | |
Wing Li | 2c556f3 | 2022-09-14 13:18:17 -0700 | [diff] [blame] | 129 | #if PSCI_OS_INIT_MODE |
| 130 | /* |
| 131 | * If in OS-initiated mode, restore the previous requested |
| 132 | * local power states for this CPU. |
| 133 | */ |
| 134 | if (psci_suspend_mode == OS_INIT) { |
| 135 | psci_restore_req_local_pwr_states(cpu_idx, prev); |
| 136 | } |
| 137 | #endif |
| 138 | |
dp-arm | 3cac786 | 2016-09-19 11:18:44 +0100 | [diff] [blame] | 139 | #if ENABLE_RUNTIME_INSTRUMENTATION |
| 140 | PMF_CAPTURE_TIMESTAMP(rt_instr_svc, |
| 141 | RT_INSTR_EXIT_HW_LOW_PWR, |
| 142 | PMF_NO_CACHE_MAINT); |
| 143 | #endif |
| 144 | |
Yatharth Kochar | 241ec6c | 2016-05-09 18:26:35 +0100 | [diff] [blame] | 145 | #if ENABLE_PSCI_STAT |
dp-arm | 66abfbe | 2017-01-31 13:01:04 +0000 | [diff] [blame] | 146 | plat_psci_stat_accounting_stop(&state_info); |
Yatharth Kochar | 241ec6c | 2016-05-09 18:26:35 +0100 | [diff] [blame] | 147 | |
| 148 | /* Update PSCI stats */ |
dp-arm | 66abfbe | 2017-01-31 13:01:04 +0000 | [diff] [blame] | 149 | psci_stats_update_pwr_up(PSCI_CPU_PWR_LVL, &state_info); |
Yatharth Kochar | 241ec6c | 2016-05-09 18:26:35 +0100 | [diff] [blame] | 150 | #endif |
| 151 | |
Soby Mathew | 74e52a7 | 2014-10-02 16:56:51 +0100 | [diff] [blame] | 152 | return PSCI_E_SUCCESS; |
Vikram Kanigiri | 3b7c59b | 2014-03-21 11:57:10 +0000 | [diff] [blame] | 153 | } |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 154 | |
Achin Gupta | 42c5280 | 2014-05-09 19:32:25 +0100 | [diff] [blame] | 155 | /* |
Soby Mathew | 981487a | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 156 | * If a power down state has been requested, we need to verify entry |
| 157 | * point and program entry information. |
Soby Mathew | 8595b87 | 2015-01-06 15:36:38 +0000 | [diff] [blame] | 158 | */ |
Antonio Nino Diaz | 78a95a6 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 159 | if (is_power_down_state != 0U) { |
Soby Mathew | f1f97a1 | 2015-07-15 12:13:26 +0100 | [diff] [blame] | 160 | rc = psci_validate_entry_point(&ep, entrypoint, context_id); |
Soby Mathew | 981487a | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 161 | if (rc != PSCI_E_SUCCESS) |
| 162 | return rc; |
| 163 | } |
Soby Mathew | f512157 | 2014-09-30 11:19:51 +0100 | [diff] [blame] | 164 | |
Soby Mathew | 8595b87 | 2015-01-06 15:36:38 +0000 | [diff] [blame] | 165 | /* |
Achin Gupta | 42c5280 | 2014-05-09 19:32:25 +0100 | [diff] [blame] | 166 | * Do what is needed to enter the power down state. Upon success, |
Soby Mathew | 981487a | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 167 | * enter the final wfi which will power down this CPU. This function |
| 168 | * might return if the power down was abandoned for any reason, e.g. |
| 169 | * arrival of an interrupt |
Achin Gupta | 42c5280 | 2014-05-09 19:32:25 +0100 | [diff] [blame] | 170 | */ |
Wing Li | 2c556f3 | 2022-09-14 13:18:17 -0700 | [diff] [blame] | 171 | rc = psci_cpu_suspend_start(&ep, |
| 172 | target_pwrlvl, |
| 173 | &state_info, |
| 174 | is_power_down_state); |
Soby Mathew | 74e52a7 | 2014-10-02 16:56:51 +0100 | [diff] [blame] | 175 | |
Wing Li | 2c556f3 | 2022-09-14 13:18:17 -0700 | [diff] [blame] | 176 | return rc; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 177 | } |
| 178 | |
Soby Mathew | 011ca18 | 2015-07-29 17:05:03 +0100 | [diff] [blame] | 179 | |
| 180 | int psci_system_suspend(uintptr_t entrypoint, u_register_t context_id) |
Soby Mathew | 9616838 | 2014-12-17 14:47:57 +0000 | [diff] [blame] | 181 | { |
| 182 | int rc; |
Soby Mathew | 981487a | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 183 | psci_power_state_t state_info; |
Soby Mathew | 9616838 | 2014-12-17 14:47:57 +0000 | [diff] [blame] | 184 | entry_point_info_t ep; |
| 185 | |
Soby Mathew | 9616838 | 2014-12-17 14:47:57 +0000 | [diff] [blame] | 186 | /* Check if the current CPU is the last ON CPU in the system */ |
Jayanth Dodderi Chidanand | 7076350 | 2022-08-22 23:46:10 +0100 | [diff] [blame] | 187 | if (!psci_is_last_on_cpu()) |
Soby Mathew | 9616838 | 2014-12-17 14:47:57 +0000 | [diff] [blame] | 188 | return PSCI_E_DENIED; |
| 189 | |
Soby Mathew | f1f97a1 | 2015-07-15 12:13:26 +0100 | [diff] [blame] | 190 | /* Validate the entry point and get the entry_point_info */ |
| 191 | rc = psci_validate_entry_point(&ep, entrypoint, context_id); |
Soby Mathew | 9616838 | 2014-12-17 14:47:57 +0000 | [diff] [blame] | 192 | if (rc != PSCI_E_SUCCESS) |
| 193 | return rc; |
| 194 | |
Soby Mathew | 981487a | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 195 | /* Query the psci_power_state for system suspend */ |
| 196 | psci_query_sys_suspend_pwrstate(&state_info); |
Soby Mathew | 9616838 | 2014-12-17 14:47:57 +0000 | [diff] [blame] | 197 | |
ldts | 1821db2 | 2018-10-11 08:40:32 +0200 | [diff] [blame] | 198 | /* |
| 199 | * Check if platform allows suspend to Highest power level |
| 200 | * (System level) |
| 201 | */ |
| 202 | if (psci_find_target_suspend_lvl(&state_info) < PLAT_MAX_PWR_LVL) |
| 203 | return PSCI_E_DENIED; |
| 204 | |
Soby Mathew | 981487a | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 205 | /* Ensure that the psci_power_state makes sense */ |
Soby Mathew | 981487a | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 206 | assert(psci_validate_suspend_req(&state_info, PSTATE_TYPE_POWERDOWN) |
| 207 | == PSCI_E_SUCCESS); |
Antonio Nino Diaz | 78a95a6 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 208 | assert(is_local_state_off( |
| 209 | state_info.pwr_domain_state[PLAT_MAX_PWR_LVL]) != 0); |
Soby Mathew | 9616838 | 2014-12-17 14:47:57 +0000 | [diff] [blame] | 210 | |
| 211 | /* |
Soby Mathew | 981487a | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 212 | * Do what is needed to enter the system suspend state. This function |
| 213 | * might return if the power down was abandoned for any reason, e.g. |
| 214 | * arrival of an interrupt |
Soby Mathew | 9616838 | 2014-12-17 14:47:57 +0000 | [diff] [blame] | 215 | */ |
Wing Li | 2c556f3 | 2022-09-14 13:18:17 -0700 | [diff] [blame] | 216 | rc = psci_cpu_suspend_start(&ep, |
| 217 | PLAT_MAX_PWR_LVL, |
| 218 | &state_info, |
| 219 | PSTATE_TYPE_POWERDOWN); |
Soby Mathew | 9616838 | 2014-12-17 14:47:57 +0000 | [diff] [blame] | 220 | |
Wing Li | 2c556f3 | 2022-09-14 13:18:17 -0700 | [diff] [blame] | 221 | return rc; |
Soby Mathew | 9616838 | 2014-12-17 14:47:57 +0000 | [diff] [blame] | 222 | } |
| 223 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 224 | int psci_cpu_off(void) |
| 225 | { |
| 226 | int rc; |
Soby Mathew | 011ca18 | 2015-07-29 17:05:03 +0100 | [diff] [blame] | 227 | unsigned int target_pwrlvl = PLAT_MAX_PWR_LVL; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 228 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 229 | /* |
Soby Mathew | 981487a | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 230 | * Do what is needed to power off this CPU and possible higher power |
| 231 | * levels if it able to do so. Upon success, enter the final wfi |
| 232 | * which will power down this CPU. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 233 | */ |
Soby Mathew | 981487a | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 234 | rc = psci_do_cpu_off(target_pwrlvl); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 235 | |
Achin Gupta | 3140a9e | 2013-12-02 16:23:12 +0000 | [diff] [blame] | 236 | /* |
| 237 | * The only error cpu_off can return is E_DENIED. So check if that's |
| 238 | * indeed the case. |
| 239 | */ |
Soby Mathew | 24ab34f | 2016-05-03 17:11:42 +0100 | [diff] [blame] | 240 | assert(rc == PSCI_E_DENIED); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 241 | |
| 242 | return rc; |
| 243 | } |
| 244 | |
Soby Mathew | 011ca18 | 2015-07-29 17:05:03 +0100 | [diff] [blame] | 245 | int psci_affinity_info(u_register_t target_affinity, |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 246 | unsigned int lowest_affinity_level) |
| 247 | { |
Deepika Bhavnani | 4287c0c | 2019-12-13 10:23:18 -0600 | [diff] [blame] | 248 | int ret; |
| 249 | unsigned int target_idx; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 250 | |
Soby Mathew | 981487a | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 251 | /* We dont support level higher than PSCI_CPU_PWR_LVL */ |
| 252 | if (lowest_affinity_level > PSCI_CPU_PWR_LVL) |
| 253 | return PSCI_E_INVALID_PARAMS; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 254 | |
Soby Mathew | 981487a | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 255 | /* Calculate the cpu index of the target */ |
Deepika Bhavnani | 4287c0c | 2019-12-13 10:23:18 -0600 | [diff] [blame] | 256 | ret = plat_core_pos_by_mpidr(target_affinity); |
| 257 | if (ret == -1) { |
Soby Mathew | 981487a | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 258 | return PSCI_E_INVALID_PARAMS; |
Deepika Bhavnani | 4287c0c | 2019-12-13 10:23:18 -0600 | [diff] [blame] | 259 | } |
| 260 | target_idx = (unsigned int)ret; |
Achin Gupta | 75f7367 | 2013-12-05 16:33:10 +0000 | [diff] [blame] | 261 | |
Roberto Vargas | 6dc8214 | 2017-11-13 08:24:07 +0000 | [diff] [blame] | 262 | /* |
| 263 | * Generic management: |
| 264 | * Perform cache maintanence ahead of reading the target CPU state to |
| 265 | * ensure that the data is not stale. |
| 266 | * There is a theoretical edge case where the cache may contain stale |
| 267 | * data for the target CPU data - this can occur under the following |
| 268 | * conditions: |
| 269 | * - the target CPU is in another cluster from the current |
| 270 | * - the target CPU was the last CPU to shutdown on its cluster |
| 271 | * - the cluster was removed from coherency as part of the CPU shutdown |
| 272 | * |
| 273 | * In this case the cache maintenace that was performed as part of the |
| 274 | * target CPUs shutdown was not seen by the current CPU's cluster. And |
| 275 | * so the cache may contain stale data for the target CPU. |
| 276 | */ |
Deepika Bhavnani | 4287c0c | 2019-12-13 10:23:18 -0600 | [diff] [blame] | 277 | flush_cpu_data_by_index(target_idx, |
Antonio Nino Diaz | 78a95a6 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 278 | psci_svc_cpu_data.aff_info_state); |
Roberto Vargas | 6dc8214 | 2017-11-13 08:24:07 +0000 | [diff] [blame] | 279 | |
Soby Mathew | 981487a | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 280 | return psci_get_aff_info_state_by_idx(target_idx); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 281 | } |
| 282 | |
Soby Mathew | 011ca18 | 2015-07-29 17:05:03 +0100 | [diff] [blame] | 283 | int psci_migrate(u_register_t target_cpu) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 284 | { |
Soby Mathew | 110fe36 | 2014-10-23 10:35:34 +0100 | [diff] [blame] | 285 | int rc; |
Soby Mathew | 011ca18 | 2015-07-29 17:05:03 +0100 | [diff] [blame] | 286 | u_register_t resident_cpu_mpidr; |
Soby Mathew | 110fe36 | 2014-10-23 10:35:34 +0100 | [diff] [blame] | 287 | |
| 288 | rc = psci_spd_migrate_info(&resident_cpu_mpidr); |
| 289 | if (rc != PSCI_TOS_UP_MIG_CAP) |
| 290 | return (rc == PSCI_TOS_NOT_UP_MIG_CAP) ? |
| 291 | PSCI_E_DENIED : PSCI_E_NOT_SUPPORTED; |
| 292 | |
| 293 | /* |
| 294 | * Migrate should only be invoked on the CPU where |
| 295 | * the Secure OS is resident. |
| 296 | */ |
| 297 | if (resident_cpu_mpidr != read_mpidr_el1()) |
| 298 | return PSCI_E_NOT_PRESENT; |
| 299 | |
| 300 | /* Check the validity of the specified target cpu */ |
Soby Mathew | 981487a | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 301 | rc = psci_validate_mpidr(target_cpu); |
Soby Mathew | 110fe36 | 2014-10-23 10:35:34 +0100 | [diff] [blame] | 302 | if (rc != PSCI_E_SUCCESS) |
| 303 | return PSCI_E_INVALID_PARAMS; |
| 304 | |
Antonio Nino Diaz | 78a95a6 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 305 | assert((psci_spd_pm != NULL) && (psci_spd_pm->svc_migrate != NULL)); |
Soby Mathew | 110fe36 | 2014-10-23 10:35:34 +0100 | [diff] [blame] | 306 | |
| 307 | rc = psci_spd_pm->svc_migrate(read_mpidr_el1(), target_cpu); |
Antonio Nino Diaz | 78a95a6 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 308 | assert((rc == PSCI_E_SUCCESS) || (rc == PSCI_E_INTERN_FAIL)); |
Soby Mathew | 110fe36 | 2014-10-23 10:35:34 +0100 | [diff] [blame] | 309 | |
| 310 | return rc; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 311 | } |
| 312 | |
Soby Mathew | 110fe36 | 2014-10-23 10:35:34 +0100 | [diff] [blame] | 313 | int psci_migrate_info_type(void) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 314 | { |
Soby Mathew | 011ca18 | 2015-07-29 17:05:03 +0100 | [diff] [blame] | 315 | u_register_t resident_cpu_mpidr; |
Soby Mathew | 110fe36 | 2014-10-23 10:35:34 +0100 | [diff] [blame] | 316 | |
| 317 | return psci_spd_migrate_info(&resident_cpu_mpidr); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 318 | } |
| 319 | |
Antonio Nino Diaz | 78a95a6 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 320 | u_register_t psci_migrate_info_up_cpu(void) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 321 | { |
Soby Mathew | 011ca18 | 2015-07-29 17:05:03 +0100 | [diff] [blame] | 322 | u_register_t resident_cpu_mpidr; |
Soby Mathew | 110fe36 | 2014-10-23 10:35:34 +0100 | [diff] [blame] | 323 | int rc; |
| 324 | |
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 | * Return value of this depends upon what |
| 327 | * psci_spd_migrate_info() returns. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 328 | */ |
Soby Mathew | 110fe36 | 2014-10-23 10:35:34 +0100 | [diff] [blame] | 329 | rc = psci_spd_migrate_info(&resident_cpu_mpidr); |
Antonio Nino Diaz | 78a95a6 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 330 | if ((rc != PSCI_TOS_NOT_UP_MIG_CAP) && (rc != PSCI_TOS_UP_MIG_CAP)) |
| 331 | return (u_register_t)(register_t) PSCI_E_INVALID_PARAMS; |
Soby Mathew | 110fe36 | 2014-10-23 10:35:34 +0100 | [diff] [blame] | 332 | |
| 333 | return resident_cpu_mpidr; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 334 | } |
| 335 | |
Jeenu Viswambharan | 7f03e9d9 | 2016-08-03 15:54:50 +0100 | [diff] [blame] | 336 | int psci_node_hw_state(u_register_t target_cpu, |
| 337 | unsigned int power_level) |
| 338 | { |
| 339 | int rc; |
| 340 | |
| 341 | /* Validate target_cpu */ |
| 342 | rc = psci_validate_mpidr(target_cpu); |
| 343 | if (rc != PSCI_E_SUCCESS) |
| 344 | return PSCI_E_INVALID_PARAMS; |
| 345 | |
| 346 | /* Validate power_level against PLAT_MAX_PWR_LVL */ |
| 347 | if (power_level > PLAT_MAX_PWR_LVL) |
| 348 | return PSCI_E_INVALID_PARAMS; |
| 349 | |
| 350 | /* |
| 351 | * Dispatch this call to platform to query power controller, and pass on |
| 352 | * to the caller what it returns |
| 353 | */ |
Antonio Nino Diaz | 78a95a6 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 354 | assert(psci_plat_pm_ops->get_node_hw_state != NULL); |
Jeenu Viswambharan | 7f03e9d9 | 2016-08-03 15:54:50 +0100 | [diff] [blame] | 355 | rc = psci_plat_pm_ops->get_node_hw_state(target_cpu, power_level); |
Antonio Nino Diaz | 78a95a6 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 356 | assert(((rc >= HW_ON) && (rc <= HW_STANDBY)) |
| 357 | || (rc == PSCI_E_NOT_SUPPORTED) |
| 358 | || (rc == PSCI_E_INVALID_PARAMS)); |
Jeenu Viswambharan | 7f03e9d9 | 2016-08-03 15:54:50 +0100 | [diff] [blame] | 359 | return rc; |
| 360 | } |
| 361 | |
Soby Mathew | 6cdddaf | 2015-01-07 11:10:22 +0000 | [diff] [blame] | 362 | int psci_features(unsigned int psci_fid) |
| 363 | { |
Soby Mathew | 011ca18 | 2015-07-29 17:05:03 +0100 | [diff] [blame] | 364 | unsigned int local_caps = psci_caps; |
Soby Mathew | 6cdddaf | 2015-01-07 11:10:22 +0000 | [diff] [blame] | 365 | |
Dimitris Papastamos | a65841a | 2018-01-22 12:58:52 +0000 | [diff] [blame] | 366 | if (psci_fid == SMCCC_VERSION) |
| 367 | return PSCI_E_SUCCESS; |
| 368 | |
Soby Mathew | 6cdddaf | 2015-01-07 11:10:22 +0000 | [diff] [blame] | 369 | /* Check if it is a 64 bit function */ |
| 370 | if (((psci_fid >> FUNCID_CC_SHIFT) & FUNCID_CC_MASK) == SMC_64) |
| 371 | local_caps &= PSCI_CAP_64BIT_MASK; |
| 372 | |
| 373 | /* Check for invalid fid */ |
| 374 | if (!(is_std_svc_call(psci_fid) && is_valid_fast_smc(psci_fid) |
| 375 | && is_psci_fid(psci_fid))) |
| 376 | return PSCI_E_NOT_SUPPORTED; |
| 377 | |
| 378 | |
| 379 | /* Check if the psci fid is supported or not */ |
Antonio Nino Diaz | 78a95a6 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 380 | if ((local_caps & define_psci_cap(psci_fid)) == 0U) |
Soby Mathew | 6cdddaf | 2015-01-07 11:10:22 +0000 | [diff] [blame] | 381 | return PSCI_E_NOT_SUPPORTED; |
| 382 | |
| 383 | /* Format the feature flags */ |
Antonio Nino Diaz | 78a95a6 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 384 | if ((psci_fid == PSCI_CPU_SUSPEND_AARCH32) || |
| 385 | (psci_fid == PSCI_CPU_SUSPEND_AARCH64)) { |
Antonio Nino Diaz | 78a95a6 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 386 | unsigned int ret = ((FF_PSTATE << FF_PSTATE_SHIFT) | |
Wing Li | d28393a | 2022-09-14 13:18:19 -0700 | [diff] [blame] | 387 | (FF_SUPPORTS_OS_INIT_MODE << FF_MODE_SUPPORT_SHIFT)); |
| 388 | return (int)ret; |
Soby Mathew | 6cdddaf | 2015-01-07 11:10:22 +0000 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | /* Return 0 for all other fid's */ |
| 392 | return PSCI_E_SUCCESS; |
| 393 | } |
| 394 | |
Wing Li | 71f69df | 2022-09-14 13:18:15 -0700 | [diff] [blame] | 395 | #if PSCI_OS_INIT_MODE |
| 396 | int psci_set_suspend_mode(unsigned int mode) |
| 397 | { |
| 398 | if (psci_suspend_mode == mode) { |
| 399 | return PSCI_E_SUCCESS; |
| 400 | } |
| 401 | |
| 402 | if (mode == PLAT_COORD) { |
| 403 | /* Check if the current CPU is the last ON CPU in the system */ |
| 404 | if (!psci_is_last_on_cpu_safe()) { |
| 405 | return PSCI_E_DENIED; |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | if (mode == OS_INIT) { |
| 410 | /* |
| 411 | * Check if all CPUs in the system are ON or if the current |
| 412 | * CPU is the last ON CPU in the system. |
| 413 | */ |
| 414 | if (!(psci_are_all_cpus_on_safe() || |
| 415 | psci_is_last_on_cpu_safe())) { |
| 416 | return PSCI_E_DENIED; |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | psci_suspend_mode = mode; |
| 421 | psci_flush_dcache_range((uintptr_t)&psci_suspend_mode, |
| 422 | sizeof(psci_suspend_mode)); |
| 423 | |
| 424 | return PSCI_E_SUCCESS; |
| 425 | } |
| 426 | #endif |
| 427 | |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 428 | /******************************************************************************* |
| 429 | * PSCI top level handler for servicing SMCs. |
| 430 | ******************************************************************************/ |
Soby Mathew | d019487 | 2016-04-29 19:01:30 +0100 | [diff] [blame] | 431 | u_register_t psci_smc_handler(uint32_t smc_fid, |
Soby Mathew | a0fedc4 | 2016-06-16 14:52:04 +0100 | [diff] [blame] | 432 | u_register_t x1, |
| 433 | u_register_t x2, |
| 434 | u_register_t x3, |
| 435 | u_register_t x4, |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 436 | void *cookie, |
| 437 | void *handle, |
Soby Mathew | a0fedc4 | 2016-06-16 14:52:04 +0100 | [diff] [blame] | 438 | u_register_t flags) |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 439 | { |
Antonio Nino Diaz | 78a95a6 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 440 | u_register_t ret; |
| 441 | |
Andrew Thoelke | 89a3c84 | 2014-06-10 16:37:37 +0100 | [diff] [blame] | 442 | if (is_caller_secure(flags)) |
Antonio Nino Diaz | 78a95a6 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 443 | return (u_register_t)SMC_UNK; |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 444 | |
Soby Mathew | 61e615b | 2015-01-15 11:49:49 +0000 | [diff] [blame] | 445 | /* Check the fid against the capabilities */ |
Antonio Nino Diaz | 78a95a6 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 446 | if ((psci_caps & define_psci_cap(smc_fid)) == 0U) |
| 447 | return (u_register_t)SMC_UNK; |
Soby Mathew | 61e615b | 2015-01-15 11:49:49 +0000 | [diff] [blame] | 448 | |
Andrew Thoelke | 89a3c84 | 2014-06-10 16:37:37 +0100 | [diff] [blame] | 449 | if (((smc_fid >> FUNCID_CC_SHIFT) & FUNCID_CC_MASK) == SMC_32) { |
| 450 | /* 32-bit PSCI function, clear top parameter bits */ |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 451 | |
Antonio Nino Diaz | 78a95a6 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 452 | uint32_t r1 = (uint32_t)x1; |
| 453 | uint32_t r2 = (uint32_t)x2; |
| 454 | uint32_t r3 = (uint32_t)x3; |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 455 | |
Andrew Thoelke | 89a3c84 | 2014-06-10 16:37:37 +0100 | [diff] [blame] | 456 | switch (smc_fid) { |
| 457 | case PSCI_VERSION: |
Antonio Nino Diaz | 78a95a6 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 458 | ret = (u_register_t)psci_version(); |
| 459 | break; |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 460 | |
Andrew Thoelke | 89a3c84 | 2014-06-10 16:37:37 +0100 | [diff] [blame] | 461 | case PSCI_CPU_OFF: |
Antonio Nino Diaz | 78a95a6 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 462 | ret = (u_register_t)psci_cpu_off(); |
| 463 | break; |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 464 | |
Andrew Thoelke | 89a3c84 | 2014-06-10 16:37:37 +0100 | [diff] [blame] | 465 | case PSCI_CPU_SUSPEND_AARCH32: |
Antonio Nino Diaz | 78a95a6 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 466 | ret = (u_register_t)psci_cpu_suspend(r1, r2, r3); |
| 467 | break; |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 468 | |
Andrew Thoelke | 89a3c84 | 2014-06-10 16:37:37 +0100 | [diff] [blame] | 469 | case PSCI_CPU_ON_AARCH32: |
Antonio Nino Diaz | 78a95a6 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 470 | ret = (u_register_t)psci_cpu_on(r1, r2, r3); |
| 471 | break; |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 472 | |
Andrew Thoelke | 89a3c84 | 2014-06-10 16:37:37 +0100 | [diff] [blame] | 473 | case PSCI_AFFINITY_INFO_AARCH32: |
Antonio Nino Diaz | 78a95a6 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 474 | ret = (u_register_t)psci_affinity_info(r1, r2); |
| 475 | break; |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 476 | |
Andrew Thoelke | 89a3c84 | 2014-06-10 16:37:37 +0100 | [diff] [blame] | 477 | case PSCI_MIG_AARCH32: |
Antonio Nino Diaz | 78a95a6 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 478 | ret = (u_register_t)psci_migrate(r1); |
| 479 | break; |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 480 | |
Andrew Thoelke | 89a3c84 | 2014-06-10 16:37:37 +0100 | [diff] [blame] | 481 | case PSCI_MIG_INFO_TYPE: |
Antonio Nino Diaz | 78a95a6 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 482 | ret = (u_register_t)psci_migrate_info_type(); |
| 483 | break; |
Andrew Thoelke | 89a3c84 | 2014-06-10 16:37:37 +0100 | [diff] [blame] | 484 | |
| 485 | case PSCI_MIG_INFO_UP_CPU_AARCH32: |
Antonio Nino Diaz | 78a95a6 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 486 | ret = psci_migrate_info_up_cpu(); |
| 487 | break; |
Andrew Thoelke | 89a3c84 | 2014-06-10 16:37:37 +0100 | [diff] [blame] | 488 | |
Jeenu Viswambharan | 7f03e9d9 | 2016-08-03 15:54:50 +0100 | [diff] [blame] | 489 | case PSCI_NODE_HW_STATE_AARCH32: |
Antonio Nino Diaz | 78a95a6 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 490 | ret = (u_register_t)psci_node_hw_state(r1, r2); |
| 491 | break; |
Jeenu Viswambharan | 7f03e9d9 | 2016-08-03 15:54:50 +0100 | [diff] [blame] | 492 | |
Soby Mathew | 9616838 | 2014-12-17 14:47:57 +0000 | [diff] [blame] | 493 | case PSCI_SYSTEM_SUSPEND_AARCH32: |
Antonio Nino Diaz | 78a95a6 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 494 | ret = (u_register_t)psci_system_suspend(r1, r2); |
| 495 | break; |
Soby Mathew | 9616838 | 2014-12-17 14:47:57 +0000 | [diff] [blame] | 496 | |
Juan Castillo | 4dc4a47 | 2014-08-12 11:17:06 +0100 | [diff] [blame] | 497 | case PSCI_SYSTEM_OFF: |
| 498 | psci_system_off(); |
| 499 | /* We should never return from psci_system_off() */ |
Jonathan Wright | de70183 | 2018-03-13 17:45:42 +0000 | [diff] [blame] | 500 | break; |
Juan Castillo | 4dc4a47 | 2014-08-12 11:17:06 +0100 | [diff] [blame] | 501 | |
| 502 | case PSCI_SYSTEM_RESET: |
| 503 | psci_system_reset(); |
| 504 | /* We should never return from psci_system_reset() */ |
Jonathan Wright | de70183 | 2018-03-13 17:45:42 +0000 | [diff] [blame] | 505 | break; |
Juan Castillo | 4dc4a47 | 2014-08-12 11:17:06 +0100 | [diff] [blame] | 506 | |
Soby Mathew | 6cdddaf | 2015-01-07 11:10:22 +0000 | [diff] [blame] | 507 | case PSCI_FEATURES: |
Antonio Nino Diaz | 78a95a6 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 508 | ret = (u_register_t)psci_features(r1); |
| 509 | break; |
Wing Li | 71f69df | 2022-09-14 13:18:15 -0700 | [diff] [blame] | 510 | |
| 511 | #if PSCI_OS_INIT_MODE |
| 512 | case PSCI_SET_SUSPEND_MODE: |
| 513 | ret = (u_register_t)psci_set_suspend_mode(r1); |
| 514 | break; |
| 515 | #endif |
Soby Mathew | 6cdddaf | 2015-01-07 11:10:22 +0000 | [diff] [blame] | 516 | |
Yatharth Kochar | 241ec6c | 2016-05-09 18:26:35 +0100 | [diff] [blame] | 517 | #if ENABLE_PSCI_STAT |
| 518 | case PSCI_STAT_RESIDENCY_AARCH32: |
Antonio Nino Diaz | 78a95a6 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 519 | ret = psci_stat_residency(r1, r2); |
| 520 | break; |
Yatharth Kochar | 241ec6c | 2016-05-09 18:26:35 +0100 | [diff] [blame] | 521 | |
| 522 | case PSCI_STAT_COUNT_AARCH32: |
Antonio Nino Diaz | 78a95a6 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 523 | ret = psci_stat_count(r1, r2); |
| 524 | break; |
Yatharth Kochar | 241ec6c | 2016-05-09 18:26:35 +0100 | [diff] [blame] | 525 | #endif |
Roberto Vargas | 0a4c261 | 2017-08-03 08:16:16 +0100 | [diff] [blame] | 526 | case PSCI_MEM_PROTECT: |
Antonio Nino Diaz | 78a95a6 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 527 | ret = psci_mem_protect(r1); |
| 528 | break; |
Roberto Vargas | 0a4c261 | 2017-08-03 08:16:16 +0100 | [diff] [blame] | 529 | |
| 530 | case PSCI_MEM_CHK_RANGE_AARCH32: |
Antonio Nino Diaz | 78a95a6 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 531 | ret = psci_mem_chk_range(r1, r2); |
| 532 | break; |
Yatharth Kochar | 241ec6c | 2016-05-09 18:26:35 +0100 | [diff] [blame] | 533 | |
Roberto Vargas | b820ad0 | 2017-07-26 09:23:09 +0100 | [diff] [blame] | 534 | case PSCI_SYSTEM_RESET2_AARCH32: |
| 535 | /* We should never return from psci_system_reset2() */ |
Antonio Nino Diaz | 78a95a6 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 536 | ret = psci_system_reset2(r1, r2); |
| 537 | break; |
Roberto Vargas | b820ad0 | 2017-07-26 09:23:09 +0100 | [diff] [blame] | 538 | |
Andrew Thoelke | 89a3c84 | 2014-06-10 16:37:37 +0100 | [diff] [blame] | 539 | default: |
Antonio Nino Diaz | 78a95a6 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 540 | WARN("Unimplemented PSCI Call: 0x%x\n", smc_fid); |
| 541 | ret = (u_register_t)SMC_UNK; |
Andrew Thoelke | 89a3c84 | 2014-06-10 16:37:37 +0100 | [diff] [blame] | 542 | break; |
| 543 | } |
| 544 | } else { |
| 545 | /* 64-bit PSCI function */ |
| 546 | |
| 547 | switch (smc_fid) { |
| 548 | case PSCI_CPU_SUSPEND_AARCH64: |
Antonio Nino Diaz | 78a95a6 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 549 | ret = (u_register_t) |
| 550 | psci_cpu_suspend((unsigned int)x1, x2, x3); |
| 551 | break; |
Andrew Thoelke | 89a3c84 | 2014-06-10 16:37:37 +0100 | [diff] [blame] | 552 | |
| 553 | case PSCI_CPU_ON_AARCH64: |
Antonio Nino Diaz | 78a95a6 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 554 | ret = (u_register_t)psci_cpu_on(x1, x2, x3); |
| 555 | break; |
Andrew Thoelke | 89a3c84 | 2014-06-10 16:37:37 +0100 | [diff] [blame] | 556 | |
| 557 | case PSCI_AFFINITY_INFO_AARCH64: |
Antonio Nino Diaz | 78a95a6 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 558 | ret = (u_register_t) |
| 559 | psci_affinity_info(x1, (unsigned int)x2); |
| 560 | break; |
Andrew Thoelke | 89a3c84 | 2014-06-10 16:37:37 +0100 | [diff] [blame] | 561 | |
| 562 | case PSCI_MIG_AARCH64: |
Antonio Nino Diaz | 78a95a6 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 563 | ret = (u_register_t)psci_migrate(x1); |
| 564 | break; |
Andrew Thoelke | 89a3c84 | 2014-06-10 16:37:37 +0100 | [diff] [blame] | 565 | |
| 566 | case PSCI_MIG_INFO_UP_CPU_AARCH64: |
Antonio Nino Diaz | 78a95a6 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 567 | ret = psci_migrate_info_up_cpu(); |
| 568 | break; |
Andrew Thoelke | 89a3c84 | 2014-06-10 16:37:37 +0100 | [diff] [blame] | 569 | |
Jeenu Viswambharan | 7f03e9d9 | 2016-08-03 15:54:50 +0100 | [diff] [blame] | 570 | case PSCI_NODE_HW_STATE_AARCH64: |
Antonio Nino Diaz | 78a95a6 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 571 | ret = (u_register_t)psci_node_hw_state( |
| 572 | x1, (unsigned int) x2); |
| 573 | break; |
Jeenu Viswambharan | 7f03e9d9 | 2016-08-03 15:54:50 +0100 | [diff] [blame] | 574 | |
Soby Mathew | 9616838 | 2014-12-17 14:47:57 +0000 | [diff] [blame] | 575 | case PSCI_SYSTEM_SUSPEND_AARCH64: |
Antonio Nino Diaz | 78a95a6 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 576 | ret = (u_register_t)psci_system_suspend(x1, x2); |
| 577 | break; |
Soby Mathew | 9616838 | 2014-12-17 14:47:57 +0000 | [diff] [blame] | 578 | |
Yatharth Kochar | 241ec6c | 2016-05-09 18:26:35 +0100 | [diff] [blame] | 579 | #if ENABLE_PSCI_STAT |
| 580 | case PSCI_STAT_RESIDENCY_AARCH64: |
Antonio Nino Diaz | 78a95a6 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 581 | ret = psci_stat_residency(x1, (unsigned int) x2); |
| 582 | break; |
Yatharth Kochar | 241ec6c | 2016-05-09 18:26:35 +0100 | [diff] [blame] | 583 | |
| 584 | case PSCI_STAT_COUNT_AARCH64: |
Antonio Nino Diaz | 78a95a6 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 585 | ret = psci_stat_count(x1, (unsigned int) x2); |
| 586 | break; |
Yatharth Kochar | 241ec6c | 2016-05-09 18:26:35 +0100 | [diff] [blame] | 587 | #endif |
| 588 | |
Roberto Vargas | 0a4c261 | 2017-08-03 08:16:16 +0100 | [diff] [blame] | 589 | case PSCI_MEM_CHK_RANGE_AARCH64: |
Antonio Nino Diaz | 78a95a6 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 590 | ret = psci_mem_chk_range(x1, x2); |
| 591 | break; |
Roberto Vargas | 0a4c261 | 2017-08-03 08:16:16 +0100 | [diff] [blame] | 592 | |
Roberto Vargas | b820ad0 | 2017-07-26 09:23:09 +0100 | [diff] [blame] | 593 | case PSCI_SYSTEM_RESET2_AARCH64: |
| 594 | /* We should never return from psci_system_reset2() */ |
Antonio Nino Diaz | 78a95a6 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 595 | ret = psci_system_reset2((uint32_t) x1, x2); |
| 596 | break; |
Roberto Vargas | 0a4c261 | 2017-08-03 08:16:16 +0100 | [diff] [blame] | 597 | |
Andrew Thoelke | 89a3c84 | 2014-06-10 16:37:37 +0100 | [diff] [blame] | 598 | default: |
Antonio Nino Diaz | 78a95a6 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 599 | WARN("Unimplemented PSCI Call: 0x%x\n", smc_fid); |
| 600 | ret = (u_register_t)SMC_UNK; |
Andrew Thoelke | 89a3c84 | 2014-06-10 16:37:37 +0100 | [diff] [blame] | 601 | break; |
| 602 | } |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 603 | } |
| 604 | |
Antonio Nino Diaz | 78a95a6 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 605 | return ret; |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 606 | } |