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