mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 40/78] ARM: aarch64: mmu: use PTE_* definitions from U-Boot
Date: Fri, 16 Mar 2018 13:53:16 +0100	[thread overview]
Message-ID: <20180316125354.23462-41-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20180316125354.23462-1-s.hauer@pengutronix.de>

'PMD' (Page Middle Directory) is a Linuxism that is not really
helpful in the barebox MMU code. Use the U-Boot definitions
which only use PTE_* and seem to be more consistent for our
usecase.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/cpu/mmu_64.c            | 22 +++++++------
 arch/arm/include/asm/pgtable64.h | 67 +++++++++++++---------------------------
 2 files changed, 35 insertions(+), 54 deletions(-)

diff --git a/arch/arm/cpu/mmu_64.c b/arch/arm/cpu/mmu_64.c
index 695a73262d..baa443f9e2 100644
--- a/arch/arm/cpu/mmu_64.c
+++ b/arch/arm/cpu/mmu_64.c
@@ -34,8 +34,12 @@
 
 #include "mmu.h"
 
-#define CACHED_MEM      (PMD_ATTRINDX(MT_NORMAL) | PMD_SECT_S | PMD_SECT_AF | PMD_TYPE_SECT)
-#define UNCACHED_MEM    (PMD_ATTRINDX(MT_DEVICE_nGnRnE) | PMD_SECT_AF)
+#define CACHED_MEM      (PTE_BLOCK_MEMTYPE(MT_NORMAL) | \
+			 PTE_BLOCK_OUTER_SHARE | \
+			 PTE_BLOCK_AF)
+#define UNCACHED_MEM    (PTE_BLOCK_MEMTYPE(MT_DEVICE_nGnRnE) | \
+			 PTE_BLOCK_OUTER_SHARE | \
+			 PTE_BLOCK_AF)
 
 static uint64_t *ttb;
 
@@ -94,14 +98,14 @@ static uint64_t level2mask(int level)
 
 static int pte_type(uint64_t *pte)
 {
-	return *pte & PMD_TYPE_MASK;
+	return *pte & PTE_TYPE_MASK;
 }
 
 static void set_table(uint64_t *pt, uint64_t *table_addr)
 {
 	uint64_t val;
 
-	val = PMD_TYPE_TABLE | (uint64_t)table_addr;
+	val = PTE_TYPE_TABLE | (uint64_t)table_addr;
 	*pt = val;
 }
 
