git: 48ba9b2669e6 - main - Use L2 blocks when in the identity map

Andrew Turner andrew at FreeBSD.org
Wed Mar 3 14:26:50 UTC 2021


The branch main has been updated by andrew:

URL: https://cgit.FreeBSD.org/src/commit/?id=48ba9b2669e6a92a3254ec34461d0d86fb20b9f4

commit 48ba9b2669e6a92a3254ec34461d0d86fb20b9f4
Author:     Andrew Turner <andrew at FreeBSD.org>
AuthorDate: 2020-12-24 11:02:34 +0000
Commit:     Andrew Turner <andrew at FreeBSD.org>
CommitDate: 2021-03-03 14:18:03 +0000

    Use L2 blocks when in the identity map
    
    This reduces the memory mapped to be closer to the minimal memory
    needed to enable the MMU.
    
    Reviewed by:    mmel
    Sponsored by:   Innovate UK
    Differential Revision:://reviews.freebsd.org/D27765
---
 sys/arm64/arm64/locore.S    | 101 ++++++++++++++++++--------------------------
 sys/arm64/include/machdep.h |   8 ++++
 sys/conf/options.arm64      |   1 -
 3 files changed, 49 insertions(+), 61 deletions(-)

diff --git a/sys/arm64/arm64/locore.S b/sys/arm64/arm64/locore.S
index b340041eb163..4d356e8897f0 100644
--- a/sys/arm64/arm64/locore.S
+++ b/sys/arm64/arm64/locore.S
@@ -466,35 +466,58 @@ common:
 	add	x27, x24, #PAGE_SIZE
 
 	mov	x6, x27		/* The initial page table */
-#if defined(SOCDEV_PA) && defined(SOCDEV_VA)
+
+	/* Create the VA = PA map */
+	mov	x7, #(ATTR_S1_nG | ATTR_S1_IDX(VM_MEMATTR_WRITE_BACK))
+	adrp	x16, _start
+	and	x16, x16, #(~L2_OFFSET)
+	mov	x9, x16		/* PA start */
+	mov	x8, x16		/* VA start (== PA start) */
+	mov	x10, #1
+	bl	build_l2_block_pagetable
+
+#if defined(SOCDEV_PA)
 	/* Create a table for the UART */
 	mov	x7, #(ATTR_S1_nG | ATTR_S1_IDX(VM_MEMATTR_DEVICE))
-	mov	x8, #(SOCDEV_VA)	/* VA start */
-	mov	x9, #(SOCDEV_PA)	/* PA start */
+	add	x16, x16, #(L2_SIZE)	/* VA start */
+	mov	x8, x16
+
+	/* Store the socdev virtual address */
+	add	x17, x8, #(SOCDEV_PA & L2_OFFSET)
+	adrp	x9, socdev_va
+	str	x17, [x9, :lo12:socdev_va]
+
+	mov	x9, #(SOCDEV_PA & ~L2_OFFSET)	/* PA start */
 	mov	x10, #1
-	bl	build_l1_block_pagetable
+	bl	build_l2_block_pagetable
 #endif
 
 #if defined(LINUX_BOOT_ABI)
 	/* Map FDT data ? */
 	cbz	x19, 1f
 
-	/* Create the identity mapping for FDT data (2 MiB max) */
+	/* Create the mapping for FDT data (2 MiB max) */
 	mov	x7, #(ATTR_S1_nG | ATTR_S1_IDX(VM_MEMATTR_WRITE_BACK))
-	mov	x9, x0
-	mov	x8, x0		/* VA start (== PA start) */
+	add	x16, x16, #(L2_SIZE)	/* VA start */
+	mov	x8, x16
+	mov	x9, x0			/* PA start */
+	/* Update the module pointer to point at the allocated memory */
+	and	x0, x0, #(L2_OFFSET)	/* Keep the lower bits */
+	add	x0, x0, x8		/* Add the aligned virtual address */
+
 	mov	x10, #1
-	bl	build_l1_block_pagetable
+	bl	build_l2_block_pagetable
 
 1:
 #endif
 
-	/* Create the VA = PA map */
-	mov	x7, #(ATTR_S1_nG | ATTR_S1_IDX(VM_MEMATTR_WRITE_BACK))
-	mov	x9, x28
-	mov	x8, x9		/* VA start (== PA start) */
-	mov	x10, #1
-	bl	build_l1_block_pagetable
+	/* Move to the l1 table */
+	add	x27, x27, #PAGE_SIZE
+
+	/* Link the l1 -> l2 table */
+	mov	x9, x6
+	mov	x6, x27
+	bl	link_l1_pagetable
 
 	/* Move to the l0 table */
 	add	x27, x27, #PAGE_SIZE
