feat(rmm-eac4): update RSI_VERSION, add RSI_FEATURES

This patch updates API of RSI_VERSION and adds new
RSI_FEATURES command handler as per RMM Specification
1.0-eac4.
RSI_ABI_VERSION_MAJOR is updated from 13 to 14.

Signed-off-by: AlexeiFedorov <Alexei.Fedorov@arm.com>
Change-Id: I7d445d18ee7fddf9f20c51f2a45fd334cb17b454
diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt
index 51352d6..1152692 100644
--- a/runtime/CMakeLists.txt
+++ b/runtime/CMakeLists.txt
@@ -59,6 +59,7 @@
 
 target_sources(rmm-runtime
     PRIVATE "rsi/config.c"
+            "rsi/feature.c"
             "rsi/host_call.c"
             "rsi/logger.c"
             "rsi/memory.c"
diff --git a/runtime/core/exit.c b/runtime/core/exit.c
index c7ead2f..ea25f6d 100644
--- a/runtime/core/exit.c
+++ b/runtime/core/exit.c
@@ -405,13 +405,16 @@
 		res.action = UPDATE_REC_RETURN_TO_REALM;
 		res.smc_res.x[0] = SMCCC_VERSION_NUMBER;
 		break;
-	case SMC_RSI_ABI_VERSION:
-		handle_rsi_version(&res);
-		break;
 	case SMC32_PSCI_FID_MIN ... SMC32_PSCI_FID_MAX:
 	case SMC64_PSCI_FID_MIN ... SMC64_PSCI_FID_MAX:
 		handle_psci(rec, rec_exit, &res);
 		break;
+	case SMC_RSI_ABI_VERSION:
+		handle_rsi_version(rec, &res);
+		break;
+	case SMC_RSI_FEATURES:
+		handle_rsi_features(rec, &res);
+		break;
 	case SMC_RSI_ATTEST_TOKEN_INIT:
 		handle_rsi_attest_token_init(rec, &res);
 		break;
diff --git a/runtime/include/rsi-handler.h b/runtime/include/rsi-handler.h
index f156fb3..43633bc 100644
--- a/runtime/include/rsi-handler.h
+++ b/runtime/include/rsi-handler.h
@@ -78,7 +78,8 @@
 	struct smc_result smc_res;
 };
 
-void handle_rsi_version(struct rsi_result *res);
+void handle_rsi_version(struct rec *rec, struct rsi_result *res);
+void handle_rsi_features(struct rec *rec, struct rsi_result *res);
 void handle_rsi_realm_config(struct rec *rec, struct rsi_result *res);
 void handle_rsi_host_call(struct rec *rec, struct rmi_rec_exit *rec_exit,
 			  struct rsi_result *res);
