xref: /rk3399_ARM-atf/plat/common/plat_bl1_common.c (revision 09d40e0e08283a249e7dce0e106c07c5141f9b7e)
17baff11fSYatharth Kochar /*
2101d01e2SSoby Mathew  * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
37baff11fSYatharth Kochar  *
482cb2c1aSdp-arm  * SPDX-License-Identifier: BSD-3-Clause
57baff11fSYatharth Kochar  */
648bfb88eSYatharth Kochar 
748bfb88eSYatharth Kochar #include <assert.h>
848bfb88eSYatharth Kochar #include <errno.h>
9*09d40e0eSAntonio Nino Diaz 
107baff11fSYatharth Kochar #include <platform_def.h>
117baff11fSYatharth Kochar 
12*09d40e0eSAntonio Nino Diaz #include <arch_helpers.h>
13*09d40e0eSAntonio Nino Diaz #include <bl1/bl1.h>
14*09d40e0eSAntonio Nino Diaz #include <common/bl_common.h>
15*09d40e0eSAntonio Nino Diaz #include <common/debug.h>
16*09d40e0eSAntonio Nino Diaz #include <plat/common/platform.h>
17*09d40e0eSAntonio Nino Diaz 
187baff11fSYatharth Kochar /*
197baff11fSYatharth Kochar  * The following platform functions are weakly defined. They
2048bfb88eSYatharth Kochar  * are default implementations that allow BL1 to compile in
217baff11fSYatharth Kochar  * absence of real definitions. The Platforms may override
227baff11fSYatharth Kochar  * with more complex definitions.
237baff11fSYatharth Kochar  */
247baff11fSYatharth Kochar #pragma weak bl1_plat_get_next_image_id
257baff11fSYatharth Kochar #pragma weak bl1_plat_set_ep_info
267baff11fSYatharth Kochar #pragma weak bl1_plat_get_image_desc
2748bfb88eSYatharth Kochar #pragma weak bl1_plat_fwu_done
28566034fcSSoby Mathew #pragma weak bl1_plat_handle_pre_image_load
29566034fcSSoby Mathew #pragma weak bl1_plat_handle_post_image_load
307baff11fSYatharth Kochar 
317baff11fSYatharth Kochar 
327baff11fSYatharth Kochar unsigned int bl1_plat_get_next_image_id(void)
337baff11fSYatharth Kochar {
347baff11fSYatharth Kochar 	/* BL2 load will be done by default. */
357baff11fSYatharth Kochar 	return BL2_IMAGE_ID;
367baff11fSYatharth Kochar }
377baff11fSYatharth Kochar 
387baff11fSYatharth Kochar void bl1_plat_set_ep_info(unsigned int image_id,
396c77e749SSandrine Bailleux 		struct entry_point_info *ep_info)
407baff11fSYatharth Kochar {
417baff11fSYatharth Kochar 
427baff11fSYatharth Kochar }
437baff11fSYatharth Kochar 
44566034fcSSoby Mathew int bl1_plat_handle_pre_image_load(unsigned int image_id)
45566034fcSSoby Mathew {
46566034fcSSoby Mathew 	return 0;
47566034fcSSoby Mathew }
48566034fcSSoby Mathew 
497baff11fSYatharth Kochar /*
507baff11fSYatharth Kochar  * Following is the default definition that always
517baff11fSYatharth Kochar  * returns BL2 image details.
527baff11fSYatharth Kochar  */
536c77e749SSandrine Bailleux struct image_desc *bl1_plat_get_image_desc(unsigned int image_id)
547baff11fSYatharth Kochar {
557baff11fSYatharth Kochar 	static image_desc_t bl2_img_desc = BL2_IMAGE_DESC;
567baff11fSYatharth Kochar 	return &bl2_img_desc;
577baff11fSYatharth Kochar }
5848bfb88eSYatharth Kochar 
591f37b944SDan Handley __dead2 void bl1_plat_fwu_done(void *client_cookie, void *reserved)
6048bfb88eSYatharth Kochar {
6148bfb88eSYatharth Kochar 	while (1)
6248bfb88eSYatharth Kochar 		wfi();
6348bfb88eSYatharth Kochar }
6448bfb88eSYatharth Kochar 
6548bfb88eSYatharth Kochar /*
6648bfb88eSYatharth Kochar  * The Platforms must override with real definition.
6748bfb88eSYatharth Kochar  */
6848bfb88eSYatharth Kochar #pragma weak bl1_plat_mem_check
6948bfb88eSYatharth Kochar 
7048bfb88eSYatharth Kochar int bl1_plat_mem_check(uintptr_t mem_base, unsigned int mem_size,
7148bfb88eSYatharth Kochar 		unsigned int flags)
7248bfb88eSYatharth Kochar {
7348bfb88eSYatharth Kochar 	assert(0);
7448bfb88eSYatharth Kochar 	return -ENOMEM;
7548bfb88eSYatharth Kochar }
76101d01e2SSoby Mathew 
77101d01e2SSoby Mathew /*
78101d01e2SSoby Mathew  * Default implementation for bl1_plat_handle_post_image_load(). This function
79101d01e2SSoby Mathew  * populates the default arguments to BL2. The BL2 memory layout structure
80101d01e2SSoby Mathew  * is allocated and the calculated layout is populated in arg1 to BL2.
81101d01e2SSoby Mathew  */
82101d01e2SSoby Mathew int bl1_plat_handle_post_image_load(unsigned int image_id)
83101d01e2SSoby Mathew {
84101d01e2SSoby Mathew 	meminfo_t *bl2_tzram_layout;
85101d01e2SSoby Mathew 	meminfo_t *bl1_tzram_layout;
86101d01e2SSoby Mathew 	image_desc_t *image_desc;
87101d01e2SSoby Mathew 	entry_point_info_t *ep_info;
88101d01e2SSoby Mathew 
89101d01e2SSoby Mathew 	if (image_id != BL2_IMAGE_ID)
90101d01e2SSoby Mathew 		return 0;
91101d01e2SSoby Mathew 
92101d01e2SSoby Mathew 	/* Get the image descriptor */
93101d01e2SSoby Mathew 	image_desc = bl1_plat_get_image_desc(BL2_IMAGE_ID);
94da5f2745SSoby Mathew 	assert(image_desc != NULL);
95101d01e2SSoby Mathew 
96101d01e2SSoby Mathew 	/* Get the entry point info */
97101d01e2SSoby Mathew 	ep_info = &image_desc->ep_info;
98101d01e2SSoby Mathew 
99101d01e2SSoby Mathew 	/* Find out how much free trusted ram remains after BL1 load */
100101d01e2SSoby Mathew 	bl1_tzram_layout = bl1_plat_sec_mem_layout();
101101d01e2SSoby Mathew 
102101d01e2SSoby Mathew 	/*
103101d01e2SSoby Mathew 	 * Create a new layout of memory for BL2 as seen by BL1 i.e.
104101d01e2SSoby Mathew 	 * tell it the amount of total and free memory available.
105101d01e2SSoby Mathew 	 * This layout is created at the first free address visible
106101d01e2SSoby Mathew 	 * to BL2. BL2 will read the memory layout before using its
107101d01e2SSoby Mathew 	 * memory for other purposes.
108101d01e2SSoby Mathew 	 */
109101d01e2SSoby Mathew 	bl2_tzram_layout = (meminfo_t *) bl1_tzram_layout->total_base;
110101d01e2SSoby Mathew 
111101d01e2SSoby Mathew 	bl1_calc_bl2_mem_layout(bl1_tzram_layout, bl2_tzram_layout);
112101d01e2SSoby Mathew 
113101d01e2SSoby Mathew 	ep_info->args.arg1 = (uintptr_t)bl2_tzram_layout;
114101d01e2SSoby Mathew 
115101d01e2SSoby Mathew 	VERBOSE("BL1: BL2 memory layout address = %p\n",
116101d01e2SSoby Mathew 		(void *) bl2_tzram_layout);
117101d01e2SSoby Mathew 	return 0;
118101d01e2SSoby Mathew }
119