git: a46059e45f4a - stable/14 - arm64: Make kern_delta unneeded in the boot params

From: Andrew Turner <andrew_at_FreeBSD.org>
Date: Mon, 19 Feb 2024 16:45:29 UTC
The branch stable/14 has been updated by andrew:

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

commit a46059e45f4a6c3001468774e10af9d41c9f4966
Author:     Andrew Turner <andrew@FreeBSD.org>
AuthorDate: 2023-11-13 15:29:30 +0000
Commit:     Andrew Turner <andrew@FreeBSD.org>
CommitDate: 2024-02-19 13:17:09 +0000

    arm64: Make kern_delta unneeded in the boot params
    
    Use pmap_early_vtophys to translate from a virtual to physical where
    we were previously using the calculated delta. This means that, while
    we still calculate it, we don't need to pass it to initarm or either
    pmap bootstrap functions.
    
    While here remove an unneeded printf that indirectly used it or was
    related to the previous printf.
    
    Sponsored by:   Arm Ltd
    Differential Revision:  https://reviews.freebsd.org/D42567
    
    (cherry picked from commit ba31362694fe465b88a025ac7c35ad7f378efc86)
    (cherry picked from commit f3a83b3a6257ea0fd5aba66ff42218350228b321)
---
 sys/arm64/arm64/genassym.c  |  1 -
 sys/arm64/arm64/locore.S    | 15 ++++-----------
 sys/arm64/arm64/machdep.c   |  2 +-
 sys/arm64/arm64/pmap.c      | 12 +++---------
 sys/arm64/include/machdep.h |  1 -
 sys/arm64/include/pmap.h    |  2 +-
 6 files changed, 9 insertions(+), 24 deletions(-)

diff --git a/sys/arm64/arm64/genassym.c b/sys/arm64/arm64/genassym.c
index 0fb00d8aceba..d4970177ab71 100644
--- a/sys/arm64/arm64/genassym.c
+++ b/sys/arm64/arm64/genassym.c
@@ -40,7 +40,6 @@
 ASSYM(BOOTPARAMS_SIZE, roundup2(sizeof(struct arm64_bootparams),
     STACKALIGNBYTES + 1));
 ASSYM(BP_MODULEP, offsetof(struct arm64_bootparams, modulep));
-ASSYM(BP_KERN_DELTA, offsetof(struct arm64_bootparams, kern_delta));
 ASSYM(BP_KERN_STACK, offsetof(struct arm64_bootparams, kern_stack));
 ASSYM(BP_KERN_TTBR0, offsetof(struct arm64_bootparams, kern_ttbr0));
 ASSYM(BP_BOOT_EL, offsetof(struct arm64_bootparams, boot_el));
diff --git a/sys/arm64/arm64/locore.S b/sys/arm64/arm64/locore.S
index f36ee5e75185..ee3404958789 100644
--- a/sys/arm64/arm64/locore.S
+++ b/sys/arm64/arm64/locore.S
@@ -82,11 +82,10 @@ ENTRY(_start)
 	msr	contextidr_el1, xzr
 
 	/* Get the virt -> phys offset */
-	bl	get_virt_delta
+	bl	get_load_phys_addr
 
 	/*
 	 * At this point:
-	 * x29 = PA - VA
 	 * x28 = Our physical load address
 	 */
 
@@ -141,11 +140,7 @@ virtdone:
 	sub	sp, sp, #BOOTPARAMS_SIZE
 	mov	x0, sp
 
