plat: tc0: Add cactus support

This patch adds tc0 platform support for cactus to execute at S-EL1

Change-Id: Iabac58de7c39e51968f0c5b578292e5a6111609a
Signed-off-by: Arunachalam Ganapathy <arunachalam.ganapathy@arm.com>
diff --git a/Makefile b/Makefile
index b09e749..8247bd9 100644
--- a/Makefile
+++ b/Makefile
@@ -127,10 +127,18 @@
 include tftf/tests/tests.mk
 include fwu/ns_bl1u/ns_bl1u.mk
 include fwu/ns_bl2u/ns_bl2u.mk
+
+# Only platform fvp supports cactus_mm, ivy, quark
+ifeq (${ARCH}-${PLAT},aarch64-fvp)
 include spm/cactus_mm/cactus_mm.mk
-include spm/cactus/cactus.mk
 include spm/ivy/ivy.mk
 include spm/quark/quark.mk
+endif
+
+# cactus is supported on platforms: fvp, tc0
+ifeq (${ARCH}-${PLAT},$(filter ${ARCH}-${PLAT},aarch64-fvp aarch64-tc0))
+include spm/cactus/cactus.mk
+endif
 
 ################################################################################
 # Include libc
@@ -359,11 +367,6 @@
 	@echo "ERROR: $@ is supported only on AArch64 FVP."
 	@exit 1
 
-.PHONY: cactus
-cactus:
-	@echo "ERROR: $@ is supported only on AArch64 FVP."
-	@exit 1
-
 .PHONY: ivy
 ivy:
 	@echo "ERROR: $@ is supported only on AArch64 FVP."
@@ -375,6 +378,13 @@
 	@exit 1
 endif
 
+ifneq (${ARCH}-${PLAT},$(filter ${ARCH}-${PLAT},aarch64-fvp aarch64-tc0))
+.PHONY: cactus
+cactus:
+	@echo "ERROR: $@ is supported only on AArch64 FVP or TC0."
+	@exit 1
+endif
+
 MAKE_DEP = -Wp,-MD,$(DEP) -MT $$@
 
 define MAKE_C
@@ -504,6 +514,10 @@
   $(eval $(call MAKE_IMG,quark))
 endif
 
+ifeq (${ARCH}-${PLAT},aarch64-tc0)
+  $(eval $(call MAKE_IMG,cactus))
+endif
+
 # The EL3 test payload is only supported in AArch64. It has an independent build
 # system.
 .PHONY: el3_payload
diff --git a/plat/arm/tc0/platform.mk b/plat/arm/tc0/platform.mk
index 05fa54c..faf0d19 100644
--- a/plat/arm/tc0/platform.mk
+++ b/plat/arm/tc0/platform.mk
@@ -17,7 +17,7 @@
 $(eval $(call add_define,NS_BL1U_DEFINES,TC0_MAX_PE_PER_CPU))
 $(eval $(call add_define,NS_BL2U_DEFINES,TC0_MAX_PE_PER_CPU))
 
-PLAT_INCLUDES	:=	-Iplat/arm/tc0/include/
+PLAT_INCLUDES	+=	-Iplat/arm/tc0/include/
 
 PLAT_SOURCES	:=	drivers/arm/gic/arm_gic_v2v3.c		\
 			drivers/arm/gic/gic_v2.c		\
