2012-03-05 11:49:27 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 ARM Ltd.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#ifndef __ASM_PGTABLE_HWDEF_H
|
|
|
|
#define __ASM_PGTABLE_HWDEF_H
|
|
|
|
|
2015-10-19 13:19:29 +00:00
|
|
|
/*
|
|
|
|
* Number of page-table levels required to address 'va_bits' wide
|
|
|
|
* address, without section mapping. We resolve the top (va_bits - PAGE_SHIFT)
|
|
|
|
* bits with (PAGE_SHIFT - 3) bits at each page table level. Hence:
|
|
|
|
*
|
|
|
|
* levels = DIV_ROUND_UP((va_bits - PAGE_SHIFT), (PAGE_SHIFT - 3))
|
|
|
|
*
|
|
|
|
* where DIV_ROUND_UP(n, d) => (((n) + (d) - 1) / (d))
|
|
|
|
*
|
|
|
|
* We cannot include linux/kernel.h which defines DIV_ROUND_UP here
|
|
|
|
* due to build issues. So we open code DIV_ROUND_UP here:
|
|
|
|
*
|
|
|
|
* ((((va_bits) - PAGE_SHIFT) + (PAGE_SHIFT - 3) - 1) / (PAGE_SHIFT - 3))
|
|
|
|
*
|
|
|
|
* which gets simplified as :
|
|
|
|
*/
|
|
|
|
#define ARM64_HW_PGTABLE_LEVELS(va_bits) (((va_bits) - 4) / (PAGE_SHIFT - 3))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Size mapped by an entry at level n ( 0 <= n <= 3)
|
|
|
|
* We map (PAGE_SHIFT - 3) at all translation levels and PAGE_SHIFT bits
|
|
|
|
* in the final page. The maximum number of translation levels supported by
|
|
|
|
* the architecture is 4. Hence, starting at at level n, we have further
|
|
|
|
* ((4 - n) - 1) levels of translation excluding the offset within the page.
|
|
|
|
* So, the total number of bits mapped by an entry at level n is :
|
|
|
|
*
|
|
|
|
* ((4 - n) - 1) * (PAGE_SHIFT - 3) + PAGE_SHIFT
|
|
|
|
*
|
|
|
|
* Rearranging it a bit we get :
|
|
|
|
* (4 - n) * (PAGE_SHIFT - 3) + 3
|
|
|
|
*/
|
|
|
|
#define ARM64_HW_PGTABLE_LEVEL_SHIFT(n) ((PAGE_SHIFT - 3) * (4 - (n)) + 3)
|
|
|
|
|
2014-07-15 15:35:38 +00:00
|
|
|
#define PTRS_PER_PTE (1 << (PAGE_SHIFT - 3))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PMD_SHIFT determines the size a level 2 page table entry can map.
|
|
|
|
*/
|
2015-04-14 22:45:39 +00:00
|
|
|
#if CONFIG_PGTABLE_LEVELS > 2
|
2015-10-19 13:19:29 +00:00
|
|
|
#define PMD_SHIFT ARM64_HW_PGTABLE_LEVEL_SHIFT(2)
|
2014-07-15 15:35:38 +00:00
|
|
|
#define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
|
|
|
|
#define PMD_MASK (~(PMD_SIZE-1))
|
|
|
|
#define PTRS_PER_PMD PTRS_PER_PTE
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PUD_SHIFT determines the size a level 1 page table entry can map.
|
|
|
|
*/
|
2015-04-14 22:45:39 +00:00
|
|
|
#if CONFIG_PGTABLE_LEVELS > 3
|
2015-10-19 13:19:29 +00:00
|
|
|
#define PUD_SHIFT ARM64_HW_PGTABLE_LEVEL_SHIFT(1)
|
2014-07-15 15:35:38 +00:00
|
|
|
#define PUD_SIZE (_AC(1, UL) << PUD_SHIFT)
|
|
|
|
#define PUD_MASK (~(PUD_SIZE-1))
|
|
|
|
#define PTRS_PER_PUD PTRS_PER_PTE
|
2012-03-05 11:49:27 +00:00
|
|
|
#endif
|
|
|
|
|
2014-07-15 15:35:38 +00:00
|
|
|
/*
|
|
|
|
* PGDIR_SHIFT determines the size a top-level page table entry can map
|
|
|
|
* (depending on the configuration, this level can be 0, 1 or 2).
|
|
|
|
*/
|
2015-10-19 13:19:29 +00:00
|
|
|
#define PGDIR_SHIFT ARM64_HW_PGTABLE_LEVEL_SHIFT(4 - CONFIG_PGTABLE_LEVELS)
|
2014-07-15 15:35:38 +00:00
|
|
|
#define PGDIR_SIZE (_AC(1, UL) << PGDIR_SHIFT)
|
|
|
|
#define PGDIR_MASK (~(PGDIR_SIZE-1))
|
|
|
|
#define PTRS_PER_PGD (1 << (VA_BITS - PGDIR_SHIFT))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Section address mask and size definitions.
|
|
|
|
*/
|
|
|
|
#define SECTION_SHIFT PMD_SHIFT
|
|
|
|
#define SECTION_SIZE (_AC(1, UL) << SECTION_SHIFT)
|
|
|
|
#define SECTION_MASK (~(SECTION_SIZE-1))
|
|
|
|
|
2015-10-07 17:00:20 +00:00
|
|
|
/*
|
|
|
|
* Contiguous page definitions.
|
|
|
|
*/
|
2015-12-17 19:31:26 +00:00
|
|
|
#ifdef CONFIG_ARM64_64K_PAGES
|
|
|
|
#define CONT_PTE_SHIFT 5
|
|
|
|
#define CONT_PMD_SHIFT 5
|
|
|
|
#elif defined(CONFIG_ARM64_16K_PAGES)
|
|
|
|
#define CONT_PTE_SHIFT 7
|
|
|
|
#define CONT_PMD_SHIFT 5
|
|
|
|
#else
|
|
|
|
#define CONT_PTE_SHIFT 4
|
|
|
|
#define CONT_PMD_SHIFT 4
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define CONT_PTES (1 << CONT_PTE_SHIFT)
|
|
|
|
#define CONT_PTE_SIZE (CONT_PTES * PAGE_SIZE)
|
|
|
|
#define CONT_PTE_MASK (~(CONT_PTE_SIZE - 1))
|
|
|
|
#define CONT_PMDS (1 << CONT_PMD_SHIFT)
|
|
|
|
#define CONT_PMD_SIZE (CONT_PMDS * PMD_SIZE)
|
|
|
|
#define CONT_PMD_MASK (~(CONT_PMD_SIZE - 1))
|
2015-10-07 17:00:20 +00:00
|
|
|
/* the the numerical offset of the PTE within a range of CONT_PTES */
|
|
|
|
#define CONT_RANGE_OFFSET(addr) (((addr)>>PAGE_SHIFT)&(CONT_PTES-1))
|
|
|
|
|
2012-03-05 11:49:27 +00:00
|
|
|
/*
|
|
|
|
* Hardware page table definitions.
|
|
|
|
*
|
2013-04-10 12:48:00 +00:00
|
|
|
* Level 1 descriptor (PUD).
|
|
|
|
*/
|
2014-05-12 09:40:51 +00:00
|
|
|
#define PUD_TYPE_TABLE (_AT(pudval_t, 3) << 0)
|
2013-04-10 12:48:00 +00:00
|
|
|
#define PUD_TABLE_BIT (_AT(pgdval_t, 1) << 1)
|
2014-05-06 13:02:27 +00:00
|
|
|
#define PUD_TYPE_MASK (_AT(pgdval_t, 3) << 0)
|
|
|
|
#define PUD_TYPE_SECT (_AT(pgdval_t, 1) << 0)
|
2013-04-10 12:48:00 +00:00
|
|
|
|
|
|
|
/*
|
2012-03-05 11:49:27 +00:00
|
|
|
* Level 2 descriptor (PMD).
|
|
|
|
*/
|
|
|
|
#define PMD_TYPE_MASK (_AT(pmdval_t, 3) << 0)
|
|
|
|
#define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
|
|
|
|
#define PMD_TYPE_TABLE (_AT(pmdval_t, 3) << 0)
|
|
|
|
#define PMD_TYPE_SECT (_AT(pmdval_t, 1) << 0)
|
2013-04-10 12:48:00 +00:00
|
|
|
#define PMD_TABLE_BIT (_AT(pmdval_t, 1) << 1)
|
2012-03-05 11:49:27 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Section
|
|
|
|
*/
|
2013-04-19 15:23:57 +00:00
|
|
|
#define PMD_SECT_VALID (_AT(pmdval_t, 1) << 0)
|
2013-12-05 12:04:51 +00:00
|
|
|
#define PMD_SECT_PROT_NONE (_AT(pmdval_t, 1) << 58)
|
2013-04-19 15:23:57 +00:00
|
|
|
#define PMD_SECT_USER (_AT(pmdval_t, 1) << 6) /* AP[1] */
|
|
|
|
#define PMD_SECT_RDONLY (_AT(pmdval_t, 1) << 7) /* AP[2] */
|
2012-03-05 11:49:27 +00:00
|
|
|
#define PMD_SECT_S (_AT(pmdval_t, 3) << 8)
|
|
|
|
#define PMD_SECT_AF (_AT(pmdval_t, 1) << 10)
|
|
|
|
#define PMD_SECT_NG (_AT(pmdval_t, 1) << 11)
|
2015-10-07 17:00:20 +00:00
|
|
|
#define PMD_SECT_CONT (_AT(pmdval_t, 1) << 52)
|
2012-11-15 17:21:16 +00:00
|
|
|
#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 53)
|
|
|
|
#define PMD_SECT_UXN (_AT(pmdval_t, 1) << 54)
|
2012-03-05 11:49:27 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* AttrIndx[2:0] encoding (mapping attributes defined in the MAIR* registers).
|
|
|
|
*/
|
|
|
|
#define PMD_ATTRINDX(t) (_AT(pmdval_t, (t)) << 2)
|
|
|
|
#define PMD_ATTRINDX_MASK (_AT(pmdval_t, 7) << 2)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Level 3 descriptor (PTE).
|
|
|
|
*/
|
|
|
|
#define PTE_TYPE_MASK (_AT(pteval_t, 3) << 0)
|
|
|
|
#define PTE_TYPE_FAULT (_AT(pteval_t, 0) << 0)
|
|
|
|
#define PTE_TYPE_PAGE (_AT(pteval_t, 3) << 0)
|
2013-04-10 12:48:00 +00:00
|
|
|
#define PTE_TABLE_BIT (_AT(pteval_t, 1) << 1)
|
2012-03-05 11:49:27 +00:00
|
|
|
#define PTE_USER (_AT(pteval_t, 1) << 6) /* AP[1] */
|
|
|
|
#define PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
|
|
|
|
#define PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
|
|
|
|
#define PTE_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
|
|
|
|
#define PTE_NG (_AT(pteval_t, 1) << 11) /* nG */
|
2015-07-10 16:24:28 +00:00
|
|
|
#define PTE_DBM (_AT(pteval_t, 1) << 51) /* Dirty Bit Management */
|
2015-10-07 17:00:20 +00:00
|
|
|
#define PTE_CONT (_AT(pteval_t, 1) << 52) /* Contiguous range */
|
2012-11-15 17:21:16 +00:00
|
|
|
#define PTE_PXN (_AT(pteval_t, 1) << 53) /* Privileged XN */
|
|
|
|
#define PTE_UXN (_AT(pteval_t, 1) << 54) /* User XN */
|
2012-03-05 11:49:27 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* AttrIndx[2:0] encoding (mapping attributes defined in the MAIR* registers).
|
|
|
|
*/
|
|
|
|
#define PTE_ATTRINDX(t) (_AT(pteval_t, (t)) << 2)
|
|
|
|
#define PTE_ATTRINDX_MASK (_AT(pteval_t, 7) << 2)
|
|
|
|
|
2012-12-07 18:35:41 +00:00
|
|
|
/*
|
|
|
|
* 2nd stage PTE definitions
|
|
|
|
*/
|
|
|
|
#define PTE_S2_RDONLY (_AT(pteval_t, 1) << 6) /* HAP[2:1] */
|
|
|
|
#define PTE_S2_RDWR (_AT(pteval_t, 3) << 6) /* HAP[2:1] */
|
|
|
|
|
2015-01-15 23:58:59 +00:00
|
|
|
#define PMD_S2_RDONLY (_AT(pmdval_t, 1) << 6) /* HAP[2:1] */
|
2012-11-01 16:14:45 +00:00
|
|
|
#define PMD_S2_RDWR (_AT(pmdval_t, 3) << 6) /* HAP[2:1] */
|
|
|
|
|
2012-12-07 18:35:41 +00:00
|
|
|
/*
|
|
|
|
* Memory Attribute override for Stage-2 (MemAttr[3:0])
|
|
|
|
*/
|
|
|
|
#define PTE_S2_MEMATTR(t) (_AT(pteval_t, (t)) << 2)
|
|
|
|
#define PTE_S2_MEMATTR_MASK (_AT(pteval_t, 0xf) << 2)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* EL2/HYP PTE/PMD definitions
|
|
|
|
*/
|
|
|
|
#define PMD_HYP PMD_SECT_USER
|
|
|
|
#define PTE_HYP PTE_USER
|
|
|
|
|
2012-03-05 11:49:27 +00:00
|
|
|
/*
|
2014-03-07 08:49:25 +00:00
|
|
|
* Highest possible physical address supported.
|
2012-03-05 11:49:27 +00:00
|
|
|
*/
|
2014-03-07 08:49:25 +00:00
|
|
|
#define PHYS_MASK_SHIFT (48)
|
2012-03-05 11:49:27 +00:00
|
|
|
#define PHYS_MASK ((UL(1) << PHYS_MASK_SHIFT) - 1)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TCR flags.
|
|
|
|
*/
|
arm64: mm: increase VA range of identity map
The page size and the number of translation levels, and hence the supported
virtual address range, are build-time configurables on arm64 whose optimal
values are use case dependent. However, in the current implementation, if
the system's RAM is located at a very high offset, the virtual address range
needs to reflect that merely because the identity mapping, which is only used
to enable or disable the MMU, requires the extended virtual range to map the
physical memory at an equal virtual offset.
This patch relaxes that requirement, by increasing the number of translation
levels for the identity mapping only, and only when actually needed, i.e.,
when system RAM's offset is found to be out of reach at runtime.
Tested-by: Laura Abbott <lauraa@codeaurora.org>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Tested-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-03-19 16:42:27 +00:00
|
|
|
#define TCR_T0SZ_OFFSET 0
|
|
|
|
#define TCR_T1SZ_OFFSET 16
|
|
|
|
#define TCR_T0SZ(x) ((UL(64) - (x)) << TCR_T0SZ_OFFSET)
|
|
|
|
#define TCR_T1SZ(x) ((UL(64) - (x)) << TCR_T1SZ_OFFSET)
|
|
|
|
#define TCR_TxSZ(x) (TCR_T0SZ(x) | TCR_T1SZ(x))
|
|
|
|
#define TCR_TxSZ_WIDTH 6
|
2012-03-05 11:49:27 +00:00
|
|
|
#define TCR_IRGN_NC ((UL(0) << 8) | (UL(0) << 24))
|
|
|
|
#define TCR_IRGN_WBWA ((UL(1) << 8) | (UL(1) << 24))
|
|
|
|
#define TCR_IRGN_WT ((UL(2) << 8) | (UL(2) << 24))
|
|
|
|
#define TCR_IRGN_WBnWA ((UL(3) << 8) | (UL(3) << 24))
|
|
|
|
#define TCR_IRGN_MASK ((UL(3) << 8) | (UL(3) << 24))
|
|
|
|
#define TCR_ORGN_NC ((UL(0) << 10) | (UL(0) << 26))
|
|
|
|
#define TCR_ORGN_WBWA ((UL(1) << 10) | (UL(1) << 26))
|
|
|
|
#define TCR_ORGN_WT ((UL(2) << 10) | (UL(2) << 26))
|
|
|
|
#define TCR_ORGN_WBnWA ((UL(3) << 10) | (UL(3) << 26))
|
|
|
|
#define TCR_ORGN_MASK ((UL(3) << 10) | (UL(3) << 26))
|
|
|
|
#define TCR_SHARED ((UL(3) << 12) | (UL(3) << 28))
|
2014-04-02 16:55:40 +00:00
|
|
|
#define TCR_TG0_4K (UL(0) << 14)
|
2012-03-05 11:49:27 +00:00
|
|
|
#define TCR_TG0_64K (UL(1) << 14)
|
2014-04-02 16:55:40 +00:00
|
|
|
#define TCR_TG0_16K (UL(2) << 14)
|
|
|
|
#define TCR_TG1_16K (UL(1) << 30)
|
|
|
|
#define TCR_TG1_4K (UL(2) << 30)
|
|
|
|
#define TCR_TG1_64K (UL(3) << 30)
|
2012-03-05 11:49:27 +00:00
|
|
|
#define TCR_ASID16 (UL(1) << 36)
|
2013-06-12 15:28:04 +00:00
|
|
|
#define TCR_TBI0 (UL(1) << 37)
|
2015-07-10 16:24:28 +00:00
|
|
|
#define TCR_HA (UL(1) << 39)
|
|
|
|
#define TCR_HD (UL(1) << 40)
|
2012-03-05 11:49:27 +00:00
|
|
|
|
|
|
|
#endif
|