Refactor FF-A boot info

Refactor the FF-A boot info related types to prepare for adding the FF-A
v1.1 structures.

Signed-off-by: Balint Dobszay <balint.dobszay@arm.com>
Change-Id: I03dd0275d367611e6156c4ba47bdbacb62296001
diff --git a/components/config/loader/sp/sp_config_loader.c b/components/config/loader/sp/sp_config_loader.c
index b4d81b4..6aaff4b 100644
--- a/components/config/loader/sp/sp_config_loader.c
+++ b/components/config/loader/sp/sp_config_loader.c
@@ -9,16 +9,17 @@
 #include <platform/interface/device_region.h>
 #include <platform/interface/memory_region.h>
 #include <stdbool.h>
+#include <stdint.h>
 #include <string.h>
 #include <trace.h>
 
 #include "sp_config_loader.h"
 
 /*
- * According to the FF-A 1.0 spec: in the SP manifest the size of device and
+ * According to the FF-A spec: in the SP manifest the size of device and
  * memory regions is expressed as a count of 4K pages.
  */
-#define FFA_SP_MANIFEST_PAGE_SIZE	0x1000
+#define FFA_SP_MANIFEST_PAGE_SIZE UINT32_C(0x1000)
 
 struct sp_param_region {
 	char name[16];
@@ -26,7 +27,7 @@
 	size_t size;
 };
 
-static bool load_device_regions(const struct ffa_name_value_pair *value_pair)
+static bool load_device_regions(const struct ffa_name_value_pair_v1_0 *value_pair)
 {
 	struct sp_param_region *d = (struct sp_param_region *)value_pair->value;
 
@@ -55,7 +56,7 @@
 	return true;
 }
 
-static bool load_memory_regions(const struct ffa_name_value_pair *value_pair)
+static bool load_memory_regions(const struct ffa_name_value_pair_v1_0 *value_pair)
 {
 	struct sp_param_region *d = (struct sp_param_region *)value_pair->value;
 
@@ -82,7 +83,7 @@
 	return true;
 }
 
-static bool load_blob(const struct ffa_name_value_pair *value_pair)
+static bool load_blob(const struct ffa_name_value_pair_v1_0 *value_pair)
 {
 	struct config_blob blob;
 
@@ -98,10 +99,8 @@
 	return true;
 }
 
-static bool load_fdt(const struct ffa_name_value_pair *value_pair)
+static bool load_fdt(const void *fdt, size_t fdt_size)
 {
-	const void *fdt = (const void *)value_pair->value;
-	size_t fdt_size = value_pair->size;
 	int root = -1, node = -1, subnode = -1, rc = -1;
 	static const char *ffa_manifest_compatible = "arm,ffa-manifest-1.0";
 
@@ -262,36 +261,31 @@
 	return true;
 }
 
