From 341df6af6eb911ffd175e129f61fc59efcf9fcea Mon Sep 17 00:00:00 2001 From: Rohit Mathew Date: Sun, 21 Jan 2024 22:49:08 +0000 Subject: [PATCH] feat(arm): move GPT setup to common BL source As of now, GPT setup is being handled from BL2 for plat/arm platforms. However, for platforms having a separate entity to load firmware images, it is possible for BL31 to setup the GPT. In order to address this concern, move the GPT setup implementation from arm_bl2_setup.c file to arm_common.c. Additionally, rename the API from arm_bl2_gpt_setup to arm_gpt_setup to make it boot stage agnostic. Signed-off-by: Rohit Mathew Change-Id: I35d17a179c8746945c69db37fd23d763a7774ddc --- .../granule-protection-tables-design.rst | 2 +- include/plat/arm/common/plat_arm.h | 1 + plat/arm/common/arm_bl2_setup.c | 42 +------------------ plat/arm/common/arm_common.c | 42 ++++++++++++++++++- 4 files changed, 44 insertions(+), 43 deletions(-) diff --git a/docs/components/granule-protection-tables-design.rst b/docs/components/granule-protection-tables-design.rst index 7a4ffcf0b..9d85bef82 100644 --- a/docs/components/granule-protection-tables-design.rst +++ b/docs/components/granule-protection-tables-design.rst @@ -81,7 +81,7 @@ below. In the reference implementation for FVP models, you can find an example of PAS region definitions in the file ``plat/arm/board/fvp/include/fvp_pas_def.h``. -Table creation API calls can be found in ``plat/arm/common/arm_bl2_setup.c`` and +Table creation API calls can be found in ``plat/arm/common/arm_common.c`` and runtime initialization API calls can be seen in ``plat/arm/common/arm_bl31_setup.c``. diff --git a/include/plat/arm/common/plat_arm.h b/include/plat/arm/common/plat_arm.h index 97f544630..4c425a70c 100644 --- a/include/plat/arm/common/plat_arm.h +++ b/include/plat/arm/common/plat_arm.h @@ -375,6 +375,7 @@ unsigned int plat_arm_calc_core_pos(u_register_t mpidr); const mmap_region_t *plat_arm_get_mmap(void); const arm_gpt_info_t *plat_arm_get_gpt_info(void); +void arm_gpt_setup(void); /* Allow platform to override psci_pm_ops during runtime */ const plat_psci_ops_t *plat_arm_psci_override_pm_ops(plat_psci_ops_t *ops); diff --git a/plat/arm/common/arm_bl2_setup.c b/plat/arm/common/arm_bl2_setup.c index 3ef561a92..30d064791 100644 --- a/plat/arm/common/arm_bl2_setup.c +++ b/plat/arm/common/arm_bl2_setup.c @@ -131,46 +131,6 @@ void bl2_platform_setup(void) arm_bl2_platform_setup(); } -#if ENABLE_RME -static void arm_bl2_gpt_setup(void) -{ - /* - * It is to be noted that any Arm platform that reuses arm_bl2_gpt_setup - * must implement plat_arm_get_gpt_info within its platform code - */ - const arm_gpt_info_t *arm_gpt_info = - plat_arm_get_gpt_info(); - - if (arm_gpt_info == NULL) { - ERROR("arm_gpt_info not initialized!!\n"); - panic(); - } - - /* Initialize entire protected space to GPT_GPI_ANY. */ - if (gpt_init_l0_tables(arm_gpt_info->pps, arm_gpt_info->l0_base, - arm_gpt_info->l0_size) < 0) { - ERROR("gpt_init_l0_tables() failed!\n"); - panic(); - } - - /* Carve out defined PAS ranges. */ - if (gpt_init_pas_l1_tables(arm_gpt_info->pgs, - arm_gpt_info->l1_base, - arm_gpt_info->l1_size, - arm_gpt_info->pas_region_base, - arm_gpt_info->pas_region_count) < 0) { - ERROR("gpt_init_pas_l1_tables() failed!\n"); - panic(); - } - - INFO("Enabling Granule Protection Checks\n"); - if (gpt_enable() < 0) { - ERROR("gpt_enable() failed!\n"); - panic(); - } -} -#endif /* ENABLE_RME */ - /******************************************************************************* * Perform the very early platform specific architectural setup here. * When RME is enabled the secure environment is initialised before @@ -211,7 +171,7 @@ void arm_bl2_plat_arch_setup(void) enable_mmu_el3(0); /* Initialise and enable granule protection after MMU. */ - arm_bl2_gpt_setup(); + arm_gpt_setup(); #else enable_mmu_el1(0); #endif diff --git a/plat/arm/common/arm_common.c b/plat/arm/common/arm_common.c index fc681149e..21cc39ccf 100644 --- a/plat/arm/common/arm_common.c +++ b/plat/arm/common/arm_common.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015-2021, ARM Limited and Contributors. All rights reserved. + * Copyright (c) 2015-2024, ARM Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -241,3 +241,43 @@ const mmap_region_t *plat_get_addr_mmap(void) { return plat_arm_mmap; } + +#if ENABLE_RME +void arm_gpt_setup(void) +{ + /* + * It is to be noted that any Arm platform that reuses arm_gpt_setup + * must implement plat_arm_get_gpt_info within its platform code + */ + const arm_gpt_info_t *arm_gpt_info = + plat_arm_get_gpt_info(); + + if (arm_gpt_info == NULL) { + ERROR("arm_gpt_info not initialized!!\n"); + panic(); + } + + /* Initialize entire protected space to GPT_GPI_ANY. */ + if (gpt_init_l0_tables(arm_gpt_info->pps, arm_gpt_info->l0_base, + arm_gpt_info->l0_size) < 0) { + ERROR("gpt_init_l0_tables() failed!\n"); + panic(); + } + + /* Carve out defined PAS ranges. */ + if (gpt_init_pas_l1_tables(arm_gpt_info->pgs, + arm_gpt_info->l1_base, + arm_gpt_info->l1_size, + arm_gpt_info->pas_region_base, + arm_gpt_info->pas_region_count) < 0) { + ERROR("gpt_init_pas_l1_tables() failed!\n"); + panic(); + } + + INFO("Enabling Granule Protection Checks\n"); + if (gpt_enable() < 0) { + ERROR("gpt_enable() failed!\n"); + panic(); + } +} +#endif /* ENABLE_RME */