blob: 4ea2bb3019847696394d79151d50314555d46fc8 [file] [log] [blame]
sah01066afc22021-11-18 10:04:27 +00001/*
Chandni Cherukuric873efc2023-02-16 20:22:32 +05302 * Copyright (c) 2021-2023, 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>
16
sah01066afc22021-11-18 10:04:27 +000017/* In client mode, a part of the DDR memory is reserved for Tag bits.
18 * Calculate the usable memory size after subtracting the Tag memory.
19 */
20static inline uint64_t get_mem_client_mode(uint64_t size)
21{
22 return (size - (size / 128ULL));
23}
24
25/*******************************************************************************
Werner Lewiscb5e71a2023-08-17 12:06:52 +010026 * This function inserts Platform information and firmware versions
27 * via device tree nodes as,
sah01066afc22021-11-18 10:04:27 +000028 * platform-info {
29 * local-ddr-size = <0x0 0x0>;
30 *#ifdef TARGET_PLATFORM_SOC
31 * remote-ddr-size = <0x0 0x0>;
32 * remote-chip-count = <0x0>;
33 * multichip-mode = <0x0>;
34 * scc-config = <0x0>;
35 *#endif
36 * };
Werner Lewiscb5e71a2023-08-17 12:06:52 +010037 * firmware-version {
38 *#ifdef TARGET_PLATFORM_SOC
39 * mcc-fw-version = <0x0>;
40 * pcc-fw-version = <0x0>;
41 *#endif
42 * scp-fw-version = <0x0>;
43 * scp-fw-commit = <0x0>;
Werner Lewisa2e00bf2023-08-17 12:10:06 +010044 * tfa-fw-version = "unknown-dirty_00000000";
Werner Lewiscb5e71a2023-08-17 12:06:52 +010045 * };
sah01066afc22021-11-18 10:04:27 +000046 ******************************************************************************/
Werner Lewiscb5e71a2023-08-17 12:06:52 +010047static int plat_morello_append_config_node(struct morello_plat_info *plat_info,
48 struct morello_firmware_version *fw_version)
sah01066afc22021-11-18 10:04:27 +000049{
50 bl_mem_params_node_t *mem_params;
51 void *fdt;
Werner Lewiscb5e71a2023-08-17 12:06:52 +010052 int nodeoffset_plat, nodeoffset_fw, err;
sah01066afc22021-11-18 10:04:27 +000053 uint64_t usable_mem_size;
54
55 usable_mem_size = plat_info->local_ddr_size;
56
57 mem_params = get_bl_mem_params_node(NT_FW_CONFIG_ID);
58 if (mem_params == NULL) {
59 ERROR("NT_FW CONFIG base address is NULL\n");
60 return -1;
61 }
62
63 fdt = (void *)(mem_params->image_info.image_base);
64
65 /* Check the validity of the fdt */
66 if (fdt_check_header(fdt) != 0) {
67 ERROR("Invalid NT_FW_CONFIG DTB passed\n");
68 return -1;
69 }
70
Werner Lewiscb5e71a2023-08-17 12:06:52 +010071 nodeoffset_plat = fdt_subnode_offset(fdt, 0, "platform-info");
72 if (nodeoffset_plat < 0) {
sah01066afc22021-11-18 10:04:27 +000073 ERROR("NT_FW_CONFIG: Failed to get platform-info node offset\n");
74 return -1;
75 }
76
Werner Lewiscb5e71a2023-08-17 12:06:52 +010077 nodeoffset_fw = fdt_subnode_offset(fdt, 0, "firmware-version");
78 if (nodeoffset_fw < 0) {
79 ERROR("NT_FW_CONFIG: Failed to get firmware-version node offset\n");
80 return -1;
81 }
82
sah01066afc22021-11-18 10:04:27 +000083#ifdef TARGET_PLATFORM_SOC
Werner Lewiscb5e71a2023-08-17 12:06:52 +010084 err = fdt_setprop_u64(fdt, nodeoffset_plat, "remote-ddr-size",
sah01066afc22021-11-18 10:04:27 +000085 plat_info->remote_ddr_size);
86 if (err < 0) {
87 ERROR("NT_FW_CONFIG: Failed to set remote-ddr-size\n");
88 return -1;
89 }
90
Werner Lewiscb5e71a2023-08-17 12:06:52 +010091 err = fdt_setprop_u32(fdt, nodeoffset_plat, "remote-chip-count",
sah01066afc22021-11-18 10:04:27 +000092 plat_info->remote_chip_count);
93 if (err < 0) {
94 ERROR("NT_FW_CONFIG: Failed to set remote-chip-count\n");
95 return -1;
96 }
97
Werner Lewiscb5e71a2023-08-17 12:06:52 +010098 err = fdt_setprop_u32(fdt, nodeoffset_plat, "multichip-mode",
sah01066afc22021-11-18 10:04:27 +000099 plat_info->multichip_mode);
100 if (err < 0) {
101 ERROR("NT_FW_CONFIG: Failed to set multichip-mode\n");
102 return -1;
103 }
104
Werner Lewiscb5e71a2023-08-17 12:06:52 +0100105 err = fdt_setprop_u32(fdt, nodeoffset_plat, "scc-config",
sah01066afc22021-11-18 10:04:27 +0000106 plat_info->scc_config);
107 if (err < 0) {
108 ERROR("NT_FW_CONFIG: Failed to set scc-config\n");
109 return -1;
110 }
111
112 if (plat_info->scc_config & MORELLO_SCC_CLIENT_MODE_MASK) {
113 usable_mem_size = get_mem_client_mode(plat_info->local_ddr_size);
114 }
Werner Lewiscb5e71a2023-08-17 12:06:52 +0100115
116 err = fdt_setprop_u32(fdt, nodeoffset_fw, "mcc-fw-version",
117 fw_version->mcc_fw_ver);
118 if (err < 0) {
119 ERROR("NT_FW_CONFIG: Failed to set mcc-fw-version\n");
120 return -1;
121 }
122
123 err = fdt_setprop_u32(fdt, nodeoffset_fw, "pcc-fw-version",
124 fw_version->pcc_fw_ver);
125 if (err < 0) {
126 ERROR("NT_FW_CONFIG: Failed to set pcc-fw-version\n");
127 return -1;
128 }
sah01066afc22021-11-18 10:04:27 +0000129#endif
Werner Lewiscb5e71a2023-08-17 12:06:52 +0100130 err = fdt_setprop_u32(fdt, nodeoffset_fw, "scp-fw-version",
131 fw_version->scp_fw_ver);
132 if (err < 0) {
133 ERROR("NT_FW_CONFIG: Failed to set scp-fw-version\n");
134 return -1;
135 }
136
137 err = fdt_setprop_u32(fdt, nodeoffset_fw, "scp-fw-commit",
138 fw_version->scp_fw_commit);
139 if (err < 0) {
140 ERROR("NT_FW_CONFIG: Failed to set scp-fw-commit\n");
141 return -1;
142 }
143
Werner Lewisa2e00bf2023-08-17 12:10:06 +0100144 err = fdt_setprop_string(fdt, nodeoffset_fw, "tfa-fw-version", version_string);
145 if (err < 0) {
146 WARN("NT_FW_CONFIG: Unable to set tfa-fw-version\n");
147 }
148
Werner Lewiscb5e71a2023-08-17 12:06:52 +0100149 err = fdt_setprop_u64(fdt, nodeoffset_plat, "local-ddr-size",
sah01066afc22021-11-18 10:04:27 +0000150 usable_mem_size);
151 if (err < 0) {
152 ERROR("NT_FW_CONFIG: Failed to set local-ddr-size\n");
153 return -1;
154 }
155
156 flush_dcache_range((uintptr_t)fdt, mem_params->image_info.image_size);
157
158 return 0;
159}
160
161/*******************************************************************************
162 * This function returns the list of executable images.
163 ******************************************************************************/
164bl_params_t *plat_get_next_bl_params(void)
165{
166 int ret;
167 struct morello_plat_info plat_info;
Werner Lewiscb5e71a2023-08-17 12:06:52 +0100168 struct morello_firmware_version fw_version;
sah01066afc22021-11-18 10:04:27 +0000169
170 ret = sds_init();
171 if (ret != SDS_OK) {
172 ERROR("SDS initialization failed. ret:%d\n", ret);
173 panic();
174 }
175
176 ret = sds_struct_read(MORELLO_SDS_PLATFORM_INFO_STRUCT_ID,
177 MORELLO_SDS_PLATFORM_INFO_OFFSET,
178 &plat_info,
179 MORELLO_SDS_PLATFORM_INFO_SIZE,
180 SDS_ACCESS_MODE_NON_CACHED);
181 if (ret != SDS_OK) {
182 ERROR("Error getting platform info from SDS. ret:%d\n", ret);
183 panic();
184 }
185
Werner Lewiscb5e71a2023-08-17 12:06:52 +0100186 ret = sds_struct_read(MORELLO_SDS_FIRMWARE_VERSION_STRUCT_ID,
187 MORELLO_SDS_FIRMWARE_VERSION_OFFSET,
188 &fw_version,
189 MORELLO_SDS_FIRMWARE_VERSION_SIZE,
190 SDS_ACCESS_MODE_NON_CACHED);
191 if (ret != SDS_OK) {
192 ERROR("Error getting firmware version from SDS. ret:%d\n", ret);
193 panic();
194 }
195
sah01066afc22021-11-18 10:04:27 +0000196 /* Validate plat_info SDS */
197#ifdef TARGET_PLATFORM_FVP
198 if (plat_info.local_ddr_size == 0U) {
199#else
200 if ((plat_info.local_ddr_size == 0U)
201 || (plat_info.local_ddr_size > MORELLO_MAX_DDR_CAPACITY)
202 || (plat_info.remote_ddr_size > MORELLO_MAX_DDR_CAPACITY)
203 || (plat_info.remote_chip_count > MORELLO_MAX_REMOTE_CHIP_COUNT)
204 ){
205#endif
206 ERROR("platform info SDS is corrupted\n");
207 panic();
208 }
209
Werner Lewiscb5e71a2023-08-17 12:06:52 +0100210 ret = plat_morello_append_config_node(&plat_info, &fw_version);
sah01066afc22021-11-18 10:04:27 +0000211 if (ret != 0) {
212 panic();
213 }
214
215 return arm_get_next_bl_params();
216}