Trusted Firmware-A Tests, version 2.0

This is the first public version of the tests for the Trusted
Firmware-A project. Please see the documentation provided in the
source tree for more details.

Change-Id: I6f3452046a1351ac94a71b3525c30a4ca8db7867
Signed-off-by: Sandrine Bailleux <sandrine.bailleux@arm.com>
Co-authored-by: amobal01 <amol.balasokamble@arm.com>
Co-authored-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
Co-authored-by: Asha R <asha.r@arm.com>
Co-authored-by: Chandni Cherukuri <chandni.cherukuri@arm.com>
Co-authored-by: David Cunado <david.cunado@arm.com>
Co-authored-by: Dimitris Papastamos <dimitris.papastamos@arm.com>
Co-authored-by: Douglas Raillard <douglas.raillard@arm.com>
Co-authored-by: dp-arm <dimitris.papastamos@arm.com>
Co-authored-by: Jeenu Viswambharan <jeenu.viswambharan@arm.com>
Co-authored-by: Jonathan Wright <jonathan.wright@arm.com>
Co-authored-by: Kévin Petit <kevin.petit@arm.com>
Co-authored-by: Roberto Vargas <roberto.vargas@arm.com>
Co-authored-by: Sathees Balya <sathees.balya@arm.com>
Co-authored-by: Shawon Roy <Shawon.Roy@arm.com>
Co-authored-by: Soby Mathew <soby.mathew@arm.com>
Co-authored-by: Thomas Abraham <thomas.abraham@arm.com>
Co-authored-by: Vikram Kanigiri <vikram.kanigiri@arm.com>
Co-authored-by: Yatharth Kochar <yatharth.kochar@arm.com>
diff --git a/include/runtime_services/arm_arch_svc.h b/include/runtime_services/arm_arch_svc.h
new file mode 100644
index 0000000..12358f8
--- /dev/null
+++ b/include/runtime_services/arm_arch_svc.h
@@ -0,0 +1,15 @@
+/*
+ * Copyright (c) 2018, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef __ARM_ARCH_SVC_H__
+#define __ARM_ARCH_SVC_H__
+
+#define SMCCC_VERSION		0x80000000
+#define SMCCC_ARCH_FEATURES	0x80000001
+#define SMCCC_ARCH_WORKAROUND_1	0x80008000
+#define SMCCC_ARCH_WORKAROUND_2	0x80007FFF
+
+#endif /* __ARM_ARCH_SVC_H__ */
diff --git a/include/runtime_services/pmf.h b/include/runtime_services/pmf.h
new file mode 100644
index 0000000..04f79c1
--- /dev/null
+++ b/include/runtime_services/pmf.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2018, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef __PMF_H__
+#define __PMF_H__
+
+#ifndef __ASSEMBLY__
+#include <assert.h>
+#include <platform_def.h>
+#include <stdbool.h>
+#include <stdint.h>
+#endif
+
+/*
+ * Constants used for/by PMF services.
+ */
+#define PMF_ARM_TIF_IMPL_ID	0x41
+#define PMF_TID_SHIFT		0
+#define PMF_TID_MASK		(0xFF << PMF_TID_SHIFT)
+#define PMF_SVC_ID_SHIFT	10
+#define PMF_SVC_ID_MASK		(0x3F << PMF_SVC_ID_SHIFT)
+#define PMF_IMPL_ID_SHIFT	24
+#define PMF_IMPL_ID_MASK	(0xFFU << PMF_IMPL_ID_SHIFT)
+
+/*
+ * Flags passed to PMF_GET_TIMESTAMP_XXX and PMF_CAPTURE_TIMESTAMP
+ */
+#define PMF_CACHE_MAINT		(1 << 0)
+#define PMF_NO_CACHE_MAINT	0
+
+/*
+ * Defines for PMF SMC function ids.
+ */
+#ifdef AARCH32
+#define PMF_SMC_GET_TIMESTAMP	0x82000010
+#else
+#define PMF_SMC_GET_TIMESTAMP	0xC2000010
+#endif
+
+#define PMF_NUM_SMC_CALLS		2
+
+/* Following are the supported PMF service IDs */
+#define PMF_PSCI_STAT_SVC_ID	0
+#define PMF_RT_INSTR_SVC_ID	1
+
+#endif /* __PMF_H__ */
diff --git a/include/runtime_services/psci.h b/include/runtime_services/psci.h
new file mode 100644
index 0000000..1ecfc63
--- /dev/null
+++ b/include/runtime_services/psci.h
@@ -0,0 +1,224 @@
+/*
+ * Copyright (c) 2018, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+/*
+ * Definitions related to the Power State Coordination Interface (PSCI)
+ * as per the SMC Calling Convention.
+ *
+ * PSCI calls are a subset of the Standard Service Calls.
+ */
+
+#ifndef __PSCI_H__
+#define __PSCI_H__
+
+#ifndef __ASSEMBLY__
+#include <assert.h>
+#include <platform_def.h>
+#include <stdbool.h>
+#include <stdint.h>
+#endif
+
+/*******************************************************************************
+ * Macro to create the array entry for psci_functions[]
+ ******************************************************************************/
+#define DEFINE_PSCI_FUNC(_func_id, _mandatory) \
+	{ SMC_##_func_id, _mandatory, "SMC_" # _func_id }
+
+/*******************************************************************************
+ * Defines for runtime services function ids
+ ******************************************************************************/
+#define SMC_PSCI_VERSION			0x84000000
+#define SMC_PSCI_CPU_SUSPEND_AARCH32		0x84000001
+#define SMC_PSCI_CPU_SUSPEND_AARCH64		0xc4000001
+#define SMC_PSCI_CPU_OFF			0x84000002
+#define SMC_PSCI_CPU_ON_AARCH32			0x84000003
+#define SMC_PSCI_CPU_ON_AARCH64			0xc4000003
+#define SMC_PSCI_AFFINITY_INFO_AARCH32		0x84000004
+#define SMC_PSCI_AFFINITY_INFO_AARCH64		0xc4000004
+#define SMC_PSCI_MIG_AARCH32			0x84000005
+#define SMC_PSCI_MIG_AARCH64			0xc4000005
+#define SMC_PSCI_MIG_INFO_TYPE			0x84000006
+#define SMC_PSCI_MIG_INFO_UP_CPU_AARCH32	0x84000007
+#define SMC_PSCI_MIG_INFO_UP_CPU_AARCH64	0xc4000007
+#define SMC_PSCI_SYSTEM_OFF			0x84000008
+#define SMC_PSCI_SYSTEM_RESET			0x84000009
+#define SMC_PSCI_FEATURES			0x8400000a
+#define SMC_PSCI_CPU_FREEZE			0x8400000b
+#define SMC_PSCI_CPU_DEFAULT_SUSPEND32		0x8400000c
+#define SMC_PSCI_CPU_DEFAULT_SUSPEND64		0xc400000c
+#define SMC_PSCI_CPU_HW_STATE32			0x8400000d
+#define SMC_PSCI_CPU_HW_STATE64			0xc400000d
+#define SMC_PSCI_SYSTEM_SUSPEND32		0x8400000e
+#define SMC_PSCI_SYSTEM_SUSPEND64		0xc400000e
+#define SMC_PSCI_SET_SUSPEND_MODE		0x8400000f
+#define SMC_PSCI_STAT_RESIDENCY32		0x84000010
+#define SMC_PSCI_STAT_RESIDENCY64		0xc4000010
+#define SMC_PSCI_STAT_COUNT32			0x84000011
+#define SMC_PSCI_STAT_COUNT64			0xc4000011
+#define SMC_PSCI_RESET2_AARCH32			0x84000012
+#define SMC_PSCI_RESET2_AARCH64			0xc4000012
+#define SMC_PSCI_MEM_PROTECT			0x84000013
+#define SMC_PSCI_MEM_PROTECT_CHECK_RANGE32	0x84000014
+#define SMC_PSCI_MEM_PROTECT_CHECK_RANGE64	0xc4000014
+
+/*
+ * Architecture-specific SMC function IDs
+ */
+#ifndef AARCH32
+#define SMC_PSCI_CPU_SUSPEND		SMC_PSCI_CPU_SUSPEND_AARCH64
+#define SMC_PSCI_CPU_ON			SMC_PSCI_CPU_ON_AARCH64
+#define SMC_PSCI_AFFINITY_INFO		SMC_PSCI_AFFINITY_INFO_AARCH64
+#define SMC_PSCI_MIG			SMC_PSCI_MIG_AARCH64
+#define SMC_PSCI_MIG_INFO_UP_CPU	SMC_PSCI_MIG_INFO_UP_CPU_AARCH64
+#define SMC_PSCI_CPU_DEFAULT_SUSPEND	SMC_PSCI_CPU_DEFAULT_SUSPEND64
+#define SMC_PSCI_CPU_HW_STATE		SMC_PSCI_CPU_HW_STATE64
+#define SMC_PSCI_SYSTEM_SUSPEND		SMC_PSCI_SYSTEM_SUSPEND64
+#define SMC_PSCI_STAT_RESIDENCY		SMC_PSCI_STAT_RESIDENCY64
+#define SMC_PSCI_STAT_COUNT		SMC_PSCI_STAT_COUNT64
+#define SMC_PSCI_RESET2			SMC_PSCI_RESET2_AARCH64
+#define SMC_PSCI_MEM_PROTECT_CHECK	SMC_PSCI_MEM_PROTECT_CHECK_RANGE64
+#else
+#define SMC_PSCI_CPU_SUSPEND		SMC_PSCI_CPU_SUSPEND_AARCH32
+#define SMC_PSCI_CPU_ON			SMC_PSCI_CPU_ON_AARCH32
+#define SMC_PSCI_AFFINITY_INFO		SMC_PSCI_AFFINITY_INFO_AARCH32
+#define SMC_PSCI_MIG			SMC_PSCI_MIG_AARCH32
+#define SMC_PSCI_MIG_INFO_UP_CPU	SMC_PSCI_MIG_INFO_UP_CPU_AARCH32
+#define SMC_PSCI_CPU_DEFAULT_SUSPEND	SMC_PSCI_CPU_DEFAULT_SUSPEND32
+#define SMC_PSCI_CPU_HW_STATE		SMC_PSCI_CPU_HW_STATE32
+#define SMC_PSCI_SYSTEM_SUSPEND		SMC_PSCI_SYSTEM_SUSPEND32
+#define SMC_PSCI_STAT_RESIDENCY		SMC_PSCI_STAT_RESIDENCY32
+#define SMC_PSCI_STAT_COUNT		SMC_PSCI_STAT_COUNT32
+#define SMC_PSCI_RESET2			SMC_PSCI_RESET2_AARCH32
+#define SMC_PSCI_MEM_PROTECT_CHECK	SMC_PSCI_MEM_PROTECT_CHECK_RANGE32
+#endif
+
+/*
+ * Number of PSCI calls defined in the PSCI specification.
+ */
+#define PSCI_NUM_CALLS				33
+
+#ifndef __ASSEMBLY__
+typedef struct {
+	uint32_t	id;
+	bool		mandatory;
+	const char	*str;
+} psci_function_t;
+
+extern const psci_function_t psci_functions[PSCI_NUM_CALLS];
+#endif /* __ASSEMBLY__ */
+
+/*******************************************************************************
+ * PSCI Migrate specific defines
+ ******************************************************************************/
+#define PSCI_TOS_UP_MIG_CAP	0
+#define PSCI_TOS_NOT_UP_MIG_CAP	1
+#define PSCI_TOS_NOT_PRESENT_MP	2
+
+/*******************************************************************************
+ * PSCI CPU_SUSPEND 'power_state' parameter specific defines
+ ******************************************************************************/
+/* Original format */
+#define PSTATE_ID_SHIFT		0
+#define PSTATE_TYPE_SHIFT	16
+#define PSTATE_AFF_LVL_SHIFT	24
+#define PSTATE_ID_MASK		0xFFFF
+#define PSTATE_AFF_LVL_MASK	0x3
+
+#define psci_state_id_valid(state_id)			\
+	(((state_id) & ~PSTATE_ID_MASK) == 0)
+
+#define psci_affinity_level_valid(aff_level)		\
+	(((aff_level) & ~PSTATE_AFF_LVL_MASK) == 0)
+
+/* Extended format */
+#define PSTATE_ID_SHIFT_EXT	0
+#define PSTATE_TYPE_SHIFT_EXT	30
+#define PSTATE_ID_MASK_EXT	0xFFFFFFF
+
+#define psci_state_id_ext_valid(state_id)		\
+	(((state_id) & ~PSTATE_ID_MASK_EXT) == 0)
+
+/* Definitions common to original and extended StateID formats */
+#define PSTATE_TYPE_MASK	0x1
+
+#define PSTATE_TYPE_STANDBY	0x0
+#define PSTATE_TYPE_POWERDOWN	0x1
+
+#define PSTATE_AFF_LVL_0	0
+#define PSTATE_AFF_LVL_1	1
+#define PSTATE_AFF_LVL_2	2
+#define PSTATE_AFF_LVL_3	3
+
+#define psci_state_type_valid(state_type)		\
+	(((state_type) & ~PSTATE_TYPE_MASK) == 0)
+
+/*******************************************************************************
+ * PSCI 'Feature Flags' defines for CPU_SUSPEND
+ ******************************************************************************/
+#define CPU_SUSPEND_FEAT_OS_INIT_MODE_SHIFT	0
+#define CPU_SUSPEND_FEAT_PSTATE_FORMAT_SHIFT	1
+#define CPU_SUSPEND_FEAT_PSTATE_FORMAT_ORIGINAL	0
+#define CPU_SUSPEND_FEAT_PSTATE_FORMAT_EXTENDED	1
+
+#define CPU_SUSPEND_FEAT_VALID_MASK			\
+	((1 << CPU_SUSPEND_FEAT_OS_INIT_MODE_SHIFT) |	\
+	 (1 << CPU_SUSPEND_FEAT_PSTATE_FORMAT_SHIFT))
+
+/*******************************************************************************
+ * PSCI 'Feature Flags' defines for functions other than CPU_SUSPEND
+ ******************************************************************************/
+#define PSCI_FEATURE_FLAGS_ZERO			0
+
+#ifndef __ASSEMBLY__
+
+/*
+ * Construct the local State-ID for a particular level according to
+ * the platform specific local state-ID width.
+ */
+#define psci_make_local_state_id(level, local_state) \
+		(((local_state) & ((1 << PLAT_LOCAL_PSTATE_WIDTH) - 1)) \
+			<< (PLAT_LOCAL_PSTATE_WIDTH * (level)))
+#endif
+
+/*******************************************************************************
+ * PSCI version
+ ******************************************************************************/
+#define PSCI_MAJOR_VER		1
+#define PSCI_MINOR_VER		1
+#define PSCI_MAJOR_VER_SHIFT	16
+#define PSCI_MAJOR_VER_MASK	0xFFFF0000
+#define PSCI_VERSION(major, minor)	((major << PSCI_MAJOR_VER_SHIFT) \
+					| minor)
+
+/*******************************************************************************
+ * PSCI error codes
+ ******************************************************************************/
+#define PSCI_E_SUCCESS		0
+#define PSCI_E_NOT_SUPPORTED	-1
+#define PSCI_E_INVALID_PARAMS	-2
+#define PSCI_E_DENIED		-3
+#define PSCI_E_ALREADY_ON	-4
+#define PSCI_E_ON_PENDING	-5
+#define PSCI_E_INTERN_FAIL	-6
+#define PSCI_E_NOT_PRESENT	-7
+#define PSCI_E_DISABLED		-8
+#define PSCI_E_INVALID_ADDRESS	-9
+
+/*******************************************************************************
+ * PSCI affinity state related constants.
+ ******************************************************************************/
+#define PSCI_STATE_ON		0x0
+#define PSCI_STATE_OFF		0x1
+#define PSCI_STATE_ON_PENDING	0x2
+
+/*******************************************************************************
+ * PSCI node hardware state related constants.
+ ******************************************************************************/
+#define PSCI_HW_STATE_ON	0x0
+#define PSCI_HW_STATE_OFF	0x1
+#define PSCI_HW_STATE_STANDBY	0x2
+
+#endif /* __PSCI_H__ */
diff --git a/include/runtime_services/sdei.h b/include/runtime_services/sdei.h
new file mode 100644
index 0000000..0e0a249
--- /dev/null
+++ b/include/runtime_services/sdei.h
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2018, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef __SDEI_H__
+#define __SDEI_H__
+
+#define SDEI_VERSION				0xC4000020
+#define SDEI_EVENT_REGISTER			0xC4000021
+#define SDEI_EVENT_ENABLE			0xC4000022
+#define SDEI_EVENT_DISABLE			0xC4000023
+#define SDEI_EVENT_CONTEXT			0xC4000024
+#define SDEI_EVENT_COMPLETE			0xC4000025
+#define SDEI_EVENT_COMPLETE_AND_RESUME		0xC4000026
+
+#define SDEI_EVENT_UNREGISTER			0xC4000027
+#define SDEI_EVENT_STATUS			0xC4000028
+#define SDEI_EVENT_GET_INFO			0xC4000029
+#define SDEI_EVENT_ROUTING_SET			0xC400002A
+#define SDEI_PE_MASK				0xC400002B
+#define SDEI_PE_UNMASK				0xC400002C
+
+#define SDEI_INTERRUPT_BIND			0xC400002D
+#define SDEI_INTERRUPT_RELEASE			0xC400002E
+#define SDEI_EVENT_SIGNAL			0xC400002F
+#define SDEI_FEATURES				0xC4000030
+#define SDEI_PRIVATE_RESET			0xC4000031
+#define SDEI_SHARED_RESET			0xC4000032
+
+/* For debug */
+#define SDEI_SHOW_DEBUG				0xC400003F
+
+/* SDEI_EVENT_REGISTER flags */
+#define SDEI_REGF_RM_ANY	0
+#define SDEI_REGF_RM_PE		1
+
+/* SDEI_EVENT_COMPLETE status flags */
+#define SDEI_EV_HANDLED		0
+#define SDEI_EV_FAILED		1
+
+/* sde event status values in bit position */
+#define SDEI_STATF_REGISTERED		0
+#define SDEI_STATF_ENABLED		1
+#define SDEI_STATF_RUNNING		2
+
+#define SDEI_INFOF_TYPE			0
+#define SDEI_INFOF_SIGNALABLE		1
+#define SDEI_INFOF_ROUTING_MODE		2
+#define SDEI_INFOF_ROUTING_AFF		3
+
+#define	SMC_EINVAL	2
+#define	SMC_EDENY	3
+#define	SMC_EPEND	5
+#define	SMC_ENOMEM	10
+
+#define MAKE_SDEI_VERSION(_major, _minor, _vendor) \
+	(((uint64_t)(_major)) << 48 | \
+	((uint64_t)(_minor)) << 32 | \
+	(_vendor))
+
+#ifndef __ASSEMBLY__
+#include <stdint.h>
+
+struct sdei_intr_ctx {
+	unsigned int priority;
+	unsigned int num;
+	unsigned int enabled;
+};
+
+typedef int sdei_handler_t(int ev, uint64_t arg);
+
+void sdei_trigger_event(void);
+void sdei_handler_done(void);
+
+int64_t sdei_version(void);
+int64_t sdei_interrupt_bind(int intr, struct sdei_intr_ctx *intr_ctx);
+int64_t sdei_interrupt_release(int intr, const struct sdei_intr_ctx *intr_ctx);
+int64_t sdei_event_register(int ev, sdei_handler_t *ep,
+	uint64_t ep_arg, int flags, uint64_t mpidr);
+int64_t sdei_event_unregister(int ev);
+int64_t sdei_event_enable(int ev);
+int64_t sdei_event_disable(int ev);
+int64_t sdei_pe_mask(void);
+int64_t sdei_pe_unmask(void);
+int64_t sdei_private_reset(void);
+int64_t sdei_shared_reset(void);
+int64_t sdei_event_signal(uint64_t mpidr);
+int64_t sdei_event_status(int32_t ev);
+int64_t sdei_event_routing_set(int32_t ev, uint64_t flags);
+int64_t sdei_event_context(uint32_t param);
+int64_t sdei_event_complete(uint32_t flags);
+int64_t sdei_event_complete_and_resume(uint64_t addr);
+#endif /* __ASSEMBLY__ */
+
+#endif /* __SDEI_H__ */
diff --git a/include/runtime_services/secure_el0_payloads/mm_svc.h b/include/runtime_services/secure_el0_payloads/mm_svc.h
new file mode 100644
index 0000000..290fd7d
--- /dev/null
+++ b/include/runtime_services/secure_el0_payloads/mm_svc.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2017, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef __MM_SVC_H__
+#define __MM_SVC_H__
+
+#include <utils_def.h>
+
+#define MM_VERSION_MAJOR	U(1)
+#define MM_VERSION_MAJOR_SHIFT	16
+#define MM_VERSION_MAJOR_MASK	U(0x7FFF)
+#define MM_VERSION_MINOR	U(0)
+#define MM_VERSION_MINOR_SHIFT	0
+#define MM_VERSION_MINOR_MASK	U(0xFFFF)
+#define MM_VERSION_FORM(major, minor)	((major << MM_VERSION_MAJOR_SHIFT) | (minor))
+#define MM_VERSION_COMPILED	MM_VERSION_FORM(MM_VERSION_MAJOR, MM_VERSION_MINOR)
+
+/*
+ * SMC IDs defined in [1] for accessing MM services from the Non-secure world.
+ * These FIDs occupy the range 0x40 - 0x5f.
+ * [1] DEN0060A_ARM_MM_Interface_Specification.pdf
+ */
+#define MM_VERSION_AARCH32		U(0x84000040)
+
+#define MM_COMMUNICATE_AARCH64		U(0xC4000041)
+#define MM_COMMUNICATE_AARCH32		U(0x84000041)
+
+#endif /* __MM_SVC_H__ */
diff --git a/include/runtime_services/secure_el0_payloads/secure_partition.h b/include/runtime_services/secure_el0_payloads/secure_partition.h
new file mode 100644
index 0000000..4ee466c
--- /dev/null
+++ b/include/runtime_services/secure_el0_payloads/secure_partition.h
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 2018, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef __SECURE_PARTITION_H__
+#define __SECURE_PARTITION_H__
+
+#ifndef __ASSEMBLY__
+#include <cassert.h>
+#include <param_header.h>
+#include <types.h>
+#endif
+#include <utils_def.h>
+
+/*
+ * Definitions used to access the members of secure_partition_boot_info from
+ * assembly code.
+ */
+#define SP_BOOT_INFO_STACK_BASE_OFFSET		U(32)
+#define SP_BOOT_INFO_IMAGE_SIZE_OFFSET		U(64)
+#define SP_BOOT_INFO_PCPU_STACK_SIZE_OFFSET	U(72)
+
+#ifndef __ASSEMBLY__
+
+/*
+ * Flags used by the secure_partition_mp_info structure to describe the
+ * characteristics of a cpu. Only a single flag is defined at the moment to
+ * indicate the primary cpu.
+ */
+#define MP_INFO_FLAG_PRIMARY_CPU	U(0x00000001)
+
+/*
+ * This structure is used to provide information required to initialise a S-EL0
+ * partition.
+ */
+typedef struct secure_partition_mp_info {
+	uint64_t		mpidr;
+	uint32_t		linear_id;
+	uint32_t		flags;
+} secure_partition_mp_info_t;
+
+typedef struct secure_partition_boot_info {
+	param_header_t		h;
+	uint64_t		sp_mem_base;
+	uint64_t		sp_mem_limit;
+	uint64_t		sp_image_base;
+	uint64_t		sp_stack_base;
+	uint64_t		sp_heap_base;
+	uint64_t		sp_ns_comm_buf_base;
+	uint64_t		sp_shared_buf_base;
+	uint64_t		sp_image_size;
+	uint64_t		sp_pcpu_stack_size;
+	uint64_t		sp_heap_size;
+	uint64_t		sp_ns_comm_buf_size;
+	uint64_t		sp_shared_buf_size;
+	uint32_t		num_sp_mem_regions;
+	uint32_t		num_cpus;
+	secure_partition_mp_info_t *mp_info;
+} secure_partition_boot_info_t;
+
+/*
+ * This structure is used to pass data associated to secure service requests.
+ */
+#define SPS_MAX_PAYLOAD_SIZE	32
+typedef struct secure_partition_request_info {
+	uint32_t		id;
+	uint64_t		data_size;
+	uint8_t			data[SPS_MAX_PAYLOAD_SIZE];
+} secure_partition_request_info_t;
+
+/* Define some fast secure partition requests (SPS) IDs. */
+#define SPS_TIMER_SLEEP			1
+#define SPS_CHECK_ALIVE			2
+
+#define CACTUS_FAST_REQUEST_SUCCESS	0xCACF900D
+
+secure_partition_request_info_t *create_sps_request(uint32_t id,
+						    const void *data,
+						    uint64_t data_size);
+
+/*
+ * Compile time assertions related to the 'secure_partition_boot_info' structure
+ * to ensure that the assembler and the compiler view of the offsets of the
+ * structure members is the same.
+ */
+CASSERT(SP_BOOT_INFO_STACK_BASE_OFFSET ==
+	__builtin_offsetof(secure_partition_boot_info_t, sp_stack_base), \
+	assert_secure_partition_boot_info_sp_stack_base_offset_mismatch);
+
+CASSERT(SP_BOOT_INFO_IMAGE_SIZE_OFFSET ==
+	__builtin_offsetof(secure_partition_boot_info_t, sp_image_size), \
+	assert_secure_partition_boot_info_sp_image_size_offset_mismatch);
+
+CASSERT(SP_BOOT_INFO_PCPU_STACK_SIZE_OFFSET ==
+	__builtin_offsetof(secure_partition_boot_info_t, sp_pcpu_stack_size), \
+	assert_secure_partition_boot_info_sp_pcpu_stack_size_offset_mismatch);
+
+#endif /* __ASSEMBLY__ */
+
+#endif /* __SECURE_PARTITION_H__ */
diff --git a/include/runtime_services/secure_el0_payloads/spm_svc.h b/include/runtime_services/secure_el0_payloads/spm_svc.h
new file mode 100644
index 0000000..e3b6cc5
--- /dev/null
+++ b/include/runtime_services/secure_el0_payloads/spm_svc.h
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2017, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef __SPM_SVC_H__
+#define __SPM_SVC_H__
+
+#include <utils_def.h>
+
+#define SPM_VERSION_MAJOR	U(0)
+#define SPM_VERSION_MAJOR_SHIFT	16
+#define SPM_VERSION_MAJOR_MASK	U(0x7FFF)
+#define SPM_VERSION_MINOR	U(1)
+#define SPM_VERSION_MINOR_SHIFT	0
+#define SPM_VERSION_MINOR_MASK	U(0xFFFF)
+#define SPM_VERSION_FORM(major, minor)	((major << SPM_VERSION_MAJOR_SHIFT) | (minor))
+#define SPM_VERSION_COMPILED	SPM_VERSION_FORM(SPM_VERSION_MAJOR, SPM_VERSION_MINOR)
+
+/* The macros below are used to identify SPM calls from the SMC function ID */
+#define SPM_FID_MASK			U(0xffff)
+#define SPM_FID_MIN_VALUE		U(0x40)
+#define SPM_FID_MAX_VALUE		U(0xbf)
+#define is_spm_fid(_fid)						\
+		((((_fid) & SPM_FID_MASK) >= SPM_FID_MIN_VALUE) &&	\
+		 (((_fid) & SPM_FID_MASK) <= SPM_FID_MAX_VALUE))
+
+/*
+ * SMC IDs defined for accessing services implemented by the Secure Partition
+ * Manager from the Secure Partition(s). These services enable a partition to
+ * handle delegated events and request privileged operations from the manager.
+ * They occupy the range 0x60-0x7f.
+ */
+#define SPM_VERSION_AARCH32			U(0x84000060)
+#define SP_EVENT_COMPLETE_AARCH64		U(0xC4000061)
+#define SP_MEMORY_ATTRIBUTES_GET_AARCH64	U(0xC4000064)
+#define SP_MEMORY_ATTRIBUTES_SET_AARCH64	U(0xC4000065)
+
+/*
+ * Macros used by SP_MEMORY_ATTRIBUTES_SET_AARCH64.
+ */
+
+#define SP_MEMORY_ATTRIBUTES_ACCESS_NOACCESS	U(0)
+#define SP_MEMORY_ATTRIBUTES_ACCESS_RW		U(1)
+/* Value U(2) is reserved. */
+#define SP_MEMORY_ATTRIBUTES_ACCESS_RO		U(3)
+#define SP_MEMORY_ATTRIBUTES_ACCESS_MASK	U(3)
+#define SP_MEMORY_ATTRIBUTES_ACCESS_SHIFT	0
+
+#define SP_MEMORY_ATTRIBUTES_EXEC		(U(0) << 2)
+#define SP_MEMORY_ATTRIBUTES_NON_EXEC		(U(1) << 2)
+
+/* SPM error codes. */
+#define SPM_SUCCESS		0
+#define SPM_NOT_SUPPORTED	-1
+#define SPM_INVALID_PARAMETER	-2
+#define SPM_DENIED		-3
+#define SPM_NO_MEMORY		-5
+#define SPM_NOT_PRESENT		-7
+
+
+#endif /* __SPM_SVC_H__ */
diff --git a/include/runtime_services/secure_el1_payloads/tsp.h b/include/runtime_services/secure_el1_payloads/tsp.h
new file mode 100644
index 0000000..6a4a3d6
--- /dev/null
+++ b/include/runtime_services/secure_el1_payloads/tsp.h
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2018, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+/*
+ * This header file contains definitions related to the Trusted Firmware-A
+ * Test Secure-EL1 Payload (TSP).
+ */
+
+#ifndef __TSP_H__
+#define __TSP_H__
+
+#include <psci.h>
+#include <uuid.h>
+
+static const uuid_t tsp_uuid = {
+	0x5b3056a0, 0x3291, 0x427b, 0x98, 0x11,
+	{ 0x71, 0x68, 0xca, 0x50, 0xf3, 0xfa }
+};
+
+/*
+ * Identifiers for various TSP services. Corresponding function IDs (whether
+ * fast or standard) are generated by macros defined below
+ */
+#define TSP_ADD		0x2000
+#define TSP_SUB		0x2001
+#define TSP_MUL		0x2002
+#define TSP_DIV		0x2003
+#define TSP_HANDLE_SEL1_INTR_AND_RETURN	0x2004
+
+/*
+ * Identify a TSP service from function ID filtering the last 16 bits from the
+ * SMC function ID
+ */
+#define TSP_BARE_FID(fid)	((fid) & 0xffff)
+/*
+ * Generate function IDs for TSP services to be used in SMC calls, by
+ * appropriately setting bit 31 to differentiate standard and fast SMC calls
+ */
+#define TSP_STD_FID(fid)	((TSP_BARE_FID(fid) | 0x72000000))
+#define TSP_FAST_FID(fid)	((TSP_BARE_FID(fid) | 0x72000000) | (1u << 31))
+
+/* SMC function ID to request a previously preempted std smc */
+#define TSP_FID_RESUME		TSP_STD_FID(0x3000)
+/*
+ * SMC function ID to request abortion of a previously preempted std smc. A
+ * fast SMC is used so that the TSP abort handler does not have to be
+ * reentrant.
+ */
+#define TSP_FID_ABORT		TSP_FAST_FID(0x3001)
+
+#define TSP_SMC_PREEMPTED	-2
+
+/*
+ * Total number of function IDs implemented for services offered to NS clients.
+ * The function IDs are defined above
+ */
+#define TSP_NUM_FID		0x5
+
+/* TSP implementation revision numbers */
+#define TSP_REVISION_MAJOR	0x0
+#define TSP_REVISION_MINOR	0x1
+
+/* TSP is multiprocessor capable so does not require migration */
+#define TSP_MIGRATE_INFO	PSCI_TOS_NOT_PRESENT_MP
+
+#endif /* __TSP_H__ */
diff --git a/include/runtime_services/smccc.h b/include/runtime_services/smccc.h
new file mode 100644
index 0000000..c8bc1b9
--- /dev/null
+++ b/include/runtime_services/smccc.h
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2018, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef __SMCCC_H__
+#define __SMCCC_H__
+
+#include <utils_def.h>
+
+#define SMCCC_VERSION_MAJOR_SHIFT	U(16)
+#define SMCCC_VERSION_MAJOR_MASK	U(0x7FFF)
+#define SMCCC_VERSION_MINOR_SHIFT	U(0)
+#define SMCCC_VERSION_MINOR_MASK	U(0xFFFF)
+#define MAKE_SMCCC_VERSION(_major, _minor) \
+	((((uint32_t)(_major) & SMCCC_VERSION_MAJOR_MASK) << \
+						SMCCC_VERSION_MAJOR_SHIFT) \
+	| (((uint32_t)(_minor) & SMCCC_VERSION_MINOR_MASK) << \
+						SMCCC_VERSION_MINOR_SHIFT))
+
+#define SMCCC_MAJOR_VERSION		1
+#define SMCCC_MINOR_VERSION		1
+
+#define SMC_UNKNOWN			-1
+
+/* TODO: Import SMCCC 2.0 properly instead of having this */
+#define FUNCID_NAMESPACE_SHIFT		U(28)
+#define FUNCID_NAMESPACE_MASK		U(0x3)
+#define FUNCID_NAMESPACE_WIDTH		U(2)
+#define FUNCID_NAMESPACE_SPRT		U(2)
+#define FUNCID_NAMESPACE_SPCI		U(3)
+
+/*******************************************************************************
+ * Bit definitions inside the function id as per the SMC calling convention
+ ******************************************************************************/
+#define FUNCID_TYPE_SHIFT		31
+#define FUNCID_CC_SHIFT			30
+#define FUNCID_OEN_SHIFT		24
+#define FUNCID_NUM_SHIFT		0
+
+#define FUNCID_TYPE_MASK		0x1
+#define FUNCID_CC_MASK			0x1
+#define FUNCID_OEN_MASK			0x3f
+#define FUNCID_NUM_MASK			0xffff
+
+#define FUNCID_TYPE_WIDTH		1
+#define FUNCID_CC_WIDTH			1
+#define FUNCID_OEN_WIDTH		6
+#define FUNCID_NUM_WIDTH		16
+
+#define SMC_64				1
+#define SMC_32				0
+#define SMC_TYPE_FAST			1
+#define SMC_TYPE_STD			0
+
+/*******************************************************************************
+ * Owning entity number definitions inside the function id as per the SMC
+ * calling convention
+ ******************************************************************************/
+#define OEN_ARM_START			0
+#define OEN_ARM_END			0
+#define OEN_CPU_START			1
+#define OEN_CPU_END			1
+#define OEN_SIP_START			2
+#define OEN_SIP_END			2
+#define OEN_OEM_START			3
+#define OEN_OEM_END			3
+#define OEN_STD_START			4	/* Standard Calls */
+#define OEN_STD_END			4
+#define OEN_TAP_START			48	/* Trusted Applications */
+#define OEN_TAP_END			49
+#define OEN_TOS_START			50	/* Trusted OS */
+#define OEN_TOS_END			63
+#define OEN_LIMIT			64
+
+#endif /* __SMCCC_H__ */
diff --git a/include/runtime_services/sprt_svc.h b/include/runtime_services/sprt_svc.h
new file mode 100644
index 0000000..e789880
--- /dev/null
+++ b/include/runtime_services/sprt_svc.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2018, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef __SPRT_SVC_H__
+#define __SPRT_SVC_H__
+
+#include <smccc.h>
+#include <utils_def.h>
+
+/* SPRT_VERSION helpers */
+#define SPRT_VERSION_MAJOR		U(0)
+#define SPRT_VERSION_MAJOR_SHIFT	16
+#define SPRT_VERSION_MAJOR_MASK		U(0x7FFF)
+/* TODO: Move up minor version to 1 when SPRT is properly supported. */
+#define SPRT_VERSION_MINOR		U(0)
+#define SPRT_VERSION_MINOR_SHIFT	0
+#define SPRT_VERSION_MINOR_MASK		U(0xFFFF)
+#define SPRT_VERSION_FORM(major, minor)	((((major) & SPRT_VERSION_MAJOR_MASK) << SPRT_VERSION_MAJOR_SHIFT) | \
+					((minor) & SPRT_VERSION_MINOR_MASK))
+#define SPRT_VERSION_COMPILED		SPRT_VERSION_FORM(SPRT_VERSION_MAJOR, SPRT_VERSION_MINOR)
+
+/* TODO: Check all values below are correct when they're specified in SPRT. */
+
+/* SPRT function IDs */
+#define SPRT_FID_VERSION		U(0x0)
+#define SPRT_FID_RETURN_RESPONSE	U(0x1)
+
+#define SPRT_FID_MASK			U(0xFF)
+
+/* Definitions to build the complete SMC ID */
+#define SPRT_SMC_ID(sprt_fid)		((FUNCID_SERV_SPRT << FUNCID_SERV_SHIFT) | \
+					 (U(1) << 31) | ((sprt_fid) & SPRT_FID_MASK))
+
+/* Complete SMC IDs */
+#define SPRT_VERSION			SPRT_SMC_ID(SPRT_FID_VERSION)
+#define SPRT_RETURN_RESPONSE		SPRT_SMC_ID(SPRT_FID_RETURN_RESPONSE)
+
+/* SPRT error codes. */
+#define SPRT_SUCCESS		 0
+#define SPRT_NOT_SUPPORTED	-1
+#define SPRT_INVALID_PARAMETER	-2
+
+#endif /* __SPRT_SVC_H__ */
diff --git a/include/runtime_services/std_svc.h b/include/runtime_services/std_svc.h
new file mode 100644
index 0000000..75ca4e6
--- /dev/null
+++ b/include/runtime_services/std_svc.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2018, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+/*
+ * Definitions related to the Standard Service as per the SMC Calling Convention
+ *
+ * Although PSCI calls are part of the Standard Service call range, PSCI-related
+ * definitions are not in this header file but in psci.h instead.
+ */
+
+#ifndef __STD_SVC_H__
+#define __STD_SVC_H__
+
+/* SMC function IDs for Standard Service queries */
+#define SMC_STD_SVC_CALL_COUNT		0x8400ff00
+#define SMC_STD_SVC_UID			0x8400ff01
+/*					0x8400ff02 is reserved */
+#define SMC_STD_SVC_REVISION		0x8400ff03
+
+/* Standard Service Calls revision numbers */
+#define STD_SVC_REVISION_MAJOR		0x0
+#define STD_SVC_REVISION_MINOR		0x1
+
+#endif /* __STD_SVC_H__ */
diff --git a/include/runtime_services/trusted_os.h b/include/runtime_services/trusted_os.h
new file mode 100644
index 0000000..f480c6b
--- /dev/null
+++ b/include/runtime_services/trusted_os.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2018, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+/*
+ * Definitions related to the Trusted OS Service as per the SMC Calling
+ * Convention.
+ */
+
+#ifndef __TRUSTED_OS_H__
+#define __TRUSTED_OS_H__
+
+#include <uuid.h>
+
+/* Trusted OS Function IDs that fall under Trusted OS call range */
+#define SMC_TOS_CALL_COUNT	0xbf00ff00
+#define SMC_TOS_UID		0xbf00ff01
+/*				0xbf00ff02 is reserved */
+#define SMC_TOS_REVISION	0xbf00ff03
+
+/*
+ * Detect whether a Trusted OS is present in the software stack.
+ * This is implemented using the Trusted OS UID SMC call.
+ *
+ * If a Trusted OS is detected then this function returns 1
+ * and populates 'tos_uuid' with the UUID of the detected Trusted OS.
+ * Otherwise, this function returns 0 and the value pointed by 'tos_uuid'
+ * should be ignored.
+ */
+unsigned int is_trusted_os_present(uuid_t *tos_uuid);
+
+#endif /* __TRUSTED_OS_H__ */