xref: /rk3399_ARM-atf/include/lib/xlat_tables/xlat_mmu_helpers.h (revision 63ddbae3655d267fd76eef65798a48f58de75485)
17bb01fb2SAntonio Nino Diaz /*
2883d1b5dSAntonio Nino Diaz  * Copyright (c) 2014-2018, ARM Limited and Contributors. All rights reserved.
37bb01fb2SAntonio Nino Diaz  *
482cb2c1aSdp-arm  * SPDX-License-Identifier: BSD-3-Clause
57bb01fb2SAntonio Nino Diaz  */
67bb01fb2SAntonio Nino Diaz 
77bb01fb2SAntonio Nino Diaz #ifndef __XLAT_MMU_HELPERS_H__
87bb01fb2SAntonio Nino Diaz #define __XLAT_MMU_HELPERS_H__
97bb01fb2SAntonio Nino Diaz 
10883d1b5dSAntonio Nino Diaz /*
11883d1b5dSAntonio Nino Diaz  * The following flags are passed to enable_mmu_xxx() to override the default
12883d1b5dSAntonio Nino Diaz  * values used to program system registers while enabling the MMU.
13883d1b5dSAntonio Nino Diaz  */
14883d1b5dSAntonio Nino Diaz 
15883d1b5dSAntonio Nino Diaz /*
16883d1b5dSAntonio Nino Diaz  * When this flag is used, all data access to Normal memory from this EL and all
17883d1b5dSAntonio Nino Diaz  * Normal memory accesses to the translation tables of this EL are non-cacheable
18883d1b5dSAntonio Nino Diaz  * for all levels of data and unified cache until the caches are enabled by
19883d1b5dSAntonio Nino Diaz  * setting the bit SCTLR_ELx.C.
20883d1b5dSAntonio Nino Diaz  */
21883d1b5dSAntonio Nino Diaz #define DISABLE_DCACHE			(U(1) << 0)
22883d1b5dSAntonio Nino Diaz 
23883d1b5dSAntonio Nino Diaz /*
24883d1b5dSAntonio Nino Diaz  * Mark the translation tables as non-cacheable for the MMU table walker, which
25883d1b5dSAntonio Nino Diaz  * is a different observer from the PE/CPU. If the flag is not specified, the
26883d1b5dSAntonio Nino Diaz  * tables are cacheable for the MMU table walker.
27883d1b5dSAntonio Nino Diaz  *
28883d1b5dSAntonio Nino Diaz  * Note that, as far as the PE/CPU observer is concerned, the attributes used
29883d1b5dSAntonio Nino Diaz  * are the ones specified in the translation tables themselves. The MAIR
30883d1b5dSAntonio Nino Diaz  * register specifies the cacheability through the field AttrIndx of the lower
31883d1b5dSAntonio Nino Diaz  * attributes of the translation tables. The shareability is specified in the SH
32883d1b5dSAntonio Nino Diaz  * field of the lower attributes.
33883d1b5dSAntonio Nino Diaz  *
34883d1b5dSAntonio Nino Diaz  * The MMU table walker uses the attributes specified in the fields ORGNn, IRGNn
35883d1b5dSAntonio Nino Diaz  * and SHn of the TCR register to access the translation tables.
36883d1b5dSAntonio Nino Diaz  *
37883d1b5dSAntonio Nino Diaz  * The attributes specified in the TCR register and the tables can be different
38883d1b5dSAntonio Nino Diaz  * as there are no checks to prevent that. Special care must be taken to ensure
39883d1b5dSAntonio Nino Diaz  * that there aren't mismatches. The behaviour in that case is described in the
40883d1b5dSAntonio Nino Diaz  * sections 'Mismatched memory attributes' in the ARMv8 ARM.
41883d1b5dSAntonio Nino Diaz  */
42883d1b5dSAntonio Nino Diaz #define XLAT_TABLE_NC			(U(1) << 1)
43883d1b5dSAntonio Nino Diaz 
44*63ddbae3SAntonio Nino Diaz /*
45*63ddbae3SAntonio Nino Diaz  * Offsets into a mmu_cfg_params array generated by setup_mmu_cfg(). All
46*63ddbae3SAntonio Nino Diaz  * parameters are 64 bits wide.
47*63ddbae3SAntonio Nino Diaz  */
48*63ddbae3SAntonio Nino Diaz #define MMU_CFG_MAIR		0
49*63ddbae3SAntonio Nino Diaz #define MMU_CFG_TCR		1
50*63ddbae3SAntonio Nino Diaz #define MMU_CFG_TTBR0		2
51*63ddbae3SAntonio Nino Diaz #define MMU_CFG_PARAM_MAX	3
52*63ddbae3SAntonio Nino Diaz 
53883d1b5dSAntonio Nino Diaz #ifndef __ASSEMBLY__
54883d1b5dSAntonio Nino Diaz 
55a0b9bb79SAntonio Nino Diaz #include <sys/types.h>
56a0b9bb79SAntonio Nino Diaz 
57*63ddbae3SAntonio Nino Diaz /*
58*63ddbae3SAntonio Nino Diaz  * Return the values that the MMU configuration registers must contain for the
59*63ddbae3SAntonio Nino Diaz  * specified translation context. `params` must be a pointer to array of size
60*63ddbae3SAntonio Nino Diaz  * MMU_CFG_PARAM_MAX.
61*63ddbae3SAntonio Nino Diaz  */
62*63ddbae3SAntonio Nino Diaz void setup_mmu_cfg(uint64_t *params, unsigned int flags,
63*63ddbae3SAntonio Nino Diaz 		   const uint64_t *base_table, unsigned long long max_pa,
64*63ddbae3SAntonio Nino Diaz 		   uintptr_t max_va, int xlat_regime);
65*63ddbae3SAntonio Nino Diaz 
667bb01fb2SAntonio Nino Diaz #ifdef AARCH32
677bb01fb2SAntonio Nino Diaz /* AArch32 specific translation table API */
68883d1b5dSAntonio Nino Diaz void enable_mmu_secure(unsigned int flags);
690cc7aa89SJeenu Viswambharan 
700cc7aa89SJeenu Viswambharan void enable_mmu_direct(unsigned int flags);
717bb01fb2SAntonio Nino Diaz #else
727bb01fb2SAntonio Nino Diaz /* AArch64 specific translation table APIs */
737bb01fb2SAntonio Nino Diaz void enable_mmu_el1(unsigned int flags);
747bb01fb2SAntonio Nino Diaz void enable_mmu_el3(unsigned int flags);
750cc7aa89SJeenu Viswambharan 
760cc7aa89SJeenu Viswambharan void enable_mmu_direct_el1(unsigned int flags);
770cc7aa89SJeenu Viswambharan void enable_mmu_direct_el3(unsigned int flags);
787bb01fb2SAntonio Nino Diaz #endif /* AARCH32 */
797bb01fb2SAntonio Nino Diaz 
80a0b9bb79SAntonio Nino Diaz int xlat_arch_is_granule_size_supported(size_t size);
81a0b9bb79SAntonio Nino Diaz size_t xlat_arch_get_max_supported_granule_size(void);
82a0b9bb79SAntonio Nino Diaz 
83883d1b5dSAntonio Nino Diaz #endif /* __ASSEMBLY__ */
84883d1b5dSAntonio Nino Diaz 
857bb01fb2SAntonio Nino Diaz #endif /* __XLAT_MMU_HELPERS_H__ */
86