13fc4124cSDan Handley /* 23202ce8bSAlexei Fedorov * Copyright (c) 2013-2021, ARM Limited and Contributors. All rights reserved. 33fc4124cSDan Handley * 482cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause 53fc4124cSDan Handley */ 63fc4124cSDan Handley 73fc4124cSDan Handley #include <assert.h> 809d40e0eSAntonio Nino Diaz 9*6437a09aSAndre Przywara #include <arch_features.h> 1009d40e0eSAntonio Nino Diaz #include <arch_helpers.h> 1109d40e0eSAntonio Nino Diaz #include <common/debug.h> 1209d40e0eSAntonio Nino Diaz #include <drivers/arm/gicv3.h> 13560293bbSAntonio Nino Diaz #include <drivers/arm/fvp/fvp_pwrc.h> 1409d40e0eSAntonio Nino Diaz #include <lib/extensions/spe.h> 1509d40e0eSAntonio Nino Diaz #include <lib/mmio.h> 1609d40e0eSAntonio Nino Diaz #include <lib/psci/psci.h> 17bd9344f6SAntonio Nino Diaz #include <plat/arm/common/arm_config.h> 18bd9344f6SAntonio Nino Diaz #include <plat/arm/common/plat_arm.h> 19234bc7f8SAntonio Nino Diaz #include <platform_def.h> 2009d40e0eSAntonio Nino Diaz 213fc4124cSDan Handley #include "fvp_private.h" 22609e053cSAmbroise Vincent #include "../drivers/arm/gic/v3/gicv3_private.h" 233fc4124cSDan Handley 243fc4124cSDan Handley 252204afdeSSoby Mathew #if ARM_RECOM_STATE_ID_ENC 262204afdeSSoby Mathew /* 272204afdeSSoby Mathew * The table storing the valid idle power states. Ensure that the 282204afdeSSoby Mathew * array entries are populated in ascending order of state-id to 292204afdeSSoby Mathew * enable us to use binary search during power state validation. 302204afdeSSoby Mathew * The table must be terminated by a NULL entry. 312204afdeSSoby Mathew */ 322204afdeSSoby Mathew const unsigned int arm_pm_idle_states[] = { 332204afdeSSoby Mathew /* State-id - 0x01 */ 342204afdeSSoby Mathew arm_make_pwrstate_lvl1(ARM_LOCAL_STATE_RUN, ARM_LOCAL_STATE_RET, 352204afdeSSoby Mathew ARM_PWR_LVL0, PSTATE_TYPE_STANDBY), 362204afdeSSoby Mathew /* State-id - 0x02 */ 372204afdeSSoby Mathew arm_make_pwrstate_lvl1(ARM_LOCAL_STATE_RUN, ARM_LOCAL_STATE_OFF, 382204afdeSSoby Mathew ARM_PWR_LVL0, PSTATE_TYPE_POWERDOWN), 392204afdeSSoby Mathew /* State-id - 0x22 */ 402204afdeSSoby Mathew arm_make_pwrstate_lvl1(ARM_LOCAL_STATE_OFF, ARM_LOCAL_STATE_OFF, 412204afdeSSoby Mathew ARM_PWR_LVL1, PSTATE_TYPE_POWERDOWN), 42e35a3fb5SSoby Mathew /* State-id - 0x222 */ 43e35a3fb5SSoby Mathew arm_make_pwrstate_lvl2(ARM_LOCAL_STATE_OFF, ARM_LOCAL_STATE_OFF, 44e35a3fb5SSoby Mathew ARM_LOCAL_STATE_OFF, ARM_PWR_LVL2, PSTATE_TYPE_POWERDOWN), 452204afdeSSoby Mathew 0, 462204afdeSSoby Mathew }; 472204afdeSSoby Mathew #endif 482204afdeSSoby Mathew 493fc4124cSDan Handley /******************************************************************************* 503fc4124cSDan Handley * Function which implements the common FVP specific operations to power down a 513fc4124cSDan Handley * cluster in response to a CPU_OFF or CPU_SUSPEND request. 523fc4124cSDan Handley ******************************************************************************/ 533fc4124cSDan Handley static void fvp_cluster_pwrdwn_common(void) 543fc4124cSDan Handley { 553fc4124cSDan Handley uint64_t mpidr = read_mpidr_el1(); 563fc4124cSDan Handley 57d832aee9Sdp-arm /* 58d832aee9Sdp-arm * On power down we need to disable statistical profiling extensions 59d832aee9Sdp-arm * before exiting coherency. 60d832aee9Sdp-arm */ 61*6437a09aSAndre Przywara if (is_feat_spe_supported()) { 62281a08ccSDimitris Papastamos spe_disable(); 63*6437a09aSAndre Przywara } 64d832aee9Sdp-arm 653fc4124cSDan Handley /* Disable coherency if this cluster is to be turned off */ 666355f234SVikram Kanigiri fvp_interconnect_disable(); 673fc4124cSDan Handley 689cf7f355SMadhukar Pappireddy #if HW_ASSISTED_COHERENCY 699cf7f355SMadhukar Pappireddy uint32_t reg; 709cf7f355SMadhukar Pappireddy 719cf7f355SMadhukar Pappireddy /* 729cf7f355SMadhukar Pappireddy * If we have determined this core to be the last man standing and we 739cf7f355SMadhukar Pappireddy * intend to power down the cluster proactively, we provide a hint to 749cf7f355SMadhukar Pappireddy * the power controller that cluster power is not required when all 759cf7f355SMadhukar Pappireddy * cores are powered down. 769cf7f355SMadhukar Pappireddy * Note that this is only an advisory to power controller and is supported 779cf7f355SMadhukar Pappireddy * by SoCs with DynamIQ Shared Units only. 789cf7f355SMadhukar Pappireddy */ 799cf7f355SMadhukar Pappireddy reg = read_clusterpwrdn(); 809cf7f355SMadhukar Pappireddy 819cf7f355SMadhukar Pappireddy /* Clear and set bit 0 : Cluster power not required */ 829cf7f355SMadhukar Pappireddy reg &= ~DSU_CLUSTER_PWR_MASK; 839cf7f355SMadhukar Pappireddy reg |= DSU_CLUSTER_PWR_OFF; 849cf7f355SMadhukar Pappireddy write_clusterpwrdn(reg); 859cf7f355SMadhukar Pappireddy #endif 869cf7f355SMadhukar Pappireddy 873fc4124cSDan Handley /* Program the power controller to turn the cluster off */ 883fc4124cSDan Handley fvp_pwrc_write_pcoffr(mpidr); 893fc4124cSDan Handley } 903fc4124cSDan Handley 91e35a3fb5SSoby Mathew /* 92e35a3fb5SSoby Mathew * Empty implementation of these hooks avoid setting the GICR_WAKER.Sleep bit 93e35a3fb5SSoby Mathew * on ARM GICv3 implementations on FVP. This is required, because FVP does not 94e35a3fb5SSoby Mathew * support SYSTEM_SUSPEND and it is `faked` in firmware. Hence, for wake up 95e35a3fb5SSoby Mathew * from `fake` system suspend the GIC must not be powered off. 96e35a3fb5SSoby Mathew */ 97dc6aad2eSRoberto Vargas void arm_gicv3_distif_pre_save(unsigned int rdist_proc_num) 98e35a3fb5SSoby Mathew {} 99e35a3fb5SSoby Mathew 100dc6aad2eSRoberto Vargas void arm_gicv3_distif_post_restore(unsigned int rdist_proc_num) 101e35a3fb5SSoby Mathew {} 102e35a3fb5SSoby Mathew 103f14d1886SSoby Mathew static void fvp_power_domain_on_finish_common(const psci_power_state_t *target_state) 104f14d1886SSoby Mathew { 105f14d1886SSoby Mathew unsigned long mpidr; 106f14d1886SSoby Mathew 107f14d1886SSoby Mathew assert(target_state->pwr_domain_state[ARM_PWR_LVL0] == 108f14d1886SSoby Mathew ARM_LOCAL_STATE_OFF); 109f14d1886SSoby Mathew 110f14d1886SSoby Mathew /* Get the mpidr for this cpu */ 111f14d1886SSoby Mathew mpidr = read_mpidr_el1(); 112f14d1886SSoby Mathew 113f14d1886SSoby Mathew /* Perform the common cluster specific operations */ 114f14d1886SSoby Mathew if (target_state->pwr_domain_state[ARM_PWR_LVL1] == 115f14d1886SSoby Mathew ARM_LOCAL_STATE_OFF) { 116f14d1886SSoby Mathew /* 117f14d1886SSoby Mathew * This CPU might have woken up whilst the cluster was 118f14d1886SSoby Mathew * attempting to power down. In this case the FVP power 119f14d1886SSoby Mathew * controller will have a pending cluster power off request 120f14d1886SSoby Mathew * which needs to be cleared by writing to the PPONR register. 121f14d1886SSoby Mathew * This prevents the power controller from interpreting a 122f14d1886SSoby Mathew * subsequent entry of this cpu into a simple wfi as a power 123f14d1886SSoby Mathew * down request. 124f14d1886SSoby Mathew */ 125f14d1886SSoby Mathew fvp_pwrc_write_pponr(mpidr); 126f14d1886SSoby Mathew 127f14d1886SSoby Mathew /* Enable coherency if this cluster was off */ 1286355f234SVikram Kanigiri fvp_interconnect_enable(); 129f14d1886SSoby Mathew } 130e35a3fb5SSoby Mathew /* Perform the common system specific operations */ 131e35a3fb5SSoby Mathew if (target_state->pwr_domain_state[ARM_PWR_LVL2] == 132e35a3fb5SSoby Mathew ARM_LOCAL_STATE_OFF) 133e35a3fb5SSoby Mathew arm_system_pwr_domain_resume(); 134f14d1886SSoby Mathew 135f14d1886SSoby Mathew /* 136f14d1886SSoby Mathew * Clear PWKUPR.WEN bit to ensure interrupts do not interfere 137f14d1886SSoby Mathew * with a cpu power down unless the bit is set again 138f14d1886SSoby Mathew */ 139f14d1886SSoby Mathew fvp_pwrc_clr_wen(mpidr); 140f14d1886SSoby Mathew } 141f14d1886SSoby Mathew 1423fc4124cSDan Handley /******************************************************************************* 14338dce70fSSoby Mathew * FVP handler called when a CPU is about to enter standby. 1443fc4124cSDan Handley ******************************************************************************/ 1451af540efSRoberto Vargas static void fvp_cpu_standby(plat_local_state_t cpu_state) 1463fc4124cSDan Handley { 1473202ce8bSAlexei Fedorov u_register_t scr = read_scr_el3(); 14838dce70fSSoby Mathew 14938dce70fSSoby Mathew assert(cpu_state == ARM_LOCAL_STATE_RET); 15038dce70fSSoby Mathew 1513fc4124cSDan Handley /* 1523202ce8bSAlexei Fedorov * Enable the Non-secure interrupt to wake the CPU. 1533202ce8bSAlexei Fedorov * In GICv3 affinity routing mode, the Non-secure Group 1 interrupts 1543202ce8bSAlexei Fedorov * use Physical FIQ at EL3 whereas in GICv2, Physical IRQ is used. 1553202ce8bSAlexei Fedorov * Enabling both the bits works for both GICv2 mode and GICv3 affinity 1563202ce8bSAlexei Fedorov * routing mode. 1573202ce8bSAlexei Fedorov */ 1583202ce8bSAlexei Fedorov write_scr_el3(scr | SCR_IRQ_BIT | SCR_FIQ_BIT); 1593202ce8bSAlexei Fedorov isb(); 1603202ce8bSAlexei Fedorov 1613202ce8bSAlexei Fedorov /* 1623202ce8bSAlexei Fedorov * Enter standby state. 1633202ce8bSAlexei Fedorov * dsb is good practice before using wfi to enter low power states. 1643fc4124cSDan Handley */ 1653fc4124cSDan Handley dsb(); 1663fc4124cSDan Handley wfi(); 1673202ce8bSAlexei Fedorov 1683202ce8bSAlexei Fedorov /* 1693202ce8bSAlexei Fedorov * Restore SCR_EL3 to the original value, synchronisation of SCR_EL3 1703202ce8bSAlexei Fedorov * is done by eret in el3_exit() to save some execution cycles. 1713202ce8bSAlexei Fedorov */ 1723202ce8bSAlexei Fedorov write_scr_el3(scr); 1733fc4124cSDan Handley } 1743fc4124cSDan Handley 1753fc4124cSDan Handley /******************************************************************************* 17638dce70fSSoby Mathew * FVP handler called when a power domain is about to be turned on. The 17738dce70fSSoby Mathew * mpidr determines the CPU to be turned on. 1783fc4124cSDan Handley ******************************************************************************/ 1791af540efSRoberto Vargas static int fvp_pwr_domain_on(u_register_t mpidr) 1803fc4124cSDan Handley { 1813fc4124cSDan Handley int rc = PSCI_E_SUCCESS; 1823fc4124cSDan Handley unsigned int psysr; 1833fc4124cSDan Handley 1843fc4124cSDan Handley /* 1850f09c8f7SSandrine Bailleux * Ensure that we do not cancel an inflight power off request for the 1860f09c8f7SSandrine Bailleux * target cpu. That would leave it in a zombie wfi. Wait for it to power 1870f09c8f7SSandrine Bailleux * off and then program the power controller to turn that CPU on. 1883fc4124cSDan Handley */ 1893fc4124cSDan Handley do { 1903fc4124cSDan Handley psysr = fvp_pwrc_read_psysr(mpidr); 191e02f469fSSathees Balya } while ((psysr & PSYSR_AFF_L0) != 0U); 1923fc4124cSDan Handley 1933fc4124cSDan Handley fvp_pwrc_write_pponr(mpidr); 1943fc4124cSDan Handley return rc; 1953fc4124cSDan Handley } 1963fc4124cSDan Handley 1973fc4124cSDan Handley /******************************************************************************* 19838dce70fSSoby Mathew * FVP handler called when a power domain is about to be turned off. The 19938dce70fSSoby Mathew * target_state encodes the power state that each level should transition to. 2003fc4124cSDan Handley ******************************************************************************/ 2011af540efSRoberto Vargas static void fvp_pwr_domain_off(const psci_power_state_t *target_state) 2023fc4124cSDan Handley { 20338dce70fSSoby Mathew assert(target_state->pwr_domain_state[ARM_PWR_LVL0] == 20438dce70fSSoby Mathew ARM_LOCAL_STATE_OFF); 2053fc4124cSDan Handley 2063fc4124cSDan Handley /* 20738dce70fSSoby Mathew * If execution reaches this stage then this power domain will be 20838dce70fSSoby Mathew * suspended. Perform at least the cpu specific actions followed 20938dce70fSSoby Mathew * by the cluster specific operations if applicable. 2103fc4124cSDan Handley */ 21174a9578cSJeenu Viswambharan 21274a9578cSJeenu Viswambharan /* Prevent interrupts from spuriously waking up this cpu */ 21374a9578cSJeenu Viswambharan plat_arm_gic_cpuif_disable(); 21474a9578cSJeenu Viswambharan 21574a9578cSJeenu Viswambharan /* Turn redistributor off */ 21674a9578cSJeenu Viswambharan plat_arm_gic_redistif_off(); 21774a9578cSJeenu Viswambharan 21874a9578cSJeenu Viswambharan /* Program the power controller to power off this cpu. */ 21974a9578cSJeenu Viswambharan fvp_pwrc_write_ppoffr(read_mpidr_el1()); 2203fc4124cSDan Handley 22138dce70fSSoby Mathew if (target_state->pwr_domain_state[ARM_PWR_LVL1] == 22238dce70fSSoby Mathew ARM_LOCAL_STATE_OFF) 2233fc4124cSDan Handley fvp_cluster_pwrdwn_common(); 2243fc4124cSDan Handley 2253fc4124cSDan Handley } 2263fc4124cSDan Handley 2273fc4124cSDan Handley /******************************************************************************* 22838dce70fSSoby Mathew * FVP handler called when a power domain is about to be suspended. The 22938dce70fSSoby Mathew * target_state encodes the power state that each level should transition to. 2303fc4124cSDan Handley ******************************************************************************/ 2311af540efSRoberto Vargas static void fvp_pwr_domain_suspend(const psci_power_state_t *target_state) 2323fc4124cSDan Handley { 2333fc4124cSDan Handley unsigned long mpidr; 2343fc4124cSDan Handley 23538dce70fSSoby Mathew /* 23638dce70fSSoby Mathew * FVP has retention only at cpu level. Just return 23738dce70fSSoby Mathew * as nothing is to be done for retention. 23838dce70fSSoby Mathew */ 23938dce70fSSoby Mathew if (target_state->pwr_domain_state[ARM_PWR_LVL0] == 24038dce70fSSoby Mathew ARM_LOCAL_STATE_RET) 2413fc4124cSDan Handley return; 2423fc4124cSDan Handley 24338dce70fSSoby Mathew assert(target_state->pwr_domain_state[ARM_PWR_LVL0] == 24438dce70fSSoby Mathew ARM_LOCAL_STATE_OFF); 24538dce70fSSoby Mathew 2463fc4124cSDan Handley /* Get the mpidr for this cpu */ 2473fc4124cSDan Handley mpidr = read_mpidr_el1(); 2483fc4124cSDan Handley 2493fc4124cSDan Handley /* Program the power controller to enable wakeup interrupts. */ 2503fc4124cSDan Handley fvp_pwrc_set_wen(mpidr); 2513fc4124cSDan Handley 25274a9578cSJeenu Viswambharan /* Prevent interrupts from spuriously waking up this cpu */ 25374a9578cSJeenu Viswambharan plat_arm_gic_cpuif_disable(); 25474a9578cSJeenu Viswambharan 25574a9578cSJeenu Viswambharan /* 25674a9578cSJeenu Viswambharan * The Redistributor is not powered off as it can potentially prevent 25774a9578cSJeenu Viswambharan * wake up events reaching the CPUIF and/or might lead to losing 25874a9578cSJeenu Viswambharan * register context. 25974a9578cSJeenu Viswambharan */ 26074a9578cSJeenu Viswambharan 2613fc4124cSDan Handley /* Perform the common cluster specific operations */ 26238dce70fSSoby Mathew if (target_state->pwr_domain_state[ARM_PWR_LVL1] == 26338dce70fSSoby Mathew ARM_LOCAL_STATE_OFF) 2643fc4124cSDan Handley fvp_cluster_pwrdwn_common(); 265e35a3fb5SSoby Mathew 266e35a3fb5SSoby Mathew /* Perform the common system specific operations */ 267e35a3fb5SSoby Mathew if (target_state->pwr_domain_state[ARM_PWR_LVL2] == 268e35a3fb5SSoby Mathew ARM_LOCAL_STATE_OFF) 269e35a3fb5SSoby Mathew arm_system_pwr_domain_save(); 270e35a3fb5SSoby Mathew 271e35a3fb5SSoby Mathew /* Program the power controller to power off this cpu. */ 272e35a3fb5SSoby Mathew fvp_pwrc_write_ppoffr(read_mpidr_el1()); 2733fc4124cSDan Handley } 2743fc4124cSDan Handley 2753fc4124cSDan Handley /******************************************************************************* 27638dce70fSSoby Mathew * FVP handler called when a power domain has just been powered on after 27738dce70fSSoby Mathew * being turned off earlier. The target_state encodes the low power state that 27838dce70fSSoby Mathew * each level has woken up from. 2793fc4124cSDan Handley ******************************************************************************/ 2801af540efSRoberto Vargas static void fvp_pwr_domain_on_finish(const psci_power_state_t *target_state) 2813fc4124cSDan Handley { 282f14d1886SSoby Mathew fvp_power_domain_on_finish_common(target_state); 2833fc4124cSDan Handley 2846806cd23SMadhukar Pappireddy } 2856806cd23SMadhukar Pappireddy 2866806cd23SMadhukar Pappireddy /******************************************************************************* 2876806cd23SMadhukar Pappireddy * FVP handler called when a power domain has just been powered on and the cpu 2886806cd23SMadhukar Pappireddy * and its cluster are fully participating in coherent transaction on the 2896806cd23SMadhukar Pappireddy * interconnect. Data cache must be enabled for CPU at this point. 2906806cd23SMadhukar Pappireddy ******************************************************************************/ 2916806cd23SMadhukar Pappireddy static void fvp_pwr_domain_on_finish_late(const psci_power_state_t *target_state) 2926806cd23SMadhukar Pappireddy { 2936806cd23SMadhukar Pappireddy /* Program GIC per-cpu distributor or re-distributor interface */ 29427573c59SAchin Gupta plat_arm_gic_pcpu_init(); 29527573c59SAchin Gupta 2966806cd23SMadhukar Pappireddy /* Enable GIC CPU interface */ 29727573c59SAchin Gupta plat_arm_gic_cpuif_enable(); 2983fc4124cSDan Handley } 2993fc4124cSDan Handley 3003fc4124cSDan Handley /******************************************************************************* 30138dce70fSSoby Mathew * FVP handler called when a power domain has just been powered on after 30238dce70fSSoby Mathew * having been suspended earlier. The target_state encodes the low power state 30338dce70fSSoby Mathew * that each level has woken up from. 3043fc4124cSDan Handley * TODO: At the moment we reuse the on finisher and reinitialize the secure 3053fc4124cSDan Handley * context. Need to implement a separate suspend finisher. 3063fc4124cSDan Handley ******************************************************************************/ 3071af540efSRoberto Vargas static void fvp_pwr_domain_suspend_finish(const psci_power_state_t *target_state) 3083fc4124cSDan Handley { 30938dce70fSSoby Mathew /* 31038dce70fSSoby Mathew * Nothing to be done on waking up from retention from CPU level. 31138dce70fSSoby Mathew */ 31238dce70fSSoby Mathew if (target_state->pwr_domain_state[ARM_PWR_LVL0] == 31338dce70fSSoby Mathew ARM_LOCAL_STATE_RET) 31438dce70fSSoby Mathew return; 31538dce70fSSoby Mathew 316f14d1886SSoby Mathew fvp_power_domain_on_finish_common(target_state); 317f14d1886SSoby Mathew 3186806cd23SMadhukar Pappireddy /* Enable GIC CPU interface */ 31927573c59SAchin Gupta plat_arm_gic_cpuif_enable(); 3203fc4124cSDan Handley } 3213fc4124cSDan Handley 3223fc4124cSDan Handley /******************************************************************************* 3233fc4124cSDan Handley * FVP handlers to shutdown/reboot the system 3243fc4124cSDan Handley ******************************************************************************/ 3253fc4124cSDan Handley static void __dead2 fvp_system_off(void) 3263fc4124cSDan Handley { 3273fc4124cSDan Handley /* Write the System Configuration Control Register */ 3283fc4124cSDan Handley mmio_write_32(V2M_SYSREGS_BASE + V2M_SYS_CFGCTRL, 3293fc4124cSDan Handley V2M_CFGCTRL_START | 3303fc4124cSDan Handley V2M_CFGCTRL_RW | 3313fc4124cSDan Handley V2M_CFGCTRL_FUNC(V2M_FUNC_SHUTDOWN)); 3323fc4124cSDan Handley wfi(); 3333fc4124cSDan Handley ERROR("FVP System Off: operation not handled.\n"); 3343fc4124cSDan Handley panic(); 3353fc4124cSDan Handley } 3363fc4124cSDan Handley 3373fc4124cSDan Handley static void __dead2 fvp_system_reset(void) 3383fc4124cSDan Handley { 3393fc4124cSDan Handley /* Write the System Configuration Control Register */ 3403fc4124cSDan Handley mmio_write_32(V2M_SYSREGS_BASE + V2M_SYS_CFGCTRL, 3413fc4124cSDan Handley V2M_CFGCTRL_START | 3423fc4124cSDan Handley V2M_CFGCTRL_RW | 3433fc4124cSDan Handley V2M_CFGCTRL_FUNC(V2M_FUNC_REBOOT)); 3443fc4124cSDan Handley wfi(); 3453fc4124cSDan Handley ERROR("FVP System Reset: operation not handled.\n"); 3463fc4124cSDan Handley panic(); 3473fc4124cSDan Handley } 3483fc4124cSDan Handley 3491298ae02SJeenu Viswambharan static int fvp_node_hw_state(u_register_t target_cpu, 3501298ae02SJeenu Viswambharan unsigned int power_level) 3511298ae02SJeenu Viswambharan { 3521298ae02SJeenu Viswambharan unsigned int psysr; 3531298ae02SJeenu Viswambharan int ret; 3541298ae02SJeenu Viswambharan 3551298ae02SJeenu Viswambharan /* 3561298ae02SJeenu Viswambharan * The format of 'power_level' is implementation-defined, but 0 must 3571298ae02SJeenu Viswambharan * mean a CPU. We also allow 1 to denote the cluster 3581298ae02SJeenu Viswambharan */ 359e02f469fSSathees Balya if ((power_level != ARM_PWR_LVL0) && (power_level != ARM_PWR_LVL1)) 3601298ae02SJeenu Viswambharan return PSCI_E_INVALID_PARAMS; 3611298ae02SJeenu Viswambharan 3621298ae02SJeenu Viswambharan /* 3631298ae02SJeenu Viswambharan * Read the status of the given MPDIR from FVP power controller. The 3641298ae02SJeenu Viswambharan * power controller only gives us on/off status, so map that to expected 3651298ae02SJeenu Viswambharan * return values of the PSCI call 3661298ae02SJeenu Viswambharan */ 3671298ae02SJeenu Viswambharan psysr = fvp_pwrc_read_psysr(target_cpu); 3681298ae02SJeenu Viswambharan if (psysr == PSYSR_INVALID) 3691298ae02SJeenu Viswambharan return PSCI_E_INVALID_PARAMS; 3701298ae02SJeenu Viswambharan 371649c48f5SJonathan Wright if (power_level == ARM_PWR_LVL0) { 372e02f469fSSathees Balya ret = ((psysr & PSYSR_AFF_L0) != 0U) ? HW_ON : HW_OFF; 373649c48f5SJonathan Wright } else { 374649c48f5SJonathan Wright /* power_level == ARM_PWR_LVL1 */ 375e02f469fSSathees Balya ret = ((psysr & PSYSR_AFF_L1) != 0U) ? HW_ON : HW_OFF; 3761298ae02SJeenu Viswambharan } 3771298ae02SJeenu Viswambharan 3781298ae02SJeenu Viswambharan return ret; 3791298ae02SJeenu Viswambharan } 3801298ae02SJeenu Viswambharan 381e35a3fb5SSoby Mathew /* 382e35a3fb5SSoby Mathew * The FVP doesn't truly support power management at SYSTEM power domain. The 383e35a3fb5SSoby Mathew * SYSTEM_SUSPEND will be down-graded to the cluster level within the platform 384e35a3fb5SSoby Mathew * layer. The `fake` SYSTEM_SUSPEND allows us to validate some of the driver 385e35a3fb5SSoby Mathew * save and restore sequences on FVP. 386e35a3fb5SSoby Mathew */ 3871af540efSRoberto Vargas #if !ARM_BL31_IN_DRAM 3881af540efSRoberto Vargas static void fvp_get_sys_suspend_power_state(psci_power_state_t *req_state) 389e35a3fb5SSoby Mathew { 390e35a3fb5SSoby Mathew unsigned int i; 391e35a3fb5SSoby Mathew 392e35a3fb5SSoby Mathew for (i = ARM_PWR_LVL0; i <= PLAT_MAX_PWR_LVL; i++) 393e35a3fb5SSoby Mathew req_state->pwr_domain_state[i] = ARM_LOCAL_STATE_OFF; 394e35a3fb5SSoby Mathew } 3951af540efSRoberto Vargas #endif 396e35a3fb5SSoby Mathew 397e35a3fb5SSoby Mathew /******************************************************************************* 398e35a3fb5SSoby Mathew * Handler to filter PSCI requests. 399e35a3fb5SSoby Mathew ******************************************************************************/ 400e35a3fb5SSoby Mathew /* 401e35a3fb5SSoby Mathew * The system power domain suspend is only supported only via 402e35a3fb5SSoby Mathew * PSCI SYSTEM_SUSPEND API. PSCI CPU_SUSPEND request to system power domain 403e35a3fb5SSoby Mathew * will be downgraded to the lower level. 404e35a3fb5SSoby Mathew */ 405e35a3fb5SSoby Mathew static int fvp_validate_power_state(unsigned int power_state, 406e35a3fb5SSoby Mathew psci_power_state_t *req_state) 407e35a3fb5SSoby Mathew { 408e35a3fb5SSoby Mathew int rc; 409e35a3fb5SSoby Mathew rc = arm_validate_power_state(power_state, req_state); 410e35a3fb5SSoby Mathew 411e35a3fb5SSoby Mathew /* 412e35a3fb5SSoby Mathew * Ensure that the system power domain level is never suspended 413e35a3fb5SSoby Mathew * via PSCI CPU SUSPEND API. Currently system suspend is only 414e35a3fb5SSoby Mathew * supported via PSCI SYSTEM SUSPEND API. 415e35a3fb5SSoby Mathew */ 416e35a3fb5SSoby Mathew req_state->pwr_domain_state[ARM_PWR_LVL2] = ARM_LOCAL_STATE_RUN; 417e35a3fb5SSoby Mathew return rc; 418e35a3fb5SSoby Mathew } 419e35a3fb5SSoby Mathew 420e35a3fb5SSoby Mathew /* 421e35a3fb5SSoby Mathew * Custom `translate_power_state_by_mpidr` handler for FVP. Unlike in the 422e35a3fb5SSoby Mathew * `fvp_validate_power_state`, we do not downgrade the system power 423e35a3fb5SSoby Mathew * domain level request in `power_state` as it will be used to query the 424e35a3fb5SSoby Mathew * PSCI_STAT_COUNT/RESIDENCY at the system power domain level. 425e35a3fb5SSoby Mathew */ 426e35a3fb5SSoby Mathew static int fvp_translate_power_state_by_mpidr(u_register_t mpidr, 427e35a3fb5SSoby Mathew unsigned int power_state, 428e35a3fb5SSoby Mathew psci_power_state_t *output_state) 429e35a3fb5SSoby Mathew { 430e35a3fb5SSoby Mathew return arm_validate_power_state(power_state, output_state); 431e35a3fb5SSoby Mathew } 432e35a3fb5SSoby Mathew 4333fc4124cSDan Handley /******************************************************************************* 434785fb92bSSoby Mathew * Export the platform handlers via plat_arm_psci_pm_ops. The ARM Standard 435785fb92bSSoby Mathew * platform layer will take care of registering the handlers with PSCI. 4363fc4124cSDan Handley ******************************************************************************/ 4375486a965SSoby Mathew plat_psci_ops_t plat_arm_psci_pm_ops = { 43838dce70fSSoby Mathew .cpu_standby = fvp_cpu_standby, 43938dce70fSSoby Mathew .pwr_domain_on = fvp_pwr_domain_on, 44038dce70fSSoby Mathew .pwr_domain_off = fvp_pwr_domain_off, 44138dce70fSSoby Mathew .pwr_domain_suspend = fvp_pwr_domain_suspend, 44238dce70fSSoby Mathew .pwr_domain_on_finish = fvp_pwr_domain_on_finish, 4436806cd23SMadhukar Pappireddy .pwr_domain_on_finish_late = fvp_pwr_domain_on_finish_late, 44438dce70fSSoby Mathew .pwr_domain_suspend_finish = fvp_pwr_domain_suspend_finish, 4453fc4124cSDan Handley .system_off = fvp_system_off, 4463fc4124cSDan Handley .system_reset = fvp_system_reset, 447e35a3fb5SSoby Mathew .validate_power_state = fvp_validate_power_state, 44871e7a4e5SJeenu Viswambharan .validate_ns_entrypoint = arm_validate_psci_entrypoint, 449e35a3fb5SSoby Mathew .translate_power_state_by_mpidr = fvp_translate_power_state_by_mpidr, 450f145403cSRoberto Vargas .get_node_hw_state = fvp_node_hw_state, 4517d44ac1eSAntonio Nino Diaz #if !ARM_BL31_IN_DRAM 4527d44ac1eSAntonio Nino Diaz /* 4537d44ac1eSAntonio Nino Diaz * The TrustZone Controller is set up during the warmboot sequence after 4547d44ac1eSAntonio Nino Diaz * resuming the CPU from a SYSTEM_SUSPEND. If BL31 is located in SRAM 4557d44ac1eSAntonio Nino Diaz * this is not a problem but, if it is in TZC-secured DRAM, it tries to 4567d44ac1eSAntonio Nino Diaz * reconfigure the same memory it is running on, causing an exception. 4577d44ac1eSAntonio Nino Diaz */ 458e35a3fb5SSoby Mathew .get_sys_suspend_power_state = fvp_get_sys_suspend_power_state, 4597d44ac1eSAntonio Nino Diaz #endif 460f145403cSRoberto Vargas .mem_protect_chk = arm_psci_mem_protect_chk, 461f145403cSRoberto Vargas .read_mem_protect = arm_psci_read_mem_protect, 462f145403cSRoberto Vargas .write_mem_protect = arm_nor_psci_write_mem_protect, 4633fc4124cSDan Handley }; 46489f2e589SChandni Cherukuri 46589f2e589SChandni Cherukuri const plat_psci_ops_t *plat_arm_psci_override_pm_ops(plat_psci_ops_t *ops) 46689f2e589SChandni Cherukuri { 46789f2e589SChandni Cherukuri return ops; 46889f2e589SChandni Cherukuri } 469