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