blob: 3452fde74edc49f76b6d41aa6fe57d19142c9da0 [file] [log] [blame]
Jens Wiklander52c798e2015-12-07 14:37:10 +01001/*
Harrison Mutai8eba0142025-05-27 10:39:02 +00002 * Copyright (c) 2015-2025, Arm Limited and Contributors. All rights reserved.
Jens Wiklander52c798e2015-12-07 14:37:10 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Jens Wiklander52c798e2015-12-07 14:37:10 +01005 */
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00006
Fu Weic2f78442017-05-27 21:21:42 +08007#include <assert.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00008#include <string.h>
9
Jens Wiklander52c798e2015-12-07 14:37:10 +010010#include <libfdt.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000011
Jens Wiklander52c798e2015-12-07 14:37:10 +010012#include <platform_def.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000013
Jean-Philippe Brucker721b83d2023-09-07 18:13:07 +010014#include <arch_features.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000015#include <arch_helpers.h>
16#include <common/bl_common.h>
17#include <common/debug.h>
18#include <common/desc_image_load.h>
Andre Przywaraffbacb02019-07-10 17:27:17 +010019#include <common/fdt_fixup.h>
Jens Wiklandera43c1282022-11-22 14:39:26 +010020#include <common/fdt_wrappers.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000021#include <lib/optee_utils.h>
Harrison Mutai8eba0142025-05-27 10:39:02 +000022#if TRANSFER_LIST
Raymond Mao032ba022023-06-28 15:07:15 -070023#include <lib/transfer_list.h>
Harrison Mutai8eba0142025-05-27 10:39:02 +000024#endif
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000025#include <lib/utils.h>
26#include <plat/common/platform.h>
27
Isla Mitchelle3631462017-07-14 10:46:32 +010028#include "qemu_private.h"
Jens Wiklander52c798e2015-12-07 14:37:10 +010029
Chen Baozif7d9aa82023-02-20 10:50:15 +000030#define MAP_BL2_TOTAL MAP_REGION_FLAT( \
31 bl2_tzram_layout.total_base, \
32 bl2_tzram_layout.total_size, \
Jean-Philippe Bruckerb54f6c92023-09-07 17:46:12 +010033 MT_MEMORY | MT_RW | EL3_PAS)
Chen Baozif7d9aa82023-02-20 10:50:15 +000034
35#define MAP_BL2_RO MAP_REGION_FLAT( \
36 BL_CODE_BASE, \
37 BL_CODE_END - BL_CODE_BASE, \
Jean-Philippe Bruckerb54f6c92023-09-07 17:46:12 +010038 MT_CODE | EL3_PAS), \
Chen Baozif7d9aa82023-02-20 10:50:15 +000039 MAP_REGION_FLAT( \
40 BL_RO_DATA_BASE, \
41 BL_RO_DATA_END \
42 - BL_RO_DATA_BASE, \
Jean-Philippe Bruckerb54f6c92023-09-07 17:46:12 +010043 MT_RO_DATA | EL3_PAS)
Chen Baozif7d9aa82023-02-20 10:50:15 +000044
Chen Baozi097a43a2023-03-12 20:58:04 +080045#if USE_COHERENT_MEM
Chen Baozif7d9aa82023-02-20 10:50:15 +000046#define MAP_BL_COHERENT_RAM MAP_REGION_FLAT( \
47 BL_COHERENT_RAM_BASE, \
48 BL_COHERENT_RAM_END \
49 - BL_COHERENT_RAM_BASE, \
Jean-Philippe Bruckerb54f6c92023-09-07 17:46:12 +010050 MT_DEVICE | MT_RW | EL3_PAS)
Chen Baozi097a43a2023-03-12 20:58:04 +080051#endif
Jens Wiklander52c798e2015-12-07 14:37:10 +010052
Fu Weic2f78442017-05-27 21:21:42 +080053/* Data structure which holds the extents of the trusted SRAM for BL2 */
54static meminfo_t bl2_tzram_layout __aligned(CACHE_WRITEBACK_GRANULE);
Harrison Mutai8eba0142025-05-27 10:39:02 +000055static struct transfer_list_header __maybe_unused *bl2_tl;
Fu Weic2f78442017-05-27 21:21:42 +080056
Jens Wiklandere22b91e2018-09-04 14:07:19 +020057void bl2_early_platform_setup2(u_register_t arg0, u_register_t arg1,
58 u_register_t arg2, u_register_t arg3)
Jens Wiklander52c798e2015-12-07 14:37:10 +010059{
Jens Wiklandere22b91e2018-09-04 14:07:19 +020060 meminfo_t *mem_layout = (void *)arg1;
61
Jens Wiklander52c798e2015-12-07 14:37:10 +010062 /* Initialize the console to provide early debug support */
Michalis Pappascca6cb72018-03-04 15:43:38 +080063 qemu_console_init();
Jens Wiklander52c798e2015-12-07 14:37:10 +010064
65 /* Setup the BL2 memory layout */
66 bl2_tzram_layout = *mem_layout;
67
68 plat_qemu_io_setup();
69}
70
71static void security_setup(void)
72{
73 /*
74 * This is where a TrustZone address space controller and other
75 * security related peripherals, would be configured.
76 */
77}
78
79static void update_dt(void)
80{
Raymond Mao032ba022023-06-28 15:07:15 -070081#if TRANSFER_LIST
82 struct transfer_list_entry *te;
83#endif
Jens Wiklander52c798e2015-12-07 14:37:10 +010084 int ret;
Andrew Walbran9c4d0692020-01-15 14:11:31 +000085 void *fdt = (void *)(uintptr_t)ARM_PRELOADED_DTB_BASE;
Mathieu Poirierdfbaf642024-10-10 15:07:49 -060086 void *dst = plat_qemu_dt_runtime_address();
Jens Wiklander52c798e2015-12-07 14:37:10 +010087
Mathieu Poirierdfbaf642024-10-10 15:07:49 -060088 ret = fdt_open_into(fdt, dst, PLAT_QEMU_DT_MAX_SIZE);
Jens Wiklander52c798e2015-12-07 14:37:10 +010089 if (ret < 0) {
90 ERROR("Invalid Device Tree at %p: error %d\n", fdt, ret);
91 return;
92 }
93
94 if (dt_add_psci_node(fdt)) {
95 ERROR("Failed to add PSCI Device Tree node\n");
96 return;
97 }
98
99 if (dt_add_psci_cpu_enable_methods(fdt)) {
100 ERROR("Failed to add PSCI cpu enable methods in Device Tree\n");
101 return;
102 }
103
Jean-Philippe Brucker721b83d2023-09-07 18:13:07 +0100104#if ENABLE_RME
105 if (fdt_add_reserved_memory(fdt, "rmm", REALM_DRAM_BASE,
106 REALM_DRAM_SIZE)) {
107 ERROR("Failed to reserve RMM memory in Device Tree\n");
108 return;
109 }
110
111 INFO("Reserved RMM memory [0x%lx, 0x%lx] in Device tree\n",
112 (uintptr_t)REALM_DRAM_BASE,
113 (uintptr_t)REALM_DRAM_BASE + REALM_DRAM_SIZE - 1);
114#endif
115
Jens Wiklander52c798e2015-12-07 14:37:10 +0100116 ret = fdt_pack(fdt);
117 if (ret < 0)
118 ERROR("Failed to pack Device Tree at %p: error %d\n", fdt, ret);
Raymond Mao032ba022023-06-28 15:07:15 -0700119
120#if TRANSFER_LIST
Raymond Maobb653862023-10-04 09:58:29 -0700121 /* create a TE */
Raymond Mao032ba022023-06-28 15:07:15 -0700122 te = transfer_list_add(bl2_tl, TL_TAG_FDT, fdt_totalsize(fdt), fdt);
123 if (!te) {
124 ERROR("Failed to add FDT entry to Transfer List\n");
125 return;
126 }
127#endif
Jens Wiklander52c798e2015-12-07 14:37:10 +0100128}
129
130void bl2_platform_setup(void)
131{
Raymond Mao032ba022023-06-28 15:07:15 -0700132#if TRANSFER_LIST
133 bl2_tl = transfer_list_init((void *)(uintptr_t)FW_HANDOFF_BASE,
134 FW_HANDOFF_SIZE);
135 if (!bl2_tl) {
136 ERROR("Failed to initialize Transfer List at 0x%lx\n",
137 (unsigned long)FW_HANDOFF_BASE);
138 }
139#endif
Jens Wiklander52c798e2015-12-07 14:37:10 +0100140 security_setup();
141 update_dt();
142
143 /* TODO Initialize timer */
144}
145
Raymond Mao032ba022023-06-28 15:07:15 -0700146void qemu_bl2_sync_transfer_list(void)
147{
148#if TRANSFER_LIST
149 transfer_list_update_checksum(bl2_tl);
150#endif
151}
152
Chen Baozif7d9aa82023-02-20 10:50:15 +0000153void bl2_plat_arch_setup(void)
154{
155 const mmap_region_t bl_regions[] = {
156 MAP_BL2_TOTAL,
157 MAP_BL2_RO,
Chen Baozi097a43a2023-03-12 20:58:04 +0800158#if USE_COHERENT_MEM
Chen Baozif7d9aa82023-02-20 10:50:15 +0000159 MAP_BL_COHERENT_RAM,
Chen Baozi097a43a2023-03-12 20:58:04 +0800160#endif
Jean-Philippe Brucker721b83d2023-09-07 18:13:07 +0100161#if ENABLE_RME
162 MAP_RMM_DRAM,
163 MAP_GPT_L0_REGION,
164 MAP_GPT_L1_REGION,
165#endif
Chen Baozif7d9aa82023-02-20 10:50:15 +0000166 {0}
167 };
168
169 setup_page_tables(bl_regions, plat_qemu_get_mmap());
170
Jean-Philippe Brucker721b83d2023-09-07 18:13:07 +0100171#if ENABLE_RME
172 /* BL2 runs in EL3 when RME enabled. */
Sona Mathew9e505f92024-03-13 11:33:54 -0500173 assert(is_feat_rme_present());
Jean-Philippe Brucker721b83d2023-09-07 18:13:07 +0100174 enable_mmu_el3(0);
175#else /* ENABLE_RME */
176
Julius Werner8e0ef0f2019-07-09 14:02:43 -0700177#ifdef __aarch64__
Chen Baozif7d9aa82023-02-20 10:50:15 +0000178 enable_mmu_el1(0);
Julius Werner8e0ef0f2019-07-09 14:02:43 -0700179#else
Chen Baozif7d9aa82023-02-20 10:50:15 +0000180 enable_mmu_svc_mon(0);
Etienne Carriere911de8c2018-02-02 13:23:22 +0100181#endif
Jean-Philippe Brucker721b83d2023-09-07 18:13:07 +0100182#endif /* ENABLE_RME */
Jens Wiklander52c798e2015-12-07 14:37:10 +0100183}
184
185/*******************************************************************************
186 * Gets SPSR for BL32 entry
187 ******************************************************************************/
188static uint32_t qemu_get_spsr_for_bl32_entry(void)
189{
Julius Werner8e0ef0f2019-07-09 14:02:43 -0700190#ifdef __aarch64__
Jens Wiklander52c798e2015-12-07 14:37:10 +0100191 /*
192 * The Secure Payload Dispatcher service is responsible for
193 * setting the SPSR prior to entry into the BL3-2 image.
194 */
195 return 0;
Etienne Carriere911de8c2018-02-02 13:23:22 +0100196#else
197 return SPSR_MODE32(MODE32_svc, SPSR_T_ARM, SPSR_E_LITTLE,
198 DISABLE_ALL_EXCEPTIONS);
199#endif
Jens Wiklander52c798e2015-12-07 14:37:10 +0100200}
201
202/*******************************************************************************
203 * Gets SPSR for BL33 entry
204 ******************************************************************************/
205static uint32_t qemu_get_spsr_for_bl33_entry(void)
206{
Jens Wiklander52c798e2015-12-07 14:37:10 +0100207 uint32_t spsr;
Julius Werner8e0ef0f2019-07-09 14:02:43 -0700208#ifdef __aarch64__
Etienne Carriere911de8c2018-02-02 13:23:22 +0100209 unsigned int mode;
Jens Wiklander52c798e2015-12-07 14:37:10 +0100210
211 /* Figure out what mode we enter the non-secure world in */
Antonio Nino Diaz864ca6f2018-10-31 15:25:35 +0000212 mode = (el_implemented(2) != EL_IMPL_NONE) ? MODE_EL2 : MODE_EL1;
Jens Wiklander52c798e2015-12-07 14:37:10 +0100213
214 /*
215 * TODO: Consider the possibility of specifying the SPSR in
216 * the FIP ToC and allowing the platform to have a say as
217 * well.
218 */
219 spsr = SPSR_64(mode, MODE_SP_ELX, DISABLE_ALL_EXCEPTIONS);
Etienne Carriere911de8c2018-02-02 13:23:22 +0100220#else
221 spsr = SPSR_MODE32(MODE32_svc,
222 plat_get_ns_image_entrypoint() & 0x1,
223 SPSR_E_LITTLE, DISABLE_ALL_EXCEPTIONS);
224#endif
Jens Wiklander52c798e2015-12-07 14:37:10 +0100225 return spsr;
226}
227
Jens Wiklandera43c1282022-11-22 14:39:26 +0100228#if defined(SPD_spmd) && SPMD_SPM_AT_SEL2
229static int load_sps_from_tb_fw_config(struct image_info *image_info)
230{
231 void *dtb = (void *)image_info->image_base;
232 const char *compat_str = "arm,sp";
233 const struct fdt_property *uuid;
234 uint32_t load_addr;
235 const char *name;
236 int sp_node;
237 int node;
238
239 node = fdt_node_offset_by_compatible(dtb, -1, compat_str);
240 if (node < 0) {
241 ERROR("Can't find %s in TB_FW_CONFIG", compat_str);
242 return -1;
243 }
244
245 fdt_for_each_subnode(sp_node, dtb, node) {
246 name = fdt_get_name(dtb, sp_node, NULL);
247 if (name == NULL) {
248 ERROR("Can't get name of node in dtb\n");
249 return -1;
250 }
251 uuid = fdt_get_property(dtb, sp_node, "uuid", NULL);
252 if (uuid == NULL) {
253 ERROR("Can't find property uuid in node %s", name);
254 return -1;
255 }
256 if (fdt_read_uint32(dtb, sp_node, "load-address",
257 &load_addr) < 0) {
258 ERROR("Can't read load-address in node %s", name);
259 return -1;
260 }
261 if (qemu_io_register_sp_pkg(name, uuid->data, load_addr) < 0) {
262 return -1;
263 }
264 }
265
266 return 0;
267}
268#endif /*defined(SPD_spmd) && SPMD_SPM_AT_SEL2*/
269
Raymond Maobb653862023-10-04 09:58:29 -0700270#if defined(SPD_opteed) || defined(AARCH32_SP_OPTEE) || defined(SPMC_OPTEE)
271static int handoff_pageable_part(uint64_t pagable_part)
272{
273#if TRANSFER_LIST
274 struct transfer_list_entry *te;
275
276 te = transfer_list_add(bl2_tl, TL_TAG_OPTEE_PAGABLE_PART,
277 sizeof(pagable_part), &pagable_part);
278 if (!te) {
279 INFO("Cannot add TE for pageable part\n");
280 return -1;
281 }
282#endif
283 return 0;
284}
285#endif
286
Fu Weic2f78442017-05-27 21:21:42 +0800287static int qemu_bl2_handle_post_image_load(unsigned int image_id)
288{
289 int err = 0;
290 bl_mem_params_node_t *bl_mem_params = get_bl_mem_params_node(image_id);
Jens Wiklanderff263dc2021-05-25 18:15:11 +0200291#if defined(SPD_opteed) || defined(AARCH32_SP_OPTEE) || defined(SPMC_OPTEE)
Jens Wiklander0acbaaa2017-08-24 13:16:26 +0200292 bl_mem_params_node_t *pager_mem_params = NULL;
293 bl_mem_params_node_t *paged_mem_params = NULL;
294#endif
Jens Wiklanderff263dc2021-05-25 18:15:11 +0200295#if defined(SPD_spmd)
Jens Wiklanderd4b84f02022-11-18 15:40:04 +0100296 bl_mem_params_node_t *bl32_mem_params = NULL;
Jens Wiklanderff263dc2021-05-25 18:15:11 +0200297#endif
Raymond Mao032ba022023-06-28 15:07:15 -0700298#if TRANSFER_LIST
299 struct transfer_list_header *ns_tl = NULL;
Raymond Mao032ba022023-06-28 15:07:15 -0700300#endif
Fu Weic2f78442017-05-27 21:21:42 +0800301
302 assert(bl_mem_params);
303
304 switch (image_id) {
Raymond Maobb653862023-10-04 09:58:29 -0700305#if TRANSFER_LIST
306 case BL31_IMAGE_ID:
307 /*
308 * arg0 is a bl_params_t reserved for bl31_early_platform_setup2
levi.yun010d2ae2024-05-13 10:27:17 +0100309 * we just need arg1 and arg3 for BL31 to update the TL from S
Raymond Maobb653862023-10-04 09:58:29 -0700310 * to NS memory before it exits
311 */
levi.yun010d2ae2024-05-13 10:27:17 +0100312#ifdef __aarch64__
313 if (GET_RW(bl_mem_params->ep_info.spsr) == MODE_RW_64) {
314 bl_mem_params->ep_info.args.arg1 =
315 TRANSFER_LIST_HANDOFF_X1_VALUE(REGISTER_CONVENTION_VERSION);
316 } else
317#endif
318 {
319 bl_mem_params->ep_info.args.arg1 =
320 TRANSFER_LIST_HANDOFF_R1_VALUE(REGISTER_CONVENTION_VERSION);
321 }
322
Raymond Maobb653862023-10-04 09:58:29 -0700323 bl_mem_params->ep_info.args.arg3 = (uintptr_t)bl2_tl;
324 break;
325#endif
Fu Weic2f78442017-05-27 21:21:42 +0800326 case BL32_IMAGE_ID:
Jens Wiklanderff263dc2021-05-25 18:15:11 +0200327#if defined(SPD_opteed) || defined(AARCH32_SP_OPTEE) || defined(SPMC_OPTEE)
Jens Wiklander0acbaaa2017-08-24 13:16:26 +0200328 pager_mem_params = get_bl_mem_params_node(BL32_EXTRA1_IMAGE_ID);
329 assert(pager_mem_params);
330
331 paged_mem_params = get_bl_mem_params_node(BL32_EXTRA2_IMAGE_ID);
332 assert(paged_mem_params);
333
334 err = parse_optee_header(&bl_mem_params->ep_info,
335 &pager_mem_params->image_info,
336 &paged_mem_params->image_info);
337 if (err != 0) {
338 WARN("OPTEE header parse error.\n");
339 }
Raymond Maobb653862023-10-04 09:58:29 -0700340
341 /* add TL_TAG_OPTEE_PAGABLE_PART entry to the TL */
342 if (handoff_pageable_part(bl_mem_params->ep_info.args.arg1)) {
343 return -1;
344 }
Jens Wiklanderff263dc2021-05-25 18:15:11 +0200345#endif
Jens Wiklander0acbaaa2017-08-24 13:16:26 +0200346
Raymond Maobb653862023-10-04 09:58:29 -0700347 INFO("Handoff to BL32\n");
348 bl_mem_params->ep_info.spsr = qemu_get_spsr_for_bl32_entry();
Harrison Mutai8eba0142025-05-27 10:39:02 +0000349#if TRANSFER_LIST
350 if (transfer_list_set_handoff_args(bl2_tl,
351 &bl_mem_params->ep_info))
Raymond Maobb653862023-10-04 09:58:29 -0700352 break;
Harrison Mutai8eba0142025-05-27 10:39:02 +0000353#endif
Raymond Maobb653862023-10-04 09:58:29 -0700354 INFO("Using default arguments\n");
Jens Wiklanderd4b84f02022-11-18 15:40:04 +0100355#if defined(SPMC_OPTEE)
356 /*
357 * Explicit zeroes to unused registers since they may have
358 * been populated by parse_optee_header() above.
359 *
360 * OP-TEE expects system DTB in x2 and TOS_FW_CONFIG in x0,
361 * the latter is filled in below for TOS_FW_CONFIG_ID and
362 * applies to any other SPMC too.
363 */
364 bl_mem_params->ep_info.args.arg2 = ARM_PRELOADED_DTB_BASE;
Jens Wiklanderff263dc2021-05-25 18:15:11 +0200365#elif defined(SPD_opteed)
Jens Wiklander0acbaaa2017-08-24 13:16:26 +0200366 /*
367 * OP-TEE expect to receive DTB address in x2.
368 * This will be copied into x2 by dispatcher.
369 */
Andrew Walbran9c4d0692020-01-15 14:11:31 +0000370 bl_mem_params->ep_info.args.arg3 = ARM_PRELOADED_DTB_BASE;
Jens Wiklanderff263dc2021-05-25 18:15:11 +0200371#elif defined(AARCH32_SP_OPTEE)
Etienne Carriere911de8c2018-02-02 13:23:22 +0100372 bl_mem_params->ep_info.args.arg0 =
373 bl_mem_params->ep_info.args.arg1;
374 bl_mem_params->ep_info.args.arg1 = 0;
Andrew Walbran9c4d0692020-01-15 14:11:31 +0000375 bl_mem_params->ep_info.args.arg2 = ARM_PRELOADED_DTB_BASE;
Etienne Carriere911de8c2018-02-02 13:23:22 +0100376 bl_mem_params->ep_info.args.arg3 = 0;
377#endif
Fu Weic2f78442017-05-27 21:21:42 +0800378 break;
Etienne Carriere911de8c2018-02-02 13:23:22 +0100379
Fu Weic2f78442017-05-27 21:21:42 +0800380 case BL33_IMAGE_ID:
Etienne Carriere911de8c2018-02-02 13:23:22 +0100381#ifdef AARCH32_SP_OPTEE
382 /* AArch32 only core: OP-TEE expects NSec EP in register LR */
383 pager_mem_params = get_bl_mem_params_node(BL32_IMAGE_ID);
384 assert(pager_mem_params);
385 pager_mem_params->ep_info.lr_svc = bl_mem_params->ep_info.pc;
386#endif
387
Raymond Mao032ba022023-06-28 15:07:15 -0700388 bl_mem_params->ep_info.spsr = qemu_get_spsr_for_bl33_entry();
389
Andrew Walbran9c4d0692020-01-15 14:11:31 +0000390#if ARM_LINUX_KERNEL_AS_BL33
391 /*
392 * According to the file ``Documentation/arm64/booting.txt`` of
393 * the Linux kernel tree, Linux expects the physical address of
394 * the device tree blob (DTB) in x0, while x1-x3 are reserved
395 * for future use and must be 0.
396 */
397 bl_mem_params->ep_info.args.arg0 =
398 (u_register_t)ARM_PRELOADED_DTB_BASE;
399 bl_mem_params->ep_info.args.arg1 = 0U;
400 bl_mem_params->ep_info.args.arg2 = 0U;
401 bl_mem_params->ep_info.args.arg3 = 0U;
Raymond Mao032ba022023-06-28 15:07:15 -0700402#elif TRANSFER_LIST
403 if (bl2_tl) {
Raymond Maobb653862023-10-04 09:58:29 -0700404 /* relocate the tl to pre-allocate NS memory */
Raymond Mao032ba022023-06-28 15:07:15 -0700405 ns_tl = transfer_list_relocate(bl2_tl,
406 (void *)(uintptr_t)FW_NS_HANDOFF_BASE,
407 bl2_tl->max_size);
408 if (!ns_tl) {
409 ERROR("Relocate TL to 0x%lx failed\n",
410 (unsigned long)FW_NS_HANDOFF_BASE);
411 return -1;
412 }
Raymond Maobb653862023-10-04 09:58:29 -0700413 }
Raymond Mao032ba022023-06-28 15:07:15 -0700414
Raymond Maobb653862023-10-04 09:58:29 -0700415 INFO("Handoff to BL33\n");
416 if (!transfer_list_set_handoff_args(ns_tl,
417 &bl_mem_params->ep_info)) {
418 INFO("Invalid TL, fallback to default arguments\n");
Raymond Mao032ba022023-06-28 15:07:15 -0700419 bl_mem_params->ep_info.args.arg0 = 0xffff & read_mpidr();
420 }
Andrew Walbran9c4d0692020-01-15 14:11:31 +0000421#else
Fu Weic2f78442017-05-27 21:21:42 +0800422 /* BL33 expects to receive the primary CPU MPID (through r0) */
423 bl_mem_params->ep_info.args.arg0 = 0xffff & read_mpidr();
Raymond Maobb653862023-10-04 09:58:29 -0700424#endif /* ARM_LINUX_KERNEL_AS_BL33 */
Andrew Walbran9c4d0692020-01-15 14:11:31 +0000425
Fu Weic2f78442017-05-27 21:21:42 +0800426 break;
Jens Wiklandera43c1282022-11-22 14:39:26 +0100427#ifdef SPD_spmd
428#if SPMD_SPM_AT_SEL2
429 case TB_FW_CONFIG_ID:
430 err = load_sps_from_tb_fw_config(&bl_mem_params->image_info);
431 break;
432#endif
Jens Wiklanderd4b84f02022-11-18 15:40:04 +0100433 case TOS_FW_CONFIG_ID:
434 /* An SPMC expects TOS_FW_CONFIG in x0/r0 */
435 bl32_mem_params = get_bl_mem_params_node(BL32_IMAGE_ID);
436 bl32_mem_params->ep_info.args.arg0 =
437 bl_mem_params->image_info.image_base;
438 break;
439#endif
Jonathan Wrightff957ed2018-03-14 15:24:00 +0000440 default:
441 /* Do nothing in default case */
442 break;
Fu Weic2f78442017-05-27 21:21:42 +0800443 }
444
445 return err;
446}
447
448/*******************************************************************************
449 * This function can be used by the platforms to update/use image
450 * information for given `image_id`.
451 ******************************************************************************/
452int bl2_plat_handle_post_image_load(unsigned int image_id)
453{
454 return qemu_bl2_handle_post_image_load(image_id);
455}
Jens Wiklander52c798e2015-12-07 14:37:10 +0100456
Etienne Carriere911de8c2018-02-02 13:23:22 +0100457uintptr_t plat_get_ns_image_entrypoint(void)
Jens Wiklander52c798e2015-12-07 14:37:10 +0100458{
459 return NS_IMAGE_OFFSET;
460}