feat(amd): add platform specific test cases

Add test cases in the TF-A test framework to validate the
functionality of the EEMI APIs.
Also add client infrastructure to call PM APIs.

-get_api_version
-get_chipid
-feature_check

Note: As of now these changes are just for versal platform. We'll
refactor some of files in future to make it generic for all the
platforms.

Change-Id: Id55de9eadaeaf96ccab4aaa1a494620108c25a19
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
new file mode 100644
index 0000000..6dcb632
--- /dev/null
+++ b/tftf/tests/plat/amd/common/common_files/eemi_api.c
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 2025, Advanced Micro Devices, Inc. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include "eemi_api.h"
+#include "xpm_defs.h"
+
+static int do_feature_check(const uint32_t api_id)
+{
+	smc_args args;
+	smc_ret_values ret;
+
+	args.fid = (PM_SIP_SVC | PM_FEATURE_CHECK);
+	args.arg1 = api_id;
+
+	ret = tftf_smc(&args);
+
+	return lower_32_bits(ret.ret0);
+}
+
+static int eemi_call(const uint32_t arg0, const uint64_t arg1, const uint64_t arg2,
+		     const uint64_t arg3, const uint64_t arg4, const uint64_t arg5,
+		     const uint64_t arg6, const uint64_t arg7,
+		     uint32_t *const ret_payload)
+{
+	smc_args args;
+	smc_ret_values ret;
+	int32_t status;
+
+	args.fid = (PM_SIP_SVC | arg0);
+	args.arg1 = arg1;
+	args.arg2 = arg2;
+	args.arg3 = arg3;
+	args.arg4 = arg4;
+	args.arg5 = arg5;
+	args.arg6 = arg6;
+	args.arg7 = arg7;
+
+	/*
+	 * 'arg0' represents the API ID. This check ensures that the API is supported
+	 * by TF-A/PLM before making the actual API call.
+	 */
+	status = do_feature_check(arg0);
+	if (status != PM_RET_SUCCESS) {
+		tftf_testcase_printf("%s ERROR Status:0x%x, Feature Check Failed for "
+				     "API Id:0x%x\n", __func__, status, arg0);
+		return status;
+	}
+
+	ret = tftf_smc(&args);
+
+	if (ret_payload) {
+		ret_payload[0] = lower_32_bits(ret.ret0);
+		ret_payload[1] = upper_32_bits(ret.ret0);
+		ret_payload[2] = lower_32_bits(ret.ret1);
+		ret_payload[3] = upper_32_bits(ret.ret1);
+		ret_payload[4] = lower_32_bits(ret.ret2);
+		ret_payload[5] = upper_32_bits(ret.ret2);
+		ret_payload[6] = lower_32_bits(ret.ret3);
+	}
+
+	return lower_32_bits(ret.ret0);
+}
+
+int xpm_get_api_version(uint32_t *version)
+{
+	uint32_t ret_payload[PAYLOAD_ARG_CNT];
+	int ret;
+
+	ret = eemi_call(PM_GET_API_VERSION, 0, 0, 0, 0, 0, 0, 0, ret_payload);
+	if (ret == PM_RET_SUCCESS)
+		*version = ret_payload[1];
+
+	return ret;
+}
+
+int xpm_get_chip_id(uint32_t *id_code, uint32_t *version)
+{
+	uint32_t ret_payload[PAYLOAD_ARG_CNT];
+	int ret;
+
+	ret = eemi_call(PM_GET_CHIPID, 0, 0, 0, 0, 0, 0, 0, ret_payload);
+	if (ret == PM_RET_SUCCESS) {
+		*id_code = ret_payload[1];
+		*version = ret_payload[2];
+	}
+
+	return ret;
+}
+
+int xpm_feature_check(const uint32_t api_id, uint32_t *const version)
+{
+	uint32_t ret_payload[PAYLOAD_ARG_CNT];
+	int ret;
+
+	ret = eemi_call(PM_FEATURE_CHECK, api_id, 0, 0, 0, 0, 0, 0, ret_payload);
+	if (ret == PM_RET_SUCCESS)
+		*version = ret_payload[1];
+
+	return ret;
+}
diff --git a/tftf/tests/plat/amd/common/common_files/eemi_api.h b/tftf/tests/plat/amd/common/common_files/eemi_api.h
new file mode 100644
index 0000000..59de2ca
--- /dev/null
+++ b/tftf/tests/plat/amd/common/common_files/eemi_api.h
@@ -0,0 +1,16 @@
+/*
+ * Copyright (c) 2025, Advanced Micro Devices, Inc. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef __EEMI_API_H__
+#define __EEMI_API_H__
+
+#include "xpm_defs.h"
+
+int xpm_get_api_version(uint32_t *version);
+int xpm_get_chip_id(uint32_t *id_code, uint32_t *version);
+int xpm_feature_check(const uint32_t api_id, uint32_t *const version);
+
+#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
new file mode 100644
index 0000000..90d5ddd
--- /dev/null
+++ b/tftf/tests/plat/amd/common/common_files/xpm_defs.h
@@ -0,0 +1,112 @@
+/*
+ * Copyright (c) 2025, Advanced Micro Devices, Inc. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef XPM_DEFS_H_
+#define XPM_DEFS_H_
+
+#include <irq.h>
+#include <smccc.h>
+#include <tftf_lib.h>
+
+#define PM_SIP_SVC		0xC2000000U
+#define PAYLOAD_ARG_CNT		7U
+
+#define upper_32_bits(n)	((uint32_t)(((n) >> 32U)))
+#define lower_32_bits(n)	((uint32_t)((n) & 0xffffffffU))
+
+#define VERSION_MAJOR(v)	((v) >> 16)
+#define VERSION_MINOR(v)	((v) & 0xFFFF)
+
+#define PM_RET_SUCCESS		0U
+#define PM_RET_ERROR_ARGS	1U
+#define PM_NO_ACCESS		2002L
+#define PM_ERR_VERSION		2014L
+
+/* TF-A only commands */
+#define PM_GET_CALLBACK_DATA	0xa01U
+
+/* API IDs */
+enum pm_api_id {
+	PM_API_MIN,                                     /**< 0x0 */
+	PM_GET_API_VERSION,                             /**< 0x1 */
+	PM_SET_CONFIGURATION,                           /**< 0x2 */
+	PM_GET_NODE_STATUS,                             /**< 0x3 */
+	PM_GET_OP_CHARACTERISTIC,                       /**< 0x4 */
+	PM_REGISTER_NOTIFIER,                           /**< 0x5 */
+	PM_REQUEST_SUSPEND,                             /**< 0x6 */
+	PM_SELF_SUSPEND,                                /**< 0x7 */
+	PM_FORCE_POWERDOWN,                             /**< 0x8 */
+	PM_ABORT_SUSPEND,                               /**< 0x9 */
+	PM_REQUEST_WAKEUP,                              /**< 0xA */
+	PM_SET_WAKEUP_SOURCE,                           /**< 0xB */
+	PM_SYSTEM_SHUTDOWN,                             /**< 0xC */
+	PM_REQUEST_NODE,                                /**< 0xD */
+	PM_RELEASE_NODE,                                /**< 0xE */
+	PM_SET_REQUIREMENT,                             /**< 0xF */
+	PM_SET_MAX_LATENCY,                             /**< 0x10 */
+	PM_RESET_ASSERT,                                /**< 0x11 */
+	PM_RESET_GET_STATUS,                            /**< 0x12 */
+	PM_MMIO_WRITE,                                  /**< 0x13 */
+	PM_MMIO_READ,                                   /**< 0x14 */
+	PM_INIT_FINALIZE,                               /**< 0x15 */
+	PM_FPGA_LOAD,                                   /**< 0x16 */
+	PM_FPGA_GET_STATUS,                             /**< 0x17 */
+	PM_GET_CHIPID,                                  /**< 0x18 */
+	PM_SECURE_RSA_AES,                              /**< 0x19 */
+	PM_SECURE_SHA,                                  /**< 0x1A */
+	PM_SECURE_RSA,                                  /**< 0x1B */
+	PM_PINCTRL_REQUEST,                             /**< 0x1C */
+	PM_PINCTRL_RELEASE,                             /**< 0x1D */
+	PM_PINCTRL_GET_FUNCTION,                        /**< 0x1E */
+	PM_PINCTRL_SET_FUNCTION,                        /**< 0x1F */
+	PM_PINCTRL_CONFIG_PARAM_GET,                    /**< 0x20 */
+	PM_PINCTRL_CONFIG_PARAM_SET,                    /**< 0x21 */
+	PM_IOCTL,                                       /**< 0x22 */
+	PM_QUERY_DATA,                                  /**< 0x23 */
+	PM_CLOCK_ENABLE,                                /**< 0x24 */
+	PM_CLOCK_DISABLE,                               /**< 0x25 */
+	PM_CLOCK_GETSTATE,                              /**< 0x26 */
+	PM_CLOCK_SETDIVIDER,                            /**< 0x27 */
+	PM_CLOCK_GETDIVIDER,                            /**< 0x28 */
+	PM_CLOCK_SETRATE,                               /**< 0x29 */
+	/* PM_CLOCK_GETRATE API is deprecated */
+	PM_RESERVE_ID,                                  /**< 0x2A */
+	PM_CLOCK_SETPARENT,                             /**< 0x2B */
+	PM_CLOCK_GETPARENT,                             /**< 0x2C */
+	PM_SECURE_IMAGE,                                /**< 0x2D */
+	PM_FPGA_READ,                                   /**< 0x2E */
+	PM_SECURE_AES,                                  /**< 0x2F */
+	PM_PLL_SET_PARAMETER,                           /**< 0x30 */
+	PM_PLL_GET_PARAMETER,                           /**< 0x31 */
+	PM_PLL_SET_MODE,                                /**< 0x32 */
+	PM_PLL_GET_MODE,                                /**< 0x33 */
+	PM_REGISTER_ACCESS,                             /**< 0x34 */
+	PM_EFUSE_ACCESS,                                /**< 0x35 */
+	PM_ADD_SUBSYSTEM,                               /**< 0x36 */
+	PM_DESTROY_SUBSYSTEM,                           /**< 0x37 */
+	PM_DESCRIBE_NODES,                              /**< 0x38 */
+	PM_ADD_NODE,                                    /**< 0x39 */
+	PM_ADD_NODE_PARENT,                             /**< 0x3A */
+	PM_ADD_NODE_NAME,                               /**< 0x3B */
+	PM_ADD_REQUIREMENT,                             /**< 0x3C */
+	PM_SET_CURRENT_SUBSYSTEM,                       /**< 0x3D */
+	PM_INIT_NODE,                                   /**< 0x3E */
+	PM_FEATURE_CHECK,                               /**< 0x3F */
+	PM_ISO_CONTROL,                                 /**< 0x40 */
+	PM_ACTIVATE_SUBSYSTEM,                          /**< 0x41 */
+	PM_SET_NODE_ACCESS,                             /**< 0x42 */
+	PM_BISR,                                        /**< 0x43 */
+	PM_APPLY_TRIM,                                  /**< 0x44 */
+	PM_NOC_CLOCK_ENABLE,                            /**< 0x45 */
+	PM_IF_NOC_CLOCK_ENABLE,                         /**< 0x46 */
+	PM_FORCE_HOUSECLEAN,                            /**< 0x47 */
+	PM_FPGA_GET_VERSION,                            /**< 0x48 */
+	PM_FPGA_GET_FEATURE_LIST,                       /**< 0x49 */
+	PM_HNICX_NPI_DATA_XFER,                         /**< 0x4A */
+	PM_API_MAX                                      /**< 0x4B */
+};
+
+#endif /* XPM_DEFS_H_ */
diff --git a/tftf/tests/plat/amd/common/feature_check/feature_check.c b/tftf/tests/plat/amd/common/feature_check/feature_check.c
new file mode 100644
index 0000000..50095dd
--- /dev/null
+++ b/tftf/tests/plat/amd/common/feature_check/feature_check.c
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2025, Advanced Micro Devices, Inc. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include "eemi_api.h"
+#include "xpm_defs.h"
+
+/*
+ * This function tests the behavior of the xpm_feature_check() function, which
+ * queries information about the feature version.
+ */
+
+int api_id[] = {
+	PM_GET_API_VERSION,
+	PM_GET_NODE_STATUS,
+	PM_FEATURE_CHECK
+};
+
+test_result_t test_feature_check(void)
+{
+	uint32_t version = 0U;
+	int32_t status, index;
+
+	for (index = 0; index < ARRAY_SIZE(api_id); index++) {
+		status = xpm_feature_check(api_id[index], &version);
+
+		if (status != PM_RET_SUCCESS) {
+			tftf_testcase_printf("%s ERROR querying feature version for API Id:0x%x, "
+					     "Status: 0x%x\n", __func__, api_id[index], status);
+			return TEST_RESULT_FAIL;
+		}
+
+		tftf_testcase_printf("Api Id: 0x%x Version: %u\n\n", api_id[index], version);
+	}
+
+	return TEST_RESULT_SUCCESS;
+}
diff --git a/tftf/tests/plat/amd/common/get_api_version_test/get_api_version_test.c b/tftf/tests/plat/amd/common/get_api_version_test/get_api_version_test.c
new file mode 100644
index 0000000..b1a3bd4
--- /dev/null
+++ b/tftf/tests/plat/amd/common/get_api_version_test/get_api_version_test.c
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2025, Advanced Micro Devices, Inc. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include "eemi_api.h"
+#include "xpm_defs.h"
+
+/*
+ * This function tests the behavior of the xpm_get_api_version() function,
+ * which retrieves the API version of the Energy Efficient Management
+ * Interface (EEMI) on AMD-Xilinx platforms.
+ */
+test_result_t test_pm_api_version(void)
+{
+	uint32_t version = 0U;
+	uint32_t major, minor;
+	int32_t status;
+
+	status = xpm_get_api_version(&version);
+	if (status != PM_RET_SUCCESS) {
+		tftf_testcase_printf("%s ERROR reading PM API version\n", __func__);
+		return TEST_RESULT_FAIL;
+	}
+
+	major = VERSION_MAJOR(version);
+	minor = VERSION_MINOR(version);
+	tftf_testcase_printf("%s PM API version: %d.%d\n", __func__, major, minor);
+
+	return TEST_RESULT_SUCCESS;
+}
diff --git a/tftf/tests/plat/amd/common/get_chipid_test/get_chipid_test.c b/tftf/tests/plat/amd/common/get_chipid_test/get_chipid_test.c
new file mode 100644
index 0000000..1190ce2
--- /dev/null
+++ b/tftf/tests/plat/amd/common/get_chipid_test/get_chipid_test.c
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2025, Advanced Micro Devices, Inc. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include "eemi_api.h"
+#include "xpm_defs.h"
+
+/*
+ * This function tests the behavior of the xpm_get_chip_id() function, which
+ * retrieves the Chip ID and version information from the Energy Efficient
+ * Management Interface (EEMI) on AMD-Xilinx platforms.
+ */
+test_result_t test_get_chip_id(void)
+{
+	uint32_t id_code = 0U;
+	uint32_t version = 0U;
+	int32_t status;
+
+	status = xpm_get_chip_id(&id_code, &version);
+	if (status != PM_RET_SUCCESS) {
+		tftf_testcase_printf("%s ERROR reading chip id, Status: 0x%x\n", __func__, status);
+		return TEST_RESULT_FAIL;
+	}
+
+	tftf_testcase_printf("%s id_code = 0x%08x, version = 0x%08x\n", __func__,
+			     id_code, version);
+
+	return TEST_RESULT_SUCCESS;
+}
diff --git a/tftf/tests/tests-versal.mk b/tftf/tests/tests-versal.mk
index 6717ee5..0a2ad54 100644
--- a/tftf/tests/tests-versal.mk
+++ b/tftf/tests/tests-versal.mk
@@ -1,12 +1,12 @@
 #
