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/cactus/aarch64/cactus_entrypoint.S b/spm/cactus/aarch64/cactus_entrypoint.S
index 6ca342a..6eff65e 100644
--- a/spm/cactus/aarch64/cactus_entrypoint.S
+++ b/spm/cactus/aarch64/cactus_entrypoint.S
@@ -1,13 +1,12 @@
 /*
- * Copyright (c) 2017-2021, Arm Limited. All rights reserved.
+ * Copyright (c) 2017-2022, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
 
 #include <arch.h>
 #include <asm_macros.S>
-#include <cactus_def.h>
-#include <cactus_platform_def.h>
+#include <sp_def.h>
 
 	.globl	cactus_entrypoint
 	.globl	secondary_cold_entry
@@ -15,7 +14,7 @@
 /* Provision one stack per Execution Context (or vCPU) */
 .section .bss.stacks
 	.balign CACHE_WRITEBACK_GRANULE
-	.fill	CACTUS_STACKS_SIZE * PLAT_CACTUS_CORE_COUNT
+	.fill	SP_STACKS_SIZE * PLAT_SP_CORE_COUNT
 stacks_end:
 
 func cactus_entrypoint
@@ -38,7 +37,7 @@
 
 	/* Setup the stack pointer. */
 	adr	x1, stacks_end
-	mov	x2, #CACTUS_STACKS_SIZE
+	mov	x2, #SP_STACKS_SIZE
 	mul	x2, x0, x2
 	sub	sp, x1, x2
 
@@ -81,7 +80,7 @@
 pie_fixup:
 	ldr	x0, =pie_fixup
 	and	x0, x0, #~(0x1000 - 1)
-	mov	x1, #CACTUS_IMAGE_SIZE
+	mov	x1, #SP_IMAGE_SIZE
 	add	x1, x1, x0
 	bl	fixup_gdt_reloc
 
diff --git a/spm/cactus/cactus.ld.S b/spm/cactus/cactus.ld.S
index 50fc576..afd72cb 100644
--- a/spm/cactus/cactus.ld.S
+++ b/spm/cactus/cactus.ld.S
@@ -1,10 +1,10 @@
 /*
- * Copyright (c) 2017-2021, Arm Limited. All rights reserved.
+ * Copyright (c) 2017-2022, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
 
-#include <cactus_def.h>
+#include <sp_def.h>
 #include <platform_def.h>
 #include <xlat_tables_defs.h>
 
@@ -14,7 +14,7 @@
 
 SECTIONS
 {
-    . = CACTUS_IMAGE_BASE;
+    . = SP_IMAGE_BASE;
 
     ASSERT(. == ALIGN(PAGE_SIZE),
            "TEXT_START address is not aligned to PAGE_SIZE.")
diff --git a/spm/cactus/cactus.mk b/spm/cactus/cactus.mk
index 6e6f2da..ce65035 100644
--- a/spm/cactus/cactus.mk
+++ b/spm/cactus/cactus.mk
@@ -27,7 +27,8 @@
 	-Iinclude/plat/common				\
 	-Iinclude/runtime_services			\
 	-Ispm/cactus					\
-	-Ispm/common
+	-Ispm/common					\
+	-Ispm/common/sp_tests
 
 CACTUS_SOURCES	:=					\
 	$(addprefix spm/cactus/,			\
@@ -41,11 +42,13 @@
 		sp_helpers.c				\
 		spm_helpers.c				\
 	)						\
+	$(addprefix spm/common/sp_tests/,		\
+		sp_test_ffa.c				\
+	)						\
 	$(addprefix spm/cactus/cactus_tests/,		\
 		cactus_message_loop.c			\
 		cactus_test_cpu_features.c		\
 		cactus_test_direct_messaging.c		\
-		cactus_test_ffa.c 			\
 		cactus_test_interrupts.c		\
 		cactus_test_memory_sharing.c		\
 		cactus_tests_smmuv3.c			\
diff --git a/spm/cactus/cactus_def.h b/spm/cactus/cactus_def.h
deleted file mode 100644
index 190f063..0000000
--- a/spm/cactus/cactus_def.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (c) 2018-2020, Arm Limited. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#ifndef CACTUS_DEF_H
-#define CACTUS_DEF_H
-
-#include <utils_def.h>
-
-/*
- * Layout of the Secure Partition image.
- */
-
-/* Up to 2 MiB at an arbitrary address that doesn't overlap the devices. */
-#define CACTUS_IMAGE_BASE		ULL(0x1000)
-#define CACTUS_IMAGE_SIZE		ULL(0x200000)
-
-/* Memory reserved for stacks */
-#define CACTUS_STACKS_SIZE		ULL(0x1000)
-
-/*
- * RX/TX buffer used by VM's in SPM for memory sharing
- * Each VM allocated 2 pages, one for RX and one for TX buffer.
- */
-#define CACTUS_RX_BASE			PLAT_CACTUS_RX_BASE
-#define CACTUS_TX_BASE			CACTUS_RX_BASE + PAGE_SIZE
-#define CACTUS_RX_TX_SIZE		PAGE_SIZE * 2
-
-/*
- * RX/TX buffer helpers.
- */
-#define get_sp_rx_start(sp_id) (CACTUS_RX_BASE + (((sp_id & 0x7FFFU) - 1U) * CACTUS_RX_TX_SIZE))
-#define get_sp_rx_end(sp_id) (CACTUS_RX_BASE + (((sp_id & 0x7FFFU) - 1U) * CACTUS_RX_TX_SIZE) + PAGE_SIZE)
-#define get_sp_tx_start(sp_id) (CACTUS_TX_BASE + (((sp_id & 0x7FFFU) - 1U) * CACTUS_RX_TX_SIZE))
-#define get_sp_tx_end(sp_id) (CACTUS_TX_BASE + (((sp_id & 0x7FFFU) - 1U) * CACTUS_RX_TX_SIZE) + PAGE_SIZE)
-
-#endif /* CACTUS_DEF_H */
diff --git a/spm/cactus/cactus_main.c b/spm/cactus/cactus_main.c
index 56cf21d..f610a3f 100644
--- a/spm/cactus/cactus_main.c
+++ b/spm/cactus/cactus_main.c
@@ -9,7 +9,6 @@
 #include <debug.h>
 
 #include <cactus_message_loop.h>
