blob: cfe8bee5891cfd452530f59b6d458877c5ff2c55 [file] [log] [blame]
sah01066afc22021-11-18 10:04:27 +00001/*
Tamas Banf728b612023-05-08 13:50:37 +02002 * Copyright (c) 2021-2024, Arm Limited. All rights reserved.
sah01066afc22021-11-18 10:04:27 +00003 *
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 Banf728b612023-05-08 13:50:37 +020016#include <platform_def.h>
sah01066afc22021-11-18 10:04:27 +000017
sah01066afc22021-11-18 10:04:27 +000018/* 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 */
21static inline uint64_t get_mem_client_mode(uint64_t size)
22{
23 return (size - (size / 128ULL));
24}
25
26/*******************************************************************************
Werner Lewiscb5e71a2023-08-17 12:06:52 +010027 * This function inserts Platform information and firmware versions
28 * via device tree nodes as,
sah01066afc22021-11-18 10:04:27 +000029 * 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 Lewiscb5e71a2023-08-17 12:06:52 +010038 * 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 Lewisa2e00bf2023-08-17 12:10:06 +010045 * tfa-fw-version = "unknown-dirty_00000000";
Werner Lewiscb5e71a2023-08-17 12:06:52 +010046 * };
sah01066afc22021-11-18 10:04:27 +000047 ******************************************************************************/
Werner Lewiscb5e71a2023-08-17 12:06:52 +010048static int plat_morello_append_config_node(struct morello_plat_info *plat_info,
49 struct morello_firmware_version *fw_version)
sah01066afc22021-11-18 10:04:27 +000050{
51 bl_mem_params_node_t *mem_params;
52 void *fdt;
Werner Lewiscb5e71a2023-08-17 12:06:52 +010053 int nodeoffset_plat, nodeoffset_fw, err;
sah01066afc22021-11-18 10:04:27 +000054 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 Lewiscb5e71a2023-08-17 12:06:52 +010072 nodeoffset_plat = fdt_subnode_offset(fdt, 0, "platform-info");
73 if (nodeoffset_plat < 0) {
sah01066afc22021-11-18 10:04:27 +000074 ERROR("NT_FW_CONFIG: Failed to get platform-info node offset\n");
75 return -1;
76 }
77
Werner Lewiscb5e71a2023-08-17 12:06:52 +010078 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
sah01066afc22021-11-18 10:04:27 +000084#ifdef TARGET_PLATFORM_SOC
Werner Lewiscb5e71a2023-08-17 12:06:52 +010085 err = fdt_setprop_u64(fdt, nodeoffset_plat, "remote-ddr-size",
sah01066afc22021-11-18 10:04:27 +000086 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 Lewiscb5e71a2023-08-17 12:06:52 +010092 err = fdt_setprop_u32(fdt, nodeoffset_plat, "remote-chip-count",
sah01066afc22021-11-18 10:04:27 +000093 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 Lewiscb5e71a2023-08-17 12:06:52 +010099 err = fdt_setprop_u32(fdt, nodeoffset_plat, "multichip-mode",
sah01066afc22021-11-18 10:04:27 +0000100 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 Lewiscb5e71a2023-08-17 12:06:52 +0100106 err = fdt_setprop_u32(fdt, nodeoffset_plat, "scc-config",
sah01066afc22021-11-18 10:04:27 +0000107 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 Lewiscb5e71a2023-08-17 12:06:52 +0100116
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 }
sah01066afc22021-11-18 10:04:27 +0000130#endif
Werner Lewiscb5e71a2023-08-17 12:06:52 +0100131 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 Lewisa2e00bf2023-08-17 12:10:06 +0100145 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 Lewiscb5e71a2023-08-17 12:06:52 +0100150 err = fdt_setprop_u64(fdt, nodeoffset_plat, "local-ddr-size",
sah01066afc22021-11-18 10:04:27 +0000151 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 ******************************************************************************/
165bl_params_t *plat_get_next_bl_params(void)
166{
167 int ret;
168 struct morello_plat_info plat_info;
Werner Lewiscb5e71a2023-08-17 12:06:52 +0100169 struct morello_firmware_version fw_version;
sah01066afc22021-11-18 10:04:27 +0000170
Tamas Banf728b612023-05-08 13:50:37 +0200171 ret = sds_init(SDS_SCP_AP_REGION_ID);
sah01066afc22021-11-18 10:04:27 +0000172 if (ret != SDS_OK) {
173 ERROR("SDS initialization failed. ret:%d\n", ret);
174 panic();
175 }
176
Tamas Banf728b612023-05-08 13:50:37 +0200177 ret = sds_struct_read(SDS_SCP_AP_REGION_ID,
178 MORELLO_SDS_PLATFORM_INFO_STRUCT_ID,
sah01066afc22021-11-18 10:04:27 +0000179 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 Banf728b612023-05-08 13:50:37 +0200188 ret = sds_struct_read(SDS_SCP_AP_REGION_ID,
189 MORELLO_SDS_FIRMWARE_VERSION_STRUCT_ID,
Werner Lewiscb5e71a2023-08-17 12:06:52 +0100190 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
sah01066afc22021-11-18 10:04:27 +0000199 /* 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 Lewiscb5e71a2023-08-17 12:06:52 +0100213 ret = plat_morello_append_config_node(&plat_info, &fw_version);
sah01066afc22021-11-18 10:04:27 +0000214 if (ret != 0) {
215 panic();
216 }
217
218 return arm_get_next_bl_params();
219}