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