blob: 8554709f4f7d24fdbaf7ed55762961a1bb5b68d9 [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001/*
Olivier Deprez2661ba52024-02-19 18:50:53 +01002 * Copyright (c) 2018-2024, Arm Limited. All rights reserved.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <assert.h>
Antonio Nino Diaz43ef3932018-07-03 14:39:47 +01008#include <errno.h>
J-Alves9f6f0142020-06-17 15:37:59 +01009#include <debug.h>
Max Shvetsov103e0562021-02-04 16:58:31 +000010
J-Alveseeb25472021-03-11 09:54:21 +000011#include <cactus_message_loop.h>
J-Alves9f6f0142020-06-17 15:37:59 +010012#include <drivers/arm/pl011.h>
13#include <drivers/console.h>
J-Alves9f6f0142020-06-17 15:37:59 +010014#include <lib/aarch64/arch_helpers.h>
Kathleen Capella8808a942025-01-07 15:45:39 -050015#include <lib/hob/hob.h>
Max Shvetsov2263efb2020-11-12 17:30:11 +000016#include <lib/tftf_lib.h>
J-Alves9f6f0142020-06-17 15:37:59 +010017#include <lib/xlat_tables/xlat_mmu_helpers.h>
18#include <lib/xlat_tables/xlat_tables_v2.h>
Ruari Phippsddc661a2020-09-10 09:06:14 +010019
Daniel Boulbyce386b12022-03-29 18:36:36 +010020#include <ffa_helpers.h>
Max Shvetsov103e0562021-02-04 16:58:31 +000021#include <plat_arm.h>
22#include <plat/common/platform.h>
23#include <platform_def.h>
Ruari Phippsddc661a2020-09-10 09:06:14 +010024#include <sp_debug.h>
J-Alves5aecd982020-06-11 10:25:33 +010025#include <sp_helpers.h>
Olivier Deprez6967c242021-04-09 09:24:08 +020026#include <spm_helpers.h>
J-Alves9f6f0142020-06-17 15:37:59 +010027#include <std_svc.h>
Olivier Deprezafcdb7c2019-11-29 14:21:48 +010028
Daniel Boulbyf3da5912022-04-01 12:31:52 +010029#include "sp_def.h"
30#include "sp_tests.h"
Max Shvetsov103e0562021-02-04 16:58:31 +000031#include "cactus.h"
J-Alves63cdaa72020-10-08 17:22:45 +010032
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020033/* Host machine information injected by the build system in the ELF file. */
34extern const char build_message[];
35extern const char version_string[];
36
Max Shvetsov2263efb2020-11-12 17:30:11 +000037extern void secondary_cold_entry(void);
38
Manish Pandey87d4c702021-03-02 22:31:57 +000039/* Global ffa_id */
Daniel Boulbye79d2072021-03-03 11:34:53 +000040ffa_id_t g_ffa_id;
Manish Pandey87d4c702021-03-02 22:31:57 +000041
Olivier Deprezafcdb7c2019-11-29 14:21:48 +010042/*
43 *
44 * Message loop function
45 * Notice we cannot use regular print functions because this serves to both
46 * "primary" and "secondary" VMs. Secondary VM cannot access UART directly
47 * but rather through Hafnium print hypercall.
48 *
49 */
J-Alves0e1e7ca2021-01-25 14:11:06 +000050
Daniel Boulbye79d2072021-03-03 11:34:53 +000051static void __dead2 message_loop(ffa_id_t vm_id, struct mailbox_buffers *mb)
Olivier Deprezafcdb7c2019-11-29 14:21:48 +010052{
Daniel Boulbyce386b12022-03-29 18:36:36 +010053 struct ffa_value ffa_ret;
Daniel Boulbye79d2072021-03-03 11:34:53 +000054 ffa_id_t destination;
J-Alves1d203f12020-11-11 11:38:49 +000055
Olivier Deprezafcdb7c2019-11-29 14:21:48 +010056 /*
J-Alves63cdaa72020-10-08 17:22:45 +010057 * This initial wait call is necessary to inform SPMD that
58 * SP initialization has completed. It blocks until receiving
59 * a direct message request.
60 */
61
J-Alves7581c382020-05-07 18:34:20 +010062 ffa_ret = ffa_msg_wait();
Olivier Deprezafcdb7c2019-11-29 14:21:48 +010063
64 for (;;) {
Madhukar Pappireddy6681b7a2024-11-01 16:27:44 -050065 VERBOSE("Woke up with func:%s id: %x\n",
66 ffa_func_name(ffa_func_id(ffa_ret)),
67 ffa_func_id(ffa_ret));
Olivier Deprezafcdb7c2019-11-29 14:21:48 +010068
J-Alves6cb21d92021-01-07 15:18:12 +000069 if (ffa_func_id(ffa_ret) == FFA_ERROR) {
Karl Meakine3e57062024-01-18 14:28:36 +000070 ERROR("Error: %s\n",
71 ffa_error_name(ffa_error_code(ffa_ret)));
J-Alvesda6ac322020-11-09 15:45:30 +000072 break;
73 }
74
J-Alves6cb21d92021-01-07 15:18:12 +000075 if (ffa_func_id(ffa_ret) != FFA_MSG_SEND_DIRECT_REQ_SMC32 &&
Madhukar Pappireddycd183ef2021-08-05 15:34:07 -050076 ffa_func_id(ffa_ret) != FFA_MSG_SEND_DIRECT_REQ_SMC64 &&
Olivier Deprez57245242022-08-24 16:19:27 +020077 ffa_func_id(ffa_ret) != FFA_INTERRUPT &&
78 ffa_func_id(ffa_ret) != FFA_RUN) {
Madhukar Pappireddy6681b7a2024-11-01 16:27:44 -050079 ERROR("%s(%x) unknown func id %s\n", __func__, vm_id,
Karl Meakine3e57062024-01-18 14:28:36 +000080 ffa_func_name(ffa_func_id(ffa_ret)));
Olivier Deprez73d81cf2020-09-15 16:57:00 +020081 break;
Olivier Deprezafcdb7c2019-11-29 14:21:48 +010082 }
83
Olivier Deprez57245242022-08-24 16:19:27 +020084 if ((ffa_func_id(ffa_ret) == FFA_INTERRUPT) ||
85 (ffa_func_id(ffa_ret) == FFA_RUN)) {
Madhukar Pappireddycd183ef2021-08-05 15:34:07 -050086 /*
87 * Received FFA_INTERRUPT in waiting state.
88 * The interrupt id is passed although this is just
89 * informational as we're running with virtual
90 * interrupts unmasked and the interrupt is processed
91 * by the interrupt handler.
92 */
Madhukar Pappireddy6681b7a2024-11-01 16:27:44 -050093 if (ffa_func_id(ffa_ret) == FFA_RUN) {
94 /*
95 * Received FFA_RUN in waiting state, the
96 * endpoint simply returns by FFA_MSG_WAIT.
97 */
98 VERBOSE("Nothing to do. Exit to NWd\n");
99 }
100
Madhukar Pappireddycd183ef2021-08-05 15:34:07 -0500101 ffa_ret = ffa_msg_wait();
102 continue;
103 }
J-Alvesda6ac322020-11-09 15:45:30 +0000104
Madhukar Pappireddycd183ef2021-08-05 15:34:07 -0500105 destination = ffa_dir_msg_dest(ffa_ret);
J-Alvesda6ac322020-11-09 15:45:30 +0000106 if (destination != vm_id) {
J-Alves6cb21d92021-01-07 15:18:12 +0000107 ERROR("%s(%u) invalid vm id 0x%x\n",
108 __func__, vm_id, destination);
Olivier Deprez73d81cf2020-09-15 16:57:00 +0200109 break;
Olivier Deprezafcdb7c2019-11-29 14:21:48 +0100110 }
Olivier Deprezafcdb7c2019-11-29 14:21:48 +0100111
J-Alves4cb9dee2021-03-03 13:59:52 +0000112 if (!cactus_handle_cmd(&ffa_ret, &ffa_ret, mb)) {
J-Alves63cdaa72020-10-08 17:22:45 +0100113 break;
114 }
Olivier Deprezafcdb7c2019-11-29 14:21:48 +0100115 }
Olivier Deprez73d81cf2020-09-15 16:57:00 +0200116
117 panic();
Olivier Deprezafcdb7c2019-11-29 14:21:48 +0100118}
119
120static const mmap_region_t cactus_mmap[] __attribute__((used)) = {
Daniel Boulby3d8cd682024-07-23 14:28:15 +0100121 MAP_REGION_FLAT(PLAT_CACTUS_DEVICE_BASE, PLAT_CACTUS_DEVICE_SIZE,
Arunachalam Ganapathy51be1fe2020-09-22 13:25:21 +0100122 MT_DEVICE | MT_RW),
Daniel Boulby3d8cd682024-07-23 14:28:15 +0100123
Madhukar Pappireddy172523b2020-12-31 19:25:33 -0600124 /* scratch memory allocated to be used for running SMMU tests */
125 MAP_REGION_FLAT(PLAT_CACTUS_MEMCPY_BASE, PLAT_CACTUS_MEMCPY_RANGE,
126 MT_MEMORY | MT_RW),
Madhukar Pappireddy5d4936a2024-02-12 18:49:21 -0600127#if PLAT_fvp
Madhukar Pappireddya08c7192023-10-18 17:49:32 -0500128 MAP_REGION_FLAT(PLAT_CACTUS_NS_MEMCPY_BASE, PLAT_CACTUS_MEMCPY_RANGE,
129 MT_MEMORY | MT_RW | MT_NS),
Madhukar Pappireddy5d4936a2024-02-12 18:49:21 -0600130#endif
Olivier Deprezafcdb7c2019-11-29 14:21:48 +0100131 {0}
132};
133
Manish Pandey26c6f812020-04-30 11:43:00 +0100134static void cactus_print_memory_layout(unsigned int vm_id)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200135{
Olivier Deprezaed7f082020-11-04 15:11:59 +0100136 INFO("Secure Partition memory layout:\n");
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200137
Olivier Deprezaed7f082020-11-04 15:11:59 +0100138 INFO(" Text region : %p - %p\n",
Antonio Nino Diaz1486f3b2018-06-26 10:30:10 +0100139 (void *)CACTUS_TEXT_START, (void *)CACTUS_TEXT_END);
Manish Pandey26c6f812020-04-30 11:43:00 +0100140
Olivier Deprezaed7f082020-11-04 15:11:59 +0100141 INFO(" Read-only data region : %p - %p\n",
Antonio Nino Diaz1486f3b2018-06-26 10:30:10 +0100142 (void *)CACTUS_RODATA_START, (void *)CACTUS_RODATA_END);
Manish Pandey26c6f812020-04-30 11:43:00 +0100143
Olivier Deprezaed7f082020-11-04 15:11:59 +0100144 INFO(" Data region : %p - %p\n",
Antonio Nino Diaz1486f3b2018-06-26 10:30:10 +0100145 (void *)CACTUS_DATA_START, (void *)CACTUS_DATA_END);
Manish Pandey26c6f812020-04-30 11:43:00 +0100146
Olivier Deprezaed7f082020-11-04 15:11:59 +0100147 INFO(" BSS region : %p - %p\n",
Antonio Nino Diaz1486f3b2018-06-26 10:30:10 +0100148 (void *)CACTUS_BSS_START, (void *)CACTUS_BSS_END);
Manish Pandey26c6f812020-04-30 11:43:00 +0100149
Olivier Deprezaed7f082020-11-04 15:11:59 +0100150 INFO(" RX : %p - %p\n",
Max Shvetsovc32f4782020-06-23 09:41:15 +0100151 (void *)get_sp_rx_start(vm_id),
152 (void *)get_sp_rx_end(vm_id));
Manish Pandey26c6f812020-04-30 11:43:00 +0100153
Olivier Deprezaed7f082020-11-04 15:11:59 +0100154 INFO(" TX : %p - %p\n",
Max Shvetsovc32f4782020-06-23 09:41:15 +0100155 (void *)get_sp_tx_start(vm_id),
156 (void *)get_sp_tx_end(vm_id));
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200157}
158
Kathleen Capella8808a942025-01-07 15:45:39 -0500159static void cactus_print_hob_list(uint64_t hob_content_addr, size_t size)
160{
161 INFO("SP Hob List Contents: 0x%llx, size 0x%lx\n", hob_content_addr, size);
162 struct efi_hob_handoff_info_table *hob_list = (struct
163 efi_hob_handoff_info_table *) hob_content_addr;
164
165 dump_hob_list(hob_list);
166}
167
J-Alves31d87952022-04-04 12:34:16 +0100168static void cactus_print_boot_info(struct ffa_boot_info_header *boot_info_header)
169{
170 struct ffa_boot_info_desc *boot_info_desc;
171
172 if (boot_info_header == NULL) {
173 NOTICE("SP doesn't have boot information!\n");
174 return;
175 }
176
177 VERBOSE("SP boot info:\n");
178 VERBOSE(" Signature: %x\n", boot_info_header->signature);
179 VERBOSE(" Version: %x\n", boot_info_header->version);
180 VERBOSE(" Blob Size: %u\n", boot_info_header->info_blob_size);
181 VERBOSE(" Descriptor Size: %u\n", boot_info_header->desc_size);
182 VERBOSE(" Descriptor Count: %u\n", boot_info_header->desc_count);
183
184 boot_info_desc = boot_info_header->boot_info;
185
186 if (boot_info_desc == NULL) {
187 ERROR("Boot data arguments error...\n");
188 return;
189 }
190
191 for (uint32_t i = 0; i < boot_info_header->desc_count; i++) {
192 VERBOSE(" Boot Data:\n");
193 VERBOSE(" Type: %u\n",
194 ffa_boot_info_type(&boot_info_desc[i]));
195 VERBOSE(" Type ID: %u\n",
196 ffa_boot_info_type_id(&boot_info_desc[i]));
197 VERBOSE(" Flags:\n");
198 VERBOSE(" Name Format: %x\n",
199 ffa_boot_info_name_format(&boot_info_desc[i]));
200 VERBOSE(" Content Format: %x\n",
201 ffa_boot_info_content_format(&boot_info_desc[i]));
202 VERBOSE(" Size: %u\n", boot_info_desc[i].size);
203 VERBOSE(" Value: %llx\n", boot_info_desc[i].content);
Kathleen Capella8808a942025-01-07 15:45:39 -0500204 if (ffa_boot_info_type_id(&boot_info_desc[i]) == 1) {
205 cactus_print_hob_list(boot_info_desc[i].content, boot_info_desc[i].size);
206 }
J-Alves31d87952022-04-04 12:34:16 +0100207 }
208}
209
Manish Pandey26c6f812020-04-30 11:43:00 +0100210static void cactus_plat_configure_mmu(unsigned int vm_id)
Antonio Nino Diaz43ef3932018-07-03 14:39:47 +0100211{
Olivier Deprezafcdb7c2019-11-29 14:21:48 +0100212 mmap_add_region(CACTUS_TEXT_START,
213 CACTUS_TEXT_START,
214 CACTUS_TEXT_END - CACTUS_TEXT_START,
215 MT_CODE);
216 mmap_add_region(CACTUS_RODATA_START,
217 CACTUS_RODATA_START,
218 CACTUS_RODATA_END - CACTUS_RODATA_START,
219 MT_RO_DATA);
220 mmap_add_region(CACTUS_DATA_START,
221 CACTUS_DATA_START,
222 CACTUS_DATA_END - CACTUS_DATA_START,
223 MT_RW_DATA);
224 mmap_add_region(CACTUS_BSS_START,
225 CACTUS_BSS_START,
226 CACTUS_BSS_END - CACTUS_BSS_START,
227 MT_RW_DATA);
Antonio Nino Diaz43ef3932018-07-03 14:39:47 +0100228
Max Shvetsovc32f4782020-06-23 09:41:15 +0100229 mmap_add_region(get_sp_rx_start(vm_id),
230 get_sp_rx_start(vm_id),
Daniel Boulbyf3da5912022-04-01 12:31:52 +0100231 (SP_RX_TX_SIZE / 2),
Manish Pandey26c6f812020-04-30 11:43:00 +0100232 MT_RO_DATA);
233
Max Shvetsovc32f4782020-06-23 09:41:15 +0100234 mmap_add_region(get_sp_tx_start(vm_id),
235 get_sp_tx_start(vm_id),
Daniel Boulbyf3da5912022-04-01 12:31:52 +0100236 (SP_RX_TX_SIZE / 2),
Manish Pandey26c6f812020-04-30 11:43:00 +0100237 MT_RW_DATA);
238
Kathleen Capellaeb2dd232025-02-07 18:41:54 -0500239 mmap_add(cactus_mmap);
Olivier Deprezafcdb7c2019-11-29 14:21:48 +0100240 init_xlat_tables();
Antonio Nino Diaz43ef3932018-07-03 14:39:47 +0100241}
242
Madhukar Pappireddyd4de7ed2023-12-11 17:48:48 -0600243static struct ffa_value register_secondary_entrypoint(void)
Max Shvetsov2263efb2020-11-12 17:30:11 +0000244{
Arunachalam Ganapathybbf08c52023-11-07 13:38:54 +0000245 struct ffa_value args;
Max Shvetsov2263efb2020-11-12 17:30:11 +0000246
247 args.fid = FFA_SECONDARY_EP_REGISTER_SMC64;
248 args.arg1 = (u_register_t)&secondary_cold_entry;
249
Madhukar Pappireddyd4de7ed2023-12-11 17:48:48 -0600250 return ffa_service_call(&args);
Max Shvetsov2263efb2020-11-12 17:30:11 +0000251}
252
J-Alves8ac4dd82024-12-17 19:37:33 +0000253static void cactus_map_boot_info(struct ffa_boot_info_header *boot_info_header,
254 bool do_desc_access)
255{
256 struct ffa_boot_info_desc *boot_info_desc;
257
258 assert(boot_info_header != NULL);
259
260 boot_info_desc = boot_info_header->boot_info;
261 /*
262 * TODO: Currently just validating that cactus can
263 * access the boot info descriptors. By default, allocate one page
264 * for boot info. In case we want to use the boot info contents, we should check the
265 * blob and remap if the size is bigger than one page.
266 * Only then access the contents.
267 */
268 mmap_add_dynamic_region(
269 (unsigned long long)boot_info_header,
270 (uintptr_t)boot_info_header,
271 PAGE_SIZE, MT_RO_DATA);
272
273 if (do_desc_access) {
274 for (uint32_t i = 0; i < boot_info_header->desc_count; i++) {
275 mmap_add_dynamic_region(
276 (unsigned long long)boot_info_desc[i].content,
277 (uintptr_t)boot_info_desc[i].content,
278 PAGE_SIZE, MT_RO_DATA);
279 }
280 }
281}
282
J-Alves31d87952022-04-04 12:34:16 +0100283void __dead2 cactus_main(bool primary_cold_boot,
284 struct ffa_boot_info_header *boot_info_header)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200285{
Olivier Deprezafcdb7c2019-11-29 14:21:48 +0100286 assert(IS_IN_EL1() != 0);
287
Max Shvetsovc32f4782020-06-23 09:41:15 +0100288 struct mailbox_buffers mb;
Daniel Boulbyce386b12022-03-29 18:36:36 +0100289 struct ffa_value ret;
J-Alvesda6ac322020-11-09 15:45:30 +0000290
J-Alves7581c382020-05-07 18:34:20 +0100291 /* Get current FFA id */
Daniel Boulbyce386b12022-03-29 18:36:36 +0100292 struct ffa_value ffa_id_ret = ffa_id_get();
Daniel Boulby198deda2021-03-03 11:35:25 +0000293 ffa_id_t ffa_id = ffa_endpoint_id(ffa_id_ret);
J-Alves6cb21d92021-01-07 15:18:12 +0000294 if (ffa_func_id(ffa_id_ret) != FFA_SUCCESS_SMC32) {
J-Alves7581c382020-05-07 18:34:20 +0100295 ERROR("FFA_ID_GET failed.\n");
Olivier Deprezafcdb7c2019-11-29 14:21:48 +0100296 panic();
297 }
Olivier Deprezafcdb7c2019-11-29 14:21:48 +0100298
Max Shvetsov2263efb2020-11-12 17:30:11 +0000299 if (primary_cold_boot == true) {
300 /* Clear BSS */
301 memset((void *)CACTUS_BSS_START,
302 0, CACTUS_BSS_END - CACTUS_BSS_START);
303
Max Shvetsov2263efb2020-11-12 17:30:11 +0000304 mb.send = (void *) get_sp_tx_start(ffa_id);
305 mb.recv = (void *) get_sp_rx_start(ffa_id);
306
307 /* Configure and enable Stage-1 MMU, enable D-Cache */
308 cactus_plat_configure_mmu(ffa_id);
Madhukar Pappireddy7caaa4a2022-01-28 17:01:35 -0600309
310 /* Initialize locks for tail end interrupt handler */
311 sp_handler_spin_lock_init();
J-Alves31d87952022-04-04 12:34:16 +0100312
313 if (boot_info_header != NULL) {
Kathleen Capellaeb2dd232025-02-07 18:41:54 -0500314 cactus_map_boot_info(boot_info_header, ffa_id == SP_ID(3));
J-Alves31d87952022-04-04 12:34:16 +0100315 }
Max Shvetsov2263efb2020-11-12 17:30:11 +0000316 }
317
Manish Pandey87d4c702021-03-02 22:31:57 +0000318 /*
319 * The local ffa_id value is held on the stack. The global g_ffa_id
320 * value is set after BSS is cleared.
321 */
322 g_ffa_id = ffa_id;
323
Manish Pandey26c6f812020-04-30 11:43:00 +0100324 enable_mmu_el1(0);
325
Manish Pandeyd27b37d2021-03-02 14:41:58 +0000326 /* Enable IRQ/FIQ */
327 enable_irq();
328 enable_fiq();
329
Max Shvetsov2263efb2020-11-12 17:30:11 +0000330 if (primary_cold_boot == false) {
331 goto msg_loop;
332 }
333
J-Alvesf3ea1a82024-01-17 11:06:55 +0000334 set_putc_impl(FFA_SVC_SMC_CALL_AS_STDOUT);
Manish Pandey29495372020-04-09 15:19:26 +0100335
Olivier Deprez24bd1702021-10-05 14:35:17 +0200336 /* Below string is monitored by CI expect script. */
337 NOTICE("Booting Secure Partition (ID: %x)\n%s\n%s\n",
338 ffa_id, build_message, version_string);
Ruari Phippsbd0a7e42020-07-17 16:42:21 +0100339
J-Alves8ac4dd82024-12-17 19:37:33 +0000340 /*
341 * Print FF-A boot info if requested in manifest via FF-A boot info
342 * protocol.
343 */
Kathleen Capellaeb2dd232025-02-07 18:41:54 -0500344 if (ffa_id == SP_ID(1) || ffa_id == SP_ID(3)) {
J-Alvesf3ea1a82024-01-17 11:06:55 +0000345 cactus_print_boot_info(boot_info_header);
346 }
347
J-Alves8ac4dd82024-12-17 19:37:33 +0000348 cactus_print_memory_layout(ffa_id);
349
Kathleen Capellae8a17a92024-12-05 18:28:29 -0500350 /*
Kathleen Capellaeb2dd232025-02-07 18:41:54 -0500351 * Cactus-tertiary makes use of FFA_RXTX_MAP API instead of specifying
352 * `rx_tx-info` in its manifest, as done by the primary and secondary
353 * cactus partitions.
Kathleen Capellae8a17a92024-12-05 18:28:29 -0500354 */
Kathleen Capellaeb2dd232025-02-07 18:41:54 -0500355 if (ffa_id == SP_ID(3)) {
Olivier Deprez24bd1702021-10-05 14:35:17 +0200356 VERBOSE("Mapping RXTX Region\n");
357 CONFIGURE_AND_MAP_MAILBOX(mb, PAGE_SIZE, ret);
358 if (ffa_func_id(ret) != FFA_SUCCESS_SMC32) {
Karl Meakine3e57062024-01-18 14:28:36 +0000359 ERROR("Failed to map RXTX buffers. Error: %s\n",
360 ffa_error_name(ffa_error_code(ret)));
Olivier Deprez24bd1702021-10-05 14:35:17 +0200361 panic();
Ruari Phippsbd0a7e42020-07-17 16:42:21 +0100362 }
Olivier Deprezafcdb7c2019-11-29 14:21:48 +0100363 }
Manish Pandey26c6f812020-04-30 11:43:00 +0100364
Manish Pandey26c6f812020-04-30 11:43:00 +0100365
Madhukar Pappireddyd4de7ed2023-12-11 17:48:48 -0600366 ret = register_secondary_entrypoint();
367
368 /* FFA_SECONDARY_EP_REGISTER interface is not supported for UP SP. */
Kathleen Capellaeb2dd232025-02-07 18:41:54 -0500369 if (ffa_id == SP_ID(3)) {
Karl Meakinc884d6b2024-04-16 14:01:10 +0100370 EXPECT(ffa_func_id(ret), FFA_ERROR);
371 EXPECT(ffa_error_code(ret), FFA_ERROR_NOT_SUPPORTED);
Madhukar Pappireddyd4de7ed2023-12-11 17:48:48 -0600372 } else {
Karl Meakinc884d6b2024-04-16 14:01:10 +0100373 EXPECT(ffa_func_id(ret), FFA_SUCCESS_SMC32);
Madhukar Pappireddyd4de7ed2023-12-11 17:48:48 -0600374 }
375
Madhukar Pappireddy6f7344b2024-07-05 16:21:26 -0500376#if !SPMC_AT_EL3
Madhukar Pappireddyca1e2012022-06-22 17:05:09 -0500377 discover_managed_exit_interrupt_id();
Madhukar Pappireddy4d1f1122023-03-16 17:54:24 -0500378 register_maintenance_interrupt_handlers();
Max Shvetsov2263efb2020-11-12 17:30:11 +0000379
Olivier Deprez2661ba52024-02-19 18:50:53 +0100380 /* Invoking self tests */
J-Alves367154e2024-05-13 18:01:02 +0100381 ffa_tests(&mb, true);
Olivier Deprez2661ba52024-02-19 18:50:53 +0100382 cpu_feature_tests();
Madhukar Pappireddy6f7344b2024-07-05 16:21:26 -0500383#endif
J-Alves9f6f0142020-06-17 15:37:59 +0100384
Max Shvetsov2263efb2020-11-12 17:30:11 +0000385msg_loop:
Olivier Deprezafcdb7c2019-11-29 14:21:48 +0100386 /* End up to message loop */
J-Alves63cdaa72020-10-08 17:22:45 +0100387 message_loop(ffa_id, &mb);
Antonio Nino Diaz43ef3932018-07-03 14:39:47 +0100388
Olivier Deprezafcdb7c2019-11-29 14:21:48 +0100389 /* Not reached */
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200390}