blob: bcf9f8956566e4566d3102512498fa2d8deb1b59 [file] [log] [blame]
Yatharth Kochara65be2f2015-10-09 18:06:13 +01001/*
Manish V Badarkhe3ff0f792021-08-10 20:51:55 +01002 * Copyright (c) 2015-2021, Arm Limited and Contributors. All rights reserved.
Yatharth Kochara65be2f2015-10-09 18:06:13 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Yatharth Kochara65be2f2015-10-09 18:06:13 +01005 */
Yatharth Kochar71c9a5e2015-10-10 19:06:53 +01006
Yatharth Kochar71c9a5e2015-10-10 19:06:53 +01007#include <assert.h>
Yatharth Kochar71c9a5e2015-10-10 19:06:53 +01008#include <errno.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00009
Yatharth Kochara65be2f2015-10-09 18:06:13 +010010#include <platform_def.h>
11
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000012#include <arch_helpers.h>
13#include <bl1/bl1.h>
14#include <common/bl_common.h>
15#include <common/debug.h>
16#include <plat/common/platform.h>
17
Yatharth Kochara65be2f2015-10-09 18:06:13 +010018/*
19 * The following platform functions are weakly defined. They
Yatharth Kochar71c9a5e2015-10-10 19:06:53 +010020 * are default implementations that allow BL1 to compile in
Yatharth Kochara65be2f2015-10-09 18:06:13 +010021 * absence of real definitions. The Platforms may override
22 * with more complex definitions.
23 */
24#pragma weak bl1_plat_get_next_image_id
25#pragma weak bl1_plat_set_ep_info
26#pragma weak bl1_plat_get_image_desc
Yatharth Kochar71c9a5e2015-10-10 19:06:53 +010027#pragma weak bl1_plat_fwu_done
Soby Mathew2f38ce32018-02-08 17:45:12 +000028#pragma weak bl1_plat_handle_pre_image_load
29#pragma weak bl1_plat_handle_post_image_load
Yatharth Kochara65be2f2015-10-09 18:06:13 +010030
31unsigned int bl1_plat_get_next_image_id(void)
32{
33 /* BL2 load will be done by default. */
34 return BL2_IMAGE_ID;
35}
36
37void bl1_plat_set_ep_info(unsigned int image_id,
Sandrine Bailleuxb3b6e222018-07-11 12:44:22 +020038 struct entry_point_info *ep_info)
Yatharth Kochara65be2f2015-10-09 18:06:13 +010039{
40
41}
42
Soby Mathew2f38ce32018-02-08 17:45:12 +000043int bl1_plat_handle_pre_image_load(unsigned int image_id)
44{
45 return 0;
46}
47
Yatharth Kochara65be2f2015-10-09 18:06:13 +010048/*
49 * Following is the default definition that always
50 * returns BL2 image details.
51 */
Sandrine Bailleuxb3b6e222018-07-11 12:44:22 +020052struct image_desc *bl1_plat_get_image_desc(unsigned int image_id)
Yatharth Kochara65be2f2015-10-09 18:06:13 +010053{
54 static image_desc_t bl2_img_desc = BL2_IMAGE_DESC;
55 return &bl2_img_desc;
56}
Yatharth Kochar71c9a5e2015-10-10 19:06:53 +010057
Dan Handley89f8f332015-12-15 14:28:24 +000058__dead2 void bl1_plat_fwu_done(void *client_cookie, void *reserved)
Yatharth Kochar71c9a5e2015-10-10 19:06:53 +010059{
Jimmy Brisson471550a2020-08-06 10:50:15 -050060 while (true)
Yatharth Kochar71c9a5e2015-10-10 19:06:53 +010061 wfi();
62}
63
64/*
65 * The Platforms must override with real definition.
66 */
67#pragma weak bl1_plat_mem_check
68
69int bl1_plat_mem_check(uintptr_t mem_base, unsigned int mem_size,
70 unsigned int flags)
71{
72 assert(0);
73 return -ENOMEM;
74}
Soby Mathew6e16a332018-01-10 12:51:34 +000075
76/*
77 * Default implementation for bl1_plat_handle_post_image_load(). This function
78 * populates the default arguments to BL2. The BL2 memory layout structure
79 * is allocated and the calculated layout is populated in arg1 to BL2.
80 */
81int bl1_plat_handle_post_image_load(unsigned int image_id)
82{
Jimmy Brissond7297c72020-08-05 14:05:53 -050083 meminfo_t *bl2_secram_layout;
84 meminfo_t *bl1_secram_layout;
Soby Mathew6e16a332018-01-10 12:51:34 +000085 image_desc_t *image_desc;
86 entry_point_info_t *ep_info;
87
88 if (image_id != BL2_IMAGE_ID)
89 return 0;
90
91 /* Get the image descriptor */
92 image_desc = bl1_plat_get_image_desc(BL2_IMAGE_ID);
Soby Mathewcc364842018-02-21 01:16:39 +000093 assert(image_desc != NULL);
Soby Mathew6e16a332018-01-10 12:51:34 +000094
95 /* Get the entry point info */
96 ep_info = &image_desc->ep_info;
97
98 /* Find out how much free trusted ram remains after BL1 load */
Jimmy Brissond7297c72020-08-05 14:05:53 -050099 bl1_secram_layout = bl1_plat_sec_mem_layout();
Soby Mathew6e16a332018-01-10 12:51:34 +0000100
101 /*
102 * Create a new layout of memory for BL2 as seen by BL1 i.e.
103 * tell it the amount of total and free memory available.
104 * This layout is created at the first free address visible
105 * to BL2. BL2 will read the memory layout before using its
106 * memory for other purposes.
107 */
Jimmy Brissond7297c72020-08-05 14:05:53 -0500108 bl2_secram_layout = (meminfo_t *) bl1_secram_layout->total_base;
Soby Mathew6e16a332018-01-10 12:51:34 +0000109
Jimmy Brissond7297c72020-08-05 14:05:53 -0500110 bl1_calc_bl2_mem_layout(bl1_secram_layout, bl2_secram_layout);
Soby Mathew6e16a332018-01-10 12:51:34 +0000111
Jimmy Brissond7297c72020-08-05 14:05:53 -0500112 ep_info->args.arg1 = (uintptr_t)bl2_secram_layout;
Soby Mathew6e16a332018-01-10 12:51:34 +0000113
114 VERBOSE("BL1: BL2 memory layout address = %p\n",
Jimmy Brissond7297c72020-08-05 14:05:53 -0500115 (void *) bl2_secram_layout);
Soby Mathew6e16a332018-01-10 12:51:34 +0000116 return 0;
117}