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