xref: /rk3399_ARM-atf/plat/arm/board/fvp/fvp_bl2_setup.c (revision a5566f65fd1be689ca5c63baa1f5b61b40960c8d)
13fc4124cSDan Handley /*
286e4859aSRohit Mathew  * Copyright (c) 2013-2024, Arm Limited and Contributors. All rights reserved.
33fc4124cSDan Handley  *
482cb2c1aSdp-arm  * SPDX-License-Identifier: BSD-3-Clause
53fc4124cSDan Handley  */
63fc4124cSDan Handley 
77fb9bcd8SManish V Badarkhe #include <assert.h>
87fb9bcd8SManish V Badarkhe 
94a135bc3SAlexei Fedorov #include <common/debug.h>
107fb9bcd8SManish V Badarkhe #include <common/desc_image_load.h>
1109d40e0eSAntonio Nino Diaz #include <drivers/arm/sp804_delay_timer.h>
1286e4859aSRohit Mathew #include <fvp_pas_def.h>
137fb9bcd8SManish V Badarkhe #include <lib/fconf/fconf.h>
147fb9bcd8SManish V Badarkhe #include <lib/fconf/fconf_dyn_cfg_getter.h>
1594c90ac8SHarrison Mutai #include <lib/transfer_list.h>
167fb9bcd8SManish V Badarkhe 
17bd9344f6SAntonio Nino Diaz #include <plat/arm/common/plat_arm.h>
1809d40e0eSAntonio Nino Diaz #include <plat/common/platform.h>
19234bc7f8SAntonio Nino Diaz #include <platform_def.h>
2009d40e0eSAntonio Nino Diaz 
213fc4124cSDan Handley #include "fvp_private.h"
223fc4124cSDan Handley 
2386e4859aSRohit Mathew #if ENABLE_RME
2486e4859aSRohit Mathew /*
2586e4859aSRohit Mathew  * The GPT library might modify the gpt regions structure to optimize
2686e4859aSRohit Mathew  * the layout, so the array cannot be constant.
2786e4859aSRohit Mathew  */
2886e4859aSRohit Mathew static pas_region_t pas_regions[] = {
2986e4859aSRohit Mathew 	ARM_PAS_KERNEL,
3086e4859aSRohit Mathew 	ARM_PAS_SECURE,
3186e4859aSRohit Mathew 	ARM_PAS_REALM,
3286e4859aSRohit Mathew 	ARM_PAS_EL3_DRAM,
3386e4859aSRohit Mathew 	ARM_PAS_GPTS,
3486e4859aSRohit Mathew 	ARM_PAS_KERNEL_1
3586e4859aSRohit Mathew };
3686e4859aSRohit Mathew 
3786e4859aSRohit Mathew static const arm_gpt_info_t arm_gpt_info = {
3886e4859aSRohit Mathew 	.pas_region_base  = pas_regions,
3986e4859aSRohit Mathew 	.pas_region_count = (unsigned int)ARRAY_SIZE(pas_regions),
4086e4859aSRohit Mathew 	.l0_base = (uintptr_t)ARM_L0_GPT_BASE,
4186e4859aSRohit Mathew 	.l1_base = (uintptr_t)ARM_L1_GPT_BASE,
4286e4859aSRohit Mathew 	.l0_size = (size_t)ARM_L0_GPT_SIZE,
4386e4859aSRohit Mathew 	.l1_size = (size_t)ARM_L1_GPT_SIZE,
4486e4859aSRohit Mathew 	.pps = GPCCR_PPS_64GB,
4586e4859aSRohit Mathew 	.pgs = GPCCR_PGS_4K
4686e4859aSRohit Mathew };
4786e4859aSRohit Mathew #endif
4886e4859aSRohit Mathew 
490c306cc0SSoby Mathew void bl2_early_platform_setup2(u_register_t arg0, u_register_t arg1, u_register_t arg2, u_register_t arg3)
503fc4124cSDan Handley {
51cab0b5b0SSoby Mathew 	arm_bl2_early_platform_setup((uintptr_t)arg0, (meminfo_t *)arg1);
523fc4124cSDan Handley 
533fc4124cSDan Handley 	/* Initialize the platform config for future decision making */
543fc4124cSDan Handley 	fvp_config_setup();
553fc4124cSDan Handley }
56b49b3221SRyan Harkin 
57b49b3221SRyan Harkin void bl2_platform_setup(void)
58b49b3221SRyan Harkin {
59b49b3221SRyan Harkin 	arm_bl2_platform_setup();
60b49b3221SRyan Harkin 
611b597c22SAlexei Fedorov 	/* Initialize System level generic or SP804 timer */
621b597c22SAlexei Fedorov 	fvp_timer_init();
63b49b3221SRyan Harkin }
647fb9bcd8SManish V Badarkhe 
6586e4859aSRohit Mathew #if ENABLE_RME
6686e4859aSRohit Mathew const arm_gpt_info_t *plat_arm_get_gpt_info(void)
6786e4859aSRohit Mathew {
6886e4859aSRohit Mathew 	return &arm_gpt_info;
6986e4859aSRohit Mathew }
7086e4859aSRohit Mathew #endif /* ENABLE_RME */
7186e4859aSRohit Mathew 
727fb9bcd8SManish V Badarkhe /*******************************************************************************
737fb9bcd8SManish V Badarkhe  * This function returns the list of executable images
747fb9bcd8SManish V Badarkhe  ******************************************************************************/
757fb9bcd8SManish V Badarkhe struct bl_params *plat_get_next_bl_params(void)
767fb9bcd8SManish V Badarkhe {
777fb9bcd8SManish V Badarkhe 	struct bl_params *arm_bl_params;
78568d406cSHarrison Mutai 	bl_mem_params_node_t *param_node __unused;
79*a5566f65SHarrison Mutai 	const struct dyn_cfg_dtb_info_t *fw_config_info __unused;
80*a5566f65SHarrison Mutai 	const struct dyn_cfg_dtb_info_t *hw_config_info __unused;
81*a5566f65SHarrison Mutai 	entry_point_info_t *ep __unused;
82*a5566f65SHarrison Mutai 	uint32_t next_exe_img_id __unused;
83*a5566f65SHarrison Mutai 	uintptr_t fw_config_base __unused;
847fb9bcd8SManish V Badarkhe 
857fb9bcd8SManish V Badarkhe 	arm_bl_params = arm_get_next_bl_params();
867fb9bcd8SManish V Badarkhe 
8739f0b86aSManish V Badarkhe #if __aarch64__
887fb9bcd8SManish V Badarkhe 	/* Get BL31 image node */
897fb9bcd8SManish V Badarkhe 	param_node = get_bl_mem_params_node(BL31_IMAGE_ID);
9039f0b86aSManish V Badarkhe #else /* aarch32 */
9139f0b86aSManish V Badarkhe 	/* Get SP_MIN image node */
9239f0b86aSManish V Badarkhe 	param_node = get_bl_mem_params_node(BL32_IMAGE_ID);
9339f0b86aSManish V Badarkhe #endif /* __aarch64__ */
947fb9bcd8SManish V Badarkhe 	assert(param_node != NULL);
957fb9bcd8SManish V Badarkhe 
96*a5566f65SHarrison Mutai #if TRANSFER_LIST
97*a5566f65SHarrison Mutai 	arm_bl_params->head = &param_node->params_node_mem;
98*a5566f65SHarrison Mutai 	arm_bl_params->head->ep_info = &param_node->ep_info;
99*a5566f65SHarrison Mutai 	arm_bl_params->head->image_id = param_node->image_id;
100*a5566f65SHarrison Mutai 
101*a5566f65SHarrison Mutai 	arm_bl2_setup_next_ep_info(param_node);
102*a5566f65SHarrison Mutai #elif !RESET_TO_BL2 && !EL3_PAYLOAD_BASE
103*a5566f65SHarrison Mutai 	fw_config_base = 0UL;
104*a5566f65SHarrison Mutai 
105568d406cSHarrison Mutai 	/* Update the next image's ep info with the FW config address */
1067fb9bcd8SManish V Badarkhe 	fw_config_info = FCONF_GET_PROPERTY(dyn_cfg, dtb, FW_CONFIG_ID);
1077fb9bcd8SManish V Badarkhe 	assert(fw_config_info != NULL);
1087fb9bcd8SManish V Badarkhe 
1097fb9bcd8SManish V Badarkhe 	fw_config_base = fw_config_info->config_addr;
11039f0b86aSManish V Badarkhe 	assert(fw_config_base != 0UL);
1117fb9bcd8SManish V Badarkhe 
112568d406cSHarrison Mutai 	param_node->ep_info.args.arg1 = (uint32_t)fw_config_base;
11339f0b86aSManish V Badarkhe 
114568d406cSHarrison Mutai 	/* Update BL33's ep info with the NS HW config address */
115568d406cSHarrison Mutai 	param_node = get_bl_mem_params_node(BL33_IMAGE_ID);
116568d406cSHarrison Mutai 	assert(param_node != NULL);
117568d406cSHarrison Mutai 
11839f0b86aSManish V Badarkhe 	hw_config_info = FCONF_GET_PROPERTY(dyn_cfg, dtb, HW_CONFIG_ID);
119a42b426bSManish V Badarkhe 	assert(hw_config_info != NULL);
12039f0b86aSManish V Badarkhe 
121568d406cSHarrison Mutai 	param_node->ep_info.args.arg1 = hw_config_info->secondary_config_addr;
12294c90ac8SHarrison Mutai #endif /* TRANSFER_LIST */
1237fb9bcd8SManish V Badarkhe 
1247fb9bcd8SManish V Badarkhe 	return arm_bl_params;
1257fb9bcd8SManish V Badarkhe }
126ed567207SHarrison Mutai 
127ed567207SHarrison Mutai int bl2_plat_handle_post_image_load(unsigned int image_id)
128ed567207SHarrison Mutai {
129*a5566f65SHarrison Mutai #if !RESET_TO_BL2 && !EL3_PAYLOAD_BASE && !TRANSFER_LIST
130568d406cSHarrison Mutai 	if (image_id == HW_CONFIG_ID) {
131*a5566f65SHarrison Mutai 		const struct dyn_cfg_dtb_info_t *hw_config_info __unused;
132568d406cSHarrison Mutai 		struct transfer_list_entry *te __unused;
133*a5566f65SHarrison Mutai 		bl_mem_params_node_t *param_node __unused;
134568d406cSHarrison Mutai 
135*a5566f65SHarrison Mutai 		param_node = get_bl_mem_params_node(image_id);
136568d406cSHarrison Mutai 		assert(param_node != NULL);
137568d406cSHarrison Mutai 
138568d406cSHarrison Mutai 		hw_config_info = FCONF_GET_PROPERTY(dyn_cfg, dtb, HW_CONFIG_ID);
139568d406cSHarrison Mutai 		assert(hw_config_info != NULL);
140568d406cSHarrison Mutai 
141568d406cSHarrison Mutai 		memcpy((void *)hw_config_info->secondary_config_addr,
142568d406cSHarrison Mutai 		       (void *)hw_config_info->config_addr,
143568d406cSHarrison Mutai 		       (size_t)param_node->image_info.image_size);
144568d406cSHarrison Mutai 
145568d406cSHarrison Mutai 		/*
146568d406cSHarrison Mutai 		 * Ensure HW-config device tree is committed to memory, as the HW-Config
147568d406cSHarrison Mutai 		 * might be used without cache and MMU enabled at BL33.
148568d406cSHarrison Mutai 		 */
149568d406cSHarrison Mutai 		flush_dcache_range(hw_config_info->secondary_config_addr,
150568d406cSHarrison Mutai 				   param_node->image_info.image_size);
151568d406cSHarrison Mutai 	}
152*a5566f65SHarrison Mutai #endif /* !RESET_TO_BL2 && !EL3_PAYLOAD_BASE && !TRANSFER_LIST*/
153568d406cSHarrison Mutai 
154ed567207SHarrison Mutai 	return arm_bl2_plat_handle_post_image_load(image_id);
155ed567207SHarrison Mutai }
156