Add test case for SMCCC_ARCH_SOC_ID feature

Added test case for "SMCCC_ARCH_SOC_ID" SMC call.
This SMC call is used to retrieve SOC version and SOC revision

Test execution output is as below:

> Executing 'SMCCC_ARCH_SOC_ID test'
  TEST COMPLETE                                                 Passed
SOC Rev is not implemented
SOC Ver = 0x43b0000

Signed-off-by: Manish V Badarkhe <Manish.Badarkhe@arm.com>
Change-Id: I48668ce22bb5d5767dadb42ce9526d77fd916bed
diff --git a/include/runtime_services/arm_arch_svc.h b/include/runtime_services/arm_arch_svc.h
index 12358f8..36b4448 100644
--- a/include/runtime_services/arm_arch_svc.h
+++ b/include/runtime_services/arm_arch_svc.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018, Arm Limited. All rights reserved.
+ * Copyright (c) 2018-2020, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
@@ -9,6 +9,7 @@
 
 #define SMCCC_VERSION		0x80000000
 #define SMCCC_ARCH_FEATURES	0x80000001
+#define SMCCC_ARCH_SOC_ID	0x80000002
 #define SMCCC_ARCH_WORKAROUND_1	0x80008000
 #define SMCCC_ARCH_WORKAROUND_2	0x80007FFF
 
diff --git a/include/runtime_services/smccc.h b/include/runtime_services/smccc.h
index 34930b6..283b463 100644
--- a/include/runtime_services/smccc.h
+++ b/include/runtime_services/smccc.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018-2019, Arm Limited. All rights reserved.
+ * Copyright (c) 2018-2020, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
@@ -20,6 +20,13 @@
 						SMCCC_VERSION_MINOR_SHIFT))
 
 #define SMC_UNKNOWN			-1
+#define SMC_OK				0
+
+/* Return codes for Arm Architecture Service SMC calls */
+#define SMC_ARCH_CALL_SUCCESS           0
+#define SMC_ARCH_CALL_NOT_SUPPORTED     -1
+#define SMC_ARCH_CALL_NOT_REQUIRED      -2
+#define SMC_ARCH_CALL_INVAL_PARAM       -3
 
 /*******************************************************************************
  * Bit definitions inside the function id as per the SMC calling convention
@@ -64,4 +71,10 @@
 #define OEN_TOS_END			63
 #define OEN_LIMIT			64
 
+/*******************************************************************************
+ * Argument definitions passed to SMC call
+ ******************************************************************************/
+#define SMC_GET_SOC_VERSION		0
+#define SMC_GET_SOC_REVISION		1
+
 #endif /* __SMCCC_H__ */