-#include <cactus_platform_def.h>
 #include <drivers/arm/pl011.h>
 #include <drivers/console.h>
 #include <lib/aarch64/arch_helpers.h>
@@ -26,8 +25,8 @@
 #include <spm_helpers.h>
 #include <std_svc.h>
 
-#include "cactus_def.h"
-#include "cactus_tests.h"
+#include "sp_def.h"
+#include "sp_tests.h"
 #include "cactus.h"
 
 /* Host machine information injected by the build system in the ELF file. */
@@ -199,12 +198,12 @@
 
 	mmap_add_region(get_sp_rx_start(vm_id),
 			get_sp_rx_start(vm_id),
-			(CACTUS_RX_TX_SIZE / 2),
+			(SP_RX_TX_SIZE / 2),
 			MT_RO_DATA);
 
 	mmap_add_region(get_sp_tx_start(vm_id),
 			get_sp_tx_start(vm_id),
-			(CACTUS_RX_TX_SIZE / 2),
+			(SP_RX_TX_SIZE / 2),
 			MT_RW_DATA);
 
 	mmap_add(cactus_mmap);
diff --git a/spm/cactus/cactus_tests/cactus_test_memory_sharing.c b/spm/cactus/cactus_tests/cactus_test_memory_sharing.c
index e67ff42..d5e43d8 100644
--- a/spm/cactus/cactus_tests/cactus_test_memory_sharing.c
+++ b/spm/cactus/cactus_tests/cactus_test_memory_sharing.c
@@ -4,14 +4,13 @@
  * SPDX-License-Identifier: BSD-3-Clause
  */
 
-#include <cactus_def.h>
-#include <cactus_platform_def.h>
+#include <sp_def.h>
 #include "cactus_message_loop.h"
 #include "cactus_test_cmds.h"
-#include "cactus_tests.h"
 #include <debug.h>
 #include <ffa_helpers.h>
 #include <sp_helpers.h>
+#include "sp_tests.h"
 #include <xlat_tables_defs.h>
 #include <lib/xlat_tables/xlat_tables_v2.h>
 #include <sync.h>
