sah01 | 066afc2 | 2021-11-18 10:04:27 +0000 | [diff] [blame] | 1 | /* |
Tamas Ban | f728b61 | 2023-05-08 13:50:37 +0200 | [diff] [blame] | 2 | * Copyright (c) 2021-2024, Arm Limited. All rights reserved. |
sah01 | 066afc2 | 2021-11-18 10:04:27 +0000 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <arch_helpers.h> |
| 8 | #include <common/debug.h> |
| 9 | #include <common/desc_image_load.h> |
| 10 | #include <drivers/arm/css/sds.h> |
| 11 | #include <libfdt.h> |
| 12 | |
| 13 | #include "morello_def.h" |
| 14 | #include <plat/arm/common/plat_arm.h> |
| 15 | #include <plat/common/platform.h> |
Tamas Ban | f728b61 | 2023-05-08 13:50:37 +0200 | [diff] [blame] | 16 | #include <platform_def.h> |
sah01 | 066afc2 | 2021-11-18 10:04:27 +0000 | [diff] [blame] | 17 | |
sah01 | 066afc2 | 2021-11-18 10:04:27 +0000 | [diff] [blame] | 18 | /* In client mode, a part of the DDR memory is reserved for Tag bits. |
| 19 | * Calculate the usable memory size after subtracting the Tag memory. |
| 20 | */ |
| 21 | static inline uint64_t get_mem_client_mode(uint64_t size) |
| 22 | { |
| 23 | return (size - (size / 128ULL)); |
| 24 | } |
| 25 | |
| 26 | /******************************************************************************* |
Werner Lewis | cb5e71a | 2023-08-17 12:06:52 +0100 | [diff] [blame] | 27 | * This function inserts Platform information and firmware versions |
| 28 | * via device tree nodes as, |
sah01 | 066afc2 | 2021-11-18 10:04:27 +0000 | [diff] [blame] | 29 | * platform-info { |
| 30 | * local-ddr-size = <0x0 0x0>; |
| 31 | *#ifdef TARGET_PLATFORM_SOC |
| 32 | * remote-ddr-size = <0x0 0x0>; |
| 33 | * remote-chip-count = <0x0>; |
| 34 | * multichip-mode = <0x0>; |
| 35 | * scc-config = <0x0>; |
| 36 | *#endif |
| 37 | * }; |
Werner Lewis | cb5e71a | 2023-08-17 12:06:52 +0100 | [diff] [blame] | 38 | * firmware-version { |
| 39 | *#ifdef TARGET_PLATFORM_SOC |
| 40 | * mcc-fw-version = <0x0>; |
| 41 | * pcc-fw-version = <0x0>; |
| 42 | *#endif |
| 43 | * scp-fw-version = <0x0>; |
| 44 | * scp-fw-commit = <0x0>; |
Werner Lewis | a2e00bf | 2023-08-17 12:10:06 +0100 | [diff] [blame] | 45 | * tfa-fw-version = "unknown-dirty_00000000"; |
Werner Lewis | cb5e71a | 2023-08-17 12:06:52 +0100 | [diff] [blame] | 46 | * }; |
sah01 | 066afc2 | 2021-11-18 10:04:27 +0000 | [diff] [blame] | 47 | ******************************************************************************/ |
Werner Lewis | cb5e71a | 2023-08-17 12:06:52 +0100 | [diff] [blame] | 48 | static int plat_morello_append_config_node(struct morello_plat_info *plat_info, |
| 49 | struct morello_firmware_version *fw_version) |
sah01 | 066afc2 | 2021-11-18 10:04:27 +0000 | [diff] [blame] | 50 | { |
| 51 | bl_mem_params_node_t *mem_params; |
| 52 | void *fdt; |
Werner Lewis | cb5e71a | 2023-08-17 12:06:52 +0100 | [diff] [blame] | 53 | int nodeoffset_plat, nodeoffset_fw, err; |
sah01 | 066afc2 | 2021-11-18 10:04:27 +0000 | [diff] [blame] | 54 | uint64_t usable_mem_size; |
| 55 | |
| 56 | usable_mem_size = plat_info->local_ddr_size; |
| 57 | |
| 58 | mem_params = get_bl_mem_params_node(NT_FW_CONFIG_ID); |
| 59 | if (mem_params == NULL) { |
| 60 | ERROR("NT_FW CONFIG base address is NULL\n"); |
| 61 | return -1; |
| 62 | } |
| 63 | |
| 64 | fdt = (void *)(mem_params->image_info.image_base); |
| 65 | |
| 66 | /* Check the validity of the fdt */ |
| 67 | if (fdt_check_header(fdt) != 0) { |
| 68 | ERROR("Invalid NT_FW_CONFIG DTB passed\n"); |
| 69 | return -1; |
| 70 | } |
| 71 | |
Werner Lewis | cb5e71a | 2023-08-17 12:06:52 +0100 | [diff] [blame] | 72 | nodeoffset_plat = fdt_subnode_offset(fdt, 0, "platform-info"); |
| 73 | if (nodeoffset_plat < 0) { |
sah01 | 066afc2 | 2021-11-18 10:04:27 +0000 | [diff] [blame] | 74 | ERROR("NT_FW_CONFIG: Failed to get platform-info node offset\n"); |
| 75 | return -1; |
| 76 | } |
| 77 | |
Werner Lewis | cb5e71a | 2023-08-17 12:06:52 +0100 | [diff] [blame] | 78 | nodeoffset_fw = fdt_subnode_offset(fdt, 0, "firmware-version"); |
| 79 | if (nodeoffset_fw < 0) { |
| 80 | ERROR("NT_FW_CONFIG: Failed to get firmware-version node offset\n"); |
| 81 | return -1; |
| 82 | } |
| 83 | |
sah01 | 066afc2 | 2021-11-18 10:04:27 +0000 | [diff] [blame] | 84 | #ifdef TARGET_PLATFORM_SOC |
Werner Lewis | cb5e71a | 2023-08-17 12:06:52 +0100 | [diff] [blame] | 85 | err = fdt_setprop_u64(fdt, nodeoffset_plat, "remote-ddr-size", |
sah01 | 066afc2 | 2021-11-18 10:04:27 +0000 | [diff] [blame] | 86 | plat_info->remote_ddr_size); |
| 87 | if (err < 0) { |
| 88 | ERROR("NT_FW_CONFIG: Failed to set remote-ddr-size\n"); |
| 89 | return -1; |
| 90 | } |
| 91 | |
Werner Lewis | cb5e71a | 2023-08-17 12:06:52 +0100 | [diff] [blame] | 92 | err = fdt_setprop_u32(fdt, nodeoffset_plat, "remote-chip-count", |
sah01 | 066afc2 | 2021-11-18 10:04:27 +0000 | [diff] [blame] | 93 | plat_info->remote_chip_count); |
| 94 | if (err < 0) { |
| 95 | ERROR("NT_FW_CONFIG: Failed to set remote-chip-count\n"); |
| 96 | return -1; |
| 97 | } |
| 98 | |
Werner Lewis | cb5e71a | 2023-08-17 12:06:52 +0100 | [diff] [blame] | 99 | err = fdt_setprop_u32(fdt, nodeoffset_plat, "multichip-mode", |
sah01 | 066afc2 | 2021-11-18 10:04:27 +0000 | [diff] [blame] | 100 | plat_info->multichip_mode); |
| 101 | if (err < 0) { |
| 102 | ERROR("NT_FW_CONFIG: Failed to set multichip-mode\n"); |
| 103 | return -1; |
| 104 | } |
| 105 | |
Werner Lewis | cb5e71a | 2023-08-17 12:06:52 +0100 | [diff] [blame] | 106 | err = fdt_setprop_u32(fdt, nodeoffset_plat, "scc-config", |
sah01 | 066afc2 | 2021-11-18 10:04:27 +0000 | [diff] [blame] | 107 | plat_info->scc_config); |
| 108 | if (err < 0) { |
| 109 | ERROR("NT_FW_CONFIG: Failed to set scc-config\n"); |
| 110 | return -1; |
| 111 | } |
| 112 | |
| 113 | if (plat_info->scc_config & MORELLO_SCC_CLIENT_MODE_MASK) { |
| 114 | usable_mem_size = get_mem_client_mode(plat_info->local_ddr_size); |
| 115 | } |
Werner Lewis | cb5e71a | 2023-08-17 12:06:52 +0100 | [diff] [blame] | 116 | |
| 117 | err = fdt_setprop_u32(fdt, nodeoffset_fw, "mcc-fw-version", |
| 118 | fw_version->mcc_fw_ver); |
| 119 | if (err < 0) { |
| 120 | ERROR("NT_FW_CONFIG: Failed to set mcc-fw-version\n"); |
| 121 | return -1; |
| 122 | } |
| 123 | |
| 124 | err = fdt_setprop_u32(fdt, nodeoffset_fw, "pcc-fw-version", |
| 125 | fw_version->pcc_fw_ver); |
| 126 | if (err < 0) { |
| 127 | ERROR("NT_FW_CONFIG: Failed to set pcc-fw-version\n"); |
| 128 | return -1; |
| 129 | } |
sah01 | 066afc2 | 2021-11-18 10:04:27 +0000 | [diff] [blame] | 130 | #endif |
Werner Lewis | cb5e71a | 2023-08-17 12:06:52 +0100 | [diff] [blame] | 131 | err = fdt_setprop_u32(fdt, nodeoffset_fw, "scp-fw-version", |
| 132 | fw_version->scp_fw_ver); |
| 133 | if (err < 0) { |
| 134 | ERROR("NT_FW_CONFIG: Failed to set scp-fw-version\n"); |
| 135 | return -1; |
| 136 | } |
| 137 | |
| 138 | err = fdt_setprop_u32(fdt, nodeoffset_fw, "scp-fw-commit", |
| 139 | fw_version->scp_fw_commit); |
| 140 | if (err < 0) { |
| 141 | ERROR("NT_FW_CONFIG: Failed to set scp-fw-commit\n"); |
| 142 | return -1; |
| 143 | } |
| 144 | |
Werner Lewis | a2e00bf | 2023-08-17 12:10:06 +0100 | [diff] [blame] | 145 | err = fdt_setprop_string(fdt, nodeoffset_fw, "tfa-fw-version", version_string); |
| 146 | if (err < 0) { |
| 147 | WARN("NT_FW_CONFIG: Unable to set tfa-fw-version\n"); |
| 148 | } |
| 149 | |
Werner Lewis | cb5e71a | 2023-08-17 12:06:52 +0100 | [diff] [blame] | 150 | err = fdt_setprop_u64(fdt, nodeoffset_plat, "local-ddr-size", |
sah01 | 066afc2 | 2021-11-18 10:04:27 +0000 | [diff] [blame] | 151 | usable_mem_size); |
| 152 | if (err < 0) { |
| 153 | ERROR("NT_FW_CONFIG: Failed to set local-ddr-size\n"); |
| 154 | return -1; |
| 155 | } |
| 156 | |
| 157 | flush_dcache_range((uintptr_t)fdt, mem_params->image_info.image_size); |
| 158 | |
| 159 | return 0; |
| 160 | } |
| 161 | |
| 162 | /******************************************************************************* |
| 163 | * This function returns the list of executable images. |
| 164 | ******************************************************************************/ |
| 165 | bl_params_t *plat_get_next_bl_params(void) |
| 166 | { |
| 167 | int ret; |
| 168 | struct morello_plat_info plat_info; |
Werner Lewis | cb5e71a | 2023-08-17 12:06:52 +0100 | [diff] [blame] | 169 | struct morello_firmware_version fw_version; |
sah01 | 066afc2 | 2021-11-18 10:04:27 +0000 | [diff] [blame] | 170 | |
Tamas Ban | f728b61 | 2023-05-08 13:50:37 +0200 | [diff] [blame] | 171 | ret = sds_init(SDS_SCP_AP_REGION_ID); |
sah01 | 066afc2 | 2021-11-18 10:04:27 +0000 | [diff] [blame] | 172 | if (ret != SDS_OK) { |
| 173 | ERROR("SDS initialization failed. ret:%d\n", ret); |
| 174 | panic(); |
| 175 | } |
| 176 | |
Tamas Ban | f728b61 | 2023-05-08 13:50:37 +0200 | [diff] [blame] | 177 | ret = sds_struct_read(SDS_SCP_AP_REGION_ID, |
| 178 | MORELLO_SDS_PLATFORM_INFO_STRUCT_ID, |
sah01 | 066afc2 | 2021-11-18 10:04:27 +0000 | [diff] [blame] | 179 | MORELLO_SDS_PLATFORM_INFO_OFFSET, |
| 180 | &plat_info, |
| 181 | MORELLO_SDS_PLATFORM_INFO_SIZE, |
| 182 | SDS_ACCESS_MODE_NON_CACHED); |
| 183 | if (ret != SDS_OK) { |
| 184 | ERROR("Error getting platform info from SDS. ret:%d\n", ret); |
| 185 | panic(); |
| 186 | } |
| 187 | |
Tamas Ban | f728b61 | 2023-05-08 13:50:37 +0200 | [diff] [blame] | 188 | ret = sds_struct_read(SDS_SCP_AP_REGION_ID, |
| 189 | MORELLO_SDS_FIRMWARE_VERSION_STRUCT_ID, |
Werner Lewis | cb5e71a | 2023-08-17 12:06:52 +0100 | [diff] [blame] | 190 | MORELLO_SDS_FIRMWARE_VERSION_OFFSET, |
| 191 | &fw_version, |
| 192 | MORELLO_SDS_FIRMWARE_VERSION_SIZE, |
| 193 | SDS_ACCESS_MODE_NON_CACHED); |
| 194 | if (ret != SDS_OK) { |
| 195 | ERROR("Error getting firmware version from SDS. ret:%d\n", ret); |
| 196 | panic(); |
| 197 | } |
| 198 | |
sah01 | 066afc2 | 2021-11-18 10:04:27 +0000 | [diff] [blame] | 199 | /* Validate plat_info SDS */ |
| 200 | #ifdef TARGET_PLATFORM_FVP |
| 201 | if (plat_info.local_ddr_size == 0U) { |
| 202 | #else |
| 203 | if ((plat_info.local_ddr_size == 0U) |
| 204 | || (plat_info.local_ddr_size > MORELLO_MAX_DDR_CAPACITY) |
| 205 | || (plat_info.remote_ddr_size > MORELLO_MAX_DDR_CAPACITY) |
| 206 | || (plat_info.remote_chip_count > MORELLO_MAX_REMOTE_CHIP_COUNT) |
| 207 | ){ |
| 208 | #endif |
| 209 | ERROR("platform info SDS is corrupted\n"); |
| 210 | panic(); |
| 211 | } |
| 212 | |
Werner Lewis | cb5e71a | 2023-08-17 12:06:52 +0100 | [diff] [blame] | 213 | ret = plat_morello_append_config_node(&plat_info, &fw_version); |
sah01 | 066afc2 | 2021-11-18 10:04:27 +0000 | [diff] [blame] | 214 | if (ret != 0) { |
| 215 | panic(); |
| 216 | } |
| 217 | |
| 218 | return arm_get_next_bl_params(); |
| 219 | } |