xref: /rk3399_ARM-atf/lib/el3_runtime/aarch32/context_mgmt.c (revision a6b3643c2a1a95146e93c8b6f07c2e491a1230d6)
1e33b78a6SSoby Mathew /*
2*a6b3643cSChris Kay  * Copyright (c) 2016-2024, Arm Limited and Contributors. All rights reserved.
3e33b78a6SSoby Mathew  *
482cb2c1aSdp-arm  * SPDX-License-Identifier: BSD-3-Clause
5e33b78a6SSoby Mathew  */
6e33b78a6SSoby Mathew 
7e33b78a6SSoby Mathew #include <assert.h>
840daecc1SAntonio Nino Diaz #include <stdbool.h>
9e33b78a6SSoby Mathew #include <string.h>
1009d40e0eSAntonio Nino Diaz 
1109d40e0eSAntonio Nino Diaz #include <platform_def.h>
1209d40e0eSAntonio Nino Diaz 
1309d40e0eSAntonio Nino Diaz #include <arch.h>
14fc8d2d39SAndre Przywara #include <arch_features.h>
1509d40e0eSAntonio Nino Diaz #include <arch_helpers.h>
1609d40e0eSAntonio Nino Diaz #include <common/bl_common.h>
1709d40e0eSAntonio Nino Diaz #include <context.h>
1809d40e0eSAntonio Nino Diaz #include <lib/el3_runtime/context_mgmt.h>
1909d40e0eSAntonio Nino Diaz #include <lib/extensions/amu.h>
20c73686a1SBoyan Karatotev #include <lib/extensions/pmuv3.h>
21d4582d30SManish V Badarkhe #include <lib/extensions/sys_reg_trace.h>
228fcd3d96SManish V Badarkhe #include <lib/extensions/trf.h>
2309d40e0eSAntonio Nino Diaz #include <lib/utils.h>
24e33b78a6SSoby Mathew 
25e33b78a6SSoby Mathew /*******************************************************************************
26e33b78a6SSoby Mathew  * Context management library initialisation routine. This library is used by
27e33b78a6SSoby Mathew  * runtime services to share pointers to 'cpu_context' structures for the secure
28e33b78a6SSoby Mathew  * and non-secure states. Management of the structures and their associated
29e33b78a6SSoby Mathew  * memory is not done by the context management library e.g. the PSCI service
30e33b78a6SSoby Mathew  * manages the cpu context used for entry from and exit to the non-secure state.
31e33b78a6SSoby Mathew  * The Secure payload manages the context(s) corresponding to the secure state.
32e33b78a6SSoby Mathew  * It also uses this library to get access to the non-secure
33e33b78a6SSoby Mathew  * state cpu context pointers.
34e33b78a6SSoby Mathew  ******************************************************************************/
35e33b78a6SSoby Mathew void cm_init(void)
36e33b78a6SSoby Mathew {
37e33b78a6SSoby Mathew 	/*
38e33b78a6SSoby Mathew 	 * The context management library has only global data to initialize, but
39e33b78a6SSoby Mathew 	 * that will be done when the BSS is zeroed out
40e33b78a6SSoby Mathew 	 */
41e33b78a6SSoby Mathew }
42e33b78a6SSoby Mathew 
43e33b78a6SSoby Mathew /*******************************************************************************
44e33b78a6SSoby Mathew  * The following function initializes the cpu_context 'ctx' for
45e33b78a6SSoby Mathew  * first use, and sets the initial entrypoint state as specified by the
46e33b78a6SSoby Mathew  * entry_point_info structure.
47e33b78a6SSoby Mathew  *
48e33b78a6SSoby Mathew  * The security state to initialize is determined by the SECURE attribute
491634cae8SAntonio Nino Diaz  * of the entry_point_info.
50e33b78a6SSoby Mathew  *
51e33b78a6SSoby Mathew  * The EE and ST attributes are used to configure the endianness and secure
52e33b78a6SSoby Mathew  * timer availability for the new execution context.
53e33b78a6SSoby Mathew  *
54e33b78a6SSoby Mathew  * To prepare the register state for entry call cm_prepare_el3_exit() and
55e33b78a6SSoby Mathew  * el3_exit(). For Secure-EL1 cm_prepare_el3_exit() is equivalent to
562e61d687SOlivier Deprez  * cm_el1_sysregs_context_restore().
57e33b78a6SSoby Mathew  ******************************************************************************/
581634cae8SAntonio Nino Diaz void cm_setup_context(cpu_context_t *ctx, const entry_point_info_t *ep)
59e33b78a6SSoby Mathew {
60e33b78a6SSoby Mathew 	unsigned int security_state;
61e33b78a6SSoby Mathew 	uint32_t scr, sctlr;
62e33b78a6SSoby Mathew 	regs_t *reg_ctx;
63e33b78a6SSoby Mathew 
64a0fee747SAntonio Nino Diaz 	assert(ctx != NULL);
65e33b78a6SSoby Mathew 
66e33b78a6SSoby Mathew 	security_state = GET_SECURITY_STATE(ep->h.attr);
67e33b78a6SSoby Mathew 
68e33b78a6SSoby Mathew 	/* Clear any residual register values from the context */
6932f0d3c6SDouglas Raillard 	zeromem(ctx, sizeof(*ctx));
70e33b78a6SSoby Mathew 
719e3b4cbbSSoby Mathew 	reg_ctx = get_regs_ctx(ctx);
729e3b4cbbSSoby Mathew 
73e33b78a6SSoby Mathew 	/*
74e33b78a6SSoby Mathew 	 * Base the context SCR on the current value, adjust for entry point
75e33b78a6SSoby Mathew 	 * specific requirements
76e33b78a6SSoby Mathew 	 */
77e33b78a6SSoby Mathew 	scr = read_scr();
78e33b78a6SSoby Mathew 	scr &= ~(SCR_NS_BIT | SCR_HCE_BIT);
79e33b78a6SSoby Mathew 
80e33b78a6SSoby Mathew 	if (security_state != SECURE)
81e33b78a6SSoby Mathew 		scr |= SCR_NS_BIT;
82e33b78a6SSoby Mathew 
83e33b78a6SSoby Mathew 	if (security_state != SECURE) {
84b7b0787dSSoby Mathew 		/*
8518f2efd6SDavid Cunado 		 * Set up SCTLR for the Non-secure context.
8618f2efd6SDavid Cunado 		 *
8718f2efd6SDavid Cunado 		 * SCTLR.EE: Endianness is taken from the entrypoint attributes.
8818f2efd6SDavid Cunado 		 *
8918f2efd6SDavid Cunado 		 * SCTLR.M, SCTLR.C and SCTLR.I: These fields must be zero (as
9018f2efd6SDavid Cunado 		 *  required by PSCI specification)
9118f2efd6SDavid Cunado 		 *
9218f2efd6SDavid Cunado 		 * Set remaining SCTLR fields to their architecturally defined
9318f2efd6SDavid Cunado 		 * values. Some fields reset to an IMPLEMENTATION DEFINED value:
9418f2efd6SDavid Cunado 		 *
9518f2efd6SDavid Cunado 		 * SCTLR.TE: Set to zero so that exceptions to an Exception
9618f2efd6SDavid Cunado 		 *  Level executing at PL1 are taken to A32 state.
9718f2efd6SDavid Cunado 		 *
9818f2efd6SDavid Cunado 		 * SCTLR.V: Set to zero to select the normal exception vectors
9918f2efd6SDavid Cunado 		 *  with base address held in VBAR.
100b7b0787dSSoby Mathew 		 */
10118f2efd6SDavid Cunado 		assert(((ep->spsr >> SPSR_E_SHIFT) & SPSR_E_MASK) ==
10218f2efd6SDavid Cunado 			(EP_GET_EE(ep->h.attr) >> EP_EE_SHIFT));
10318f2efd6SDavid Cunado 
104a0fee747SAntonio Nino Diaz 		sctlr = (EP_GET_EE(ep->h.attr) != 0U) ? SCTLR_EE_BIT : 0U;
10518f2efd6SDavid Cunado 		sctlr |= (SCTLR_RESET_VAL & ~(SCTLR_TE_BIT | SCTLR_V_BIT));
106e33b78a6SSoby Mathew 		write_ctx_reg(reg_ctx, CTX_NS_SCTLR, sctlr);
107e33b78a6SSoby Mathew 	}
108e33b78a6SSoby Mathew 
10918f2efd6SDavid Cunado 	/*
11018f2efd6SDavid Cunado 	 * The target exception level is based on the spsr mode requested. If
11118f2efd6SDavid Cunado 	 * execution is requested to hyp mode, HVC is enabled via SCR.HCE.
11218f2efd6SDavid Cunado 	 */
113e33b78a6SSoby Mathew 	if (GET_M32(ep->spsr) == MODE32_hyp)
114e33b78a6SSoby Mathew 		scr |= SCR_HCE_BIT;
115e33b78a6SSoby Mathew 
11618f2efd6SDavid Cunado 	/*
11718f2efd6SDavid Cunado 	 * Store the initialised values for SCTLR and SCR in the cpu_context.
11818f2efd6SDavid Cunado 	 * The Hyp mode registers are not part of the saved context and are
11918f2efd6SDavid Cunado 	 * set-up in cm_prepare_el3_exit().
12018f2efd6SDavid Cunado 	 */
121e33b78a6SSoby Mathew 	write_ctx_reg(reg_ctx, CTX_SCR, scr);
122e33b78a6SSoby Mathew 	write_ctx_reg(reg_ctx, CTX_LR, ep->pc);
123e33b78a6SSoby Mathew 	write_ctx_reg(reg_ctx, CTX_SPSR, ep->spsr);
124e33b78a6SSoby Mathew 
125e33b78a6SSoby Mathew 	/*
126e33b78a6SSoby Mathew 	 * Store the r0-r3 value from the entrypoint into the context
127e33b78a6SSoby Mathew 	 * Use memcpy as we are in control of the layout of the structures
128e33b78a6SSoby Mathew 	 */
129e33b78a6SSoby Mathew 	memcpy((void *)reg_ctx, (void *)&ep->args, sizeof(aapcs32_params_t));
130e33b78a6SSoby Mathew }
131e33b78a6SSoby Mathew 
132e33b78a6SSoby Mathew /*******************************************************************************
1330fd0f222SDimitris Papastamos  * Enable architecture extensions on first entry to Non-secure world.
1340fd0f222SDimitris Papastamos  * When EL2 is implemented but unused `el2_unused` is non-zero, otherwise
1350fd0f222SDimitris Papastamos  * it is zero.
1360fd0f222SDimitris Papastamos  ******************************************************************************/
13740daecc1SAntonio Nino Diaz static void enable_extensions_nonsecure(bool el2_unused)
1380fd0f222SDimitris Papastamos {
1390fd0f222SDimitris Papastamos #if IMAGE_BL32
140b57e16a4SAndre Przywara 	if (is_feat_amu_supported()) {
141ef69e1eaSDimitris Papastamos 		amu_enable(el2_unused);
142b57e16a4SAndre Przywara 	}
143d4582d30SManish V Badarkhe 
144603a0c6fSAndre Przywara 	if (is_feat_sys_reg_trace_supported()) {
14560d330dcSBoyan Karatotev 		sys_reg_trace_init_el3();
146603a0c6fSAndre Przywara 	}
1478fcd3d96SManish V Badarkhe 
148fc8d2d39SAndre Przywara 	if (is_feat_trf_supported()) {
14960d330dcSBoyan Karatotev 		trf_init_el3();
150fc8d2d39SAndre Przywara 	}
151c73686a1SBoyan Karatotev 
152c73686a1SBoyan Karatotev 	/*
153c73686a1SBoyan Karatotev 	 * Also applies to PMU < v3. The PMU is only disabled for EL3 and Secure
154c73686a1SBoyan Karatotev 	 * state execution. This does not affect lower NS ELs.
155c73686a1SBoyan Karatotev 	 */
15660d330dcSBoyan Karatotev 	pmuv3_init_el3();
15760d330dcSBoyan Karatotev #endif /*  IMAGE_BL32 */
1580fd0f222SDimitris Papastamos }
1590fd0f222SDimitris Papastamos 
160*a6b3643cSChris Kay #if !IMAGE_BL1
1610fd0f222SDimitris Papastamos /*******************************************************************************
162e33b78a6SSoby Mathew  * The following function initializes the cpu_context for a CPU specified by
163e33b78a6SSoby Mathew  * its `cpu_idx` for first use, and sets the initial entrypoint state as
164e33b78a6SSoby Mathew  * specified by the entry_point_info structure.
165e33b78a6SSoby Mathew  ******************************************************************************/
166e33b78a6SSoby Mathew void cm_init_context_by_index(unsigned int cpu_idx,
167e33b78a6SSoby Mathew 			      const entry_point_info_t *ep)
168e33b78a6SSoby Mathew {
169e33b78a6SSoby Mathew 	cpu_context_t *ctx;
170e33b78a6SSoby Mathew 	ctx = cm_get_context_by_index(cpu_idx, GET_SECURITY_STATE(ep->h.attr));
1711634cae8SAntonio Nino Diaz 	cm_setup_context(ctx, ep);
172e33b78a6SSoby Mathew }
173*a6b3643cSChris Kay #endif /* !IMAGE_BL1 */
174e33b78a6SSoby Mathew 
175e33b78a6SSoby Mathew /*******************************************************************************
176e33b78a6SSoby Mathew  * The following function initializes the cpu_context for the current CPU
177e33b78a6SSoby Mathew  * for first use, and sets the initial entrypoint state as specified by the
178e33b78a6SSoby Mathew  * entry_point_info structure.
179e33b78a6SSoby Mathew  ******************************************************************************/
180e33b78a6SSoby Mathew void cm_init_my_context(const entry_point_info_t *ep)
181e33b78a6SSoby Mathew {
182e33b78a6SSoby Mathew 	cpu_context_t *ctx;
183e33b78a6SSoby Mathew 	ctx = cm_get_context(GET_SECURITY_STATE(ep->h.attr));
1841634cae8SAntonio Nino Diaz 	cm_setup_context(ctx, ep);
185e33b78a6SSoby Mathew }
186e33b78a6SSoby Mathew 
187e33b78a6SSoby Mathew /*******************************************************************************
188e33b78a6SSoby Mathew  * Prepare the CPU system registers for first entry into secure or normal world
189e33b78a6SSoby Mathew  *
190e33b78a6SSoby Mathew  * If execution is requested to hyp mode, HSCTLR is initialized
191e33b78a6SSoby Mathew  * If execution is requested to non-secure PL1, and the CPU supports
192e33b78a6SSoby Mathew  * HYP mode then HYP mode is disabled by configuring all necessary HYP mode
193e33b78a6SSoby Mathew  * registers.
194e33b78a6SSoby Mathew  ******************************************************************************/
195e33b78a6SSoby Mathew void cm_prepare_el3_exit(uint32_t security_state)
196e33b78a6SSoby Mathew {
19718f2efd6SDavid Cunado 	uint32_t hsctlr, scr;
198e33b78a6SSoby Mathew 	cpu_context_t *ctx = cm_get_context(security_state);
19940daecc1SAntonio Nino Diaz 	bool el2_unused = false;
200e33b78a6SSoby Mathew 
201a0fee747SAntonio Nino Diaz 	assert(ctx != NULL);
202e33b78a6SSoby Mathew 
203e33b78a6SSoby Mathew 	if (security_state == NON_SECURE) {
204e33b78a6SSoby Mathew 		scr = read_ctx_reg(get_regs_ctx(ctx), CTX_SCR);
205a0fee747SAntonio Nino Diaz 		if ((scr & SCR_HCE_BIT) != 0U) {
206e33b78a6SSoby Mathew 			/* Use SCTLR value to initialize HSCTLR */
20718f2efd6SDavid Cunado 			hsctlr = read_ctx_reg(get_regs_ctx(ctx),
208e33b78a6SSoby Mathew 						 CTX_NS_SCTLR);
20918f2efd6SDavid Cunado 			hsctlr |= HSCTLR_RES1;
210e33b78a6SSoby Mathew 			/* Temporarily set the NS bit to access HSCTLR */
211e33b78a6SSoby Mathew 			write_scr(read_scr() | SCR_NS_BIT);
212e33b78a6SSoby Mathew 			/*
213e33b78a6SSoby Mathew 			 * Make sure the write to SCR is complete so that
214e33b78a6SSoby Mathew 			 * we can access HSCTLR
215e33b78a6SSoby Mathew 			 */
216e33b78a6SSoby Mathew 			isb();
21718f2efd6SDavid Cunado 			write_hsctlr(hsctlr);
218e33b78a6SSoby Mathew 			isb();
219e33b78a6SSoby Mathew 
220e33b78a6SSoby Mathew 			write_scr(read_scr() & ~SCR_NS_BIT);
221e33b78a6SSoby Mathew 			isb();
222a0fee747SAntonio Nino Diaz 		} else if ((read_id_pfr1() &
223a0fee747SAntonio Nino Diaz 			(ID_PFR1_VIRTEXT_MASK << ID_PFR1_VIRTEXT_SHIFT)) != 0U) {
22440daecc1SAntonio Nino Diaz 			el2_unused = true;
2250fd0f222SDimitris Papastamos 
226495f3d3cSDavid Cunado 			/*
227495f3d3cSDavid Cunado 			 * Set the NS bit to access NS copies of certain banked
228495f3d3cSDavid Cunado 			 * registers
229495f3d3cSDavid Cunado 			 */
230e33b78a6SSoby Mathew 			write_scr(read_scr() | SCR_NS_BIT);
231e33b78a6SSoby Mathew 			isb();
232e33b78a6SSoby Mathew 
23318f2efd6SDavid Cunado 			/*
23418f2efd6SDavid Cunado 			 * Hyp / PL2 present but unused, need to disable safely.
23518f2efd6SDavid Cunado 			 * HSCTLR can be ignored in this case.
23618f2efd6SDavid Cunado 			 *
23718f2efd6SDavid Cunado 			 * Set HCR to its architectural reset value so that
23818f2efd6SDavid Cunado 			 * Non-secure operations do not trap to Hyp mode.
23918f2efd6SDavid Cunado 			 */
24018f2efd6SDavid Cunado 			write_hcr(HCR_RESET_VAL);
241e33b78a6SSoby Mathew 
24218f2efd6SDavid Cunado 			/*
24318f2efd6SDavid Cunado 			 * Set HCPTR to its architectural reset value so that
24418f2efd6SDavid Cunado 			 * Non-secure access from EL1 or EL0 to trace and to
24518f2efd6SDavid Cunado 			 * Advanced SIMD and floating point functionality does
24618f2efd6SDavid Cunado 			 * not trap to Hyp mode.
24718f2efd6SDavid Cunado 			 */
24818f2efd6SDavid Cunado 			write_hcptr(HCPTR_RESET_VAL);
249e33b78a6SSoby Mathew 
25018f2efd6SDavid Cunado 			/*
25118f2efd6SDavid Cunado 			 * Initialise CNTHCTL. All fields are architecturally
25218f2efd6SDavid Cunado 			 * UNKNOWN on reset and are set to zero except for
25318f2efd6SDavid Cunado 			 * field(s) listed below.
25418f2efd6SDavid Cunado 			 *
25518f2efd6SDavid Cunado 			 * CNTHCTL.PL1PCEN: Disable traps to Hyp mode of
25618f2efd6SDavid Cunado 			 *  Non-secure EL0 and EL1 accessed to the physical
25718f2efd6SDavid Cunado 			 *  timer registers.
25818f2efd6SDavid Cunado 			 *
25918f2efd6SDavid Cunado 			 * CNTHCTL.PL1PCTEN: Disable traps to Hyp mode of
26018f2efd6SDavid Cunado 			 *  Non-secure EL0 and EL1 accessed to the physical
26118f2efd6SDavid Cunado 			 *  counter registers.
26218f2efd6SDavid Cunado 			 */
26318f2efd6SDavid Cunado 			write_cnthctl(CNTHCTL_RESET_VAL |
26418f2efd6SDavid Cunado 					PL1PCEN_BIT | PL1PCTEN_BIT);
265e33b78a6SSoby Mathew 
26618f2efd6SDavid Cunado 			/*
26718f2efd6SDavid Cunado 			 * Initialise CNTVOFF to zero as it resets to an
26818f2efd6SDavid Cunado 			 * IMPLEMENTATION DEFINED value.
26918f2efd6SDavid Cunado 			 */
270e33b78a6SSoby Mathew 			write64_cntvoff(0);
271e33b78a6SSoby Mathew 
27218f2efd6SDavid Cunado 			/*
27318f2efd6SDavid Cunado 			 * Set VPIDR and VMPIDR to match MIDR_EL1 and MPIDR
27418f2efd6SDavid Cunado 			 * respectively.
27518f2efd6SDavid Cunado 			 */
276e33b78a6SSoby Mathew 			write_vpidr(read_midr());
277e33b78a6SSoby Mathew 			write_vmpidr(read_mpidr());
278e33b78a6SSoby Mathew 
279e33b78a6SSoby Mathew 			/*
28018f2efd6SDavid Cunado 			 * Initialise VTTBR, setting all fields rather than
28118f2efd6SDavid Cunado 			 * relying on the hw. Some fields are architecturally
28218f2efd6SDavid Cunado 			 * UNKNOWN at reset.
28318f2efd6SDavid Cunado 			 *
28418f2efd6SDavid Cunado 			 * VTTBR.VMID: Set to zero which is the architecturally
28518f2efd6SDavid Cunado 			 *  defined reset value. Even though EL1&0 stage 2
28618f2efd6SDavid Cunado 			 *  address translation is disabled, cache maintenance
28718f2efd6SDavid Cunado 			 *  operations depend on the VMID.
28818f2efd6SDavid Cunado 			 *
28918f2efd6SDavid Cunado 			 * VTTBR.BADDR: Set to zero as EL1&0 stage 2 address
29018f2efd6SDavid Cunado 			 *  translation is disabled.
291e33b78a6SSoby Mathew 			 */
29218f2efd6SDavid Cunado 			write64_vttbr(VTTBR_RESET_VAL &
29318f2efd6SDavid Cunado 				~((VTTBR_VMID_MASK << VTTBR_VMID_SHIFT)
29418f2efd6SDavid Cunado 				| (VTTBR_BADDR_MASK << VTTBR_BADDR_SHIFT)));
295495f3d3cSDavid Cunado 
296495f3d3cSDavid Cunado 			/*
29718f2efd6SDavid Cunado 			 * Initialise HDCR, setting all the fields rather than
29818f2efd6SDavid Cunado 			 * relying on hw.
29918f2efd6SDavid Cunado 			 *
30018f2efd6SDavid Cunado 			 * HDCR.HPMN: Set to value of PMCR.N which is the
30118f2efd6SDavid Cunado 			 *  architecturally-defined reset value.
302c3e8b0beSAlexei Fedorov 			 *
303c3e8b0beSAlexei Fedorov 			 * HDCR.HLP: Set to one so that event counter
304c3e8b0beSAlexei Fedorov 			 *  overflow, that is recorded in PMOVSCLR[0-30],
305c3e8b0beSAlexei Fedorov 			 *  occurs on the increment that changes
306c3e8b0beSAlexei Fedorov 			 *  PMEVCNTR<n>[63] from 1 to 0, when ARMv8.5-PMU is
307c3e8b0beSAlexei Fedorov 			 *  implemented. This bit is RES0 in versions of the
308c3e8b0beSAlexei Fedorov 			 *  architecture earlier than ARMv8.5, setting it to 1
309c3e8b0beSAlexei Fedorov 			 *  doesn't have any effect on them.
310c3e8b0beSAlexei Fedorov 			 *  This bit is Reserved, UNK/SBZP in ARMv7.
311c3e8b0beSAlexei Fedorov 			 *
312c3e8b0beSAlexei Fedorov 			 * HDCR.HPME: Set to zero to disable EL2 Event
313c3e8b0beSAlexei Fedorov 			 *  counters.
314495f3d3cSDavid Cunado 			 */
315c3e8b0beSAlexei Fedorov #if (ARM_ARCH_MAJOR > 7)
316c3e8b0beSAlexei Fedorov 			write_hdcr((HDCR_RESET_VAL | HDCR_HLP_BIT |
317c3e8b0beSAlexei Fedorov 				   ((read_pmcr() & PMCR_N_BITS) >>
318c3e8b0beSAlexei Fedorov 				    PMCR_N_SHIFT)) & ~HDCR_HPME_BIT);
319c3e8b0beSAlexei Fedorov #else
320c3e8b0beSAlexei Fedorov 			write_hdcr((HDCR_RESET_VAL |
321c3e8b0beSAlexei Fedorov 				   ((read_pmcr() & PMCR_N_BITS) >>
322c3e8b0beSAlexei Fedorov 				    PMCR_N_SHIFT)) & ~HDCR_HPME_BIT);
323c3e8b0beSAlexei Fedorov #endif
324939f66d6SDavid Cunado 			/*
32518f2efd6SDavid Cunado 			 * Set HSTR to its architectural reset value so that
32618f2efd6SDavid Cunado 			 * access to system registers in the cproc=1111
32718f2efd6SDavid Cunado 			 * encoding space do not trap to Hyp mode.
328939f66d6SDavid Cunado 			 */
32918f2efd6SDavid Cunado 			write_hstr(HSTR_RESET_VAL);
33018f2efd6SDavid Cunado 			/*
33118f2efd6SDavid Cunado 			 * Set CNTHP_CTL to its architectural reset value to
33218f2efd6SDavid Cunado 			 * disable the EL2 physical timer and prevent timer
33318f2efd6SDavid Cunado 			 * interrupts. Some fields are architecturally UNKNOWN
33418f2efd6SDavid Cunado 			 * on reset and are set to zero.
33518f2efd6SDavid Cunado 			 */
33618f2efd6SDavid Cunado 			write_cnthp_ctl(CNTHP_CTL_RESET_VAL);
337e33b78a6SSoby Mathew 			isb();
338e33b78a6SSoby Mathew 
339e33b78a6SSoby Mathew 			write_scr(read_scr() & ~SCR_NS_BIT);
340e33b78a6SSoby Mathew 			isb();
341e33b78a6SSoby Mathew 		}
3420fd0f222SDimitris Papastamos 		enable_extensions_nonsecure(el2_unused);
343e33b78a6SSoby Mathew 	}
344e33b78a6SSoby Mathew }
3458b95e848SZelalem Aweke 
3468b95e848SZelalem Aweke /*******************************************************************************
3478b95e848SZelalem Aweke  * This function is used to exit to Non-secure world. It simply calls the
3488b95e848SZelalem Aweke  * cm_prepare_el3_exit function for AArch32.
3498b95e848SZelalem Aweke  ******************************************************************************/
3508b95e848SZelalem Aweke void cm_prepare_el3_exit_ns(void)
3518b95e848SZelalem Aweke {
3528b95e848SZelalem Aweke 	cm_prepare_el3_exit(NON_SECURE);
3538b95e848SZelalem Aweke }
354