xref: /rk3399_ARM-atf/plat/xilinx/versal_net/plat_psci_pm.c (revision 8a4a551c2a4157fdd7ff92a1a532fb277628051b)
10654ab7fSJay Buddhabhatti /*
20654ab7fSJay Buddhabhatti  * Copyright (c) 2022, Xilinx, Inc. All rights reserved.
35f22f573SSenthil Nathan Thangaraj  * Copyright (c) 2022-2025, Advanced Micro Devices, Inc. All rights reserved.
40654ab7fSJay Buddhabhatti  *
50654ab7fSJay Buddhabhatti  * SPDX-License-Identifier: BSD-3-Clause
60654ab7fSJay Buddhabhatti  */
70654ab7fSJay Buddhabhatti 
80654ab7fSJay Buddhabhatti #include <assert.h>
90654ab7fSJay Buddhabhatti 
100654ab7fSJay Buddhabhatti #include <common/debug.h>
110654ab7fSJay Buddhabhatti #include <lib/mmio.h>
120654ab7fSJay Buddhabhatti #include <lib/psci/psci.h>
130654ab7fSJay Buddhabhatti #include <plat/arm/common/plat_arm.h>
140654ab7fSJay Buddhabhatti #include <plat/common/platform.h>
150654ab7fSJay Buddhabhatti #include <plat_arm.h>
160654ab7fSJay Buddhabhatti 
1788ee0816SJay Buddhabhatti #include <drivers/delay_timer.h>
180654ab7fSJay Buddhabhatti #include <plat_private.h>
190654ab7fSJay Buddhabhatti #include "pm_api_sys.h"
200654ab7fSJay Buddhabhatti #include "pm_client.h"
210654ab7fSJay Buddhabhatti #include <pm_common.h>
2288ee0816SJay Buddhabhatti #include "pm_ipi.h"
230654ab7fSJay Buddhabhatti #include "pm_svc_main.h"
240654ab7fSJay Buddhabhatti #include "versal_net_def.h"
250654ab7fSJay Buddhabhatti 
260654ab7fSJay Buddhabhatti static uintptr_t versal_net_sec_entry;
270654ab7fSJay Buddhabhatti 
280654ab7fSJay Buddhabhatti static int32_t versal_net_pwr_domain_on(u_register_t mpidr)
290654ab7fSJay Buddhabhatti {
303cbe0ae5SMaheedhar Bollapalli 	int32_t cpu_id = plat_core_pos_by_mpidr(mpidr);
310654ab7fSJay Buddhabhatti 	const struct pm_proc *proc;
325003a332SMaheedhar Bollapalli 	int32_t ret = PSCI_E_INTERN_FAIL;
330654ab7fSJay Buddhabhatti 
340654ab7fSJay Buddhabhatti 	VERBOSE("%s: mpidr: 0x%lx, cpuid: %x\n",
350654ab7fSJay Buddhabhatti 		__func__, mpidr, cpu_id);
360654ab7fSJay Buddhabhatti 
370654ab7fSJay Buddhabhatti 	if (cpu_id == -1) {
385003a332SMaheedhar Bollapalli 		goto exit_label;
390654ab7fSJay Buddhabhatti 	}
400654ab7fSJay Buddhabhatti 
410654ab7fSJay Buddhabhatti 	proc = pm_get_proc(cpu_id);
42655e62aaSRonak Jain 	if (proc == NULL) {
435003a332SMaheedhar Bollapalli 		goto exit_label;
440654ab7fSJay Buddhabhatti 	}
450654ab7fSJay Buddhabhatti 
46aa6df8ecSMaheedhar Bollapalli 	(void)pm_req_wakeup(proc->node_id, (versal_net_sec_entry & 0xFFFFFFFFU) | 0x1U,
470654ab7fSJay Buddhabhatti 		      versal_net_sec_entry >> 32, 0, 0);
480654ab7fSJay Buddhabhatti 
490654ab7fSJay Buddhabhatti 	/* Clear power down request */
500654ab7fSJay Buddhabhatti 	pm_client_wakeup(proc);
510654ab7fSJay Buddhabhatti 
525003a332SMaheedhar Bollapalli 	ret = PSCI_E_SUCCESS;
535003a332SMaheedhar Bollapalli 
545003a332SMaheedhar Bollapalli exit_label:
555003a332SMaheedhar Bollapalli 	return ret;
560654ab7fSJay Buddhabhatti }
570654ab7fSJay Buddhabhatti 
580654ab7fSJay Buddhabhatti /**
59de7ed953SPrasad Kummari  * versal_net_pwr_domain_off() - This function performs actions to turn off
60de7ed953SPrasad Kummari  *                               core.
61de7ed953SPrasad Kummari  * @target_state: Targeted state.
620654ab7fSJay Buddhabhatti  *
630654ab7fSJay Buddhabhatti  */
640654ab7fSJay Buddhabhatti static void versal_net_pwr_domain_off(const psci_power_state_t *target_state)
650654ab7fSJay Buddhabhatti {
664d2b4e4dSMaheedhar Bollapalli 	uint32_t ret, fw_api_version, version_type[RET_PAYLOAD_ARG_CNT] = {0U};
670654ab7fSJay Buddhabhatti 	uint32_t cpu_id = plat_my_core_pos();
680654ab7fSJay Buddhabhatti 	const struct pm_proc *proc = pm_get_proc(cpu_id);
690654ab7fSJay Buddhabhatti 
70655e62aaSRonak Jain 	if (proc == NULL) {
715003a332SMaheedhar Bollapalli 		goto exit_label;
72652c1ab1SMichal Simek 	}
73652c1ab1SMichal Simek 
740654ab7fSJay Buddhabhatti 	for (size_t i = 0; i <= PLAT_MAX_PWR_LVL; i++) {
750654ab7fSJay Buddhabhatti 		VERBOSE("%s: target_state->pwr_domain_state[%lu]=%x\n",
760654ab7fSJay Buddhabhatti 			__func__, i, target_state->pwr_domain_state[i]);
770654ab7fSJay Buddhabhatti 	}
780654ab7fSJay Buddhabhatti 
790654ab7fSJay Buddhabhatti 	/*
800654ab7fSJay Buddhabhatti 	 * Send request to PMC to power down the appropriate APU CPU
810654ab7fSJay Buddhabhatti 	 * core.
820654ab7fSJay Buddhabhatti 	 * According to PSCI specification, CPU_off function does not
830654ab7fSJay Buddhabhatti 	 * have resume address and CPU core can only be woken up
840654ab7fSJay Buddhabhatti 	 * invoking CPU_on function, during which resume address will
850654ab7fSJay Buddhabhatti 	 * be set.
860654ab7fSJay Buddhabhatti 	 */
874d2b4e4dSMaheedhar Bollapalli 	ret = pm_feature_check((uint32_t)PM_SELF_SUSPEND, &version_type[0], SECURE_FLAG);
883cbe0ae5SMaheedhar Bollapalli 	if (ret == (uint32_t)PM_RET_SUCCESS) {
894d2b4e4dSMaheedhar Bollapalli 		fw_api_version = version_type[0] & 0xFFFFU;
9059497016SJay Buddhabhatti 		if (fw_api_version >= 3U) {
9159497016SJay Buddhabhatti 			(void)pm_self_suspend(proc->node_id, MAX_LATENCY, PM_STATE_CPU_OFF, 0,
920654ab7fSJay Buddhabhatti 					      SECURE_FLAG);
9359497016SJay Buddhabhatti 		} else {
9459497016SJay Buddhabhatti 			(void)pm_self_suspend(proc->node_id, MAX_LATENCY, PM_STATE_CPU_IDLE, 0,
9559497016SJay Buddhabhatti 					      SECURE_FLAG);
9659497016SJay Buddhabhatti 		}
9759497016SJay Buddhabhatti 	}
985003a332SMaheedhar Bollapalli 
995003a332SMaheedhar Bollapalli exit_label:
1005003a332SMaheedhar Bollapalli 	return;
1010654ab7fSJay Buddhabhatti }
1020654ab7fSJay Buddhabhatti 
103e5e417ddSMaheedhar Bollapalli static int32_t versal_net_validate_ns_entrypoint(uint64_t ns_entrypoint)
104e5e417ddSMaheedhar Bollapalli {
105e5e417ddSMaheedhar Bollapalli 	int32_t ret = PSCI_E_SUCCESS;
106e5e417ddSMaheedhar Bollapalli 
107e5e417ddSMaheedhar Bollapalli 	if (((ns_entrypoint >= PLAT_DDR_LOWMEM_MAX) && (ns_entrypoint <= PLAT_DDR_HIGHMEM_MAX)) ||
108e5e417ddSMaheedhar Bollapalli 		((ns_entrypoint >= BL31_BASE) && (ns_entrypoint <= BL31_LIMIT))) {
109e5e417ddSMaheedhar Bollapalli 		ret = PSCI_E_INVALID_ADDRESS;
110e5e417ddSMaheedhar Bollapalli 	}
111e5e417ddSMaheedhar Bollapalli 
112e5e417ddSMaheedhar Bollapalli 	return ret;
113e5e417ddSMaheedhar Bollapalli }
114e5e417ddSMaheedhar Bollapalli 
1150654ab7fSJay Buddhabhatti /**
1165f22f573SSenthil Nathan Thangaraj  * versal_net_system_reset_scope() - Sends the reset request to firmware for
1175f22f573SSenthil Nathan Thangaraj  * the system to reset.
1185f22f573SSenthil Nathan Thangaraj  * @scope : scope of reset which could be SYSTEM/SUBSYSTEM/PS-ONLY
119de7ed953SPrasad Kummari  *
1205f22f573SSenthil Nathan Thangaraj  * Return:
1215f22f573SSenthil Nathan Thangaraj  *     Does not return if system resets, none if there is a failure.
1220654ab7fSJay Buddhabhatti  */
1235f22f573SSenthil Nathan Thangaraj static void __dead2 versal_net_system_reset_scope(uint32_t scope)
1240654ab7fSJay Buddhabhatti {
12588ee0816SJay Buddhabhatti 	uint32_t ret, timeout = 10000U;
12688ee0816SJay Buddhabhatti 
12788ee0816SJay Buddhabhatti 	request_cpu_pwrdwn();
12888ee0816SJay Buddhabhatti 
12988ee0816SJay Buddhabhatti 	/*
13088ee0816SJay Buddhabhatti 	 * Send the system reset request to the firmware if power down request
13188ee0816SJay Buddhabhatti 	 * is not received from firmware.
13288ee0816SJay Buddhabhatti 	 */
133c0719d21SDevanshi Chauhan 	if (!pm_pwrdwn_req_status()) {
13488ee0816SJay Buddhabhatti 		(void)pm_system_shutdown(XPM_SHUTDOWN_TYPE_RESET,
1355f22f573SSenthil Nathan Thangaraj 					 scope, SECURE_FLAG);
1360654ab7fSJay Buddhabhatti 
13788ee0816SJay Buddhabhatti 		/*
13888ee0816SJay Buddhabhatti 		 * Wait for system shutdown request completed and idle callback
13988ee0816SJay Buddhabhatti 		 * not received.
14088ee0816SJay Buddhabhatti 		 */
14188ee0816SJay Buddhabhatti 		do {
14288ee0816SJay Buddhabhatti 			ret = ipi_mb_enquire_status(primary_proc->ipi->local_ipi_id,
14388ee0816SJay Buddhabhatti 						    primary_proc->ipi->remote_ipi_id);
14488ee0816SJay Buddhabhatti 			udelay(100);
14588ee0816SJay Buddhabhatti 			timeout--;
14688ee0816SJay Buddhabhatti 		} while ((ret != IPI_MB_STATUS_RECV_PENDING) && (timeout > 0U));
14788ee0816SJay Buddhabhatti 	}
14888ee0816SJay Buddhabhatti 
14988ee0816SJay Buddhabhatti 	(void)psci_cpu_off();
15088ee0816SJay Buddhabhatti 
15183c3c36bSMaheedhar Bollapalli 	while (true) {
1520654ab7fSJay Buddhabhatti 		wfi();
1530654ab7fSJay Buddhabhatti 	}
1540654ab7fSJay Buddhabhatti }
1550654ab7fSJay Buddhabhatti 
1560654ab7fSJay Buddhabhatti /**
1575f22f573SSenthil Nathan Thangaraj  * versal_net_system_reset() - This function sends the reset request to firmware
1585f22f573SSenthil Nathan Thangaraj  * for the system to reset in response to SYSTEM_RESET call
1595f22f573SSenthil Nathan Thangaraj  *
1605f22f573SSenthil Nathan Thangaraj  * Return:
1615f22f573SSenthil Nathan Thangaraj  *     Does not return if system resets, none if there is a failure.
1625f22f573SSenthil Nathan Thangaraj  */
1635f22f573SSenthil Nathan Thangaraj static void __dead2 versal_net_system_reset(void)
1645f22f573SSenthil Nathan Thangaraj {
1655f22f573SSenthil Nathan Thangaraj 	/*
1665f22f573SSenthil Nathan Thangaraj 	 * Any platform-specific actions for handling a cold reset
1675f22f573SSenthil Nathan Thangaraj 	 * should be performed here before invoking
1685f22f573SSenthil Nathan Thangaraj 	 * versal_net_system_reset_scope.
1695f22f573SSenthil Nathan Thangaraj 	 */
1705f22f573SSenthil Nathan Thangaraj 	versal_net_system_reset_scope(XPM_SHUTDOWN_SUBTYPE_RST_SUBSYSTEM);
1715f22f573SSenthil Nathan Thangaraj }
1725f22f573SSenthil Nathan Thangaraj 
1735f22f573SSenthil Nathan Thangaraj /**
1745f22f573SSenthil Nathan Thangaraj  * versal_net_system_reset2() - Handles warm / vendor-specific system reset
1755f22f573SSenthil Nathan Thangaraj  * in response to SYSTEM_RESET2 call.
1765f22f573SSenthil Nathan Thangaraj  * @is_vendor: Flag indicating if this is a vendor-specific reset
1775f22f573SSenthil Nathan Thangaraj  * @reset_type: Type of reset requested
1785f22f573SSenthil Nathan Thangaraj  * @cookie: Additional reset data
1795f22f573SSenthil Nathan Thangaraj  *
1805f22f573SSenthil Nathan Thangaraj  * This function initiates a controlled system reset by requesting it
1815f22f573SSenthil Nathan Thangaraj  * through the PM firmware.
1825f22f573SSenthil Nathan Thangaraj  *
1835f22f573SSenthil Nathan Thangaraj  * Return:
1845f22f573SSenthil Nathan Thangaraj  *	Does not return if system resets, PSCI_E_INTERN_FAIL
1855f22f573SSenthil Nathan Thangaraj  *	if there is a failure.
1865f22f573SSenthil Nathan Thangaraj  */
1875f22f573SSenthil Nathan Thangaraj static int versal_net_system_reset2(int is_vendor, int reset_type, u_register_t cookie)
1885f22f573SSenthil Nathan Thangaraj {
1895f22f573SSenthil Nathan Thangaraj 	if (is_vendor == 0 && reset_type == PSCI_RESET2_SYSTEM_WARM_RESET) {
1905f22f573SSenthil Nathan Thangaraj 		/*
1915f22f573SSenthil Nathan Thangaraj 		 * Any platform-specific actions for handling a warm reset
1925f22f573SSenthil Nathan Thangaraj 		 * should be performed here before invoking
1935f22f573SSenthil Nathan Thangaraj 		 * versal_net_system_reset_scope.
1945f22f573SSenthil Nathan Thangaraj 		 */
1955f22f573SSenthil Nathan Thangaraj 		versal_net_system_reset_scope(XPM_SHUTDOWN_SUBTYPE_RST_SUBSYSTEM);
1965f22f573SSenthil Nathan Thangaraj 	} else {
1975f22f573SSenthil Nathan Thangaraj 		/* Vendor specific reset */
1985f22f573SSenthil Nathan Thangaraj 		versal_net_system_reset_scope(pm_get_shutdown_scope());
1995f22f573SSenthil Nathan Thangaraj 	}
2005f22f573SSenthil Nathan Thangaraj 
2015f22f573SSenthil Nathan Thangaraj 	return PSCI_E_INTERN_FAIL;
2025f22f573SSenthil Nathan Thangaraj }
2035f22f573SSenthil Nathan Thangaraj 
2045f22f573SSenthil Nathan Thangaraj /**
2050654ab7fSJay Buddhabhatti  * versal_net_pwr_domain_suspend() - This function sends request to PMC to suspend
2060654ab7fSJay Buddhabhatti  *                                   core.
207de7ed953SPrasad Kummari  * @target_state: Targeted state.
2080654ab7fSJay Buddhabhatti  *
2090654ab7fSJay Buddhabhatti  */
2100654ab7fSJay Buddhabhatti static void versal_net_pwr_domain_suspend(const psci_power_state_t *target_state)
2110654ab7fSJay Buddhabhatti {
2120654ab7fSJay Buddhabhatti 	uint32_t state;
2130654ab7fSJay Buddhabhatti 	uint32_t cpu_id = plat_my_core_pos();
2140654ab7fSJay Buddhabhatti 	const struct pm_proc *proc = pm_get_proc(cpu_id);
2150654ab7fSJay Buddhabhatti 
216655e62aaSRonak Jain 	if (proc == NULL) {
2175003a332SMaheedhar Bollapalli 		goto exit_label;
218652c1ab1SMichal Simek 	}
219652c1ab1SMichal Simek 
2200654ab7fSJay Buddhabhatti 	for (size_t i = 0; i <= PLAT_MAX_PWR_LVL; i++) {
2210654ab7fSJay Buddhabhatti 		VERBOSE("%s: target_state->pwr_domain_state[%lu]=%x\n",
2220654ab7fSJay Buddhabhatti 			__func__, i, target_state->pwr_domain_state[i]);
2230654ab7fSJay Buddhabhatti 	}
2240654ab7fSJay Buddhabhatti 
2250654ab7fSJay Buddhabhatti 	if (target_state->pwr_domain_state[1] > PLAT_MAX_RET_STATE) {
226*8a4a551cSBoyan Karatotev 		gic_save();
2270654ab7fSJay Buddhabhatti 	}
2280654ab7fSJay Buddhabhatti 
229a4ddd24fSMaheedhar Bollapalli 	state = (target_state->pwr_domain_state[1] > PLAT_MAX_RET_STATE) ?
2300654ab7fSJay Buddhabhatti 		PM_STATE_SUSPEND_TO_RAM : PM_STATE_CPU_IDLE;
2310654ab7fSJay Buddhabhatti 
2320654ab7fSJay Buddhabhatti 	/* Send request to PMC to suspend this core */
233aa6df8ecSMaheedhar Bollapalli 	(void)pm_self_suspend(proc->node_id, MAX_LATENCY, state, versal_net_sec_entry,
2340654ab7fSJay Buddhabhatti 			SECURE_FLAG);
2350654ab7fSJay Buddhabhatti 
2360654ab7fSJay Buddhabhatti 	/* TODO: disable coherency */
2375003a332SMaheedhar Bollapalli 
2385003a332SMaheedhar Bollapalli exit_label:
2395003a332SMaheedhar Bollapalli 	return;
2400654ab7fSJay Buddhabhatti }
2410654ab7fSJay Buddhabhatti 
2420654ab7fSJay Buddhabhatti static void versal_net_pwr_domain_on_finish(const psci_power_state_t *target_state)
2430654ab7fSJay Buddhabhatti {
2440654ab7fSJay Buddhabhatti 	(void)target_state;
2450654ab7fSJay Buddhabhatti }
2460654ab7fSJay Buddhabhatti 
2470654ab7fSJay Buddhabhatti /**
2480654ab7fSJay Buddhabhatti  * versal_net_pwr_domain_suspend_finish() - This function performs actions to finish
2490654ab7fSJay Buddhabhatti  *                                          suspend procedure.
250de7ed953SPrasad Kummari  * @target_state: Targeted state.
2510654ab7fSJay Buddhabhatti  *
2520654ab7fSJay Buddhabhatti  */
2530654ab7fSJay Buddhabhatti static void versal_net_pwr_domain_suspend_finish(const psci_power_state_t *target_state)
2540654ab7fSJay Buddhabhatti {
2550654ab7fSJay Buddhabhatti 	uint32_t cpu_id = plat_my_core_pos();
2560654ab7fSJay Buddhabhatti 	const struct pm_proc *proc = pm_get_proc(cpu_id);
2570654ab7fSJay Buddhabhatti 
258655e62aaSRonak Jain 	if (proc == NULL) {
2595003a332SMaheedhar Bollapalli 		goto exit_label;
260652c1ab1SMichal Simek 	}
261652c1ab1SMichal Simek 
2629334fdf9SMaheedhar Bollapalli 	for (size_t i = 0; i <= PLAT_MAX_PWR_LVL; i++) {
2630654ab7fSJay Buddhabhatti 		VERBOSE("%s: target_state->pwr_domain_state[%lu]=%x\n",
2640654ab7fSJay Buddhabhatti 			__func__, i, target_state->pwr_domain_state[i]);
2659334fdf9SMaheedhar Bollapalli 	}
2660654ab7fSJay Buddhabhatti 
2670654ab7fSJay Buddhabhatti 	/* Clear the APU power control register for this cpu */
2680654ab7fSJay Buddhabhatti 	pm_client_wakeup(proc);
2690654ab7fSJay Buddhabhatti 
2700654ab7fSJay Buddhabhatti 	/* TODO: enable coherency */
2710654ab7fSJay Buddhabhatti 
2720654ab7fSJay Buddhabhatti 	/* APU was turned off, so restore GIC context */
2730654ab7fSJay Buddhabhatti 	if (target_state->pwr_domain_state[1] > PLAT_MAX_RET_STATE) {
274*8a4a551cSBoyan Karatotev 		gic_resume();
2750654ab7fSJay Buddhabhatti 	}
2760654ab7fSJay Buddhabhatti 
2775003a332SMaheedhar Bollapalli exit_label:
2785003a332SMaheedhar Bollapalli 	return;
2790654ab7fSJay Buddhabhatti }
2800654ab7fSJay Buddhabhatti 
2810654ab7fSJay Buddhabhatti /**
2820654ab7fSJay Buddhabhatti  * versal_net_system_off() - This function sends the system off request
2830654ab7fSJay Buddhabhatti  *                           to firmware. This function does not return.
284de7ed953SPrasad Kummari  *
2850654ab7fSJay Buddhabhatti  */
2860654ab7fSJay Buddhabhatti static void __dead2 versal_net_system_off(void)
2870654ab7fSJay Buddhabhatti {
2880654ab7fSJay Buddhabhatti 	/* Send the power down request to the PMC */
289aa6df8ecSMaheedhar Bollapalli 	(void)pm_system_shutdown(XPM_SHUTDOWN_TYPE_SHUTDOWN,
2900654ab7fSJay Buddhabhatti 			  pm_get_shutdown_scope(), SECURE_FLAG);
2910654ab7fSJay Buddhabhatti 
29283c3c36bSMaheedhar Bollapalli 	while (true) {
2930654ab7fSJay Buddhabhatti 		wfi();
2940654ab7fSJay Buddhabhatti 	}
2950654ab7fSJay Buddhabhatti }
2960654ab7fSJay Buddhabhatti 
2970654ab7fSJay Buddhabhatti /**
2980654ab7fSJay Buddhabhatti  * versal_net_validate_power_state() - This function ensures that the power state
2990654ab7fSJay Buddhabhatti  *                                     parameter in request is valid.
300de7ed953SPrasad Kummari  * @power_state: Power state of core.
301de7ed953SPrasad Kummari  * @req_state: Requested state.
3020654ab7fSJay Buddhabhatti  *
303de7ed953SPrasad Kummari  * Return: Returns status, either PSCI_E_SUCCESS or reason.
3040654ab7fSJay Buddhabhatti  *
3050654ab7fSJay Buddhabhatti  */
3060654ab7fSJay Buddhabhatti static int32_t versal_net_validate_power_state(unsigned int power_state,
3070654ab7fSJay Buddhabhatti 					       psci_power_state_t *req_state)
3080654ab7fSJay Buddhabhatti {
3095003a332SMaheedhar Bollapalli 	int32_t ret = PSCI_E_INVALID_PARAMS;
3105003a332SMaheedhar Bollapalli 
3110654ab7fSJay Buddhabhatti 	VERBOSE("%s: power_state: 0x%x\n", __func__, power_state);
3120654ab7fSJay Buddhabhatti 
313d51c8e4cSMaheedhar Bollapalli 	uint32_t pstate = psci_get_pstate_type(power_state);
3140654ab7fSJay Buddhabhatti 
31537c46d85SMaheedhar Bollapalli 	assert(req_state != NULL);
3160654ab7fSJay Buddhabhatti 
3170654ab7fSJay Buddhabhatti 	/* Sanity check the requested state */
3180654ab7fSJay Buddhabhatti 	if (pstate == PSTATE_TYPE_STANDBY) {
3190654ab7fSJay Buddhabhatti 		req_state->pwr_domain_state[MPIDR_AFFLVL0] = PLAT_MAX_RET_STATE;
3200654ab7fSJay Buddhabhatti 	} else {
3216ada9dc3SJay Buddhabhatti 		req_state->pwr_domain_state[MPIDR_AFFLVL0] = PLAT_MAX_OFF_STATE;
3220654ab7fSJay Buddhabhatti 	}
3230654ab7fSJay Buddhabhatti 
3240654ab7fSJay Buddhabhatti 	/* We expect the 'state id' to be zero */
3255003a332SMaheedhar Bollapalli 	if (psci_get_pstate_id(power_state) == 0U) {
3265003a332SMaheedhar Bollapalli 		ret = PSCI_E_SUCCESS;
3270654ab7fSJay Buddhabhatti 	}
3280654ab7fSJay Buddhabhatti 
3295003a332SMaheedhar Bollapalli 	return ret;
3300654ab7fSJay Buddhabhatti }
3310654ab7fSJay Buddhabhatti 
3320654ab7fSJay Buddhabhatti /**
333de7ed953SPrasad Kummari  * versal_net_get_sys_suspend_power_state() - Get power state for system
334de7ed953SPrasad Kummari  *                                            suspend.
335de7ed953SPrasad Kummari  * @req_state: Requested state.
3360654ab7fSJay Buddhabhatti  *
3370654ab7fSJay Buddhabhatti  */
3380654ab7fSJay Buddhabhatti static void versal_net_get_sys_suspend_power_state(psci_power_state_t *req_state)
3390654ab7fSJay Buddhabhatti {
3401f79bdfdSJay Buddhabhatti 	uint64_t i;
3411f79bdfdSJay Buddhabhatti 
3429334fdf9SMaheedhar Bollapalli 	for (i = MPIDR_AFFLVL0; i <= PLAT_MAX_PWR_LVL; i++) {
3431f79bdfdSJay Buddhabhatti 		req_state->pwr_domain_state[i] = PLAT_MAX_OFF_STATE;
3440654ab7fSJay Buddhabhatti 	}
3459334fdf9SMaheedhar Bollapalli }
3460654ab7fSJay Buddhabhatti 
3470654ab7fSJay Buddhabhatti static const struct plat_psci_ops versal_net_nopmc_psci_ops = {
3480654ab7fSJay Buddhabhatti 	.pwr_domain_on                  = versal_net_pwr_domain_on,
3490654ab7fSJay Buddhabhatti 	.pwr_domain_off                 = versal_net_pwr_domain_off,
3500654ab7fSJay Buddhabhatti 	.pwr_domain_on_finish           = versal_net_pwr_domain_on_finish,
3510654ab7fSJay Buddhabhatti 	.pwr_domain_suspend             = versal_net_pwr_domain_suspend,
3520654ab7fSJay Buddhabhatti 	.pwr_domain_suspend_finish      = versal_net_pwr_domain_suspend_finish,
3530654ab7fSJay Buddhabhatti 	.system_off                     = versal_net_system_off,
3540654ab7fSJay Buddhabhatti 	.system_reset                   = versal_net_system_reset,
3555f22f573SSenthil Nathan Thangaraj 	.system_reset2                  = versal_net_system_reset2,
356e5e417ddSMaheedhar Bollapalli 	.validate_ns_entrypoint		= versal_net_validate_ns_entrypoint,
3570654ab7fSJay Buddhabhatti 	.validate_power_state           = versal_net_validate_power_state,
3580654ab7fSJay Buddhabhatti 	.get_sys_suspend_power_state    = versal_net_get_sys_suspend_power_state,
3590654ab7fSJay Buddhabhatti };
3600654ab7fSJay Buddhabhatti 
3610654ab7fSJay Buddhabhatti /*******************************************************************************
3620654ab7fSJay Buddhabhatti  * Export the platform specific power ops.
3630654ab7fSJay Buddhabhatti  ******************************************************************************/
3640654ab7fSJay Buddhabhatti int32_t plat_setup_psci_ops(uintptr_t sec_entrypoint,
3650654ab7fSJay Buddhabhatti 			    const struct plat_psci_ops **psci_ops)
3660654ab7fSJay Buddhabhatti {
3670654ab7fSJay Buddhabhatti 	versal_net_sec_entry = sec_entrypoint;
3680654ab7fSJay Buddhabhatti 
3690654ab7fSJay Buddhabhatti 	VERBOSE("Setting up entry point %lx\n", versal_net_sec_entry);
3700654ab7fSJay Buddhabhatti 
3710654ab7fSJay Buddhabhatti 	*psci_ops = &versal_net_nopmc_psci_ops;
3720654ab7fSJay Buddhabhatti 
3730654ab7fSJay Buddhabhatti 	return 0;
3740654ab7fSJay Buddhabhatti }
3750654ab7fSJay Buddhabhatti 
3760654ab7fSJay Buddhabhatti int32_t sip_svc_setup_init(void)
3770654ab7fSJay Buddhabhatti {
3780654ab7fSJay Buddhabhatti 	return pm_setup();
3790654ab7fSJay Buddhabhatti }
3800654ab7fSJay Buddhabhatti 
3810654ab7fSJay Buddhabhatti uint64_t smc_handler(uint32_t smc_fid, uint64_t x1, uint64_t x2, uint64_t x3, uint64_t x4,
3820654ab7fSJay Buddhabhatti 		     void *cookie, void *handle, uint64_t flags)
3830654ab7fSJay Buddhabhatti {
3840654ab7fSJay Buddhabhatti 	return pm_smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle, flags);
3850654ab7fSJay Buddhabhatti }
386