feat(fvp): enable kernel dt convention

Enable USE_KERNEL_DT_CONVENTION for the FVP platform to pass the DT blob
(DTB) in x0 to BL33. This aligns with the Linux boot protocol as
described in Documentation/arm64/booting.rst.

In addition:

- Clean up legacy ARM_LINUX_KERNEL_AS_BL33 handling since
  USE_KERNEL_DT_CONVENTION now implies this mode for DT handoff.
- Override args.arg0 for BL33 to point to ARM_PRELOADED_DTB_BASE in
  RESET_TO_BL31.
- Skip setting the primary MPID in x0 when using this convention.

Change-Id: Ieea8cfe68104b82038b9311613abf13afe7b48f1
Signed-off-by: Harrison Mutai <harrison.mutai@arm.com>
diff --git a/plat/arm/board/fvp/fvp_bl2_setup.c b/plat/arm/board/fvp/fvp_bl2_setup.c
index 852a1e7..9479af6 100644
--- a/plat/arm/board/fvp/fvp_bl2_setup.c
+++ b/plat/arm/board/fvp/fvp_bl2_setup.c
@@ -116,15 +116,6 @@
 	assert(fw_config_base != 0UL);
 
 	param_node->ep_info.args.arg1 = (uint32_t)fw_config_base;
-
-	/* Update BL33's ep info with the NS HW config address */
-	param_node = get_bl_mem_params_node(BL33_IMAGE_ID);
-	assert(param_node != NULL);
-
-	hw_config_info = FCONF_GET_PROPERTY(dyn_cfg, dtb, HW_CONFIG_ID);
-	assert(hw_config_info != NULL);
-
-	param_node->ep_info.args.arg1 = hw_config_info->secondary_config_addr;
 #endif /* TRANSFER_LIST */
 
 	return arm_bl_params;
@@ -159,3 +150,15 @@
 
 	return arm_bl2_plat_handle_post_image_load(image_id);
 }
+
+uintptr_t plat_get_hw_dt_base(void)
+{
+	const struct dyn_cfg_dtb_info_t *hw_config_info;
+
+	hw_config_info = FCONF_GET_PROPERTY(dyn_cfg, dtb, HW_CONFIG_ID);
+	if (hw_config_info == NULL) {
+		return 0U;
+	}
+
+	return hw_config_info->secondary_config_addr;
+}
diff --git a/plat/arm/board/fvp/platform.mk b/plat/arm/board/fvp/platform.mk
index 2b44c25..17949e7 100644
--- a/plat/arm/board/fvp/platform.mk
+++ b/plat/arm/board/fvp/platform.mk
@@ -33,6 +33,10 @@
 # Macro to enable helpers for running SPM tests. Disabled by default.
 PLAT_TEST_SPM	:= 0
 
+
+# Enable passing the DT to BL33 in x0 by default.
+USE_KERNEL_DT_CONVENTION	:= 1
+
 # By default dont build CPUs with no FVP model.
 BUILD_CPUS_WITH_NO_FVP_MODEL	?= 0
 
diff --git a/plat/arm/common/arm_bl2_setup.c b/plat/arm/common/arm_bl2_setup.c
index 668e34d..946af3b 100644
--- a/plat/arm/common/arm_bl2_setup.c
+++ b/plat/arm/common/arm_bl2_setup.c
@@ -271,8 +271,10 @@
 #endif
 
 	case BL33_IMAGE_ID:
+#if !USE_KERNEL_DT_CONVENTION
 		/* BL33 expects to receive the primary CPU MPID (through r0) */
 		bl_mem_params->ep_info.args.arg0 = 0xffff & read_mpidr();
+#endif /* !USE_KERNEL_DT_CONVENTION */
 		bl_mem_params->ep_info.spsr = arm_get_spsr_for_bl33_entry();
 		break;
 
diff --git a/plat/arm/common/arm_bl31_setup.c b/plat/arm/common/arm_bl31_setup.c
index ce6b21e..f44be5c 100644
--- a/plat/arm/common/arm_bl31_setup.c
+++ b/plat/arm/common/arm_bl31_setup.c
@@ -246,6 +246,13 @@
 	 */
 	bl33_image_ep_info.pc = plat_get_ns_image_entrypoint();
 
+#if ARM_LINUX_KERNEL_AS_BL33
+	bl33_image_ep_info.args.arg0 = ARM_PRELOADED_DTB_BASE;
+	bl33_image_ep_info.args.arg1 = 0U;
+	bl33_image_ep_info.args.arg2 = 0U;
+	bl33_image_ep_info.args.arg3 = 0U;
+#endif /* ARM_LINUX_KERNEL_AS_BL33 */
+
 	bl33_image_ep_info.spsr = arm_get_spsr_for_bl33_entry();
 	SET_SECURITY_STATE(bl33_image_ep_info.h.attr, NON_SECURE);
 
@@ -321,27 +328,6 @@
 		panic();
 #endif
 #endif /* RESET_TO_BL31 */
-
-#if ARM_LINUX_KERNEL_AS_BL33
-	/*
-	 * According to the file ``Documentation/arm64/booting.txt`` of the
-	 * Linux kernel tree, Linux expects the physical address of the device
-	 * tree blob (DTB) in x0, while x1-x3 are reserved for future use and
-	 * must be 0.
-	 * Repurpose the option to load Hafnium hypervisor in the normal world.
-	 * It expects its manifest address in x0. This is essentially the linux
-	 * dts (passed to the primary VM) by adding 'hypervisor' and chosen
-	 * nodes specifying the Hypervisor configuration.
-	 */
-#if RESET_TO_BL31
-	bl33_image_ep_info.args.arg0 = (u_register_t)ARM_PRELOADED_DTB_BASE;
-#else
-	bl33_image_ep_info.args.arg0 = arg2;
-#endif /* RESET_TO_BL31 */
-	bl33_image_ep_info.args.arg1 = 0U;
-	bl33_image_ep_info.args.arg2 = 0U;
-	bl33_image_ep_info.args.arg3 = 0U;
-#endif /* ARM_LINUX_KERNEL_AS_BL33 */
 #endif /* TRANSFER_LIST */
 }