Yatharth Kochar | f9a0f16 | 2016-09-13 17:07:57 +0100 | [diff] [blame] | 1 | /* |
Harrison Mutai | 91ce7c9 | 2023-12-01 15:50:00 +0000 | [diff] [blame] | 2 | * Copyright (c) 2016-2024, Arm Limited and Contributors. All rights reserved. |
Yatharth Kochar | f9a0f16 | 2016-09-13 17:07:57 +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 | f9a0f16 | 2016-09-13 17:07:57 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
Sathees Balya | 9095009 | 2018-11-15 14:22:30 +0000 | [diff] [blame] | 7 | #include <assert.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 8 | #include <common/bl_common.h> |
| 9 | #include <common/desc_image_load.h> |
Manish Pandey | 1fa6ecb | 2020-02-25 11:38:19 +0000 | [diff] [blame] | 10 | #if defined(SPD_spmd) |
| 11 | #include <plat/arm/common/fconf_arm_sp_getter.h> |
| 12 | #endif |
Antonio Nino Diaz | bd7b740 | 2019-01-25 14:30:04 +0000 | [diff] [blame] | 13 | #include <plat/arm/common/plat_arm.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 14 | #include <plat/common/platform.h> |
| 15 | |
Yatharth Kochar | f9a0f16 | 2016-09-13 17:07:57 +0100 | [diff] [blame] | 16 | #pragma weak plat_flush_next_bl_params |
| 17 | #pragma weak plat_get_bl_image_load_info |
| 18 | #pragma weak plat_get_next_bl_params |
| 19 | |
Harrison Mutai | 91ce7c9 | 2023-12-01 15:50:00 +0000 | [diff] [blame] | 20 | #if TRANSFER_LIST |
| 21 | static bl_params_t next_bl_params_cpy; |
| 22 | #endif |
| 23 | bl_params_t *next_bl_params_cpy_ptr; |
Yatharth Kochar | f9a0f16 | 2016-09-13 17:07:57 +0100 | [diff] [blame] | 24 | |
| 25 | /******************************************************************************* |
| 26 | * This function flushes the data structures so that they are visible |
| 27 | * in memory for the next BL image. |
| 28 | ******************************************************************************/ |
| 29 | void plat_flush_next_bl_params(void) |
| 30 | { |
Sathees Balya | 9095009 | 2018-11-15 14:22:30 +0000 | [diff] [blame] | 31 | assert(next_bl_params_cpy_ptr != NULL); |
| 32 | |
| 33 | flush_bl_params_desc_args(bl_mem_params_desc_ptr, |
| 34 | bl_mem_params_desc_num, |
| 35 | next_bl_params_cpy_ptr); |
Yatharth Kochar | f9a0f16 | 2016-09-13 17:07:57 +0100 | [diff] [blame] | 36 | } |
| 37 | |
Balint Dobszay | 719ba9c | 2021-03-26 16:23:18 +0100 | [diff] [blame] | 38 | #if defined(SPD_spmd) && BL2_ENABLE_SP_LOAD |
Manish Pandey | 1fa6ecb | 2020-02-25 11:38:19 +0000 | [diff] [blame] | 39 | /******************************************************************************* |
| 40 | * This function appends Secure Partitions to list of loadable images. |
| 41 | ******************************************************************************/ |
Olivier Deprez | 042db53 | 2020-03-19 09:27:11 +0100 | [diff] [blame] | 42 | static void plat_add_sp_images_load_info(struct bl_load_info *load_info) |
Manish Pandey | 1fa6ecb | 2020-02-25 11:38:19 +0000 | [diff] [blame] | 43 | { |
Heyi Guo | 578408f | 2021-01-25 21:45:47 +0800 | [diff] [blame] | 44 | bl_load_info_node_t *curr_node = load_info->head; |
| 45 | bl_load_info_node_t *prev_node; |
Manish Pandey | 1fa6ecb | 2020-02-25 11:38:19 +0000 | [diff] [blame] | 46 | |
Heyi Guo | 578408f | 2021-01-25 21:45:47 +0800 | [diff] [blame] | 47 | /* Shortcut for empty SP list */ |
| 48 | if (sp_mem_params_descs[0].image_id == 0) { |
Manish Pandey | 1fa6ecb | 2020-02-25 11:38:19 +0000 | [diff] [blame] | 49 | ERROR("No Secure Partition Image available\n"); |
| 50 | return; |
| 51 | } |
| 52 | |
| 53 | /* Traverse through the bl images list */ |
| 54 | do { |
Heyi Guo | 578408f | 2021-01-25 21:45:47 +0800 | [diff] [blame] | 55 | curr_node = curr_node->next_load_info; |
| 56 | } while (curr_node->next_load_info != NULL); |
Manish Pandey | 1fa6ecb | 2020-02-25 11:38:19 +0000 | [diff] [blame] | 57 | |
Heyi Guo | 578408f | 2021-01-25 21:45:47 +0800 | [diff] [blame] | 58 | prev_node = curr_node; |
Heyi Guo | 3dd9493 | 2021-01-25 21:45:47 +0800 | [diff] [blame] | 59 | |
Heyi Guo | 578408f | 2021-01-25 21:45:47 +0800 | [diff] [blame] | 60 | for (unsigned int index = 0; index < MAX_SP_IDS; index++) { |
| 61 | if (sp_mem_params_descs[index].image_id == 0) { |
Manish Pandey | 1fa6ecb | 2020-02-25 11:38:19 +0000 | [diff] [blame] | 62 | return; |
| 63 | } |
Heyi Guo | 578408f | 2021-01-25 21:45:47 +0800 | [diff] [blame] | 64 | curr_node = &sp_mem_params_descs[index].load_node_mem; |
| 65 | /* Populate the image information */ |
| 66 | curr_node->image_id = sp_mem_params_descs[index].image_id; |
| 67 | curr_node->image_info = &sp_mem_params_descs[index].image_info; |
Manish Pandey | 1fa6ecb | 2020-02-25 11:38:19 +0000 | [diff] [blame] | 68 | |
Heyi Guo | 578408f | 2021-01-25 21:45:47 +0800 | [diff] [blame] | 69 | prev_node->next_load_info = curr_node; |
| 70 | prev_node = curr_node; |
Manish Pandey | 1fa6ecb | 2020-02-25 11:38:19 +0000 | [diff] [blame] | 71 | } |
Heyi Guo | 578408f | 2021-01-25 21:45:47 +0800 | [diff] [blame] | 72 | |
| 73 | INFO("Reached Max number of SPs\n"); |
Manish Pandey | 1fa6ecb | 2020-02-25 11:38:19 +0000 | [diff] [blame] | 74 | } |
| 75 | #endif |
| 76 | |
Yatharth Kochar | f9a0f16 | 2016-09-13 17:07:57 +0100 | [diff] [blame] | 77 | /******************************************************************************* |
| 78 | * This function returns the list of loadable images. |
| 79 | ******************************************************************************/ |
Sandrine Bailleux | b3b6e22 | 2018-07-11 12:44:22 +0200 | [diff] [blame] | 80 | struct bl_load_info *plat_get_bl_image_load_info(void) |
Yatharth Kochar | f9a0f16 | 2016-09-13 17:07:57 +0100 | [diff] [blame] | 81 | { |
Balint Dobszay | 719ba9c | 2021-03-26 16:23:18 +0100 | [diff] [blame] | 82 | #if defined(SPD_spmd) && BL2_ENABLE_SP_LOAD |
Manish Pandey | 1fa6ecb | 2020-02-25 11:38:19 +0000 | [diff] [blame] | 83 | bl_load_info_t *bl_load_info; |
| 84 | |
| 85 | bl_load_info = get_bl_load_info_from_mem_params_desc(); |
| 86 | plat_add_sp_images_load_info(bl_load_info); |
| 87 | |
| 88 | return bl_load_info; |
| 89 | #else |
Yatharth Kochar | f9a0f16 | 2016-09-13 17:07:57 +0100 | [diff] [blame] | 90 | return get_bl_load_info_from_mem_params_desc(); |
Manish Pandey | 1fa6ecb | 2020-02-25 11:38:19 +0000 | [diff] [blame] | 91 | #endif |
Yatharth Kochar | f9a0f16 | 2016-09-13 17:07:57 +0100 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | /******************************************************************************* |
Sathees Balya | 9095009 | 2018-11-15 14:22:30 +0000 | [diff] [blame] | 95 | * ARM helper function to return the list of executable images.Since the default |
| 96 | * descriptors are allocated within BL2 RW memory, this prevents BL31/BL32 |
| 97 | * overlay of BL2 memory. Hence this function also copies the descriptors to a |
| 98 | * pre-allocated memory indicated by ARM_BL2_MEM_DESC_BASE. |
Yatharth Kochar | f9a0f16 | 2016-09-13 17:07:57 +0100 | [diff] [blame] | 99 | ******************************************************************************/ |
Sathees Balya | 9095009 | 2018-11-15 14:22:30 +0000 | [diff] [blame] | 100 | struct bl_params *arm_get_next_bl_params(void) |
Yatharth Kochar | f9a0f16 | 2016-09-13 17:07:57 +0100 | [diff] [blame] | 101 | { |
Harrison Mutai | 91ce7c9 | 2023-12-01 15:50:00 +0000 | [diff] [blame] | 102 | bl_mem_params_node_t *bl2_mem_params_descs_cpy __unused; |
| 103 | const bl_params_t *next_bl_params __unused; |
| 104 | |
| 105 | #if TRANSFER_LIST |
| 106 | next_bl_params_cpy_ptr = &next_bl_params_cpy; |
| 107 | SET_PARAM_HEAD(next_bl_params_cpy_ptr, PARAM_BL_PARAMS, VERSION_2, 0U); |
| 108 | #else |
| 109 | bl2_mem_params_descs_cpy = |
| 110 | (bl_mem_params_node_t *)ARM_BL2_MEM_DESC_BASE; |
Sathees Balya | 9095009 | 2018-11-15 14:22:30 +0000 | [diff] [blame] | 111 | |
| 112 | next_bl_params_cpy_ptr = |
| 113 | (bl_params_t *)(ARM_BL2_MEM_DESC_BASE + |
| 114 | (bl_mem_params_desc_num * sizeof(bl_mem_params_node_t))); |
| 115 | |
| 116 | /* |
| 117 | * Copy the memory descriptors to ARM_BL2_MEM_DESC_BASE area. |
| 118 | */ |
| 119 | (void) memcpy(bl2_mem_params_descs_cpy, bl_mem_params_desc_ptr, |
| 120 | (bl_mem_params_desc_num * sizeof(bl_mem_params_node_t))); |
Soby Mathew | 96a1c6b | 2018-01-15 14:45:33 +0000 | [diff] [blame] | 121 | |
Sathees Balya | 9095009 | 2018-11-15 14:22:30 +0000 | [diff] [blame] | 122 | /* |
| 123 | * Modify the global 'bl_mem_params_desc_ptr' to point to the |
| 124 | * copied location. |
| 125 | */ |
| 126 | bl_mem_params_desc_ptr = bl2_mem_params_descs_cpy; |
| 127 | |
| 128 | next_bl_params = get_next_bl_params_from_mem_params_desc(); |
| 129 | assert(next_bl_params != NULL); |
| 130 | |
| 131 | /* |
| 132 | * Copy 'next_bl_params' to the reserved location after the copied |
| 133 | * memory descriptors. |
| 134 | */ |
| 135 | (void) memcpy(next_bl_params_cpy_ptr, next_bl_params, |
| 136 | (sizeof(bl_params_t))); |
| 137 | |
| 138 | populate_next_bl_params_config(next_bl_params_cpy_ptr); |
Harrison Mutai | 91ce7c9 | 2023-12-01 15:50:00 +0000 | [diff] [blame] | 139 | #endif /* TRANSFER_LIST */ |
Sathees Balya | 9095009 | 2018-11-15 14:22:30 +0000 | [diff] [blame] | 140 | |
| 141 | return next_bl_params_cpy_ptr; |
Yatharth Kochar | f9a0f16 | 2016-09-13 17:07:57 +0100 | [diff] [blame] | 142 | } |
Sathees Balya | 9095009 | 2018-11-15 14:22:30 +0000 | [diff] [blame] | 143 | |
| 144 | /******************************************************************************* |
| 145 | * This function returns the list of executable images |
| 146 | ******************************************************************************/ |
| 147 | struct bl_params *plat_get_next_bl_params(void) |
| 148 | { |
| 149 | return arm_get_next_bl_params(); |
| 150 | } |
| 151 | |