-/**
- * Loads externally provided configuration data passed into the SP via
- * FFA initialisation parameters.  Data can originate from
- * the SP manifest, an external device tree or a dynamic configuration
- * mechanism such as a handover block (HOB).
- */
-bool sp_config_load(struct ffa_init_info *init_info)
+static bool sp_config_load_v1_0(struct ffa_boot_info_v1_0 *boot_info)
 {
 	/* Load deployment specific configuration */
-	for (size_t param_index = 0; param_index < init_info->count; param_index++) {
-		const char *name = (const char *)init_info->nvp[param_index].name;
-		const size_t name_max_size = sizeof(init_info->nvp[param_index].name);
+	for (size_t param_index = 0; param_index < boot_info->count; param_index++) {
+		const char *name = (const char *)boot_info->nvp[param_index].name;
+		const size_t name_max_size = sizeof(boot_info->nvp[param_index].name);
 
 		if (!strncmp(name, "DEVICE_REGIONS", name_max_size)) {
-			if (!load_device_regions(&init_info->nvp[param_index])) {
+			if (!load_device_regions(&boot_info->nvp[param_index])) {
 				EMSG("Failed to load device regions");
 				return false;
 			}
 		} else if (!strncmp(name, "MEMORY_REGIONS", name_max_size)) {
-			if (!load_memory_regions(&init_info->nvp[param_index])) {
+			if (!load_memory_regions(&boot_info->nvp[param_index])) {
 				EMSG("Failed to load memory regions");
 				return false;
 			}
 		} else if (!memcmp(name, "TYPE_DT\0\0\0\0\0\0\0\0", name_max_size)) {
-			if (!load_fdt(&init_info->nvp[param_index])) {
+			if (!load_fdt((void *)boot_info->nvp[param_index].value,
+					boot_info->nvp[param_index].size)) {
 				EMSG("Failed to load SP config from DT");
 				return false;
 			}
 		} else {
-			if (!load_blob(&init_info->nvp[param_index])) {
+			if (!load_blob(&boot_info->nvp[param_index])) {
 				EMSG("Failed to load blob");
 				return false;
 			}
@@ -300,3 +294,19 @@
 
 	return true;
 }
+
+bool sp_config_load(union ffa_boot_info *boot_info)
+{
+	if (!boot_info)
+		return false;
+
+	switch (boot_info->signature) {
+	case FFA_BOOT_INFO_SIGNATURE_V1_0:
+		return sp_config_load_v1_0((struct ffa_boot_info_v1_0 *)&boot_info->boot_info_v1_0);
+	default:
+		EMSG("Invalid FF-A boot info signature");
+		return false;
+	}
+
+	return false;
+}
diff --git a/components/config/loader/sp/sp_config_loader.h b/components/config/loader/sp/sp_config_loader.h
index 6448c62..3e585ce 100644
--- a/components/config/loader/sp/sp_config_loader.h
+++ b/components/config/loader/sp/sp_config_loader.h
@@ -14,6 +14,6 @@
  * Loads the secure partition specific configuration passed as
  * SP initialization parameters.
  */
-bool sp_config_load(struct ffa_init_info *init_info);
+bool sp_config_load(union ffa_boot_info *boot_info);
 
 #endif /* SP_CONFIG_LOADER_H */
diff --git a/components/messaging/ffa/libsp/include/ffa_api_defines.h b/components/messaging/ffa/libsp/include/ffa_api_defines.h
index 163a0cd..03b1198 100644
--- a/components/messaging/ffa/libsp/include/ffa_api_defines.h
+++ b/components/messaging/ffa/libsp/include/ffa_api_defines.h
@@ -66,6 +66,9 @@
 /* Special value for MBZ parameters */
 #define FFA_PARAM_MBZ			UINT32_C(0x0)
 
+/* Boot information signature */
+#define FFA_BOOT_INFO_SIGNATURE_V1_0	UINT32_C(0x412D4646) /* FF-A ASCII */
+
 /* FFA_VERSION */
 #define FFA_VERSION_MAJOR		UINT32_C(1)
 #define FFA_VERSION_MAJOR_SHIFT		UINT32_C(16)
diff --git a/components/messaging/ffa/libsp/include/ffa_api_types.h b/components/messaging/ffa/libsp/include/ffa_api_types.h
index b1be7ac..8333488 100644
--- a/components/messaging/ffa/libsp/include/ffa_api_types.h
+++ b/components/messaging/ffa/libsp/include/ffa_api_types.h
@@ -11,25 +11,30 @@
 #include <stdint.h>
 
 /**
- * Init info
+ * Boot info
  */
 
 /**
  * @brief Boot protocol name-value pairs
  */
-struct ffa_name_value_pair {
+struct ffa_name_value_pair_v1_0 {
 	uint32_t name[4]; /**< Name of the item */
 	uintptr_t value; /**< Value of the item */
 	size_t size; /**< Size of the referenced value */
 };
 
 /**
- * @brief Structure for passing boot protocol data
+ * @brief Structure for passing boot protocol data (FF-A v1.0)
  */
-struct ffa_init_info {
+struct ffa_boot_info_v1_0 {
 	uint32_t magic; /**< FF-A */
 	uint32_t count; /**< Count of name value size pairs */
-	struct ffa_name_value_pair nvp[]; /**< Array of name value size pairs */
+	struct ffa_name_value_pair_v1_0 nvp[]; /**< Array of name value size pairs */
+};
+
+union ffa_boot_info {
+	uint32_t signature;
+	struct ffa_boot_info_v1_0 boot_info_v1_0;
 };
 
 /**
diff --git a/components/messaging/ffa/libsp/include/sp_api.h b/components/messaging/ffa/libsp/include/sp_api.h
index 3c432bb..b220c91 100644
--- a/components/messaging/ffa/libsp/include/sp_api.h
+++ b/components/messaging/ffa/libsp/include/sp_api.h
@@ -30,9 +30,9 @@
  * @brief      Entry point of the SP's application code. SPs must implement this
  *             function.
  *
- * @param      init_info  The boot info
+ * @param      boot_info  The boot info
  */
-void __noreturn sp_main(struct ffa_init_info *init_info);
+void __noreturn sp_main(union ffa_boot_info *boot_info);
 
 #ifdef __cplusplus
 }
diff --git a/components/service/spm_test/sp.c b/components/service/spm_test/sp.c
index 01cc7d2..30ddea7 100644
--- a/components/service/spm_test/sp.c
+++ b/components/service/spm_test/sp.c
@@ -744,10 +744,12 @@
 	return_error(err, msg);
 }
 
-void __noreturn sp_main(struct ffa_init_info *init_info) {
+void __noreturn sp_main(union ffa_boot_info *boot_info) {
 	struct ffa_direct_msg msg = {0};
 	uint16_t own_id = 0;
 
+	(void)boot_info;
+
 	/* Boot phase */
 	if (sp_discovery_own_id_get(&own_id) != SP_RESULT_OK) {
 		EMSG("Couldn't get own_id!!");