xref: /rk3399_ARM-atf/plat/arm/board/fvp/fvp_pm.c (revision 234bc7f88ed42a5305016009c47e8a6dc3408f96)
13fc4124cSDan Handley /*
2dc6aad2eSRoberto Vargas  * Copyright (c) 2013-2018, 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>
83fc4124cSDan Handley #include <errno.h>
909d40e0eSAntonio Nino Diaz 
1009d40e0eSAntonio Nino Diaz #include <arch_helpers.h>
1109d40e0eSAntonio Nino Diaz #include <common/debug.h>
1209d40e0eSAntonio Nino Diaz #include <drivers/arm/gicv3.h>
1309d40e0eSAntonio Nino Diaz #include <lib/extensions/spe.h>
1409d40e0eSAntonio Nino Diaz #include <lib/mmio.h>
1509d40e0eSAntonio Nino Diaz #include <lib/psci/psci.h>
1609d40e0eSAntonio Nino Diaz #include <plat/common/platform.h>
17*234bc7f8SAntonio Nino Diaz #include <platform_def.h>
1809d40e0eSAntonio Nino Diaz 
1909d40e0eSAntonio Nino Diaz #include <arm_config.h>
203fc4124cSDan Handley #include <plat_arm.h>
2109d40e0eSAntonio Nino Diaz 
221af540efSRoberto Vargas #include "../../../../drivers/arm/gic/v3/gicv3_private.h"
233fc4124cSDan Handley #include "drivers/pwrc/fvp_pwrc.h"
243fc4124cSDan Handley #include "fvp_private.h"
253fc4124cSDan Handley 
263fc4124cSDan Handley 
272204afdeSSoby Mathew #if ARM_RECOM_STATE_ID_ENC
282204afdeSSoby Mathew /*
292204afdeSSoby Mathew  *  The table storing the valid idle power states. Ensure that the
302204afdeSSoby Mathew  *  array entries are populated in ascending order of state-id to
312204afdeSSoby Mathew  *  enable us to use binary search during power state validation.
322204afdeSSoby Mathew  *  The table must be terminated by a NULL entry.
332204afdeSSoby Mathew  */
342204afdeSSoby Mathew const unsigned int arm_pm_idle_states[] = {
352204afdeSSoby Mathew 	/* State-id - 0x01 */
362204afdeSSoby Mathew 	arm_make_pwrstate_lvl1(ARM_LOCAL_STATE_RUN, ARM_LOCAL_STATE_RET,
372204afdeSSoby Mathew 			ARM_PWR_LVL0, PSTATE_TYPE_STANDBY),
382204afdeSSoby Mathew 	/* State-id - 0x02 */
392204afdeSSoby Mathew 	arm_make_pwrstate_lvl1(ARM_LOCAL_STATE_RUN, ARM_LOCAL_STATE_OFF,
402204afdeSSoby Mathew 			ARM_PWR_LVL0, PSTATE_TYPE_POWERDOWN),
412204afdeSSoby Mathew 	/* State-id - 0x22 */
422204afdeSSoby Mathew 	arm_make_pwrstate_lvl1(ARM_LOCAL_STATE_OFF, ARM_LOCAL_STATE_OFF,
432204afdeSSoby Mathew 			ARM_PWR_LVL1, PSTATE_TYPE_POWERDOWN),
44e35a3fb5SSoby Mathew 	/* State-id - 0x222 */
45e35a3fb5SSoby Mathew 	arm_make_pwrstate_lvl2(ARM_LOCAL_STATE_OFF, ARM_LOCAL_STATE_OFF,
46e35a3fb5SSoby Mathew 		ARM_LOCAL_STATE_OFF, ARM_PWR_LVL2, PSTATE_TYPE_POWERDOWN),
472204afdeSSoby Mathew 	0,
482204afdeSSoby Mathew };
492204afdeSSoby Mathew #endif
502204afdeSSoby Mathew 
513fc4124cSDan Handley /*******************************************************************************
523fc4124cSDan Handley  * Function which implements the common FVP specific operations to power down a
533fc4124cSDan Handley  * cluster in response to a CPU_OFF or CPU_SUSPEND request.
543fc4124cSDan Handley  ******************************************************************************/
553fc4124cSDan Handley static void fvp_cluster_pwrdwn_common(void)
563fc4124cSDan Handley {
573fc4124cSDan Handley 	uint64_t mpidr = read_mpidr_el1();
583fc4124cSDan Handley 
59d832aee9Sdp-arm #if ENABLE_SPE_FOR_LOWER_ELS
60d832aee9Sdp-arm 	/*
61d832aee9Sdp-arm 	 * On power down we need to disable statistical profiling extensions
62d832aee9Sdp-arm 	 * before exiting coherency.
63d832aee9Sdp-arm 	 */
64281a08ccSDimitris Papastamos 	spe_disable();
65d832aee9Sdp-arm #endif
66d832aee9Sdp-arm 
673fc4124cSDan Handley 	/* Disable coherency if this cluster is to be turned off */
686355f234SVikram Kanigiri 	fvp_interconnect_disable();
693fc4124cSDan Handley 
703fc4124cSDan Handley 	/* Program the power controller to turn the cluster off */
713fc4124cSDan Handley 	fvp_pwrc_write_pcoffr(mpidr);
723fc4124cSDan Handley }
733fc4124cSDan Handley 
74e35a3fb5SSoby Mathew /*
75e35a3fb5SSoby Mathew  * Empty implementation of these hooks avoid setting the GICR_WAKER.Sleep bit
76e35a3fb5SSoby Mathew  * on ARM GICv3 implementations on FVP. This is required, because FVP does not
77e35a3fb5SSoby Mathew  * support SYSTEM_SUSPEND and it is `faked` in firmware. Hence, for wake up
78e35a3fb5SSoby Mathew  * from `fake` system suspend the GIC must not be powered off.
79e35a3fb5SSoby Mathew  */
80dc6aad2eSRoberto Vargas void arm_gicv3_distif_pre_save(unsigned int rdist_proc_num)
81e35a3fb5SSoby Mathew {}
82e35a3fb5SSoby Mathew 
83dc6aad2eSRoberto Vargas void arm_gicv3_distif_post_restore(unsigned int rdist_proc_num)
84e35a3fb5SSoby Mathew {}
85e35a3fb5SSoby Mathew 
86f14d1886SSoby Mathew static void fvp_power_domain_on_finish_common(const psci_power_state_t *target_state)
87f14d1886SSoby Mathew {
88f14d1886SSoby Mathew 	unsigned long mpidr;
89f14d1886SSoby Mathew 
90f14d1886SSoby Mathew 	assert(target_state->pwr_domain_state[ARM_PWR_LVL0] ==
91f14d1886SSoby Mathew 					ARM_LOCAL_STATE_OFF);
92f14d1886SSoby Mathew 
93f14d1886SSoby Mathew 	/* Get the mpidr for this cpu */
94f14d1886SSoby Mathew 	mpidr = read_mpidr_el1();
95f14d1886SSoby Mathew 
96f14d1886SSoby Mathew 	/* Perform the common cluster specific operations */
97f14d1886SSoby Mathew 	if (target_state->pwr_domain_state[ARM_PWR_LVL1] ==
98f14d1886SSoby Mathew 					ARM_LOCAL_STATE_OFF) {
99f14d1886SSoby Mathew 		/*
100f14d1886SSoby Mathew 		 * This CPU might have woken up whilst the cluster was
101f14d1886SSoby Mathew 		 * attempting to power down. In this case the FVP power
102f14d1886SSoby Mathew 		 * controller will have a pending cluster power off request
103f14d1886SSoby Mathew 		 * which needs to be cleared by writing to the PPONR register.
104f14d1886SSoby Mathew 		 * This prevents the power controller from interpreting a
105f14d1886SSoby Mathew 		 * subsequent entry of this cpu into a simple wfi as a power
106f14d1886SSoby Mathew 		 * down request.
107f14d1886SSoby Mathew 		 */
108f14d1886SSoby Mathew 		fvp_pwrc_write_pponr(mpidr);
109f14d1886SSoby Mathew 
110f14d1886SSoby Mathew 		/* Enable coherency if this cluster was off */
1116355f234SVikram Kanigiri 		fvp_interconnect_enable();
112f14d1886SSoby Mathew 	}
113e35a3fb5SSoby Mathew 	/* Perform the common system specific operations */
114e35a3fb5SSoby Mathew 	if (target_state->pwr_domain_state[ARM_PWR_LVL2] ==
115e35a3fb5SSoby Mathew 						ARM_LOCAL_STATE_OFF)
116e35a3fb5SSoby Mathew 		arm_system_pwr_domain_resume();
117f14d1886SSoby Mathew 
118f14d1886SSoby Mathew 	/*
119f14d1886SSoby Mathew 	 * Clear PWKUPR.WEN bit to ensure interrupts do not interfere
120f14d1886SSoby Mathew 	 * with a cpu power down unless the bit is set again
121f14d1886SSoby Mathew 	 */
122f14d1886SSoby Mathew 	fvp_pwrc_clr_wen(mpidr);
123f14d1886SSoby Mathew }
124f14d1886SSoby Mathew 
125f14d1886SSoby Mathew 
1263fc4124cSDan Handley /*******************************************************************************
12738dce70fSSoby Mathew  * FVP handler called when a CPU is about to enter standby.
1283fc4124cSDan Handley  ******************************************************************************/
1291af540efSRoberto Vargas static void fvp_cpu_standby(plat_local_state_t cpu_state)
1303fc4124cSDan Handley {
13138dce70fSSoby Mathew 
13238dce70fSSoby Mathew 	assert(cpu_state == ARM_LOCAL_STATE_RET);
13338dce70fSSoby Mathew 
1343fc4124cSDan Handley 	/*
1353fc4124cSDan Handley 	 * Enter standby state
1363fc4124cSDan Handley 	 * dsb is good practice before using wfi to enter low power states
1373fc4124cSDan Handley 	 */
1383fc4124cSDan Handley 	dsb();
1393fc4124cSDan Handley 	wfi();
1403fc4124cSDan Handley }
1413fc4124cSDan Handley 
1423fc4124cSDan Handley /*******************************************************************************
14338dce70fSSoby Mathew  * FVP handler called when a power domain is about to be turned on. The
14438dce70fSSoby Mathew  * mpidr determines the CPU to be turned on.
1453fc4124cSDan Handley  ******************************************************************************/
1461af540efSRoberto Vargas static int fvp_pwr_domain_on(u_register_t mpidr)
1473fc4124cSDan Handley {
1483fc4124cSDan Handley 	int rc = PSCI_E_SUCCESS;
1493fc4124cSDan Handley 	unsigned int psysr;
1503fc4124cSDan Handley 
1513fc4124cSDan Handley 	/*
1520f09c8f7SSandrine Bailleux 	 * Ensure that we do not cancel an inflight power off request for the
1530f09c8f7SSandrine Bailleux 	 * target cpu. That would leave it in a zombie wfi. Wait for it to power
1540f09c8f7SSandrine Bailleux 	 * off and then program the power controller to turn that CPU on.
1553fc4124cSDan Handley 	 */
1563fc4124cSDan Handley 	do {
1573fc4124cSDan Handley 		psysr = fvp_pwrc_read_psysr(mpidr);
158e02f469fSSathees Balya 	} while ((psysr & PSYSR_AFF_L0) != 0U);
1593fc4124cSDan Handley 
1603fc4124cSDan Handley 	fvp_pwrc_write_pponr(mpidr);
1613fc4124cSDan Handley 	return rc;
1623fc4124cSDan Handley }
1633fc4124cSDan Handley 
1643fc4124cSDan Handley /*******************************************************************************
16538dce70fSSoby Mathew  * FVP handler called when a power domain is about to be turned off. The
16638dce70fSSoby Mathew  * target_state encodes the power state that each level should transition to.
1673fc4124cSDan Handley  ******************************************************************************/
1681af540efSRoberto Vargas static void fvp_pwr_domain_off(const psci_power_state_t *target_state)
1693fc4124cSDan Handley {
17038dce70fSSoby Mathew 	assert(target_state->pwr_domain_state[ARM_PWR_LVL0] ==
17138dce70fSSoby Mathew 					ARM_LOCAL_STATE_OFF);
1723fc4124cSDan Handley 
1733fc4124cSDan Handley 	/*
17438dce70fSSoby Mathew 	 * If execution reaches this stage then this power domain will be
17538dce70fSSoby Mathew 	 * suspended. Perform at least the cpu specific actions followed
17638dce70fSSoby Mathew 	 * by the cluster specific operations if applicable.
1773fc4124cSDan Handley 	 */
17874a9578cSJeenu Viswambharan 
17974a9578cSJeenu Viswambharan 	/* Prevent interrupts from spuriously waking up this cpu */
18074a9578cSJeenu Viswambharan 	plat_arm_gic_cpuif_disable();
18174a9578cSJeenu Viswambharan 
18274a9578cSJeenu Viswambharan 	/* Turn redistributor off */
18374a9578cSJeenu Viswambharan 	plat_arm_gic_redistif_off();
18474a9578cSJeenu Viswambharan 
18574a9578cSJeenu Viswambharan 	/* Program the power controller to power off this cpu. */
18674a9578cSJeenu Viswambharan 	fvp_pwrc_write_ppoffr(read_mpidr_el1());
1873fc4124cSDan Handley 
18838dce70fSSoby Mathew 	if (target_state->pwr_domain_state[ARM_PWR_LVL1] ==
18938dce70fSSoby Mathew 					ARM_LOCAL_STATE_OFF)
1903fc4124cSDan Handley 		fvp_cluster_pwrdwn_common();
1913fc4124cSDan Handley 
1923fc4124cSDan Handley }
1933fc4124cSDan Handley 
1943fc4124cSDan Handley /*******************************************************************************
19538dce70fSSoby Mathew  * FVP handler called when a power domain is about to be suspended. The
19638dce70fSSoby Mathew  * target_state encodes the power state that each level should transition to.
1973fc4124cSDan Handley  ******************************************************************************/
1981af540efSRoberto Vargas static void fvp_pwr_domain_suspend(const psci_power_state_t *target_state)
1993fc4124cSDan Handley {
2003fc4124cSDan Handley 	unsigned long mpidr;
2013fc4124cSDan Handley 
20238dce70fSSoby Mathew 	/*
20338dce70fSSoby Mathew 	 * FVP has retention only at cpu level. Just return
20438dce70fSSoby Mathew 	 * as nothing is to be done for retention.
20538dce70fSSoby Mathew 	 */
20638dce70fSSoby Mathew 	if (target_state->pwr_domain_state[ARM_PWR_LVL0] ==
20738dce70fSSoby Mathew 					ARM_LOCAL_STATE_RET)
2083fc4124cSDan Handley 		return;
2093fc4124cSDan Handley 
21038dce70fSSoby Mathew 	assert(target_state->pwr_domain_state[ARM_PWR_LVL0] ==
21138dce70fSSoby Mathew 					ARM_LOCAL_STATE_OFF);
21238dce70fSSoby Mathew 
2133fc4124cSDan Handley 	/* Get the mpidr for this cpu */
2143fc4124cSDan Handley 	mpidr = read_mpidr_el1();
2153fc4124cSDan Handley 
2163fc4124cSDan Handley 	/* Program the power controller to enable wakeup interrupts. */
2173fc4124cSDan Handley 	fvp_pwrc_set_wen(mpidr);
2183fc4124cSDan Handley 
21974a9578cSJeenu Viswambharan 	/* Prevent interrupts from spuriously waking up this cpu */
22074a9578cSJeenu Viswambharan 	plat_arm_gic_cpuif_disable();
22174a9578cSJeenu Viswambharan 
22274a9578cSJeenu Viswambharan 	/*
22374a9578cSJeenu Viswambharan 	 * The Redistributor is not powered off as it can potentially prevent
22474a9578cSJeenu Viswambharan 	 * wake up events reaching the CPUIF and/or might lead to losing
22574a9578cSJeenu Viswambharan 	 * register context.
22674a9578cSJeenu Viswambharan 	 */
22774a9578cSJeenu Viswambharan 
2283fc4124cSDan Handley 	/* Perform the common cluster specific operations */
22938dce70fSSoby Mathew 	if (target_state->pwr_domain_state[ARM_PWR_LVL1] ==
23038dce70fSSoby Mathew 					ARM_LOCAL_STATE_OFF)
2313fc4124cSDan Handley 		fvp_cluster_pwrdwn_common();
232e35a3fb5SSoby Mathew 
233e35a3fb5SSoby Mathew 	/* Perform the common system specific operations */
234e35a3fb5SSoby Mathew 	if (target_state->pwr_domain_state[ARM_PWR_LVL2] ==
235e35a3fb5SSoby Mathew 						ARM_LOCAL_STATE_OFF)
236e35a3fb5SSoby Mathew 		arm_system_pwr_domain_save();
237e35a3fb5SSoby Mathew 
238e35a3fb5SSoby Mathew 	/* Program the power controller to power off this cpu. */
239e35a3fb5SSoby Mathew 	fvp_pwrc_write_ppoffr(read_mpidr_el1());
2403fc4124cSDan Handley }
2413fc4124cSDan Handley 
2423fc4124cSDan Handley /*******************************************************************************
24338dce70fSSoby Mathew  * FVP handler called when a power domain has just been powered on after
24438dce70fSSoby Mathew  * being turned off earlier. The target_state encodes the low power state that
24538dce70fSSoby Mathew  * each level has woken up from.
2463fc4124cSDan Handley  ******************************************************************************/
2471af540efSRoberto Vargas static void fvp_pwr_domain_on_finish(const psci_power_state_t *target_state)
2483fc4124cSDan Handley {
249f14d1886SSoby Mathew 	fvp_power_domain_on_finish_common(target_state);
2503fc4124cSDan Handley 
2513fc4124cSDan Handley 	/* Enable the gic cpu interface */
25227573c59SAchin Gupta 	plat_arm_gic_pcpu_init();
25327573c59SAchin Gupta 
25427573c59SAchin Gupta 	/* Program the gic per-cpu distributor or re-distributor interface */
25527573c59SAchin Gupta 	plat_arm_gic_cpuif_enable();
2563fc4124cSDan Handley }
2573fc4124cSDan Handley 
2583fc4124cSDan Handley /*******************************************************************************
25938dce70fSSoby Mathew  * FVP handler called when a power domain has just been powered on after
26038dce70fSSoby Mathew  * having been suspended earlier. The target_state encodes the low power state
26138dce70fSSoby Mathew  * that each level has woken up from.
2623fc4124cSDan Handley  * TODO: At the moment we reuse the on finisher and reinitialize the secure
2633fc4124cSDan Handley  * context. Need to implement a separate suspend finisher.
2643fc4124cSDan Handley  ******************************************************************************/
2651af540efSRoberto Vargas static void fvp_pwr_domain_suspend_finish(const psci_power_state_t *target_state)
2663fc4124cSDan Handley {
26738dce70fSSoby Mathew 	/*
26838dce70fSSoby Mathew 	 * Nothing to be done on waking up from retention from CPU level.
26938dce70fSSoby Mathew 	 */
27038dce70fSSoby Mathew 	if (target_state->pwr_domain_state[ARM_PWR_LVL0] ==
27138dce70fSSoby Mathew 					ARM_LOCAL_STATE_RET)
27238dce70fSSoby Mathew 		return;
27338dce70fSSoby Mathew 
274f14d1886SSoby Mathew 	fvp_power_domain_on_finish_common(target_state);
275f14d1886SSoby Mathew 
276f14d1886SSoby Mathew 	/* Enable the gic cpu interface */
27727573c59SAchin Gupta 	plat_arm_gic_cpuif_enable();
2783fc4124cSDan Handley }
2793fc4124cSDan Handley 
2803fc4124cSDan Handley /*******************************************************************************
2813fc4124cSDan Handley  * FVP handlers to shutdown/reboot the system
2823fc4124cSDan Handley  ******************************************************************************/
2833fc4124cSDan Handley static void __dead2 fvp_system_off(void)
2843fc4124cSDan Handley {
2853fc4124cSDan Handley 	/* Write the System Configuration Control Register */
2863fc4124cSDan Handley 	mmio_write_32(V2M_SYSREGS_BASE + V2M_SYS_CFGCTRL,
2873fc4124cSDan Handley 		V2M_CFGCTRL_START |
2883fc4124cSDan Handley 		V2M_CFGCTRL_RW |
2893fc4124cSDan Handley 		V2M_CFGCTRL_FUNC(V2M_FUNC_SHUTDOWN));
2903fc4124cSDan Handley 	wfi();
2913fc4124cSDan Handley 	ERROR("FVP System Off: operation not handled.\n");
2923fc4124cSDan Handley 	panic();
2933fc4124cSDan Handley }
2943fc4124cSDan Handley 
2953fc4124cSDan Handley static void __dead2 fvp_system_reset(void)
2963fc4124cSDan Handley {
2973fc4124cSDan Handley 	/* Write the System Configuration Control Register */
2983fc4124cSDan Handley 	mmio_write_32(V2M_SYSREGS_BASE + V2M_SYS_CFGCTRL,
2993fc4124cSDan Handley 		V2M_CFGCTRL_START |
3003fc4124cSDan Handley 		V2M_CFGCTRL_RW |
3013fc4124cSDan Handley 		V2M_CFGCTRL_FUNC(V2M_FUNC_REBOOT));
3023fc4124cSDan Handley 	wfi();
3033fc4124cSDan Handley 	ERROR("FVP System Reset: operation not handled.\n");
3043fc4124cSDan Handley 	panic();
3053fc4124cSDan Handley }
3063fc4124cSDan Handley 
3071298ae02SJeenu Viswambharan static int fvp_node_hw_state(u_register_t target_cpu,
3081298ae02SJeenu Viswambharan 			     unsigned int power_level)
3091298ae02SJeenu Viswambharan {
3101298ae02SJeenu Viswambharan 	unsigned int psysr;
3111298ae02SJeenu Viswambharan 	int ret;
3121298ae02SJeenu Viswambharan 
3131298ae02SJeenu Viswambharan 	/*
3141298ae02SJeenu Viswambharan 	 * The format of 'power_level' is implementation-defined, but 0 must
3151298ae02SJeenu Viswambharan 	 * mean a CPU. We also allow 1 to denote the cluster
3161298ae02SJeenu Viswambharan 	 */
317e02f469fSSathees Balya 	if ((power_level != ARM_PWR_LVL0) && (power_level != ARM_PWR_LVL1))
3181298ae02SJeenu Viswambharan 		return PSCI_E_INVALID_PARAMS;
3191298ae02SJeenu Viswambharan 
3201298ae02SJeenu Viswambharan 	/*
3211298ae02SJeenu Viswambharan 	 * Read the status of the given MPDIR from FVP power controller. The
3221298ae02SJeenu Viswambharan 	 * power controller only gives us on/off status, so map that to expected
3231298ae02SJeenu Viswambharan 	 * return values of the PSCI call
3241298ae02SJeenu Viswambharan 	 */
3251298ae02SJeenu Viswambharan 	psysr = fvp_pwrc_read_psysr(target_cpu);
3261298ae02SJeenu Viswambharan 	if (psysr == PSYSR_INVALID)
3271298ae02SJeenu Viswambharan 		return PSCI_E_INVALID_PARAMS;
3281298ae02SJeenu Viswambharan 
329649c48f5SJonathan Wright 	if (power_level == ARM_PWR_LVL0) {
330e02f469fSSathees Balya 		ret = ((psysr & PSYSR_AFF_L0) != 0U) ? HW_ON : HW_OFF;
331649c48f5SJonathan Wright 	} else {
332649c48f5SJonathan Wright 		/* power_level == ARM_PWR_LVL1 */
333e02f469fSSathees Balya 		ret = ((psysr & PSYSR_AFF_L1) != 0U) ? HW_ON : HW_OFF;
3341298ae02SJeenu Viswambharan 	}
3351298ae02SJeenu Viswambharan 
3361298ae02SJeenu Viswambharan 	return ret;
3371298ae02SJeenu Viswambharan }
3381298ae02SJeenu Viswambharan 
339e35a3fb5SSoby Mathew /*
340e35a3fb5SSoby Mathew  * The FVP doesn't truly support power management at SYSTEM power domain. The
341e35a3fb5SSoby Mathew  * SYSTEM_SUSPEND will be down-graded to the cluster level within the platform
342e35a3fb5SSoby Mathew  * layer. The `fake` SYSTEM_SUSPEND allows us to validate some of the driver
343e35a3fb5SSoby Mathew  * save and restore sequences on FVP.
344e35a3fb5SSoby Mathew  */
3451af540efSRoberto Vargas #if !ARM_BL31_IN_DRAM
3461af540efSRoberto Vargas static void fvp_get_sys_suspend_power_state(psci_power_state_t *req_state)
347e35a3fb5SSoby Mathew {
348e35a3fb5SSoby Mathew 	unsigned int i;
349e35a3fb5SSoby Mathew 
350e35a3fb5SSoby Mathew 	for (i = ARM_PWR_LVL0; i <= PLAT_MAX_PWR_LVL; i++)
351e35a3fb5SSoby Mathew 		req_state->pwr_domain_state[i] = ARM_LOCAL_STATE_OFF;
352e35a3fb5SSoby Mathew }
3531af540efSRoberto Vargas #endif
354e35a3fb5SSoby Mathew 
355e35a3fb5SSoby Mathew /*******************************************************************************
356e35a3fb5SSoby Mathew  * Handler to filter PSCI requests.
357e35a3fb5SSoby Mathew  ******************************************************************************/
358e35a3fb5SSoby Mathew /*
359e35a3fb5SSoby Mathew  * The system power domain suspend is only supported only via
360e35a3fb5SSoby Mathew  * PSCI SYSTEM_SUSPEND API. PSCI CPU_SUSPEND request to system power domain
361e35a3fb5SSoby Mathew  * will be downgraded to the lower level.
362e35a3fb5SSoby Mathew  */
363e35a3fb5SSoby Mathew static int fvp_validate_power_state(unsigned int power_state,
364e35a3fb5SSoby Mathew 			    psci_power_state_t *req_state)
365e35a3fb5SSoby Mathew {
366e35a3fb5SSoby Mathew 	int rc;
367e35a3fb5SSoby Mathew 	rc = arm_validate_power_state(power_state, req_state);
368e35a3fb5SSoby Mathew 
369e35a3fb5SSoby Mathew 	/*
370e35a3fb5SSoby Mathew 	 * Ensure that the system power domain level is never suspended
371e35a3fb5SSoby Mathew 	 * via PSCI CPU SUSPEND API. Currently system suspend is only
372e35a3fb5SSoby Mathew 	 * supported via PSCI SYSTEM SUSPEND API.
373e35a3fb5SSoby Mathew 	 */
374e35a3fb5SSoby Mathew 	req_state->pwr_domain_state[ARM_PWR_LVL2] = ARM_LOCAL_STATE_RUN;
375e35a3fb5SSoby Mathew 	return rc;
376e35a3fb5SSoby Mathew }
377e35a3fb5SSoby Mathew 
378e35a3fb5SSoby Mathew /*
379e35a3fb5SSoby Mathew  * Custom `translate_power_state_by_mpidr` handler for FVP. Unlike in the
380e35a3fb5SSoby Mathew  * `fvp_validate_power_state`, we do not downgrade the system power
381e35a3fb5SSoby Mathew  * domain level request in `power_state` as it will be used to query the
382e35a3fb5SSoby Mathew  * PSCI_STAT_COUNT/RESIDENCY at the system power domain level.
383e35a3fb5SSoby Mathew  */
384e35a3fb5SSoby Mathew static int fvp_translate_power_state_by_mpidr(u_register_t mpidr,
385e35a3fb5SSoby Mathew 		unsigned int power_state,
386e35a3fb5SSoby Mathew 		psci_power_state_t *output_state)
387e35a3fb5SSoby Mathew {
388e35a3fb5SSoby Mathew 	return arm_validate_power_state(power_state, output_state);
389e35a3fb5SSoby Mathew }
390e35a3fb5SSoby Mathew 
3913fc4124cSDan Handley /*******************************************************************************
392785fb92bSSoby Mathew  * Export the platform handlers via plat_arm_psci_pm_ops. The ARM Standard
393785fb92bSSoby Mathew  * platform layer will take care of registering the handlers with PSCI.
3943fc4124cSDan Handley  ******************************************************************************/
3955486a965SSoby Mathew plat_psci_ops_t plat_arm_psci_pm_ops = {
39638dce70fSSoby Mathew 	.cpu_standby = fvp_cpu_standby,
39738dce70fSSoby Mathew 	.pwr_domain_on = fvp_pwr_domain_on,
39838dce70fSSoby Mathew 	.pwr_domain_off = fvp_pwr_domain_off,
39938dce70fSSoby Mathew 	.pwr_domain_suspend = fvp_pwr_domain_suspend,
40038dce70fSSoby Mathew 	.pwr_domain_on_finish = fvp_pwr_domain_on_finish,
40138dce70fSSoby Mathew 	.pwr_domain_suspend_finish = fvp_pwr_domain_suspend_finish,
4023fc4124cSDan Handley 	.system_off = fvp_system_off,
4033fc4124cSDan Handley 	.system_reset = fvp_system_reset,
404e35a3fb5SSoby Mathew 	.validate_power_state = fvp_validate_power_state,
40571e7a4e5SJeenu Viswambharan 	.validate_ns_entrypoint = arm_validate_psci_entrypoint,
406e35a3fb5SSoby Mathew 	.translate_power_state_by_mpidr = fvp_translate_power_state_by_mpidr,
407f145403cSRoberto Vargas 	.get_node_hw_state = fvp_node_hw_state,
4087d44ac1eSAntonio Nino Diaz #if !ARM_BL31_IN_DRAM
4097d44ac1eSAntonio Nino Diaz 	/*
4107d44ac1eSAntonio Nino Diaz 	 * The TrustZone Controller is set up during the warmboot sequence after
4117d44ac1eSAntonio Nino Diaz 	 * resuming the CPU from a SYSTEM_SUSPEND. If BL31 is located in SRAM
4127d44ac1eSAntonio Nino Diaz 	 * this is  not a problem but, if it is in TZC-secured DRAM, it tries to
4137d44ac1eSAntonio Nino Diaz 	 * reconfigure the same memory it is running on, causing an exception.
4147d44ac1eSAntonio Nino Diaz 	 */
415e35a3fb5SSoby Mathew 	.get_sys_suspend_power_state = fvp_get_sys_suspend_power_state,
4167d44ac1eSAntonio Nino Diaz #endif
417f145403cSRoberto Vargas 	.mem_protect_chk	= arm_psci_mem_protect_chk,
418f145403cSRoberto Vargas 	.read_mem_protect	= arm_psci_read_mem_protect,
419f145403cSRoberto Vargas 	.write_mem_protect	= arm_nor_psci_write_mem_protect,
4203fc4124cSDan Handley };
42189f2e589SChandni Cherukuri 
42289f2e589SChandni Cherukuri const plat_psci_ops_t *plat_arm_psci_override_pm_ops(plat_psci_ops_t *ops)
42389f2e589SChandni Cherukuri {
42489f2e589SChandni Cherukuri 	return ops;
42589f2e589SChandni Cherukuri }
426