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