xref: /arm-trusted-firmware/lib/xlat_mpu/xlat_mpu_context.c (revision 91f16700b400a8c0651d24a598fc48ee2997a0d7)
1*91f16700Schasinglulu /*
2*91f16700Schasinglulu  * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
3*91f16700Schasinglulu  *
4*91f16700Schasinglulu  * SPDX-License-Identifier: BSD-3-Clause
5*91f16700Schasinglulu  */
6*91f16700Schasinglulu 
7*91f16700Schasinglulu #include <assert.h>
8*91f16700Schasinglulu 
9*91f16700Schasinglulu #include <common/debug.h>
10*91f16700Schasinglulu 
11*91f16700Schasinglulu #include "lib/xlat_mpu/xlat_mpu.h"
12*91f16700Schasinglulu #include <lib/xlat_tables/xlat_tables_defs.h>
13*91f16700Schasinglulu #include <lib/xlat_tables/xlat_tables_v2.h>
14*91f16700Schasinglulu #include "xlat_mpu_private.h"
15*91f16700Schasinglulu 
16*91f16700Schasinglulu #include <fvp_r_arch_helpers.h>
17*91f16700Schasinglulu #include <platform_def.h>
18*91f16700Schasinglulu 
19*91f16700Schasinglulu #warning "xlat_mpu library is currently experimental and its API may change in future."
20*91f16700Schasinglulu 
21*91f16700Schasinglulu 
22*91f16700Schasinglulu /*
23*91f16700Schasinglulu  * MMU configuration register values for the active translation context. Used
24*91f16700Schasinglulu  * from the MMU assembly helpers.
25*91f16700Schasinglulu  */
26*91f16700Schasinglulu uint64_t mmu_cfg_params[MMU_CFG_PARAM_MAX];
27*91f16700Schasinglulu 
28*91f16700Schasinglulu /*
29*91f16700Schasinglulu  * Allocate and initialise the default translation context for the BL image
30*91f16700Schasinglulu  * currently executing.
31*91f16700Schasinglulu  */
32*91f16700Schasinglulu REGISTER_XLAT_CONTEXT(tf, MAX_MMAP_REGIONS, MAX_XLAT_TABLES,
33*91f16700Schasinglulu 			PLAT_VIRT_ADDR_SPACE_SIZE, PLAT_PHY_ADDR_SPACE_SIZE);
34*91f16700Schasinglulu 
35*91f16700Schasinglulu void mmap_add(const mmap_region_t *mm)
36*91f16700Schasinglulu {
37*91f16700Schasinglulu 	mmap_add_ctx(&tf_xlat_ctx, mm);
38*91f16700Schasinglulu }
39*91f16700Schasinglulu 
40*91f16700Schasinglulu void __init init_xlat_tables(void)
41*91f16700Schasinglulu {
42*91f16700Schasinglulu 	assert(tf_xlat_ctx.xlat_regime == EL_REGIME_INVALID);
43*91f16700Schasinglulu 
44*91f16700Schasinglulu 	unsigned int current_el = xlat_arch_current_el();
45*91f16700Schasinglulu 
46*91f16700Schasinglulu 	if (current_el == 1U) {
47*91f16700Schasinglulu 		tf_xlat_ctx.xlat_regime = EL1_EL0_REGIME;
48*91f16700Schasinglulu 	} else {
49*91f16700Schasinglulu 		assert(current_el == 2U);
50*91f16700Schasinglulu 		tf_xlat_ctx.xlat_regime = EL2_REGIME;
51*91f16700Schasinglulu 	}
52*91f16700Schasinglulu 	/* Note:  If EL3 is supported in future v8-R64, add EL3 assignment */
53*91f16700Schasinglulu 	init_xlat_tables_ctx(&tf_xlat_ctx);
54*91f16700Schasinglulu }
55*91f16700Schasinglulu 
56*91f16700Schasinglulu int xlat_get_mem_attributes(uintptr_t base_va, uint32_t *attr)
57*91f16700Schasinglulu {
58*91f16700Schasinglulu 	return xlat_get_mem_attributes_ctx(&tf_xlat_ctx, base_va, attr);
59*91f16700Schasinglulu }
60*91f16700Schasinglulu 
61*91f16700Schasinglulu void enable_mpu_el2(unsigned int flags)
62*91f16700Schasinglulu {
63*91f16700Schasinglulu 	/* EL2 is strictly MPU on v8-R64, so no need for setup_mpu_cfg() */
64*91f16700Schasinglulu 	enable_mpu_direct_el2(flags);
65*91f16700Schasinglulu }
66