feat(amd): add test for self suspend EEMI API

Add tests for setting wakeup source and self-suspend EEMI APIs.
The purpose of these tests is to validate the setting up of wake up
source and for a cpu to declare that it is about to suspend itself.

Change-Id: I93374924703e03663b0d038a2aa79298e1cdb6f6
Signed-off-by: Madhav Bhatt <madhav.bhatt@amd.com>
diff --git a/tftf/tests/plat/amd/common/common_files/eemi_api.c b/tftf/tests/plat/amd/common/common_files/eemi_api.c
index 86f8f7f..87a63f5 100644
--- a/tftf/tests/plat/amd/common/common_files/eemi_api.c
+++ b/tftf/tests/plat/amd/common/common_files/eemi_api.c
@@ -495,3 +495,21 @@
 
 	return ret;
 }
+
+int xpm_self_suspend(const uint32_t device_id, const uint32_t latency, const uint8_t state,
+		     uint32_t address)
+{
+	uint32_t ret_payload[PAYLOAD_ARG_CNT];
+
+	return eemi_call(PM_SELF_SUSPEND, ((uint64_t)latency << 32 | device_id),
+			 (uint64_t)address << 32 | state, 0, 0, 0, 0, 0, ret_payload);
+}
+
+int xpm_set_wakeup_source(const uint32_t target_node_id, const uint32_t source_node_id,
+			  const uint32_t enable)
+{
+	uint32_t ret_payload[PAYLOAD_ARG_CNT];
+
+	return eemi_call(PM_SET_WAKEUP_SOURCE, ((uint64_t)source_node_id << 32 | target_node_id),
+			 enable, 0, 0, 0, 0, 0, ret_payload);
+}
diff --git a/tftf/tests/plat/amd/common/common_files/eemi_api.h b/tftf/tests/plat/amd/common/common_files/eemi_api.h
index 14cc66f..61c31f2 100644
--- a/tftf/tests/plat/amd/common/common_files/eemi_api.h
+++ b/tftf/tests/plat/amd/common/common_files/eemi_api.h
@@ -89,5 +89,9 @@
 			  uint32_t *value);
 int xpm_pll_set_mode(const uint32_t clock_id, const uint32_t value);
 int xpm_pll_get_mode(const uint32_t clock_id, uint32_t *value);
+int xpm_self_suspend(const uint32_t device_id, const uint32_t latency,
+		     const uint8_t state, uint32_t address);
+int xpm_set_wakeup_source(const uint32_t target_node_id, const uint32_t source_node_id,
+			  const uint32_t enable);
 
 #endif /* __EEMI_API_H__ */
diff --git a/tftf/tests/plat/amd/common/common_files/xpm_defs.h b/tftf/tests/plat/amd/common/common_files/xpm_defs.h
index 0bd8177..2e12d58 100644
--- a/tftf/tests/plat/amd/common/common_files/xpm_defs.h
+++ b/tftf/tests/plat/amd/common/common_files/xpm_defs.h
@@ -54,6 +54,13 @@
 #define PM_SHUTDOWN_SUBTYPE_RST_PS_ONLY         (1U)
 #define PM_SHUTDOWN_SUBTYPE_RST_SYSTEM          (2U)
 
+/**
+ * State arguments of the self suspend
+ */
+#define PM_SUSPEND_STATE_CPU_IDLE               0x0U
+#define PM_SUSPEND_STATE_CPU_OFF                0x1U
+#define PM_SUSPEND_STATE_SUSPEND_TO_RAM         0xFU
+
 /* API IDs */
 enum pm_api_id {
 	PM_API_MIN,                                     /**< 0x0 */
diff --git a/tftf/tests/plat/amd/common/common_files/xpm_nodeid.h b/tftf/tests/plat/amd/common/common_files/xpm_nodeid.h
index 1349d15..80259f9 100644
--- a/tftf/tests/plat/amd/common/common_files/xpm_nodeid.h
+++ b/tftf/tests/plat/amd/common/common_files/xpm_nodeid.h
@@ -10,13 +10,14 @@
 /*
  * Device Nodes
  */
+#define PM_DEV_ACPU_0           0x1810C003U
 #define PM_DEV_RPU0_0           0x18110005U
 #define PM_DEV_USB_0		0x18224018U
-#define PM_DEV_RTC              0x18224034U
+#define PM_DEV_TTC_0            0x18224024U
 #define PM_DEV_GEM_0            0x18224019U
 #define PM_DEV_QSPI		0x1822402BU
+#define PM_DEV_RTC              0x18224034U
 #define PM_DEV_SOC              0x18428044U
-
 /*
  * Clock Nodes
  */
diff --git a/tftf/tests/plat/amd/common/self_suspend/self_suspend.c b/tftf/tests/plat/amd/common/self_suspend/self_suspend.c
new file mode 100644
index 0000000..15cbea3
--- /dev/null
+++ b/tftf/tests/plat/amd/common/self_suspend/self_suspend.c
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2025, Advanced Micro Devices, Inc. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include "eemi_api.h"
+#include "xpm_nodeid.h"
+
+#define PROC_DEV_ID             PM_DEV_ACPU_0
+
+/* Extern Variable */
+extern void  __attribute__((weak)) *_vector_table;
+
+/*
+ * This function is used by a CPU to set wakeup source.
+ */
+test_result_t test_set_wakeup_source(void)
+{
+	int32_t status;
+
+	status = xpm_set_wakeup_source(PROC_DEV_ID, PM_DEV_TTC_0, 1);
+	if (status != PM_RET_SUCCESS) {
+		tftf_testcase_printf("%s ERROR Set WakeUp Source: 0x%x, Status: 0x%x\n",
+				     __func__, PM_DEV_TTC_0, status);
+
+		return TEST_RESULT_FAIL;
+	}
+
+	return TEST_RESULT_SUCCESS;
+}
+
+/*
+ * This function is used by a CPU to declare that it is about to
+ * suspend itself.
+ */
+test_result_t test_self_suspend(void)
+{
+	int32_t status;
+
+	status = xpm_self_suspend(PROC_DEV_ID, 0xFFFFFFFF,
+				  PM_SUSPEND_STATE_SUSPEND_TO_RAM,
+				  (uint64_t)&_vector_table);
+	if (status != PM_RET_SUCCESS) {
+		tftf_testcase_printf("%s ERROR Self-suspend, Status: 0x%x\n", __func__, status);
+
+		return TEST_RESULT_FAIL;
+	}
+
+	return TEST_RESULT_SUCCESS;
+}
diff --git a/tftf/tests/tests-versal.xml b/tftf/tests/tests-versal.xml
index d967fdb..4fd12e7 100644
--- a/tftf/tests/tests-versal.xml
+++ b/tftf/tests/tests-versal.xml
@@ -39,6 +39,8 @@
       <testcase name="Get PLL Mode" function="test_pll_get_mode" />
       <testcase name="Set PLL parameter " function="test_pll_set_parameter" />
       <testcase name="Get PLL parameter " function="test_pll_get_parameter" />
+      <testcase name="Set Wake Up Source" function="test_set_wakeup_source" />
+      <testcase name="Self Suspend" function="test_self_suspend" />
     </testsuite>
 
   </testsuites>