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