xref: /rk3399_ARM-atf/include/lib/xlat_tables/aarch32/xlat_tables_aarch32.h (revision 72e8f2456af54b75a0a1d92aadfce0b4bcde6ba1)
18933c34bSSandrine Bailleux /*
2*4c700c15SGovindraj Raja  * Copyright (c) 2017-2018, Arm Limited and Contributors. All rights reserved.
38933c34bSSandrine Bailleux  *
48933c34bSSandrine Bailleux  * SPDX-License-Identifier: BSD-3-Clause
58933c34bSSandrine Bailleux  */
68933c34bSSandrine Bailleux 
7e7b9886cSAntonio Nino Diaz #ifndef XLAT_TABLES_AARCH32_H
8e7b9886cSAntonio Nino Diaz #define XLAT_TABLES_AARCH32_H
98933c34bSSandrine Bailleux 
108933c34bSSandrine Bailleux #include <arch.h>
1109d40e0eSAntonio Nino Diaz #include <lib/utils_def.h>
1209d40e0eSAntonio Nino Diaz #include <lib/xlat_tables/xlat_tables_defs.h>
138933c34bSSandrine Bailleux 
148933c34bSSandrine Bailleux #if !defined(PAGE_SIZE)
158933c34bSSandrine Bailleux #error "PAGE_SIZE is not defined."
168933c34bSSandrine Bailleux #endif
178933c34bSSandrine Bailleux 
188933c34bSSandrine Bailleux /*
198933c34bSSandrine Bailleux  * In AArch32 state, the MMU only supports 4KB page granularity, which means
208933c34bSSandrine Bailleux  * that the first translation table level is either 1 or 2. Both of them are
218933c34bSSandrine Bailleux  * allowed to have block and table descriptors. See section G4.5.6 of the
228933c34bSSandrine Bailleux  * ARMv8-A Architecture Reference Manual (DDI 0487A.k) for more information.
238933c34bSSandrine Bailleux  *
248933c34bSSandrine Bailleux  * The define below specifies the first table level that allows block
258933c34bSSandrine Bailleux  * descriptors.
268933c34bSSandrine Bailleux  */
27e7b9886cSAntonio Nino Diaz #if PAGE_SIZE != PAGE_SIZE_4KB
288933c34bSSandrine Bailleux #error "Invalid granule size. AArch32 supports 4KB pages only."
298933c34bSSandrine Bailleux #endif
308933c34bSSandrine Bailleux 
310044231dSSandrine Bailleux #define MIN_LVL_BLOCK_DESC	U(1)
328933c34bSSandrine Bailleux 
338933c34bSSandrine Bailleux #define XLAT_TABLE_LEVEL_MIN	U(1)
348933c34bSSandrine Bailleux 
358933c34bSSandrine Bailleux /*
368933c34bSSandrine Bailleux  * Define the architectural limits of the virtual address space in AArch32
378933c34bSSandrine Bailleux  * state.
388933c34bSSandrine Bailleux  *
398933c34bSSandrine Bailleux  * TTBCR.TxSZ is calculated as 32 minus the width of said address space. The
408933c34bSSandrine Bailleux  * value of TTBCR.TxSZ must be in the range 0 to 7 [1], which means that the
418933c34bSSandrine Bailleux  * virtual address space width must be in the range 32 to 25 bits.
428933c34bSSandrine Bailleux  *
438933c34bSSandrine Bailleux  * [1] See the ARMv8-A Architecture Reference Manual (DDI 0487A.j) for more
448933c34bSSandrine Bailleux  * information, Section G4.6.5
458933c34bSSandrine Bailleux  */
46e7b9886cSAntonio Nino Diaz #define MIN_VIRT_ADDR_SPACE_SIZE	(ULL(1) << (U(32) - TTBCR_TxSZ_MAX))
47e7b9886cSAntonio Nino Diaz #define MAX_VIRT_ADDR_SPACE_SIZE	(ULL(1) << (U(32) - TTBCR_TxSZ_MIN))
488933c34bSSandrine Bailleux 
498933c34bSSandrine Bailleux /*
508933c34bSSandrine Bailleux  * Here we calculate the initial lookup level from the value of the given
518933c34bSSandrine Bailleux  * virtual address space size. For a 4 KB page size,
528933c34bSSandrine Bailleux  * - level 1 supports virtual address spaces of widths 32 to 31 bits;
538933c34bSSandrine Bailleux  * - level 2 from 30 to 25.
548933c34bSSandrine Bailleux  *
558933c34bSSandrine Bailleux  * Wider or narrower address spaces are not supported. As a result, level 3
568933c34bSSandrine Bailleux  * cannot be used as the initial lookup level with 4 KB granularity.
578933c34bSSandrine Bailleux  * See the ARMv8-A Architecture Reference Manual (DDI 0487A.j) for more
588933c34bSSandrine Bailleux  * information, Section G4.6.5
598933c34bSSandrine Bailleux  *
608933c34bSSandrine Bailleux  * For example, for a 31-bit address space (i.e. virt_addr_space_size ==
618933c34bSSandrine Bailleux  * 1 << 31), TTBCR.TxSZ will be programmed to (32 - 31) = 1. According to Table
628933c34bSSandrine Bailleux  * G4-5 in the ARM ARM, the initial lookup level for an address space like that
638933c34bSSandrine Bailleux  * is 1.
648933c34bSSandrine Bailleux  *
658933c34bSSandrine Bailleux  * Note that this macro assumes that the given virtual address space size is
66cedfa04bSSathees Balya  * valid.
678933c34bSSandrine Bailleux  */
68e7b9886cSAntonio Nino Diaz #define GET_XLAT_TABLE_LEVEL_BASE(_virt_addr_space_sz)			\
69e7b9886cSAntonio Nino Diaz 	(((_virt_addr_space_sz) > (ULL(1) << L1_XLAT_ADDRESS_SHIFT)) ?	\
70e7b9886cSAntonio Nino Diaz 	 U(1) : U(2))
718933c34bSSandrine Bailleux 
72e7b9886cSAntonio Nino Diaz #endif /* XLAT_TABLES_AARCH32_H */
73