test(spm): run ffa_tests on ivy

Move cactus_test_ffa.c to a common directory for SPs so the
ivy partition can also run the same tests.

We also create a sp_platform_def.h file which contains various
plaform defines required for the tests. This header is defined
in both cactus and ivy directories and then fvp and tc0
subdirectories within those. The appropriate header for the sp
and platform being built is then included in the build scripts.

Signed-off-by: Daniel Boulby <daniel.boulby@arm.com>
Change-Id: If65d099d43cd930ef730539b5ad1596e686f788a
diff --git a/spm/ivy/app/ivy_main.c b/spm/ivy/app/ivy_main.c
index 1aafb57..30d2f37 100644
--- a/spm/ivy/app/ivy_main.c
+++ b/spm/ivy/app/ivy_main.c
@@ -9,8 +9,10 @@
 #include <errno.h>
 #include <ffa_helpers.h>
 #include <sp_debug.h>
+#include <sp_helpers.h>
 
 #include "ivy.h"
+#include "sp_tests.h"
 
 /* Host machine information injected by the build system in the ELF file. */
 extern const char build_message[];
@@ -20,6 +22,7 @@
 {
 	struct ffa_value ret;
 	ffa_id_t my_id;
+	struct mailbox_buffers mb;
 
 	set_putc_impl(SVC_CALL_AS_STDOUT);
 
@@ -36,6 +39,16 @@
 	NOTICE("%s\n", version_string);
 
 init:
+	VERBOSE("Mapping RXTX Regions\n");
+	CONFIGURE_AND_MAP_MAILBOX(mb, PAGE_SIZE, ret);
+	if (ffa_func_id(ret) != FFA_SUCCESS_SMC32) {
+		ERROR("Failed to map RXTX buffers. Error %x\n",
+		      ffa_error_code(ret));
+		panic();
+	}
+
+	ffa_tests(&mb);
+
 	ret = ffa_msg_wait();
 
 	while (1) {
diff --git a/spm/ivy/app/plat/arm/fvp/include/ivy_platform_def.h b/spm/ivy/app/plat/arm/fvp/include/ivy_platform_def.h
deleted file mode 100644
index 49c8231..0000000
--- a/spm/ivy/app/plat/arm/fvp/include/ivy_platform_def.h
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright (c) 2021, Arm Limited. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#include <platform_def.h>
-
-#ifndef CACTUS_PLATFORM_DEF_H
-#define CACTUS_PLATFORM_DEF_H
-
-#define PLAT_ARM_DEVICE0_BASE		DEVICE0_BASE
-#define PLAT_ARM_DEVICE0_SIZE		DEVICE0_SIZE
-
-#define CACTUS_PL011_UART_BASE		PL011_UART2_BASE
-#define CACTUS_PL011_UART_CLK_IN_HZ	PL011_UART2_CLK_IN_HZ
-
-#define PLAT_CACTUS_RX_BASE		ULL(0x7300000)
-
-#endif /* CACTUS_PLATFORM_DEF_H */
diff --git a/spm/ivy/app/plat/arm/fvp/include/sp_platform_def.h b/spm/ivy/app/plat/arm/fvp/include/sp_platform_def.h
new file mode 100644
index 0000000..b17f006
--- /dev/null
+++ b/spm/ivy/app/plat/arm/fvp/include/sp_platform_def.h
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2022, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+/*
+ * This file contains common defines for a secure partition. The correct
+ * platform_def.h header file is selected according to the secure partition
+ * and platform being built using the make scripts.
+ */
+
+#ifndef SP_PLATFORM_DEF_H
+#define SP_PLATFORM_DEF_H
+
+#define PLAT_SP_RX_BASE		ULL(0x7300000)
+
+#endif /* SP_PLATFORM_DEF_H */
diff --git a/spm/ivy/app/plat/arm/tc0/include/ivy_platform_def.h b/spm/ivy/app/plat/arm/tc0/include/ivy_platform_def.h
deleted file mode 100644
index 49c8231..0000000
--- a/spm/ivy/app/plat/arm/tc0/include/ivy_platform_def.h
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright (c) 2021, Arm Limited. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#include <platform_def.h>
-
-#ifndef CACTUS_PLATFORM_DEF_H
-#define CACTUS_PLATFORM_DEF_H
-
-#define PLAT_ARM_DEVICE0_BASE		DEVICE0_BASE
-#define PLAT_ARM_DEVICE0_SIZE		DEVICE0_SIZE
-
-#define CACTUS_PL011_UART_BASE		PL011_UART2_BASE
-#define CACTUS_PL011_UART_CLK_IN_HZ	PL011_UART2_CLK_IN_HZ
-
-#define PLAT_CACTUS_RX_BASE		ULL(0x7300000)
-
-#endif /* CACTUS_PLATFORM_DEF_H */
diff --git a/spm/ivy/app/plat/arm/tc0/include/sp_platform_def.h b/spm/ivy/app/plat/arm/tc0/include/sp_platform_def.h
new file mode 100644
index 0000000..326cb13
--- /dev/null
+++ b/spm/ivy/app/plat/arm/tc0/include/sp_platform_def.h
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2022, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+/*
+ * This file contains common defines for a secure partition. The correct
+ * platform_def.h header file is selected according to the secure partition
+ * and platform being built using the make scripts.
+ */
+
+#ifndef SP_PLATFORM_DEF_H
+#define SP_PLATFORM_DEF_H
+
+#define PLAT_SP_RX_BASE			ULL(0x7300000)
+
+#endif /* SP_PLATFORM_DEF_H */
diff --git a/spm/ivy/ivy.mk b/spm/ivy/ivy.mk
index e996a7c..0c0039d 100644
--- a/spm/ivy/ivy.mk
+++ b/spm/ivy/ivy.mk
@@ -30,11 +30,13 @@
 	-Iinclude/lib/${ARCH}				\
 	-Iinclude/lib/utils				\
 	-Iinclude/lib/xlat_tables			\
+	-Iinclude/plat/common				\
 	-Iinclude/runtime_services			\
 	-Iinclude/runtime_services/secure_el0_payloads	\
-	-Ispm/ivy/app				\
+	-Ispm/ivy/app					\
 	-Ispm/ivy/shim					\
-	-Ispm/common
+	-Ispm/common					\
+	-Ispm/common/sp_tests/
 
 IVY_SOURCES	:=					\
 	$(addprefix spm/ivy/app/,			\
@@ -46,6 +48,9 @@
 		sp_helpers.c				\
 		spm_helpers.c				\
 	)						\
+	$(addprefix spm/common/sp_tests/,		\
+		sp_test_ffa.c				\
+	)
 
 ifeq ($(IVY_SHIM),1)
 IVY_SOURCES	+=					\
@@ -57,11 +62,12 @@
 endif
 
 # TODO: Remove dependency on TFTF files.
-IVY_SOURCES	+=					\
-	tftf/framework/debug.c				\
-	tftf/framework/${ARCH}/asm_debug.S		\
+IVY_SOURCES	+=							\
+	tftf/framework/debug.c						\
+	tftf/framework/${ARCH}/asm_debug.S				\
 	tftf/tests/runtime_services/secure_service/${ARCH}/ffa_arch_helpers.S \
-	tftf/tests/runtime_services/secure_service/ffa_helpers.c
+	tftf/tests/runtime_services/secure_service/ffa_helpers.c 	\
+	tftf/tests/runtime_services/secure_service/spm_common.c
 
 IVY_SOURCES	+= 	drivers/arm/pl011/${ARCH}/pl011_console.S	\
 			lib/${ARCH}/cache_helpers.S			\