Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 1 | /* |
Boyan Karatotev | 44ee771 | 2024-09-30 13:15:25 +0100 | [diff] [blame^] | 2 | * Copyright (c) 2013-2025, Arm Limited and Contributors. All rights reserved. |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 3 | * |
dp-arm | 82cb2c1 | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
Antonio Nino Diaz | 09d40e0 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 7 | #include <assert.h> |
| 8 | #include <stddef.h> |
| 9 | |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 10 | #include <arch.h> |
| 11 | #include <arch_helpers.h> |
Antonio Nino Diaz | 09d40e0 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 12 | #include <common/bl_common.h> |
| 13 | #include <common/debug.h> |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 14 | #include <context.h> |
Antonio Nino Diaz | 09d40e0 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 15 | #include <lib/el3_runtime/context_mgmt.h> |
| 16 | #include <lib/el3_runtime/cpu_data.h> |
| 17 | #include <lib/el3_runtime/pubsub_events.h> |
| 18 | #include <lib/pmf/pmf.h> |
| 19 | #include <lib/runtime_instr.h> |
| 20 | #include <plat/common/platform.h> |
| 21 | |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 22 | #include "psci_private.h" |
| 23 | |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 24 | /******************************************************************************* |
Soby Mathew | 8ee2498 | 2015-04-07 12:16:56 +0100 | [diff] [blame] | 25 | * This function does generic and platform specific operations after a wake-up |
| 26 | * from standby/retention states at multiple power levels. |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 27 | ******************************************************************************/ |
Boyan Karatotev | 44ee771 | 2024-09-30 13:15:25 +0100 | [diff] [blame^] | 28 | static void psci_cpu_suspend_to_standby_finish(unsigned int cpu_idx, |
| 29 | unsigned int end_pwrlvl, |
| 30 | psci_power_state_t *state_info) |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 31 | { |
Achin Gupta | 61eae52 | 2016-06-28 16:46:15 +0100 | [diff] [blame] | 32 | /* |
Soby Mathew | 8ee2498 | 2015-04-07 12:16:56 +0100 | [diff] [blame] | 33 | * Plat. management: Allow the platform to do operations |
| 34 | * on waking up from retention. |
| 35 | */ |
Boyan Karatotev | 44ee771 | 2024-09-30 13:15:25 +0100 | [diff] [blame^] | 36 | psci_plat_pm_ops->pwr_domain_suspend_finish(state_info); |
Soby Mathew | 8ee2498 | 2015-04-07 12:16:56 +0100 | [diff] [blame] | 37 | |
Boyan Karatotev | 0c83655 | 2024-09-30 11:31:55 +0100 | [diff] [blame] | 38 | /* This loses its meaning when not suspending, reset so it's correct for OFF */ |
| 39 | psci_set_suspend_pwrlvl(PLAT_MAX_PWR_LVL); |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | /******************************************************************************* |
Soby Mathew | 8ee2498 | 2015-04-07 12:16:56 +0100 | [diff] [blame] | 43 | * This function does generic and platform specific suspend to power down |
| 44 | * operations. |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 45 | ******************************************************************************/ |
Soby Mathew | 9d070b9 | 2015-07-29 17:05:03 +0100 | [diff] [blame] | 46 | static void psci_suspend_to_pwrdown_start(unsigned int end_pwrlvl, |
Antonio Nino Diaz | 621d64f | 2018-07-16 23:19:25 +0100 | [diff] [blame] | 47 | const entry_point_info_t *ep, |
| 48 | const psci_power_state_t *state_info) |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 49 | { |
Achin Gupta | f1054c9 | 2015-09-07 20:43:27 +0100 | [diff] [blame] | 50 | unsigned int max_off_lvl = psci_find_max_off_lvl(state_info); |
| 51 | |
Dimitris Papastamos | 7593252 | 2017-11-28 15:16:00 +0000 | [diff] [blame] | 52 | PUBLISH_EVENT(psci_suspend_pwrdown_start); |
| 53 | |
Wing Li | 606b743 | 2022-09-14 13:18:17 -0700 | [diff] [blame] | 54 | #if PSCI_OS_INIT_MODE |
| 55 | #ifdef PLAT_MAX_CPU_SUSPEND_PWR_LVL |
| 56 | end_pwrlvl = PLAT_MAX_CPU_SUSPEND_PWR_LVL; |
| 57 | #else |
| 58 | end_pwrlvl = PLAT_MAX_PWR_LVL; |
| 59 | #endif |
| 60 | #endif |
| 61 | |
Soby Mathew | 8ee2498 | 2015-04-07 12:16:56 +0100 | [diff] [blame] | 62 | /* Save PSCI target power level for the suspend finisher handler */ |
| 63 | psci_set_suspend_pwrlvl(end_pwrlvl); |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 64 | |
Soby Mathew | 8ee2498 | 2015-04-07 12:16:56 +0100 | [diff] [blame] | 65 | /* |
Jeenu Viswambharan | a10d363 | 2017-01-06 14:58:11 +0000 | [diff] [blame] | 66 | * Flush the target power level as it might be accessed on power up with |
Soby Mathew | 8ee2498 | 2015-04-07 12:16:56 +0100 | [diff] [blame] | 67 | * Data cache disabled. |
| 68 | */ |
Jeenu Viswambharan | a10d363 | 2017-01-06 14:58:11 +0000 | [diff] [blame] | 69 | psci_flush_cpu_data(psci_svc_cpu_data.target_pwrlvl); |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 70 | |
Soby Mathew | 8ee2498 | 2015-04-07 12:16:56 +0100 | [diff] [blame] | 71 | /* |
| 72 | * Call the cpu suspend handler registered by the Secure Payload |
| 73 | * Dispatcher to let it do any book-keeping. If the handler encounters an |
| 74 | * error, it's expected to assert within |
| 75 | */ |
Antonio Nino Diaz | 621d64f | 2018-07-16 23:19:25 +0100 | [diff] [blame] | 76 | if ((psci_spd_pm != NULL) && (psci_spd_pm->svc_suspend != NULL)) |
Achin Gupta | f1054c9 | 2015-09-07 20:43:27 +0100 | [diff] [blame] | 77 | psci_spd_pm->svc_suspend(max_off_lvl); |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 78 | |
Varun Wadekar | 1862d62 | 2017-07-10 16:02:05 -0700 | [diff] [blame] | 79 | #if !HW_ASSISTED_COHERENCY |
| 80 | /* |
| 81 | * Plat. management: Allow the platform to perform any early |
| 82 | * actions required to power down the CPU. This might be useful for |
| 83 | * HW_ASSISTED_COHERENCY = 0 platforms that can safely perform these |
| 84 | * actions with data caches enabled. |
| 85 | */ |
Antonio Nino Diaz | 621d64f | 2018-07-16 23:19:25 +0100 | [diff] [blame] | 86 | if (psci_plat_pm_ops->pwr_domain_suspend_pwrdown_early != NULL) |
Varun Wadekar | 1862d62 | 2017-07-10 16:02:05 -0700 | [diff] [blame] | 87 | psci_plat_pm_ops->pwr_domain_suspend_pwrdown_early(state_info); |
| 88 | #endif |
| 89 | |
Soby Mathew | 8ee2498 | 2015-04-07 12:16:56 +0100 | [diff] [blame] | 90 | /* |
| 91 | * Store the re-entry information for the non-secure world. |
| 92 | */ |
| 93 | cm_init_my_context(ep); |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 94 | |
dp-arm | 7941816 | 2016-11-15 13:25:30 +0000 | [diff] [blame] | 95 | #if ENABLE_RUNTIME_INSTRUMENTATION |
| 96 | |
| 97 | /* |
| 98 | * Flush cache line so that even if CPU power down happens |
| 99 | * the timestamp update is reflected in memory. |
| 100 | */ |
| 101 | PMF_CAPTURE_TIMESTAMP(rt_instr_svc, |
| 102 | RT_INSTR_ENTER_CFLUSH, |
| 103 | PMF_CACHE_MAINT); |
| 104 | #endif |
| 105 | |
Soby Mathew | 8ee2498 | 2015-04-07 12:16:56 +0100 | [diff] [blame] | 106 | /* |
Jeenu Viswambharan | b0408e8 | 2017-01-05 11:01:02 +0000 | [diff] [blame] | 107 | * Arch. management. Initiate power down sequence. |
Soby Mathew | 8ee2498 | 2015-04-07 12:16:56 +0100 | [diff] [blame] | 108 | * TODO : Introduce a mechanism to query the cache level to flush |
| 109 | * and the cpu-ops power down to perform from the platform. |
| 110 | */ |
Pranav Madhu | 65bbb93 | 2022-07-22 23:11:16 +0530 | [diff] [blame] | 111 | psci_pwrdown_cpu(max_off_lvl); |
dp-arm | 7941816 | 2016-11-15 13:25:30 +0000 | [diff] [blame] | 112 | |
| 113 | #if ENABLE_RUNTIME_INSTRUMENTATION |
| 114 | PMF_CAPTURE_TIMESTAMP(rt_instr_svc, |
| 115 | RT_INSTR_EXIT_CFLUSH, |
| 116 | PMF_NO_CACHE_MAINT); |
| 117 | #endif |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | /******************************************************************************* |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 121 | * Top level handler which is called when a cpu wants to suspend its execution. |
Soby Mathew | 4067dc3 | 2015-05-05 16:33:16 +0100 | [diff] [blame] | 122 | * It is assumed that along with suspending the cpu power domain, power domains |
Soby Mathew | 8ee2498 | 2015-04-07 12:16:56 +0100 | [diff] [blame] | 123 | * at higher levels until the target power level will be suspended as well. It |
| 124 | * coordinates with the platform to negotiate the target state for each of |
| 125 | * the power domain level till the target power domain level. It then performs |
| 126 | * generic, architectural, platform setup and state management required to |
| 127 | * suspend that power domain level and power domain levels below it. |
| 128 | * e.g. For a cpu that's to be suspended, it could mean programming the |
| 129 | * power controller whereas for a cluster that's to be suspended, it will call |
| 130 | * the platform specific code which will disable coherency at the interconnect |
| 131 | * level if the cpu is the last in the cluster and also the program the power |
| 132 | * controller. |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 133 | * |
| 134 | * All the required parameter checks are performed at the beginning and after |
Soby Mathew | 6590ce2 | 2015-06-30 11:00:24 +0100 | [diff] [blame] | 135 | * the state transition has been done, no further error is expected and it is |
| 136 | * not possible to undo any of the actions taken beyond that point. |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 137 | ******************************************************************************/ |
Wing Li | 606b743 | 2022-09-14 13:18:17 -0700 | [diff] [blame] | 138 | int psci_cpu_suspend_start(const entry_point_info_t *ep, |
| 139 | unsigned int end_pwrlvl, |
| 140 | psci_power_state_t *state_info, |
| 141 | unsigned int is_power_down_state) |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 142 | { |
Wing Li | 606b743 | 2022-09-14 13:18:17 -0700 | [diff] [blame] | 143 | int rc = PSCI_E_SUCCESS; |
| 144 | bool skip_wfi = false; |
Deepika Bhavnani | 5b33ad1 | 2019-12-13 10:23:18 -0600 | [diff] [blame] | 145 | unsigned int idx = plat_my_core_pos(); |
Andrew F. Davis | 74d27d0 | 2019-06-04 10:46:54 -0400 | [diff] [blame] | 146 | unsigned int parent_nodes[PLAT_MAX_PWR_LVL] = {0}; |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 147 | |
| 148 | /* |
| 149 | * This function must only be called on platforms where the |
| 150 | * CPU_SUSPEND platform hooks have been implemented. |
| 151 | */ |
Antonio Nino Diaz | 621d64f | 2018-07-16 23:19:25 +0100 | [diff] [blame] | 152 | assert((psci_plat_pm_ops->pwr_domain_suspend != NULL) && |
| 153 | (psci_plat_pm_ops->pwr_domain_suspend_finish != NULL)); |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 154 | |
Andrew F. Davis | 74d27d0 | 2019-06-04 10:46:54 -0400 | [diff] [blame] | 155 | /* Get the parent nodes */ |
| 156 | psci_get_parent_pwr_domain_nodes(idx, end_pwrlvl, parent_nodes); |
| 157 | |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 158 | /* |
Soby Mathew | 4067dc3 | 2015-05-05 16:33:16 +0100 | [diff] [blame] | 159 | * This function acquires the lock corresponding to each power |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 160 | * level so that by the time all locks are taken, the system topology |
| 161 | * is snapshot and state management can be done safely. |
| 162 | */ |
Andrew F. Davis | 74d27d0 | 2019-06-04 10:46:54 -0400 | [diff] [blame] | 163 | psci_acquire_pwr_domain_locks(end_pwrlvl, parent_nodes); |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 164 | |
| 165 | /* |
| 166 | * We check if there are any pending interrupts after the delay |
| 167 | * introduced by lock contention to increase the chances of early |
| 168 | * detection that a wake-up interrupt has fired. |
| 169 | */ |
Antonio Nino Diaz | 621d64f | 2018-07-16 23:19:25 +0100 | [diff] [blame] | 170 | if (read_isr_el1() != 0U) { |
Wing Li | 606b743 | 2022-09-14 13:18:17 -0700 | [diff] [blame] | 171 | skip_wfi = true; |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 172 | goto exit; |
| 173 | } |
| 174 | |
Wing Li | 606b743 | 2022-09-14 13:18:17 -0700 | [diff] [blame] | 175 | #if PSCI_OS_INIT_MODE |
| 176 | if (psci_suspend_mode == OS_INIT) { |
| 177 | /* |
| 178 | * This function validates the requested state info for |
| 179 | * OS-initiated mode. |
| 180 | */ |
| 181 | rc = psci_validate_state_coordination(end_pwrlvl, state_info); |
| 182 | if (rc != PSCI_E_SUCCESS) { |
| 183 | skip_wfi = true; |
| 184 | goto exit; |
| 185 | } |
| 186 | } else { |
| 187 | #endif |
| 188 | /* |
| 189 | * This function is passed the requested state info and |
| 190 | * it returns the negotiated state info for each power level upto |
| 191 | * the end level specified. |
| 192 | */ |
| 193 | psci_do_state_coordination(end_pwrlvl, state_info); |
| 194 | #if PSCI_OS_INIT_MODE |
| 195 | } |
| 196 | #endif |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 197 | |
Wing Li | d348861 | 2023-05-04 08:31:19 -0700 | [diff] [blame] | 198 | #if PSCI_OS_INIT_MODE |
| 199 | if (psci_plat_pm_ops->pwr_domain_validate_suspend != NULL) { |
| 200 | rc = psci_plat_pm_ops->pwr_domain_validate_suspend(state_info); |
| 201 | if (rc != PSCI_E_SUCCESS) { |
| 202 | skip_wfi = true; |
| 203 | goto exit; |
| 204 | } |
| 205 | } |
| 206 | #endif |
| 207 | |
| 208 | /* Update the target state in the power domain nodes */ |
| 209 | psci_set_target_local_pwr_states(end_pwrlvl, state_info); |
| 210 | |
Yatharth Kochar | 170fb93 | 2016-05-09 18:26:35 +0100 | [diff] [blame] | 211 | #if ENABLE_PSCI_STAT |
| 212 | /* Update the last cpu for each level till end_pwrlvl */ |
| 213 | psci_stats_update_pwr_down(end_pwrlvl, state_info); |
| 214 | #endif |
| 215 | |
Antonio Nino Diaz | 621d64f | 2018-07-16 23:19:25 +0100 | [diff] [blame] | 216 | if (is_power_down_state != 0U) |
Soby Mathew | 8ee2498 | 2015-04-07 12:16:56 +0100 | [diff] [blame] | 217 | psci_suspend_to_pwrdown_start(end_pwrlvl, ep, state_info); |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 218 | |
Soby Mathew | 6590ce2 | 2015-06-30 11:00:24 +0100 | [diff] [blame] | 219 | /* |
| 220 | * Plat. management: Allow the platform to perform the |
| 221 | * necessary actions to turn off this cpu e.g. set the |
| 222 | * platform defined mailbox with the psci entrypoint, |
| 223 | * program the power controller etc. |
| 224 | */ |
Wing Li | 606b743 | 2022-09-14 13:18:17 -0700 | [diff] [blame] | 225 | |
Sandrine Bailleux | eb975f5 | 2015-06-11 10:46:48 +0100 | [diff] [blame] | 226 | psci_plat_pm_ops->pwr_domain_suspend(state_info); |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 227 | |
Yatharth Kochar | 170fb93 | 2016-05-09 18:26:35 +0100 | [diff] [blame] | 228 | #if ENABLE_PSCI_STAT |
dp-arm | 04c1db1 | 2017-01-31 13:01:04 +0000 | [diff] [blame] | 229 | plat_psci_stat_accounting_start(state_info); |
Yatharth Kochar | 170fb93 | 2016-05-09 18:26:35 +0100 | [diff] [blame] | 230 | #endif |
| 231 | |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 232 | exit: |
| 233 | /* |
Soby Mathew | 4067dc3 | 2015-05-05 16:33:16 +0100 | [diff] [blame] | 234 | * Release the locks corresponding to each power level in the |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 235 | * reverse order to which they were acquired. |
| 236 | */ |
Andrew F. Davis | 74d27d0 | 2019-06-04 10:46:54 -0400 | [diff] [blame] | 237 | psci_release_pwr_domain_locks(end_pwrlvl, parent_nodes); |
| 238 | |
Wing Li | 606b743 | 2022-09-14 13:18:17 -0700 | [diff] [blame] | 239 | if (skip_wfi) { |
| 240 | return rc; |
| 241 | } |
Soby Mathew | 8ee2498 | 2015-04-07 12:16:56 +0100 | [diff] [blame] | 242 | |
Antonio Nino Diaz | 621d64f | 2018-07-16 23:19:25 +0100 | [diff] [blame] | 243 | if (is_power_down_state != 0U) { |
dp-arm | 872be88 | 2016-09-19 11:18:44 +0100 | [diff] [blame] | 244 | #if ENABLE_RUNTIME_INSTRUMENTATION |
| 245 | |
| 246 | /* |
| 247 | * Update the timestamp with cache off. We assume this |
| 248 | * timestamp can only be read from the current CPU and the |
| 249 | * timestamp cache line will be flushed before return to |
| 250 | * normal world on wakeup. |
| 251 | */ |
| 252 | PMF_CAPTURE_TIMESTAMP(rt_instr_svc, |
| 253 | RT_INSTR_ENTER_HW_LOW_PWR, |
| 254 | PMF_NO_CACHE_MAINT); |
| 255 | #endif |
| 256 | |
Soby Mathew | ac1cc8e | 2016-04-27 14:46:28 +0100 | [diff] [blame] | 257 | /* The function calls below must not return */ |
Antonio Nino Diaz | 621d64f | 2018-07-16 23:19:25 +0100 | [diff] [blame] | 258 | if (psci_plat_pm_ops->pwr_domain_pwr_down_wfi != NULL) |
Soby Mathew | ac1cc8e | 2016-04-27 14:46:28 +0100 | [diff] [blame] | 259 | psci_plat_pm_ops->pwr_domain_pwr_down_wfi(state_info); |
| 260 | else |
| 261 | psci_power_down_wfi(); |
| 262 | } |
Soby Mathew | 8ee2498 | 2015-04-07 12:16:56 +0100 | [diff] [blame] | 263 | |
dp-arm | 872be88 | 2016-09-19 11:18:44 +0100 | [diff] [blame] | 264 | #if ENABLE_RUNTIME_INSTRUMENTATION |
| 265 | PMF_CAPTURE_TIMESTAMP(rt_instr_svc, |
| 266 | RT_INSTR_ENTER_HW_LOW_PWR, |
| 267 | PMF_NO_CACHE_MAINT); |
| 268 | #endif |
| 269 | |
Soby Mathew | 8ee2498 | 2015-04-07 12:16:56 +0100 | [diff] [blame] | 270 | /* |
| 271 | * We will reach here if only retention/standby states have been |
| 272 | * requested at multiple power levels. This means that the cpu |
| 273 | * context will be preserved. |
| 274 | */ |
| 275 | wfi(); |
| 276 | |
dp-arm | 872be88 | 2016-09-19 11:18:44 +0100 | [diff] [blame] | 277 | #if ENABLE_RUNTIME_INSTRUMENTATION |
| 278 | PMF_CAPTURE_TIMESTAMP(rt_instr_svc, |
| 279 | RT_INSTR_EXIT_HW_LOW_PWR, |
| 280 | PMF_NO_CACHE_MAINT); |
| 281 | #endif |
| 282 | |
Boyan Karatotev | 44ee771 | 2024-09-30 13:15:25 +0100 | [diff] [blame^] | 283 | psci_acquire_pwr_domain_locks(end_pwrlvl, parent_nodes); |
| 284 | /* |
| 285 | * Find out which retention states this CPU has exited from until the |
| 286 | * 'end_pwrlvl'. The exit retention state could be deeper than the entry |
| 287 | * state as a result of state coordination amongst other CPUs post wfi. |
| 288 | */ |
| 289 | psci_get_target_local_pwr_states(end_pwrlvl, state_info); |
| 290 | |
| 291 | #if ENABLE_PSCI_STAT |
| 292 | plat_psci_stat_accounting_stop(state_info); |
| 293 | psci_stats_update_pwr_up(end_pwrlvl, state_info); |
| 294 | #endif |
| 295 | |
Soby Mathew | 8ee2498 | 2015-04-07 12:16:56 +0100 | [diff] [blame] | 296 | /* |
| 297 | * After we wake up from context retaining suspend, call the |
| 298 | * context retaining suspend finisher. |
| 299 | */ |
Boyan Karatotev | 44ee771 | 2024-09-30 13:15:25 +0100 | [diff] [blame^] | 300 | psci_cpu_suspend_to_standby_finish(idx, end_pwrlvl, state_info); |
| 301 | |
| 302 | /* |
| 303 | * Set the requested and target state of this CPU and all the higher |
| 304 | * power domain levels for this CPU to run. |
| 305 | */ |
| 306 | psci_set_pwr_domains_to_run(end_pwrlvl); |
| 307 | |
| 308 | psci_release_pwr_domain_locks(end_pwrlvl, parent_nodes); |
Wing Li | 606b743 | 2022-09-14 13:18:17 -0700 | [diff] [blame] | 309 | |
| 310 | return rc; |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | /******************************************************************************* |
Soby Mathew | 4067dc3 | 2015-05-05 16:33:16 +0100 | [diff] [blame] | 314 | * The following functions finish an earlier suspend request. They |
Soby Mathew | 8ee2498 | 2015-04-07 12:16:56 +0100 | [diff] [blame] | 315 | * are called by the common finisher routine in psci_common.c. The `state_info` |
| 316 | * is the psci_power_state from which this CPU has woken up from. |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 317 | ******************************************************************************/ |
Boyan Karatotev | 44ee771 | 2024-09-30 13:15:25 +0100 | [diff] [blame^] | 318 | void psci_cpu_suspend_to_powerdown_finish(unsigned int cpu_idx, const psci_power_state_t *state_info) |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 319 | { |
Antonio Nino Diaz | d448639 | 2016-05-18 16:53:31 +0100 | [diff] [blame] | 320 | unsigned int counter_freq; |
Achin Gupta | f1054c9 | 2015-09-07 20:43:27 +0100 | [diff] [blame] | 321 | unsigned int max_off_lvl; |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 322 | |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 323 | /* Ensure we have been woken up from a suspended state */ |
Antonio Nino Diaz | 621d64f | 2018-07-16 23:19:25 +0100 | [diff] [blame] | 324 | assert((psci_get_aff_info_state() == AFF_STATE_ON) && |
| 325 | (is_local_state_off( |
| 326 | state_info->pwr_domain_state[PSCI_CPU_PWR_LVL]) != 0)); |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 327 | |
| 328 | /* |
| 329 | * Plat. management: Perform the platform specific actions |
| 330 | * before we change the state of the cpu e.g. enabling the |
| 331 | * gic or zeroing the mailbox register. If anything goes |
| 332 | * wrong then assert as there is no way to recover from this |
| 333 | * situation. |
| 334 | */ |
Soby Mathew | 8ee2498 | 2015-04-07 12:16:56 +0100 | [diff] [blame] | 335 | psci_plat_pm_ops->pwr_domain_suspend_finish(state_info); |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 336 | |
Soby Mathew | bcc3c49 | 2017-04-10 22:35:42 +0100 | [diff] [blame] | 337 | #if !(HW_ASSISTED_COHERENCY || WARMBOOT_ENABLE_DCACHE_EARLY) |
Jeenu Viswambharan | b0408e8 | 2017-01-05 11:01:02 +0000 | [diff] [blame] | 338 | /* Arch. management: Enable the data cache, stack memory maintenance. */ |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 339 | psci_do_pwrup_cache_maintenance(); |
Jeenu Viswambharan | b0408e8 | 2017-01-05 11:01:02 +0000 | [diff] [blame] | 340 | #endif |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 341 | |
| 342 | /* Re-init the cntfrq_el0 register */ |
Antonio Nino Diaz | d448639 | 2016-05-18 16:53:31 +0100 | [diff] [blame] | 343 | counter_freq = plat_get_syscnt_freq2(); |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 344 | write_cntfrq_el0(counter_freq); |
| 345 | |
Alexei Fedorov | ed108b5 | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 346 | #if ENABLE_PAUTH |
| 347 | /* Store APIAKey_EL1 key */ |
| 348 | set_cpu_data(apiakey[0], read_apiakeylo_el1()); |
| 349 | set_cpu_data(apiakey[1], read_apiakeyhi_el1()); |
| 350 | #endif /* ENABLE_PAUTH */ |
| 351 | |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 352 | /* |
| 353 | * Call the cpu suspend finish handler registered by the Secure Payload |
| 354 | * Dispatcher to let it do any bookeeping. If the handler encounters an |
| 355 | * error, it's expected to assert within |
| 356 | */ |
Antonio Nino Diaz | 621d64f | 2018-07-16 23:19:25 +0100 | [diff] [blame] | 357 | if ((psci_spd_pm != NULL) && (psci_spd_pm->svc_suspend_finish != NULL)) { |
Achin Gupta | f1054c9 | 2015-09-07 20:43:27 +0100 | [diff] [blame] | 358 | max_off_lvl = psci_find_max_off_lvl(state_info); |
Antonio Nino Diaz | 621d64f | 2018-07-16 23:19:25 +0100 | [diff] [blame] | 359 | assert(max_off_lvl != PSCI_INVALID_PWR_LVL); |
Achin Gupta | f1054c9 | 2015-09-07 20:43:27 +0100 | [diff] [blame] | 360 | psci_spd_pm->svc_suspend_finish(max_off_lvl); |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 361 | } |
| 362 | |
Boyan Karatotev | 0c83655 | 2024-09-30 11:31:55 +0100 | [diff] [blame] | 363 | /* This loses its meaning when not suspending, reset so it's correct for OFF */ |
| 364 | psci_set_suspend_pwrlvl(PLAT_MAX_PWR_LVL); |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 365 | |
Dimitris Papastamos | 7593252 | 2017-11-28 15:16:00 +0000 | [diff] [blame] | 366 | PUBLISH_EVENT(psci_suspend_pwrdown_finish); |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 367 | } |