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