-	/* Negate the delta so it is VA -> PA */
-	neg	x29, x29
-
 	str	x1,  [x0, #BP_MODULEP]
-	str	x29, [x0, #BP_KERN_DELTA]
 	adrp	x25, initstack
 	add	x25, x25, :lo12:initstack
 	str	x25, [x0, #BP_KERN_STACK]
@@ -367,11 +362,9 @@ LENTRY(drop_to_el1)
 LEND(drop_to_el1)
 
 /*
- * Get the delta between the physical address we were loaded to and the
- * virtual address we expect to run from. This is used when building the
- * initial page table.
+ * Get the physical address the kernel was loaded at.
  */
-LENTRY(get_virt_delta)
+LENTRY(get_load_phys_addr)
 	/* Load the physical address of virt_map */
 	adrp	x29, virt_map
 	add	x29, x29, :lo12:virt_map
@@ -387,7 +380,7 @@ LENTRY(get_virt_delta)
 	.align 3
 virt_map:
 	.quad	virt_map
-LEND(get_virt_delta)
+LEND(get_load_phys_addr)
 
 /*
  * This builds the page tables containing the identity map, and the kernel
diff --git a/sys/arm64/arm64/machdep.c b/sys/arm64/arm64/machdep.c
index 7aa20357acf4..01896c15e650 100644
--- a/sys/arm64/arm64/machdep.c
+++ b/sys/arm64/arm64/machdep.c
@@ -957,7 +957,7 @@ initarm(struct arm64_bootparams *abp)
 	pan_setup();
 
 	/* Bootstrap enough of pmap  to enter the kernel proper */
-	pmap_bootstrap(KERNBASE - abp->kern_delta, lastaddr - KERNBASE);
+	pmap_bootstrap(lastaddr - KERNBASE);
 	/* Exclude entries needed in the DMAP region, but not phys_avail */
 	if (efihdr != NULL)
 		exclude_efi_map_entries(efihdr);
diff --git a/sys/arm64/arm64/pmap.c b/sys/arm64/arm64/pmap.c
index d9d224f44fb6..b372295d5d43 100644
--- a/sys/arm64/arm64/pmap.c
+++ b/sys/arm64/arm64/pmap.c
@@ -1258,22 +1258,16 @@ pmap_bootstrap_allocate_kasan_l2(vm_paddr_t start_pa, vm_paddr_t end_pa,
  *	Bootstrap the system enough to run with virtual memory.
  */
 void
-pmap_bootstrap(vm_paddr_t kernstart, vm_size_t kernlen)
+pmap_bootstrap(vm_size_t kernlen)
 {
 	vm_offset_t dpcpu, msgbufpv;
 	vm_paddr_t start_pa, pa, min_pa;
-	uint64_t kern_delta;
 	int i;
 
 	/* Verify that the ASID is set through TTBR0. */
 	KASSERT((READ_SPECIALREG(tcr_el1) & TCR_A1) == 0,
 	    ("pmap_bootstrap: TCR_EL1.A1 != 0"));
 
-	kern_delta = KERNBASE - kernstart;
-
-	printf("pmap_bootstrap %lx %lx\n", kernstart, kernlen);
-	printf("%lx\n", (KERNBASE >> L1_SHIFT) & Ln_ADDR_MASK);
-
 	/* Set this early so we can use the pagetable walking functions */
 	kernel_pmap_store.pm_l0 = pagetable_l0_ttbr1;
 	PMAP_LOCK_INIT(kernel_pmap);
@@ -1288,7 +1282,7 @@ pmap_bootstrap(vm_paddr_t kernstart, vm_size_t kernlen)
 	kernel_pmap->pm_asid_set = &asids;
 
 	/* Assume the address we were loaded to is a valid physical address */
-	min_pa = KERNBASE - kern_delta;
+	min_pa = pmap_early_vtophys(KERNBASE);
 
 	physmap_idx = physmem_avail(physmap, nitems(physmap));
 	physmap_idx /= 2;
@@ -1316,7 +1310,7 @@ pmap_bootstrap(vm_paddr_t kernstart, vm_size_t kernlen)
 	 */
 	bs_state.table_attrs &= ~TATTR_PXN_TABLE;
 
-	start_pa = pa = KERNBASE - kern_delta;
+	start_pa = pa = pmap_early_vtophys(KERNBASE);
 
 	/*
 	 * Create the l2 tables up to VM_MAX_KERNEL_ADDRESS.  We assume that the
diff --git a/sys/arm64/include/machdep.h b/sys/arm64/include/machdep.h
index 026a64e0a350..80cb28bcfbeb 100644
--- a/sys/arm64/include/machdep.h
+++ b/sys/arm64/include/machdep.h
@@ -31,7 +31,6 @@
 
 struct arm64_bootparams {
 	vm_offset_t	modulep;
-	uint64_t	kern_delta;
 	vm_offset_t	kern_stack;
 	vm_paddr_t	kern_ttbr0;
 	uint64_t	hcr_el2;
diff --git a/sys/arm64/include/pmap.h b/sys/arm64/include/pmap.h
index e7d23dfb2844..4b4d47ccc7af 100644
--- a/sys/arm64/include/pmap.h
+++ b/sys/arm64/include/pmap.h
@@ -144,7 +144,7 @@ extern vm_offset_t virtual_end;
 #define	pmap_vm_page_alloc_check(m)
 
 void	pmap_activate_vm(pmap_t);
-void	pmap_bootstrap(vm_paddr_t, vm_size_t);
+void	pmap_bootstrap(vm_size_t);
 int	pmap_change_attr(vm_offset_t va, vm_size_t size, int mode);
 int	pmap_change_prot(vm_offset_t va, vm_size_t size, vm_prot_t prot);
 void	pmap_kenter(vm_offset_t sva, vm_size_t size, vm_paddr_t pa, int mode);