fix(ff-a): tftf handling of its RXTX buffer pair

The way tftf was handling the RXTX buffer pair created a dependency
on a set of tests from 'test_ffa_setup_and_discovery.c'. This was
problematic for test configurations for which the SPM tests are
not present.

This patch removes such dependency:
- Delete the 'INIT_MAILBOX' macro, and 'init_mailbox' function;
- RXTX buffer pair allocated within the 'get_tftf_mailbox'.
They are mapped into the SPMC via FFA_RXTX_MAP, and are returned
in the function's argument.

Signed-off-by: J-Alves <joao.alves@arm.com>
Change-Id: Ia010ebd21f11ab7ca6582b574ffc9179693b1eed
diff --git a/include/common/test_helpers.h b/include/common/test_helpers.h
index 43203a7..aa13a3f 100644
--- a/include/common/test_helpers.h
+++ b/include/common/test_helpers.h
@@ -238,17 +238,7 @@
 #define GET_TFTF_MAILBOX(mb)							\
 	do {									\
 		if (!get_tftf_mailbox(&mb)) {					\
-			ERROR("Mailbox not configured!\nThis test relies on"	\
-			" test suite \"FF-A RXTX Mapping\" to map/configure"	\
-			" RXTX buffers\n");					\
-			return TEST_RESULT_FAIL;				\
-		}								\
-	} while (false);
-
-#define INIT_TFTF_MAILBOX(mb)							\
-	do {									\
-		if (!mailbox_init(mb)) {					\
-			ERROR("Mailbox not configured properly!\n");		\
+			ERROR("Mailbox RXTX buffers not configured!\n");	\
 			return TEST_RESULT_FAIL;				\
 		}								\
 	} while (false);
@@ -402,17 +392,18 @@
 			     test_function_arg_t test);
 
 /*
- * Helper function to set TFTF global mailbox for SPM related tests.
- * This function should be invoked by the first TFTF test that requires
- * RX and/or TX buffers.
+ * Helper function to reset TFTF global mailbox for SPM related tests.
+ * It calls the FFA_RXTX_UNMAP interface, for the SPMC to drop the current
+ * address.
  */
-void set_tftf_mailbox(const struct mailbox_buffers *mb);
+bool reset_tftf_mailbox(void);
 
 /*
  * Helper function to get TFTF global mailbox for SPM related tests.
- * This function should be called by all tests that require access to RX or TX
- * buffers, after the function 'set_tftf_mailbox' has been used by the first
- * test to rely on RX and TX buffers.
+ * Allocates RX/TX buffer pair and calls FFA_RXTX_MAP interface, for the SPMC
+ * to map them into its own S1 translation.
+ * If this function is called, and the buffers had been priorly mapped, it
+ * sets 'mb' with the respective addresses.
  */
 bool get_tftf_mailbox(struct mailbox_buffers *mb);
 
diff --git a/tftf/tests/common/test_helpers.c b/tftf/tests/common/test_helpers.c
index 46a376f..cba4dad 100644
--- a/tftf/tests/common/test_helpers.c
+++ b/tftf/tests/common/test_helpers.c
@@ -132,20 +132,32 @@
 	return test_ret;
 }
 
-void set_tftf_mailbox(const struct mailbox_buffers *mb)
+bool reset_tftf_mailbox(void)
 {
-	if (mb != NULL) {
-		test_mb = *mb;
+	if (is_ffa_call_error(ffa_rxtx_unmap())) {
+		return false;
 	}
+
+	test_mb.send = NULL;
+	test_mb.recv = NULL;
+
+	return true;
 }
 
 bool get_tftf_mailbox(struct mailbox_buffers *mb)
 {
-	if ((test_mb.recv != NULL) && (test_mb.send != NULL)) {
-		*mb = test_mb;
-		return true;
+	struct ffa_value ret;
+
+	if (test_mb.recv == NULL || test_mb.send == NULL) {
+		CONFIGURE_AND_MAP_MAILBOX(test_mb, PAGE_SIZE, ret);
+		if (is_ffa_call_error(ret)) {
+			return false;
+		}
 	}
-	return false;
+
+	*mb = test_mb;
+
+	return true;
 }
 
 test_result_t check_spmc_testing_set_up(
@@ -235,24 +247,6 @@
 }
 
 /*
- * Initializes the Mailbox for other SPM related tests that need to use
- * RXTX buffers.
- */
-bool mailbox_init(struct mailbox_buffers mb)
-{
-	struct ffa_value ret;
-
-	ffa_rxtx_unmap();
-	CONFIGURE_AND_MAP_MAILBOX(mb, PAGE_SIZE, ret);
-	if (ffa_func_id(ret) != FFA_SUCCESS_SMC32) {
-		ERROR("Failed to map RXTX buffers %x!\n", ffa_error_code(ret));
-		return false;
-	}
-	set_tftf_mailbox(&mb);
-	return true;
-}
-
-/*
  * Utility function to wait for all CPUs other than the caller to be
  * OFF.
  */
diff --git a/tftf/tests/misc_tests/test_invalid_access.c b/tftf/tests/misc_tests/test_invalid_access.c
index c6331e4..1d0b6f4 100644
--- a/tftf/tests/misc_tests/test_invalid_access.c
+++ b/tftf/tests/misc_tests/test_invalid_access.c
@@ -315,8 +315,6 @@
 
 	SKIP_TEST_IF_FFA_VERSION_LESS_THAN(1,1);
 
-	INIT_TFTF_MAILBOX(mb);
-
 	CHECK_SPMC_TESTING_SETUP(1, 1, expected_sp_uuids);
 
 	GET_TFTF_MAILBOX(mb);
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 72982e9..e521411 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
@@ -291,17 +291,17 @@
 
 /**
  * Test mapping RXTX buffers that have been previously unmapped from NWd.
- * This test also sets the Mailbox for other SPM related tests that need to use
- * RXTX buffers.
  */
 test_result_t test_ffa_rxtx_map_unmapped_success(void)
 {
 	test_result_t ret =  test_ffa_rxtx_map(FFA_SUCCESS_SMC32);
-
-	if (ret == TEST_RESULT_SUCCESS) {
-		VERBOSE("Set RXTX Mailbox for remaining spm tests.\n");
-		set_tftf_mailbox(&mb);
-	}
+	/*
+	 * Unmapping buffers such that further tests can map and use RXTX
+	 * buffers.
+	 * Subsequent attempts to map the RXTX buffers will fail, if this is
+	 * invoked at this point.
+	 */
+	ffa_rxtx_unmap();
 	return ret;
 }
 
diff --git a/tftf/tests/tests-spm.xml b/tftf/tests/tests-spm.xml
index 9d5bcad..6f6fb75 100644
--- a/tftf/tests/tests-spm.xml
+++ b/tftf/tests/tests-spm.xml
@@ -21,11 +21,6 @@
      <testcase name="Smaller FFA version than SPM"
                function="test_ffa_version_smaller" />
 
-       <!--
-	 The ordering of the RXTX Buffer tests must be maintained.
-         With test_ffa_rxtx_map_unmapped_success coming last as the
-         mailbox for the remaining tftf tests is set here.
-       -->
      <testcase name="FF-A RXTX Map API success"
                function="test_ffa_rxtx_map_success" />
      <testcase name="FF-A RXTX Map API consecutive"