xref: /rk3399_ARM-atf/bl31/bl31_main.c (revision 9acaf99f427623304e6cdf7a0d0bca8803282da6)
14f6ad66aSAchin Gupta /*
2ec7c29abSBoyan Karatotev  * Copyright (c) 2013-2025, Arm Limited and Contributors. All rights reserved.
34f6ad66aSAchin Gupta  *
482cb2c1aSdp-arm  * SPDX-License-Identifier: BSD-3-Clause
54f6ad66aSAchin Gupta  */
64f6ad66aSAchin Gupta 
709d40e0eSAntonio Nino Diaz #include <assert.h>
809d40e0eSAntonio Nino Diaz #include <string.h>
909d40e0eSAntonio Nino Diaz 
1097043ac9SDan Handley #include <arch.h>
11ed108b56SAlexei Fedorov #include <arch_features.h>
124f6ad66aSAchin Gupta #include <arch_helpers.h>
1309d40e0eSAntonio Nino Diaz #include <bl31/bl31.h>
1409d40e0eSAntonio Nino Diaz #include <bl31/ehf.h>
1509d40e0eSAntonio Nino Diaz #include <common/bl_common.h>
16758ccb80SChris Kay #include <common/build_message.h>
1709d40e0eSAntonio Nino Diaz #include <common/debug.h>
186a0da736SJayanth Dodderi Chidanand #include <common/feat_detect.h>
1909d40e0eSAntonio Nino Diaz #include <common/runtime_svc.h>
20d52ff2b3SArvind Ram Prakash #include <drivers/arm/dsu.h>
215d893410SBoyan Karatotev #include <drivers/arm/gic.h>
2209d40e0eSAntonio Nino Diaz #include <drivers/console.h>
23ed8f06ddSthagon01-arm #include <lib/bootmarker_capture.h>
24bfef8b90SJuan Pablo Conde #include <lib/el3_runtime/context_debug.h>
2509d40e0eSAntonio Nino Diaz #include <lib/el3_runtime/context_mgmt.h>
26d158d425SBoyan Karatotev #include <lib/extensions/pauth.h>
27d158d425SBoyan Karatotev #include <lib/gpt_rme/gpt_rme.h>
2809d40e0eSAntonio Nino Diaz #include <lib/pmf/pmf.h>
2909d40e0eSAntonio Nino Diaz #include <lib/runtime_instr.h>
30d158d425SBoyan Karatotev #include <lib/xlat_tables/xlat_mmu_helpers.h>
3109d40e0eSAntonio Nino Diaz #include <plat/common/platform.h>
3209d40e0eSAntonio Nino Diaz #include <services/std_svc.h>
337aea9087SAchin Gupta 
34872be88aSdp-arm #if ENABLE_RUNTIME_INSTRUMENTATION
35872be88aSdp-arm 	PMF_REGISTER_SERVICE_SMC(rt_instr_svc, PMF_RT_INSTR_SVC_ID,
36872be88aSdp-arm 		RT_INSTR_TOTAL_IDS, PMF_STORE_ENABLE)
37872be88aSdp-arm #endif
38872be88aSdp-arm 
39ed8f06ddSthagon01-arm #if ENABLE_RUNTIME_INSTRUMENTATION
40ed8f06ddSthagon01-arm 	PMF_REGISTER_SERVICE(bl_svc, PMF_RT_INSTR_SVC_ID,
41ed8f06ddSthagon01-arm 		BL_TOTAL_IDS, PMF_DUMP_ENABLE)
42ed8f06ddSthagon01-arm #endif
43ed8f06ddSthagon01-arm 
447f366605SJeenu Viswambharan /*******************************************************************************
457f366605SJeenu Viswambharan  * This function pointer is used to initialise the BL32 image. It's initialized
467f366605SJeenu Viswambharan  * by SPD calling bl31_register_bl32_init after setting up all things necessary
477f366605SJeenu Viswambharan  * for SP execution. In cases where both SPD and SP are absent, or when SPD
487f366605SJeenu Viswambharan  * finds it impossible to execute SP, this pointer is left as NULL
497f366605SJeenu Viswambharan  ******************************************************************************/
506871c5d3SVikram Kanigiri static int32_t (*bl32_init)(void);
517f366605SJeenu Viswambharan 
525b18de09SZelalem Aweke /*****************************************************************************
535b18de09SZelalem Aweke  * Function used to initialise RMM if RME is enabled
545b18de09SZelalem Aweke  *****************************************************************************/
555b18de09SZelalem Aweke #if ENABLE_RME
565b18de09SZelalem Aweke static int32_t (*rmm_init)(void);
575b18de09SZelalem Aweke #endif
585b18de09SZelalem Aweke 
597aea9087SAchin Gupta /*******************************************************************************
6035ca3511SAchin Gupta  * Variable to indicate whether next image to execute after BL31 is BL33
6135ca3511SAchin Gupta  * (non-secure & default) or BL32 (secure).
6235ca3511SAchin Gupta  ******************************************************************************/
632fa4dee6SMaheedhar Bollapalli static uint32_t next_image_type = (uint32_t)NON_SECURE;
6435ca3511SAchin Gupta 
651994e562SJavier Almansa Sobrino #ifdef SUPPORT_UNKNOWN_MPID
661994e562SJavier Almansa Sobrino /*
671994e562SJavier Almansa Sobrino  * Flag to know whether an unsupported MPID has been detected. To avoid having it
681994e562SJavier Almansa Sobrino  * landing on the .bss section, it is initialized to a non-zero value, this way
691994e562SJavier Almansa Sobrino  * we avoid potential WAW hazards during system bring up.
701994e562SJavier Almansa Sobrino  * */
711994e562SJavier Almansa Sobrino volatile uint32_t unsupported_mpid_flag = 1;
721994e562SJavier Almansa Sobrino #endif
731994e562SJavier Almansa Sobrino 
7458e946aeSSoby Mathew /*
7558e946aeSSoby Mathew  * Implement the ARM Standard Service function to get arguments for a
7658e946aeSSoby Mathew  * particular service.
7758e946aeSSoby Mathew  */
get_arm_std_svc_args(unsigned int svc_mask)7858e946aeSSoby Mathew uintptr_t get_arm_std_svc_args(unsigned int svc_mask)
7958e946aeSSoby Mathew {
8058e946aeSSoby Mathew 	/* Setup the arguments for PSCI Library */
8158e946aeSSoby Mathew 	DEFINE_STATIC_PSCI_LIB_ARGS_V1(psci_args, bl31_warm_entrypoint);
8258e946aeSSoby Mathew 
8358e946aeSSoby Mathew 	/* PSCI is the only ARM Standard Service implemented */
8458e946aeSSoby Mathew 	assert(svc_mask == PSCI_FID_MASK);
8558e946aeSSoby Mathew 
8658e946aeSSoby Mathew 	return (uintptr_t)&psci_args;
8758e946aeSSoby Mathew }
8858e946aeSSoby Mathew 
8935ca3511SAchin Gupta /*******************************************************************************
907aea9087SAchin Gupta  * Simple function to initialise all BL31 helper libraries.
917aea9087SAchin Gupta  ******************************************************************************/
bl31_lib_init(void)92c42d0d87SArvind Ram Prakash static void __init bl31_lib_init(void)
937aea9087SAchin Gupta {
947aea9087SAchin Gupta 	cm_init();
957aea9087SAchin Gupta }
964f6ad66aSAchin Gupta 
974f6ad66aSAchin Gupta /*******************************************************************************
98d158d425SBoyan Karatotev  * BL31 is responsible for setting up the runtime services for the primary cpu
99d158d425SBoyan Karatotev  * before passing control to the bootloader or an Operating System. This
100d158d425SBoyan Karatotev  * function calls runtime_svc_init() which initializes all registered runtime
101d158d425SBoyan Karatotev  * services. The run time services would setup enough context for the core to
102d158d425SBoyan Karatotev  * switch to the next exception level. When this function returns, the core will
103d158d425SBoyan Karatotev  * switch to the programmed exception level via an ERET.
10488cfd9a6SAntonio Nino Diaz  ******************************************************************************/
bl31_main(u_register_t arg0,u_register_t arg1,u_register_t arg2,u_register_t arg3)105d158d425SBoyan Karatotev void __no_pauth bl31_main(u_register_t arg0, u_register_t arg1, u_register_t arg2,
10688cfd9a6SAntonio Nino Diaz 		u_register_t arg3)
10788cfd9a6SAntonio Nino Diaz {
108d158d425SBoyan Karatotev 	unsigned int core_pos = plat_my_core_pos();
1090f57a388SBoyan Karatotev 
110ae770fedSYann Gautier 	/* Enable early console if EARLY_CONSOLE flag is enabled */
111ae770fedSYann Gautier 	plat_setup_early_console();
112ae770fedSYann Gautier 
11388cfd9a6SAntonio Nino Diaz 	/* Perform early platform-specific setup */
11488cfd9a6SAntonio Nino Diaz 	bl31_early_platform_setup2(arg0, arg1, arg2, arg3);
11588cfd9a6SAntonio Nino Diaz 
11688cfd9a6SAntonio Nino Diaz 	/* Perform late platform-specific setup */
11788cfd9a6SAntonio Nino Diaz 	bl31_plat_arch_setup();
118ed108b56SAlexei Fedorov 
119d158d425SBoyan Karatotev #if FEATURE_DETECTION
120d158d425SBoyan Karatotev 	/* Detect if features enabled during compilation are supported by PE. */
121d158d425SBoyan Karatotev 	detect_arch_features(core_pos);
122d158d425SBoyan Karatotev #endif /* FEATURE_DETECTION */
123d158d425SBoyan Karatotev 
124bfef8b90SJuan Pablo Conde 	/* Prints context_memory allocated for all the security states */
125bfef8b90SJuan Pablo Conde 	report_ctx_memory_usage();
12688cfd9a6SAntonio Nino Diaz 
12763900851SBoyan Karatotev 	/* Init registers that never change for the lifetime of the core. */
128d335bbb1SBoyan Karatotev 	cm_manage_extensions_el3(core_pos);
12924a70738SBoyan Karatotev 
1306eafc060SBoyan Karatotev 	/* Init per-world context registers */
1316eafc060SBoyan Karatotev 	cm_manage_extensions_per_world();
132461c0a5dSElizabeth Ho 
133758ccb80SChris Kay 	NOTICE("BL31: %s\n", build_version_string);
134d178637dSJuan Castillo 	NOTICE("BL31: %s\n", build_message);
1356ad2e461SDan Handley 
136ed8f06ddSthagon01-arm #if ENABLE_RUNTIME_INSTRUMENTATION
137ed8f06ddSthagon01-arm 	PMF_CAPTURE_TIMESTAMP(bl_svc, BL31_ENTRY, PMF_CACHE_MAINT);
138ed8f06ddSthagon01-arm #endif
139ed8f06ddSthagon01-arm 
1401994e562SJavier Almansa Sobrino #ifdef SUPPORT_UNKNOWN_MPID
1411994e562SJavier Almansa Sobrino 	if (unsupported_mpid_flag == 0) {
1421994e562SJavier Almansa Sobrino 		NOTICE("Unsupported MPID detected!\n");
1431994e562SJavier Almansa Sobrino 	}
1441994e562SJavier Almansa Sobrino #endif
1451994e562SJavier Almansa Sobrino 
14678e61613SSoby Mathew 	/* Perform platform setup in BL31 */
1474f6ad66aSAchin Gupta 	bl31_platform_setup();
1484f6ad66aSAchin Gupta 
149d52ff2b3SArvind Ram Prakash #if USE_DSU_DRIVER
150d52ff2b3SArvind Ram Prakash 	dsu_driver_init(&plat_dsu_data);
151d52ff2b3SArvind Ram Prakash #endif
152d52ff2b3SArvind Ram Prakash 
1535d893410SBoyan Karatotev #if USE_GIC_DRIVER
1545d893410SBoyan Karatotev 	/*
1555d893410SBoyan Karatotev 	 * Initialize the GIC driver as well as per-cpu and global interfaces.
1565d893410SBoyan Karatotev 	 * Platform has had an opportunity to initialise specifics.
1575d893410SBoyan Karatotev 	 */
1585d893410SBoyan Karatotev 	gic_init(core_pos);
1595d893410SBoyan Karatotev 	gic_pcpu_init(core_pos);
1605d893410SBoyan Karatotev 	gic_cpuif_enable(core_pos);
1615d893410SBoyan Karatotev #endif /* USE_GIC_DRIVER */
1625d893410SBoyan Karatotev 
1637aea9087SAchin Gupta 	/* Initialise helper libraries */
1647aea9087SAchin Gupta 	bl31_lib_init();
1654f6ad66aSAchin Gupta 
16621b818c0SJeenu Viswambharan #if EL3_EXCEPTION_HANDLING
16721b818c0SJeenu Viswambharan 	INFO("BL31: Initialising Exception Handling Framework\n");
16821b818c0SJeenu Viswambharan 	ehf_init();
16921b818c0SJeenu Viswambharan #endif
17021b818c0SJeenu Viswambharan 
17158e946aeSSoby Mathew 	/* Initialize the runtime services e.g. psci. */
172d178637dSJuan Castillo 	INFO("BL31: Initializing runtime services\n");
1737421b465SAchin Gupta 	runtime_svc_init();
1744f6ad66aSAchin Gupta 
17535ca3511SAchin Gupta 	/*
1767f366605SJeenu Viswambharan 	 * All the cold boot actions on the primary cpu are done. We now need to
1775b18de09SZelalem Aweke 	 * decide which is the next image and how to execute it.
1787f366605SJeenu Viswambharan 	 * If the SPD runtime service is present, it would want to pass control
1797f366605SJeenu Viswambharan 	 * to BL32 first in S-EL1. In that case, SPD would have registered a
1808aabea33SPaul Beesley 	 * function to initialize bl32 where it takes responsibility of entering
1815b18de09SZelalem Aweke 	 * S-EL1 and returning control back to bl31_main. Similarly, if RME is
1825b18de09SZelalem Aweke 	 * enabled and a function is registered to initialize RMM, control is
1835b18de09SZelalem Aweke 	 * transferred to RMM in R-EL2. After RMM initialization, control is
1845b18de09SZelalem Aweke 	 * returned back to bl31_main. Once this is done we can prepare entry
1855b18de09SZelalem Aweke 	 * into BL33 as normal.
18635ca3511SAchin Gupta 	 */
18735ca3511SAchin Gupta 
1887f366605SJeenu Viswambharan 	/*
1898aabea33SPaul Beesley 	 * If SPD had registered an init hook, invoke it.
1907f366605SJeenu Viswambharan 	 */
191c9512bcaSAntonio Nino Diaz 	if (bl32_init != NULL) {
192d178637dSJuan Castillo 		INFO("BL31: Initializing BL32\n");
193c9512bcaSAntonio Nino Diaz 
194889e3d1cSPrasad Kummari 		console_flush();
195c9512bcaSAntonio Nino Diaz 		int32_t rc = (*bl32_init)();
196c9512bcaSAntonio Nino Diaz 
1975b18de09SZelalem Aweke 		if (rc == 0) {
19874ad948fSAntonio Nino Diaz 			WARN("BL31: BL32 initialization failed\n");
1996ad2e461SDan Handley 		}
2005b18de09SZelalem Aweke 	}
2015b18de09SZelalem Aweke 
2025b18de09SZelalem Aweke 	/*
2035b18de09SZelalem Aweke 	 * If RME is enabled and init hook is registered, initialize RMM
2045b18de09SZelalem Aweke 	 * in R-EL2.
2055b18de09SZelalem Aweke 	 */
2065b18de09SZelalem Aweke #if ENABLE_RME
2075b18de09SZelalem Aweke 	if (rmm_init != NULL) {
2085b18de09SZelalem Aweke 		INFO("BL31: Initializing RMM\n");
2095b18de09SZelalem Aweke 
210889e3d1cSPrasad Kummari 		console_flush();
2115b18de09SZelalem Aweke 		int32_t rc = (*rmm_init)();
2125b18de09SZelalem Aweke 
2135b18de09SZelalem Aweke 		if (rc == 0) {
2145b18de09SZelalem Aweke 			WARN("BL31: RMM initialization failed\n");
2155b18de09SZelalem Aweke 		}
2165b18de09SZelalem Aweke 	}
2175b18de09SZelalem Aweke #endif
2185b18de09SZelalem Aweke 
21935ca3511SAchin Gupta 	/*
22035ca3511SAchin Gupta 	 * We are ready to enter the next EL. Prepare entry into the image
22135ca3511SAchin Gupta 	 * corresponding to the desired security state after the next ERET.
22235ca3511SAchin Gupta 	 */
22335ca3511SAchin Gupta 	bl31_prepare_next_image_entry();
22478e61613SSoby Mathew 
22578e61613SSoby Mathew 	/*
22678e61613SSoby Mathew 	 * Perform any platform specific runtime setup prior to cold boot exit
22778e61613SSoby Mathew 	 * from BL31
22878e61613SSoby Mathew 	 */
22978e61613SSoby Mathew 	bl31_plat_runtime_setup();
230ed8f06ddSthagon01-arm 
231ed8f06ddSthagon01-arm #if ENABLE_RUNTIME_INSTRUMENTATION
232ed8f06ddSthagon01-arm 	console_flush();
233af3e8e63SSalman Nabi 	PMF_CAPTURE_TIMESTAMP(bl_svc, BL31_EXIT, PMF_CACHE_MAINT);
234ed8f06ddSthagon01-arm #endif
235af3e8e63SSalman Nabi 
236af3e8e63SSalman Nabi 	console_flush();
237af3e8e63SSalman Nabi 	console_switch_state(CONSOLE_FLAG_RUNTIME);
23835ca3511SAchin Gupta }
23935ca3511SAchin Gupta 
bl31_warmboot(void)240d158d425SBoyan Karatotev void __no_pauth bl31_warmboot(void)
241d158d425SBoyan Karatotev {
24263900851SBoyan Karatotev 	unsigned int core_pos = plat_my_core_pos();
24363900851SBoyan Karatotev 
24463900851SBoyan Karatotev #if FEATURE_DETECTION
24563900851SBoyan Karatotev 	/* Detect if features enabled during compilation are supported by PE. */
24663900851SBoyan Karatotev 	detect_arch_features(core_pos);
24763900851SBoyan Karatotev #endif /* FEATURE_DETECTION */
24863900851SBoyan Karatotev 
249d158d425SBoyan Karatotev 	/*
250d158d425SBoyan Karatotev 	 * We're about to enable MMU and participate in PSCI state coordination.
251d158d425SBoyan Karatotev 	 *
252d158d425SBoyan Karatotev 	 * The PSCI implementation invokes platform routines that enable CPUs to
253d158d425SBoyan Karatotev 	 * participate in coherency. On a system where CPUs are not
254d158d425SBoyan Karatotev 	 * cache-coherent without appropriate platform specific programming,
255d158d425SBoyan Karatotev 	 * having caches enabled until such time might lead to coherency issues
256d158d425SBoyan Karatotev 	 * (resulting from stale data getting speculatively fetched, among
257d158d425SBoyan Karatotev 	 * others). Therefore we keep data caches disabled even after enabling
258d158d425SBoyan Karatotev 	 * the MMU for such platforms.
259d158d425SBoyan Karatotev 	 *
260d158d425SBoyan Karatotev 	 * On systems with hardware-assisted coherency, or on single cluster
261d158d425SBoyan Karatotev 	 * platforms, such platform specific programming is not required to
262d158d425SBoyan Karatotev 	 * enter coherency (as CPUs already are); and there's no reason to have
263d158d425SBoyan Karatotev 	 * caches disabled either.
264d158d425SBoyan Karatotev 	 */
265d158d425SBoyan Karatotev #if HW_ASSISTED_COHERENCY || WARMBOOT_ENABLE_DCACHE_EARLY
266d158d425SBoyan Karatotev 	bl31_plat_enable_mmu(0);
267d158d425SBoyan Karatotev #else
268d158d425SBoyan Karatotev 	bl31_plat_enable_mmu(DISABLE_DCACHE);
269d158d425SBoyan Karatotev #endif
270d158d425SBoyan Karatotev 
27163900851SBoyan Karatotev 	/* Init registers that never change for the lifetime of the core. */
27263900851SBoyan Karatotev 	cm_manage_extensions_el3(core_pos);
27363900851SBoyan Karatotev 
274d158d425SBoyan Karatotev #if ENABLE_RME
275d158d425SBoyan Karatotev 	/*
276d158d425SBoyan Karatotev 	 * At warm boot GPT data structures have already been initialized in RAM
277d158d425SBoyan Karatotev 	 * but the sysregs for this CPU need to be initialized. Note that the GPT
278d158d425SBoyan Karatotev 	 * accesses are controlled attributes in GPCCR and do not depend on the
279d158d425SBoyan Karatotev 	 * SCR_EL3.C bit.
280d158d425SBoyan Karatotev 	 */
281d158d425SBoyan Karatotev 	if (gpt_enable() != 0) {
282d158d425SBoyan Karatotev 		panic();
283d158d425SBoyan Karatotev 	}
284d158d425SBoyan Karatotev #endif
285d158d425SBoyan Karatotev 
286*98863b1eSAhmed Azeem /* Enable DSU driver for each booting core */
287*98863b1eSAhmed Azeem #if USE_DSU_DRIVER
288*98863b1eSAhmed Azeem 	dsu_driver_init(&plat_dsu_data);
289*98863b1eSAhmed Azeem #endif
290*98863b1eSAhmed Azeem 
29163900851SBoyan Karatotev 	psci_warmboot_entrypoint(core_pos);
292d158d425SBoyan Karatotev }
293d158d425SBoyan Karatotev 
29435ca3511SAchin Gupta /*******************************************************************************
29535ca3511SAchin Gupta  * Accessor functions to help runtime services decide which image should be
29635ca3511SAchin Gupta  * executed after BL31. This is BL33 or the non-secure bootloader image by
29735ca3511SAchin Gupta  * default but the Secure payload dispatcher could override this by requesting
29835ca3511SAchin Gupta  * an entry into BL32 (Secure payload) first. If it does so then it should use
29935ca3511SAchin Gupta  * the same API to program an entry into BL33 once BL32 initialisation is
30035ca3511SAchin Gupta  * complete.
30135ca3511SAchin Gupta  ******************************************************************************/
bl31_set_next_image_type(uint32_t security_state)30235ca3511SAchin Gupta void bl31_set_next_image_type(uint32_t security_state)
30335ca3511SAchin Gupta {
304d3280bebSJuan Castillo 	assert(sec_state_is_valid(security_state));
30535ca3511SAchin Gupta 	next_image_type = security_state;
30635ca3511SAchin Gupta }
30735ca3511SAchin Gupta 
bl31_get_next_image_type(void)308d9712f9cSSigned-off-by: Maheedhar Bollapalli static uint32_t bl31_get_next_image_type(void)
30935ca3511SAchin Gupta {
31035ca3511SAchin Gupta 	return next_image_type;
31135ca3511SAchin Gupta }
31235ca3511SAchin Gupta 
31335ca3511SAchin Gupta /*******************************************************************************
31435ca3511SAchin Gupta  * This function programs EL3 registers and performs other setup to enable entry
31535ca3511SAchin Gupta  * into the next image after BL31 at the next ERET.
31635ca3511SAchin Gupta  ******************************************************************************/
bl31_prepare_next_image_entry(void)31787c85134SDaniel Boulby void __init bl31_prepare_next_image_entry(void)
31835ca3511SAchin Gupta {
319e358089dSNithin G 	const entry_point_info_t *next_image_info;
320167a9357SAndrew Thoelke 	uint32_t image_type;
32135ca3511SAchin Gupta 
3228cd16e6bSSoby Mathew #if CTX_INCLUDE_AARCH32_REGS
3238cd16e6bSSoby Mathew 	/*
3248cd16e6bSSoby Mathew 	 * Ensure that the build flag to save AArch32 system registers in CPU
3258cd16e6bSSoby Mathew 	 * context is not set for AArch64-only platforms.
3268cd16e6bSSoby Mathew 	 */
327a0fee747SAntonio Nino Diaz 	if (el_implemented(1) == EL_IMPL_A64ONLY) {
3288cd16e6bSSoby Mathew 		ERROR("EL1 supports AArch64-only. Please set build flag "
329a0fee747SAntonio Nino Diaz 				"CTX_INCLUDE_AARCH32_REGS = 0\n");
3308cd16e6bSSoby Mathew 		panic();
3318cd16e6bSSoby Mathew 	}
3328cd16e6bSSoby Mathew #endif
3338cd16e6bSSoby Mathew 
33435ca3511SAchin Gupta 	/* Determine which image to execute next */
33535ca3511SAchin Gupta 	image_type = bl31_get_next_image_type();
33635ca3511SAchin Gupta 
337caa84939SJeenu Viswambharan 	/* Program EL3 registers to enable entry into the next EL */
3389865ac15SDan Handley 	next_image_info = bl31_plat_get_next_image_ep_info(image_type);
339c9512bcaSAntonio Nino Diaz 	assert(next_image_info != NULL);
340f05cb4a7SVikram Kanigiri 	assert(image_type == GET_SECURITY_STATE(next_image_info->h.attr));
34135ca3511SAchin Gupta 
342d178637dSJuan Castillo 	INFO("BL31: Preparing for EL3 exit to %s world\n",
3436ad2e461SDan Handley 		(image_type == SECURE) ? "secure" : "normal");
34468a68c92SSandrine Bailleux 	print_entry_point_info(next_image_info);
34585a181ceSSoby Mathew 	cm_init_my_context(next_image_info);
3468b95e848SZelalem Aweke 
3478b95e848SZelalem Aweke 	/*
3488b95e848SZelalem Aweke 	* If we are entering the Non-secure world, use
3498b95e848SZelalem Aweke 	* 'cm_prepare_el3_exit_ns' to exit.
3508b95e848SZelalem Aweke 	*/
3518b95e848SZelalem Aweke 	if (image_type == NON_SECURE) {
3528b95e848SZelalem Aweke 		cm_prepare_el3_exit_ns();
3538b95e848SZelalem Aweke 	} else {
354167a9357SAndrew Thoelke 		cm_prepare_el3_exit(image_type);
3554f6ad66aSAchin Gupta 	}
3568b95e848SZelalem Aweke }
3577f366605SJeenu Viswambharan 
3587f366605SJeenu Viswambharan /*******************************************************************************
3597f366605SJeenu Viswambharan  * This function initializes the pointer to BL32 init function. This is expected
3607f366605SJeenu Viswambharan  * to be called by the SPD after it finishes all its initialization
3617f366605SJeenu Viswambharan  ******************************************************************************/
bl31_register_bl32_init(int32_t (* func)(void))3626871c5d3SVikram Kanigiri void bl31_register_bl32_init(int32_t (*func)(void))
3637f366605SJeenu Viswambharan {
3647f366605SJeenu Viswambharan 	bl32_init = func;
3657f366605SJeenu Viswambharan }
3665b18de09SZelalem Aweke 
3675b18de09SZelalem Aweke #if ENABLE_RME
3685b18de09SZelalem Aweke /*******************************************************************************
3695b18de09SZelalem Aweke  * This function initializes the pointer to RMM init function. This is expected
3705b18de09SZelalem Aweke  * to be called by the RMMD after it finishes all its initialization
3715b18de09SZelalem Aweke  ******************************************************************************/
bl31_register_rmm_init(int32_t (* func)(void))3725b18de09SZelalem Aweke void bl31_register_rmm_init(int32_t (*func)(void))
3735b18de09SZelalem Aweke {
3745b18de09SZelalem Aweke 	rmm_init = func;
3755b18de09SZelalem Aweke }
3765b18de09SZelalem Aweke #endif
377