162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (C) 2012 ARM Ltd.
462306a36Sopenharmony_ci */
562306a36Sopenharmony_ci#ifndef __ASM_PGTABLE_HWDEF_H
662306a36Sopenharmony_ci#define __ASM_PGTABLE_HWDEF_H
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#include <asm/memory.h>
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci/*
1162306a36Sopenharmony_ci * Number of page-table levels required to address 'va_bits' wide
1262306a36Sopenharmony_ci * address, without section mapping. We resolve the top (va_bits - PAGE_SHIFT)
1362306a36Sopenharmony_ci * bits with (PAGE_SHIFT - 3) bits at each page table level. Hence:
1462306a36Sopenharmony_ci *
1562306a36Sopenharmony_ci *  levels = DIV_ROUND_UP((va_bits - PAGE_SHIFT), (PAGE_SHIFT - 3))
1662306a36Sopenharmony_ci *
1762306a36Sopenharmony_ci * where DIV_ROUND_UP(n, d) => (((n) + (d) - 1) / (d))
1862306a36Sopenharmony_ci *
1962306a36Sopenharmony_ci * We cannot include linux/kernel.h which defines DIV_ROUND_UP here
2062306a36Sopenharmony_ci * due to build issues. So we open code DIV_ROUND_UP here:
2162306a36Sopenharmony_ci *
2262306a36Sopenharmony_ci *	((((va_bits) - PAGE_SHIFT) + (PAGE_SHIFT - 3) - 1) / (PAGE_SHIFT - 3))
2362306a36Sopenharmony_ci *
2462306a36Sopenharmony_ci * which gets simplified as :
2562306a36Sopenharmony_ci */
2662306a36Sopenharmony_ci#define ARM64_HW_PGTABLE_LEVELS(va_bits) (((va_bits) - 4) / (PAGE_SHIFT - 3))
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci/*
2962306a36Sopenharmony_ci * Size mapped by an entry at level n ( 0 <= n <= 3)
3062306a36Sopenharmony_ci * We map (PAGE_SHIFT - 3) at all translation levels and PAGE_SHIFT bits
3162306a36Sopenharmony_ci * in the final page. The maximum number of translation levels supported by
3262306a36Sopenharmony_ci * the architecture is 4. Hence, starting at level n, we have further
3362306a36Sopenharmony_ci * ((4 - n) - 1) levels of translation excluding the offset within the page.
3462306a36Sopenharmony_ci * So, the total number of bits mapped by an entry at level n is :
3562306a36Sopenharmony_ci *
3662306a36Sopenharmony_ci *  ((4 - n) - 1) * (PAGE_SHIFT - 3) + PAGE_SHIFT
3762306a36Sopenharmony_ci *
3862306a36Sopenharmony_ci * Rearranging it a bit we get :
3962306a36Sopenharmony_ci *   (4 - n) * (PAGE_SHIFT - 3) + 3
4062306a36Sopenharmony_ci */
4162306a36Sopenharmony_ci#define ARM64_HW_PGTABLE_LEVEL_SHIFT(n)	((PAGE_SHIFT - 3) * (4 - (n)) + 3)
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ci#define PTRS_PER_PTE		(1 << (PAGE_SHIFT - 3))
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_ci/*
4662306a36Sopenharmony_ci * PMD_SHIFT determines the size a level 2 page table entry can map.
4762306a36Sopenharmony_ci */
4862306a36Sopenharmony_ci#if CONFIG_PGTABLE_LEVELS > 2
4962306a36Sopenharmony_ci#define PMD_SHIFT		ARM64_HW_PGTABLE_LEVEL_SHIFT(2)
5062306a36Sopenharmony_ci#define PMD_SIZE		(_AC(1, UL) << PMD_SHIFT)
5162306a36Sopenharmony_ci#define PMD_MASK		(~(PMD_SIZE-1))
5262306a36Sopenharmony_ci#define PTRS_PER_PMD		(1 << (PAGE_SHIFT - 3))
5362306a36Sopenharmony_ci#endif
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ci/*
5662306a36Sopenharmony_ci * PUD_SHIFT determines the size a level 1 page table entry can map.
5762306a36Sopenharmony_ci */
5862306a36Sopenharmony_ci#if CONFIG_PGTABLE_LEVELS > 3
5962306a36Sopenharmony_ci#define PUD_SHIFT		ARM64_HW_PGTABLE_LEVEL_SHIFT(1)
6062306a36Sopenharmony_ci#define PUD_SIZE		(_AC(1, UL) << PUD_SHIFT)
6162306a36Sopenharmony_ci#define PUD_MASK		(~(PUD_SIZE-1))
6262306a36Sopenharmony_ci#define PTRS_PER_PUD		(1 << (PAGE_SHIFT - 3))
6362306a36Sopenharmony_ci#endif
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ci/*
6662306a36Sopenharmony_ci * PGDIR_SHIFT determines the size a top-level page table entry can map
6762306a36Sopenharmony_ci * (depending on the configuration, this level can be 0, 1 or 2).
6862306a36Sopenharmony_ci */
6962306a36Sopenharmony_ci#define PGDIR_SHIFT		ARM64_HW_PGTABLE_LEVEL_SHIFT(4 - CONFIG_PGTABLE_LEVELS)
7062306a36Sopenharmony_ci#define PGDIR_SIZE		(_AC(1, UL) << PGDIR_SHIFT)
7162306a36Sopenharmony_ci#define PGDIR_MASK		(~(PGDIR_SIZE-1))
7262306a36Sopenharmony_ci#define PTRS_PER_PGD		(1 << (VA_BITS - PGDIR_SHIFT))
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ci/*
7562306a36Sopenharmony_ci * Contiguous page definitions.
7662306a36Sopenharmony_ci */
7762306a36Sopenharmony_ci#define CONT_PTE_SHIFT		(CONFIG_ARM64_CONT_PTE_SHIFT + PAGE_SHIFT)
7862306a36Sopenharmony_ci#define CONT_PTES		(1 << (CONT_PTE_SHIFT - PAGE_SHIFT))
7962306a36Sopenharmony_ci#define CONT_PTE_SIZE		(CONT_PTES * PAGE_SIZE)
8062306a36Sopenharmony_ci#define CONT_PTE_MASK		(~(CONT_PTE_SIZE - 1))
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_ci#define CONT_PMD_SHIFT		(CONFIG_ARM64_CONT_PMD_SHIFT + PMD_SHIFT)
8362306a36Sopenharmony_ci#define CONT_PMDS		(1 << (CONT_PMD_SHIFT - PMD_SHIFT))
8462306a36Sopenharmony_ci#define CONT_PMD_SIZE		(CONT_PMDS * PMD_SIZE)
8562306a36Sopenharmony_ci#define CONT_PMD_MASK		(~(CONT_PMD_SIZE - 1))
8662306a36Sopenharmony_ci
8762306a36Sopenharmony_ci/*
8862306a36Sopenharmony_ci * Hardware page table definitions.
8962306a36Sopenharmony_ci *
9062306a36Sopenharmony_ci * Level 0 descriptor (P4D).
9162306a36Sopenharmony_ci */
9262306a36Sopenharmony_ci#define P4D_TYPE_TABLE		(_AT(p4dval_t, 3) << 0)
9362306a36Sopenharmony_ci#define P4D_TABLE_BIT		(_AT(p4dval_t, 1) << 1)
9462306a36Sopenharmony_ci#define P4D_TYPE_MASK		(_AT(p4dval_t, 3) << 0)
9562306a36Sopenharmony_ci#define P4D_TYPE_SECT		(_AT(p4dval_t, 1) << 0)
9662306a36Sopenharmony_ci#define P4D_SECT_RDONLY		(_AT(p4dval_t, 1) << 7)		/* AP[2] */
9762306a36Sopenharmony_ci#define P4D_TABLE_PXN		(_AT(p4dval_t, 1) << 59)
9862306a36Sopenharmony_ci#define P4D_TABLE_UXN		(_AT(p4dval_t, 1) << 60)
9962306a36Sopenharmony_ci
10062306a36Sopenharmony_ci/*
10162306a36Sopenharmony_ci * Level 1 descriptor (PUD).
10262306a36Sopenharmony_ci */
10362306a36Sopenharmony_ci#define PUD_TYPE_TABLE		(_AT(pudval_t, 3) << 0)
10462306a36Sopenharmony_ci#define PUD_TABLE_BIT		(_AT(pudval_t, 1) << 1)
10562306a36Sopenharmony_ci#define PUD_TYPE_MASK		(_AT(pudval_t, 3) << 0)
10662306a36Sopenharmony_ci#define PUD_TYPE_SECT		(_AT(pudval_t, 1) << 0)
10762306a36Sopenharmony_ci#define PUD_SECT_RDONLY		(_AT(pudval_t, 1) << 7)		/* AP[2] */
10862306a36Sopenharmony_ci#define PUD_TABLE_PXN		(_AT(pudval_t, 1) << 59)
10962306a36Sopenharmony_ci#define PUD_TABLE_UXN		(_AT(pudval_t, 1) << 60)
11062306a36Sopenharmony_ci
11162306a36Sopenharmony_ci/*
11262306a36Sopenharmony_ci * Level 2 descriptor (PMD).
11362306a36Sopenharmony_ci */
11462306a36Sopenharmony_ci#define PMD_TYPE_MASK		(_AT(pmdval_t, 3) << 0)
11562306a36Sopenharmony_ci#define PMD_TYPE_TABLE		(_AT(pmdval_t, 3) << 0)
11662306a36Sopenharmony_ci#define PMD_TYPE_SECT		(_AT(pmdval_t, 1) << 0)
11762306a36Sopenharmony_ci#define PMD_TABLE_BIT		(_AT(pmdval_t, 1) << 1)
11862306a36Sopenharmony_ci
11962306a36Sopenharmony_ci/*
12062306a36Sopenharmony_ci * Section
12162306a36Sopenharmony_ci */
12262306a36Sopenharmony_ci#define PMD_SECT_VALID		(_AT(pmdval_t, 1) << 0)
12362306a36Sopenharmony_ci#define PMD_SECT_USER		(_AT(pmdval_t, 1) << 6)		/* AP[1] */
12462306a36Sopenharmony_ci#define PMD_SECT_RDONLY		(_AT(pmdval_t, 1) << 7)		/* AP[2] */
12562306a36Sopenharmony_ci#define PMD_SECT_S		(_AT(pmdval_t, 3) << 8)
12662306a36Sopenharmony_ci#define PMD_SECT_AF		(_AT(pmdval_t, 1) << 10)
12762306a36Sopenharmony_ci#define PMD_SECT_NG		(_AT(pmdval_t, 1) << 11)
12862306a36Sopenharmony_ci#define PMD_SECT_CONT		(_AT(pmdval_t, 1) << 52)
12962306a36Sopenharmony_ci#define PMD_SECT_PXN		(_AT(pmdval_t, 1) << 53)
13062306a36Sopenharmony_ci#define PMD_SECT_UXN		(_AT(pmdval_t, 1) << 54)
13162306a36Sopenharmony_ci#define PMD_TABLE_PXN		(_AT(pmdval_t, 1) << 59)
13262306a36Sopenharmony_ci#define PMD_TABLE_UXN		(_AT(pmdval_t, 1) << 60)
13362306a36Sopenharmony_ci
13462306a36Sopenharmony_ci/*
13562306a36Sopenharmony_ci * AttrIndx[2:0] encoding (mapping attributes defined in the MAIR* registers).
13662306a36Sopenharmony_ci */
13762306a36Sopenharmony_ci#define PMD_ATTRINDX(t)		(_AT(pmdval_t, (t)) << 2)
13862306a36Sopenharmony_ci#define PMD_ATTRINDX_MASK	(_AT(pmdval_t, 7) << 2)
13962306a36Sopenharmony_ci
14062306a36Sopenharmony_ci/*
14162306a36Sopenharmony_ci * Level 3 descriptor (PTE).
14262306a36Sopenharmony_ci */
14362306a36Sopenharmony_ci#define PTE_VALID		(_AT(pteval_t, 1) << 0)
14462306a36Sopenharmony_ci#define PTE_TYPE_MASK		(_AT(pteval_t, 3) << 0)
14562306a36Sopenharmony_ci#define PTE_TYPE_PAGE		(_AT(pteval_t, 3) << 0)
14662306a36Sopenharmony_ci#define PTE_TABLE_BIT		(_AT(pteval_t, 1) << 1)
14762306a36Sopenharmony_ci#define PTE_USER		(_AT(pteval_t, 1) << 6)		/* AP[1] */
14862306a36Sopenharmony_ci#define PTE_RDONLY		(_AT(pteval_t, 1) << 7)		/* AP[2] */
14962306a36Sopenharmony_ci#define PTE_SHARED		(_AT(pteval_t, 3) << 8)		/* SH[1:0], inner shareable */
15062306a36Sopenharmony_ci#define PTE_AF			(_AT(pteval_t, 1) << 10)	/* Access Flag */
15162306a36Sopenharmony_ci#define PTE_NG			(_AT(pteval_t, 1) << 11)	/* nG */
15262306a36Sopenharmony_ci#define PTE_GP			(_AT(pteval_t, 1) << 50)	/* BTI guarded */
15362306a36Sopenharmony_ci#define PTE_DBM			(_AT(pteval_t, 1) << 51)	/* Dirty Bit Management */
15462306a36Sopenharmony_ci#define PTE_CONT		(_AT(pteval_t, 1) << 52)	/* Contiguous range */
15562306a36Sopenharmony_ci#define PTE_PXN			(_AT(pteval_t, 1) << 53)	/* Privileged XN */
15662306a36Sopenharmony_ci#define PTE_UXN			(_AT(pteval_t, 1) << 54)	/* User XN */
15762306a36Sopenharmony_ci
15862306a36Sopenharmony_ci#define PTE_ADDR_LOW		(((_AT(pteval_t, 1) << (48 - PAGE_SHIFT)) - 1) << PAGE_SHIFT)
15962306a36Sopenharmony_ci#ifdef CONFIG_ARM64_PA_BITS_52
16062306a36Sopenharmony_ci#define PTE_ADDR_HIGH		(_AT(pteval_t, 0xf) << 12)
16162306a36Sopenharmony_ci#define PTE_ADDR_MASK		(PTE_ADDR_LOW | PTE_ADDR_HIGH)
16262306a36Sopenharmony_ci#define PTE_ADDR_HIGH_SHIFT	36
16362306a36Sopenharmony_ci#else
16462306a36Sopenharmony_ci#define PTE_ADDR_MASK		PTE_ADDR_LOW
16562306a36Sopenharmony_ci#endif
16662306a36Sopenharmony_ci
16762306a36Sopenharmony_ci/*
16862306a36Sopenharmony_ci * AttrIndx[2:0] encoding (mapping attributes defined in the MAIR* registers).
16962306a36Sopenharmony_ci */
17062306a36Sopenharmony_ci#define PTE_ATTRINDX(t)		(_AT(pteval_t, (t)) << 2)
17162306a36Sopenharmony_ci#define PTE_ATTRINDX_MASK	(_AT(pteval_t, 7) << 2)
17262306a36Sopenharmony_ci
17362306a36Sopenharmony_ci/*
17462306a36Sopenharmony_ci * PIIndex[3:0] encoding (Permission Indirection Extension)
17562306a36Sopenharmony_ci */
17662306a36Sopenharmony_ci#define PTE_PI_IDX_0	6	/* AP[1], USER */
17762306a36Sopenharmony_ci#define PTE_PI_IDX_1	51	/* DBM */
17862306a36Sopenharmony_ci#define PTE_PI_IDX_2	53	/* PXN */
17962306a36Sopenharmony_ci#define PTE_PI_IDX_3	54	/* UXN */
18062306a36Sopenharmony_ci
18162306a36Sopenharmony_ci/*
18262306a36Sopenharmony_ci * Memory Attribute override for Stage-2 (MemAttr[3:0])
18362306a36Sopenharmony_ci */
18462306a36Sopenharmony_ci#define PTE_S2_MEMATTR(t)	(_AT(pteval_t, (t)) << 2)
18562306a36Sopenharmony_ci
18662306a36Sopenharmony_ci/*
18762306a36Sopenharmony_ci * Highest possible physical address supported.
18862306a36Sopenharmony_ci */
18962306a36Sopenharmony_ci#define PHYS_MASK_SHIFT		(CONFIG_ARM64_PA_BITS)
19062306a36Sopenharmony_ci#define PHYS_MASK		((UL(1) << PHYS_MASK_SHIFT) - 1)
19162306a36Sopenharmony_ci
19262306a36Sopenharmony_ci#define TTBR_CNP_BIT		(UL(1) << 0)
19362306a36Sopenharmony_ci
19462306a36Sopenharmony_ci/*
19562306a36Sopenharmony_ci * TCR flags.
19662306a36Sopenharmony_ci */
19762306a36Sopenharmony_ci#define TCR_T0SZ_OFFSET		0
19862306a36Sopenharmony_ci#define TCR_T1SZ_OFFSET		16
19962306a36Sopenharmony_ci#define TCR_T0SZ(x)		((UL(64) - (x)) << TCR_T0SZ_OFFSET)
20062306a36Sopenharmony_ci#define TCR_T1SZ(x)		((UL(64) - (x)) << TCR_T1SZ_OFFSET)
20162306a36Sopenharmony_ci#define TCR_TxSZ(x)		(TCR_T0SZ(x) | TCR_T1SZ(x))
20262306a36Sopenharmony_ci#define TCR_TxSZ_WIDTH		6
20362306a36Sopenharmony_ci#define TCR_T0SZ_MASK		(((UL(1) << TCR_TxSZ_WIDTH) - 1) << TCR_T0SZ_OFFSET)
20462306a36Sopenharmony_ci#define TCR_T1SZ_MASK		(((UL(1) << TCR_TxSZ_WIDTH) - 1) << TCR_T1SZ_OFFSET)
20562306a36Sopenharmony_ci
20662306a36Sopenharmony_ci#define TCR_EPD0_SHIFT		7
20762306a36Sopenharmony_ci#define TCR_EPD0_MASK		(UL(1) << TCR_EPD0_SHIFT)
20862306a36Sopenharmony_ci#define TCR_IRGN0_SHIFT		8
20962306a36Sopenharmony_ci#define TCR_IRGN0_MASK		(UL(3) << TCR_IRGN0_SHIFT)
21062306a36Sopenharmony_ci#define TCR_IRGN0_NC		(UL(0) << TCR_IRGN0_SHIFT)
21162306a36Sopenharmony_ci#define TCR_IRGN0_WBWA		(UL(1) << TCR_IRGN0_SHIFT)
21262306a36Sopenharmony_ci#define TCR_IRGN0_WT		(UL(2) << TCR_IRGN0_SHIFT)
21362306a36Sopenharmony_ci#define TCR_IRGN0_WBnWA		(UL(3) << TCR_IRGN0_SHIFT)
21462306a36Sopenharmony_ci
21562306a36Sopenharmony_ci#define TCR_EPD1_SHIFT		23
21662306a36Sopenharmony_ci#define TCR_EPD1_MASK		(UL(1) << TCR_EPD1_SHIFT)
21762306a36Sopenharmony_ci#define TCR_IRGN1_SHIFT		24
21862306a36Sopenharmony_ci#define TCR_IRGN1_MASK		(UL(3) << TCR_IRGN1_SHIFT)
21962306a36Sopenharmony_ci#define TCR_IRGN1_NC		(UL(0) << TCR_IRGN1_SHIFT)
22062306a36Sopenharmony_ci#define TCR_IRGN1_WBWA		(UL(1) << TCR_IRGN1_SHIFT)
22162306a36Sopenharmony_ci#define TCR_IRGN1_WT		(UL(2) << TCR_IRGN1_SHIFT)
22262306a36Sopenharmony_ci#define TCR_IRGN1_WBnWA		(UL(3) << TCR_IRGN1_SHIFT)
22362306a36Sopenharmony_ci
22462306a36Sopenharmony_ci#define TCR_IRGN_NC		(TCR_IRGN0_NC | TCR_IRGN1_NC)
22562306a36Sopenharmony_ci#define TCR_IRGN_WBWA		(TCR_IRGN0_WBWA | TCR_IRGN1_WBWA)
22662306a36Sopenharmony_ci#define TCR_IRGN_WT		(TCR_IRGN0_WT | TCR_IRGN1_WT)
22762306a36Sopenharmony_ci#define TCR_IRGN_WBnWA		(TCR_IRGN0_WBnWA | TCR_IRGN1_WBnWA)
22862306a36Sopenharmony_ci#define TCR_IRGN_MASK		(TCR_IRGN0_MASK | TCR_IRGN1_MASK)
22962306a36Sopenharmony_ci
23062306a36Sopenharmony_ci
23162306a36Sopenharmony_ci#define TCR_ORGN0_SHIFT		10
23262306a36Sopenharmony_ci#define TCR_ORGN0_MASK		(UL(3) << TCR_ORGN0_SHIFT)
23362306a36Sopenharmony_ci#define TCR_ORGN0_NC		(UL(0) << TCR_ORGN0_SHIFT)
23462306a36Sopenharmony_ci#define TCR_ORGN0_WBWA		(UL(1) << TCR_ORGN0_SHIFT)
23562306a36Sopenharmony_ci#define TCR_ORGN0_WT		(UL(2) << TCR_ORGN0_SHIFT)
23662306a36Sopenharmony_ci#define TCR_ORGN0_WBnWA		(UL(3) << TCR_ORGN0_SHIFT)
23762306a36Sopenharmony_ci
23862306a36Sopenharmony_ci#define TCR_ORGN1_SHIFT		26
23962306a36Sopenharmony_ci#define TCR_ORGN1_MASK		(UL(3) << TCR_ORGN1_SHIFT)
24062306a36Sopenharmony_ci#define TCR_ORGN1_NC		(UL(0) << TCR_ORGN1_SHIFT)
24162306a36Sopenharmony_ci#define TCR_ORGN1_WBWA		(UL(1) << TCR_ORGN1_SHIFT)
24262306a36Sopenharmony_ci#define TCR_ORGN1_WT		(UL(2) << TCR_ORGN1_SHIFT)
24362306a36Sopenharmony_ci#define TCR_ORGN1_WBnWA		(UL(3) << TCR_ORGN1_SHIFT)
24462306a36Sopenharmony_ci
24562306a36Sopenharmony_ci#define TCR_ORGN_NC		(TCR_ORGN0_NC | TCR_ORGN1_NC)
24662306a36Sopenharmony_ci#define TCR_ORGN_WBWA		(TCR_ORGN0_WBWA | TCR_ORGN1_WBWA)
24762306a36Sopenharmony_ci#define TCR_ORGN_WT		(TCR_ORGN0_WT | TCR_ORGN1_WT)
24862306a36Sopenharmony_ci#define TCR_ORGN_WBnWA		(TCR_ORGN0_WBnWA | TCR_ORGN1_WBnWA)
24962306a36Sopenharmony_ci#define TCR_ORGN_MASK		(TCR_ORGN0_MASK | TCR_ORGN1_MASK)
25062306a36Sopenharmony_ci
25162306a36Sopenharmony_ci#define TCR_SH0_SHIFT		12
25262306a36Sopenharmony_ci#define TCR_SH0_MASK		(UL(3) << TCR_SH0_SHIFT)
25362306a36Sopenharmony_ci#define TCR_SH0_INNER		(UL(3) << TCR_SH0_SHIFT)
25462306a36Sopenharmony_ci
25562306a36Sopenharmony_ci#define TCR_SH1_SHIFT		28
25662306a36Sopenharmony_ci#define TCR_SH1_MASK		(UL(3) << TCR_SH1_SHIFT)
25762306a36Sopenharmony_ci#define TCR_SH1_INNER		(UL(3) << TCR_SH1_SHIFT)
25862306a36Sopenharmony_ci#define TCR_SHARED		(TCR_SH0_INNER | TCR_SH1_INNER)
25962306a36Sopenharmony_ci
26062306a36Sopenharmony_ci#define TCR_TG0_SHIFT		14
26162306a36Sopenharmony_ci#define TCR_TG0_MASK		(UL(3) << TCR_TG0_SHIFT)
26262306a36Sopenharmony_ci#define TCR_TG0_4K		(UL(0) << TCR_TG0_SHIFT)
26362306a36Sopenharmony_ci#define TCR_TG0_64K		(UL(1) << TCR_TG0_SHIFT)
26462306a36Sopenharmony_ci#define TCR_TG0_16K		(UL(2) << TCR_TG0_SHIFT)
26562306a36Sopenharmony_ci
26662306a36Sopenharmony_ci#define TCR_TG1_SHIFT		30
26762306a36Sopenharmony_ci#define TCR_TG1_MASK		(UL(3) << TCR_TG1_SHIFT)
26862306a36Sopenharmony_ci#define TCR_TG1_16K		(UL(1) << TCR_TG1_SHIFT)
26962306a36Sopenharmony_ci#define TCR_TG1_4K		(UL(2) << TCR_TG1_SHIFT)
27062306a36Sopenharmony_ci#define TCR_TG1_64K		(UL(3) << TCR_TG1_SHIFT)
27162306a36Sopenharmony_ci
27262306a36Sopenharmony_ci#define TCR_IPS_SHIFT		32
27362306a36Sopenharmony_ci#define TCR_IPS_MASK		(UL(7) << TCR_IPS_SHIFT)
27462306a36Sopenharmony_ci#define TCR_A1			(UL(1) << 22)
27562306a36Sopenharmony_ci#define TCR_ASID16		(UL(1) << 36)
27662306a36Sopenharmony_ci#define TCR_TBI0		(UL(1) << 37)
27762306a36Sopenharmony_ci#define TCR_TBI1		(UL(1) << 38)
27862306a36Sopenharmony_ci#define TCR_HA			(UL(1) << 39)
27962306a36Sopenharmony_ci#define TCR_HD			(UL(1) << 40)
28062306a36Sopenharmony_ci#define TCR_TBID1		(UL(1) << 52)
28162306a36Sopenharmony_ci#define TCR_NFD0		(UL(1) << 53)
28262306a36Sopenharmony_ci#define TCR_NFD1		(UL(1) << 54)
28362306a36Sopenharmony_ci#define TCR_E0PD0		(UL(1) << 55)
28462306a36Sopenharmony_ci#define TCR_E0PD1		(UL(1) << 56)
28562306a36Sopenharmony_ci#define TCR_TCMA0		(UL(1) << 57)
28662306a36Sopenharmony_ci#define TCR_TCMA1		(UL(1) << 58)
28762306a36Sopenharmony_ci
28862306a36Sopenharmony_ci/*
28962306a36Sopenharmony_ci * TTBR.
29062306a36Sopenharmony_ci */
29162306a36Sopenharmony_ci#ifdef CONFIG_ARM64_PA_BITS_52
29262306a36Sopenharmony_ci/*
29362306a36Sopenharmony_ci * TTBR_ELx[1] is RES0 in this configuration.
29462306a36Sopenharmony_ci */
29562306a36Sopenharmony_ci#define TTBR_BADDR_MASK_52	GENMASK_ULL(47, 2)
29662306a36Sopenharmony_ci#endif
29762306a36Sopenharmony_ci
29862306a36Sopenharmony_ci#ifdef CONFIG_ARM64_VA_BITS_52
29962306a36Sopenharmony_ci/* Must be at least 64-byte aligned to prevent corruption of the TTBR */
30062306a36Sopenharmony_ci#define TTBR1_BADDR_4852_OFFSET	(((UL(1) << (52 - PGDIR_SHIFT)) - \
30162306a36Sopenharmony_ci				 (UL(1) << (48 - PGDIR_SHIFT))) * 8)
30262306a36Sopenharmony_ci#endif
30362306a36Sopenharmony_ci
30462306a36Sopenharmony_ci#endif
305