xref: /rk3399_ARM-atf/plat/arm/common/arm_dyn_cfg.c (revision 73a9605197ba04aaf02d436a2a4ad56e695b426c)
1 /*
2  * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #include <arm_dyn_cfg_helpers.h>
8 #include <assert.h>
9 #include <debug.h>
10 #include <desc_image_load.h>
11 #include <plat_arm.h>
12 #include <platform.h>
13 #include <platform_def.h>
14 #include <string.h>
15 #include <tbbr_img_def.h>
16 
17 #if LOAD_IMAGE_V2
18 
19 /* Variable to store the address to TB_FW_CONFIG passed from BL1 */
20 static void *tb_fw_cfg_dtb;
21 
22 /*
23  * Helper function to load TB_FW_CONFIG and populate the load information to
24  * arg0 of BL2 entrypoint info.
25  */
26 void arm_load_tb_fw_config(void)
27 {
28 	int err;
29 	uintptr_t config_base = 0;
30 	image_desc_t *image_desc;
31 
32 	image_desc_t arm_tb_fw_info = {
33 		.image_id = TB_FW_CONFIG_ID,
34 		SET_STATIC_PARAM_HEAD(image_info, PARAM_IMAGE_BINARY,
35 				VERSION_2, image_info_t, 0),
36 		.image_info.image_base = ARM_TB_FW_CONFIG_BASE,
37 		.image_info.image_max_size = ARM_TB_FW_CONFIG_LIMIT - ARM_TB_FW_CONFIG_BASE,
38 	};
39 
40 	VERBOSE("BL1: Loading TB_FW_CONFIG\n");
41 	err = load_auth_image(TB_FW_CONFIG_ID, &arm_tb_fw_info.image_info);
42 	if (err != 0) {
43 		/* Return if TB_FW_CONFIG is not loaded */
44 		VERBOSE("Failed to load TB_FW_CONFIG\n");
45 		return;
46 	}
47 
48 	config_base = arm_tb_fw_info.image_info.image_base;
49 
50 	/* The BL2 ep_info arg0 is modified to point to TB_FW_CONFIG */
51 	image_desc = bl1_plat_get_image_desc(BL2_IMAGE_ID);
52 	assert(image_desc != NULL);
53 	image_desc->ep_info.args.arg0 = config_base;
54 
55 	INFO("BL1: TB_FW_CONFIG loaded at address = %p\n",
56 			(void *) config_base);
57 }
58 
59 /*
60  * BL2 utility function to set the address of TB_FW_CONFIG passed from BL1.
61  */
62 void arm_bl2_set_tb_cfg_addr(void *dtb)
63 {
64 	assert(dtb != NULL);
65 	tb_fw_cfg_dtb = dtb;
66 }
67 
68 /*
69  * BL2 utility function to initialize dynamic configuration specified by
70  * TB_FW_CONFIG. Return early if TB_FW_CONFIG is not found or HW_CONFIG is
71  * not specified in TB_FW_CONFIG.
72  */
73 void arm_bl2_dyn_cfg_init(void)
74 {
75 	int err = 0;
76 	int tb_fw_node;
77 	bl_mem_params_node_t *hw_cfg_mem_params = NULL;
78 
79 	if (tb_fw_cfg_dtb == NULL) {
80 		VERBOSE("No TB_FW_CONFIG specified\n");
81 		return;
82 	}
83 
84 	err = arm_dyn_tb_fw_cfg_init((void *)tb_fw_cfg_dtb, &tb_fw_node);
85 	if (err < 0) {
86 		ERROR("Invalid TB_FW_CONFIG passed from BL1\n");
87 		panic();
88 	}
89 
90 	/* Get the hw_config load address and size from TB_FW_CONFIG */
91 	hw_cfg_mem_params = get_bl_mem_params_node(HW_CONFIG_ID);
92 	if (hw_cfg_mem_params == NULL) {
93 		VERBOSE("Couldn't find HW_CONFIG in bl_mem_params_node\n");
94 		return;
95 	}
96 
97 	err = arm_dyn_get_hwconfig_info((void *)tb_fw_cfg_dtb, tb_fw_node,
98 		(uint64_t *) &hw_cfg_mem_params->image_info.image_base,
99 		&hw_cfg_mem_params->image_info.image_max_size);
100 	if (err < 0) {
101 		VERBOSE("Couldn't find HW_CONFIG load info in TB_FW_CONFIG\n");
102 		return;
103 	}
104 
105 	/* Remove the IMAGE_ATTRIB_SKIP_LOADING attribute from HW_CONFIG node */
106 	hw_cfg_mem_params->image_info.h.attr &= ~IMAGE_ATTRIB_SKIP_LOADING;
107 }
108 
109 #endif /* LOAD_IMAGE_V2 */
110