xref: /rk3399_ARM-atf/plat/xilinx/versal_net/plat_psci_pm.c (revision 0c0b19f42de25bb75760d6cca02c325c08a33882)
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>
11*3e3cdf26SRonak Jain #include <common/ep_info.h>
120654ab7fSJay Buddhabhatti #include <lib/mmio.h>
130654ab7fSJay Buddhabhatti #include <lib/psci/psci.h>
140654ab7fSJay Buddhabhatti #include <plat/arm/common/plat_arm.h>
150654ab7fSJay Buddhabhatti #include <plat/common/platform.h>
160654ab7fSJay Buddhabhatti #include <plat_arm.h>
170654ab7fSJay Buddhabhatti 
1888ee0816SJay Buddhabhatti #include <drivers/delay_timer.h>
190654ab7fSJay Buddhabhatti #include <plat_private.h>
200654ab7fSJay Buddhabhatti #include "pm_api_sys.h"
210654ab7fSJay Buddhabhatti #include "pm_client.h"
220654ab7fSJay Buddhabhatti #include <pm_common.h>
2388ee0816SJay Buddhabhatti #include "pm_ipi.h"
240654ab7fSJay Buddhabhatti #include "pm_svc_main.h"
250654ab7fSJay Buddhabhatti #include "versal_net_def.h"
260654ab7fSJay Buddhabhatti 
270654ab7fSJay Buddhabhatti static uintptr_t versal_net_sec_entry;
280654ab7fSJay Buddhabhatti 
versal_net_pwr_domain_on(u_register_t mpidr)290654ab7fSJay Buddhabhatti static int32_t versal_net_pwr_domain_on(u_register_t mpidr)
300654ab7fSJay Buddhabhatti {
313cbe0ae5SMaheedhar Bollapalli 	int32_t cpu_id = plat_core_pos_by_mpidr(mpidr);
320654ab7fSJay Buddhabhatti 	const struct pm_proc *proc;
335003a332SMaheedhar Bollapalli 	int32_t ret = PSCI_E_INTERN_FAIL;
340654ab7fSJay Buddhabhatti 
350654ab7fSJay Buddhabhatti 	VERBOSE("%s: mpidr: 0x%lx, cpuid: %x\n",
360654ab7fSJay Buddhabhatti 		__func__, mpidr, cpu_id);
370654ab7fSJay Buddhabhatti 
380654ab7fSJay Buddhabhatti 	if (cpu_id == -1) {
395003a332SMaheedhar Bollapalli 		goto exit_label;
400654ab7fSJay Buddhabhatti 	}
410654ab7fSJay Buddhabhatti 
420654ab7fSJay Buddhabhatti 	proc = pm_get_proc(cpu_id);
43655e62aaSRonak Jain 	if (proc == NULL) {
445003a332SMaheedhar Bollapalli 		goto exit_label;
450654ab7fSJay Buddhabhatti 	}
460654ab7fSJay Buddhabhatti 
47aa6df8ecSMaheedhar Bollapalli 	(void)pm_req_wakeup(proc->node_id, (versal_net_sec_entry & 0xFFFFFFFFU) | 0x1U,
480654ab7fSJay Buddhabhatti 		      versal_net_sec_entry >> 32, 0, 0);
490654ab7fSJay Buddhabhatti 
500654ab7fSJay Buddhabhatti 	/* Clear power down request */
510654ab7fSJay Buddhabhatti 	pm_client_wakeup(proc);
520654ab7fSJay Buddhabhatti 
535003a332SMaheedhar Bollapalli 	ret = PSCI_E_SUCCESS;
545003a332SMaheedhar Bollapalli 
555003a332SMaheedhar Bollapalli exit_label:
565003a332SMaheedhar Bollapalli 	return ret;
570654ab7fSJay Buddhabhatti }
580654ab7fSJay Buddhabhatti 
590654ab7fSJay Buddhabhatti /**
60de7ed953SPrasad Kummari  * versal_net_pwr_domain_off() - This function performs actions to turn off
61de7ed953SPrasad Kummari  *                               core.
62de7ed953SPrasad Kummari  * @target_state: Targeted state.
630654ab7fSJay Buddhabhatti  *
640654ab7fSJay Buddhabhatti  */
versal_net_pwr_domain_off(const psci_power_state_t * target_state)650654ab7fSJay Buddhabhatti static void versal_net_pwr_domain_off(const psci_power_state_t *target_state)
660654ab7fSJay Buddhabhatti {
674d2b4e4dSMaheedhar Bollapalli 	uint32_t ret, fw_api_version, version_type[RET_PAYLOAD_ARG_CNT] = {0U};
680654ab7fSJay Buddhabhatti 	uint32_t cpu_id = plat_my_core_pos();
690654ab7fSJay Buddhabhatti 	const struct pm_proc *proc = pm_get_proc(cpu_id);
700654ab7fSJay Buddhabhatti 
71655e62aaSRonak Jain 	if (proc == NULL) {
725003a332SMaheedhar Bollapalli 		goto exit_label;
73652c1ab1SMichal Simek 	}
74652c1ab1SMichal Simek 
750654ab7fSJay Buddhabhatti 	for (size_t i = 0; i <= PLAT_MAX_PWR_LVL; i++) {
760654ab7fSJay Buddhabhatti 		VERBOSE("%s: target_state->pwr_domain_state[%lu]=%x\n",
770654ab7fSJay Buddhabhatti 			__func__, i, target_state->pwr_domain_state[i]);
780654ab7fSJay Buddhabhatti 	}
790654ab7fSJay Buddhabhatti 
800654ab7fSJay Buddhabhatti 	/*
810654ab7fSJay Buddhabhatti 	 * Send request to PMC to power down the appropriate APU CPU
820654ab7fSJay Buddhabhatti 	 * core.
830654ab7fSJay Buddhabhatti 	 * According to PSCI specification, CPU_off function does not
840654ab7fSJay Buddhabhatti 	 * have resume address and CPU core can only be woken up
850654ab7fSJay Buddhabhatti 	 * invoking CPU_on function, during which resume address will
860654ab7fSJay Buddhabhatti 	 * be set.
870654ab7fSJay Buddhabhatti 	 */
88*3e3cdf26SRonak Jain 	ret = pm_feature_check((uint32_t)PM_SELF_SUSPEND, &version_type[0], NON_SECURE);
893cbe0ae5SMaheedhar Bollapalli 	if (ret == (uint32_t)PM_RET_SUCCESS) {
904d2b4e4dSMaheedhar Bollapalli 		fw_api_version = version_type[0] & 0xFFFFU;
9159497016SJay Buddhabhatti 		if (fw_api_version >= 3U) {
9259497016SJay Buddhabhatti 			(void)pm_self_suspend(proc->node_id, MAX_LATENCY, PM_STATE_CPU_OFF, 0,
93*3e3cdf26SRonak Jain 					      NON_SECURE);
9459497016SJay Buddhabhatti 		} else {
9559497016SJay Buddhabhatti 			(void)pm_self_suspend(proc->node_id, MAX_LATENCY, PM_STATE_CPU_IDLE, 0,
96*3e3cdf26SRonak Jain 					      NON_SECURE);
9759497016SJay Buddhabhatti 		}
9859497016SJay Buddhabhatti 	}
995003a332SMaheedhar Bollapalli 
1005003a332SMaheedhar Bollapalli exit_label:
1015003a332SMaheedhar Bollapalli 	return;
1020654ab7fSJay Buddhabhatti }
1030654ab7fSJay Buddhabhatti 
versal_net_validate_ns_entrypoint(uint64_t ns_entrypoint)104e5e417ddSMaheedhar Bollapalli static int32_t versal_net_validate_ns_entrypoint(uint64_t ns_entrypoint)
105e5e417ddSMaheedhar Bollapalli {
106e5e417ddSMaheedhar Bollapalli 	int32_t ret = PSCI_E_SUCCESS;
107e5e417ddSMaheedhar Bollapalli 
108e5e417ddSMaheedhar Bollapalli 	if (((ns_entrypoint >= PLAT_DDR_LOWMEM_MAX) && (ns_entrypoint <= PLAT_DDR_HIGHMEM_MAX)) ||
109e5e417ddSMaheedhar Bollapalli 		((ns_entrypoint >= BL31_BASE) && (ns_entrypoint <= BL31_LIMIT))) {
110e5e417ddSMaheedhar Bollapalli 		ret = PSCI_E_INVALID_ADDRESS;
111e5e417ddSMaheedhar Bollapalli 	}
112e5e417ddSMaheedhar Bollapalli 
113e5e417ddSMaheedhar Bollapalli 	return ret;
114e5e417ddSMaheedhar Bollapalli }
115e5e417ddSMaheedhar Bollapalli 
1160654ab7fSJay Buddhabhatti /**
1175f22f573SSenthil Nathan Thangaraj  * versal_net_system_reset_scope() - Sends the reset request to firmware for
1185f22f573SSenthil Nathan Thangaraj  * the system to reset.
1195f22f573SSenthil Nathan Thangaraj  * @scope : scope of reset which could be SYSTEM/SUBSYSTEM/PS-ONLY
120de7ed953SPrasad Kummari  *
1215f22f573SSenthil Nathan Thangaraj  * Return:
1225f22f573SSenthil Nathan Thangaraj  *     Does not return if system resets, none if there is a failure.
1230654ab7fSJay Buddhabhatti  */
versal_net_system_reset_scope(uint32_t scope)1245f22f573SSenthil Nathan Thangaraj static void __dead2 versal_net_system_reset_scope(uint32_t scope)
1250654ab7fSJay Buddhabhatti {
12688ee0816SJay Buddhabhatti 	uint32_t ret, timeout = 10000U;
12788ee0816SJay Buddhabhatti 
12888ee0816SJay Buddhabhatti 	request_cpu_pwrdwn();
12988ee0816SJay Buddhabhatti 
13088ee0816SJay Buddhabhatti 	/*
13188ee0816SJay Buddhabhatti 	 * Send the system reset request to the firmware if power down request
13288ee0816SJay Buddhabhatti 	 * is not received from firmware.
13388ee0816SJay Buddhabhatti 	 */
134c0719d21SDevanshi Chauhan 	if (!pm_pwrdwn_req_status()) {
13588ee0816SJay Buddhabhatti 		(void)pm_system_shutdown(XPM_SHUTDOWN_TYPE_RESET,
136*3e3cdf26SRonak Jain 					 scope, NON_SECURE);
1370654ab7fSJay Buddhabhatti 
13888ee0816SJay Buddhabhatti 		/*
13988ee0816SJay Buddhabhatti 		 * Wait for system shutdown request completed and idle callback
14088ee0816SJay Buddhabhatti 		 * not received.
14188ee0816SJay Buddhabhatti 		 */
14288ee0816SJay Buddhabhatti 		do {
14388ee0816SJay Buddhabhatti 			ret = ipi_mb_enquire_status(primary_proc->ipi->local_ipi_id,
14488ee0816SJay Buddhabhatti 						    primary_proc->ipi->remote_ipi_id);
14588ee0816SJay Buddhabhatti 			udelay(100);
14688ee0816SJay Buddhabhatti 			timeout--;
14788ee0816SJay Buddhabhatti 		} while ((ret != IPI_MB_STATUS_RECV_PENDING) && (timeout > 0U));
14888ee0816SJay Buddhabhatti 	}
14988ee0816SJay Buddhabhatti 
15088ee0816SJay Buddhabhatti 	(void)psci_cpu_off();
15188ee0816SJay Buddhabhatti 
15283c3c36bSMaheedhar Bollapalli 	while (true) {
1530654ab7fSJay Buddhabhatti 		wfi();
1540654ab7fSJay Buddhabhatti 	}
1550654ab7fSJay Buddhabhatti }
1560654ab7fSJay Buddhabhatti 
1570654ab7fSJay Buddhabhatti /**
1585f22f573SSenthil Nathan Thangaraj  * versal_net_system_reset() - This function sends the reset request to firmware
1595f22f573SSenthil Nathan Thangaraj  * for the system to reset in response to SYSTEM_RESET call
1605f22f573SSenthil Nathan Thangaraj  *
1615f22f573SSenthil Nathan Thangaraj  * Return:
1625f22f573SSenthil Nathan Thangaraj  *     Does not return if system resets, none if there is a failure.
1635f22f573SSenthil Nathan Thangaraj  */
versal_net_system_reset(void)1645f22f573SSenthil Nathan Thangaraj static void __dead2 versal_net_system_reset(void)
1655f22f573SSenthil Nathan Thangaraj {
1665f22f573SSenthil Nathan Thangaraj 	/*
1675f22f573SSenthil Nathan Thangaraj 	 * Any platform-specific actions for handling a cold reset
1685f22f573SSenthil Nathan Thangaraj 	 * should be performed here before invoking
1695f22f573SSenthil Nathan Thangaraj 	 * versal_net_system_reset_scope.
1705f22f573SSenthil Nathan Thangaraj 	 */
1715f22f573SSenthil Nathan Thangaraj 	versal_net_system_reset_scope(XPM_SHUTDOWN_SUBTYPE_RST_SUBSYSTEM);
1725f22f573SSenthil Nathan Thangaraj }
1735f22f573SSenthil Nathan Thangaraj 
1745f22f573SSenthil Nathan Thangaraj /**
1755f22f573SSenthil Nathan Thangaraj  * versal_net_system_reset2() - Handles warm / vendor-specific system reset
1765f22f573SSenthil Nathan Thangaraj  * in response to SYSTEM_RESET2 call.
1775f22f573SSenthil Nathan Thangaraj  * @is_vendor: Flag indicating if this is a vendor-specific reset
1785f22f573SSenthil Nathan Thangaraj  * @reset_type: Type of reset requested
1795f22f573SSenthil Nathan Thangaraj  * @cookie: Additional reset data
1805f22f573SSenthil Nathan Thangaraj  *
1815f22f573SSenthil Nathan Thangaraj  * This function initiates a controlled system reset by requesting it
1825f22f573SSenthil Nathan Thangaraj  * through the PM firmware.
1835f22f573SSenthil Nathan Thangaraj  *
1845f22f573SSenthil Nathan Thangaraj  * Return:
1855f22f573SSenthil Nathan Thangaraj  *	Does not return if system resets, PSCI_E_INTERN_FAIL
1865f22f573SSenthil Nathan Thangaraj  *	if there is a failure.
1875f22f573SSenthil Nathan Thangaraj  */
versal_net_system_reset2(int is_vendor,int reset_type,u_register_t cookie)1885f22f573SSenthil Nathan Thangaraj static int versal_net_system_reset2(int is_vendor, int reset_type, u_register_t cookie)
1895f22f573SSenthil Nathan Thangaraj {
1905f22f573SSenthil Nathan Thangaraj 	if (is_vendor == 0 && reset_type == PSCI_RESET2_SYSTEM_WARM_RESET) {
1915f22f573SSenthil Nathan Thangaraj 		/*
1925f22f573SSenthil Nathan Thangaraj 		 * Any platform-specific actions for handling a warm reset
1935f22f573SSenthil Nathan Thangaraj 		 * should be performed here before invoking
1945f22f573SSenthil Nathan Thangaraj 		 * versal_net_system_reset_scope.
1955f22f573SSenthil Nathan Thangaraj 		 */
1965f22f573SSenthil Nathan Thangaraj 		versal_net_system_reset_scope(XPM_SHUTDOWN_SUBTYPE_RST_SUBSYSTEM);
1975f22f573SSenthil Nathan Thangaraj 	} else {
1985f22f573SSenthil Nathan Thangaraj 		/* Vendor specific reset */
1995f22f573SSenthil Nathan Thangaraj 		versal_net_system_reset_scope(pm_get_shutdown_scope());
2005f22f573SSenthil Nathan Thangaraj 	}
2015f22f573SSenthil Nathan Thangaraj 
2025f22f573SSenthil Nathan Thangaraj 	return PSCI_E_INTERN_FAIL;
2035f22f573SSenthil Nathan Thangaraj }
2045f22f573SSenthil Nathan Thangaraj 
2055f22f573SSenthil Nathan Thangaraj /**
2060654ab7fSJay Buddhabhatti  * versal_net_pwr_domain_suspend() - This function sends request to PMC to suspend
2070654ab7fSJay Buddhabhatti  *                                   core.
208de7ed953SPrasad Kummari  * @target_state: Targeted state.
2090654ab7fSJay Buddhabhatti  *
2100654ab7fSJay Buddhabhatti  */
versal_net_pwr_domain_suspend(const psci_power_state_t * target_state)2110654ab7fSJay Buddhabhatti static void versal_net_pwr_domain_suspend(const psci_power_state_t *target_state)
2120654ab7fSJay Buddhabhatti {
2130654ab7fSJay Buddhabhatti 	uint32_t state;
2140654ab7fSJay Buddhabhatti 	uint32_t cpu_id = plat_my_core_pos();
2150654ab7fSJay Buddhabhatti 	const struct pm_proc *proc = pm_get_proc(cpu_id);
2160654ab7fSJay Buddhabhatti 
217655e62aaSRonak Jain 	if (proc == NULL) {
2185003a332SMaheedhar Bollapalli 		goto exit_label;
219652c1ab1SMichal Simek 	}
220652c1ab1SMichal Simek 
2210654ab7fSJay Buddhabhatti 	for (size_t i = 0; i <= PLAT_MAX_PWR_LVL; i++) {
2220654ab7fSJay Buddhabhatti 		VERBOSE("%s: target_state->pwr_domain_state[%lu]=%x\n",
2230654ab7fSJay Buddhabhatti 			__func__, i, target_state->pwr_domain_state[i]);
2240654ab7fSJay Buddhabhatti 	}
2250654ab7fSJay Buddhabhatti 
2260654ab7fSJay Buddhabhatti 	if (target_state->pwr_domain_state[1] > PLAT_MAX_RET_STATE) {
2278a4a551cSBoyan Karatotev 		gic_save();
2280654ab7fSJay Buddhabhatti 	}
2290654ab7fSJay Buddhabhatti 
230a4ddd24fSMaheedhar Bollapalli 	state = (target_state->pwr_domain_state[1] > PLAT_MAX_RET_STATE) ?
2310654ab7fSJay Buddhabhatti 		PM_STATE_SUSPEND_TO_RAM : PM_STATE_CPU_IDLE;
2320654ab7fSJay Buddhabhatti 
2330654ab7fSJay Buddhabhatti 	/* Send request to PMC to suspend this core */
234aa6df8ecSMaheedhar Bollapalli 	(void)pm_self_suspend(proc->node_id, MAX_LATENCY, state, versal_net_sec_entry,
235*3e3cdf26SRonak Jain 			      NON_SECURE);
2360654ab7fSJay Buddhabhatti 
2370654ab7fSJay Buddhabhatti 	/* TODO: disable coherency */
2385003a332SMaheedhar Bollapalli 
2395003a332SMaheedhar Bollapalli exit_label:
2405003a332SMaheedhar Bollapalli 	return;
2410654ab7fSJay Buddhabhatti }
2420654ab7fSJay Buddhabhatti 
versal_net_pwr_domain_on_finish(const psci_power_state_t * target_state)2430654ab7fSJay Buddhabhatti static void versal_net_pwr_domain_on_finish(const psci_power_state_t *target_state)
2440654ab7fSJay Buddhabhatti {
2450654ab7fSJay Buddhabhatti 	(void)target_state;
2460654ab7fSJay Buddhabhatti }
2470654ab7fSJay Buddhabhatti 
2480654ab7fSJay Buddhabhatti /**
2490654ab7fSJay Buddhabhatti  * versal_net_pwr_domain_suspend_finish() - This function performs actions to finish
2500654ab7fSJay Buddhabhatti  *                                          suspend procedure.
251de7ed953SPrasad Kummari  * @target_state: Targeted state.
2520654ab7fSJay Buddhabhatti  *
2530654ab7fSJay Buddhabhatti  */
versal_net_pwr_domain_suspend_finish(const psci_power_state_t * target_state)2540654ab7fSJay Buddhabhatti static void versal_net_pwr_domain_suspend_finish(const psci_power_state_t *target_state)
2550654ab7fSJay Buddhabhatti {
2560654ab7fSJay Buddhabhatti 	uint32_t cpu_id = plat_my_core_pos();
2570654ab7fSJay Buddhabhatti 	const struct pm_proc *proc = pm_get_proc(cpu_id);
2580654ab7fSJay Buddhabhatti 
259655e62aaSRonak Jain 	if (proc == NULL) {
2605003a332SMaheedhar Bollapalli 		goto exit_label;
261652c1ab1SMichal Simek 	}
262652c1ab1SMichal Simek 
2639334fdf9SMaheedhar Bollapalli 	for (size_t i = 0; i <= PLAT_MAX_PWR_LVL; i++) {
2640654ab7fSJay Buddhabhatti 		VERBOSE("%s: target_state->pwr_domain_state[%lu]=%x\n",
2650654ab7fSJay Buddhabhatti 			__func__, i, target_state->pwr_domain_state[i]);
2669334fdf9SMaheedhar Bollapalli 	}
2670654ab7fSJay Buddhabhatti 
2680654ab7fSJay Buddhabhatti 	/* Clear the APU power control register for this cpu */
2690654ab7fSJay Buddhabhatti 	pm_client_wakeup(proc);
2700654ab7fSJay Buddhabhatti 
2710654ab7fSJay Buddhabhatti 	/* TODO: enable coherency */
2720654ab7fSJay Buddhabhatti 
2730654ab7fSJay Buddhabhatti 	/* APU was turned off, so restore GIC context */
2740654ab7fSJay Buddhabhatti 	if (target_state->pwr_domain_state[1] > PLAT_MAX_RET_STATE) {
2758a4a551cSBoyan Karatotev 		gic_resume();
2760654ab7fSJay Buddhabhatti 	}
2770654ab7fSJay Buddhabhatti 
2785003a332SMaheedhar Bollapalli exit_label:
2795003a332SMaheedhar Bollapalli 	return;
2800654ab7fSJay Buddhabhatti }
2810654ab7fSJay Buddhabhatti 
2820654ab7fSJay Buddhabhatti /**
2830654ab7fSJay Buddhabhatti  * versal_net_system_off() - This function sends the system off request
2840654ab7fSJay Buddhabhatti  *                           to firmware. This function does not return.
285de7ed953SPrasad Kummari  *
2860654ab7fSJay Buddhabhatti  */
versal_net_system_off(void)2870654ab7fSJay Buddhabhatti static void __dead2 versal_net_system_off(void)
2880654ab7fSJay Buddhabhatti {
2890654ab7fSJay Buddhabhatti 	/* Send the power down request to the PMC */
290aa6df8ecSMaheedhar Bollapalli 	(void)pm_system_shutdown(XPM_SHUTDOWN_TYPE_SHUTDOWN,
291*3e3cdf26SRonak Jain 				 pm_get_shutdown_scope(), NON_SECURE);
2920654ab7fSJay Buddhabhatti 
29383c3c36bSMaheedhar Bollapalli 	while (true) {
2940654ab7fSJay Buddhabhatti 		wfi();
2950654ab7fSJay Buddhabhatti 	}
2960654ab7fSJay Buddhabhatti }
2970654ab7fSJay Buddhabhatti 
2980654ab7fSJay Buddhabhatti /**
2990654ab7fSJay Buddhabhatti  * versal_net_validate_power_state() - This function ensures that the power state
3000654ab7fSJay Buddhabhatti  *                                     parameter in request is valid.
301de7ed953SPrasad Kummari  * @power_state: Power state of core.
302de7ed953SPrasad Kummari  * @req_state: Requested state.
3030654ab7fSJay Buddhabhatti  *
304de7ed953SPrasad Kummari  * Return: Returns status, either PSCI_E_SUCCESS or reason.
3050654ab7fSJay Buddhabhatti  *
3060654ab7fSJay Buddhabhatti  */
versal_net_validate_power_state(unsigned int power_state,psci_power_state_t * req_state)3070654ab7fSJay Buddhabhatti static int32_t versal_net_validate_power_state(unsigned int power_state,
3080654ab7fSJay Buddhabhatti 					       psci_power_state_t *req_state)
3090654ab7fSJay Buddhabhatti {
3105003a332SMaheedhar Bollapalli 	int32_t ret = PSCI_E_INVALID_PARAMS;
3115003a332SMaheedhar Bollapalli 
3120654ab7fSJay Buddhabhatti 	VERBOSE("%s: power_state: 0x%x\n", __func__, power_state);
3130654ab7fSJay Buddhabhatti 
314d51c8e4cSMaheedhar Bollapalli 	uint32_t pstate = psci_get_pstate_type(power_state);
3150654ab7fSJay Buddhabhatti 
31637c46d85SMaheedhar Bollapalli 	assert(req_state != NULL);
3170654ab7fSJay Buddhabhatti 
3180654ab7fSJay Buddhabhatti 	/* Sanity check the requested state */
3190654ab7fSJay Buddhabhatti 	if (pstate == PSTATE_TYPE_STANDBY) {
3200654ab7fSJay Buddhabhatti 		req_state->pwr_domain_state[MPIDR_AFFLVL0] = PLAT_MAX_RET_STATE;
3210654ab7fSJay Buddhabhatti 	} else {
3226ada9dc3SJay Buddhabhatti 		req_state->pwr_domain_state[MPIDR_AFFLVL0] = PLAT_MAX_OFF_STATE;
3230654ab7fSJay Buddhabhatti 	}
3240654ab7fSJay Buddhabhatti 
3250654ab7fSJay Buddhabhatti 	/* We expect the 'state id' to be zero */
3265003a332SMaheedhar Bollapalli 	if (psci_get_pstate_id(power_state) == 0U) {
3275003a332SMaheedhar Bollapalli 		ret = PSCI_E_SUCCESS;
3280654ab7fSJay Buddhabhatti 	}
3290654ab7fSJay Buddhabhatti 
3305003a332SMaheedhar Bollapalli 	return ret;
3310654ab7fSJay Buddhabhatti }
3320654ab7fSJay Buddhabhatti 
3330654ab7fSJay Buddhabhatti /**
334de7ed953SPrasad Kummari  * versal_net_get_sys_suspend_power_state() - Get power state for system
335de7ed953SPrasad Kummari  *                                            suspend.
336de7ed953SPrasad Kummari  * @req_state: Requested state.
3370654ab7fSJay Buddhabhatti  *
3380654ab7fSJay Buddhabhatti  */
versal_net_get_sys_suspend_power_state(psci_power_state_t * req_state)3390654ab7fSJay Buddhabhatti static void versal_net_get_sys_suspend_power_state(psci_power_state_t *req_state)
3400654ab7fSJay Buddhabhatti {
3411f79bdfdSJay Buddhabhatti 	uint64_t i;
3421f79bdfdSJay Buddhabhatti 
3439334fdf9SMaheedhar Bollapalli 	for (i = MPIDR_AFFLVL0; i <= PLAT_MAX_PWR_LVL; i++) {
3441f79bdfdSJay Buddhabhatti 		req_state->pwr_domain_state[i] = PLAT_MAX_OFF_STATE;
3450654ab7fSJay Buddhabhatti 	}
3469334fdf9SMaheedhar Bollapalli }
3470654ab7fSJay Buddhabhatti 
3480654ab7fSJay Buddhabhatti static const struct plat_psci_ops versal_net_nopmc_psci_ops = {
3490654ab7fSJay Buddhabhatti 	.pwr_domain_on                  = versal_net_pwr_domain_on,
3500654ab7fSJay Buddhabhatti 	.pwr_domain_off                 = versal_net_pwr_domain_off,
3510654ab7fSJay Buddhabhatti 	.pwr_domain_on_finish           = versal_net_pwr_domain_on_finish,
3520654ab7fSJay Buddhabhatti 	.pwr_domain_suspend             = versal_net_pwr_domain_suspend,
3530654ab7fSJay Buddhabhatti 	.pwr_domain_suspend_finish      = versal_net_pwr_domain_suspend_finish,
3540654ab7fSJay Buddhabhatti 	.system_off                     = versal_net_system_off,
3550654ab7fSJay Buddhabhatti 	.system_reset                   = versal_net_system_reset,
3565f22f573SSenthil Nathan Thangaraj 	.system_reset2                  = versal_net_system_reset2,
357e5e417ddSMaheedhar Bollapalli 	.validate_ns_entrypoint		= versal_net_validate_ns_entrypoint,
3580654ab7fSJay Buddhabhatti 	.validate_power_state           = versal_net_validate_power_state,
3590654ab7fSJay Buddhabhatti 	.get_sys_suspend_power_state    = versal_net_get_sys_suspend_power_state,
3600654ab7fSJay Buddhabhatti };
3610654ab7fSJay Buddhabhatti 
3620654ab7fSJay Buddhabhatti /*******************************************************************************
3630654ab7fSJay Buddhabhatti  * Export the platform specific power ops.
3640654ab7fSJay Buddhabhatti  ******************************************************************************/
plat_setup_psci_ops(uintptr_t sec_entrypoint,const struct plat_psci_ops ** psci_ops)3650654ab7fSJay Buddhabhatti int32_t plat_setup_psci_ops(uintptr_t sec_entrypoint,
3660654ab7fSJay Buddhabhatti 			    const struct plat_psci_ops **psci_ops)
3670654ab7fSJay Buddhabhatti {
3680654ab7fSJay Buddhabhatti 	versal_net_sec_entry = sec_entrypoint;
3690654ab7fSJay Buddhabhatti 
3700654ab7fSJay Buddhabhatti 	VERBOSE("Setting up entry point %lx\n", versal_net_sec_entry);
3710654ab7fSJay Buddhabhatti 
3720654ab7fSJay Buddhabhatti 	*psci_ops = &versal_net_nopmc_psci_ops;
3730654ab7fSJay Buddhabhatti 
3740654ab7fSJay Buddhabhatti 	return 0;
3750654ab7fSJay Buddhabhatti }
3760654ab7fSJay Buddhabhatti 
sip_svc_setup_init(void)3770654ab7fSJay Buddhabhatti int32_t sip_svc_setup_init(void)
3780654ab7fSJay Buddhabhatti {
3790654ab7fSJay Buddhabhatti 	return pm_setup();
3800654ab7fSJay Buddhabhatti }
3810654ab7fSJay Buddhabhatti 
smc_handler(uint32_t smc_fid,uint64_t x1,uint64_t x2,uint64_t x3,uint64_t x4,void * cookie,void * handle,uint64_t flags)3820654ab7fSJay Buddhabhatti uint64_t smc_handler(uint32_t smc_fid, uint64_t x1, uint64_t x2, uint64_t x3, uint64_t x4,
3830654ab7fSJay Buddhabhatti 		     void *cookie, void *handle, uint64_t flags)
3840654ab7fSJay Buddhabhatti {
3850654ab7fSJay Buddhabhatti 	return pm_smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle, flags);
3860654ab7fSJay Buddhabhatti }
387