Add Test Secure Payload Dispatcher (TSPD) service

This patch adds the TSPD service which is responsible for managing
communication between the non-secure state and the Test Secure Payload
(TSP) executing in S-EL1.

The TSPD does the following:

1. Determines the location of the TSP (BL3-2) image and passes control
   to it for initialization. This is done by exporting the 'bl32_init()'
   function.

2. Receives a structure containing the various entry points into the TSP
   image as a response to being initialized. The TSPD uses this
   information to determine how the TSP should be entered depending on
   the type of operation.

3. Implements a synchronous mechanism for entering into and returning
   from the TSP image. This mechanism saves the current C runtime
   context on top of the current stack and jumps to the TSP through an
   ERET instruction. The TSP issues an SMC to indicate completion of the
   previous request. The TSPD restores the saved C runtime context and
   resumes TSP execution.

This patch also introduces a Make variable 'SPD' to choose the specific
SPD to include in the build. By default, no SPDs are included in the
build.

Change-Id: I124da5695cdc510999b859a1bf007f4d049e04f3
Co-authored-by: Jeenu Viswambharan <jeenu.viswambharan@arm.com>
diff --git a/plat/fvp/plat_io_storage.c b/plat/fvp/plat_io_storage.c
index fd2d2b2..768c3c5 100644
--- a/plat/fvp/plat_io_storage.c
+++ b/plat/fvp/plat_io_storage.c
@@ -62,6 +62,7 @@
 
 static int fvp_bl2_policy(io_dev_handle *dev_handle, void **image_spec);
 static int fvp_bl31_policy(io_dev_handle *dev_handle, void **image_spec);
+static int fvp_bl32_policy(io_dev_handle *dev_handle, void **image_spec);
 static int fvp_bl33_policy(io_dev_handle *dev_handle, void **image_spec);
 static int fvp_fip_policy(io_dev_handle *dev_handle, void **image_spec);
 
@@ -81,6 +82,11 @@
 	.mode = FOPEN_MODE_R
 };
 
+static io_file_spec bl32_file_spec = {
+	.path = BL32_IMAGE_NAME,
+	.mode = FOPEN_MODE_R
+};
+
 static io_file_spec bl33_file_spec = {
 	.path = BL33_IMAGE_NAME,
 	.mode = FOPEN_MODE_R
@@ -89,6 +95,7 @@
 static plat_io_policy fvp_policy[] = {
 	{BL2_IMAGE_NAME,  fvp_bl2_policy},
 	{BL31_IMAGE_NAME, fvp_bl31_policy},
+	{BL32_IMAGE_NAME, fvp_bl32_policy},
 	{BL33_IMAGE_NAME, fvp_bl33_policy},
 	{FIP_IMAGE_NAME,  fvp_fip_policy},
 	{NULL, NULL}
@@ -194,6 +201,31 @@
 }
 
 
+/* Try to load BL32 from Firmware Image Package in FLASH first. If there is no
+ * FIP in FLASH or it is broken, try to load the file from semi-hosting.
+ */
+static int fvp_bl32_policy(io_dev_handle *dev_handle, void **image_spec)
+{
+	int result = IO_FAIL;
+	void *local_image_spec = &bl32_file_spec;
+
+	INFO("Loading BL32\n");
+	/* FIP first then fall back to semi-hosting */
+	result = open_fip(local_image_spec);
+	if (result == IO_SUCCESS) {
+		*dev_handle = fip_dev_handle;
+		*(io_file_spec **)image_spec = local_image_spec;
+	} else {
+		result = open_semihosting(local_image_spec);
+		if (result == IO_SUCCESS) {
+			*dev_handle = sh_dev_handle;
+			*(io_file_spec **)image_spec = local_image_spec;
+		}
+	}
+	return result;
+}
+
+
 /* Try to load BL33 from Firmware Image Package in FLASH first. If there is no
  * FIP in FLASH or it is broken, try to load the file from semi-hosting.
  */