Merge "feat(mt8189): add dfd driver" into integration
diff --git a/lib/psci/psci_main.c b/lib/psci/psci_main.c
index dfec9a1..00b0003 100644
--- a/lib/psci/psci_main.c
+++ b/lib/psci/psci_main.c
@@ -64,9 +64,6 @@
 	psci_power_state_t state_info = { {PSCI_LOCAL_STATE_RUN} };
 	plat_local_state_t cpu_pd_state;
 	unsigned int cpu_idx = plat_my_core_pos();
-#if PSCI_OS_INIT_MODE
-	plat_local_state_t prev[PLAT_MAX_PWR_LVL];
-#endif
 
 #if ERRATA_SME_POWER_DOWN
 	/*
@@ -103,7 +100,7 @@
 		panic();
 	}
 
-	/* Fast path for CPU standby.*/
+	/* Fast path for local CPU standby, won't interact with higher power levels. */
 	if (is_cpu_standby_req(is_power_down_state, target_pwrlvl)) {
 		if  (psci_plat_pm_ops->cpu_standby == NULL) {
 			return PSCI_E_INVALID_PARAMS;
@@ -116,18 +113,6 @@
 		cpu_pd_state = state_info.pwr_domain_state[PSCI_CPU_PWR_LVL];
 		psci_set_cpu_local_state(cpu_pd_state);
 
-#if PSCI_OS_INIT_MODE
-		/*
-		 * If in OS-initiated mode, save a copy of the previous
-		 * requested local power states and update the new requested
-		 * local power states for this CPU.
-		 */
-		if (psci_suspend_mode == OS_INIT) {
-			psci_update_req_local_pwr_states(target_pwrlvl, cpu_idx,
-							 &state_info, prev);
-		}
-#endif
-
 #if ENABLE_PSCI_STAT
 		plat_psci_stat_accounting_start(&state_info);
 #endif
@@ -143,16 +128,6 @@
 		/* Upon exit from standby, set the state back to RUN. */
 		psci_set_cpu_local_state(PSCI_LOCAL_STATE_RUN);
 
-#if PSCI_OS_INIT_MODE
-		/*
-		 * If in OS-initiated mode, restore the previous requested
-		 * local power states for this CPU.
-		 */
-		if (psci_suspend_mode == OS_INIT) {
-			psci_restore_req_local_pwr_states(cpu_idx, prev);
-		}
-#endif
-
 #if ENABLE_RUNTIME_INSTRUMENTATION
 		PMF_CAPTURE_TIMESTAMP(rt_instr_svc,
 		    RT_INSTR_EXIT_HW_LOW_PWR,
diff --git a/plat/amd/versal2/plat_psci_pm.c b/plat/amd/versal2/plat_psci_pm.c
index 3cc6b95..ab71043 100644
--- a/plat/amd/versal2/plat_psci_pm.c
+++ b/plat/amd/versal2/plat_psci_pm.c
@@ -110,7 +110,7 @@
 	 * Send the system reset request to the firmware if power down request
 	 * is not received from firmware.
 	 */
-	if (pwrdwn_req_received == false) {
+	if (pm_pwrdwn_req_status() == false) {
 		/*
 		 * TODO: shutdown scope for this reset needs be revised once
 		 * we have a clearer understanding of the overall reset scoping
diff --git a/plat/amd/versal2/pm_service/pm_svc_main.c b/plat/amd/versal2/pm_service/pm_svc_main.c
index 55fd963..ae26d6b 100644
--- a/plat/amd/versal2/pm_service/pm_svc_main.c
+++ b/plat/amd/versal2/pm_service/pm_svc_main.c
@@ -68,7 +68,12 @@
 /* pm_up = true - UP, pm_up = false - DOWN */
 static bool pm_up;
 static uint32_t sgi = (uint32_t)INVALID_SGI;
-bool pwrdwn_req_received;
+static bool pwrdwn_req_received;
+
+bool pm_pwrdwn_req_status(void)
+{
+	return pwrdwn_req_received;
+}
 
 static void notify_os(void)
 {
@@ -269,6 +274,7 @@
 
 	pm_ipi_init(primary_proc);
 	pm_up = true;
+	pwrdwn_req_received = false;
 
 	/* register SGI handler for CPU power down request */
 	ret = request_intr_type_el3(CPU_PWR_DOWN_REQ_INTR, cpu_pwrdwn_req_handler);
diff --git a/plat/ti/k3/common/k3_psci.c b/plat/ti/k3/common/k3_psci.c
index c679344c..ec37d9f 100644
--- a/plat/ti/k3/common/k3_psci.c
+++ b/plat/ti/k3/common/k3_psci.c
@@ -226,6 +226,28 @@
 		wfi();
 }
 
+static int k3_validate_power_state(unsigned int power_state, psci_power_state_t *req_state)
+{
+	unsigned int pwr_lvl = psci_get_pstate_pwrlvl(power_state);
+	unsigned int pstate = psci_get_pstate_type(power_state);
+
+	if (pwr_lvl > PLAT_MAX_PWR_LVL)
+		return PSCI_E_INVALID_PARAMS;
+
+	if (pstate == PSTATE_TYPE_STANDBY) {
+		/*
+		 * It's possible to enter standby only on power level 0
+		 * Ignore any other power level.
+		 */
+		if (pwr_lvl != MPIDR_AFFLVL0)
+			return PSCI_E_INVALID_PARAMS;
+
+		CORE_PWR_STATE(req_state) = PLAT_MAX_RET_STATE;
+	}
+
+	return PSCI_E_SUCCESS;
+}
+
 static void k3_pwr_domain_suspend_to_mode(const psci_power_state_t *target_state, uint8_t mode)
 {
 	unsigned int core, proc_id;
@@ -286,6 +308,7 @@
 	.get_sys_suspend_power_state = k3_get_sys_suspend_power_state,
 	.system_off = k3_system_off,
 	.system_reset = k3_system_reset,
+	.validate_power_state = k3_validate_power_state,
 };
 
 int plat_setup_psci_ops(uintptr_t sec_entrypoint,
diff --git a/plat/xilinx/common/include/pm_svc_main.h b/plat/xilinx/common/include/pm_svc_main.h
index 000f198..32a425c 100644
--- a/plat/xilinx/common/include/pm_svc_main.h
+++ b/plat/xilinx/common/include/pm_svc_main.h
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 2019-2022, Xilinx, Inc. All rights reserved.
- * Copyright (c) 2022-2024, Advanced Micro Devices, Inc. All rights reserved.
+ * Copyright (c) 2022-2025, Advanced Micro Devices, Inc. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
@@ -10,8 +10,6 @@
 
 #include <pm_common.h>
 
-extern bool pwrdwn_req_received;
-
 #define PASS_THROUGH_FW_CMD_ID	U(0xfff)
 
 /******************************************************************************/
@@ -34,6 +32,7 @@
 		status_tmp = function(__VA_ARGS__); \
 	}
 
+bool pm_pwrdwn_req_status(void);
 void request_cpu_pwrdwn(void);
 int32_t pm_setup(void);
 uint64_t pm_smc_handler(uint32_t smc_fid, uint64_t x1, uint64_t x2, uint64_t x3,
diff --git a/plat/xilinx/common/pm_service/pm_svc_main.c b/plat/xilinx/common/pm_service/pm_svc_main.c
index b8ff926..fd21917 100644
--- a/plat/xilinx/common/pm_service/pm_svc_main.c
+++ b/plat/xilinx/common/pm_service/pm_svc_main.c
@@ -67,7 +67,12 @@
 /* pm_up = true - UP, pm_up = false - DOWN */
 static bool pm_up;
 static uint32_t sgi = (uint32_t)INVALID_SGI;
-bool pwrdwn_req_received;
+static bool pwrdwn_req_received;
+
+bool pm_pwrdwn_req_status(void)
+{
+	return pwrdwn_req_received;
+}
 
 static void notify_os(void)
 {
@@ -257,6 +262,7 @@
 
 	pm_ipi_init(primary_proc);
 	pm_up = true;
+	pwrdwn_req_received = false;
 
 	/* register SGI handler for CPU power down request */
 	ret = request_intr_type_el3(CPU_PWR_DOWN_REQ_INTR, cpu_pwrdwn_req_handler);
diff --git a/plat/xilinx/versal/plat_psci.c b/plat/xilinx/versal/plat_psci.c
index 1c365b4..2b1b075 100644
--- a/plat/xilinx/versal/plat_psci.c
+++ b/plat/xilinx/versal/plat_psci.c
@@ -182,7 +182,7 @@
 	 * Send the system reset request to the firmware if power down request
 	 * is not received from firmware.
 	 */
-	if (!pwrdwn_req_received) {
+	if (!pm_pwrdwn_req_status()) {
 		(void)pm_system_shutdown(XPM_SHUTDOWN_TYPE_RESET,
 					 pm_get_shutdown_scope(), SECURE_FLAG);
 
diff --git a/plat/xilinx/versal_net/plat_psci_pm.c b/plat/xilinx/versal_net/plat_psci_pm.c
index 6ec8649..6d69d52 100644
--- a/plat/xilinx/versal_net/plat_psci_pm.c
+++ b/plat/xilinx/versal_net/plat_psci_pm.c
@@ -133,7 +133,7 @@
 	 * Send the system reset request to the firmware if power down request
 	 * is not received from firmware.
 	 */
-	if (!pwrdwn_req_received) {
+	if (!pm_pwrdwn_req_status()) {
 		(void)pm_system_shutdown(XPM_SHUTDOWN_TYPE_RESET,
 					 scope, SECURE_FLAG);