From owner-dev-commits-src-all@freebsd.org Wed Mar 3 14:26:50 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 081E356BEF5; Wed, 3 Mar 2021 14:26:50 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DrGXT6rhKz3qHg; Wed, 3 Mar 2021 14:26:49 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id DE86D324D; Wed, 3 Mar 2021 14:26:49 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 123EQnLc082899; Wed, 3 Mar 2021 14:26:49 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 123EQnRg082898; Wed, 3 Mar 2021 14:26:49 GMT (envelope-from git) Date: Wed, 3 Mar 2021 14:26:49 GMT Message-Id: <202103031426.123EQnRg082898@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Andrew Turner Subject: git: 48ba9b2669e6 - main - Use L2 blocks when in the identity map MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: andrew X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 48ba9b2669e6a92a3254ec34461d0d86fb20b9f4 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Mar 2021 14:26:50 -0000 The branch main has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=48ba9b2669e6a92a3254ec34461d0d86fb20b9f4 commit 48ba9b2669e6a92a3254ec34461d0d86fb20b9f4 Author: Andrew Turner AuthorDate: 2020-12-24 11:02:34 +0000 Commit: Andrew Turner 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