xref: /arm-trusted-firmware/include/lib/xlat_tables/xlat_mmu_helpers.h (revision 91f16700b400a8c0651d24a598fc48ee2997a0d7)
1*91f16700Schasinglulu /*
2*91f16700Schasinglulu  * Copyright (c) 2014-2018, Arm Limited and Contributors. All rights reserved.
3*91f16700Schasinglulu  *
4*91f16700Schasinglulu  * SPDX-License-Identifier: BSD-3-Clause
5*91f16700Schasinglulu  */
6*91f16700Schasinglulu 
7*91f16700Schasinglulu #ifndef XLAT_MMU_HELPERS_H
8*91f16700Schasinglulu #define XLAT_MMU_HELPERS_H
9*91f16700Schasinglulu 
10*91f16700Schasinglulu /*
11*91f16700Schasinglulu  * The following flags are passed to enable_mmu_xxx() to override the default
12*91f16700Schasinglulu  * values used to program system registers while enabling the MMU.
13*91f16700Schasinglulu  */
14*91f16700Schasinglulu 
15*91f16700Schasinglulu /*
16*91f16700Schasinglulu  * When this flag is used, all data access to Normal memory from this EL and all
17*91f16700Schasinglulu  * Normal memory accesses to the translation tables of this EL are non-cacheable
18*91f16700Schasinglulu  * for all levels of data and unified cache until the caches are enabled by
19*91f16700Schasinglulu  * setting the bit SCTLR_ELx.C.
20*91f16700Schasinglulu  */
21*91f16700Schasinglulu #define DISABLE_DCACHE			(U(1) << 0)
22*91f16700Schasinglulu 
23*91f16700Schasinglulu /*
24*91f16700Schasinglulu  * Mark the translation tables as non-cacheable for the MMU table walker, which
25*91f16700Schasinglulu  * is a different observer from the PE/CPU. If the flag is not specified, the
26*91f16700Schasinglulu  * tables are cacheable for the MMU table walker.
27*91f16700Schasinglulu  *
28*91f16700Schasinglulu  * Note that, as far as the PE/CPU observer is concerned, the attributes used
29*91f16700Schasinglulu  * are the ones specified in the translation tables themselves. The MAIR
30*91f16700Schasinglulu  * register specifies the cacheability through the field AttrIndx of the lower
31*91f16700Schasinglulu  * attributes of the translation tables. The shareability is specified in the SH
32*91f16700Schasinglulu  * field of the lower attributes.
33*91f16700Schasinglulu  *
34*91f16700Schasinglulu  * The MMU table walker uses the attributes specified in the fields ORGNn, IRGNn
35*91f16700Schasinglulu  * and SHn of the TCR register to access the translation tables.
36*91f16700Schasinglulu  *
37*91f16700Schasinglulu  * The attributes specified in the TCR register and the tables can be different
38*91f16700Schasinglulu  * as there are no checks to prevent that. Special care must be taken to ensure
39*91f16700Schasinglulu  * that there aren't mismatches. The behaviour in that case is described in the
40*91f16700Schasinglulu  * sections 'Mismatched memory attributes' in the ARMv8 ARM.
41*91f16700Schasinglulu  */
42*91f16700Schasinglulu #define XLAT_TABLE_NC			(U(1) << 1)
43*91f16700Schasinglulu 
44*91f16700Schasinglulu /*
45*91f16700Schasinglulu  * Offsets into a mmu_cfg_params array generated by setup_mmu_cfg(). All
46*91f16700Schasinglulu  * parameters are 64 bits wide.
47*91f16700Schasinglulu  */
48*91f16700Schasinglulu #define MMU_CFG_MAIR		0
49*91f16700Schasinglulu #define MMU_CFG_TCR		1
50*91f16700Schasinglulu #define MMU_CFG_TTBR0		2
51*91f16700Schasinglulu #define MMU_CFG_PARAM_MAX	3
52*91f16700Schasinglulu 
53*91f16700Schasinglulu #ifndef __ASSEMBLER__
54*91f16700Schasinglulu 
55*91f16700Schasinglulu #include <stdbool.h>
56*91f16700Schasinglulu #include <stdint.h>
57*91f16700Schasinglulu #include <string.h>
58*91f16700Schasinglulu 
59*91f16700Schasinglulu #include <arch_helpers.h>
60*91f16700Schasinglulu 
61*91f16700Schasinglulu /*
62*91f16700Schasinglulu  * Return the values that the MMU configuration registers must contain for the
63*91f16700Schasinglulu  * specified translation context. `params` must be a pointer to array of size
64*91f16700Schasinglulu  * MMU_CFG_PARAM_MAX.
65*91f16700Schasinglulu  */
66*91f16700Schasinglulu void setup_mmu_cfg(uint64_t *params, unsigned int flags,
67*91f16700Schasinglulu 		   const uint64_t *base_table, unsigned long long max_pa,
68*91f16700Schasinglulu 		   uintptr_t max_va, int xlat_regime);
69*91f16700Schasinglulu 
70*91f16700Schasinglulu #ifdef __aarch64__
71*91f16700Schasinglulu /* AArch64 specific translation table APIs */
72*91f16700Schasinglulu void enable_mmu_el1(unsigned int flags);
73*91f16700Schasinglulu void enable_mmu_el2(unsigned int flags);
74*91f16700Schasinglulu void enable_mmu_el3(unsigned int flags);
75*91f16700Schasinglulu void enable_mmu(unsigned int flags);
76*91f16700Schasinglulu 
77*91f16700Schasinglulu void enable_mmu_direct_el1(unsigned int flags);
78*91f16700Schasinglulu void enable_mmu_direct_el2(unsigned int flags);
79*91f16700Schasinglulu void enable_mmu_direct_el3(unsigned int flags);
80*91f16700Schasinglulu #else
81*91f16700Schasinglulu /* AArch32 specific translation table API */
82*91f16700Schasinglulu void enable_mmu_svc_mon(unsigned int flags);
83*91f16700Schasinglulu void enable_mmu_hyp(unsigned int flags);
84*91f16700Schasinglulu 
85*91f16700Schasinglulu void enable_mmu_direct_svc_mon(unsigned int flags);
86*91f16700Schasinglulu void enable_mmu_direct_hyp(unsigned int flags);
87*91f16700Schasinglulu #endif /* __aarch64__ */
88*91f16700Schasinglulu 
89*91f16700Schasinglulu bool xlat_arch_is_granule_size_supported(size_t size);
90*91f16700Schasinglulu size_t xlat_arch_get_max_supported_granule_size(void);
91*91f16700Schasinglulu 
92*91f16700Schasinglulu #endif /* __ASSEMBLER__ */
93*91f16700Schasinglulu 
94*91f16700Schasinglulu #endif /* XLAT_MMU_HELPERS_H */
95