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 96437a09aSAndre 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 */ 616437a09aSAndre Przywara if (is_feat_spe_supported()) { 62281a08ccSDimitris Papastamos spe_disable(); 636437a09aSAndre 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()); 273e75cc247SWing Li 274e75cc247SWing Li return; 2753fc4124cSDan Handley } 2763fc4124cSDan Handley 2773fc4124cSDan Handley /******************************************************************************* 27838dce70fSSoby Mathew * FVP handler called when a power domain has just been powered on after 27938dce70fSSoby Mathew * being turned off earlier. The target_state encodes the low power state that 28038dce70fSSoby Mathew * each level has woken up from. 2813fc4124cSDan Handley ******************************************************************************/ 2821af540efSRoberto Vargas static void fvp_pwr_domain_on_finish(const psci_power_state_t *target_state) 2833fc4124cSDan Handley { 284f14d1886SSoby Mathew fvp_power_domain_on_finish_common(target_state); 2853fc4124cSDan Handley 2866806cd23SMadhukar Pappireddy } 2876806cd23SMadhukar Pappireddy 2886806cd23SMadhukar Pappireddy /******************************************************************************* 2896806cd23SMadhukar Pappireddy * FVP handler called when a power domain has just been powered on and the cpu 2906806cd23SMadhukar Pappireddy * and its cluster are fully participating in coherent transaction on the 2916806cd23SMadhukar Pappireddy * interconnect. Data cache must be enabled for CPU at this point. 2926806cd23SMadhukar Pappireddy ******************************************************************************/ 2936806cd23SMadhukar Pappireddy static void fvp_pwr_domain_on_finish_late(const psci_power_state_t *target_state) 2946806cd23SMadhukar Pappireddy { 2956806cd23SMadhukar Pappireddy /* Program GIC per-cpu distributor or re-distributor interface */ 29627573c59SAchin Gupta plat_arm_gic_pcpu_init(); 29727573c59SAchin Gupta 2986806cd23SMadhukar Pappireddy /* Enable GIC CPU interface */ 29927573c59SAchin Gupta plat_arm_gic_cpuif_enable(); 3003fc4124cSDan Handley } 3013fc4124cSDan Handley 3023fc4124cSDan Handley /******************************************************************************* 30338dce70fSSoby Mathew * FVP handler called when a power domain has just been powered on after 30438dce70fSSoby Mathew * having been suspended earlier. The target_state encodes the low power state 30538dce70fSSoby Mathew * that each level has woken up from. 3063fc4124cSDan Handley * TODO: At the moment we reuse the on finisher and reinitialize the secure 3073fc4124cSDan Handley * context. Need to implement a separate suspend finisher. 3083fc4124cSDan Handley ******************************************************************************/ 3091af540efSRoberto Vargas static void fvp_pwr_domain_suspend_finish(const psci_power_state_t *target_state) 3103fc4124cSDan Handley { 31138dce70fSSoby Mathew /* 31238dce70fSSoby Mathew * Nothing to be done on waking up from retention from CPU level. 31338dce70fSSoby Mathew */ 31438dce70fSSoby Mathew if (target_state->pwr_domain_state[ARM_PWR_LVL0] == 31538dce70fSSoby Mathew ARM_LOCAL_STATE_RET) 31638dce70fSSoby Mathew return; 31738dce70fSSoby Mathew 318f14d1886SSoby Mathew fvp_power_domain_on_finish_common(target_state); 319f14d1886SSoby Mathew 3206806cd23SMadhukar Pappireddy /* Enable GIC CPU interface */ 32127573c59SAchin Gupta plat_arm_gic_cpuif_enable(); 3223fc4124cSDan Handley } 3233fc4124cSDan Handley 3243fc4124cSDan Handley /******************************************************************************* 3253fc4124cSDan Handley * FVP handlers to shutdown/reboot the system 3263fc4124cSDan Handley ******************************************************************************/ 3273fc4124cSDan Handley static void __dead2 fvp_system_off(void) 3283fc4124cSDan Handley { 3293fc4124cSDan Handley /* Write the System Configuration Control Register */ 3303fc4124cSDan Handley mmio_write_32(V2M_SYSREGS_BASE + V2M_SYS_CFGCTRL, 3313fc4124cSDan Handley V2M_CFGCTRL_START | 3323fc4124cSDan Handley V2M_CFGCTRL_RW | 3333fc4124cSDan Handley V2M_CFGCTRL_FUNC(V2M_FUNC_SHUTDOWN)); 3343fc4124cSDan Handley wfi(); 3353fc4124cSDan Handley ERROR("FVP System Off: operation not handled.\n"); 3363fc4124cSDan Handley panic(); 3373fc4124cSDan Handley } 3383fc4124cSDan Handley 3393fc4124cSDan Handley static void __dead2 fvp_system_reset(void) 3403fc4124cSDan Handley { 3413fc4124cSDan Handley /* Write the System Configuration Control Register */ 3423fc4124cSDan Handley mmio_write_32(V2M_SYSREGS_BASE + V2M_SYS_CFGCTRL, 3433fc4124cSDan Handley V2M_CFGCTRL_START | 3443fc4124cSDan Handley V2M_CFGCTRL_RW | 3453fc4124cSDan Handley V2M_CFGCTRL_FUNC(V2M_FUNC_REBOOT)); 3463fc4124cSDan Handley wfi(); 3473fc4124cSDan Handley ERROR("FVP System Reset: operation not handled.\n"); 3483fc4124cSDan Handley panic(); 3493fc4124cSDan Handley } 3503fc4124cSDan Handley 3511298ae02SJeenu Viswambharan static int fvp_node_hw_state(u_register_t target_cpu, 3521298ae02SJeenu Viswambharan unsigned int power_level) 3531298ae02SJeenu Viswambharan { 3541298ae02SJeenu Viswambharan unsigned int psysr; 3551298ae02SJeenu Viswambharan int ret; 3561298ae02SJeenu Viswambharan 3571298ae02SJeenu Viswambharan /* 3581298ae02SJeenu Viswambharan * The format of 'power_level' is implementation-defined, but 0 must 3591298ae02SJeenu Viswambharan * mean a CPU. We also allow 1 to denote the cluster 3601298ae02SJeenu Viswambharan */ 361e02f469fSSathees Balya if ((power_level != ARM_PWR_LVL0) && (power_level != ARM_PWR_LVL1)) 3621298ae02SJeenu Viswambharan return PSCI_E_INVALID_PARAMS; 3631298ae02SJeenu Viswambharan 3641298ae02SJeenu Viswambharan /* 3651298ae02SJeenu Viswambharan * Read the status of the given MPDIR from FVP power controller. The 3661298ae02SJeenu Viswambharan * power controller only gives us on/off status, so map that to expected 3671298ae02SJeenu Viswambharan * return values of the PSCI call 3681298ae02SJeenu Viswambharan */ 3691298ae02SJeenu Viswambharan psysr = fvp_pwrc_read_psysr(target_cpu); 3701298ae02SJeenu Viswambharan if (psysr == PSYSR_INVALID) 3711298ae02SJeenu Viswambharan return PSCI_E_INVALID_PARAMS; 3721298ae02SJeenu Viswambharan 373649c48f5SJonathan Wright if (power_level == ARM_PWR_LVL0) { 374e02f469fSSathees Balya ret = ((psysr & PSYSR_AFF_L0) != 0U) ? HW_ON : HW_OFF; 375649c48f5SJonathan Wright } else { 376649c48f5SJonathan Wright /* power_level == ARM_PWR_LVL1 */ 377e02f469fSSathees Balya ret = ((psysr & PSYSR_AFF_L1) != 0U) ? HW_ON : HW_OFF; 3781298ae02SJeenu Viswambharan } 3791298ae02SJeenu Viswambharan 3801298ae02SJeenu Viswambharan return ret; 3811298ae02SJeenu Viswambharan } 3821298ae02SJeenu Viswambharan 383e35a3fb5SSoby Mathew /* 384e35a3fb5SSoby Mathew * The FVP doesn't truly support power management at SYSTEM power domain. The 385e35a3fb5SSoby Mathew * SYSTEM_SUSPEND will be down-graded to the cluster level within the platform 386e35a3fb5SSoby Mathew * layer. The `fake` SYSTEM_SUSPEND allows us to validate some of the driver 387e35a3fb5SSoby Mathew * save and restore sequences on FVP. 388e35a3fb5SSoby Mathew */ 3891af540efSRoberto Vargas #if !ARM_BL31_IN_DRAM 3901af540efSRoberto Vargas static void fvp_get_sys_suspend_power_state(psci_power_state_t *req_state) 391e35a3fb5SSoby Mathew { 392e35a3fb5SSoby Mathew unsigned int i; 393e35a3fb5SSoby Mathew 394e35a3fb5SSoby Mathew for (i = ARM_PWR_LVL0; i <= PLAT_MAX_PWR_LVL; i++) 395e35a3fb5SSoby Mathew req_state->pwr_domain_state[i] = ARM_LOCAL_STATE_OFF; 396*e0ef05bbSWing Li 397*e0ef05bbSWing Li #if PSCI_OS_INIT_MODE 398*e0ef05bbSWing Li req_state->last_at_pwrlvl = PLAT_MAX_PWR_LVL; 399*e0ef05bbSWing Li #endif 400e35a3fb5SSoby Mathew } 4011af540efSRoberto Vargas #endif 402e35a3fb5SSoby Mathew 403e35a3fb5SSoby Mathew /******************************************************************************* 404e35a3fb5SSoby Mathew * Handler to filter PSCI requests. 405e35a3fb5SSoby Mathew ******************************************************************************/ 406e35a3fb5SSoby Mathew /* 407e35a3fb5SSoby Mathew * The system power domain suspend is only supported only via 408e35a3fb5SSoby Mathew * PSCI SYSTEM_SUSPEND API. PSCI CPU_SUSPEND request to system power domain 409e35a3fb5SSoby Mathew * will be downgraded to the lower level. 410e35a3fb5SSoby Mathew */ 411e35a3fb5SSoby Mathew static int fvp_validate_power_state(unsigned int power_state, 412e35a3fb5SSoby Mathew psci_power_state_t *req_state) 413e35a3fb5SSoby Mathew { 414e35a3fb5SSoby Mathew int rc; 415e35a3fb5SSoby Mathew rc = arm_validate_power_state(power_state, req_state); 416e35a3fb5SSoby Mathew 417e35a3fb5SSoby Mathew /* 418e35a3fb5SSoby Mathew * Ensure that the system power domain level is never suspended 419e35a3fb5SSoby Mathew * via PSCI CPU SUSPEND API. Currently system suspend is only 420e35a3fb5SSoby Mathew * supported via PSCI SYSTEM SUSPEND API. 421e35a3fb5SSoby Mathew */ 422e35a3fb5SSoby Mathew req_state->pwr_domain_state[ARM_PWR_LVL2] = ARM_LOCAL_STATE_RUN; 423e35a3fb5SSoby Mathew return rc; 424e35a3fb5SSoby Mathew } 425e35a3fb5SSoby Mathew 426e35a3fb5SSoby Mathew /* 427e35a3fb5SSoby Mathew * Custom `translate_power_state_by_mpidr` handler for FVP. Unlike in the 428e35a3fb5SSoby Mathew * `fvp_validate_power_state`, we do not downgrade the system power 429e35a3fb5SSoby Mathew * domain level request in `power_state` as it will be used to query the 430e35a3fb5SSoby Mathew * PSCI_STAT_COUNT/RESIDENCY at the system power domain level. 431e35a3fb5SSoby Mathew */ 432e35a3fb5SSoby Mathew static int fvp_translate_power_state_by_mpidr(u_register_t mpidr, 433e35a3fb5SSoby Mathew unsigned int power_state, 434e35a3fb5SSoby Mathew psci_power_state_t *output_state) 435e35a3fb5SSoby Mathew { 436e35a3fb5SSoby Mathew return arm_validate_power_state(power_state, output_state); 437e35a3fb5SSoby Mathew } 438e35a3fb5SSoby Mathew 4393fc4124cSDan Handley /******************************************************************************* 440785fb92bSSoby Mathew * Export the platform handlers via plat_arm_psci_pm_ops. The ARM Standard 441785fb92bSSoby Mathew * platform layer will take care of registering the handlers with PSCI. 4423fc4124cSDan Handley ******************************************************************************/ 4435486a965SSoby Mathew plat_psci_ops_t plat_arm_psci_pm_ops = { 44438dce70fSSoby Mathew .cpu_standby = fvp_cpu_standby, 44538dce70fSSoby Mathew .pwr_domain_on = fvp_pwr_domain_on, 44638dce70fSSoby Mathew .pwr_domain_off = fvp_pwr_domain_off, 44738dce70fSSoby Mathew .pwr_domain_suspend = fvp_pwr_domain_suspend, 44838dce70fSSoby Mathew .pwr_domain_on_finish = fvp_pwr_domain_on_finish, 4496806cd23SMadhukar Pappireddy .pwr_domain_on_finish_late = fvp_pwr_domain_on_finish_late, 45038dce70fSSoby Mathew .pwr_domain_suspend_finish = fvp_pwr_domain_suspend_finish, 4513fc4124cSDan Handley .system_off = fvp_system_off, 4523fc4124cSDan Handley .system_reset = fvp_system_reset, 453e35a3fb5SSoby Mathew .validate_power_state = fvp_validate_power_state, 45471e7a4e5SJeenu Viswambharan .validate_ns_entrypoint = arm_validate_psci_entrypoint, 455e35a3fb5SSoby Mathew .translate_power_state_by_mpidr = fvp_translate_power_state_by_mpidr, 456f145403cSRoberto Vargas .get_node_hw_state = fvp_node_hw_state, 4577d44ac1eSAntonio Nino Diaz #if !ARM_BL31_IN_DRAM 4587d44ac1eSAntonio Nino Diaz /* 4597d44ac1eSAntonio Nino Diaz * The TrustZone Controller is set up during the warmboot sequence after 4607d44ac1eSAntonio Nino Diaz * resuming the CPU from a SYSTEM_SUSPEND. If BL31 is located in SRAM 4617d44ac1eSAntonio Nino Diaz * this is not a problem but, if it is in TZC-secured DRAM, it tries to 4627d44ac1eSAntonio Nino Diaz * reconfigure the same memory it is running on, causing an exception. 4637d44ac1eSAntonio Nino Diaz */ 464e35a3fb5SSoby Mathew .get_sys_suspend_power_state = fvp_get_sys_suspend_power_state, 4657d44ac1eSAntonio Nino Diaz #endif 466f145403cSRoberto Vargas .mem_protect_chk = arm_psci_mem_protect_chk, 467f145403cSRoberto Vargas .read_mem_protect = arm_psci_read_mem_protect, 468f145403cSRoberto Vargas .write_mem_protect = arm_nor_psci_write_mem_protect, 4693fc4124cSDan Handley }; 47089f2e589SChandni Cherukuri 47189f2e589SChandni Cherukuri const plat_psci_ops_t *plat_arm_psci_override_pm_ops(plat_psci_ops_t *ops) 47289f2e589SChandni Cherukuri { 47389f2e589SChandni Cherukuri return ops; 47489f2e589SChandni Cherukuri } 475