17baff11fSYatharth Kochar /* 2*6a4da290SHarrison Mutai * Copyright (c) 2015-2024, 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> 909d40e0eSAntonio Nino Diaz 107baff11fSYatharth Kochar #include <platform_def.h> 117baff11fSYatharth Kochar 1209d40e0eSAntonio Nino Diaz #include <arch_helpers.h> 1309d40e0eSAntonio Nino Diaz #include <bl1/bl1.h> 1409d40e0eSAntonio Nino Diaz #include <common/bl_common.h> 1509d40e0eSAntonio Nino Diaz #include <common/debug.h> 1609d40e0eSAntonio Nino Diaz #include <plat/common/platform.h> 1709d40e0eSAntonio 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 unsigned int bl1_plat_get_next_image_id(void) 327baff11fSYatharth Kochar { 337baff11fSYatharth Kochar /* BL2 load will be done by default. */ 347baff11fSYatharth Kochar return BL2_IMAGE_ID; 357baff11fSYatharth Kochar } 367baff11fSYatharth Kochar 377baff11fSYatharth Kochar void bl1_plat_set_ep_info(unsigned int image_id, 386c77e749SSandrine Bailleux struct entry_point_info *ep_info) 397baff11fSYatharth Kochar { 407baff11fSYatharth Kochar 417baff11fSYatharth Kochar } 427baff11fSYatharth Kochar 43566034fcSSoby Mathew int bl1_plat_handle_pre_image_load(unsigned int image_id) 44566034fcSSoby Mathew { 45566034fcSSoby Mathew return 0; 46566034fcSSoby Mathew } 47566034fcSSoby Mathew 487baff11fSYatharth Kochar /* 497baff11fSYatharth Kochar * Following is the default definition that always 507baff11fSYatharth Kochar * returns BL2 image details. 517baff11fSYatharth Kochar */ 526c77e749SSandrine Bailleux struct image_desc *bl1_plat_get_image_desc(unsigned int image_id) 537baff11fSYatharth Kochar { 547baff11fSYatharth Kochar static image_desc_t bl2_img_desc = BL2_IMAGE_DESC; 557baff11fSYatharth Kochar return &bl2_img_desc; 567baff11fSYatharth Kochar } 5748bfb88eSYatharth Kochar 581f37b944SDan Handley __dead2 void bl1_plat_fwu_done(void *client_cookie, void *reserved) 5948bfb88eSYatharth Kochar { 6092069086SJimmy Brisson while (true) 6148bfb88eSYatharth Kochar wfi(); 6248bfb88eSYatharth Kochar } 6348bfb88eSYatharth Kochar 6448bfb88eSYatharth Kochar /* 6548bfb88eSYatharth Kochar * The Platforms must override with real definition. 6648bfb88eSYatharth Kochar */ 6748bfb88eSYatharth Kochar #pragma weak bl1_plat_mem_check 6848bfb88eSYatharth Kochar 6948bfb88eSYatharth Kochar int bl1_plat_mem_check(uintptr_t mem_base, unsigned int mem_size, 7048bfb88eSYatharth Kochar unsigned int flags) 7148bfb88eSYatharth Kochar { 7248bfb88eSYatharth Kochar assert(0); 7348bfb88eSYatharth Kochar return -ENOMEM; 7448bfb88eSYatharth Kochar } 75101d01e2SSoby Mathew 76101d01e2SSoby Mathew /* 77101d01e2SSoby Mathew * Default implementation for bl1_plat_handle_post_image_load(). This function 78101d01e2SSoby Mathew * populates the default arguments to BL2. The BL2 memory layout structure 79101d01e2SSoby Mathew * is allocated and the calculated layout is populated in arg1 to BL2. 80101d01e2SSoby Mathew */ 81101d01e2SSoby Mathew int bl1_plat_handle_post_image_load(unsigned int image_id) 82101d01e2SSoby Mathew { 83*6a4da290SHarrison Mutai meminfo_t *bl1_tzram_layout; 84101d01e2SSoby Mathew image_desc_t *image_desc; 85101d01e2SSoby Mathew 86101d01e2SSoby Mathew if (image_id != BL2_IMAGE_ID) 87101d01e2SSoby Mathew return 0; 88101d01e2SSoby Mathew 89101d01e2SSoby Mathew /* Get the image descriptor */ 90101d01e2SSoby Mathew image_desc = bl1_plat_get_image_desc(BL2_IMAGE_ID); 91da5f2745SSoby Mathew assert(image_desc != NULL); 92101d01e2SSoby Mathew 93101d01e2SSoby Mathew /* Find out how much free trusted ram remains after BL1 load */ 94*6a4da290SHarrison Mutai bl1_tzram_layout = bl1_plat_sec_mem_layout(); 95101d01e2SSoby Mathew 96101d01e2SSoby Mathew /* 97*6a4da290SHarrison Mutai * Convey this information to BL2 by storing the layout at the first free 98*6a4da290SHarrison Mutai * address visible to BL2. 99101d01e2SSoby Mathew */ 100*6a4da290SHarrison Mutai bl1_plat_calc_bl2_layout(bl1_tzram_layout, 101*6a4da290SHarrison Mutai (meminfo_t *)bl1_tzram_layout->total_base); 102101d01e2SSoby Mathew 103*6a4da290SHarrison Mutai image_desc->ep_info.args.arg1 = (uintptr_t)bl1_tzram_layout->total_base; 104101d01e2SSoby Mathew 105101d01e2SSoby Mathew VERBOSE("BL1: BL2 memory layout address = %p\n", 106*6a4da290SHarrison Mutai (void *)image_desc->ep_info.args.arg1); 107*6a4da290SHarrison Mutai 108101d01e2SSoby Mathew return 0; 109101d01e2SSoby Mathew } 110*6a4da290SHarrison Mutai 111*6a4da290SHarrison Mutai /******************************************************************************* 112*6a4da290SHarrison Mutai * Helper utility to calculate the BL2 memory layout taking into consideration 113*6a4da290SHarrison Mutai * the BL1 RW data assuming that it is at the top of the memory layout. 114*6a4da290SHarrison Mutai ******************************************************************************/ 115*6a4da290SHarrison Mutai void bl1_plat_calc_bl2_layout(const meminfo_t *bl1_mem_layout, 116*6a4da290SHarrison Mutai meminfo_t *bl2_mem_layout) 117*6a4da290SHarrison Mutai { 118*6a4da290SHarrison Mutai assert(bl1_mem_layout != NULL); 119*6a4da290SHarrison Mutai assert(bl2_mem_layout != NULL); 120*6a4da290SHarrison Mutai 121*6a4da290SHarrison Mutai /* 122*6a4da290SHarrison Mutai * Remove BL1 RW data from the scope of memory visible to BL2. 123*6a4da290SHarrison Mutai * This is assuming BL1 RW data is at the top of bl1_mem_layout. 124*6a4da290SHarrison Mutai */ 125*6a4da290SHarrison Mutai assert(BL1_RW_BASE > bl1_mem_layout->total_base); 126*6a4da290SHarrison Mutai bl2_mem_layout->total_base = bl1_mem_layout->total_base; 127*6a4da290SHarrison Mutai bl2_mem_layout->total_size = BL1_RW_BASE - bl1_mem_layout->total_base; 128*6a4da290SHarrison Mutai 129*6a4da290SHarrison Mutai flush_dcache_range((uintptr_t)bl2_mem_layout, sizeof(meminfo_t)); 130*6a4da290SHarrison Mutai } 131