@@ -119,7 +123,7 @@ static uint64_t *get_level_table(uint64_t *pte)
 {
 	uint64_t *table = (uint64_t *)(*pte & XLAT_ADDR_MASK);
 
-	if (pte_type(pte) != PMD_TYPE_TABLE) {
+	if (pte_type(pte) != PTE_TYPE_TABLE) {
 		table = create_table();
 		set_table(pte, table);
 	}
@@ -141,7 +145,7 @@ static __maybe_unused uint64_t *find_pte(uint64_t addr)
 		idx = (addr & level2mask(i)) >> block_shift;
 		pte += idx;
 
-		if ((pte_type(pte) != PMD_TYPE_TABLE) || (block_shift <= GRANULE_SIZE_SHIFT))
+		if ((pte_type(pte) != PTE_TYPE_TABLE) || (block_shift <= GRANULE_SIZE_SHIFT))
 			break;
 		else
 			pte = (uint64_t *)(*pte & XLAT_ADDR_MASK);
@@ -165,21 +169,21 @@ static void map_region(uint64_t virt, uint64_t phys, uint64_t size, uint64_t att
 
 	addr = virt;
 
-	attr &= ~(PMD_TYPE_SECT);
+	attr &= ~PTE_TYPE_MASK;
 
 	while (size) {
 		table = ttb;
 		for (level = 1; level < 4; level++) {
 			block_shift = level2shift(level);
 			idx = (addr & level2mask(level)) >> block_shift;
-			block_size = (1 << block_shift);
+			block_size = (1ULL << block_shift);
 
 			pte = table + idx;
 
 			if (level == 3)
 				attr |= PTE_TYPE_PAGE;
 			else
-				attr |= PMD_TYPE_SECT;
+				attr |= PTE_TYPE_BLOCK;
 
 			if (size >= block_size && IS_ALIGNED(addr, block_size)) {
 				*pte = phys | attr;
diff --git a/arch/arm/include/asm/pgtable64.h b/arch/arm/include/asm/pgtable64.h
index 7f7efa10ca..f2888c3ccd 100644
--- a/arch/arm/include/asm/pgtable64.h
+++ b/arch/arm/include/asm/pgtable64.h
@@ -47,51 +47,28 @@
 
 #define GRANULE_MASK	GRANULE_SIZE
 
-
-/*
- * Level 2 descriptor (PMD).
- */
-#define PMD_TYPE_MASK		(3 << 0)
-#define PMD_TYPE_FAULT		(0 << 0)
-#define PMD_TYPE_TABLE		(3 << 0)
-#define PMD_TYPE_SECT		(1 << 0)
-#define PMD_TABLE_BIT		(1 << 1)
-
-/*
- * Section
- */
-#define PMD_SECT_VALID		(1 << 0)
-#define PMD_SECT_USER		(1 << 6)		/* AP[1] */
-#define PMD_SECT_RDONLY		(1 << 7)		/* AP[2] */
-#define PMD_SECT_S		(3 << 8)
-#define PMD_SECT_AF		(1 << 10)
-#define PMD_SECT_NG		(1 << 11)
-#define PMD_SECT_CONT		(1 << 52)
-#define PMD_SECT_PXN		(1 << 53)
-#define PMD_SECT_UXN		(1 << 54)
-
-/*
- * AttrIndx[2:0] encoding (mapping attributes defined in the MAIR* registers).
- */
-#define PMD_ATTRINDX(t)		((t) << 2)
-#define PMD_ATTRINDX_MASK	(7 << 2)
-
-/*
- * Level 3 descriptor (PTE).
- */
-#define PTE_TYPE_MASK		(3 << 0)
-#define PTE_TYPE_FAULT		(0 << 0)
-#define PTE_TYPE_PAGE		(3 << 0)
-#define PTE_TABLE_BIT		(1 << 1)
-#define PTE_USER		(1 << 6)		/* AP[1] */
-#define PTE_RDONLY		(1 << 7)		/* AP[2] */
-#define PTE_SHARED		(3 << 8)		/* SH[1:0], inner shareable */
-#define PTE_AF			(1 << 10)	/* Access Flag */
-#define PTE_NG			(1 << 11)	/* nG */
-#define PTE_DBM			(1 << 51)	/* Dirty Bit Management */
-#define PTE_CONT		(1 << 52)	/* Contiguous range */
-#define PTE_PXN			(1 << 53)	/* Privileged XN */
-#define PTE_UXN			(1 << 54)	/* User XN */
+/* Hardware page table definitions */
+#define PTE_TYPE_MASK           (3 << 0)
+#define PTE_TYPE_FAULT          (0 << 0)
+#define PTE_TYPE_TABLE          (3 << 0)
+#define PTE_TYPE_PAGE           (3 << 0)
+#define PTE_TYPE_BLOCK          (1 << 0)
+
+#define PTE_TABLE_PXN           (1UL << 59)
+#define PTE_TABLE_XN            (1UL << 60)
+#define PTE_TABLE_AP            (1UL << 61)
+#define PTE_TABLE_NS            (1UL << 63)
+
+/* Block */
+#define PTE_BLOCK_MEMTYPE(x)    ((x) << 2)
+#define PTE_BLOCK_NS            (1 << 5)
+#define PTE_BLOCK_NON_SHARE     (0 << 8)
+#define PTE_BLOCK_OUTER_SHARE   (2 << 8)
+#define PTE_BLOCK_INNER_SHARE   (3 << 8)
+#define PTE_BLOCK_AF            (1 << 10)
+#define PTE_BLOCK_NG            (1 << 11)
+#define PTE_BLOCK_PXN           (UL(1) << 53)
+#define PTE_BLOCK_UXN           (UL(1) << 54)
 
 /*
  * AttrIndx[2:0] encoding (mapping attributes defined in the MAIR* registers).
-- 
2.16.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2018-03-16 12:54 UTC|newest]

Thread overview: 86+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-16 12:52 [PATCH 00/78] ARM aarch64 updates Sascha Hauer
2018-03-16 12:52 ` [PATCH 01/78] ARM: Use obj-pbl- where appropriate Sascha Hauer
2018-03-16 12:52 ` [PATCH 02/78] ARM: Add 64bit compilation alternative Sascha Hauer
2018-03-16 12:52 ` [PATCH 03/78] ARM: return positive offset in get_runtime_offset() Sascha Hauer
2018-03-16 12:52 ` [PATCH 04/78] ARM: mmu: include pgtable header from where it's needed Sascha Hauer
2018-03-16 12:52 ` [PATCH 05/78] ARM: For relocatable image force TEXT_BASE 0x0 Sascha Hauer
2018-03-16 12:52 ` [PATCH 06/78] ARM: scroll past image end without ld_var Sascha Hauer
2018-03-16 12:52 ` [PATCH 07/78] ARM: move away from ld_var Sascha Hauer
2018-03-16 12:52 ` [PATCH 08/78] ARM: remove ld_var support Sascha Hauer
2018-03-16 12:52 ` [PATCH 09/78] ARM: android image: Fix compiler warning on aarch64 Sascha Hauer
2018-03-16 12:52 ` [PATCH 10/78] ARM: bootm: Fix wrong format specifier Sascha Hauer
2018-03-16 12:52 ` [PATCH 11/78] ARM: shutdown: Fix compiler warning Sascha Hauer
2018-03-16 12:52 ` [PATCH 12/78] ARM: aarch64: silence " Sascha Hauer
2018-03-16 12:52 ` [PATCH 13/78] ARM: aarch64: Add dummy naked attribute Sascha Hauer
2018-03-16 12:52 ` [PATCH 14/78] ARM: get_runtime_offset() returns unsigned long Sascha Hauer
2018-03-16 12:52 ` [PATCH 15/78] ARM: aarch64: Add runtime-offset Sascha Hauer
2018-03-16 12:52 ` [PATCH 16/78] ARM: aarch64: implement get_pc() Sascha Hauer
2018-03-16 12:52 ` [PATCH 17/78] ARM: Use generic ffz() Sascha Hauer
2018-03-16 12:52 ` [PATCH 18/78] ARM: bitops: remove unnecessary #ifdef Sascha Hauer
2018-03-16 12:52 ` [PATCH 19/78] ARM: aarch64: Do not use 32bit optimized fls Sascha Hauer
2018-03-16 12:52 ` [PATCH 20/78] ARM: Move mmu_disable to mmu.c Sascha Hauer
2018-03-16 12:52 ` [PATCH 21/78] debug_ll: support 64bit longs Sascha Hauer
2018-03-16 12:52 ` [PATCH 22/78] ARM: aarch64: fix early cache flushing Sascha Hauer
2018-03-16 12:52 ` [PATCH 23/78] ARM: aarch64: cache: Add v8_inv_dcache_range Sascha Hauer
2018-03-16 12:53 ` [PATCH 24/78] ARM: aarch64: cache: no need to ifdef prototypes Sascha Hauer
2018-03-16 12:53 ` [PATCH 25/78] ARM: Add function to return offset to global variables Sascha Hauer
2018-03-16 12:53 ` [PATCH 26/78] ARM: remove function prototypes from the past Sascha Hauer
2018-03-16 12:53 ` [PATCH 27/78] ARM: move linker variable declarations to sections.h Sascha Hauer
2018-03-16 12:53 ` [PATCH 28/78] ARM: relocate_to_current_adr: Use unsigned long for variables Sascha Hauer
2018-03-16 12:53 ` [PATCH 29/78] clocksource: Add armv8 generic timer support Sascha Hauer
2018-03-16 12:53 ` [PATCH 30/78] ARM: aarch64: Add relocation support Sascha Hauer
2018-03-16 21:51   ` Andrey Smirnov
2018-03-19  8:50     ` Sascha Hauer
2018-03-21  5:27       ` Andrey Smirnov
2018-03-21 11:26   ` [PATCH v2 " Sascha Hauer
2018-03-16 12:53 ` [PATCH 31/78] ARM: aarch64: fix pbl linker script for aarch64 Sascha Hauer
2018-03-16 12:53 ` [PATCH 32/78] ARM: aarch64: mmu: Allocate page tables dynamically Sascha Hauer
2018-03-16 12:53 ` [PATCH 33/78] ARM: aarch64: mmu: create_sections() takes size in bytes Sascha Hauer
2018-03-16 12:53 ` [PATCH 34/78] ARM: aarch64: mmu: fix creation of flat mapping Sascha Hauer
2018-03-16 12:53 ` [PATCH 35/78] ARM: aarch64: mmu: remove unused map_io_sections() Sascha Hauer
2018-03-16 12:53 ` [PATCH 36/78] ARM: aarch64: mmu: by default map as device memory Sascha Hauer
2018-03-16 12:53 ` [PATCH 37/78] ARM: aarch64: mmu: Fix mair register setting Sascha Hauer
2018-03-16 12:53 ` [PATCH 38/78] ARM: aarch64: qemu board: remove unnecessary mapping Sascha Hauer
2018-03-16 12:53 ` [PATCH 39/78] ARM: aarch64: mmu: enable mmu in generic code Sascha Hauer
2018-03-16 12:53 ` Sascha Hauer [this message]
2018-03-16 12:53 ` [PATCH 41/78] ARM: aarch64: mmu: Fix adding additional page table levels Sascha Hauer
2018-03-16 12:53 ` [PATCH 42/78] ARM: aarch64: mmu: Fix PTE_TYPE_* flags Sascha Hauer
2018-03-16 12:53 ` [PATCH 43/78] ARM: aarch64: mmu: Fix TCR setting Sascha Hauer
2018-03-16 12:53 ` [PATCH 44/78] ARM: aarch64: mmu: No need to disable icache Sascha Hauer
2018-03-16 12:53 ` [PATCH 45/78] ARM: aarch64: mmu: drop ttb check when disabling the MMU Sascha Hauer
2018-03-16 12:53 ` [PATCH 46/78] ARM: aarch64: mmu: Fix " Sascha Hauer
2018-03-16 12:53 ` [PATCH 47/78] ARM: Make some variables 64bit aware Sascha Hauer
2018-03-16 12:53 ` [PATCH 48/78] dma: Use dma_addr_t as type for DMA addresses Sascha Hauer
2018-03-16 12:53 ` [PATCH 49/78] dma: Add prototypes for dma mapping functions Sascha Hauer
2018-03-16 12:53 ` [PATCH 50/78] ARM: implement " Sascha Hauer
2018-03-16 12:53 ` [PATCH 51/78] ARM: aarch64: implement dma operations Sascha Hauer
2018-03-16 12:53 ` [PATCH 52/78] ARM: aarch64: compile with strict alignment Sascha Hauer
2018-03-16 12:53 ` [PATCH 53/78] ARM: aarch64: move aarch64 exception support to separate file Sascha Hauer
2018-03-16 12:53 ` [PATCH 54/78] ARM: aarch64: fix exception level mixup Sascha Hauer
2018-03-16 12:53 ` [PATCH 55/78] ARM: aarch64: Setup exception vectors in initcall Sascha Hauer
2018-03-16 12:53 ` [PATCH 56/78] ARM: aarch64: lowlevel: Use switch_el Sascha Hauer
2018-03-16 12:53 ` [PATCH 57/78] ARM: aarch64: remove dead code in linker script Sascha Hauer
2018-03-16 12:53 ` [PATCH 58/78] ARM: aarch64: hide some config options Sascha Hauer
2018-03-16 12:53 ` [PATCH 59/78] ARM: aarch64: implement show_regs() Sascha Hauer
2018-03-16 12:53 ` [PATCH 60/78] ARM: aarch64: implement stacktraces Sascha Hauer
2018-03-16 12:53 ` [PATCH 61/78] ARM: aarch64: mmu: Make zero page faulting Sascha Hauer
2018-03-21  4:53   ` Andrey Smirnov
2018-04-09  6:55     ` Sascha Hauer
2018-03-16 12:53 ` [PATCH 62/78] ARM: aarch64: Allow to leave exceptions Sascha Hauer
2018-03-16 12:53 ` [PATCH 63/78] ARM: aarch64: Add esr strings Sascha Hauer
2018-03-16 12:53 ` [PATCH 64/78] ARM: aarch64: print more information on sync exception Sascha Hauer
2018-03-16 12:53 ` [PATCH 65/78] ARM: aarch64: implement ignoring data aborts Sascha Hauer
2018-03-16 12:53 ` [PATCH 66/78] dt-bindings: Drop unused files Sascha Hauer
2018-03-16 12:53 ` [PATCH 67/78] ARM: aarch64: Add barebox head support Sascha Hauer
2018-03-16 12:53 ` [PATCH 68/78] filetype: Detect ARM aarch64 Linux images Sascha Hauer
2018-03-16 12:53 ` [PATCH 69/78] common: Add functions to find free RAM Sascha Hauer
2018-03-16 12:53 ` [PATCH 70/78] bootm: provide handlers the start of the OS image Sascha Hauer
2018-03-16 12:53 ` [PATCH 71/78] ARM: aarch64: disable 32bit boot commands Sascha Hauer
2018-03-16 12:53 ` [PATCH 72/78] ARM: aarch64: Add support to start kernel and barebox Sascha Hauer
2018-03-16 12:53 ` [PATCH 73/78] ARM: cache-armv4: Fix wrong section Sascha Hauer
2018-03-16 12:53 ` [PATCH 74/78] ARM: build: Remove duplicate file compilation Sascha Hauer
2018-03-16 12:53 ` [PATCH 75/78] ARM: Create own cache.c file for aarch64 Sascha Hauer
2018-03-16 12:53 ` [PATCH 76/78] ARM: create separate mmu_64.h file Sascha Hauer
2018-03-16 12:53 ` [PATCH 77/78] ARM: change mmu_early_enable() prototype Sascha Hauer
2018-03-16 12:53 ` [PATCH 78/78] ARM: aarch64: Make early MMU support work Sascha Hauer
2018-03-21  5:35 ` [PATCH 00/78] ARM aarch64 updates Andrey Smirnov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180316125354.23462-41-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox