diff options
Diffstat (limited to 'spm/cactus/cactus_main.c')
-rw-r--r-- | spm/cactus/cactus_main.c | 177 |
1 files changed, 127 insertions, 50 deletions
diff --git a/spm/cactus/cactus_main.c b/spm/cactus/cactus_main.c index ff3f61871..b3f745182 100644 --- a/spm/cactus/cactus_main.c +++ b/spm/cactus/cactus_main.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2021, Arm Limited. All rights reserved. + * Copyright (c) 2018-2023, Arm Limited. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -9,22 +9,24 @@ #include <debug.h> #include <cactus_message_loop.h> -#include <cactus_platform_def.h> #include <drivers/arm/pl011.h> #include <drivers/console.h> #include <lib/aarch64/arch_helpers.h> #include <lib/tftf_lib.h> #include <lib/xlat_tables/xlat_mmu_helpers.h> #include <lib/xlat_tables/xlat_tables_v2.h> + +#include <ffa_helpers.h> #include <plat_arm.h> #include <plat/common/platform.h> #include <platform_def.h> +#include <sp_debug.h> #include <sp_helpers.h> #include <spm_helpers.h> #include <std_svc.h> -#include "cactus_def.h" -#include "cactus_tests.h" +#include "sp_def.h" +#include "sp_tests.h" #include "cactus.h" /* Host machine information injected by the build system in the ELF file. */ @@ -34,7 +36,7 @@ extern const char version_string[]; extern void secondary_cold_entry(void); /* Global ffa_id */ -ffa_vm_id_t g_ffa_id; +ffa_id_t g_ffa_id; /* * @@ -45,10 +47,10 @@ ffa_vm_id_t g_ffa_id; * */ -static void __dead2 message_loop(ffa_vm_id_t vm_id, struct mailbox_buffers *mb) +static void __dead2 message_loop(ffa_id_t vm_id, struct mailbox_buffers *mb) { - smc_ret_values ffa_ret; - ffa_vm_id_t destination; + struct ffa_value ffa_ret; + ffa_id_t destination; /* * This initial wait call is necessary to inform SPMD that @@ -67,14 +69,31 @@ static void __dead2 message_loop(ffa_vm_id_t vm_id, struct mailbox_buffers *mb) } if (ffa_func_id(ffa_ret) != FFA_MSG_SEND_DIRECT_REQ_SMC32 && - ffa_func_id(ffa_ret) != FFA_MSG_SEND_DIRECT_REQ_SMC64) { + ffa_func_id(ffa_ret) != FFA_MSG_SEND_DIRECT_REQ_SMC64 && + ffa_func_id(ffa_ret) != FFA_INTERRUPT && + ffa_func_id(ffa_ret) != FFA_RUN) { ERROR("%s(%u) unknown func id 0x%x\n", __func__, vm_id, ffa_func_id(ffa_ret)); break; } - destination = ffa_dir_msg_dest(ffa_ret); + if ((ffa_func_id(ffa_ret) == FFA_INTERRUPT) || + (ffa_func_id(ffa_ret) == FFA_RUN)) { + /* + * Received FFA_INTERRUPT in waiting state. + * The interrupt id is passed although this is just + * informational as we're running with virtual + * interrupts unmasked and the interrupt is processed + * by the interrupt handler. + * + * Received FFA_RUN in waiting state, the endpoint + * simply returns by FFA_MSG_WAIT. + */ + ffa_ret = ffa_msg_wait(); + continue; + } + destination = ffa_dir_msg_dest(ffa_ret); if (destination != vm_id) { ERROR("%s(%u) invalid vm id 0x%x\n", __func__, vm_id, destination); @@ -96,6 +115,10 @@ static const mmap_region_t cactus_mmap[] __attribute__((used)) = { /* scratch memory allocated to be used for running SMMU tests */ MAP_REGION_FLAT(PLAT_CACTUS_MEMCPY_BASE, PLAT_CACTUS_MEMCPY_RANGE, MT_MEMORY | MT_RW), +#if PLAT_fvp + MAP_REGION_FLAT(PLAT_CACTUS_NS_MEMCPY_BASE, PLAT_CACTUS_MEMCPY_RANGE, + MT_MEMORY | MT_RW | MT_NS), +#endif {0} }; @@ -124,6 +147,45 @@ static void cactus_print_memory_layout(unsigned int vm_id) (void *)get_sp_tx_end(vm_id)); } +static void cactus_print_boot_info(struct ffa_boot_info_header *boot_info_header) +{ + struct ffa_boot_info_desc *boot_info_desc; + + if (boot_info_header == NULL) { + NOTICE("SP doesn't have boot information!\n"); + return; + } + + VERBOSE("SP boot info:\n"); + VERBOSE(" Signature: %x\n", boot_info_header->signature); + VERBOSE(" Version: %x\n", boot_info_header->version); + VERBOSE(" Blob Size: %u\n", boot_info_header->info_blob_size); + VERBOSE(" Descriptor Size: %u\n", boot_info_header->desc_size); + VERBOSE(" Descriptor Count: %u\n", boot_info_header->desc_count); + + boot_info_desc = boot_info_header->boot_info; + + if (boot_info_desc == NULL) { + ERROR("Boot data arguments error...\n"); + return; + } + + for (uint32_t i = 0; i < boot_info_header->desc_count; i++) { + VERBOSE(" Boot Data:\n"); + VERBOSE(" Type: %u\n", + ffa_boot_info_type(&boot_info_desc[i])); + VERBOSE(" Type ID: %u\n", + ffa_boot_info_type_id(&boot_info_desc[i])); + VERBOSE(" Flags:\n"); + VERBOSE(" Name Format: %x\n", + ffa_boot_info_name_format(&boot_info_desc[i])); + VERBOSE(" Content Format: %x\n", + ffa_boot_info_content_format(&boot_info_desc[i])); + VERBOSE(" Size: %u\n", boot_info_desc[i].size); + VERBOSE(" Value: %llx\n", boot_info_desc[i].content); + } +} + static void cactus_plat_configure_mmu(unsigned int vm_id) { mmap_add_region(CACTUS_TEXT_START, @@ -145,44 +207,39 @@ static void cactus_plat_configure_mmu(unsigned int vm_id) mmap_add_region(get_sp_rx_start(vm_id), get_sp_rx_start(vm_id), - (CACTUS_RX_TX_SIZE / 2), + (SP_RX_TX_SIZE / 2), MT_RO_DATA); mmap_add_region(get_sp_tx_start(vm_id), get_sp_tx_start(vm_id), - (CACTUS_RX_TX_SIZE / 2), + (SP_RX_TX_SIZE / 2), MT_RW_DATA); mmap_add(cactus_mmap); init_xlat_tables(); } -static void register_secondary_entrypoint(void) +static struct ffa_value register_secondary_entrypoint(void) { - smc_args args; + struct ffa_value args; args.fid = FFA_SECONDARY_EP_REGISTER_SMC64; args.arg1 = (u_register_t)&secondary_cold_entry; - tftf_smc(&args); + return ffa_service_call(&args); } -int tftf_irq_handler_dispatcher(void) -{ - ERROR("%s\n", __func__); - - return 0; -} - -void __dead2 cactus_main(bool primary_cold_boot) +void __dead2 cactus_main(bool primary_cold_boot, + struct ffa_boot_info_header *boot_info_header) { assert(IS_IN_EL1() != 0); struct mailbox_buffers mb; + struct ffa_value ret; /* Get current FFA id */ - smc_ret_values ffa_id_ret = ffa_id_get(); - ffa_vm_id_t ffa_id = (ffa_vm_id_t)(ffa_id_ret.ret2 & 0xffff); + struct ffa_value ffa_id_ret = ffa_id_get(); + ffa_id_t ffa_id = ffa_endpoint_id(ffa_id_ret); if (ffa_func_id(ffa_id_ret) != FFA_SUCCESS_SMC32) { ERROR("FFA_ID_GET failed.\n"); panic(); @@ -198,6 +255,23 @@ void __dead2 cactus_main(bool primary_cold_boot) /* Configure and enable Stage-1 MMU, enable D-Cache */ cactus_plat_configure_mmu(ffa_id); + + /* Initialize locks for tail end interrupt handler */ + sp_handler_spin_lock_init(); + + if (boot_info_header != NULL) { + /* + * TODO: Currently just validating that cactus can + * access the boot info descriptors. In case we want to + * use the boot info contents, we should check the + * blob and remap if the size is bigger than one page. + * Only then access the contents. + */ + mmap_add_dynamic_region( + (unsigned long long)boot_info_header, + (uintptr_t)boot_info_header, + PAGE_SIZE, MT_RO_DATA); + } } /* @@ -216,38 +290,41 @@ void __dead2 cactus_main(bool primary_cold_boot) goto msg_loop; } - if (ffa_id == SPM_VM_ID_FIRST) { - console_init(CACTUS_PL011_UART_BASE, - CACTUS_PL011_UART_CLK_IN_HZ, - PL011_BAUDRATE); + set_putc_impl(FFA_SVC_SMC_CALL_AS_STDOUT); - set_putc_impl(PL011_AS_STDOUT); + /* Below string is monitored by CI expect script. */ + NOTICE("Booting Secure Partition (ID: %x)\n%s\n%s\n", + ffa_id, build_message, version_string); - NOTICE("Booting Primary Cactus Secure Partition\n%s\n%s\n", - build_message, version_string); - } else { - smc_ret_values ret; - set_putc_impl(HVC_CALL_AS_STDOUT); - - NOTICE("Booting Secondary Cactus Secure Partition (ID: %x)\n%s\n%s\n", - ffa_id, build_message, version_string); - - if (ffa_id == (SPM_VM_ID_FIRST + 2)) { - VERBOSE("Mapping RXTX Region\n"); - CONFIGURE_AND_MAP_MAILBOX(mb, PAGE_SIZE, ret); - if (ffa_func_id(ret) != FFA_SUCCESS_SMC32) { - ERROR( - "Failed to map RXTX buffers. Error: %x\n", - ffa_error_code(ret)); - panic(); - } + if (ffa_id == SP_ID(1)) { + cactus_print_boot_info(boot_info_header); + } + + if (ffa_id == (SPM_VM_ID_FIRST + 2)) { + VERBOSE("Mapping RXTX Region\n"); + CONFIGURE_AND_MAP_MAILBOX(mb, PAGE_SIZE, ret); + if (ffa_func_id(ret) != FFA_SUCCESS_SMC32) { + ERROR( + "Failed to map RXTX buffers. Error: %x\n", + ffa_error_code(ret)); + panic(); } } - INFO("FF-A id: %x\n", ffa_id); cactus_print_memory_layout(ffa_id); - register_secondary_entrypoint(); + ret = register_secondary_entrypoint(); + + /* FFA_SECONDARY_EP_REGISTER interface is not supported for UP SP. */ + if (ffa_id == (SPM_VM_ID_FIRST + 2)) { + expect(ffa_func_id(ret), FFA_ERROR); + expect(ffa_error_code(ret), FFA_ERROR_NOT_SUPPORTED); + } else { + expect(ffa_func_id(ret), FFA_SUCCESS_SMC32); + } + + discover_managed_exit_interrupt_id(); + register_maintenance_interrupt_handlers(); /* Invoking Tests */ ffa_tests(&mb); |