18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) 2012 ARM Ltd.
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci#ifndef __ASM_PGTABLE_HWDEF_H
68c2ecf20Sopenharmony_ci#define __ASM_PGTABLE_HWDEF_H
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#include <asm/memory.h>
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci/*
118c2ecf20Sopenharmony_ci * Number of page-table levels required to address 'va_bits' wide
128c2ecf20Sopenharmony_ci * address, without section mapping. We resolve the top (va_bits - PAGE_SHIFT)
138c2ecf20Sopenharmony_ci * bits with (PAGE_SHIFT - 3) bits at each page table level. Hence:
148c2ecf20Sopenharmony_ci *
158c2ecf20Sopenharmony_ci *  levels = DIV_ROUND_UP((va_bits - PAGE_SHIFT), (PAGE_SHIFT - 3))
168c2ecf20Sopenharmony_ci *
178c2ecf20Sopenharmony_ci * where DIV_ROUND_UP(n, d) => (((n) + (d) - 1) / (d))
188c2ecf20Sopenharmony_ci *
198c2ecf20Sopenharmony_ci * We cannot include linux/kernel.h which defines DIV_ROUND_UP here
208c2ecf20Sopenharmony_ci * due to build issues. So we open code DIV_ROUND_UP here:
218c2ecf20Sopenharmony_ci *
228c2ecf20Sopenharmony_ci *	((((va_bits) - PAGE_SHIFT) + (PAGE_SHIFT - 3) - 1) / (PAGE_SHIFT - 3))
238c2ecf20Sopenharmony_ci *
248c2ecf20Sopenharmony_ci * which gets simplified as :
258c2ecf20Sopenharmony_ci */
268c2ecf20Sopenharmony_ci#define ARM64_HW_PGTABLE_LEVELS(va_bits) (((va_bits) - 4) / (PAGE_SHIFT - 3))
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci/*
298c2ecf20Sopenharmony_ci * Size mapped by an entry at level n ( 0 <= n <= 3)
308c2ecf20Sopenharmony_ci * We map (PAGE_SHIFT - 3) at all translation levels and PAGE_SHIFT bits
318c2ecf20Sopenharmony_ci * in the final page. The maximum number of translation levels supported by
328c2ecf20Sopenharmony_ci * the architecture is 4. Hence, starting at level n, we have further
338c2ecf20Sopenharmony_ci * ((4 - n) - 1) levels of translation excluding the offset within the page.
348c2ecf20Sopenharmony_ci * So, the total number of bits mapped by an entry at level n is :
358c2ecf20Sopenharmony_ci *
368c2ecf20Sopenharmony_ci *  ((4 - n) - 1) * (PAGE_SHIFT - 3) + PAGE_SHIFT
378c2ecf20Sopenharmony_ci *
388c2ecf20Sopenharmony_ci * Rearranging it a bit we get :
398c2ecf20Sopenharmony_ci *   (4 - n) * (PAGE_SHIFT - 3) + 3
408c2ecf20Sopenharmony_ci */
418c2ecf20Sopenharmony_ci#define ARM64_HW_PGTABLE_LEVEL_SHIFT(n)	((PAGE_SHIFT - 3) * (4 - (n)) + 3)
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci#define PTRS_PER_PTE		(1 << (PAGE_SHIFT - 3))
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci/*
468c2ecf20Sopenharmony_ci * PMD_SHIFT determines the size a level 2 page table entry can map.
478c2ecf20Sopenharmony_ci */
488c2ecf20Sopenharmony_ci#if CONFIG_PGTABLE_LEVELS > 2
498c2ecf20Sopenharmony_ci#define PMD_SHIFT		ARM64_HW_PGTABLE_LEVEL_SHIFT(2)
508c2ecf20Sopenharmony_ci#define PMD_SIZE		(_AC(1, UL) << PMD_SHIFT)
518c2ecf20Sopenharmony_ci#define PMD_MASK		(~(PMD_SIZE-1))
528c2ecf20Sopenharmony_ci#define PTRS_PER_PMD		PTRS_PER_PTE
538c2ecf20Sopenharmony_ci#endif
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci/*
568c2ecf20Sopenharmony_ci * PUD_SHIFT determines the size a level 1 page table entry can map.
578c2ecf20Sopenharmony_ci */
588c2ecf20Sopenharmony_ci#if CONFIG_PGTABLE_LEVELS > 3
598c2ecf20Sopenharmony_ci#define PUD_SHIFT		ARM64_HW_PGTABLE_LEVEL_SHIFT(1)
608c2ecf20Sopenharmony_ci#define PUD_SIZE		(_AC(1, UL) << PUD_SHIFT)
618c2ecf20Sopenharmony_ci#define PUD_MASK		(~(PUD_SIZE-1))
628c2ecf20Sopenharmony_ci#define PTRS_PER_PUD		PTRS_PER_PTE
638c2ecf20Sopenharmony_ci#endif
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci/*
668c2ecf20Sopenharmony_ci * PGDIR_SHIFT determines the size a top-level page table entry can map
678c2ecf20Sopenharmony_ci * (depending on the configuration, this level can be 0, 1 or 2).
688c2ecf20Sopenharmony_ci */
698c2ecf20Sopenharmony_ci#define PGDIR_SHIFT		ARM64_HW_PGTABLE_LEVEL_SHIFT(4 - CONFIG_PGTABLE_LEVELS)
708c2ecf20Sopenharmony_ci#define PGDIR_SIZE		(_AC(1, UL) << PGDIR_SHIFT)
718c2ecf20Sopenharmony_ci#define PGDIR_MASK		(~(PGDIR_SIZE-1))
728c2ecf20Sopenharmony_ci#define PTRS_PER_PGD		(1 << (VA_BITS - PGDIR_SHIFT))
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci/*
758c2ecf20Sopenharmony_ci * Section address mask and size definitions.
768c2ecf20Sopenharmony_ci */
778c2ecf20Sopenharmony_ci#define SECTION_SHIFT		PMD_SHIFT
788c2ecf20Sopenharmony_ci#define SECTION_SIZE		(_AC(1, UL) << SECTION_SHIFT)
798c2ecf20Sopenharmony_ci#define SECTION_MASK		(~(SECTION_SIZE-1))
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci/*
828c2ecf20Sopenharmony_ci * Contiguous page definitions.
838c2ecf20Sopenharmony_ci */
848c2ecf20Sopenharmony_ci#define CONT_PTE_SHIFT		(CONFIG_ARM64_CONT_PTE_SHIFT + PAGE_SHIFT)
858c2ecf20Sopenharmony_ci#define CONT_PTES		(1 << (CONT_PTE_SHIFT - PAGE_SHIFT))
868c2ecf20Sopenharmony_ci#define CONT_PTE_SIZE		(CONT_PTES * PAGE_SIZE)
878c2ecf20Sopenharmony_ci#define CONT_PTE_MASK		(~(CONT_PTE_SIZE - 1))
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci#define CONT_PMD_SHIFT		(CONFIG_ARM64_CONT_PMD_SHIFT + PMD_SHIFT)
908c2ecf20Sopenharmony_ci#define CONT_PMDS		(1 << (CONT_PMD_SHIFT - PMD_SHIFT))
918c2ecf20Sopenharmony_ci#define CONT_PMD_SIZE		(CONT_PMDS * PMD_SIZE)
928c2ecf20Sopenharmony_ci#define CONT_PMD_MASK		(~(CONT_PMD_SIZE - 1))
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci/*
958c2ecf20Sopenharmony_ci * Hardware page table definitions.
968c2ecf20Sopenharmony_ci *
978c2ecf20Sopenharmony_ci * Level 1 descriptor (PUD).
988c2ecf20Sopenharmony_ci */
998c2ecf20Sopenharmony_ci#define PUD_TYPE_TABLE		(_AT(pudval_t, 3) << 0)
1008c2ecf20Sopenharmony_ci#define PUD_TABLE_BIT		(_AT(pudval_t, 1) << 1)
1018c2ecf20Sopenharmony_ci#define PUD_TYPE_MASK		(_AT(pudval_t, 3) << 0)
1028c2ecf20Sopenharmony_ci#define PUD_TYPE_SECT		(_AT(pudval_t, 1) << 0)
1038c2ecf20Sopenharmony_ci#define PUD_SECT_RDONLY		(_AT(pudval_t, 1) << 7)		/* AP[2] */
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci/*
1068c2ecf20Sopenharmony_ci * Level 2 descriptor (PMD).
1078c2ecf20Sopenharmony_ci */
1088c2ecf20Sopenharmony_ci#define PMD_TYPE_MASK		(_AT(pmdval_t, 3) << 0)
1098c2ecf20Sopenharmony_ci#define PMD_TYPE_TABLE		(_AT(pmdval_t, 3) << 0)
1108c2ecf20Sopenharmony_ci#define PMD_TYPE_SECT		(_AT(pmdval_t, 1) << 0)
1118c2ecf20Sopenharmony_ci#define PMD_TABLE_BIT		(_AT(pmdval_t, 1) << 1)
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci/*
1148c2ecf20Sopenharmony_ci * Section
1158c2ecf20Sopenharmony_ci */
1168c2ecf20Sopenharmony_ci#define PMD_SECT_VALID		(_AT(pmdval_t, 1) << 0)
1178c2ecf20Sopenharmony_ci#define PMD_SECT_USER		(_AT(pmdval_t, 1) << 6)		/* AP[1] */
1188c2ecf20Sopenharmony_ci#define PMD_SECT_RDONLY		(_AT(pmdval_t, 1) << 7)		/* AP[2] */
1198c2ecf20Sopenharmony_ci#define PMD_SECT_S		(_AT(pmdval_t, 3) << 8)
1208c2ecf20Sopenharmony_ci#define PMD_SECT_AF		(_AT(pmdval_t, 1) << 10)
1218c2ecf20Sopenharmony_ci#define PMD_SECT_NG		(_AT(pmdval_t, 1) << 11)
1228c2ecf20Sopenharmony_ci#define PMD_SECT_CONT		(_AT(pmdval_t, 1) << 52)
1238c2ecf20Sopenharmony_ci#define PMD_SECT_PXN		(_AT(pmdval_t, 1) << 53)
1248c2ecf20Sopenharmony_ci#define PMD_SECT_UXN		(_AT(pmdval_t, 1) << 54)
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci/*
1278c2ecf20Sopenharmony_ci * AttrIndx[2:0] encoding (mapping attributes defined in the MAIR* registers).
1288c2ecf20Sopenharmony_ci */
1298c2ecf20Sopenharmony_ci#define PMD_ATTRINDX(t)		(_AT(pmdval_t, (t)) << 2)
1308c2ecf20Sopenharmony_ci#define PMD_ATTRINDX_MASK	(_AT(pmdval_t, 7) << 2)
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ci/*
1338c2ecf20Sopenharmony_ci * Level 3 descriptor (PTE).
1348c2ecf20Sopenharmony_ci */
1358c2ecf20Sopenharmony_ci#define PTE_VALID		(_AT(pteval_t, 1) << 0)
1368c2ecf20Sopenharmony_ci#define PTE_TYPE_MASK		(_AT(pteval_t, 3) << 0)
1378c2ecf20Sopenharmony_ci#define PTE_TYPE_PAGE		(_AT(pteval_t, 3) << 0)
1388c2ecf20Sopenharmony_ci#define PTE_TABLE_BIT		(_AT(pteval_t, 1) << 1)
1398c2ecf20Sopenharmony_ci#define PTE_USER		(_AT(pteval_t, 1) << 6)		/* AP[1] */
1408c2ecf20Sopenharmony_ci#define PTE_RDONLY		(_AT(pteval_t, 1) << 7)		/* AP[2] */
1418c2ecf20Sopenharmony_ci#define PTE_SHARED		(_AT(pteval_t, 3) << 8)		/* SH[1:0], inner shareable */
1428c2ecf20Sopenharmony_ci#define PTE_AF			(_AT(pteval_t, 1) << 10)	/* Access Flag */
1438c2ecf20Sopenharmony_ci#define PTE_NG			(_AT(pteval_t, 1) << 11)	/* nG */
1448c2ecf20Sopenharmony_ci#define PTE_GP			(_AT(pteval_t, 1) << 50)	/* BTI guarded */
1458c2ecf20Sopenharmony_ci#define PTE_DBM			(_AT(pteval_t, 1) << 51)	/* Dirty Bit Management */
1468c2ecf20Sopenharmony_ci#define PTE_CONT		(_AT(pteval_t, 1) << 52)	/* Contiguous range */
1478c2ecf20Sopenharmony_ci#define PTE_PXN			(_AT(pteval_t, 1) << 53)	/* Privileged XN */
1488c2ecf20Sopenharmony_ci#define PTE_UXN			(_AT(pteval_t, 1) << 54)	/* User XN */
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci#define PTE_ADDR_LOW		(((_AT(pteval_t, 1) << (48 - PAGE_SHIFT)) - 1) << PAGE_SHIFT)
1518c2ecf20Sopenharmony_ci#ifdef CONFIG_ARM64_PA_BITS_52
1528c2ecf20Sopenharmony_ci#define PTE_ADDR_HIGH		(_AT(pteval_t, 0xf) << 12)
1538c2ecf20Sopenharmony_ci#define PTE_ADDR_MASK		(PTE_ADDR_LOW | PTE_ADDR_HIGH)
1548c2ecf20Sopenharmony_ci#else
1558c2ecf20Sopenharmony_ci#define PTE_ADDR_MASK		PTE_ADDR_LOW
1568c2ecf20Sopenharmony_ci#endif
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ci/*
1598c2ecf20Sopenharmony_ci * AttrIndx[2:0] encoding (mapping attributes defined in the MAIR* registers).
1608c2ecf20Sopenharmony_ci */
1618c2ecf20Sopenharmony_ci#define PTE_ATTRINDX(t)		(_AT(pteval_t, (t)) << 2)
1628c2ecf20Sopenharmony_ci#define PTE_ATTRINDX_MASK	(_AT(pteval_t, 7) << 2)
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci/*
1658c2ecf20Sopenharmony_ci * Memory Attribute override for Stage-2 (MemAttr[3:0])
1668c2ecf20Sopenharmony_ci */
1678c2ecf20Sopenharmony_ci#define PTE_S2_MEMATTR(t)	(_AT(pteval_t, (t)) << 2)
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_ci/*
1708c2ecf20Sopenharmony_ci * Highest possible physical address supported.
1718c2ecf20Sopenharmony_ci */
1728c2ecf20Sopenharmony_ci#define PHYS_MASK_SHIFT		(CONFIG_ARM64_PA_BITS)
1738c2ecf20Sopenharmony_ci#define PHYS_MASK		((UL(1) << PHYS_MASK_SHIFT) - 1)
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_ci#define TTBR_CNP_BIT		(UL(1) << 0)
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_ci/*
1788c2ecf20Sopenharmony_ci * TCR flags.
1798c2ecf20Sopenharmony_ci */
1808c2ecf20Sopenharmony_ci#define TCR_T0SZ_OFFSET		0
1818c2ecf20Sopenharmony_ci#define TCR_T1SZ_OFFSET		16
1828c2ecf20Sopenharmony_ci#define TCR_T0SZ(x)		((UL(64) - (x)) << TCR_T0SZ_OFFSET)
1838c2ecf20Sopenharmony_ci#define TCR_T1SZ(x)		((UL(64) - (x)) << TCR_T1SZ_OFFSET)
1848c2ecf20Sopenharmony_ci#define TCR_TxSZ(x)		(TCR_T0SZ(x) | TCR_T1SZ(x))
1858c2ecf20Sopenharmony_ci#define TCR_TxSZ_WIDTH		6
1868c2ecf20Sopenharmony_ci#define TCR_T0SZ_MASK		(((UL(1) << TCR_TxSZ_WIDTH) - 1) << TCR_T0SZ_OFFSET)
1878c2ecf20Sopenharmony_ci#define TCR_T1SZ_MASK		(((UL(1) << TCR_TxSZ_WIDTH) - 1) << TCR_T1SZ_OFFSET)
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_ci#define TCR_EPD0_SHIFT		7
1908c2ecf20Sopenharmony_ci#define TCR_EPD0_MASK		(UL(1) << TCR_EPD0_SHIFT)
1918c2ecf20Sopenharmony_ci#define TCR_IRGN0_SHIFT		8
1928c2ecf20Sopenharmony_ci#define TCR_IRGN0_MASK		(UL(3) << TCR_IRGN0_SHIFT)
1938c2ecf20Sopenharmony_ci#define TCR_IRGN0_NC		(UL(0) << TCR_IRGN0_SHIFT)
1948c2ecf20Sopenharmony_ci#define TCR_IRGN0_WBWA		(UL(1) << TCR_IRGN0_SHIFT)
1958c2ecf20Sopenharmony_ci#define TCR_IRGN0_WT		(UL(2) << TCR_IRGN0_SHIFT)
1968c2ecf20Sopenharmony_ci#define TCR_IRGN0_WBnWA		(UL(3) << TCR_IRGN0_SHIFT)
1978c2ecf20Sopenharmony_ci
1988c2ecf20Sopenharmony_ci#define TCR_EPD1_SHIFT		23
1998c2ecf20Sopenharmony_ci#define TCR_EPD1_MASK		(UL(1) << TCR_EPD1_SHIFT)
2008c2ecf20Sopenharmony_ci#define TCR_IRGN1_SHIFT		24
2018c2ecf20Sopenharmony_ci#define TCR_IRGN1_MASK		(UL(3) << TCR_IRGN1_SHIFT)
2028c2ecf20Sopenharmony_ci#define TCR_IRGN1_NC		(UL(0) << TCR_IRGN1_SHIFT)
2038c2ecf20Sopenharmony_ci#define TCR_IRGN1_WBWA		(UL(1) << TCR_IRGN1_SHIFT)
2048c2ecf20Sopenharmony_ci#define TCR_IRGN1_WT		(UL(2) << TCR_IRGN1_SHIFT)
2058c2ecf20Sopenharmony_ci#define TCR_IRGN1_WBnWA		(UL(3) << TCR_IRGN1_SHIFT)
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_ci#define TCR_IRGN_NC		(TCR_IRGN0_NC | TCR_IRGN1_NC)
2088c2ecf20Sopenharmony_ci#define TCR_IRGN_WBWA		(TCR_IRGN0_WBWA | TCR_IRGN1_WBWA)
2098c2ecf20Sopenharmony_ci#define TCR_IRGN_WT		(TCR_IRGN0_WT | TCR_IRGN1_WT)
2108c2ecf20Sopenharmony_ci#define TCR_IRGN_WBnWA		(TCR_IRGN0_WBnWA | TCR_IRGN1_WBnWA)
2118c2ecf20Sopenharmony_ci#define TCR_IRGN_MASK		(TCR_IRGN0_MASK | TCR_IRGN1_MASK)
2128c2ecf20Sopenharmony_ci
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_ci#define TCR_ORGN0_SHIFT		10
2158c2ecf20Sopenharmony_ci#define TCR_ORGN0_MASK		(UL(3) << TCR_ORGN0_SHIFT)
2168c2ecf20Sopenharmony_ci#define TCR_ORGN0_NC		(UL(0) << TCR_ORGN0_SHIFT)
2178c2ecf20Sopenharmony_ci#define TCR_ORGN0_WBWA		(UL(1) << TCR_ORGN0_SHIFT)
2188c2ecf20Sopenharmony_ci#define TCR_ORGN0_WT		(UL(2) << TCR_ORGN0_SHIFT)
2198c2ecf20Sopenharmony_ci#define TCR_ORGN0_WBnWA		(UL(3) << TCR_ORGN0_SHIFT)
2208c2ecf20Sopenharmony_ci
2218c2ecf20Sopenharmony_ci#define TCR_ORGN1_SHIFT		26
2228c2ecf20Sopenharmony_ci#define TCR_ORGN1_MASK		(UL(3) << TCR_ORGN1_SHIFT)
2238c2ecf20Sopenharmony_ci#define TCR_ORGN1_NC		(UL(0) << TCR_ORGN1_SHIFT)
2248c2ecf20Sopenharmony_ci#define TCR_ORGN1_WBWA		(UL(1) << TCR_ORGN1_SHIFT)
2258c2ecf20Sopenharmony_ci#define TCR_ORGN1_WT		(UL(2) << TCR_ORGN1_SHIFT)
2268c2ecf20Sopenharmony_ci#define TCR_ORGN1_WBnWA		(UL(3) << TCR_ORGN1_SHIFT)
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_ci#define TCR_ORGN_NC		(TCR_ORGN0_NC | TCR_ORGN1_NC)
2298c2ecf20Sopenharmony_ci#define TCR_ORGN_WBWA		(TCR_ORGN0_WBWA | TCR_ORGN1_WBWA)
2308c2ecf20Sopenharmony_ci#define TCR_ORGN_WT		(TCR_ORGN0_WT | TCR_ORGN1_WT)
2318c2ecf20Sopenharmony_ci#define TCR_ORGN_WBnWA		(TCR_ORGN0_WBnWA | TCR_ORGN1_WBnWA)
2328c2ecf20Sopenharmony_ci#define TCR_ORGN_MASK		(TCR_ORGN0_MASK | TCR_ORGN1_MASK)
2338c2ecf20Sopenharmony_ci
2348c2ecf20Sopenharmony_ci#define TCR_SH0_SHIFT		12
2358c2ecf20Sopenharmony_ci#define TCR_SH0_MASK		(UL(3) << TCR_SH0_SHIFT)
2368c2ecf20Sopenharmony_ci#define TCR_SH0_INNER		(UL(3) << TCR_SH0_SHIFT)
2378c2ecf20Sopenharmony_ci
2388c2ecf20Sopenharmony_ci#define TCR_SH1_SHIFT		28
2398c2ecf20Sopenharmony_ci#define TCR_SH1_MASK		(UL(3) << TCR_SH1_SHIFT)
2408c2ecf20Sopenharmony_ci#define TCR_SH1_INNER		(UL(3) << TCR_SH1_SHIFT)
2418c2ecf20Sopenharmony_ci#define TCR_SHARED		(TCR_SH0_INNER | TCR_SH1_INNER)
2428c2ecf20Sopenharmony_ci
2438c2ecf20Sopenharmony_ci#define TCR_TG0_SHIFT		14
2448c2ecf20Sopenharmony_ci#define TCR_TG0_MASK		(UL(3) << TCR_TG0_SHIFT)
2458c2ecf20Sopenharmony_ci#define TCR_TG0_4K		(UL(0) << TCR_TG0_SHIFT)
2468c2ecf20Sopenharmony_ci#define TCR_TG0_64K		(UL(1) << TCR_TG0_SHIFT)
2478c2ecf20Sopenharmony_ci#define TCR_TG0_16K		(UL(2) << TCR_TG0_SHIFT)
2488c2ecf20Sopenharmony_ci
2498c2ecf20Sopenharmony_ci#define TCR_TG1_SHIFT		30
2508c2ecf20Sopenharmony_ci#define TCR_TG1_MASK		(UL(3) << TCR_TG1_SHIFT)
2518c2ecf20Sopenharmony_ci#define TCR_TG1_16K		(UL(1) << TCR_TG1_SHIFT)
2528c2ecf20Sopenharmony_ci#define TCR_TG1_4K		(UL(2) << TCR_TG1_SHIFT)
2538c2ecf20Sopenharmony_ci#define TCR_TG1_64K		(UL(3) << TCR_TG1_SHIFT)
2548c2ecf20Sopenharmony_ci
2558c2ecf20Sopenharmony_ci#define TCR_IPS_SHIFT		32
2568c2ecf20Sopenharmony_ci#define TCR_IPS_MASK		(UL(7) << TCR_IPS_SHIFT)
2578c2ecf20Sopenharmony_ci#define TCR_A1			(UL(1) << 22)
2588c2ecf20Sopenharmony_ci#define TCR_ASID16		(UL(1) << 36)
2598c2ecf20Sopenharmony_ci#define TCR_TBI0		(UL(1) << 37)
2608c2ecf20Sopenharmony_ci#define TCR_TBI1		(UL(1) << 38)
2618c2ecf20Sopenharmony_ci#define TCR_HA			(UL(1) << 39)
2628c2ecf20Sopenharmony_ci#define TCR_HD			(UL(1) << 40)
2638c2ecf20Sopenharmony_ci#define TCR_NFD0		(UL(1) << 53)
2648c2ecf20Sopenharmony_ci#define TCR_NFD1		(UL(1) << 54)
2658c2ecf20Sopenharmony_ci#define TCR_E0PD0		(UL(1) << 55)
2668c2ecf20Sopenharmony_ci#define TCR_E0PD1		(UL(1) << 56)
2678c2ecf20Sopenharmony_ci
2688c2ecf20Sopenharmony_ci/*
2698c2ecf20Sopenharmony_ci * TTBR.
2708c2ecf20Sopenharmony_ci */
2718c2ecf20Sopenharmony_ci#ifdef CONFIG_ARM64_PA_BITS_52
2728c2ecf20Sopenharmony_ci/*
2738c2ecf20Sopenharmony_ci * This should be GENMASK_ULL(47, 2).
2748c2ecf20Sopenharmony_ci * TTBR_ELx[1] is RES0 in this configuration.
2758c2ecf20Sopenharmony_ci */
2768c2ecf20Sopenharmony_ci#define TTBR_BADDR_MASK_52	(((UL(1) << 46) - 1) << 2)
2778c2ecf20Sopenharmony_ci#endif
2788c2ecf20Sopenharmony_ci
2798c2ecf20Sopenharmony_ci#ifdef CONFIG_ARM64_VA_BITS_52
2808c2ecf20Sopenharmony_ci/* Must be at least 64-byte aligned to prevent corruption of the TTBR */
2818c2ecf20Sopenharmony_ci#define TTBR1_BADDR_4852_OFFSET	(((UL(1) << (52 - PGDIR_SHIFT)) - \
2828c2ecf20Sopenharmony_ci				 (UL(1) << (48 - PGDIR_SHIFT))) * 8)
2838c2ecf20Sopenharmony_ci#endif
2848c2ecf20Sopenharmony_ci
2858c2ecf20Sopenharmony_ci#endif
286