diff --git a/spm/cactus/cactus_tests/cactus_test_notifications.c b/spm/cactus/cactus_tests/cactus_test_notifications.c
index 947c8e0..d8b88ed 100644
--- a/spm/cactus/cactus_tests/cactus_test_notifications.c
+++ b/spm/cactus/cactus_tests/cactus_test_notifications.c
@@ -6,7 +6,8 @@
 
 #include "cactus_message_loop.h"
 #include "cactus_test_cmds.h"
-#include "cactus_tests.h"
+#include "sp_tests.h"
+
 #include <ffa_helpers.h>
 #include <debug.h>
 
diff --git a/spm/cactus/cactus_tests/cactus_tests_smmuv3.c b/spm/cactus/cactus_tests/cactus_tests_smmuv3.c
index fac9514..3e6740b 100644
--- a/spm/cactus/cactus_tests/cactus_tests_smmuv3.c
+++ b/spm/cactus/cactus_tests/cactus_tests_smmuv3.c
@@ -9,14 +9,14 @@
 #include <arch_helpers.h>
 #include "cactus.h"
 #include "cactus_message_loop.h"
-#include <cactus_platform_def.h>
+#include <sp_platform_def.h>
 #include "cactus_test_cmds.h"
-#include "cactus_tests.h"
 #include <debug.h>
 #include <ffa_helpers.h>
 #include <mmio.h>
 #include "smmuv3_test_engine.h"
 #include <sp_helpers.h>
+#include "sp_tests.h"
 #include <spm_common.h>
 
 /* Source and target address for memcopy operation */
diff --git a/spm/cactus/plat/arm/fvp/include/cactus_platform_def.h b/spm/cactus/plat/arm/fvp/include/sp_platform_def.h
similarity index 66%
rename from spm/cactus/plat/arm/fvp/include/cactus_platform_def.h
rename to spm/cactus/plat/arm/fvp/include/sp_platform_def.h
index a356577..0b23189 100644
--- a/spm/cactus/plat/arm/fvp/include/cactus_platform_def.h
+++ b/spm/cactus/plat/arm/fvp/include/sp_platform_def.h
@@ -1,13 +1,22 @@
 /*
- * Copyright (c) 2020-2021, Arm Limited. All rights reserved.
+ * Copyright (c) 2020-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
+
 #include <platform_def.h>
 
-#ifndef CACTUS_PLATFORM_DEF_H
-#define CACTUS_PLATFORM_DEF_H
+#define PLAT_SP_RX_BASE			ULL(0x7300000)
+#define PLAT_SP_CORE_COUNT		U(8)
 
 #define PLAT_ARM_DEVICE0_BASE		DEVICE0_BASE
 #define PLAT_ARM_DEVICE0_SIZE		DEVICE0_SIZE
@@ -15,9 +24,6 @@
 #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)
-#define PLAT_CACTUS_CORE_COUNT		(8U)
-
 /* Scratch memory used for SMMUv3 driver testing purposes in Cactus SP */
 #define PLAT_CACTUS_MEMCPY_BASE		ULL(0x7400000)
 #define PLAT_CACTUS_MEMCPY_RANGE	ULL(0x8000)
@@ -32,4 +38,4 @@
 #define CACTUS_SP3_MEM_SHARE_BASE 0x7502000
 #define CACTUS_SP3_NS_MEM_SHARE_BASE 0x880080001000ULL
 
-#endif /* CACTUS_PLATFORM_DEF_H */
+#endif /* SP_PLATFORM_DEF_H */
diff --git a/spm/cactus/plat/arm/tc0/include/cactus_platform_def.h b/spm/cactus/plat/arm/tc0/include/sp_platform_def.h
similarity index 72%
rename from spm/cactus/plat/arm/tc0/include/cactus_platform_def.h
rename to spm/cactus/plat/arm/tc0/include/sp_platform_def.h
index e5d83d6..3d288e6 100644
--- a/spm/cactus/plat/arm/tc0/include/cactus_platform_def.h
+++ b/spm/cactus/plat/arm/tc0/include/sp_platform_def.h
@@ -4,10 +4,19 @@
  * 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
+
 #include <platform_def.h>
 
