Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1 | /* |
Manish V Badarkhe | b2e34ff | 2023-02-07 11:26:38 +0000 | [diff] [blame] | 2 | * Copyright (c) 2013-2023, Arm Limited and Contributors. All rights reserved. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
Manish V Badarkhe | 8717e03 | 2020-05-30 17:40:44 +0100 | [diff] [blame] | 7 | #include <assert.h> |
| 8 | |
Alexei Fedorov | 61369a2 | 2020-07-13 14:59:02 +0100 | [diff] [blame] | 9 | #include <common/debug.h> |
Manish V Badarkhe | 8717e03 | 2020-05-30 17:40:44 +0100 | [diff] [blame] | 10 | #include <common/desc_image_load.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 11 | #include <drivers/arm/sp804_delay_timer.h> |
Manish V Badarkhe | 8717e03 | 2020-05-30 17:40:44 +0100 | [diff] [blame] | 12 | #include <lib/fconf/fconf.h> |
| 13 | #include <lib/fconf/fconf_dyn_cfg_getter.h> |
Harrison Mutai | 1dcaf96 | 2023-08-08 15:10:07 +0100 | [diff] [blame] | 14 | #include <lib/transfer_list.h> |
Manish V Badarkhe | 8717e03 | 2020-05-30 17:40:44 +0100 | [diff] [blame] | 15 | |
Antonio Nino Diaz | bd7b740 | 2019-01-25 14:30:04 +0000 | [diff] [blame] | 16 | #include <plat/arm/common/plat_arm.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 17 | #include <plat/common/platform.h> |
Antonio Nino Diaz | a320ecd | 2019-01-15 14:19:50 +0000 | [diff] [blame] | 18 | #include <platform_def.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 19 | |
Dan Handley | ed6ff95 | 2014-05-14 17:44:19 +0100 | [diff] [blame] | 20 | #include "fvp_private.h" |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 21 | |
Harrison Mutai | 8c7d499 | 2023-09-29 11:05:32 +0100 | [diff] [blame] | 22 | static struct transfer_list_header *ns_tl __unused; |
| 23 | |
Soby Mathew | 7d5a2e7 | 2018-01-10 15:59:31 +0000 | [diff] [blame] | 24 | void bl2_early_platform_setup2(u_register_t arg0, u_register_t arg1, u_register_t arg2, u_register_t arg3) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 25 | { |
Soby Mathew | 96a1c6b | 2018-01-15 14:45:33 +0000 | [diff] [blame] | 26 | arm_bl2_early_platform_setup((uintptr_t)arg0, (meminfo_t *)arg1); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 27 | |
| 28 | /* Initialize the platform config for future decision making */ |
Dan Handley | ea45157 | 2014-05-15 14:53:30 +0100 | [diff] [blame] | 29 | fvp_config_setup(); |
Vikram Kanigiri | d8c9d26 | 2014-05-16 18:48:12 +0100 | [diff] [blame] | 30 | } |
Ryan Harkin | f96fc8f | 2015-03-17 14:54:01 +0000 | [diff] [blame] | 31 | |
| 32 | void bl2_platform_setup(void) |
| 33 | { |
| 34 | arm_bl2_platform_setup(); |
| 35 | |
Harrison Mutai | 8c7d499 | 2023-09-29 11:05:32 +0100 | [diff] [blame] | 36 | #if TRANSFER_LIST |
| 37 | ns_tl = transfer_list_init((void *)FW_NS_HANDOFF_BASE, FW_HANDOFF_SIZE); |
| 38 | assert(ns_tl != NULL); |
| 39 | #endif |
Alexei Fedorov | 7131d83 | 2019-08-16 14:15:59 +0100 | [diff] [blame] | 40 | /* Initialize System level generic or SP804 timer */ |
| 41 | fvp_timer_init(); |
Ryan Harkin | f96fc8f | 2015-03-17 14:54:01 +0000 | [diff] [blame] | 42 | } |
Manish V Badarkhe | 8717e03 | 2020-05-30 17:40:44 +0100 | [diff] [blame] | 43 | |
| 44 | /******************************************************************************* |
| 45 | * This function returns the list of executable images |
| 46 | ******************************************************************************/ |
| 47 | struct bl_params *plat_get_next_bl_params(void) |
| 48 | { |
| 49 | struct bl_params *arm_bl_params; |
Manish V Badarkhe | 86854e7 | 2022-03-15 16:05:58 +0000 | [diff] [blame] | 50 | const struct dyn_cfg_dtb_info_t *hw_config_info __unused; |
Harrison Mutai | 1dcaf96 | 2023-08-08 15:10:07 +0100 | [diff] [blame] | 51 | struct transfer_list_entry *te __unused; |
Harrison Mutai | 8c7d499 | 2023-09-29 11:05:32 +0100 | [diff] [blame] | 52 | bl_mem_params_node_t *param_node __unused; |
Manish V Badarkhe | 8717e03 | 2020-05-30 17:40:44 +0100 | [diff] [blame] | 53 | |
| 54 | arm_bl_params = arm_get_next_bl_params(); |
| 55 | |
Arvind Ram Prakash | 11b9b49 | 2022-11-22 14:41:00 -0600 | [diff] [blame] | 56 | #if !RESET_TO_BL2 && !EL3_PAYLOAD_BASE |
Manish V Badarkhe | 8717e03 | 2020-05-30 17:40:44 +0100 | [diff] [blame] | 57 | const struct dyn_cfg_dtb_info_t *fw_config_info; |
Manish V Badarkhe | 86854e7 | 2022-03-15 16:05:58 +0000 | [diff] [blame] | 58 | uintptr_t fw_config_base = 0UL; |
Manish V Badarkhe | 8717e03 | 2020-05-30 17:40:44 +0100 | [diff] [blame] | 59 | |
Manish V Badarkhe | 86854e7 | 2022-03-15 16:05:58 +0000 | [diff] [blame] | 60 | #if __aarch64__ |
Manish V Badarkhe | 8717e03 | 2020-05-30 17:40:44 +0100 | [diff] [blame] | 61 | /* Get BL31 image node */ |
| 62 | param_node = get_bl_mem_params_node(BL31_IMAGE_ID); |
Manish V Badarkhe | 86854e7 | 2022-03-15 16:05:58 +0000 | [diff] [blame] | 63 | #else /* aarch32 */ |
| 64 | /* Get SP_MIN image node */ |
| 65 | param_node = get_bl_mem_params_node(BL32_IMAGE_ID); |
| 66 | #endif /* __aarch64__ */ |
Manish V Badarkhe | 8717e03 | 2020-05-30 17:40:44 +0100 | [diff] [blame] | 67 | assert(param_node != NULL); |
| 68 | |
Harrison Mutai | 8c7d499 | 2023-09-29 11:05:32 +0100 | [diff] [blame] | 69 | /* Update the next image's ep info with the FW config address */ |
Manish V Badarkhe | 8717e03 | 2020-05-30 17:40:44 +0100 | [diff] [blame] | 70 | fw_config_info = FCONF_GET_PROPERTY(dyn_cfg, dtb, FW_CONFIG_ID); |
| 71 | assert(fw_config_info != NULL); |
| 72 | |
| 73 | fw_config_base = fw_config_info->config_addr; |
Manish V Badarkhe | 86854e7 | 2022-03-15 16:05:58 +0000 | [diff] [blame] | 74 | assert(fw_config_base != 0UL); |
Manish V Badarkhe | 8717e03 | 2020-05-30 17:40:44 +0100 | [diff] [blame] | 75 | |
Harrison Mutai | 8c7d499 | 2023-09-29 11:05:32 +0100 | [diff] [blame] | 76 | param_node->ep_info.args.arg1 = (uint32_t)fw_config_base; |
Manish V Badarkhe | 86854e7 | 2022-03-15 16:05:58 +0000 | [diff] [blame] | 77 | |
Harrison Mutai | 8c7d499 | 2023-09-29 11:05:32 +0100 | [diff] [blame] | 78 | /* Update BL33's ep info with the NS HW config address */ |
| 79 | param_node = get_bl_mem_params_node(BL33_IMAGE_ID); |
Manish V Badarkhe | 86854e7 | 2022-03-15 16:05:58 +0000 | [diff] [blame] | 80 | assert(param_node != NULL); |
| 81 | |
Harrison Mutai | 1dcaf96 | 2023-08-08 15:10:07 +0100 | [diff] [blame] | 82 | #if TRANSFER_LIST |
Harrison Mutai | 1dcaf96 | 2023-08-08 15:10:07 +0100 | [diff] [blame] | 83 | /* Update BL33's ep info with NS HW config address */ |
Harrison Mutai | 8c7d499 | 2023-09-29 11:05:32 +0100 | [diff] [blame] | 84 | te = transfer_list_find(ns_tl, TL_TAG_FDT); |
Harrison Mutai | 1dcaf96 | 2023-08-08 15:10:07 +0100 | [diff] [blame] | 85 | assert(te != NULL); |
| 86 | |
Harrison Mutai | 8c7d499 | 2023-09-29 11:05:32 +0100 | [diff] [blame] | 87 | param_node->ep_info.args.arg1 = TRANSFER_LIST_SIGNATURE | |
| 88 | REGISTER_CONVENTION_VERSION_MASK; |
| 89 | param_node->ep_info.args.arg2 = 0; |
| 90 | param_node->ep_info.args.arg3 = (uintptr_t)ns_tl; |
| 91 | param_node->ep_info.args.arg0 = |
| 92 | te ? (uintptr_t)transfer_list_entry_data(te) : 0; |
Harrison Mutai | 1dcaf96 | 2023-08-08 15:10:07 +0100 | [diff] [blame] | 93 | #else |
Harrison Mutai | 8c7d499 | 2023-09-29 11:05:32 +0100 | [diff] [blame] | 94 | hw_config_info = FCONF_GET_PROPERTY(dyn_cfg, dtb, HW_CONFIG_ID); |
| 95 | assert(hw_config_info != NULL); |
Manish V Badarkhe | 86854e7 | 2022-03-15 16:05:58 +0000 | [diff] [blame] | 96 | |
Harrison Mutai | 8c7d499 | 2023-09-29 11:05:32 +0100 | [diff] [blame] | 97 | param_node->ep_info.args.arg1 = hw_config_info->secondary_config_addr; |
Harrison Mutai | 1dcaf96 | 2023-08-08 15:10:07 +0100 | [diff] [blame] | 98 | #endif /* TRANSFER_LIST */ |
Arvind Ram Prakash | 11b9b49 | 2022-11-22 14:41:00 -0600 | [diff] [blame] | 99 | #endif /* !RESET_TO_BL2 && !EL3_PAYLOAD_BASE */ |
Manish V Badarkhe | 8717e03 | 2020-05-30 17:40:44 +0100 | [diff] [blame] | 100 | |
| 101 | return arm_bl_params; |
| 102 | } |
Harrison Mutai | b5e7d7e | 2023-10-18 09:58:48 +0100 | [diff] [blame] | 103 | |
| 104 | int bl2_plat_handle_post_image_load(unsigned int image_id) |
| 105 | { |
Harrison Mutai | 8c7d499 | 2023-09-29 11:05:32 +0100 | [diff] [blame] | 106 | #if !RESET_TO_BL2 && !EL3_PAYLOAD_BASE |
| 107 | if (image_id == HW_CONFIG_ID) { |
| 108 | const struct dyn_cfg_dtb_info_t *hw_config_info; |
| 109 | struct transfer_list_entry *te __unused; |
| 110 | |
| 111 | const bl_mem_params_node_t *param_node = |
| 112 | get_bl_mem_params_node(image_id); |
| 113 | assert(param_node != NULL); |
| 114 | |
| 115 | hw_config_info = FCONF_GET_PROPERTY(dyn_cfg, dtb, HW_CONFIG_ID); |
| 116 | assert(hw_config_info != NULL); |
| 117 | |
| 118 | #if TRANSFER_LIST |
| 119 | /* Update BL33's ep info with NS HW config address */ |
| 120 | te = transfer_list_add(ns_tl, TL_TAG_FDT, |
| 121 | param_node->image_info.image_size, |
| 122 | (void *)hw_config_info->config_addr); |
| 123 | assert(te != NULL); |
| 124 | #else |
| 125 | memcpy((void *)hw_config_info->secondary_config_addr, |
| 126 | (void *)hw_config_info->config_addr, |
| 127 | (size_t)param_node->image_info.image_size); |
| 128 | |
| 129 | /* |
| 130 | * Ensure HW-config device tree is committed to memory, as the HW-Config |
| 131 | * might be used without cache and MMU enabled at BL33. |
| 132 | */ |
| 133 | flush_dcache_range(hw_config_info->secondary_config_addr, |
| 134 | param_node->image_info.image_size); |
| 135 | #endif /* TRANSFER_LIST */ |
| 136 | } |
| 137 | #endif /* !RESET_TO_BL2 && !EL3_PAYLOAD_BASE */ |
| 138 | |
Harrison Mutai | b5e7d7e | 2023-10-18 09:58:48 +0100 | [diff] [blame] | 139 | return arm_bl2_plat_handle_post_image_load(image_id); |
| 140 | } |