blob: 4b48405285bf516086c8474ff1c05db10971d522 [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#ifndef __XLAT_TABLES_PRIVATE_H__
32#define __XLAT_TABLES_PRIVATE_H__
33
34#include <cassert.h>
35#include <platform_def.h>
36#include <utils.h>
37
38/*
39 * If the platform hasn't defined a physical and a virtual address space size
40 * default to ADDR_SPACE_SIZE.
41 */
42#if ERROR_DEPRECATED
43# ifdef ADDR_SPACE_SIZE
44# error "ADDR_SPACE_SIZE is deprecated. Use PLAT_xxx_ADDR_SPACE_SIZE instead."
45# endif
46#elif defined(ADDR_SPACE_SIZE)
47# ifndef PLAT_PHY_ADDR_SPACE_SIZE
48# define PLAT_PHY_ADDR_SPACE_SIZE ADDR_SPACE_SIZE
49# endif
50# ifndef PLAT_VIRT_ADDR_SPACE_SIZE
51# define PLAT_VIRT_ADDR_SPACE_SIZE ADDR_SPACE_SIZE
52# endif
53#endif
54
55/* The virtual and physical address space sizes must be powers of two. */
56CASSERT(IS_POWER_OF_TWO(PLAT_VIRT_ADDR_SPACE_SIZE),
57 assert_valid_virt_addr_space_size);
58CASSERT(IS_POWER_OF_TWO(PLAT_PHY_ADDR_SPACE_SIZE),
59 assert_valid_phy_addr_space_size);
60
61/* Struct that holds all information about the translation tables. */
62typedef struct {
63
64 /*
65 * Max allowed Virtual and Physical Addresses.
66 */
67 unsigned long long pa_max_address;
68 uintptr_t va_max_address;
69
70 /*
71 * Array of all memory regions stored in order of ascending end address
72 * and ascending size to simplify the code that allows overlapping
73 * regions. The list is terminated by the first entry with size == 0.
74 */
75 mmap_region_t *mmap; /* mmap_num + 1 elements */
76 int mmap_num;
77
78 /*
79 * Array of finer-grain translation tables.
80 * For example, if the initial lookup level is 1 then this array would
81 * contain both level-2 and level-3 entries.
82 */
83 uint64_t (*tables)[XLAT_TABLE_ENTRIES];
84 int tables_num;
85
86 int next_table;
87
88 /*
89 * Base translation table. It doesn't need to have the same amount of
90 * entries as the ones used for other levels.
91 */
92 uint64_t *base_table;
93 int base_table_entries;
94
95 unsigned long long max_pa;
96 uintptr_t max_va;
97
98 /* Level of the base translation table. */
99 int base_level;
100
101 /* Set to 1 when the translation tables are initialized. */
102 int initialized;
103
104} xlat_ctx_t;
105
106/* Print VA, PA, size and attributes of all regions in the mmap array. */
107void print_mmap(mmap_region_t *const mmap);
108
109/*
110 * Print the current state of the translation tables by reading them from
111 * memory.
112 */
113void xlat_tables_print(xlat_ctx_t *ctx);
114
115/*
116 * Initialize the translation tables by mapping all regions added to the
117 * specified context.
118 */
119void init_xlation_table(xlat_ctx_t *ctx);
120
121/* Add a static region to the specified context. */
122void mmap_add_region_ctx(xlat_ctx_t *ctx, mmap_region_t *mm);
123
124/*
125 * Architecture-specific initialization code.
126 */
127
128/* Execute architecture-specific translation table initialization code. */
129void init_xlat_tables_arch(unsigned long long max_pa);
130
131/* Enable MMU and configure it to use the specified translation tables. */
132void enable_mmu_arch(unsigned int flags, uint64_t *base_table);
133
134/* Return 1 if the MMU of this Exception Level is enabled, 0 otherwise. */
135int is_mmu_enabled(void);
136
137#endif /* __XLAT_TABLES_PRIVATE_H__ */