Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1 | /* |
Alexei Fedorov | d27febf | 2021-09-01 15:41:14 +0100 | [diff] [blame] | 2 | * Copyright (c) 2013-2021, ARM Limited and Contributors. All rights reserved. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
Dan Handley | 2bd4ef2 | 2014-04-09 13:14:54 +0100 | [diff] [blame] | 7 | #include <assert.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 8 | |
Andre Przywara | f3e8cfc | 2022-11-17 16:42:09 +0000 | [diff] [blame] | 9 | #include <arch_features.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 10 | #include <arch_helpers.h> |
| 11 | #include <common/debug.h> |
| 12 | #include <drivers/arm/gicv3.h> |
Antonio Nino Diaz | f13d09a | 2019-01-23 21:50:09 +0000 | [diff] [blame] | 13 | #include <drivers/arm/fvp/fvp_pwrc.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 14 | #include <lib/extensions/spe.h> |
| 15 | #include <lib/mmio.h> |
| 16 | #include <lib/psci/psci.h> |
Antonio Nino Diaz | bd7b740 | 2019-01-25 14:30:04 +0000 | [diff] [blame] | 17 | #include <plat/arm/common/arm_config.h> |
| 18 | #include <plat/arm/common/plat_arm.h> |
Antonio Nino Diaz | a320ecd | 2019-01-15 14:19:50 +0000 | [diff] [blame] | 19 | #include <platform_def.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 20 | |
Dan Handley | ed6ff95 | 2014-05-14 17:44:19 +0100 | [diff] [blame] | 21 | #include "fvp_private.h" |
Ambroise Vincent | b237bca | 2019-02-13 15:58:00 +0000 | [diff] [blame] | 22 | #include "../drivers/arm/gic/v3/gicv3_private.h" |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 23 | |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 24 | |
Soby Mathew | 7799cf7 | 2015-04-16 14:49:09 +0100 | [diff] [blame] | 25 | #if ARM_RECOM_STATE_ID_ENC |
| 26 | /* |
| 27 | * The table storing the valid idle power states. Ensure that the |
| 28 | * array entries are populated in ascending order of state-id to |
| 29 | * enable us to use binary search during power state validation. |
| 30 | * The table must be terminated by a NULL entry. |
| 31 | */ |
| 32 | const unsigned int arm_pm_idle_states[] = { |
| 33 | /* State-id - 0x01 */ |
| 34 | arm_make_pwrstate_lvl1(ARM_LOCAL_STATE_RUN, ARM_LOCAL_STATE_RET, |
| 35 | ARM_PWR_LVL0, PSTATE_TYPE_STANDBY), |
| 36 | /* State-id - 0x02 */ |
| 37 | arm_make_pwrstate_lvl1(ARM_LOCAL_STATE_RUN, ARM_LOCAL_STATE_OFF, |
| 38 | ARM_PWR_LVL0, PSTATE_TYPE_POWERDOWN), |
| 39 | /* State-id - 0x22 */ |
| 40 | arm_make_pwrstate_lvl1(ARM_LOCAL_STATE_OFF, ARM_LOCAL_STATE_OFF, |
| 41 | ARM_PWR_LVL1, PSTATE_TYPE_POWERDOWN), |
Soby Mathew | 9ca2806 | 2017-10-11 16:08:58 +0100 | [diff] [blame] | 42 | /* State-id - 0x222 */ |
| 43 | arm_make_pwrstate_lvl2(ARM_LOCAL_STATE_OFF, ARM_LOCAL_STATE_OFF, |
| 44 | ARM_LOCAL_STATE_OFF, ARM_PWR_LVL2, PSTATE_TYPE_POWERDOWN), |
Soby Mathew | 7799cf7 | 2015-04-16 14:49:09 +0100 | [diff] [blame] | 45 | 0, |
| 46 | }; |
| 47 | #endif |
| 48 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 49 | /******************************************************************************* |
Achin Gupta | 8587639 | 2014-07-31 17:45:51 +0100 | [diff] [blame] | 50 | * Function which implements the common FVP specific operations to power down a |
Achin Gupta | 8587639 | 2014-07-31 17:45:51 +0100 | [diff] [blame] | 51 | * cluster in response to a CPU_OFF or CPU_SUSPEND request. |
| 52 | ******************************************************************************/ |
Sandrine Bailleux | a64a854 | 2015-03-05 10:54:34 +0000 | [diff] [blame] | 53 | static void fvp_cluster_pwrdwn_common(void) |
Achin Gupta | 8587639 | 2014-07-31 17:45:51 +0100 | [diff] [blame] | 54 | { |
| 55 | uint64_t mpidr = read_mpidr_el1(); |
| 56 | |
dp-arm | ee3457b | 2017-05-23 09:32:49 +0100 | [diff] [blame] | 57 | /* |
| 58 | * On power down we need to disable statistical profiling extensions |
| 59 | * before exiting coherency. |
| 60 | */ |
Andre Przywara | f3e8cfc | 2022-11-17 16:42:09 +0000 | [diff] [blame] | 61 | if (is_feat_spe_supported()) { |
| 62 | spe_disable(); |
| 63 | } |
dp-arm | ee3457b | 2017-05-23 09:32:49 +0100 | [diff] [blame] | 64 | |
Achin Gupta | 8587639 | 2014-07-31 17:45:51 +0100 | [diff] [blame] | 65 | /* Disable coherency if this cluster is to be turned off */ |
Vikram Kanigiri | fbb1301 | 2016-02-15 11:54:14 +0000 | [diff] [blame] | 66 | fvp_interconnect_disable(); |
Achin Gupta | 8587639 | 2014-07-31 17:45:51 +0100 | [diff] [blame] | 67 | |
Madhukar Pappireddy | 90d6532 | 2019-10-30 14:24:39 -0500 | [diff] [blame] | 68 | #if HW_ASSISTED_COHERENCY |
| 69 | uint32_t reg; |
| 70 | |
| 71 | /* |
| 72 | * If we have determined this core to be the last man standing and we |
| 73 | * intend to power down the cluster proactively, we provide a hint to |
| 74 | * the power controller that cluster power is not required when all |
| 75 | * cores are powered down. |
| 76 | * Note that this is only an advisory to power controller and is supported |
| 77 | * by SoCs with DynamIQ Shared Units only. |
| 78 | */ |
| 79 | reg = read_clusterpwrdn(); |
| 80 | |
| 81 | /* Clear and set bit 0 : Cluster power not required */ |
| 82 | reg &= ~DSU_CLUSTER_PWR_MASK; |
| 83 | reg |= DSU_CLUSTER_PWR_OFF; |
| 84 | write_clusterpwrdn(reg); |
| 85 | #endif |
| 86 | |
Achin Gupta | 8587639 | 2014-07-31 17:45:51 +0100 | [diff] [blame] | 87 | /* Program the power controller to turn the cluster off */ |
| 88 | fvp_pwrc_write_pcoffr(mpidr); |
| 89 | } |
| 90 | |
Soby Mathew | 9ca2806 | 2017-10-11 16:08:58 +0100 | [diff] [blame] | 91 | /* |
| 92 | * Empty implementation of these hooks avoid setting the GICR_WAKER.Sleep bit |
| 93 | * on ARM GICv3 implementations on FVP. This is required, because FVP does not |
| 94 | * support SYSTEM_SUSPEND and it is `faked` in firmware. Hence, for wake up |
| 95 | * from `fake` system suspend the GIC must not be powered off. |
| 96 | */ |
Roberto Vargas | 1a6eed3 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 97 | void arm_gicv3_distif_pre_save(unsigned int rdist_proc_num) |
Soby Mathew | 9ca2806 | 2017-10-11 16:08:58 +0100 | [diff] [blame] | 98 | {} |
| 99 | |
Roberto Vargas | 1a6eed3 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 100 | void arm_gicv3_distif_post_restore(unsigned int rdist_proc_num) |
Soby Mathew | 9ca2806 | 2017-10-11 16:08:58 +0100 | [diff] [blame] | 101 | {} |
| 102 | |
Soby Mathew | 12012dd | 2015-10-26 14:01:53 +0000 | [diff] [blame] | 103 | static void fvp_power_domain_on_finish_common(const psci_power_state_t *target_state) |
| 104 | { |
| 105 | unsigned long mpidr; |
| 106 | |
| 107 | assert(target_state->pwr_domain_state[ARM_PWR_LVL0] == |
| 108 | ARM_LOCAL_STATE_OFF); |
| 109 | |
| 110 | /* Get the mpidr for this cpu */ |
| 111 | mpidr = read_mpidr_el1(); |
| 112 | |
| 113 | /* Perform the common cluster specific operations */ |
| 114 | if (target_state->pwr_domain_state[ARM_PWR_LVL1] == |
| 115 | ARM_LOCAL_STATE_OFF) { |
| 116 | /* |
| 117 | * This CPU might have woken up whilst the cluster was |
| 118 | * attempting to power down. In this case the FVP power |
| 119 | * controller will have a pending cluster power off request |
| 120 | * which needs to be cleared by writing to the PPONR register. |
| 121 | * This prevents the power controller from interpreting a |
| 122 | * subsequent entry of this cpu into a simple wfi as a power |
| 123 | * down request. |
| 124 | */ |
| 125 | fvp_pwrc_write_pponr(mpidr); |
| 126 | |
| 127 | /* Enable coherency if this cluster was off */ |
Vikram Kanigiri | fbb1301 | 2016-02-15 11:54:14 +0000 | [diff] [blame] | 128 | fvp_interconnect_enable(); |
Soby Mathew | 12012dd | 2015-10-26 14:01:53 +0000 | [diff] [blame] | 129 | } |
Soby Mathew | 9ca2806 | 2017-10-11 16:08:58 +0100 | [diff] [blame] | 130 | /* Perform the common system specific operations */ |
| 131 | if (target_state->pwr_domain_state[ARM_PWR_LVL2] == |
| 132 | ARM_LOCAL_STATE_OFF) |
| 133 | arm_system_pwr_domain_resume(); |
Soby Mathew | 12012dd | 2015-10-26 14:01:53 +0000 | [diff] [blame] | 134 | |
| 135 | /* |
| 136 | * Clear PWKUPR.WEN bit to ensure interrupts do not interfere |
| 137 | * with a cpu power down unless the bit is set again |
| 138 | */ |
| 139 | fvp_pwrc_clr_wen(mpidr); |
| 140 | } |
| 141 | |
Achin Gupta | 8587639 | 2014-07-31 17:45:51 +0100 | [diff] [blame] | 142 | /******************************************************************************* |
Soby Mathew | fec4eb7 | 2015-07-01 16:16:20 +0100 | [diff] [blame] | 143 | * FVP handler called when a CPU is about to enter standby. |
Vikram Kanigiri | 3b7c59b | 2014-03-21 11:57:10 +0000 | [diff] [blame] | 144 | ******************************************************************************/ |
Roberto Vargas | 2ca18d9 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 145 | static void fvp_cpu_standby(plat_local_state_t cpu_state) |
Vikram Kanigiri | 3b7c59b | 2014-03-21 11:57:10 +0000 | [diff] [blame] | 146 | { |
Alexei Fedorov | d27febf | 2021-09-01 15:41:14 +0100 | [diff] [blame] | 147 | u_register_t scr = read_scr_el3(); |
Soby Mathew | fec4eb7 | 2015-07-01 16:16:20 +0100 | [diff] [blame] | 148 | |
| 149 | assert(cpu_state == ARM_LOCAL_STATE_RET); |
| 150 | |
Andrew Thoelke | 42e75a7 | 2014-04-28 12:28:39 +0100 | [diff] [blame] | 151 | /* |
Alexei Fedorov | d27febf | 2021-09-01 15:41:14 +0100 | [diff] [blame] | 152 | * Enable the Non-secure interrupt to wake the CPU. |
| 153 | * In GICv3 affinity routing mode, the Non-secure Group 1 interrupts |
| 154 | * use Physical FIQ at EL3 whereas in GICv2, Physical IRQ is used. |
| 155 | * Enabling both the bits works for both GICv2 mode and GICv3 affinity |
| 156 | * routing mode. |
| 157 | */ |
| 158 | write_scr_el3(scr | SCR_IRQ_BIT | SCR_FIQ_BIT); |
| 159 | isb(); |
| 160 | |
| 161 | /* |
| 162 | * Enter standby state. |
| 163 | * dsb is good practice before using wfi to enter low power states. |
Andrew Thoelke | 42e75a7 | 2014-04-28 12:28:39 +0100 | [diff] [blame] | 164 | */ |
| 165 | dsb(); |
Vikram Kanigiri | 3b7c59b | 2014-03-21 11:57:10 +0000 | [diff] [blame] | 166 | wfi(); |
Alexei Fedorov | d27febf | 2021-09-01 15:41:14 +0100 | [diff] [blame] | 167 | |
| 168 | /* |
| 169 | * Restore SCR_EL3 to the original value, synchronisation of SCR_EL3 |
| 170 | * is done by eret in el3_exit() to save some execution cycles. |
| 171 | */ |
| 172 | write_scr_el3(scr); |
Vikram Kanigiri | 3b7c59b | 2014-03-21 11:57:10 +0000 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | /******************************************************************************* |
Soby Mathew | fec4eb7 | 2015-07-01 16:16:20 +0100 | [diff] [blame] | 176 | * FVP handler called when a power domain is about to be turned on. The |
| 177 | * mpidr determines the CPU to be turned on. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 178 | ******************************************************************************/ |
Roberto Vargas | 2ca18d9 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 179 | static int fvp_pwr_domain_on(u_register_t mpidr) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 180 | { |
| 181 | int rc = PSCI_E_SUCCESS; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 182 | unsigned int psysr; |
| 183 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 184 | /* |
Sandrine Bailleux | 7175bde | 2015-12-08 14:18:24 +0000 | [diff] [blame] | 185 | * Ensure that we do not cancel an inflight power off request for the |
| 186 | * target cpu. That would leave it in a zombie wfi. Wait for it to power |
| 187 | * off and then program the power controller to turn that CPU on. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 188 | */ |
| 189 | do { |
| 190 | psysr = fvp_pwrc_read_psysr(mpidr); |
Sathees Balya | 50905c7 | 2018-10-05 13:30:59 +0100 | [diff] [blame] | 191 | } while ((psysr & PSYSR_AFF_L0) != 0U); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 192 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 193 | fvp_pwrc_write_pponr(mpidr); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 194 | return rc; |
| 195 | } |
| 196 | |
| 197 | /******************************************************************************* |
Soby Mathew | fec4eb7 | 2015-07-01 16:16:20 +0100 | [diff] [blame] | 198 | * FVP handler called when a power domain is about to be turned off. The |
| 199 | * target_state encodes the power state that each level should transition to. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 200 | ******************************************************************************/ |
Roberto Vargas | 2ca18d9 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 201 | static void fvp_pwr_domain_off(const psci_power_state_t *target_state) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 202 | { |
Soby Mathew | fec4eb7 | 2015-07-01 16:16:20 +0100 | [diff] [blame] | 203 | assert(target_state->pwr_domain_state[ARM_PWR_LVL0] == |
| 204 | ARM_LOCAL_STATE_OFF); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 205 | |
Achin Gupta | 8587639 | 2014-07-31 17:45:51 +0100 | [diff] [blame] | 206 | /* |
Soby Mathew | fec4eb7 | 2015-07-01 16:16:20 +0100 | [diff] [blame] | 207 | * If execution reaches this stage then this power domain will be |
| 208 | * suspended. Perform at least the cpu specific actions followed |
| 209 | * by the cluster specific operations if applicable. |
Achin Gupta | 8587639 | 2014-07-31 17:45:51 +0100 | [diff] [blame] | 210 | */ |
Jeenu Viswambharan | 6ad3548 | 2016-12-09 11:14:34 +0000 | [diff] [blame] | 211 | |
| 212 | /* Prevent interrupts from spuriously waking up this cpu */ |
| 213 | plat_arm_gic_cpuif_disable(); |
| 214 | |
| 215 | /* Turn redistributor off */ |
| 216 | plat_arm_gic_redistif_off(); |
| 217 | |
| 218 | /* Program the power controller to power off this cpu. */ |
| 219 | fvp_pwrc_write_ppoffr(read_mpidr_el1()); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 220 | |
Soby Mathew | fec4eb7 | 2015-07-01 16:16:20 +0100 | [diff] [blame] | 221 | if (target_state->pwr_domain_state[ARM_PWR_LVL1] == |
| 222 | ARM_LOCAL_STATE_OFF) |
Achin Gupta | 8587639 | 2014-07-31 17:45:51 +0100 | [diff] [blame] | 223 | fvp_cluster_pwrdwn_common(); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 224 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | /******************************************************************************* |
Soby Mathew | fec4eb7 | 2015-07-01 16:16:20 +0100 | [diff] [blame] | 228 | * FVP handler called when a power domain is about to be suspended. The |
| 229 | * target_state encodes the power state that each level should transition to. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 230 | ******************************************************************************/ |
Roberto Vargas | 2ca18d9 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 231 | static void fvp_pwr_domain_suspend(const psci_power_state_t *target_state) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 232 | { |
Soby Mathew | ffb4ab1 | 2014-09-26 15:08:52 +0100 | [diff] [blame] | 233 | unsigned long mpidr; |
| 234 | |
Soby Mathew | fec4eb7 | 2015-07-01 16:16:20 +0100 | [diff] [blame] | 235 | /* |
| 236 | * FVP has retention only at cpu level. Just return |
| 237 | * as nothing is to be done for retention. |
| 238 | */ |
| 239 | if (target_state->pwr_domain_state[ARM_PWR_LVL0] == |
| 240 | ARM_LOCAL_STATE_RET) |
Soby Mathew | 74e52a7 | 2014-10-02 16:56:51 +0100 | [diff] [blame] | 241 | return; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 242 | |
Soby Mathew | fec4eb7 | 2015-07-01 16:16:20 +0100 | [diff] [blame] | 243 | assert(target_state->pwr_domain_state[ARM_PWR_LVL0] == |
| 244 | ARM_LOCAL_STATE_OFF); |
| 245 | |
Soby Mathew | ffb4ab1 | 2014-09-26 15:08:52 +0100 | [diff] [blame] | 246 | /* Get the mpidr for this cpu */ |
| 247 | mpidr = read_mpidr_el1(); |
| 248 | |
Achin Gupta | 8587639 | 2014-07-31 17:45:51 +0100 | [diff] [blame] | 249 | /* Program the power controller to enable wakeup interrupts. */ |
| 250 | fvp_pwrc_set_wen(mpidr); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 251 | |
Jeenu Viswambharan | 6ad3548 | 2016-12-09 11:14:34 +0000 | [diff] [blame] | 252 | /* Prevent interrupts from spuriously waking up this cpu */ |
| 253 | plat_arm_gic_cpuif_disable(); |
| 254 | |
| 255 | /* |
| 256 | * The Redistributor is not powered off as it can potentially prevent |
| 257 | * wake up events reaching the CPUIF and/or might lead to losing |
| 258 | * register context. |
| 259 | */ |
| 260 | |
Achin Gupta | 8587639 | 2014-07-31 17:45:51 +0100 | [diff] [blame] | 261 | /* Perform the common cluster specific operations */ |
Soby Mathew | fec4eb7 | 2015-07-01 16:16:20 +0100 | [diff] [blame] | 262 | if (target_state->pwr_domain_state[ARM_PWR_LVL1] == |
| 263 | ARM_LOCAL_STATE_OFF) |
Achin Gupta | 8587639 | 2014-07-31 17:45:51 +0100 | [diff] [blame] | 264 | fvp_cluster_pwrdwn_common(); |
Soby Mathew | 9ca2806 | 2017-10-11 16:08:58 +0100 | [diff] [blame] | 265 | |
| 266 | /* Perform the common system specific operations */ |
| 267 | if (target_state->pwr_domain_state[ARM_PWR_LVL2] == |
| 268 | ARM_LOCAL_STATE_OFF) |
| 269 | arm_system_pwr_domain_save(); |
| 270 | |
| 271 | /* Program the power controller to power off this cpu. */ |
| 272 | fvp_pwrc_write_ppoffr(read_mpidr_el1()); |
Wing Li | 05364b9 | 2023-01-26 18:33:43 -0800 | [diff] [blame] | 273 | |
Wing Li | 05364b9 | 2023-01-26 18:33:43 -0800 | [diff] [blame] | 274 | return; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | /******************************************************************************* |
Soby Mathew | fec4eb7 | 2015-07-01 16:16:20 +0100 | [diff] [blame] | 278 | * FVP handler called when a power domain has just been powered on after |
| 279 | * being turned off earlier. The target_state encodes the low power state that |
| 280 | * each level has woken up from. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 281 | ******************************************************************************/ |
Roberto Vargas | 2ca18d9 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 282 | static void fvp_pwr_domain_on_finish(const psci_power_state_t *target_state) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 283 | { |
Soby Mathew | 12012dd | 2015-10-26 14:01:53 +0000 | [diff] [blame] | 284 | fvp_power_domain_on_finish_common(target_state); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 285 | |
Madhukar Pappireddy | 2859b7d | 2019-06-10 16:54:36 -0500 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | /******************************************************************************* |
| 289 | * FVP handler called when a power domain has just been powered on and the cpu |
| 290 | * and its cluster are fully participating in coherent transaction on the |
| 291 | * interconnect. Data cache must be enabled for CPU at this point. |
| 292 | ******************************************************************************/ |
| 293 | static void fvp_pwr_domain_on_finish_late(const psci_power_state_t *target_state) |
| 294 | { |
| 295 | /* Program GIC per-cpu distributor or re-distributor interface */ |
Achin Gupta | 1fa7eb6 | 2015-11-03 14:18:34 +0000 | [diff] [blame] | 296 | plat_arm_gic_pcpu_init(); |
| 297 | |
Madhukar Pappireddy | 2859b7d | 2019-06-10 16:54:36 -0500 | [diff] [blame] | 298 | /* Enable GIC CPU interface */ |
Achin Gupta | 1fa7eb6 | 2015-11-03 14:18:34 +0000 | [diff] [blame] | 299 | plat_arm_gic_cpuif_enable(); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | /******************************************************************************* |
Soby Mathew | fec4eb7 | 2015-07-01 16:16:20 +0100 | [diff] [blame] | 303 | * FVP handler called when a power domain has just been powered on after |
| 304 | * having been suspended earlier. The target_state encodes the low power state |
| 305 | * that each level has woken up from. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 306 | * TODO: At the moment we reuse the on finisher and reinitialize the secure |
| 307 | * context. Need to implement a separate suspend finisher. |
| 308 | ******************************************************************************/ |
Roberto Vargas | 2ca18d9 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 309 | static void fvp_pwr_domain_suspend_finish(const psci_power_state_t *target_state) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 310 | { |
Soby Mathew | fec4eb7 | 2015-07-01 16:16:20 +0100 | [diff] [blame] | 311 | /* |
| 312 | * Nothing to be done on waking up from retention from CPU level. |
| 313 | */ |
| 314 | if (target_state->pwr_domain_state[ARM_PWR_LVL0] == |
| 315 | ARM_LOCAL_STATE_RET) |
| 316 | return; |
| 317 | |
Soby Mathew | 12012dd | 2015-10-26 14:01:53 +0000 | [diff] [blame] | 318 | fvp_power_domain_on_finish_common(target_state); |
| 319 | |
Madhukar Pappireddy | 2859b7d | 2019-06-10 16:54:36 -0500 | [diff] [blame] | 320 | /* Enable GIC CPU interface */ |
Achin Gupta | 1fa7eb6 | 2015-11-03 14:18:34 +0000 | [diff] [blame] | 321 | plat_arm_gic_cpuif_enable(); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 322 | } |
| 323 | |
Juan Castillo | 4dc4a47 | 2014-08-12 11:17:06 +0100 | [diff] [blame] | 324 | /******************************************************************************* |
| 325 | * FVP handlers to shutdown/reboot the system |
| 326 | ******************************************************************************/ |
| 327 | static void __dead2 fvp_system_off(void) |
| 328 | { |
| 329 | /* Write the System Configuration Control Register */ |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 330 | mmio_write_32(V2M_SYSREGS_BASE + V2M_SYS_CFGCTRL, |
| 331 | V2M_CFGCTRL_START | |
| 332 | V2M_CFGCTRL_RW | |
| 333 | V2M_CFGCTRL_FUNC(V2M_FUNC_SHUTDOWN)); |
Juan Castillo | 4dc4a47 | 2014-08-12 11:17:06 +0100 | [diff] [blame] | 334 | wfi(); |
| 335 | ERROR("FVP System Off: operation not handled.\n"); |
| 336 | panic(); |
| 337 | } |
| 338 | |
| 339 | static void __dead2 fvp_system_reset(void) |
| 340 | { |
| 341 | /* Write the System Configuration Control Register */ |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 342 | mmio_write_32(V2M_SYSREGS_BASE + V2M_SYS_CFGCTRL, |
| 343 | V2M_CFGCTRL_START | |
| 344 | V2M_CFGCTRL_RW | |
| 345 | V2M_CFGCTRL_FUNC(V2M_FUNC_REBOOT)); |
Juan Castillo | 4dc4a47 | 2014-08-12 11:17:06 +0100 | [diff] [blame] | 346 | wfi(); |
| 347 | ERROR("FVP System Reset: operation not handled.\n"); |
| 348 | panic(); |
| 349 | } |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 350 | |
Jeenu Viswambharan | 095529a | 2016-08-04 09:43:15 +0100 | [diff] [blame] | 351 | static int fvp_node_hw_state(u_register_t target_cpu, |
| 352 | unsigned int power_level) |
| 353 | { |
| 354 | unsigned int psysr; |
| 355 | int ret; |
| 356 | |
| 357 | /* |
| 358 | * The format of 'power_level' is implementation-defined, but 0 must |
| 359 | * mean a CPU. We also allow 1 to denote the cluster |
| 360 | */ |
Sathees Balya | 50905c7 | 2018-10-05 13:30:59 +0100 | [diff] [blame] | 361 | if ((power_level != ARM_PWR_LVL0) && (power_level != ARM_PWR_LVL1)) |
Jeenu Viswambharan | 095529a | 2016-08-04 09:43:15 +0100 | [diff] [blame] | 362 | return PSCI_E_INVALID_PARAMS; |
| 363 | |
| 364 | /* |
| 365 | * Read the status of the given MPDIR from FVP power controller. The |
| 366 | * power controller only gives us on/off status, so map that to expected |
| 367 | * return values of the PSCI call |
| 368 | */ |
| 369 | psysr = fvp_pwrc_read_psysr(target_cpu); |
| 370 | if (psysr == PSYSR_INVALID) |
| 371 | return PSCI_E_INVALID_PARAMS; |
| 372 | |
Jonathan Wright | ff957ed | 2018-03-14 15:24:00 +0000 | [diff] [blame] | 373 | if (power_level == ARM_PWR_LVL0) { |
Sathees Balya | 50905c7 | 2018-10-05 13:30:59 +0100 | [diff] [blame] | 374 | ret = ((psysr & PSYSR_AFF_L0) != 0U) ? HW_ON : HW_OFF; |
Jonathan Wright | ff957ed | 2018-03-14 15:24:00 +0000 | [diff] [blame] | 375 | } else { |
| 376 | /* power_level == ARM_PWR_LVL1 */ |
Sathees Balya | 50905c7 | 2018-10-05 13:30:59 +0100 | [diff] [blame] | 377 | ret = ((psysr & PSYSR_AFF_L1) != 0U) ? HW_ON : HW_OFF; |
Jeenu Viswambharan | 095529a | 2016-08-04 09:43:15 +0100 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | return ret; |
| 381 | } |
| 382 | |
Soby Mathew | 9ca2806 | 2017-10-11 16:08:58 +0100 | [diff] [blame] | 383 | /* |
| 384 | * The FVP doesn't truly support power management at SYSTEM power domain. The |
| 385 | * SYSTEM_SUSPEND will be down-graded to the cluster level within the platform |
| 386 | * layer. The `fake` SYSTEM_SUSPEND allows us to validate some of the driver |
| 387 | * save and restore sequences on FVP. |
| 388 | */ |
Roberto Vargas | 2ca18d9 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 389 | #if !ARM_BL31_IN_DRAM |
| 390 | static void fvp_get_sys_suspend_power_state(psci_power_state_t *req_state) |
Soby Mathew | 9ca2806 | 2017-10-11 16:08:58 +0100 | [diff] [blame] | 391 | { |
| 392 | unsigned int i; |
| 393 | |
| 394 | for (i = ARM_PWR_LVL0; i <= PLAT_MAX_PWR_LVL; i++) |
| 395 | req_state->pwr_domain_state[i] = ARM_LOCAL_STATE_OFF; |
Wing Li | bcff365 | 2023-06-28 14:03:21 -0700 | [diff] [blame] | 396 | |
| 397 | #if PSCI_OS_INIT_MODE |
| 398 | req_state->last_at_pwrlvl = PLAT_MAX_PWR_LVL; |
| 399 | #endif |
Soby Mathew | 9ca2806 | 2017-10-11 16:08:58 +0100 | [diff] [blame] | 400 | } |
Roberto Vargas | 2ca18d9 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 401 | #endif |
Soby Mathew | 9ca2806 | 2017-10-11 16:08:58 +0100 | [diff] [blame] | 402 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 403 | /******************************************************************************* |
Soby Mathew | 9ca2806 | 2017-10-11 16:08:58 +0100 | [diff] [blame] | 404 | * Handler to filter PSCI requests. |
| 405 | ******************************************************************************/ |
| 406 | /* |
| 407 | * The system power domain suspend is only supported only via |
| 408 | * PSCI SYSTEM_SUSPEND API. PSCI CPU_SUSPEND request to system power domain |
| 409 | * will be downgraded to the lower level. |
| 410 | */ |
| 411 | static int fvp_validate_power_state(unsigned int power_state, |
| 412 | psci_power_state_t *req_state) |
| 413 | { |
| 414 | int rc; |
| 415 | rc = arm_validate_power_state(power_state, req_state); |
| 416 | |
| 417 | /* |
| 418 | * Ensure that the system power domain level is never suspended |
| 419 | * via PSCI CPU SUSPEND API. Currently system suspend is only |
| 420 | * supported via PSCI SYSTEM SUSPEND API. |
| 421 | */ |
| 422 | req_state->pwr_domain_state[ARM_PWR_LVL2] = ARM_LOCAL_STATE_RUN; |
| 423 | return rc; |
| 424 | } |
| 425 | |
| 426 | /* |
| 427 | * Custom `translate_power_state_by_mpidr` handler for FVP. Unlike in the |
| 428 | * `fvp_validate_power_state`, we do not downgrade the system power |
| 429 | * domain level request in `power_state` as it will be used to query the |
| 430 | * PSCI_STAT_COUNT/RESIDENCY at the system power domain level. |
| 431 | */ |
| 432 | static int fvp_translate_power_state_by_mpidr(u_register_t mpidr, |
| 433 | unsigned int power_state, |
| 434 | psci_power_state_t *output_state) |
| 435 | { |
| 436 | return arm_validate_power_state(power_state, output_state); |
| 437 | } |
| 438 | |
| 439 | /******************************************************************************* |
Soby Mathew | feac8fc | 2015-09-29 15:47:16 +0100 | [diff] [blame] | 440 | * Export the platform handlers via plat_arm_psci_pm_ops. The ARM Standard |
| 441 | * platform layer will take care of registering the handlers with PSCI. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 442 | ******************************************************************************/ |
Soby Mathew | 0b4c5a3 | 2016-10-21 17:51:22 +0100 | [diff] [blame] | 443 | plat_psci_ops_t plat_arm_psci_pm_ops = { |
Soby Mathew | fec4eb7 | 2015-07-01 16:16:20 +0100 | [diff] [blame] | 444 | .cpu_standby = fvp_cpu_standby, |
| 445 | .pwr_domain_on = fvp_pwr_domain_on, |
| 446 | .pwr_domain_off = fvp_pwr_domain_off, |
| 447 | .pwr_domain_suspend = fvp_pwr_domain_suspend, |
| 448 | .pwr_domain_on_finish = fvp_pwr_domain_on_finish, |
Madhukar Pappireddy | 2859b7d | 2019-06-10 16:54:36 -0500 | [diff] [blame] | 449 | .pwr_domain_on_finish_late = fvp_pwr_domain_on_finish_late, |
Soby Mathew | fec4eb7 | 2015-07-01 16:16:20 +0100 | [diff] [blame] | 450 | .pwr_domain_suspend_finish = fvp_pwr_domain_suspend_finish, |
Juan Castillo | 4dc4a47 | 2014-08-12 11:17:06 +0100 | [diff] [blame] | 451 | .system_off = fvp_system_off, |
Soby Mathew | 74e52a7 | 2014-10-02 16:56:51 +0100 | [diff] [blame] | 452 | .system_reset = fvp_system_reset, |
Soby Mathew | 9ca2806 | 2017-10-11 16:08:58 +0100 | [diff] [blame] | 453 | .validate_power_state = fvp_validate_power_state, |
Jeenu Viswambharan | 59424d8 | 2017-09-19 09:27:18 +0100 | [diff] [blame] | 454 | .validate_ns_entrypoint = arm_validate_psci_entrypoint, |
Soby Mathew | 9ca2806 | 2017-10-11 16:08:58 +0100 | [diff] [blame] | 455 | .translate_power_state_by_mpidr = fvp_translate_power_state_by_mpidr, |
Roberto Vargas | a1c16b6 | 2017-08-03 09:16:43 +0100 | [diff] [blame] | 456 | .get_node_hw_state = fvp_node_hw_state, |
Antonio Nino Diaz | 0b6af83 | 2017-11-22 12:00:44 +0000 | [diff] [blame] | 457 | #if !ARM_BL31_IN_DRAM |
| 458 | /* |
| 459 | * The TrustZone Controller is set up during the warmboot sequence after |
| 460 | * resuming the CPU from a SYSTEM_SUSPEND. If BL31 is located in SRAM |
| 461 | * this is not a problem but, if it is in TZC-secured DRAM, it tries to |
| 462 | * reconfigure the same memory it is running on, causing an exception. |
| 463 | */ |
Soby Mathew | 9ca2806 | 2017-10-11 16:08:58 +0100 | [diff] [blame] | 464 | .get_sys_suspend_power_state = fvp_get_sys_suspend_power_state, |
Antonio Nino Diaz | 0b6af83 | 2017-11-22 12:00:44 +0000 | [diff] [blame] | 465 | #endif |
Roberto Vargas | a1c16b6 | 2017-08-03 09:16:43 +0100 | [diff] [blame] | 466 | .mem_protect_chk = arm_psci_mem_protect_chk, |
| 467 | .read_mem_protect = arm_psci_read_mem_protect, |
| 468 | .write_mem_protect = arm_nor_psci_write_mem_protect, |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 469 | }; |
Chandni Cherukuri | e4bf6a0 | 2018-11-14 13:43:59 +0530 | [diff] [blame] | 470 | |
| 471 | const plat_psci_ops_t *plat_arm_psci_override_pm_ops(plat_psci_ops_t *ops) |
| 472 | { |
| 473 | return ops; |
| 474 | } |