diff --git a/spm/cactus/plat/arm/tc0/fdts/cactus-secondary.dts b/spm/cactus/plat/arm/tc0/fdts/cactus-secondary.dts
new file mode 100644
index 0000000..cc7715c
--- /dev/null
+++ b/spm/cactus/plat/arm/tc0/fdts/cactus-secondary.dts
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2020, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * This file is a Partition Manifest (PM) for a minimal Secure Partition (SP)
+ * that has additional optional properties defined.
+ *
+ */
+
+/dts-v1/;
+
+/ {
+	compatible = "arm,ffa-manifest-1.0";
+
+	/* Properties */
+	description = "cactus-2";
+	ffa-version = <0x00010000>; /* 31:16 - Major, 15:0 - Minor */
+	uuid = <0xd1582309 0xf02347b9 0x827c4464 0xf5578fc8>;
+	id = <2>;
+	execution-ctx-count = <4>;
+	exception-level = <2>; /* S-EL1 */
+	execution-state = <0>; /* AARCH64 */
+	load-address = <0xfe100000>;
+	entrypoint-offset = <0x00001000>;
+	xlat-granule = <0>; /* 4KiB */
+	boot-order = <0>;
+	messaging-method = <0>; /* Direct messaging only */
+	run-time-model = <1>; /* Run to completion */
+
+	/* Boot protocol */
+	gp-register-num = <0x0>;
+
+	rx_tx-info {
+		compatible = "arm,ffa-manifest-rx_tx-buffer";
+		rx-buffer = <&rxbuffer>;
+		tx-buffer = <&txbuffer>;
+	};
+
+	memory-regions {
+		compatible = "arm,ffa-manifest-memory-regions";
+
+		rxbuffer: rx-buffer {
+			description = "rx-buffer";
+			pages-count = <1>;
+			base-address = <0x00000000 0xfe302000>;
+			attributes = <0x1>; /* read-only */
+		};
+
+		txbuffer: tx-buffer {
+			description = "tx-buffer";
+			pages-count = <1>;
+			base-address = <0x00000000 0xfe303000>;
+			attributes = <0x3>; /* read-write */
+		};
+	};
+};
diff --git a/spm/cactus/plat/arm/tc0/fdts/cactus-tertiary.dts b/spm/cactus/plat/arm/tc0/fdts/cactus-tertiary.dts
new file mode 100644
index 0000000..8567e06
--- /dev/null
+++ b/spm/cactus/plat/arm/tc0/fdts/cactus-tertiary.dts
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2020, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * This file is a Partition Manifest (PM) for a minimal Secure Partition (SP)
+ * that has additional optional properties defined.
+ *
+ */
+
+/dts-v1/;
+
+/ {
+	compatible = "arm,ffa-manifest-1.0";
+
+	/* Properties */
+	description = "cactus-3";
+	ffa-version = <0x00010000>; /* 31:16 - Major, 15:0 - Minor */
+	uuid = <0x79b55c73 0x1d8c44b9 0x859361e1 0x770ad8d2>;
+	id = <3>;
+	execution-ctx-count = <4>;
+	exception-level = <2>; /* S-EL1 */
+	execution-state = <0>; /* AARCH64 */
+	load-address = <0xfe200000>;
+	entrypoint-offset = <0x00001000>;
+	xlat-granule = <0>; /* 4KiB */
+	boot-order = <0>;
+	messaging-method = <0>; /* Direct messaging only */
+	run-time-model = <1>; /* Run to completion */
+
+	/* Boot protocol */
+	gp-register-num = <0x0>;
+
+	memory-regions {
+		compatible = "arm,ffa-manifest-memory-regions";
+
+		/* Without optional base-address */
+		test-memory {
+			description = "test-memory";
+			pages-count = <4>;
+			attributes = <0x7>; /* read-write-execute */
+		};
+	};
+
+	device-regions {
+		compatible = "arm,ffa-manifest-device-regions";
+
+		test-reg {
+			/* Dummy values */
+			base-address = <0x00000000 0x25000000>;
+			pages-count = <16>;
+			attributes = <0x3>; /* read-write */
+			reg = <0x10000008 0x00000001 1>;
+			smmu-id = <1>;
+			stream-ids = <0x0 0x1>;
+			interrupts = <0x2 0x3>,
+					<0x4 0x5>;
+		};
+	};
+
+};
diff --git a/spm/cactus/plat/arm/tc0/fdts/cactus.dts b/spm/cactus/plat/arm/tc0/fdts/cactus.dts
new file mode 100644
index 0000000..4b27959
--- /dev/null
+++ b/spm/cactus/plat/arm/tc0/fdts/cactus.dts
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2020, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * This file is a Partition Manifest (PM) for a minimal Secure Partition (SP)
+ * that has additional optional properties defined.
+ *
+ */
+
+/dts-v1/;
+
+/ {
+	compatible = "arm,ffa-manifest-1.0";
+
+	/* Properties */
+	description = "cactus-1";
+	ffa-version = <0x00010000>; /* 31:16 - Major, 15:0 - Minor */
+	uuid = <0xb4b5671e 0x4a904fe1 0xb81ffb13 0xdae1dacb>;
+	id = <1>;
+	execution-ctx-count = <4>;
+	exception-level = <2>; /* S-EL1 */
+	execution-state = <0>; /* AARCH64 */
+	load-address = <0xfe000000>;
+	entrypoint-offset = <0x00001000>;
+	xlat-granule = <0>; /* 4KiB */
+	boot-order = <0>;
+	messaging-method = <0>; /* Direct messaging only */
+	run-time-model = <1>; /* Run to completion */
+
+	/* Boot protocol */
+	gp-register-num = <0x0>;
+
+	rx_tx-info {
+		compatible = "arm,ffa-manifest-rx_tx-buffer";
+		rx-buffer = <&rxbuffer>;
+		tx-buffer = <&txbuffer>;
+	};
+
+	memory-regions {
+		compatible = "arm,ffa-manifest-memory-regions";
+
+		rxbuffer: rx-buffer {
+			description = "rx-buffer";
+			pages-count = <1>;
+			base-address = <0x00000000 0xfe300000>;
+			attributes = <0x1>; /* read-only */
+		};
+
+		txbuffer: tx-buffer {
+			description = "tx-buffer";
+			pages-count = <1>;
+			base-address = <0x00000000 0xfe301000>;
+			attributes = <0x3>; /* read-write */
+		};
+	};
+};
diff --git a/spm/cactus/plat/arm/tc0/include/cactus_platform_def.h b/spm/cactus/plat/arm/tc0/include/cactus_platform_def.h
new file mode 100644
index 0000000..ae4d4e8
--- /dev/null
+++ b/spm/cactus/plat/arm/tc0/include/cactus_platform_def.h
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2020, 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		TC0_DEVICE0_BASE
+#define PLAT_ARM_DEVICE0_SIZE		TC0_DEVICE0_SIZE
+
+#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 CACTUS_PRIMARY_EC_COUNT		(4U)
+#define CACTUS_SECONDARY_EC_COUNT	(4U)
+#define CACTUS_TERTIARY_EC_COUNT	(4U)
+
+#endif /* CACTUS_PLATFORM_DEF_H */
diff --git a/spm/cactus/plat/arm/tc0/platform.mk b/spm/cactus/plat/arm/tc0/platform.mk
new file mode 100644
index 0000000..3bc245e
--- /dev/null
+++ b/spm/cactus/plat/arm/tc0/platform.mk
@@ -0,0 +1,17 @@
+#
+# Copyright (c) 2020, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+TC0_CACTUS_BASE		= spm/cactus/plat/arm/tc0
+
+PLAT_INCLUDES		+= -I${TC0_CACTUS_BASE}/include/
+
+# Add the FDT source
+CACTUS_DTS		= ${TC0_CACTUS_BASE}/fdts/cactus.dts
+
+# List of FDTS to copy
+FDTS_CP_LIST		= ${TC0_CACTUS_BASE}/fdts/cactus.dts
+FDTS_CP_LIST		+= ${TC0_CACTUS_BASE}/fdts/cactus-secondary.dts
+FDTS_CP_LIST		+= ${TC0_CACTUS_BASE}/fdts/cactus-tertiary.dts