diff --git a/tftf/tests/runtime_services/arm_arch_svc/smccc_arch_soc_id.c b/tftf/tests/runtime_services/arm_arch_svc/smccc_arch_soc_id.c
new file mode 100644
index 0000000..b866450
--- /dev/null
+++ b/tftf/tests/runtime_services/arm_arch_svc/smccc_arch_soc_id.c
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2020, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <arch_helpers.h>
+#include <arm_arch_svc.h>
+#include <debug.h>
+#include <smccc.h>
+#include <string.h>
+#include <tftf_lib.h>
+
+/*
+ * Return SOC ID parameters(SOC revision/SOC version) according
+ * to argument passed
+ */
+static smc_ret_values get_soc_id_param(u_register_t arg)
+{
+	smc_args args;
+	smc_ret_values ret;
+
+	memset(&args, 0, sizeof(args));
+	args.fid = SMCCC_ARCH_SOC_ID;
+	args.arg1 = arg;
+	ret = tftf_smc(&args);
+
+	return ret;
+}
+
+/* Entry function to execute SMCCC_ARCH_SOC_ID test */
+test_result_t test_smccc_arch_soc_id(void)
+{
+	smc_args args;
+	smc_ret_values ret;
+	int32_t expected_ver;
+	int32_t	skip_cnt = 0;
+	bool	fail_soc_id_test = false;
+
+	/* Check if SMCCC version is at least v1.2 */
+	expected_ver = MAKE_SMCCC_VERSION(1, 2);
+	memset(&args, 0, sizeof(args));
+	args.fid = SMCCC_VERSION;
+	ret = tftf_smc(&args);
+	if ((int32_t)ret.ret0 < expected_ver) {
+		tftf_testcase_printf("Unexpected SMCCC version: 0x%x\n",
+		       (int)ret.ret0);
+		return TEST_RESULT_SKIPPED;
+	}
+
+	/* Check if SMCCC_ARCH_SOC_ID is implemented or not */
+	memset(&args, 0, sizeof(args));
+	args.fid = SMCCC_ARCH_FEATURES;
+	args.arg1 = SMCCC_ARCH_SOC_ID;
+	ret = tftf_smc(&args);
+	if ((int)ret.ret0 == SMC_ARCH_CALL_NOT_SUPPORTED) {
+		tftf_testcase_printf("SMCCC_ARCH_SOC_ID is not implemented\n");
+		return TEST_RESULT_FAIL;
+	}
+
+	/* If the call returns SMC_OK then SMCCC_ARCH_SOC_ID is feature available */
+	if ((int)ret.ret0 == SMC_OK) {
+		ret = get_soc_id_param(SMC_GET_SOC_REVISION);
+
+		if ((int)ret.ret0 == SMC_ARCH_CALL_INVAL_PARAM) {
+			ERROR("Invalid param passed to SMCCC_ARCH_SOC_ID\n");
+			fail_soc_id_test = true;
+		} else if ((int)ret.ret0 == SMC_ARCH_CALL_NOT_SUPPORTED) {
+			tftf_testcase_printf("SOC Rev is not implemented\n");
+			skip_cnt++;
+		} else {
+			tftf_testcase_printf("SOC Rev = 0x%x\n", (int)ret.ret0);
+		}
+
+		ret = get_soc_id_param(SMC_GET_SOC_VERSION);
+
+		if ((int)ret.ret0 == SMC_ARCH_CALL_INVAL_PARAM) {
+			ERROR("Invalid param passed to SMCCC_ARCH_SOC_ID\n");
+			fail_soc_id_test = true;
+		} else if ((int)ret.ret0 == SMC_ARCH_CALL_NOT_SUPPORTED) {
+			tftf_testcase_printf("SOC Ver is not implemented\n");
+			skip_cnt++;
+		} else {
+			tftf_testcase_printf("SOC Ver = 0x%x\n", (int)ret.ret0);
+		}
+
+		if (skip_cnt == 2)
+			return TEST_RESULT_SKIPPED;
+		else if (fail_soc_id_test)
+			return TEST_RESULT_FAIL;
+	} else {
+		ERROR("Invalid error during SMCCC_ARCH_FEATURES call = 0x%x\n",
+			(int)ret.ret0);
+		return TEST_RESULT_FAIL;
+	}
+
+	return TEST_RESULT_SUCCESS;
+}
diff --git a/tftf/tests/tests-cpu-extensions.mk b/tftf/tests/tests-cpu-extensions.mk
index 9102b35..1b7743e 100644
--- a/tftf/tests/tests-cpu-extensions.mk
+++ b/tftf/tests/tests-cpu-extensions.mk
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2018-2019, Arm Limited. All rights reserved.
+# Copyright (c) 2018-2020, Arm Limited. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -11,5 +11,6 @@
 	extensions/sve/test_sve.c					\
 	runtime_services/arm_arch_svc/smccc_arch_workaround_1.c		\
 	runtime_services/arm_arch_svc/smccc_arch_workaround_2.c		\
+	runtime_services/arm_arch_svc/smccc_arch_soc_id.c		\
 	extensions/pauth/test_pauth.c					\
 )
diff --git a/tftf/tests/tests-cpu-extensions.xml b/tftf/tests/tests-cpu-extensions.xml
index 158cb04..aff6b61 100644
--- a/tftf/tests/tests-cpu-extensions.xml
+++ b/tftf/tests/tests-cpu-extensions.xml
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 
 <!--
-  Copyright (c) 2018-2019, Arm Limited. All rights reserved.
+  Copyright (c) 2018-2020, Arm Limited. All rights reserved.
 
   SPDX-License-Identifier: BSD-3-Clause
 -->
@@ -23,6 +23,7 @@
   <testsuite name="ARM_ARCH_SVC" description="Arm Architecture Service tests">
      <testcase name="SMCCC_ARCH_WORKAROUND_1 test" function="test_smccc_arch_workaround_1" />
      <testcase name="SMCCC_ARCH_WORKAROUND_2 test" function="test_smccc_arch_workaround_2" />
+     <testcase name="SMCCC_ARCH_SOC_ID test" function="test_smccc_arch_soc_id" />
   </testsuite>
 
 </testsuites>