blob: 5b3205dc5c3c32bbc704877cfffa0d316c70c803 [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>
13
14/*
15 * In AArch64 state, the MMU may support 4 KB, 16 KB and 64 KB page
16 * granularity. For 4KB granularity, a level 0 table descriptor doesn't support
17 * block translation. For 16KB, the same thing happens to levels 0 and 1. For
18 * 64KB, same for level 1. See section D4.3.1 of the ARMv8-A Architecture
19 * 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#if PAGE_SIZE == (4*1024) /* 4KB */
26# define MIN_LVL_BLOCK_DESC 1
27#else /* 16KB or 64KB */
28# define MIN_LVL_BLOCK_DESC 2
29#endif
30
31/*
32 * Each platform can define the size of the virtual address space, which is
33 * defined in PLAT_VIRT_ADDR_SPACE_SIZE. TCR.TxSZ is calculated as 64 minus the
34 * width of said address space. The value of TCR.TxSZ must be in the range 16
35 * to 39 [1], which means that the virtual address space width must be in the
36 * range 48 to 25 bits.
37 *
38 * Here we calculate the initial lookup level from the value of
39 * PLAT_VIRT_ADDR_SPACE_SIZE. For a 4 KB page size, level 0 supports virtual
40 * address spaces of widths 48 to 40 bits, level 1 from 39 to 31, and level 2
41 * from 30 to 25. Wider or narrower address spaces are not supported. As a
42 * result, level 3 cannot be used as initial lookup level with 4 KB
43 * granularity. [2]
44 *
45 * For example, for a 35-bit address space (i.e. PLAT_VIRT_ADDR_SPACE_SIZE ==
46 * 1 << 35), TCR.TxSZ will be programmed to (64 - 35) = 29. According to Table
47 * D4-11 in the ARM ARM, the initial lookup level for an address space like
48 * that is 1.
49 *
50 * See the ARMv8-A Architecture Reference Manual (DDI 0487A.j) for more
51 * information:
52 * [1] Page 1730: 'Input address size', 'For all translation stages'.
53 * [2] Section D4.2.5
54 */
55
56#if PLAT_VIRT_ADDR_SPACE_SIZE > (1ULL << (64 - TCR_TxSZ_MIN))
57
58# error "PLAT_VIRT_ADDR_SPACE_SIZE is too big."
59
60#elif PLAT_VIRT_ADDR_SPACE_SIZE > (1ULL << L0_XLAT_ADDRESS_SHIFT)
61
62# define XLAT_TABLE_LEVEL_BASE 0
63# define NUM_BASE_LEVEL_ENTRIES \
64 (PLAT_VIRT_ADDR_SPACE_SIZE >> L0_XLAT_ADDRESS_SHIFT)
65
66#elif PLAT_VIRT_ADDR_SPACE_SIZE > (1 << L1_XLAT_ADDRESS_SHIFT)
67
68# define XLAT_TABLE_LEVEL_BASE 1
69# define NUM_BASE_LEVEL_ENTRIES \
70 (PLAT_VIRT_ADDR_SPACE_SIZE >> L1_XLAT_ADDRESS_SHIFT)
71
72#elif PLAT_VIRT_ADDR_SPACE_SIZE >= (1 << (64 - TCR_TxSZ_MAX))
73
74# define XLAT_TABLE_LEVEL_BASE 2
75# define NUM_BASE_LEVEL_ENTRIES \
76 (PLAT_VIRT_ADDR_SPACE_SIZE >> L2_XLAT_ADDRESS_SHIFT)
77
78#else
79
80# error "PLAT_VIRT_ADDR_SPACE_SIZE is too small."
81
82#endif
83
84#endif /* __XLAT_TABLES_ARCH_H__ */