Yatharth Kochar | 7baff11 | 2015-10-09 18:06:13 +0100 | [diff] [blame] | 1 | /* |
Soby Mathew | 101d01e | 2018-01-10 12:51:34 +0000 | [diff] [blame] | 2 | * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved. |
Yatharth Kochar | 7baff11 | 2015-10-09 18:06:13 +0100 | [diff] [blame] | 3 | * |
dp-arm | 82cb2c1 | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Yatharth Kochar | 7baff11 | 2015-10-09 18:06:13 +0100 | [diff] [blame] | 5 | */ |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 6 | |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 7 | #include <assert.h> |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 8 | #include <errno.h> |
Antonio Nino Diaz | 09d40e0 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 9 | |
Yatharth Kochar | 7baff11 | 2015-10-09 18:06:13 +0100 | [diff] [blame] | 10 | #include <platform_def.h> |
| 11 | |
Antonio Nino Diaz | 09d40e0 | 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 | 7baff11 | 2015-10-09 18:06:13 +0100 | [diff] [blame] | 18 | /* |
| 19 | * The following platform functions are weakly defined. They |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 20 | * are default implementations that allow BL1 to compile in |
Yatharth Kochar | 7baff11 | 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 | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 27 | #pragma weak bl1_plat_fwu_done |
Soby Mathew | 566034f | 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 | 7baff11 | 2015-10-09 18:06:13 +0100 | [diff] [blame] | 30 | |
| 31 | |
| 32 | unsigned int bl1_plat_get_next_image_id(void) |
| 33 | { |
| 34 | /* BL2 load will be done by default. */ |
| 35 | return BL2_IMAGE_ID; |
| 36 | } |
| 37 | |
| 38 | void bl1_plat_set_ep_info(unsigned int image_id, |
Sandrine Bailleux | 6c77e74 | 2018-07-11 12:44:22 +0200 | [diff] [blame] | 39 | struct entry_point_info *ep_info) |
Yatharth Kochar | 7baff11 | 2015-10-09 18:06:13 +0100 | [diff] [blame] | 40 | { |
| 41 | |
| 42 | } |
| 43 | |
Soby Mathew | 566034f | 2018-02-08 17:45:12 +0000 | [diff] [blame] | 44 | int bl1_plat_handle_pre_image_load(unsigned int image_id) |
| 45 | { |
| 46 | return 0; |
| 47 | } |
| 48 | |
Yatharth Kochar | 7baff11 | 2015-10-09 18:06:13 +0100 | [diff] [blame] | 49 | /* |
| 50 | * Following is the default definition that always |
| 51 | * returns BL2 image details. |
| 52 | */ |
Sandrine Bailleux | 6c77e74 | 2018-07-11 12:44:22 +0200 | [diff] [blame] | 53 | struct image_desc *bl1_plat_get_image_desc(unsigned int image_id) |
Yatharth Kochar | 7baff11 | 2015-10-09 18:06:13 +0100 | [diff] [blame] | 54 | { |
| 55 | static image_desc_t bl2_img_desc = BL2_IMAGE_DESC; |
| 56 | return &bl2_img_desc; |
| 57 | } |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 58 | |
Dan Handley | 1f37b94 | 2015-12-15 14:28:24 +0000 | [diff] [blame] | 59 | __dead2 void bl1_plat_fwu_done(void *client_cookie, void *reserved) |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 60 | { |
| 61 | while (1) |
| 62 | wfi(); |
| 63 | } |
| 64 | |
| 65 | /* |
| 66 | * The Platforms must override with real definition. |
| 67 | */ |
| 68 | #pragma weak bl1_plat_mem_check |
| 69 | |
| 70 | int bl1_plat_mem_check(uintptr_t mem_base, unsigned int mem_size, |
| 71 | unsigned int flags) |
| 72 | { |
| 73 | assert(0); |
| 74 | return -ENOMEM; |
| 75 | } |
Soby Mathew | 101d01e | 2018-01-10 12:51:34 +0000 | [diff] [blame] | 76 | |
| 77 | /* |
| 78 | * Default implementation for bl1_plat_handle_post_image_load(). This function |
| 79 | * populates the default arguments to BL2. The BL2 memory layout structure |
| 80 | * is allocated and the calculated layout is populated in arg1 to BL2. |
| 81 | */ |
| 82 | int bl1_plat_handle_post_image_load(unsigned int image_id) |
| 83 | { |
| 84 | meminfo_t *bl2_tzram_layout; |
| 85 | meminfo_t *bl1_tzram_layout; |
| 86 | image_desc_t *image_desc; |
| 87 | entry_point_info_t *ep_info; |
| 88 | |
| 89 | if (image_id != BL2_IMAGE_ID) |
| 90 | return 0; |
| 91 | |
| 92 | /* Get the image descriptor */ |
| 93 | image_desc = bl1_plat_get_image_desc(BL2_IMAGE_ID); |
Soby Mathew | da5f274 | 2018-02-21 01:16:39 +0000 | [diff] [blame] | 94 | assert(image_desc != NULL); |
Soby Mathew | 101d01e | 2018-01-10 12:51:34 +0000 | [diff] [blame] | 95 | |
| 96 | /* Get the entry point info */ |
| 97 | ep_info = &image_desc->ep_info; |
| 98 | |
| 99 | /* Find out how much free trusted ram remains after BL1 load */ |
| 100 | bl1_tzram_layout = bl1_plat_sec_mem_layout(); |
| 101 | |
| 102 | /* |
| 103 | * Create a new layout of memory for BL2 as seen by BL1 i.e. |
| 104 | * tell it the amount of total and free memory available. |
| 105 | * This layout is created at the first free address visible |
| 106 | * to BL2. BL2 will read the memory layout before using its |
| 107 | * memory for other purposes. |
| 108 | */ |
Soby Mathew | 101d01e | 2018-01-10 12:51:34 +0000 | [diff] [blame] | 109 | bl2_tzram_layout = (meminfo_t *) bl1_tzram_layout->total_base; |
Soby Mathew | 101d01e | 2018-01-10 12:51:34 +0000 | [diff] [blame] | 110 | |
Soby Mathew | 101d01e | 2018-01-10 12:51:34 +0000 | [diff] [blame] | 111 | bl1_calc_bl2_mem_layout(bl1_tzram_layout, bl2_tzram_layout); |
Soby Mathew | 101d01e | 2018-01-10 12:51:34 +0000 | [diff] [blame] | 112 | |
| 113 | ep_info->args.arg1 = (uintptr_t)bl2_tzram_layout; |
| 114 | |
| 115 | VERBOSE("BL1: BL2 memory layout address = %p\n", |
| 116 | (void *) bl2_tzram_layout); |
| 117 | return 0; |
| 118 | } |