-# Copyright (c) 2022-2023, Advanced Micro Devices, Inc. All rights reserved.
+# Copyright (c) 2022-2025, Advanced Micro Devices, Inc. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
-TESTS_SOURCES   +=      $(addprefix tftf/tests/plat/xilinx/common/,            \
-        plat_pm.c                                                              \
-)
 
+TFTF_INCLUDES   +=	-Itftf/tests/plat/amd/common/common_files/
+
+TESTS_SOURCES	+=	$(wildcard tftf/tests/plat/amd/common/*/*.c)
 
 include tftf/tests/tests-standard.mk
 TESTS_SOURCES += $(sort ${TESTS_SOURCES})
diff --git a/tftf/tests/tests-versal.xml b/tftf/tests/tests-versal.xml
index 6c8f519..547bf1d 100644
--- a/tftf/tests/tests-versal.xml
+++ b/tftf/tests/tests-versal.xml
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 
 <!--
-  Copyright (c) 2022-2023, Advanced Micro Devices, Inc. All rights reserved.
+  Copyright (c) 2022-2025, Advanced Micro Devices, Inc. All rights reserved.
 
   SPDX-License-Identifier: BSD-3-Clause
 -->
@@ -12,8 +12,9 @@
   <testsuites>
 
     <testsuite name="AMD-Xilinx tests" description="AMD-Xilinx common platform tests" >
-      <testcase name="Read PM API Version" function="test_pmapi_version" />
-      <testcase name="Get Platform Chip ID" function="test_get_chipid" />
+      <testcase name="Read PM API Version" function="test_pm_api_version" />
+      <testcase name="Get Platform Chip ID" function="test_get_chip_id" />
+      <testcase name="Feature Check" function="test_feature_check" />
     </testsuite>
 
   </testsuites>