refactor(bl1): clean up bl2 layout calculation
Layout calculation is spread out between core BL1 logic and common
platform code. Relocate these into common platform code so they are
organised logically.
Change-Id: I8b05403e41b800957a0367316cecd373d10bb1a4
Signed-off-by: Harrison Mutai <harrison.mutai@arm.com>
diff --git a/plat/common/plat_bl1_common.c b/plat/common/plat_bl1_common.c
index bcf9f89..ff0e082 100644
--- a/plat/common/plat_bl1_common.c
+++ b/plat/common/plat_bl1_common.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015-2021, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2015-2024, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -80,10 +80,8 @@
*/
int bl1_plat_handle_post_image_load(unsigned int image_id)
{
- meminfo_t *bl2_secram_layout;
- meminfo_t *bl1_secram_layout;
+ meminfo_t *bl1_tzram_layout;
image_desc_t *image_desc;
- entry_point_info_t *ep_info;
if (image_id != BL2_IMAGE_ID)
return 0;
@@ -92,26 +90,41 @@
image_desc = bl1_plat_get_image_desc(BL2_IMAGE_ID);
assert(image_desc != NULL);
- /* Get the entry point info */
- ep_info = &image_desc->ep_info;
-
/* Find out how much free trusted ram remains after BL1 load */
- bl1_secram_layout = bl1_plat_sec_mem_layout();
+ bl1_tzram_layout = bl1_plat_sec_mem_layout();
/*
- * Create a new layout of memory for BL2 as seen by BL1 i.e.
- * tell it the amount of total and free memory available.
- * This layout is created at the first free address visible
- * to BL2. BL2 will read the memory layout before using its
- * memory for other purposes.
+ * Convey this information to BL2 by storing the layout at the first free
+ * address visible to BL2.
*/
- bl2_secram_layout = (meminfo_t *) bl1_secram_layout->total_base;
+ bl1_plat_calc_bl2_layout(bl1_tzram_layout,
+ (meminfo_t *)bl1_tzram_layout->total_base);
- bl1_calc_bl2_mem_layout(bl1_secram_layout, bl2_secram_layout);
-
- ep_info->args.arg1 = (uintptr_t)bl2_secram_layout;
+ image_desc->ep_info.args.arg1 = (uintptr_t)bl1_tzram_layout->total_base;
VERBOSE("BL1: BL2 memory layout address = %p\n",
- (void *) bl2_secram_layout);
+ (void *)image_desc->ep_info.args.arg1);
+
return 0;
}
+
+/*******************************************************************************
+ * Helper utility to calculate the BL2 memory layout taking into consideration
+ * the BL1 RW data assuming that it is at the top of the memory layout.
+ ******************************************************************************/
+void bl1_plat_calc_bl2_layout(const meminfo_t *bl1_mem_layout,
+ meminfo_t *bl2_mem_layout)
+{
+ assert(bl1_mem_layout != NULL);
+ assert(bl2_mem_layout != NULL);
+
+ /*
+ * Remove BL1 RW data from the scope of memory visible to BL2.
+ * This is assuming BL1 RW data is at the top of bl1_mem_layout.
+ */
+ assert(BL1_RW_BASE > bl1_mem_layout->total_base);
+ bl2_mem_layout->total_base = bl1_mem_layout->total_base;
+ bl2_mem_layout->total_size = BL1_RW_BASE - bl1_mem_layout->total_base;
+
+ flush_dcache_range((uintptr_t)bl2_mem_layout, sizeof(meminfo_t));
+}