xref: /rk3399_ARM-atf/plat/common/plat_bl1_common.c (revision 1dcc28cfbac5dae3992ad9581f9ea68f6cb339c1)
1 /*
2  * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #include <arch_helpers.h>
8 #include <assert.h>
9 #include <bl_common.h>
10 #include <bl1.h>
11 #include <debug.h>
12 #include <errno.h>
13 #include <platform.h>
14 #include <platform_def.h>
15 
16 /*
17  * The following platform functions are weakly defined. They
18  * are default implementations that allow BL1 to compile in
19  * absence of real definitions. The Platforms may override
20  * with more complex definitions.
21  */
22 #pragma weak bl1_plat_get_next_image_id
23 #pragma weak bl1_plat_set_ep_info
24 #pragma weak bl1_plat_get_image_desc
25 #pragma weak bl1_plat_fwu_done
26 #pragma weak bl1_plat_handle_pre_image_load
27 #pragma weak bl1_plat_handle_post_image_load
28 
29 
30 unsigned int bl1_plat_get_next_image_id(void)
31 {
32 	/* BL2 load will be done by default. */
33 	return BL2_IMAGE_ID;
34 }
35 
36 void bl1_plat_set_ep_info(unsigned int image_id,
37 		struct entry_point_info *ep_info)
38 {
39 
40 }
41 
42 int bl1_plat_handle_pre_image_load(unsigned int image_id)
43 {
44 	return 0;
45 }
46 
47 /*
48  * Following is the default definition that always
49  * returns BL2 image details.
50  */
51 struct image_desc *bl1_plat_get_image_desc(unsigned int image_id)
52 {
53 	static image_desc_t bl2_img_desc = BL2_IMAGE_DESC;
54 	return &bl2_img_desc;
55 }
56 
57 __dead2 void bl1_plat_fwu_done(void *client_cookie, void *reserved)
58 {
59 	while (1)
60 		wfi();
61 }
62 
63 /*
64  * The Platforms must override with real definition.
65  */
66 #pragma weak bl1_plat_mem_check
67 
68 int bl1_plat_mem_check(uintptr_t mem_base, unsigned int mem_size,
69 		unsigned int flags)
70 {
71 	assert(0);
72 	return -ENOMEM;
73 }
74 
75 /*
76  * Default implementation for bl1_plat_handle_post_image_load(). This function
77  * populates the default arguments to BL2. The BL2 memory layout structure
78  * is allocated and the calculated layout is populated in arg1 to BL2.
79  */
80 int bl1_plat_handle_post_image_load(unsigned int image_id)
81 {
82 	meminfo_t *bl2_tzram_layout;
83 	meminfo_t *bl1_tzram_layout;
84 	image_desc_t *image_desc;
85 	entry_point_info_t *ep_info;
86 
87 	if (image_id != BL2_IMAGE_ID)
88 		return 0;
89 
90 	/* Get the image descriptor */
91 	image_desc = bl1_plat_get_image_desc(BL2_IMAGE_ID);
92 	assert(image_desc != NULL);
93 
94 	/* Get the entry point info */
95 	ep_info = &image_desc->ep_info;
96 
97 	/* Find out how much free trusted ram remains after BL1 load */
98 	bl1_tzram_layout = bl1_plat_sec_mem_layout();
99 
100 	/*
101 	 * Create a new layout of memory for BL2 as seen by BL1 i.e.
102 	 * tell it the amount of total and free memory available.
103 	 * This layout is created at the first free address visible
104 	 * to BL2. BL2 will read the memory layout before using its
105 	 * memory for other purposes.
106 	 */
107 	bl2_tzram_layout = (meminfo_t *) bl1_tzram_layout->total_base;
108 
109 	bl1_calc_bl2_mem_layout(bl1_tzram_layout, bl2_tzram_layout);
110 
111 	ep_info->args.arg1 = (uintptr_t)bl2_tzram_layout;
112 
113 	VERBOSE("BL1: BL2 memory layout address = %p\n",
114 		(void *) bl2_tzram_layout);
115 	return 0;
116 }
117