diff --git a/runtime/rsi/feature.c b/runtime/rsi/feature.c
new file mode 100644
index 0000000..f9a1d07
--- /dev/null
+++ b/runtime/rsi/feature.c
@@ -0,0 +1,18 @@
+/*
+ * SPDX-License-Identifier: BSD-3-Clause
+ * SPDX-FileCopyrightText: Copyright TF-RMM Contributors.
+ */
+#include <rec.h>
+#include <rsi-handler.h>
+#include <smc-rsi.h>
+
+void handle_rsi_features(struct rec *rec, struct rsi_result *res)
+{
+	(void)rec;
+
+	res->action = UPDATE_REC_RETURN_TO_REALM;
+	res->smc_res.x[0] = RSI_SUCCESS;
+
+	/* Return zero regardless of the index provided */
+	res->smc_res.x[1] = 0UL;
+}
diff --git a/runtime/rsi/logger.c b/runtime/rsi/logger.c
index 0f61aec..5db269d 100644
--- a/runtime/rsi/logger.c
+++ b/runtime/rsi/logger.c
@@ -37,7 +37,8 @@
 }
 
 static const struct rsi_handler rsi_logger[] = {
-	RSI_FUNCTION(ABI_VERSION, 0U, 1U),		/* 0xC4000190 */
+	RSI_FUNCTION(ABI_VERSION, 1U, 1U),		/* 0xC4000190 */
+	RSI_FUNCTION(FEATURES, 1U, 1U),			/* 0xC4000191 */
 	RSI_FUNCTION(MEASUREMENT_READ, 1U, 8U),		/* 0xC4000192 */
 	RSI_FUNCTION(MEASUREMENT_EXTEND, 10U, 0U),	/* 0xC4000193 */
 	RSI_FUNCTION(ATTEST_TOKEN_INIT, 9U, 0U),	/* 0xC4000194 */
@@ -75,14 +76,8 @@
 		const struct rsi_handler *logger = fid_to_rsi_logger(id);
 
 		num = logger->num_args;
-		if (logger->fn_name != NULL) {
-			cnt = snprintf(buf, MAX_NAME_LEN + 1UL,
+		cnt = snprintf(buf, MAX_NAME_LEN + 1UL,
 				"%s%s", "SMC_RSI_", logger->fn_name);
-		} else {
-			/* Handle gaps in RSI commands numbering */
-			cnt = snprintf(buf, MAX_NAME_LEN + 1UL,
-					"%s%08x", "SMC_RSI_", id);
-		}
 		break;
 	}
 	/* SMC32 PSCI calls */
@@ -144,7 +139,7 @@
 	int cnt;
 
 	switch (function_id) {
-	case SMC_RSI_MEASUREMENT_READ ... SMC_RSI_HOST_CALL: {
+	case SMC_RSI_ABI_VERSION ... SMC_RSI_HOST_CALL: {
 		const struct rsi_handler *logger =
 				fid_to_rsi_logger(function_id);
 
@@ -153,9 +148,6 @@
 		num = logger->num_vals;
 		break;
 	}
-	case SMC_RSI_ABI_VERSION:
-		num = 0U;
-		FALLTHROUGH;
 	default:
 		/* Print result code */
 		cnt = print_code(buf, len, regs[0]);
diff --git a/runtime/rsi/system.c b/runtime/rsi/system.c
index 1b5d1bb..40209bb 100644
--- a/runtime/rsi/system.c
+++ b/runtime/rsi/system.c
@@ -3,14 +3,22 @@
  * SPDX-FileCopyrightText: Copyright TF-RMM Contributors.
  */
 #include <assert.h>
+#include <rec.h>
 #include <rsi-handler.h>
 #include <smc-rsi.h>
 
 COMPILER_ASSERT(RSI_ABI_VERSION_MAJOR <= 0x7FFF);
 COMPILER_ASSERT(RSI_ABI_VERSION_MINOR <= 0xFFFF);
 
-void handle_rsi_version(struct rsi_result *res)
+void handle_rsi_version(struct rec *rec, struct rsi_result *res)
 {
 	res->action = UPDATE_REC_RETURN_TO_REALM;
-	res->smc_res.x[0] = RSI_ABI_VERSION;
+
+	if (rec->regs[1] != RSI_ABI_VERSION) {
+		res->smc_res.x[0] = RSI_ERROR_INPUT;
+	} else {
+		res->smc_res.x[0] = RSI_SUCCESS;
+	}
+
+	res->smc_res.x[1] = RSI_ABI_VERSION;
 }
diff --git a/runtime/tests/rsi_logger_tests.cpp b/runtime/tests/rsi_logger_tests.cpp
index ea549c1..3c62041 100644
--- a/runtime/tests/rsi_logger_tests.cpp
+++ b/runtime/tests/rsi_logger_tests.cpp
@@ -54,13 +54,10 @@
 	/* Fill output values */
 	switch (status) {
 	case LOG_SUCCESS:
-		regs[0] = (id == SMC_RSI_ABI_VERSION) ?
-				RSI_ABI_VERSION : RSI_SUCCESS;
+		regs[0] = RSI_SUCCESS;
 		break;
 	case LOG_ERROR:
-		regs[0] = (id == SMC_RSI_ABI_VERSION) ?
-				RSI_ABI_VERSION :
-				test_helpers_get_rand_in_range(RSI_ERROR_INPUT, RSI_INCOMPLETE);
+		regs[0] = test_helpers_get_rand_in_range(RSI_ERROR_INPUT, RSI_INCOMPLETE);
 		break;
 	default:
 		regs[0]	= rand();