Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch Provide and use kern_vtopdiff in KERN_{VTOPHYS,PHYS...
details: https://anonhg.NetBSD.org/src/rev/9e13869b61a4
branches: trunk
changeset: 991875:9e13869b61a4
user: skrll <skrll%NetBSD.org@localhost>
date: Fri Aug 03 15:46:41 2018 +0000
description:
Provide and use kern_vtopdiff in KERN_{VTOPHYS,PHYSTOV}. A step towards
generic arm.
diffstat:
sys/arch/arm/arm32/arm32_kvminit.c | 52 ++++++++++++++-----------------
sys/arch/arm/broadcom/bcm283x_platform.c | 13 +------
sys/arch/arm/include/arm32/machdep.h | 23 ++++++++++++-
sys/arch/evbarm/rpi/rpi2_start.S | 8 ++++-
sys/arch/evbarm/rpi/rpi_start.S | 10 ++++-
5 files changed, 62 insertions(+), 44 deletions(-)
diffs (280 lines):
diff -r 2078841a6c3a -r 9e13869b61a4 sys/arch/arm/arm32/arm32_kvminit.c
--- a/sys/arch/arm/arm32/arm32_kvminit.c Fri Aug 03 15:38:16 2018 +0000
+++ b/sys/arch/arm/arm32/arm32_kvminit.c Fri Aug 03 15:46:41 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: arm32_kvminit.c,v 1.43 2018/07/31 10:31:02 martin Exp $ */
+/* $NetBSD: arm32_kvminit.c,v 1.44 2018/08/03 15:46:41 skrll Exp $ */
/*
* Copyright (c) 2002, 2003, 2005 Genetec Corporation. All rights reserved.
@@ -126,7 +126,7 @@
#include "opt_multiprocessor.h"
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: arm32_kvminit.c,v 1.43 2018/07/31 10:31:02 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: arm32_kvminit.c,v 1.44 2018/08/03 15:46:41 skrll Exp $");
#include <sys/param.h>
#include <sys/device.h>
@@ -175,21 +175,7 @@
/* Page tables for mapping kernel VM */
#define KERNEL_L2PT_VMDATA_NUM 8 /* start with 32MB of KVM */
-/*
- * Macros to translate between physical and virtual for a subset of the
- * kernel address space. *Not* for general use.
- */
-#if defined(KERNEL_BASE_VOFFSET)
-#define KERN_VTOPHYS(bmi, va) \
- ((paddr_t)((vaddr_t)(va) - KERNEL_BASE_VOFFSET))
-#define KERN_PHYSTOV(bmi, pa) \
- ((vaddr_t)((paddr_t)(pa) + KERNEL_BASE_VOFFSET))
-#else
-#define KERN_VTOPHYS(bmi, va) \
- ((paddr_t)((vaddr_t)(va) - KERNEL_BASE + (bmi)->bmi_start))
-#define KERN_PHYSTOV(bmi, pa) \
- ((vaddr_t)((paddr_t)(pa) - (bmi)->bmi_start + KERNEL_BASE))
-#endif
+u_long kern_vtopdiff __attribute__((__section__(".data")));
void
arm32_bootmem_init(paddr_t memstart, psize_t memsize, vsize_t kernelstart)
@@ -197,6 +183,16 @@
struct bootmem_info * const bmi = &bootmem_info;
pv_addr_t *pv = bmi->bmi_freeblocks;
+ /*
+ * FDT/generic boot fills in kern_vtopdiff early
+ */
+#if defined(KERNEL_BASE_VOFFSET)
+ kern_vtopdiff = KERNEL_BASE_VOFFSET;
+#else
+ KASSERT(memstart == kernelstart);
+ kern_vtopdiff = KERNEL_BASE + memstart;
+#endif
+
VPRINTF("%s: memstart=%#lx, memsize=%#lx, kernelstart=%#lx\n",
__func__, memstart, memsize, kernelstart);
@@ -217,7 +213,7 @@
* Let's record where the kernel lives.
*/
bmi->bmi_kernelstart = kernelstart;
- bmi->bmi_kernelend = KERN_VTOPHYS(bmi, round_page((vaddr_t)_end));
+ bmi->bmi_kernelend = KERN_VTOPHYS(round_page((vaddr_t)_end));
#if defined(FDT)
fdt_add_reserved_memory_range(bmi->bmi_kernelstart,
@@ -230,7 +226,7 @@
* Now the rest of the free memory must be after the kernel.
*/
pv->pv_pa = bmi->bmi_kernelend;
- pv->pv_va = KERN_PHYSTOV(bmi, pv->pv_pa);
+ pv->pv_va = KERN_PHYSTOV(pv->pv_pa);
pv->pv_size = bmi->bmi_end - bmi->bmi_kernelend;
bmi->bmi_freepages += pv->pv_size / PAGE_SIZE;
VPRINTF("%s: adding %lu free pages: [%#lx..%#lx] (VA %#lx)\n",
@@ -244,7 +240,7 @@
*/
if (bmi->bmi_start < bmi->bmi_kernelstart) {
pv->pv_pa = bmi->bmi_start;
- pv->pv_va = KERN_PHYSTOV(bmi, pv->pv_pa);
+ pv->pv_va = KERN_PHYSTOV(pv->pv_pa);
pv->pv_size = bmi->bmi_kernelstart - pv->pv_pa;
bmi->bmi_freepages += pv->pv_size / PAGE_SIZE;
VPRINTF("%s: adding %lu free pages: [%#lx..%#lx] (VA %#lx)\n",
@@ -627,7 +623,7 @@
}
const vaddr_t kernel_base =
- KERN_PHYSTOV(bmi, bmi->bmi_kernelstart & -L2_S_SEGSIZE);
+ KERN_PHYSTOV(bmi->bmi_kernelstart & -L2_S_SEGSIZE);
for (size_t idx = 0; idx < KERNEL_L2PT_KERNEL_NUM; idx++) {
pmap_link_l2pt(l1pt_va, kernel_base + idx * L2_S_SEGSIZE,
&kernel_l2pt[idx]);
@@ -656,16 +652,16 @@
VPRINTF("Mapping kernel\n");
- extern char etext[], _end[];
+ extern char etext[];
size_t totalsize = bmi->bmi_kernelend - bmi->bmi_kernelstart;
- size_t textsize = KERN_VTOPHYS(bmi, (uintptr_t)etext) - bmi->bmi_kernelstart;
+ size_t textsize = KERN_VTOPHYS((uintptr_t)etext) - bmi->bmi_kernelstart;
textsize = (textsize + PGOFSET) & ~PGOFSET;
/* start at offset of kernel in RAM */
text.pv_pa = bmi->bmi_kernelstart;
- text.pv_va = KERN_PHYSTOV(bmi, bmi->bmi_kernelstart);
+ text.pv_va = KERN_PHYSTOV(bmi->bmi_kernelstart);
text.pv_size = textsize;
text.pv_prot = VM_PROT_READ | VM_PROT_EXECUTE;
text.pv_cache = PTE_CACHE;
@@ -705,7 +701,7 @@
pv = SLIST_NEXT(pv, pv_list);
} else {
cur_pv.pv_va = KERNEL_BASE;
- cur_pv.pv_pa = KERN_VTOPHYS(bmi, cur_pv.pv_va);
+ cur_pv.pv_pa = KERN_VTOPHYS(cur_pv.pv_va);
cur_pv.pv_size = pv->pv_pa - cur_pv.pv_pa;
cur_pv.pv_prot = VM_PROT_READ | VM_PROT_WRITE;
cur_pv.pv_cache = PTE_CACHE;
@@ -842,19 +838,19 @@
#endif
VPRINTF(mem_fmt, "SDRAM", bmi->bmi_start, bmi->bmi_end - 1,
- KERN_PHYSTOV(bmi, bmi->bmi_start), KERN_PHYSTOV(bmi, bmi->bmi_end - 1),
+ KERN_PHYSTOV(bmi->bmi_start), KERN_PHYSTOV(bmi->bmi_end - 1),
(int)physmem);
VPRINTF(mem_fmt, "text section",
text.pv_pa, text.pv_pa + text.pv_size - 1,
text.pv_va, text.pv_va + text.pv_size - 1,
(int)(text.pv_size / PAGE_SIZE));
VPRINTF(mem_fmt, "data section",
- KERN_VTOPHYS(bmi, __data_start), KERN_VTOPHYS(bmi, _edata),
+ KERN_VTOPHYS((vaddr_t)__data_start), KERN_VTOPHYS((vaddr_t)_edata),
(vaddr_t)__data_start, (vaddr_t)_edata,
(int)((round_page((vaddr_t)_edata)
- trunc_page((vaddr_t)__data_start)) / PAGE_SIZE));
VPRINTF(mem_fmt, "bss section",
- KERN_VTOPHYS(bmi, __bss_start), KERN_VTOPHYS(bmi, __bss_end__),
+ KERN_VTOPHYS((vaddr_t)__bss_start), KERN_VTOPHYS((vaddr_t)__bss_end__),
(vaddr_t)__bss_start, (vaddr_t)__bss_end__,
(int)((round_page((vaddr_t)__bss_end__)
- trunc_page((vaddr_t)__bss_start)) / PAGE_SIZE));
diff -r 2078841a6c3a -r 9e13869b61a4 sys/arch/arm/broadcom/bcm283x_platform.c
--- a/sys/arch/arm/broadcom/bcm283x_platform.c Fri Aug 03 15:38:16 2018 +0000
+++ b/sys/arch/arm/broadcom/bcm283x_platform.c Fri Aug 03 15:46:41 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bcm283x_platform.c,v 1.9 2018/08/03 13:48:24 skrll Exp $ */
+/* $NetBSD: bcm283x_platform.c,v 1.10 2018/08/03 15:46:41 skrll Exp $ */
/*-
* Copyright (c) 2017 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bcm283x_platform.c,v 1.9 2018/08/03 13:48:24 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bcm283x_platform.c,v 1.10 2018/08/03 15:46:41 skrll Exp $");
#include "opt_arm_debug.h"
#include "opt_bcm283x.h"
@@ -307,15 +307,6 @@
* kernel address space. *Not* for general use.
*/
-/*
- * AARCH64 defines its own
- */
-#if !(defined(KERN_VTOPHYS) && defined(KERN_PHYSTOV))
-#define KERN_VTOPDIFF KERNEL_BASE_VOFFSET
-#define KERN_VTOPHYS(va) ((paddr_t)((vaddr_t)va - KERN_VTOPDIFF))
-#define KERN_PHYSTOV(pa) ((vaddr_t)((paddr_t)pa + KERN_VTOPDIFF))
-#endif
-
#ifndef RPI_FB_WIDTH
#define RPI_FB_WIDTH 1280
#endif
diff -r 2078841a6c3a -r 9e13869b61a4 sys/arch/arm/include/arm32/machdep.h
--- a/sys/arch/arm/include/arm32/machdep.h Fri Aug 03 15:38:16 2018 +0000
+++ b/sys/arch/arm/include/arm32/machdep.h Fri Aug 03 15:46:41 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.h,v 1.23 2018/08/01 13:48:00 skrll Exp $ */
+/* $NetBSD: machdep.h,v 1.24 2018/08/03 15:46:41 skrll Exp $ */
#ifndef _ARM32_MACHDEP_H_
#define _ARM32_MACHDEP_H_
@@ -17,7 +17,6 @@
#define FIQ_STACK_SIZE 1
#endif
-
extern void (*cpu_reset_address)(void);
extern paddr_t cpu_reset_address_paddr;
@@ -71,6 +70,26 @@
u_int initarm(void *);
struct pmap_devmap;
struct boot_physmem;
+
+static inline paddr_t
+aarch32_kern_vtophys(vaddr_t va)
+{
+ extern u_long kern_vtopdiff;
+
+ return va - kern_vtopdiff;
+}
+
+static inline vaddr_t
+aarch32_kern_phystov(paddr_t pa)
+{
+ extern u_long kern_vtopdiff;
+
+ return pa + kern_vtopdiff;
+}
+
+#define KERN_VTOPHYS(va) aarch32_kern_vtophys(va)
+#define KERN_PHYSTOV(pa) aarch32_kern_phystov(pa)
+
void arm32_bootmem_init(paddr_t memstart, psize_t memsize, paddr_t kernelstart);
void arm32_kernel_vm_init(vaddr_t kvm_base, vaddr_t vectors,
vaddr_t iovbase /* (can be zero) */,
diff -r 2078841a6c3a -r 9e13869b61a4 sys/arch/evbarm/rpi/rpi2_start.S
--- a/sys/arch/evbarm/rpi/rpi2_start.S Fri Aug 03 15:38:16 2018 +0000
+++ b/sys/arch/evbarm/rpi/rpi2_start.S Fri Aug 03 15:46:41 2018 +0000
@@ -40,7 +40,7 @@
#include "assym.h"
-RCSID("$NetBSD: rpi2_start.S,v 1.7 2018/06/27 11:12:15 ryo Exp $")
+RCSID("$NetBSD: rpi2_start.S,v 1.8 2018/08/03 15:46:41 skrll Exp $")
#if defined(KERNEL_BASES_EQUAL)
#define CALL(f) bl _C_LABEL(f)
@@ -122,6 +122,12 @@
str r2, [r4]
#endif
+ mov r2, #KERNEL_BASE_VOFFSET
+ movw r4, #:lower16:kern_vtopdiff
+ movt r4, #:upper16:kern_vtopdiff
+ sub r4, r4, #KERNEL_BASE_VOFFSET
+ str r2, [r4]
+
/*
* Setup the CPU
*/
diff -r 2078841a6c3a -r 9e13869b61a4 sys/arch/evbarm/rpi/rpi_start.S
--- a/sys/arch/evbarm/rpi/rpi_start.S Fri Aug 03 15:38:16 2018 +0000
+++ b/sys/arch/evbarm/rpi/rpi_start.S Fri Aug 03 15:46:41 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rpi_start.S,v 1.19 2018/08/03 15:38:16 skrll Exp $ */
+/* $NetBSD: rpi_start.S,v 1.20 2018/08/03 15:46:41 skrll Exp $ */
/*
* Copyright (c) 2002, 2003 Genetec Corporation. All rights reserved.
@@ -96,7 +96,7 @@
#include <arm/armreg.h>
#include "assym.h"
-RCSID("$NetBSD: rpi_start.S,v 1.19 2018/08/03 15:38:16 skrll Exp $")
+RCSID("$NetBSD: rpi_start.S,v 1.20 2018/08/03 15:46:41 skrll Exp $")
#if defined(VERBOSE_INIT_ARM)
@@ -153,6 +153,12 @@
sub r8, r8, #KERNEL_BASE_VOFFSET
str r2, [r8]
#endif
+
+ ldr r8, =kern_vtopdiff
+ sub r8, r8, #KERNEL_BASE_VOFFSET
+ mov r2, #KERNEL_BASE_VOFFSET
+ str r2, [r8]
+
mrs r0, cpsr
bic r0, r0, #PSR_MODE
orr r0, r0, #(I32_bit | F32_bit | PSR_SVC32_MODE)
Home |
Main Index |
Thread Index |
Old Index