test(ff-a): versioned partition info descriptors

Add test to ensure an endpoint that sets it's version to
v1.0 receives v1.0 partition info descriptors as defined in
table 8.25 in the v1.0 FF-A specification when calling
ffa_partition_info_get. Also introduce ffa_partition_info_count
wrapper.

Signed-off-by: Daniel Boulby <daniel.boulby@arm.com>
Change-Id: I9f42e1898230208d85153714592b1a4165c92ce1
diff --git a/include/runtime_services/ffa_helpers.h b/include/runtime_services/ffa_helpers.h
index e4929b7..23b2439 100644
--- a/include/runtime_services/ffa_helpers.h
+++ b/include/runtime_services/ffa_helpers.h
@@ -72,6 +72,19 @@
 	struct ffa_uuid uuid;
 };
 
+/**
+ * Partition info descriptor as defined in Table 8.25 of the v1.0
+ * FF-A Specification
+ */
+struct ffa_partition_info_v1_0 {
+	/** The ID of the VM the information is about */
+	ffa_id_t id;
+	/** The number of execution contexts implemented by the partition */
+	uint16_t exec_context;
+	/** The Partition's properties, e.g. supported messaging methods */
+	uint32_t properties;
+};
+
 static inline uint32_t ffa_func_id(smc_ret_values val)
 {
 	return (uint32_t) val.ret0;
@@ -86,6 +99,11 @@
 	return (ffa_id_t) val.ret2 & 0xffff;
 }
 
+static inline uint32_t ffa_partition_info_count(smc_ret_values val)
+{
+	return (uint32_t) val.ret2;
+}
+
 static inline uint32_t ffa_feature_intid(smc_ret_values val)
 {
 	return (uint32_t)val.ret2;
diff --git a/tftf/tests/runtime_services/secure_service/spm_common.c b/tftf/tests/runtime_services/secure_service/spm_common.c
index 16f3c12..d01f272 100644
--- a/tftf/tests/runtime_services/secure_service/spm_common.c
+++ b/tftf/tests/runtime_services/secure_service/spm_common.c
@@ -529,7 +529,7 @@
 	smc_ret_values ret = ffa_partition_info_get(uuid);
 
 	if (ffa_func_id(ret) == FFA_SUCCESS_SMC32) {
-		if (ret.ret2 != expected_size) {
+		if (ffa_partition_info_count(ret) != expected_size) {
 			ERROR("Unexpected number of partitions %ld\n", ret.ret2);
 			return false;
 		}
diff --git a/tftf/tests/runtime_services/secure_service/test_ffa_setup_and_discovery.c b/tftf/tests/runtime_services/secure_service/test_ffa_setup_and_discovery.c
index 58d661e..3a16ee0 100644
--- a/tftf/tests/runtime_services/secure_service/test_ffa_setup_and_discovery.c
+++ b/tftf/tests/runtime_services/secure_service/test_ffa_setup_and_discovery.c
@@ -342,7 +342,7 @@
 	/***********************************************************************
 	 * Check if SPMC has ffa_version and expected FFA endpoints are deployed.
 	 **********************************************************************/
-	CHECK_SPMC_TESTING_SETUP(1, 0, sp_uuids);
+	CHECK_SPMC_TESTING_SETUP(1, 1, sp_uuids);
 
 	GET_TFTF_MAILBOX(mb);
 
@@ -366,3 +366,61 @@
 
 	return TEST_RESULT_SUCCESS;
 }
+
+/**
+ * Attempt to get v1.0 partition info descriptors.
+ */
+test_result_t test_ffa_partition_info_v1_0(void)
+{
+	/**************************************************************
+	 * Check if SPMC has ffa_version and expected FFA endpoints
+	 * are deployed.
+	 *************************************************************/
+	CHECK_SPMC_TESTING_SETUP(1, 0, sp_uuids);
+
+	GET_TFTF_MAILBOX(mb);
+
+	test_result_t result = TEST_RESULT_SUCCESS;
+	smc_ret_values ret = ffa_partition_info_get(null_uuid);
+	uint64_t expected_size = ARRAY_SIZE(ffa_expected_partition_info);
+
+	if (ffa_func_id(ret) == FFA_SUCCESS_SMC32) {
+		if (ffa_partition_info_count(ret) != expected_size) {
+			ERROR("Unexpected number of partitions %d\n",
+			      ffa_partition_info_count(ret));
+			return TEST_RESULT_FAIL;
+		}
+		const struct ffa_partition_info_v1_0 *info =
+			(const struct ffa_partition_info_v1_0 *)(mb.recv);
+
+		for (unsigned int i = 0U; i < expected_size; i++) {
+			if (info[i].id != ffa_expected_partition_info[i].id) {
+				ERROR("Wrong ID. Expected %x, got %x\n",
+				      ffa_expected_partition_info[i].id,
+				      info[i].id);
+				result = TEST_RESULT_FAIL;
+			}
+			if (info[i].exec_context !=
+			    ffa_expected_partition_info[i].exec_context) {
+				ERROR("Wrong context. Expected %d, got %d\n",
+				      ffa_expected_partition_info[i].exec_context,
+				      info[i].exec_context);
+				result = TEST_RESULT_FAIL;
+			}
+			if (info[i].properties !=
+			    ffa_expected_partition_info[i].properties) {
+				ERROR("Wrong properties. Expected %d, got %d\n",
+				      ffa_expected_partition_info[i].properties,
+				      info[i].properties);
+				result = TEST_RESULT_FAIL;
+			}
+		}
+	}
+
+	ret = ffa_rx_release();
+	if (is_ffa_call_error(ret)) {
+		ERROR("Failed to release RX buffer\n");
+		result = TEST_RESULT_FAIL;
+	}
+	return result;
+}
diff --git a/tftf/tests/tests-spm.xml b/tftf/tests/tests-spm.xml
index 9cf2ddc..f5174f5 100644
--- a/tftf/tests/tests-spm.xml
+++ b/tftf/tests/tests-spm.xml
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 
 <!--
-  Copyright (c) 2018-2021, Arm Limited. All rights reserved.
+  Copyright (c) 2018-2022, Arm Limited. All rights reserved.
 
   SPDX-License-Identifier: BSD-3-Clause
 -->
@@ -42,6 +42,8 @@
 
      <testcase name="Test FFA_PARTITION_INFO_GET"
                function="test_ffa_partition_info" />
+     <testcase name="Test FFA_PARTITION_INFO_GET v1.0"
+	       function="test_ffa_partition_info_v1_0" />
   </testsuite>
 
   <testsuite name="FF-A Direct messaging"