@@ -513,13 +536,10 @@ LEND(create_pagetables)
 /*
  * Builds an L0 -> L1 table descriptor
  *
- * This is a link for a 512GiB block of memory with up to 1GiB regions mapped
- * within it by build_l1_block_pagetable.
- *
  *  x6  = L0 table
  *  x8  = Virtual Address
  *  x9  = L1 PA (trashed)
- *  x10 = Entry count
+ *  x10 = Entry count (trashed)
  *  x11, x12 and x13 are trashed
  */
 LENTRY(link_l0_pagetable)
@@ -551,9 +571,6 @@ LEND(link_l0_pagetable)
 /*
  * Builds an L1 -> L2 table descriptor
  *
- * This is a link for a 1GiB block of memory with up to 2MiB regions mapped
- * within it by build_l2_block_pagetable.
- *
  *  x6  = L1 table
  *  x8  = Virtual Address
  *  x9  = L2 PA (trashed)
@@ -580,51 +597,13 @@ LENTRY(link_l1_pagetable)
 	ret
 LEND(link_l1_pagetable)
 
-/*
- * Builds count 1 GiB page table entry
- *  x6  = L1 table
- *  x7  = Variable lower block attributes
- *  x8  = VA start
- *  x9  = PA start (trashed)
- *  x10 = Entry count
- *  x11, x12 and x13 are trashed
- */
-LENTRY(build_l1_block_pagetable)
-	/*
-	 * Build the L1 table entry.
-	 */
-	/* Find the table index */
-	lsr	x11, x8, #L1_SHIFT
-	and	x11, x11, #Ln_ADDR_MASK
-
-	/* Build the L1 block entry */
-	orr	x12, x7, #L1_BLOCK
-	orr	x12, x12, #(ATTR_DEFAULT)
-
-	/* Only use the output address bits */
-	lsr	x9, x9, #L1_SHIFT
-
-	/* Set the physical address for this virtual address */
-1:	orr	x13, x12, x9, lsl #L1_SHIFT
-
-	/* Store the entry */
-	str	x13, [x6, x11, lsl #3]
-
-	sub	x10, x10, #1
-	add	x11, x11, #1
-	add	x9, x9, #1
-	cbnz	x10, 1b
-
-	ret
-LEND(build_l1_block_pagetable)
-
 /*
  * Builds count 2 MiB page table entry
  *  x6  = L2 table
  *  x7  = Type (0 = Device, 1 = Normal)
  *  x8  = VA start
  *  x9  = PA start (trashed)
- *  x10 = Entry count
+ *  x10 = Entry count (trashed)
  *  x11, x12 and x13 are trashed
  */
 LENTRY(build_l2_block_pagetable)
@@ -778,6 +757,8 @@ pagetable_l1_ttbr1:
 	.space	PAGE_SIZE
 pagetable_l0_ttbr1:
 	.space	PAGE_SIZE
+pagetable_l2_ttbr0_bootstrap:
+	.space	PAGE_SIZE
 pagetable_l1_ttbr0_bootstrap:
 	.space	PAGE_SIZE
 pagetable_l0_ttbr0_boostrap:
diff --git a/sys/arm64/include/machdep.h b/sys/arm64/include/machdep.h
index 54ffcbd46c81..45ff0065930a 100644
--- a/sys/arm64/include/machdep.h
+++ b/sys/arm64/include/machdep.h
@@ -60,6 +60,14 @@ void parse_fdt_bootargs(void);
 int memory_mapping_mode(vm_paddr_t pa);
 extern void (*pagezero)(void *);
 
+#ifdef SOCDEV_PA
+/*
+ * The virtual address SOCDEV_PA is mapped at.
+ * Only valid while the early pagetables are valid.
+ */
+extern uintptr_t socdev_va;
+#endif
+
 #endif /* _KERNEL */
 
 #endif /* _MACHINE_MACHDEP_H_ */
diff --git a/sys/conf/options.arm64 b/sys/conf/options.arm64
index 5a97fd6b3ef6..5185a301e55e 100644
--- a/sys/conf/options.arm64
+++ b/sys/conf/options.arm64
@@ -3,7 +3,6 @@
 ARM64				opt_global.h
 INTRNG				opt_global.h
 SOCDEV_PA			opt_global.h
-SOCDEV_VA			opt_global.h
 THUNDERX_PASS_1_1_ERRATA	opt_global.h
 VFP				opt_global.h
 LINUX_BOOT_ABI			opt_global.h


More information about the dev-commits-src-all mailing list