Cactus: Map RXTX region to third partion.

When the third cactus partition is booted, map the RXTX
region using the FFA_RXTX_MAP ABI. If this is successful,
point the mailbox to this RXTX region.

Signed-off-by: Ruari Phipps <ruari.phipps@arm.com>
Change-Id: Ifbe3bc70b187f75f29ef66356e714e8a905d2db8
diff --git a/include/runtime_services/ffa_helpers.h b/include/runtime_services/ffa_helpers.h
index 0692aa9..197879e 100644
--- a/include/runtime_services/ffa_helpers.h
+++ b/include/runtime_services/ffa_helpers.h
@@ -59,6 +59,7 @@
 smc_ret_values ffa_features(uint32_t feature);
 smc_ret_values ffa_partition_info_get(const uint32_t uuid[4]);
 smc_ret_values ffa_rx_release(void);
+smc_ret_values ffa_rxtx_map(uintptr_t send, uintptr_t recv, uint32_t pages);
 
 #endif /* __ASSEMBLY__ */
 
diff --git a/spm/cactus/cactus_main.c b/spm/cactus/cactus_main.c
index 31906d5..e833310 100644
--- a/spm/cactus/cactus_main.c
+++ b/spm/cactus/cactus_main.c
@@ -185,8 +185,32 @@
 	} else {
 		set_putc_impl(HVC_CALL_AS_STDOUT);
 
-		NOTICE("Booting Secondary Cactus Secure Partition\n%s\n%s\n",
-			build_message, version_string);
+		NOTICE("Booting Secondary Cactus Secure Partition (ID: %u)\n%s\n%s\n",
+			ffa_id, build_message, version_string);
+
+		if (ffa_id == SPM_VM_ID_THIRD) {
+			NOTICE("Mapping RXTX Region\n");
+
+			/* Declare RX/TX buffers at virtual FF-A instance */
+			static struct {
+					uint8_t rx[PAGE_SIZE];
+					uint8_t tx[PAGE_SIZE];
+			} __aligned(PAGE_SIZE) ffa_buffers;
+
+			/* Map RX/TX buffers */
+			smc_ret_values ret = ffa_rxtx_map((uintptr_t) &ffa_buffers.tx,
+				(uintptr_t) &ffa_buffers.rx,
+				sizeof(ffa_buffers.rx) / PAGE_SIZE);
+
+			if (ret.ret0 != FFA_SUCCESS_SMC32) {
+				ERROR("ffa_rxtx_map error (%lu)\n", ret.ret2);
+				panic();
+			}
+
+			/* Update mailbox with RX/TX buffer */
+			mb.send = (void *) &ffa_buffers.tx;
+			mb.recv = (void *) &ffa_buffers.rx;
+		}
 	}
 
 	NOTICE("FFA id: %u\n", ffa_id);
diff --git a/tftf/tests/runtime_services/secure_service/ffa_helpers.c b/tftf/tests/runtime_services/secure_service/ffa_helpers.c
index c90cac8..7ccf890 100644
--- a/tftf/tests/runtime_services/secure_service/ffa_helpers.c
+++ b/tftf/tests/runtime_services/secure_service/ffa_helpers.c
@@ -247,3 +247,16 @@
 
 	return tftf_smc(&args);
 }
+
+/* Map the RXTX buffer */
+smc_ret_values ffa_rxtx_map(uintptr_t send, uintptr_t recv, uint32_t pages)
+{
+	smc_args args = {
+		.fid = FFA_RXTX_MAP_SMC64,
+		.arg1 = send,
+		.arg2 = recv,
+		.arg3 = pages
+	};
+
+	return tftf_smc(&args);
+}