blob: 0b17842caaa2352e5d80a22ce43bf62e9da9117d [file] [log] [blame]
Antonio Nino Diaz233c7c12017-03-08 14:40:23 +00001/*
2 * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9 *
10 * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * Neither the name of ARM nor the names of its contributors may be used
15 * to endorse or promote products derived from this software without specific
16 * prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#include <arch.h>
32#include <arch_helpers.h>
33#include <assert.h>
34#include <cassert.h>
35#include <common_def.h>
36#include <debug.h>
37#include <errno.h>
38#include <platform_def.h>
39#include <string.h>
40#include <types.h>
41#include <utils.h>
42#include <xlat_tables_v2.h>
43#ifdef AARCH32
44# include "aarch32/xlat_tables_arch.h"
45#else
46# include "aarch64/xlat_tables_arch.h"
47#endif
48#include "xlat_tables_private.h"
49
50/*
51 * Private variables used by the TF
52 */
53static mmap_region_t tf_mmap[MAX_MMAP_REGIONS + 1];
54
55static uint64_t tf_xlat_tables[MAX_XLAT_TABLES][XLAT_TABLE_ENTRIES]
56 __aligned(XLAT_TABLE_SIZE) __section("xlat_table");
57
58static uint64_t tf_base_xlat_table[NUM_BASE_LEVEL_ENTRIES]
59 __aligned(NUM_BASE_LEVEL_ENTRIES * sizeof(uint64_t));
60
61static mmap_region_t tf_mmap[MAX_MMAP_REGIONS + 1];
62
63xlat_ctx_t tf_xlat_ctx = {
64
65 .pa_max_address = PLAT_PHY_ADDR_SPACE_SIZE - 1,
66 .va_max_address = PLAT_VIRT_ADDR_SPACE_SIZE - 1,
67
68 .mmap = tf_mmap,
69 .mmap_num = MAX_MMAP_REGIONS,
70
71 .tables = tf_xlat_tables,
72 .tables_num = MAX_XLAT_TABLES,
73
74 .base_table = tf_base_xlat_table,
75 .base_table_entries = NUM_BASE_LEVEL_ENTRIES,
76
77 .max_pa = 0,
78 .max_va = 0,
79
80 .next_table = 0,
81
82 .base_level = XLAT_TABLE_LEVEL_BASE,
83
84 .initialized = 0
85};
86
87void mmap_add_region(unsigned long long base_pa, uintptr_t base_va,
88 size_t size, unsigned int attr)
89{
90 mmap_region_t mm = {
91 .base_va = base_va,
92 .base_pa = base_pa,
93 .size = size,
94 .attr = attr,
95 };
96 mmap_add_region_ctx(&tf_xlat_ctx, (mmap_region_t *)&mm);
97}
98
99void mmap_add(const mmap_region_t *mm)
100{
101 while (mm->size) {
102 mmap_add_region_ctx(&tf_xlat_ctx, (mmap_region_t *)mm);
103 mm++;
104 }
105}
106
107void init_xlat_tables(void)
108{
109 assert(!is_mmu_enabled());
110 assert(!tf_xlat_ctx.initialized);
111 print_mmap(tf_xlat_ctx.mmap);
112 init_xlation_table(&tf_xlat_ctx);
113 xlat_tables_print(&tf_xlat_ctx);
114
115 assert(tf_xlat_ctx.max_va <= PLAT_VIRT_ADDR_SPACE_SIZE - 1);
116 assert(tf_xlat_ctx.max_pa <= PLAT_PHY_ADDR_SPACE_SIZE - 1);
117
118 init_xlat_tables_arch(tf_xlat_ctx.max_pa);
119}
120
121#ifdef AARCH32
122
123void enable_mmu_secure(unsigned int flags)
124{
125 enable_mmu_arch(flags, tf_xlat_ctx.base_table);
126}
127
128#else
129
130void enable_mmu_el1(unsigned int flags)
131{
132 enable_mmu_arch(flags, tf_xlat_ctx.base_table);
133}
134
135void enable_mmu_el3(unsigned int flags)
136{
137 enable_mmu_arch(flags, tf_xlat_ctx.base_table);
138}
139
140#endif /* AARCH32 */