blob: 070877bb7705b6505caba42f7b951ebe6488c351 [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_ARCH_H__
32#define __XLAT_TABLES_ARCH_H__
33
34#include <arch.h>
35#include <platform_def.h>
36#include <xlat_tables_defs.h>
37
38/*
39 * In AArch32 state, the MMU only supports 4KB page granularity, which means
40 * that the first translation table level is either 1 or 2. Both of them are
41 * allowed to have block and table descriptors. See section G4.5.6 of the
42 * ARMv8-A Architecture Reference Manual (DDI 0487A.k) for more information.
43 *
44 * The define below specifies the first table level that allows block
45 * descriptors.
46 */
47
48#define MIN_LVL_BLOCK_DESC 1
49
50/*
51 * Each platform can define the size of the virtual address space, which is
52 * defined in PLAT_VIRT_ADDR_SPACE_SIZE. TTBCR.TxSZ is calculated as 32 minus
53 * the width of said address space. The value of TTBCR.TxSZ must be in the
54 * range 0 to 7 [1], which means that the virtual address space width must be
55 * in the range 32 to 25 bits.
56 *
57 * Here we calculate the initial lookup level from the value of
58 * PLAT_VIRT_ADDR_SPACE_SIZE. For a 4 KB page size, level 1 supports virtual
59 * address spaces of widths 32 to 31 bits, and level 2 from 30 to 25. Wider or
60 * narrower address spaces are not supported. As a result, level 3 cannot be
61 * used as initial lookup level with 4 KB granularity [1].
62 *
63 * For example, for a 31-bit address space (i.e. PLAT_VIRT_ADDR_SPACE_SIZE ==
64 * 1 << 31), TTBCR.TxSZ will be programmed to (32 - 31) = 1. According to Table
65 * G4-5 in the ARM ARM, the initial lookup level for an address space like that
66 * is 1.
67 *
68 * See the ARMv8-A Architecture Reference Manual (DDI 0487A.j) for more
69 * information:
70 * [1] Section G4.6.5
71 */
72
73#if PLAT_VIRT_ADDR_SPACE_SIZE > (1ULL << (32 - TTBCR_TxSZ_MIN))
74
75# error "PLAT_VIRT_ADDR_SPACE_SIZE is too big."
76
77#elif PLAT_VIRT_ADDR_SPACE_SIZE > (1 << L1_XLAT_ADDRESS_SHIFT)
78
79# define XLAT_TABLE_LEVEL_BASE 1
80# define NUM_BASE_LEVEL_ENTRIES \
81 (PLAT_VIRT_ADDR_SPACE_SIZE >> L1_XLAT_ADDRESS_SHIFT)
82
83#elif PLAT_VIRT_ADDR_SPACE_SIZE >= (1 << (32 - TTBCR_TxSZ_MAX))
84
85# define XLAT_TABLE_LEVEL_BASE 2
86# define NUM_BASE_LEVEL_ENTRIES \
87 (PLAT_VIRT_ADDR_SPACE_SIZE >> L2_XLAT_ADDRESS_SHIFT)
88
89#else
90
91# error "PLAT_VIRT_ADDR_SPACE_SIZE is too small."
92
93#endif
94
95#endif /* __XLAT_TABLES_ARCH_H__ */