-#ifndef CACTUS_PLATFORM_DEF_H
-#define CACTUS_PLATFORM_DEF_H
+#define PLAT_SP_RX_BASE			ULL(0xfe300000)
+#define PLAT_SP_CORE_COUNT		U(8)
 
 #define PLAT_ARM_DEVICE0_BASE		TC0_DEVICE0_BASE
 #define PLAT_ARM_DEVICE0_SIZE		TC0_DEVICE0_SIZE
@@ -15,9 +24,6 @@
 #define CACTUS_PL011_UART_BASE		PL011_UART1_BASE
 #define CACTUS_PL011_UART_CLK_IN_HZ	PL011_UART1_CLK_IN_HZ
 
-#define PLAT_CACTUS_RX_BASE		ULL(0xfe300000)
-#define PLAT_CACTUS_CORE_COUNT		(8)
-
 /* Scratch memory used for SMMUv3 driver testing purposes in Cactus SP */
 /* SMMUv3 tests are disabled for TC platform */
 #define PLAT_CACTUS_MEMCPY_BASE		ULL(0xfe400000)
@@ -34,4 +40,4 @@
 #define CACTUS_SP3_MEM_SHARE_BASE 0xfe502000
 #define CACTUS_SP3_NS_MEM_SHARE_BASE 0x880080001000ULL
 
-#endif /* CACTUS_PLATFORM_DEF_H */
+#endif /* SP_PLATFORM_DEF_H */
diff --git a/spm/common/sp_def.h b/spm/common/sp_def.h
new file mode 100644
index 0000000..2b26b68
--- /dev/null
+++ b/spm/common/sp_def.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2022, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef SP_DEF_H
+#define SP_DEF_H
+
+#include <utils_def.h>
+#include <sp_platform_def.h>
+
+/*
+ * Layout of the Secure Partition image.
+ */
+
+/* Up to 2 MiB at an arbitrary address that doesn't overlap the devices. */
+#define SP_IMAGE_BASE		ULL(0x1000)
+#define SP_IMAGE_SIZE		ULL(0x200000)
+
+/* Memory reserved for stacks */
+#define SP_STACKS_SIZE		ULL(0x1000)
+
+/*
+ * RX/TX buffer used by VM's in SPM for memory sharing
+ * Each VM allocated 2 pages, one for RX and one for TX buffer.
+ */
+#define SP_RX_BASE			PLAT_SP_RX_BASE
+#define SP_TX_BASE			SP_RX_BASE + PAGE_SIZE
+#define SP_RX_TX_SIZE			PAGE_SIZE * 2
+
+/*
+ * RX/TX buffer helpers.
+ */
+#define get_sp_rx_start(sp_id) (SP_RX_BASE \
+				+ (((sp_id & 0x7FFFU) - 1U) * SP_RX_TX_SIZE))
+#define get_sp_rx_end(sp_id) (SP_RX_BASE \
+			      + (((sp_id & 0x7FFFU) - 1U) * SP_RX_TX_SIZE) \
+			      + PAGE_SIZE)
+#define get_sp_tx_start(sp_id) (SP_TX_BASE + \
+				(((sp_id & 0x7FFFU) - 1U) * SP_RX_TX_SIZE))
+#define get_sp_tx_end(sp_id) (SP_TX_BASE \
+			      + (((sp_id & 0x7FFFU) - 1U) * SP_RX_TX_SIZE) \
+			      + PAGE_SIZE)
+
+#endif /* SP_DEF_H */
diff --git a/spm/cactus/cactus_tests/cactus_test_ffa.c b/spm/common/sp_tests/sp_test_ffa.c
similarity index 98%
rename from spm/cactus/cactus_tests/cactus_test_ffa.c
rename to spm/common/sp_tests/sp_test_ffa.c
index 7e6bf9e..f81505a 100644
--- a/spm/cactus/cactus_tests/cactus_test_ffa.c
+++ b/spm/common/sp_tests/sp_test_ffa.c
@@ -7,8 +7,7 @@
 #include <debug.h>
 #include <errno.h>
 
-#include <cactus_def.h>
-#include <cactus_platform_def.h>
+#include <sp_def.h>
 #include <ffa_endpoints.h>
 #include <sp_helpers.h>
 #include <spm_helpers.h>
diff --git a/spm/cactus/cactus_tests.h b/spm/common/sp_tests/sp_tests.h
similarity index 100%
rename from spm/cactus/cactus_tests.h
rename to spm/common/sp_tests/sp_tests.h
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			\