| From 84f4ef4c4f2f45e2f54597f1afe80d8f8396cc57 Mon Sep 17 00:00:00 2001 |
| From: Balint Dobszay <balint.dobszay@arm.com> |
| Date: Fri, 10 Feb 2023 11:07:27 +0100 |
| Subject: core: ffa: add TOS_FW_CONFIG handling |
| |
| At boot TF-A passes two DT addresses (HW_CONFIG and TOS_FW_CONFIG), but |
| currently only the HW_CONFIG address is saved, the other one is dropped. |
| This commit adds functionality to save the TOS_FW_CONFIG too, so we can |
| retrieve it later. This is necessary for the CFG_CORE_SEL1_SPMC use |
| case, because the SPMC manifest is passed in this DT. |
| |
| Upstream-Status: Accepted |
| |
| Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> |
| Signed-off-by: Balint Dobszay <balint.dobszay@arm.com> |
| --- |
| core/arch/arm/kernel/boot.c | 60 ++++++++++++++++++++++- |
| core/arch/arm/kernel/entry_a32.S | 3 +- |
| core/arch/arm/kernel/entry_a64.S | 13 ++++- |
| core/arch/arm/kernel/link_dummies_paged.c | 4 +- |
| core/arch/arm/kernel/secure_partition.c | 2 +- |
| core/include/kernel/boot.h | 7 ++- |
| 6 files changed, 81 insertions(+), 8 deletions(-) |
| |
| diff --git a/core/arch/arm/kernel/boot.c b/core/arch/arm/kernel/boot.c |
| index e02c02b60..98e13c072 100644 |
| --- a/core/arch/arm/kernel/boot.c |
| +++ b/core/arch/arm/kernel/boot.c |
| @@ -1,6 +1,7 @@ |
| // SPDX-License-Identifier: BSD-2-Clause |
| /* |
| * Copyright (c) 2015-2022, Linaro Limited |
| + * Copyright (c) 2023, Arm Limited |
| */ |
| |
| #include <arm.h> |
| @@ -83,6 +84,9 @@ struct dt_descriptor { |
| }; |
| |
| static struct dt_descriptor external_dt __nex_bss; |
| +#ifdef CFG_CORE_SEL1_SPMC |
| +static struct dt_descriptor tos_fw_config_dt __nex_bss; |
| +#endif |
| #endif |
| |
| #ifdef CFG_SECONDARY_INIT_CNTFRQ |
| @@ -1224,6 +1228,54 @@ static struct core_mmu_phys_mem *get_nsec_memory(void *fdt __unused, |
| #endif /*CFG_CORE_DYN_SHM*/ |
| #endif /*!CFG_DT*/ |
| |
| +#if defined(CFG_CORE_SEL1_SPMC) && defined(CFG_DT) |
| +void *get_tos_fw_config_dt(void) |
| +{ |
| + if (!IS_ENABLED(CFG_MAP_EXT_DT_SECURE)) |
| + return NULL; |
| + |
| + assert(cpu_mmu_enabled()); |
| + |
| + return tos_fw_config_dt.blob; |
| +} |
| + |
| +static void init_tos_fw_config_dt(unsigned long pa) |
| +{ |
| + struct dt_descriptor *dt = &tos_fw_config_dt; |
| + void *fdt = NULL; |
| + int ret = 0; |
| + |
| + if (!IS_ENABLED(CFG_MAP_EXT_DT_SECURE)) |
| + return; |
| + |
| + if (!pa) |
| + panic("No TOS_FW_CONFIG DT found"); |
| + |
| + fdt = core_mmu_add_mapping(MEM_AREA_EXT_DT, pa, CFG_DTB_MAX_SIZE); |
| + if (!fdt) |
| + panic("Failed to map TOS_FW_CONFIG DT"); |
| + |
| + dt->blob = fdt; |
| + |
| + ret = fdt_open_into(fdt, fdt, CFG_DTB_MAX_SIZE); |
| + if (ret < 0) { |
| + EMSG("Invalid Device Tree at %#lx: error %d", pa, ret); |
| + panic(); |
| + } |
| + |
| + IMSG("TOS_FW_CONFIG DT found"); |
| +} |
| +#else |
| +void *get_tos_fw_config_dt(void) |
| +{ |
| + return NULL; |
| +} |
| + |
| +static void init_tos_fw_config_dt(unsigned long pa __unused) |
| +{ |
| +} |
| +#endif /*CFG_CORE_SEL1_SPMC && CFG_DT*/ |
| + |
| #ifdef CFG_CORE_DYN_SHM |
| static void discover_nsec_memory(void) |
| { |
| @@ -1361,10 +1413,16 @@ static bool cpu_nmfi_enabled(void) |
| * Note: this function is weak just to make it possible to exclude it from |
| * the unpaged area. |
| */ |
| -void __weak boot_init_primary_late(unsigned long fdt) |
| +void __weak boot_init_primary_late(unsigned long fdt, |
| + unsigned long tos_fw_config) |
| { |
| init_external_dt(fdt); |
| + init_tos_fw_config_dt(tos_fw_config); |
| +#ifdef CFG_CORE_SEL1_SPMC |
| + tpm_map_log_area(get_tos_fw_config_dt()); |
| +#else |
| tpm_map_log_area(get_external_dt()); |
| +#endif |
| discover_nsec_memory(); |
| update_external_dt(); |
| configure_console_from_dt(); |
| diff --git a/core/arch/arm/kernel/entry_a32.S b/core/arch/arm/kernel/entry_a32.S |
| index 0f14ca2f6..3758fd8b7 100644 |
| --- a/core/arch/arm/kernel/entry_a32.S |
| +++ b/core/arch/arm/kernel/entry_a32.S |
| @@ -1,7 +1,7 @@ |
| /* SPDX-License-Identifier: BSD-2-Clause */ |
| /* |
| * Copyright (c) 2014, Linaro Limited |
| - * Copyright (c) 2021, Arm Limited |
| + * Copyright (c) 2021-2023, Arm Limited |
| */ |
| |
| #include <arm32_macros.S> |
| @@ -560,6 +560,7 @@ shadow_stack_access_ok: |
| str r0, [r8, #THREAD_CORE_LOCAL_FLAGS] |
| #endif |
| mov r0, r6 /* DT address */ |
| + mov r1, #0 /* unused */ |
| bl boot_init_primary_late |
| #ifndef CFG_VIRTUALIZATION |
| mov r0, #THREAD_CLF_TMP |
| diff --git a/core/arch/arm/kernel/entry_a64.S b/core/arch/arm/kernel/entry_a64.S |
| index 047ae1f25..fa76437fb 100644 |
| --- a/core/arch/arm/kernel/entry_a64.S |
| +++ b/core/arch/arm/kernel/entry_a64.S |
| @@ -1,7 +1,7 @@ |
| /* SPDX-License-Identifier: BSD-2-Clause */ |
| /* |
| * Copyright (c) 2015-2022, Linaro Limited |
| - * Copyright (c) 2021, Arm Limited |
| + * Copyright (c) 2021-2023, Arm Limited |
| */ |
| |
| #include <platform_config.h> |
| @@ -320,7 +320,11 @@ clear_nex_bss: |
| bl core_mmu_set_default_prtn_tbl |
| #endif |
| |
| +#ifdef CFG_CORE_SEL1_SPMC |
| + mov x0, xzr /* pager not used */ |
| +#else |
| mov x0, x19 /* pagable part address */ |
| +#endif |
| mov x1, #-1 |
| bl boot_init_primary_early |
| |
| @@ -337,7 +341,12 @@ clear_nex_bss: |
| mov x22, x0 |
| str wzr, [x22, #THREAD_CORE_LOCAL_FLAGS] |
| #endif |
| - mov x0, x20 /* DT address */ |
| + mov x0, x20 /* DT address also known as HW_CONFIG */ |
| +#ifdef CFG_CORE_SEL1_SPMC |
| + mov x1, x19 /* TOS_FW_CONFIG DT address */ |
| +#else |
| + mov x1, xzr /* unused */ |
| +#endif |
| bl boot_init_primary_late |
| #ifdef CFG_CORE_PAUTH |
| init_pauth_per_cpu |
| diff --git a/core/arch/arm/kernel/link_dummies_paged.c b/core/arch/arm/kernel/link_dummies_paged.c |
| index 3b8287e06..023a5f3f5 100644 |
| --- a/core/arch/arm/kernel/link_dummies_paged.c |
| +++ b/core/arch/arm/kernel/link_dummies_paged.c |
| @@ -1,6 +1,7 @@ |
| // SPDX-License-Identifier: BSD-2-Clause |
| /* |
| * Copyright (c) 2017-2021, Linaro Limited |
| + * Copyright (c) 2023, Arm Limited |
| */ |
| #include <compiler.h> |
| #include <initcall.h> |
| @@ -27,7 +28,8 @@ void __section(".text.dummy.call_finalcalls") call_finalcalls(void) |
| } |
| |
| void __section(".text.dummy.boot_init_primary_late") |
| -boot_init_primary_late(unsigned long fdt __unused) |
| +boot_init_primary_late(unsigned long fdt __unused, |
| + unsigned long tos_fw_config __unused) |
| { |
| } |
| |
| diff --git a/core/arch/arm/kernel/secure_partition.c b/core/arch/arm/kernel/secure_partition.c |
| index 1d36e90b1..d386f1e4d 100644 |
| --- a/core/arch/arm/kernel/secure_partition.c |
| +++ b/core/arch/arm/kernel/secure_partition.c |
| @@ -1212,7 +1212,7 @@ static TEE_Result fip_sp_map_all(void) |
| int subnode = 0; |
| int root = 0; |
| |
| - fdt = get_external_dt(); |
| + fdt = get_tos_fw_config_dt(); |
| if (!fdt) { |
| EMSG("No SPMC manifest found"); |
| return TEE_ERROR_GENERIC; |
| diff --git a/core/include/kernel/boot.h b/core/include/kernel/boot.h |
| index 260854473..941e093b2 100644 |
| --- a/core/include/kernel/boot.h |
| +++ b/core/include/kernel/boot.h |
| @@ -1,7 +1,7 @@ |
| /* SPDX-License-Identifier: BSD-2-Clause */ |
| /* |
| * Copyright (c) 2015-2020, Linaro Limited |
| - * Copyright (c) 2021, Arm Limited |
| + * Copyright (c) 2021-2023, Arm Limited |
| */ |
| #ifndef __KERNEL_BOOT_H |
| #define __KERNEL_BOOT_H |
| @@ -46,7 +46,7 @@ extern const struct core_mmu_config boot_mmu_config; |
| /* @nsec_entry is unused if using CFG_WITH_ARM_TRUSTED_FW */ |
| void boot_init_primary_early(unsigned long pageable_part, |
| unsigned long nsec_entry); |
| -void boot_init_primary_late(unsigned long fdt); |
| +void boot_init_primary_late(unsigned long fdt, unsigned long tos_fw_config); |
| void boot_init_memtag(void); |
| |
| void __panic_at_smc_return(void) __noreturn; |
| @@ -103,6 +103,9 @@ void *get_embedded_dt(void); |
| /* Returns external DTB if present, otherwise NULL */ |
| void *get_external_dt(void); |
| |
| +/* Returns TOS_FW_CONFIG DTB if present, otherwise NULL */ |
| +void *get_tos_fw_config_dt(void); |
| + |
| /* |
| * get_aslr_seed() - return a random seed for core ASLR |
| * @fdt: Pointer to a device tree if CFG_DT_ADDR=y |
| -- |
| 2.39.1.windows.1 |
| |