Yatharth Kochar | a65be2f | 2015-10-09 18:06:13 +0100 | [diff] [blame] | 1 | /* |
Harrison Mutai | faf3ac3 | 2024-01-04 16:18:47 +0000 | [diff] [blame] | 2 | * Copyright (c) 2015-2024, Arm Limited and Contributors. All rights reserved. |
Yatharth Kochar | a65be2f | 2015-10-09 18:06:13 +0100 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Yatharth Kochar | a65be2f | 2015-10-09 18:06:13 +0100 | [diff] [blame] | 5 | */ |
Yatharth Kochar | 71c9a5e | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 6 | |
Yatharth Kochar | 71c9a5e | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 7 | #include <assert.h> |
Yatharth Kochar | 71c9a5e | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 8 | #include <errno.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 9 | |
Yatharth Kochar | a65be2f | 2015-10-09 18:06:13 +0100 | [diff] [blame] | 10 | #include <platform_def.h> |
| 11 | |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 12 | #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 Kochar | a65be2f | 2015-10-09 18:06:13 +0100 | [diff] [blame] | 18 | /* |
| 19 | * The following platform functions are weakly defined. They |
Yatharth Kochar | 71c9a5e | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 20 | * are default implementations that allow BL1 to compile in |
Yatharth Kochar | a65be2f | 2015-10-09 18:06:13 +0100 | [diff] [blame] | 21 | * 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 Kochar | 71c9a5e | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 27 | #pragma weak bl1_plat_fwu_done |
Soby Mathew | 2f38ce3 | 2018-02-08 17:45:12 +0000 | [diff] [blame] | 28 | #pragma weak bl1_plat_handle_pre_image_load |
| 29 | #pragma weak bl1_plat_handle_post_image_load |
Yatharth Kochar | a65be2f | 2015-10-09 18:06:13 +0100 | [diff] [blame] | 30 | |
| 31 | unsigned int bl1_plat_get_next_image_id(void) |
| 32 | { |
| 33 | /* BL2 load will be done by default. */ |
| 34 | return BL2_IMAGE_ID; |
| 35 | } |
| 36 | |
| 37 | void bl1_plat_set_ep_info(unsigned int image_id, |
Sandrine Bailleux | b3b6e22 | 2018-07-11 12:44:22 +0200 | [diff] [blame] | 38 | struct entry_point_info *ep_info) |
Yatharth Kochar | a65be2f | 2015-10-09 18:06:13 +0100 | [diff] [blame] | 39 | { |
| 40 | |
| 41 | } |
| 42 | |
Soby Mathew | 2f38ce3 | 2018-02-08 17:45:12 +0000 | [diff] [blame] | 43 | int bl1_plat_handle_pre_image_load(unsigned int image_id) |
| 44 | { |
| 45 | return 0; |
| 46 | } |
| 47 | |
Yatharth Kochar | a65be2f | 2015-10-09 18:06:13 +0100 | [diff] [blame] | 48 | /* |
| 49 | * Following is the default definition that always |
| 50 | * returns BL2 image details. |
| 51 | */ |
Sandrine Bailleux | b3b6e22 | 2018-07-11 12:44:22 +0200 | [diff] [blame] | 52 | struct image_desc *bl1_plat_get_image_desc(unsigned int image_id) |
Yatharth Kochar | a65be2f | 2015-10-09 18:06:13 +0100 | [diff] [blame] | 53 | { |
| 54 | static image_desc_t bl2_img_desc = BL2_IMAGE_DESC; |
| 55 | return &bl2_img_desc; |
| 56 | } |
Yatharth Kochar | 71c9a5e | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 57 | |
Dan Handley | 89f8f33 | 2015-12-15 14:28:24 +0000 | [diff] [blame] | 58 | __dead2 void bl1_plat_fwu_done(void *client_cookie, void *reserved) |
Yatharth Kochar | 71c9a5e | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 59 | { |
Jimmy Brisson | 471550a | 2020-08-06 10:50:15 -0500 | [diff] [blame] | 60 | while (true) |
Yatharth Kochar | 71c9a5e | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 61 | wfi(); |
| 62 | } |
| 63 | |
| 64 | /* |
| 65 | * The Platforms must override with real definition. |
| 66 | */ |
| 67 | #pragma weak bl1_plat_mem_check |
| 68 | |
| 69 | int 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 Mathew | 6e16a33 | 2018-01-10 12:51:34 +0000 | [diff] [blame] | 75 | |
| 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 | */ |
| 81 | int bl1_plat_handle_post_image_load(unsigned int image_id) |
| 82 | { |
Harrison Mutai | faf3ac3 | 2024-01-04 16:18:47 +0000 | [diff] [blame] | 83 | meminfo_t *bl1_tzram_layout; |
Soby Mathew | 6e16a33 | 2018-01-10 12:51:34 +0000 | [diff] [blame] | 84 | image_desc_t *image_desc; |
Soby Mathew | 6e16a33 | 2018-01-10 12:51:34 +0000 | [diff] [blame] | 85 | |
| 86 | if (image_id != BL2_IMAGE_ID) |
| 87 | return 0; |
| 88 | |
| 89 | /* Get the image descriptor */ |
| 90 | image_desc = bl1_plat_get_image_desc(BL2_IMAGE_ID); |
Soby Mathew | cc36484 | 2018-02-21 01:16:39 +0000 | [diff] [blame] | 91 | assert(image_desc != NULL); |
Soby Mathew | 6e16a33 | 2018-01-10 12:51:34 +0000 | [diff] [blame] | 92 | |
Soby Mathew | 6e16a33 | 2018-01-10 12:51:34 +0000 | [diff] [blame] | 93 | /* Find out how much free trusted ram remains after BL1 load */ |
Harrison Mutai | faf3ac3 | 2024-01-04 16:18:47 +0000 | [diff] [blame] | 94 | bl1_tzram_layout = bl1_plat_sec_mem_layout(); |
Soby Mathew | 6e16a33 | 2018-01-10 12:51:34 +0000 | [diff] [blame] | 95 | |
| 96 | /* |
Harrison Mutai | faf3ac3 | 2024-01-04 16:18:47 +0000 | [diff] [blame] | 97 | * Convey this information to BL2 by storing the layout at the first free |
| 98 | * address visible to BL2. |
Soby Mathew | 6e16a33 | 2018-01-10 12:51:34 +0000 | [diff] [blame] | 99 | */ |
Harrison Mutai | faf3ac3 | 2024-01-04 16:18:47 +0000 | [diff] [blame] | 100 | bl1_plat_calc_bl2_layout(bl1_tzram_layout, |
| 101 | (meminfo_t *)bl1_tzram_layout->total_base); |
Soby Mathew | 6e16a33 | 2018-01-10 12:51:34 +0000 | [diff] [blame] | 102 | |
Harrison Mutai | faf3ac3 | 2024-01-04 16:18:47 +0000 | [diff] [blame] | 103 | image_desc->ep_info.args.arg1 = (uintptr_t)bl1_tzram_layout->total_base; |
Soby Mathew | 6e16a33 | 2018-01-10 12:51:34 +0000 | [diff] [blame] | 104 | |
| 105 | VERBOSE("BL1: BL2 memory layout address = %p\n", |
Harrison Mutai | faf3ac3 | 2024-01-04 16:18:47 +0000 | [diff] [blame] | 106 | (void *)image_desc->ep_info.args.arg1); |
| 107 | |
Soby Mathew | 6e16a33 | 2018-01-10 12:51:34 +0000 | [diff] [blame] | 108 | return 0; |
| 109 | } |
Harrison Mutai | faf3ac3 | 2024-01-04 16:18:47 +0000 | [diff] [blame] | 110 | |
| 111 | /******************************************************************************* |
| 112 | * Helper utility to calculate the BL2 memory layout taking into consideration |
| 113 | * the BL1 RW data assuming that it is at the top of the memory layout. |
| 114 | ******************************************************************************/ |
| 115 | void bl1_plat_calc_bl2_layout(const meminfo_t *bl1_mem_layout, |
| 116 | meminfo_t *bl2_mem_layout) |
| 117 | { |
| 118 | assert(bl1_mem_layout != NULL); |
| 119 | assert(bl2_mem_layout != NULL); |
| 120 | |
| 121 | /* |
| 122 | * Remove BL1 RW data from the scope of memory visible to BL2. |
| 123 | * This is assuming BL1 RW data is at the top of bl1_mem_layout. |
| 124 | */ |
| 125 | assert(BL1_RW_BASE > bl1_mem_layout->total_base); |
| 126 | bl2_mem_layout->total_base = bl1_mem_layout->total_base; |
| 127 | bl2_mem_layout->total_size = BL1_RW_BASE - bl1_mem_layout->total_base; |
| 128 | |
| 129 | flush_dcache_range((uintptr_t)bl2_mem_layout, sizeof(meminfo_t)); |
| 130 | } |