Unverified Commit 7e0a38a4 authored by Soby Mathew's avatar Soby Mathew Committed by GitHub
Browse files

Merge pull request #1603 from antonio-nino-diaz-arm/db/reclaim-init

 Reclaim BL31 initialization code memory for runtime data
parents e44b8a9d cb4adb0d
......@@ -815,7 +815,7 @@ void mmap_add_ctx(xlat_ctx_t *ctx, const mmap_region_t *mm)
{
const mmap_region_t *mm_cursor = mm;
while (mm_cursor->size != 0U) {
while (mm_cursor->attr != 0U) {
mmap_add_region_ctx(ctx, mm_cursor);
mm_cursor++;
}
......@@ -1012,7 +1012,7 @@ int mmap_remove_dynamic_region_ctx(xlat_ctx_t *ctx, uintptr_t base_va,
#endif /* PLAT_XLAT_TABLES_DYNAMIC */
void init_xlat_tables_ctx(xlat_ctx_t *ctx)
void __init init_xlat_tables_ctx(xlat_ctx_t *ctx)
{
assert(ctx != NULL);
assert(!ctx->initialized);
......
......@@ -252,10 +252,11 @@ endef
define MAKE_LD
$(eval DEP := $(1).d)
$(eval IMAGE := IMAGE_BL$(call uppercase,$(3)))
$(1): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | bl$(3)_dirs
@echo " PP $$<"
$$(Q)$$(CPP) $$(CPPFLAGS) -P -D__ASSEMBLY__ -D__LINKER__ $(MAKE_DEP) -o $$@ $$<
$$(Q)$$(CPP) $$(CPPFLAGS) -P -D__ASSEMBLY__ -D__LINKER__ $(MAKE_DEP) -D$(IMAGE) -o $$@ $$<
-include $(DEP)
......
......@@ -146,6 +146,10 @@ SDEI_SUPPORT := 0
# platform Makefile is free to override this value.
SEPARATE_CODE_AND_RODATA := 0
# If the BL31 image initialisation code is recalimed after use for the secondary
# cores stack
RECLAIM_INIT_CODE := 0
# Default to SMCCC Version 1.X
SMCCC_MAJOR_VERSION := 1
......
/*
* Copyright (c) 2013-2017, ARM Limited and Contributors. All rights reserved.
* Copyright (c) 2013-2018, ARM Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
......@@ -70,7 +70,7 @@ void fvp_pwrc_write_pcoffr(u_register_t mpidr)
}
/* Nothing else to do here apart from initializing the lock */
void plat_arm_pwrc_setup(void)
void __init plat_arm_pwrc_setup(void)
{
arm_lock_init();
}
......
......@@ -10,8 +10,8 @@
#include <smmu_v3.h>
#include "fvp_private.h"
void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
u_register_t arg2, u_register_t arg3)
void __init bl31_early_platform_setup2(u_register_t arg0,
u_register_t arg1, u_register_t arg2, u_register_t arg3)
{
arm_bl31_early_platform_setup((void *)arg0, arg1, arg2, (void *)arg3);
......
......@@ -241,7 +241,7 @@ const struct secure_partition_boot_info *plat_get_secure_partition_boot_info(
* these platforms. This information is stored in a per-BL array to allow the
* code to take the correct path.Per BL platform configuration.
******************************************************************************/
void fvp_config_setup(void)
void __init fvp_config_setup(void)
{
unsigned int rev, hbi, bld, arch, sys_id;
......@@ -331,7 +331,7 @@ void fvp_config_setup(void)
}
void fvp_interconnect_init(void)
void __init fvp_interconnect_init(void)
{
#if FVP_INTERCONNECT_DRIVER == FVP_CCN
if (ccn_get_part0_id(PLAT_ARM_CCN_BASE) != CCN_502_PART0_ID) {
......
......@@ -6,6 +6,7 @@
#ifndef __PLAT_LD_S__
#define __PLAT_LD_S__
#include <arm_common.ld.S>
#include <arm_tzc_dram.ld.S>
#include <arm_reclaim_init.ld.S>
#endif /* __PLAT_LD_S__ */
......@@ -201,6 +201,9 @@ ENABLE_AMU := 1
# Enable dynamic mitigation support by default
DYNAMIC_WORKAROUND_CVE_2018_3639 := 1
# Enable reclaiming of BL31 initialisation code for secondary cores stacks for FVP
RECLAIM_INIT_CODE := 1
ifeq (${ENABLE_AMU},1)
BL31_SOURCES += lib/cpus/aarch64/cortex_a75_pubsub.c \
lib/cpus/aarch64/cortex_ares_pubsub.c \
......
......@@ -15,6 +15,8 @@
#include <plat_arm.h>
#include <platform.h>
#include <ras.h>
#include <utils.h>
#include <arm_xlat_tables.h>
/*
* Placeholder variables for copying the arguments that have been passed to
......@@ -39,6 +41,16 @@ CASSERT(BL31_BASE >= ARM_TB_FW_CONFIG_LIMIT, assert_bl31_base_overflows);
BL31_BASE, \
BL31_END - BL31_BASE, \
MT_MEMORY | MT_RW | MT_SECURE)
#if RECLAIM_INIT_CODE
IMPORT_SYM(unsigned long, __INIT_CODE_START__, BL_INIT_CODE_BASE);
IMPORT_SYM(unsigned long, __INIT_CODE_END__, BL_INIT_CODE_END);
#define MAP_BL_INIT_CODE MAP_REGION_FLAT( \
BL_INIT_CODE_BASE, \
BL_INIT_CODE_END \
- BL_INIT_CODE_BASE, \
MT_CODE | MT_SECURE)
#endif
/*******************************************************************************
* Return a pointer to the 'entry_point_info' structure of the next image for the
......@@ -71,7 +83,7 @@ struct entry_point_info *bl31_plat_get_next_image_ep_info(uint32_t type)
* while creating page tables. BL2 has flushed this information to memory, so
* we are guaranteed to pick up good data.
******************************************************************************/
void arm_bl31_early_platform_setup(void *from_bl2, uintptr_t soc_fw_config,
void __init arm_bl31_early_platform_setup(void *from_bl2, uintptr_t soc_fw_config,
uintptr_t hw_config, void *plat_params_from_bl2)
{
/* Initialize the console to provide early debug support */
......@@ -233,9 +245,30 @@ void arm_bl31_plat_runtime_setup(void)
/* Initialize the runtime console */
arm_console_runtime_init();
#if RECLAIM_INIT_CODE
arm_free_init_memory();
#endif
}
void bl31_platform_setup(void)
#if RECLAIM_INIT_CODE
/*
* Zero out and make RW memory used to store image boot time code so it can
* be reclaimed during runtime
*/
void arm_free_init_memory(void)
{
int ret = xlat_change_mem_attributes(BL_INIT_CODE_BASE,
BL_INIT_CODE_END - BL_INIT_CODE_BASE,
MT_RW_DATA);
if (ret != 0) {
ERROR("Could not reclaim initialization code");
panic();
}
}
#endif
void __init bl31_platform_setup(void)
{
arm_bl31_platform_setup();
}
......@@ -251,16 +284,13 @@ void bl31_plat_runtime_setup(void)
* architectural setup (bl31_arch_setup()) does not do anything platform
* specific.
******************************************************************************/
void arm_bl31_plat_arch_setup(void)
void __init arm_bl31_plat_arch_setup(void)
{
#define ARM_MAP_BL_ROMLIB MAP_REGION_FLAT( \
BL31_BASE, \
BL31_END - BL31_BASE, \
MT_MEMORY | MT_RW | MT_SECURE)
const mmap_region_t bl_regions[] = {
MAP_BL31_TOTAL,
#if RECLAIM_INIT_CODE
MAP_BL_INIT_CODE,
#endif
ARM_MAP_BL_RO,
#if USE_ROMLIB
ARM_MAP_ROMLIB_CODE,
......@@ -279,7 +309,7 @@ void arm_bl31_plat_arch_setup(void)
arm_setup_romlib();
}
void bl31_plat_arch_setup(void)
void __init bl31_plat_arch_setup(void)
{
arm_bl31_plat_arch_setup();
}
/*
* Copyright (c) 2016, ARM Limited and Contributors. All rights reserved.
* Copyright (c) 2016-2018, ARM Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
......@@ -27,7 +27,7 @@ static const int cci_map[] = {
/******************************************************************************
* Helper function to initialize ARM CCI driver.
*****************************************************************************/
void plat_arm_interconnect_init(void)
void __init plat_arm_interconnect_init(void)
{
cci_init(PLAT_ARM_CCI_BASE, cci_map, ARRAY_SIZE(cci_map));
}
......
/*
* Copyright (c) 2016, ARM Limited and Contributors. All rights reserved.
* Copyright (c) 2016-2018, ARM Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
......@@ -34,7 +34,7 @@ CASSERT(PLAT_ARM_CLUSTER_COUNT == ARRAY_SIZE(master_to_rn_id_map),
/******************************************************************************
* Helper function to initialize ARM CCN driver.
*****************************************************************************/
void plat_arm_interconnect_init(void)
void __init plat_arm_interconnect_init(void)
{
ccn_init(&arm_ccn_desc);
}
......
......@@ -38,10 +38,11 @@ void arm_setup_romlib(void)
* as an array specifying the generic memory regions which can be;
* - Code section;
* - Read-only data section;
* - Init code section, if applicable
* - Coherent memory region, if applicable.
*/
void arm_setup_page_tables(const mmap_region_t bl_regions[],
void __init arm_setup_page_tables(const mmap_region_t bl_regions[],
const mmap_region_t plat_regions[])
{
#if LOG_LEVEL >= LOG_LEVEL_VERBOSE
......
......@@ -273,3 +273,14 @@ endif
include ${IMG_PARSER_LIB_MK}
endif
# RECLAIM_INIT_CODE can only be set when LOAD_IMAGE_V2=2 and xlat tables v2
# are used
ifeq (${RECLAIM_INIT_CODE}, 1)
ifeq (${LOAD_IMAGE_V2}, 0)
$(error "LOAD_IMAGE_V2 must be enabled to use RECLAIM_INIT_CODE")
endif
ifeq (${ARM_XLAT_TABLES_LIB_V1}, 1)
$(error "To reclaim init code xlat tables v2 must be used")
endif
endif
......@@ -19,7 +19,7 @@ static console_pl011_t arm_runtime_console;
#endif
/* Initialize the console to provide early debug support */
void arm_console_boot_init(void)
void __init arm_console_boot_init(void)
{
#if MULTI_CONSOLE_API
int rc = console_pl011_register(PLAT_ARM_BOOT_UART_BASE,
......
......@@ -68,7 +68,7 @@ static const gicv3_driver_data_t arm_gic_data __unused = {
.mpidr_to_core_pos = arm_gicv3_mpidr_hash
};
void plat_arm_gic_driver_init(void)
void __init plat_arm_gic_driver_init(void)
{
/*
* The GICv3 driver is initialized in EL3 and does not need
......@@ -85,7 +85,7 @@ void plat_arm_gic_driver_init(void)
/******************************************************************************
* ARM common helper to initialize the GIC. Only invoked by BL31
*****************************************************************************/
void plat_arm_gic_init(void)
void __init plat_arm_gic_init(void)
{
gicv3_distif_init();
gicv3_rdistif_init(plat_my_core_pos());
......
......@@ -208,7 +208,7 @@ void plat_arm_program_trusted_mailbox(uintptr_t address)
* The ARM Standard platform definition of platform porting API
* `plat_setup_psci_ops`.
******************************************************************************/
int plat_setup_psci_ops(uintptr_t sec_entrypoint,
int __init plat_setup_psci_ops(uintptr_t sec_entrypoint,
const plat_psci_ops_t **psci_ops)
{
*psci_ops = plat_arm_psci_override_pm_ops(&plat_arm_psci_pm_ops);
......
......@@ -81,7 +81,7 @@ void mhu_secure_message_end(unsigned int slot_id)
arm_lock_release();
}
void mhu_secure_init(void)
void __init mhu_secure_init(void)
{
arm_lock_init();
......@@ -93,7 +93,7 @@ void mhu_secure_init(void)
assert(mmio_read_32(PLAT_CSS_MHU_BASE + CPU_INTR_S_STAT) == 0);
}
void plat_arm_pwrc_setup(void)
void __init plat_arm_pwrc_setup(void)
{
mhu_secure_init();
}
......@@ -328,7 +328,7 @@ static int scmi_ap_core_init(scmi_channel_t *ch)
return 0;
}
void plat_arm_pwrc_setup(void)
void __init plat_arm_pwrc_setup(void)
{
channel.info = &plat_css_scmi_plat_info;
channel.lock = ARM_LOCK_GET_INSTANCE;
......
......@@ -17,7 +17,7 @@
/******************************************************************************
* Helper function to initialize ARM interconnect driver.
*****************************************************************************/
void plat_arm_interconnect_init(void)
void __init plat_arm_interconnect_init(void)
{
}
......
......@@ -4,6 +4,8 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <cdefs.h>
/*
* As the SGM platform supports FCM (with automatic interconnect
* enter/exit), we should not do anything in these interface functions.
......@@ -13,7 +15,7 @@
/******************************************************************************
* Helper function to initialize ARM interconnect driver.
*****************************************************************************/
void plat_arm_interconnect_init(void)
void __init plat_arm_interconnect_init(void)
{
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment