xref: /rk3399_ARM-atf/plat/arm/board/fvp/fvp_bl2_setup.c (revision 665a8fdf3aa372862d62c34d23ffd678798a265c)
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,
33*665a8fdfSAlexeiFedorov #ifdef ARM_PAS_GPTS
3486e4859aSRohit Mathew 	ARM_PAS_GPTS,
35*665a8fdfSAlexeiFedorov #endif
3686e4859aSRohit Mathew 	ARM_PAS_KERNEL_1
3786e4859aSRohit Mathew };
3886e4859aSRohit Mathew 
3986e4859aSRohit Mathew static const arm_gpt_info_t arm_gpt_info = {
4086e4859aSRohit Mathew 	.pas_region_base  = pas_regions,
4186e4859aSRohit Mathew 	.pas_region_count = (unsigned int)ARRAY_SIZE(pas_regions),
4286e4859aSRohit Mathew 	.l0_base = (uintptr_t)ARM_L0_GPT_BASE,
4386e4859aSRohit Mathew 	.l1_base = (uintptr_t)ARM_L1_GPT_BASE,
4486e4859aSRohit Mathew 	.l0_size = (size_t)ARM_L0_GPT_SIZE,
4586e4859aSRohit Mathew 	.l1_size = (size_t)ARM_L1_GPT_SIZE,
4686e4859aSRohit Mathew 	.pps = GPCCR_PPS_64GB,
4786e4859aSRohit Mathew 	.pgs = GPCCR_PGS_4K
4886e4859aSRohit Mathew };
4986e4859aSRohit Mathew #endif
5086e4859aSRohit Mathew 
510c306cc0SSoby Mathew void bl2_early_platform_setup2(u_register_t arg0, u_register_t arg1, u_register_t arg2, u_register_t arg3)
523fc4124cSDan Handley {
539c11ed7eSHarrison Mutai #if TRANSFER_LIST
549c11ed7eSHarrison Mutai 	arg0 = arg3;
559c11ed7eSHarrison Mutai #endif
56cab0b5b0SSoby Mathew 	arm_bl2_early_platform_setup((uintptr_t)arg0, (meminfo_t *)arg1);
573fc4124cSDan Handley 
583fc4124cSDan Handley 	/* Initialize the platform config for future decision making */
593fc4124cSDan Handley 	fvp_config_setup();
603fc4124cSDan Handley }
61b49b3221SRyan Harkin 
62b49b3221SRyan Harkin void bl2_platform_setup(void)
63b49b3221SRyan Harkin {
64b49b3221SRyan Harkin 	arm_bl2_platform_setup();
65b49b3221SRyan Harkin 
661b597c22SAlexei Fedorov 	/* Initialize System level generic or SP804 timer */
671b597c22SAlexei Fedorov 	fvp_timer_init();
68b49b3221SRyan Harkin }
697fb9bcd8SManish V Badarkhe 
7086e4859aSRohit Mathew #if ENABLE_RME
7186e4859aSRohit Mathew const arm_gpt_info_t *plat_arm_get_gpt_info(void)
7286e4859aSRohit Mathew {
7386e4859aSRohit Mathew 	return &arm_gpt_info;
7486e4859aSRohit Mathew }
7586e4859aSRohit Mathew #endif /* ENABLE_RME */
7686e4859aSRohit Mathew 
777fb9bcd8SManish V Badarkhe /*******************************************************************************
787fb9bcd8SManish V Badarkhe  * This function returns the list of executable images
797fb9bcd8SManish V Badarkhe  ******************************************************************************/
807fb9bcd8SManish V Badarkhe struct bl_params *plat_get_next_bl_params(void)
817fb9bcd8SManish V Badarkhe {
827fb9bcd8SManish V Badarkhe 	struct bl_params *arm_bl_params;
83568d406cSHarrison Mutai 	bl_mem_params_node_t *param_node __unused;
84a5566f65SHarrison Mutai 	const struct dyn_cfg_dtb_info_t *fw_config_info __unused;
85a5566f65SHarrison Mutai 	const struct dyn_cfg_dtb_info_t *hw_config_info __unused;
86a5566f65SHarrison Mutai 	entry_point_info_t *ep __unused;
87a5566f65SHarrison Mutai 	uint32_t next_exe_img_id __unused;
88a5566f65SHarrison Mutai 	uintptr_t fw_config_base __unused;
897fb9bcd8SManish V Badarkhe 
907fb9bcd8SManish V Badarkhe 	arm_bl_params = arm_get_next_bl_params();
917fb9bcd8SManish V Badarkhe 
9239f0b86aSManish V Badarkhe #if __aarch64__
937fb9bcd8SManish V Badarkhe 	/* Get BL31 image node */
947fb9bcd8SManish V Badarkhe 	param_node = get_bl_mem_params_node(BL31_IMAGE_ID);
9539f0b86aSManish V Badarkhe #else /* aarch32 */
9639f0b86aSManish V Badarkhe 	/* Get SP_MIN image node */
9739f0b86aSManish V Badarkhe 	param_node = get_bl_mem_params_node(BL32_IMAGE_ID);
9839f0b86aSManish V Badarkhe #endif /* __aarch64__ */
997fb9bcd8SManish V Badarkhe 	assert(param_node != NULL);
1007fb9bcd8SManish V Badarkhe 
101a5566f65SHarrison Mutai #if TRANSFER_LIST
102a5566f65SHarrison Mutai 	arm_bl_params->head = &param_node->params_node_mem;
103a5566f65SHarrison Mutai 	arm_bl_params->head->ep_info = &param_node->ep_info;
104a5566f65SHarrison Mutai 	arm_bl_params->head->image_id = param_node->image_id;
105a5566f65SHarrison Mutai 
106a5566f65SHarrison Mutai 	arm_bl2_setup_next_ep_info(param_node);
107a5566f65SHarrison Mutai #elif !RESET_TO_BL2 && !EL3_PAYLOAD_BASE
108a5566f65SHarrison Mutai 	fw_config_base = 0UL;
109a5566f65SHarrison Mutai 
110568d406cSHarrison Mutai 	/* Update the next image's ep info with the FW config address */
1117fb9bcd8SManish V Badarkhe 	fw_config_info = FCONF_GET_PROPERTY(dyn_cfg, dtb, FW_CONFIG_ID);
1127fb9bcd8SManish V Badarkhe 	assert(fw_config_info != NULL);
1137fb9bcd8SManish V Badarkhe 
1147fb9bcd8SManish V Badarkhe 	fw_config_base = fw_config_info->config_addr;
11539f0b86aSManish V Badarkhe 	assert(fw_config_base != 0UL);
1167fb9bcd8SManish V Badarkhe 
117568d406cSHarrison Mutai 	param_node->ep_info.args.arg1 = (uint32_t)fw_config_base;
11839f0b86aSManish V Badarkhe 
119568d406cSHarrison Mutai 	/* Update BL33's ep info with the NS HW config address */
120568d406cSHarrison Mutai 	param_node = get_bl_mem_params_node(BL33_IMAGE_ID);
121568d406cSHarrison Mutai 	assert(param_node != NULL);
122568d406cSHarrison Mutai 
12339f0b86aSManish V Badarkhe 	hw_config_info = FCONF_GET_PROPERTY(dyn_cfg, dtb, HW_CONFIG_ID);
124a42b426bSManish V Badarkhe 	assert(hw_config_info != NULL);
12539f0b86aSManish V Badarkhe 
126568d406cSHarrison Mutai 	param_node->ep_info.args.arg1 = hw_config_info->secondary_config_addr;
12794c90ac8SHarrison Mutai #endif /* TRANSFER_LIST */
1287fb9bcd8SManish V Badarkhe 
1297fb9bcd8SManish V Badarkhe 	return arm_bl_params;
1307fb9bcd8SManish V Badarkhe }
131ed567207SHarrison Mutai 
132ed567207SHarrison Mutai int bl2_plat_handle_post_image_load(unsigned int image_id)
133ed567207SHarrison Mutai {
134a5566f65SHarrison Mutai #if !RESET_TO_BL2 && !EL3_PAYLOAD_BASE && !TRANSFER_LIST
135568d406cSHarrison Mutai 	if (image_id == HW_CONFIG_ID) {
136a5566f65SHarrison Mutai 		const struct dyn_cfg_dtb_info_t *hw_config_info __unused;
137568d406cSHarrison Mutai 		struct transfer_list_entry *te __unused;
138a5566f65SHarrison Mutai 		bl_mem_params_node_t *param_node __unused;
139568d406cSHarrison Mutai 
140a5566f65SHarrison Mutai 		param_node = get_bl_mem_params_node(image_id);
141568d406cSHarrison Mutai 		assert(param_node != NULL);
142568d406cSHarrison Mutai 
143568d406cSHarrison Mutai 		hw_config_info = FCONF_GET_PROPERTY(dyn_cfg, dtb, HW_CONFIG_ID);
144568d406cSHarrison Mutai 		assert(hw_config_info != NULL);
145568d406cSHarrison Mutai 
146568d406cSHarrison Mutai 		memcpy((void *)hw_config_info->secondary_config_addr,
147568d406cSHarrison Mutai 		       (void *)hw_config_info->config_addr,
148568d406cSHarrison Mutai 		       (size_t)param_node->image_info.image_size);
149568d406cSHarrison Mutai 
150568d406cSHarrison Mutai 		/*
151568d406cSHarrison Mutai 		 * Ensure HW-config device tree is committed to memory, as the HW-Config
152568d406cSHarrison Mutai 		 * might be used without cache and MMU enabled at BL33.
153568d406cSHarrison Mutai 		 */
154568d406cSHarrison Mutai 		flush_dcache_range(hw_config_info->secondary_config_addr,
155568d406cSHarrison Mutai 				   param_node->image_info.image_size);
156568d406cSHarrison Mutai 	}
157a5566f65SHarrison Mutai #endif /* !RESET_TO_BL2 && !EL3_PAYLOAD_BASE && !TRANSFER_LIST*/
158568d406cSHarrison Mutai 
159ed567207SHarrison Mutai 	return arm_bl2_plat_handle_post_image_load(image_id);
160ed567207SHarrison Mutai }
161