blob: f75ab79102d8e55fbfd4ba18a20f9f4fd6198ab2 [file] [log] [blame]
Antonio Nino Diaz233c7c12017-03-08 14:40:23 +00001/*
2 * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved.
3 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Antonio Nino Diaz233c7c12017-03-08 14:40:23 +00005 */
6
7#ifndef __XLAT_TABLES_ARCH_H__
8#define __XLAT_TABLES_ARCH_H__
9
10#include <arch.h>
11#include <platform_def.h>
12#include <xlat_tables_defs.h>
Antonio Nino Diazc0132522017-05-17 16:25:40 +010013#include "../xlat_tables_private.h"
Antonio Nino Diaz233c7c12017-03-08 14:40:23 +000014
15/*
16 * In AArch32 state, the MMU only supports 4KB page granularity, which means
17 * that the first translation table level is either 1 or 2. Both of them are
18 * allowed to have block and table descriptors. See section G4.5.6 of the
19 * ARMv8-A Architecture Reference Manual (DDI 0487A.k) for more information.
20 *
21 * The define below specifies the first table level that allows block
22 * descriptors.
23 */
24
25#define MIN_LVL_BLOCK_DESC 1
26
27/*
28 * Each platform can define the size of the virtual address space, which is
29 * defined in PLAT_VIRT_ADDR_SPACE_SIZE. TTBCR.TxSZ is calculated as 32 minus
30 * the width of said address space. The value of TTBCR.TxSZ must be in the
31 * range 0 to 7 [1], which means that the virtual address space width must be
32 * in the range 32 to 25 bits.
33 *
34 * Here we calculate the initial lookup level from the value of
35 * PLAT_VIRT_ADDR_SPACE_SIZE. For a 4 KB page size, level 1 supports virtual
36 * address spaces of widths 32 to 31 bits, and level 2 from 30 to 25. Wider or
37 * narrower address spaces are not supported. As a result, level 3 cannot be
38 * used as initial lookup level with 4 KB granularity [1].
39 *
40 * For example, for a 31-bit address space (i.e. PLAT_VIRT_ADDR_SPACE_SIZE ==
41 * 1 << 31), TTBCR.TxSZ will be programmed to (32 - 31) = 1. According to Table
42 * G4-5 in the ARM ARM, the initial lookup level for an address space like that
43 * is 1.
44 *
45 * See the ARMv8-A Architecture Reference Manual (DDI 0487A.j) for more
46 * information:
47 * [1] Section G4.6.5
48 */
49
50#if PLAT_VIRT_ADDR_SPACE_SIZE > (1ULL << (32 - TTBCR_TxSZ_MIN))
51
52# error "PLAT_VIRT_ADDR_SPACE_SIZE is too big."
53
54#elif PLAT_VIRT_ADDR_SPACE_SIZE > (1 << L1_XLAT_ADDRESS_SHIFT)
55
56# define XLAT_TABLE_LEVEL_BASE 1
57# define NUM_BASE_LEVEL_ENTRIES \
58 (PLAT_VIRT_ADDR_SPACE_SIZE >> L1_XLAT_ADDRESS_SHIFT)
59
60#elif PLAT_VIRT_ADDR_SPACE_SIZE >= (1 << (32 - TTBCR_TxSZ_MAX))
61
62# define XLAT_TABLE_LEVEL_BASE 2
63# define NUM_BASE_LEVEL_ENTRIES \
64 (PLAT_VIRT_ADDR_SPACE_SIZE >> L2_XLAT_ADDRESS_SHIFT)
65
66#else
67
68# error "PLAT_VIRT_ADDR_SPACE_SIZE is too small."
69
70#endif
71
72#endif /* __XLAT_TABLES_ARCH_H__ */